xref: /titanic_41/usr/src/cmd/ssh/include/packet.h (revision 9e39c5ba00a55fa05777cc94b148296af305e135)
1 /*
2  * Author: Tatu Ylonen <ylo@cs.hut.fi>
3  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4  *                    All rights reserved
5  * Interface for the packet protocol functions.
6  *
7  * As far as I am concerned, the code I have written for this software
8  * can be used freely for any purpose.  Any derived versions of this
9  * software must be clearly marked as such, and if the derived work is
10  * incompatible with the protocol description in the RFC file, it must be
11  * called by a name other than "ssh" or "Secure Shell".
12  */
13 /*
14  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
15  * Use is subject to license terms.
16  */
17 
18 #ifndef	_PACKET_H
19 #define	_PACKET_H
20 
21 /*	$OpenBSD: packet.h,v 1.35 2002/06/19 18:01:00 markus Exp $	*/
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 
28 #include <openssl/bn.h>
29 #include "kex.h"
30 
31 #ifdef ALTPRIVSEP
32 /* Monitor-side functions */
33 void	 packet_set_server(void);
34 void	 packet_set_no_monitor(void);
35 void	 packet_set_monitor(int pip_fd);
36 int	 packet_is_server(void);
37 int	 packet_is_monitor(void);
38 void	 packet_set_packet(const void *buf, u_int len);
39 void	 packet_set_fds(int fd, int restore);
40 #endif /* ALTPRIVSEP */
41 
42 void     packet_set_connection(int, int);
43 void     packet_set_nonblocking(void);
44 int      packet_get_connection_in(void);
45 int      packet_get_connection_out(void);
46 void     packet_close(void);
47 void	 packet_set_encryption_key(const u_char *, u_int, int);
48 u_int	 packet_get_encryption_key(u_char *);
49 void     packet_set_protocol_flags(u_int);
50 u_int	 packet_get_protocol_flags(void);
51 void     packet_start_compression(int);
52 void     packet_set_interactive(int);
53 int      packet_is_interactive(void);
54 
55 void     packet_start(u_char);
56 void     packet_put_char(int ch);
57 void     packet_put_int(u_int value);
58 void     packet_put_bignum(BIGNUM * value);
59 void     packet_put_bignum2(BIGNUM * value);
60 void     packet_put_string(const void *buf, u_int len);
61 void     packet_put_cstring(const char *str);
62 void     packet_put_ascii_cstring(const char *str);
63 void     packet_put_utf8_cstring(const u_char *str);
64 void     packet_put_raw(const void *buf, u_int len);
65 void     packet_send(void);
66 
67 #if 0
68 /* If these are needed, then get rid of the #if 0 and this comment */
69 void     packet_put_utf8_string(const u_char *buf, u_int len);
70 void     packet_put_ascii_string(const char *str, u_int len);
71 #endif
72 
73 int      packet_read(void);
74 void     packet_read_expect(int type);
75 int      packet_read_poll(void);
76 void     packet_process_incoming(const char *buf, u_int len);
77 int      packet_read_seqnr(u_int32_t *seqnr_p);
78 int      packet_read_poll_seqnr(u_int32_t *seqnr_p);
79 
80 u_int	 packet_get_char(void);
81 u_int	 packet_get_int(void);
82 void     packet_get_bignum(BIGNUM * value);
83 void     packet_get_bignum2(BIGNUM * value);
84 void	*packet_get_raw(u_int *length_ptr);
85 void	*packet_get_string(u_int *length_ptr);
86 char	*packet_get_ascii_cstring();
87 u_char	*packet_get_utf8_cstring();
88 void     packet_disconnect(const char *fmt,...) __attribute__((format(printf, 1, 2)));
89 void     packet_send_debug(const char *fmt,...) __attribute__((format(printf, 1, 2)));
90 
91 void	 set_newkeys(int mode);
92 void	 free_keys(Newkeys *keys);
93 
94 void     packet_write_poll(void);
95 void     packet_write_wait(void);
96 int      packet_have_data_to_write(void);
97 int      packet_not_very_much_data_to_write(void);
98 
99 int	 packet_connection_is_on_socket(void);
100 int	 packet_connection_is_ipv4(void);
101 int	 packet_remaining(void);
102 void	 packet_send_ignore(int);
103 void	 packet_add_padding(u_char);
104 
105 void	 tty_make_modes(int, struct termios *);
106 void	 tty_parse_modes(int, int *);
107 
108 extern int max_packet_size;
109 int      packet_set_maxsize(int);
110 #define  packet_get_maxsize() max_packet_size
111 
112 /* don't allow remaining bytes after the end of the message */
113 #define packet_check_eom() \
114 do { \
115 	int _len = packet_remaining(); \
116 	if (_len > 0) { \
117 		log("Packet integrity error (%d bytes remaining) at %s:%d", \
118 		    _len ,__FILE__, __LINE__); \
119 		packet_disconnect("Packet integrity error."); \
120 	} \
121 } while (0)
122 
123 int	 packet_need_rekeying(void);
124 void     packet_set_rekey_limit(u_int32_t);
125 
126 /* see a comment attached to will_daemonize in packet.c for more information */
127 #define NOT_DAEMONIZING			0
128 #define DAEMONIZING_REQUESTED		1
129 #define FIRST_NEWKEYS_PROCESSED		2
130 #define SECOND_NEWKEYS_PROCESSED	3
131 
132 #ifdef __cplusplus
133 }
134 #endif
135 
136 #endif /* _PACKET_H */
137