xref: /onnv-gate/usr/src/cmd/ssh/include/packet.h (revision 9600:113cf06ae502)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * Author: Tatu Ylonen <ylo@cs.hut.fi>
30Sstevel@tonic-gate  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
40Sstevel@tonic-gate  *                    All rights reserved
50Sstevel@tonic-gate  * Interface for the packet protocol functions.
60Sstevel@tonic-gate  *
70Sstevel@tonic-gate  * As far as I am concerned, the code I have written for this software
80Sstevel@tonic-gate  * can be used freely for any purpose.  Any derived versions of this
90Sstevel@tonic-gate  * software must be clearly marked as such, and if the derived work is
100Sstevel@tonic-gate  * incompatible with the protocol description in the RFC file, it must be
110Sstevel@tonic-gate  * called by a name other than "ssh" or "Secure Shell".
120Sstevel@tonic-gate  */
130Sstevel@tonic-gate /*
14*9600SNobutomo.Nakano@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
150Sstevel@tonic-gate  * Use is subject to license terms.
160Sstevel@tonic-gate  */
170Sstevel@tonic-gate 
185562Sjp161948 #ifndef	_PACKET_H
195562Sjp161948 #define	_PACKET_H
205562Sjp161948 
215562Sjp161948 /*	$OpenBSD: packet.h,v 1.35 2002/06/19 18:01:00 markus Exp $	*/
225562Sjp161948 
235562Sjp161948 #ifdef __cplusplus
245562Sjp161948 extern "C" {
255562Sjp161948 #endif
265562Sjp161948 
275562Sjp161948 
280Sstevel@tonic-gate #include <openssl/bn.h>
295562Sjp161948 #include "kex.h"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #ifdef ALTPRIVSEP
320Sstevel@tonic-gate /* Monitor-side functions */
330Sstevel@tonic-gate void	 packet_set_server(void);
340Sstevel@tonic-gate void	 packet_set_no_monitor(void);
350Sstevel@tonic-gate void	 packet_set_monitor(int pip_fd);
360Sstevel@tonic-gate int	 packet_is_server(void);
370Sstevel@tonic-gate int	 packet_is_monitor(void);
380Sstevel@tonic-gate void	 packet_set_packet(const void *buf, u_int len);
397574SJan.Pechanec@Sun.COM void	 packet_set_fds(int fd, int restore);
400Sstevel@tonic-gate #endif /* ALTPRIVSEP */
410Sstevel@tonic-gate 
420Sstevel@tonic-gate void     packet_set_connection(int, int);
430Sstevel@tonic-gate void     packet_set_nonblocking(void);
440Sstevel@tonic-gate int      packet_get_connection_in(void);
450Sstevel@tonic-gate int      packet_get_connection_out(void);
460Sstevel@tonic-gate void     packet_close(void);
470Sstevel@tonic-gate void	 packet_set_encryption_key(const u_char *, u_int, int);
480Sstevel@tonic-gate u_int	 packet_get_encryption_key(u_char *);
490Sstevel@tonic-gate void     packet_set_protocol_flags(u_int);
500Sstevel@tonic-gate u_int	 packet_get_protocol_flags(void);
510Sstevel@tonic-gate void     packet_start_compression(int);
520Sstevel@tonic-gate void     packet_set_interactive(int);
530Sstevel@tonic-gate int      packet_is_interactive(void);
540Sstevel@tonic-gate 
550Sstevel@tonic-gate void     packet_start(u_char);
560Sstevel@tonic-gate void     packet_put_char(int ch);
570Sstevel@tonic-gate void     packet_put_int(u_int value);
580Sstevel@tonic-gate void     packet_put_bignum(BIGNUM * value);
590Sstevel@tonic-gate void     packet_put_bignum2(BIGNUM * value);
600Sstevel@tonic-gate void     packet_put_string(const void *buf, u_int len);
610Sstevel@tonic-gate void     packet_put_cstring(const char *str);
620Sstevel@tonic-gate void     packet_put_raw(const void *buf, u_int len);
630Sstevel@tonic-gate void     packet_send(void);
640Sstevel@tonic-gate 
65*9600SNobutomo.Nakano@Sun.COM void     packet_put_utf8_string(const char *str, uint_t len);
66*9600SNobutomo.Nakano@Sun.COM void     packet_put_utf8_cstring(const char *str);
670Sstevel@tonic-gate 
680Sstevel@tonic-gate int      packet_read(void);
690Sstevel@tonic-gate void     packet_read_expect(int type);
700Sstevel@tonic-gate int      packet_read_poll(void);
710Sstevel@tonic-gate void     packet_process_incoming(const char *buf, u_int len);
720Sstevel@tonic-gate int      packet_read_seqnr(u_int32_t *seqnr_p);
730Sstevel@tonic-gate int      packet_read_poll_seqnr(u_int32_t *seqnr_p);
740Sstevel@tonic-gate 
750Sstevel@tonic-gate u_int	 packet_get_char(void);
760Sstevel@tonic-gate u_int	 packet_get_int(void);
770Sstevel@tonic-gate void     packet_get_bignum(BIGNUM * value);
780Sstevel@tonic-gate void     packet_get_bignum2(BIGNUM * value);
790Sstevel@tonic-gate void	*packet_get_raw(u_int *length_ptr);
800Sstevel@tonic-gate void	*packet_get_string(u_int *length_ptr);
81*9600SNobutomo.Nakano@Sun.COM char	*packet_get_utf8_string(uint_t *length_ptr);
820Sstevel@tonic-gate void     packet_disconnect(const char *fmt,...) __attribute__((format(printf, 1, 2)));
830Sstevel@tonic-gate void     packet_send_debug(const char *fmt,...) __attribute__((format(printf, 1, 2)));
840Sstevel@tonic-gate 
850Sstevel@tonic-gate void	 set_newkeys(int mode);
865562Sjp161948 void	 free_keys(Newkeys *keys);
870Sstevel@tonic-gate 
880Sstevel@tonic-gate void     packet_write_poll(void);
890Sstevel@tonic-gate void     packet_write_wait(void);
900Sstevel@tonic-gate int      packet_have_data_to_write(void);
910Sstevel@tonic-gate int      packet_not_very_much_data_to_write(void);
920Sstevel@tonic-gate 
930Sstevel@tonic-gate int	 packet_connection_is_on_socket(void);
940Sstevel@tonic-gate int	 packet_connection_is_ipv4(void);
950Sstevel@tonic-gate int	 packet_remaining(void);
960Sstevel@tonic-gate void	 packet_send_ignore(int);
970Sstevel@tonic-gate void	 packet_add_padding(u_char);
980Sstevel@tonic-gate 
990Sstevel@tonic-gate void	 tty_make_modes(int, struct termios *);
1000Sstevel@tonic-gate void	 tty_parse_modes(int, int *);
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate extern int max_packet_size;
1030Sstevel@tonic-gate int      packet_set_maxsize(int);
1040Sstevel@tonic-gate #define  packet_get_maxsize() max_packet_size
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate /* don't allow remaining bytes after the end of the message */
1070Sstevel@tonic-gate #define packet_check_eom() \
1080Sstevel@tonic-gate do { \
1090Sstevel@tonic-gate 	int _len = packet_remaining(); \
1100Sstevel@tonic-gate 	if (_len > 0) { \
1110Sstevel@tonic-gate 		log("Packet integrity error (%d bytes remaining) at %s:%d", \
1120Sstevel@tonic-gate 		    _len ,__FILE__, __LINE__); \
1130Sstevel@tonic-gate 		packet_disconnect("Packet integrity error."); \
1140Sstevel@tonic-gate 	} \
1150Sstevel@tonic-gate } while (0)
1160Sstevel@tonic-gate 
1175562Sjp161948 int	 packet_need_rekeying(void);
1185562Sjp161948 void     packet_set_rekey_limit(u_int32_t);
1195562Sjp161948 
1207574SJan.Pechanec@Sun.COM /* see a comment attached to will_daemonize in packet.c for more information */
1217574SJan.Pechanec@Sun.COM #define NOT_DAEMONIZING			0
1227574SJan.Pechanec@Sun.COM #define DAEMONIZING_REQUESTED		1
1237574SJan.Pechanec@Sun.COM #define FIRST_NEWKEYS_PROCESSED		2
1247574SJan.Pechanec@Sun.COM #define SECOND_NEWKEYS_PROCESSED	3
1257574SJan.Pechanec@Sun.COM 
1260Sstevel@tonic-gate #ifdef __cplusplus
1270Sstevel@tonic-gate }
1280Sstevel@tonic-gate #endif
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate #endif /* _PACKET_H */
131