xref: /titanic_50/usr/src/cmd/ssh/include/packet.h (revision 9a8058b57457911fab0e3b4b6f0a97740e7a816d)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Author: Tatu Ylonen <ylo@cs.hut.fi>
37c478bd9Sstevel@tonic-gate  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
47c478bd9Sstevel@tonic-gate  *                    All rights reserved
57c478bd9Sstevel@tonic-gate  * Interface for the packet protocol functions.
67c478bd9Sstevel@tonic-gate  *
77c478bd9Sstevel@tonic-gate  * As far as I am concerned, the code I have written for this software
87c478bd9Sstevel@tonic-gate  * can be used freely for any purpose.  Any derived versions of this
97c478bd9Sstevel@tonic-gate  * software must be clearly marked as such, and if the derived work is
107c478bd9Sstevel@tonic-gate  * incompatible with the protocol description in the RFC file, it must be
117c478bd9Sstevel@tonic-gate  * called by a name other than "ssh" or "Secure Shell".
127c478bd9Sstevel@tonic-gate  */
137c478bd9Sstevel@tonic-gate /*
14*9a8058b5Sjp161948  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
157c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
167c478bd9Sstevel@tonic-gate  */
177c478bd9Sstevel@tonic-gate 
18*9a8058b5Sjp161948 #ifndef	_PACKET_H
19*9a8058b5Sjp161948 #define	_PACKET_H
20*9a8058b5Sjp161948 
21*9a8058b5Sjp161948 /*	$OpenBSD: packet.h,v 1.35 2002/06/19 18:01:00 markus Exp $	*/
22*9a8058b5Sjp161948 
23*9a8058b5Sjp161948 #pragma ident	"%Z%%M%	%I%	%E% SMI"
24*9a8058b5Sjp161948 
25*9a8058b5Sjp161948 #ifdef __cplusplus
26*9a8058b5Sjp161948 extern "C" {
27*9a8058b5Sjp161948 #endif
28*9a8058b5Sjp161948 
29*9a8058b5Sjp161948 
307c478bd9Sstevel@tonic-gate #include <openssl/bn.h>
31*9a8058b5Sjp161948 #include "kex.h"
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifdef ALTPRIVSEP
347c478bd9Sstevel@tonic-gate /* Monitor-side functions */
357c478bd9Sstevel@tonic-gate void	 packet_set_server(void);
367c478bd9Sstevel@tonic-gate void	 packet_set_no_monitor(void);
377c478bd9Sstevel@tonic-gate void	 packet_set_monitor(int pip_fd);
387c478bd9Sstevel@tonic-gate int	 packet_is_server(void);
397c478bd9Sstevel@tonic-gate int	 packet_is_monitor(void);
407c478bd9Sstevel@tonic-gate void	 packet_set_packet(const void *buf, u_int len);
417c478bd9Sstevel@tonic-gate #endif /* ALTPRIVSEP */
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate void     packet_set_connection(int, int);
447c478bd9Sstevel@tonic-gate void     packet_set_nonblocking(void);
457c478bd9Sstevel@tonic-gate int      packet_get_connection_in(void);
467c478bd9Sstevel@tonic-gate int      packet_get_connection_out(void);
477c478bd9Sstevel@tonic-gate void     packet_close(void);
487c478bd9Sstevel@tonic-gate void	 packet_set_encryption_key(const u_char *, u_int, int);
497c478bd9Sstevel@tonic-gate u_int	 packet_get_encryption_key(u_char *);
507c478bd9Sstevel@tonic-gate void     packet_set_protocol_flags(u_int);
517c478bd9Sstevel@tonic-gate u_int	 packet_get_protocol_flags(void);
527c478bd9Sstevel@tonic-gate void     packet_start_compression(int);
537c478bd9Sstevel@tonic-gate void     packet_set_interactive(int);
547c478bd9Sstevel@tonic-gate int      packet_is_interactive(void);
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate void     packet_start(u_char);
577c478bd9Sstevel@tonic-gate void     packet_put_char(int ch);
587c478bd9Sstevel@tonic-gate void     packet_put_int(u_int value);
597c478bd9Sstevel@tonic-gate void     packet_put_bignum(BIGNUM * value);
607c478bd9Sstevel@tonic-gate void     packet_put_bignum2(BIGNUM * value);
617c478bd9Sstevel@tonic-gate void     packet_put_string(const void *buf, u_int len);
627c478bd9Sstevel@tonic-gate void     packet_put_cstring(const char *str);
637c478bd9Sstevel@tonic-gate void     packet_put_ascii_cstring(const char *str);
647c478bd9Sstevel@tonic-gate void     packet_put_utf8_cstring(const u_char *str);
657c478bd9Sstevel@tonic-gate void     packet_put_raw(const void *buf, u_int len);
667c478bd9Sstevel@tonic-gate void     packet_send(void);
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate #if 0
697c478bd9Sstevel@tonic-gate /* If these are needed, then get rid of the #if 0 and this comment */
707c478bd9Sstevel@tonic-gate void     packet_put_utf8_string(const u_char *buf, u_int len);
717c478bd9Sstevel@tonic-gate void     packet_put_ascii_string(const char *str, u_int len);
727c478bd9Sstevel@tonic-gate #endif
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate int      packet_read(void);
757c478bd9Sstevel@tonic-gate void     packet_read_expect(int type);
767c478bd9Sstevel@tonic-gate int      packet_read_poll(void);
777c478bd9Sstevel@tonic-gate void     packet_process_incoming(const char *buf, u_int len);
787c478bd9Sstevel@tonic-gate int      packet_read_seqnr(u_int32_t *seqnr_p);
797c478bd9Sstevel@tonic-gate int      packet_read_poll_seqnr(u_int32_t *seqnr_p);
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate u_int	 packet_get_char(void);
827c478bd9Sstevel@tonic-gate u_int	 packet_get_int(void);
837c478bd9Sstevel@tonic-gate void     packet_get_bignum(BIGNUM * value);
847c478bd9Sstevel@tonic-gate void     packet_get_bignum2(BIGNUM * value);
857c478bd9Sstevel@tonic-gate void	*packet_get_raw(u_int *length_ptr);
867c478bd9Sstevel@tonic-gate void	*packet_get_string(u_int *length_ptr);
877c478bd9Sstevel@tonic-gate char	*packet_get_ascii_cstring();
887c478bd9Sstevel@tonic-gate u_char	*packet_get_utf8_cstring();
897c478bd9Sstevel@tonic-gate void     packet_disconnect(const char *fmt,...) __attribute__((format(printf, 1, 2)));
907c478bd9Sstevel@tonic-gate void     packet_send_debug(const char *fmt,...) __attribute__((format(printf, 1, 2)));
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate void	 set_newkeys(int mode);
93*9a8058b5Sjp161948 void	 free_keys(Newkeys *keys);
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate void     packet_write_poll(void);
967c478bd9Sstevel@tonic-gate void     packet_write_wait(void);
977c478bd9Sstevel@tonic-gate int      packet_have_data_to_write(void);
987c478bd9Sstevel@tonic-gate int      packet_not_very_much_data_to_write(void);
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate int	 packet_connection_is_on_socket(void);
1017c478bd9Sstevel@tonic-gate int	 packet_connection_is_ipv4(void);
1027c478bd9Sstevel@tonic-gate int	 packet_remaining(void);
1037c478bd9Sstevel@tonic-gate void	 packet_send_ignore(int);
1047c478bd9Sstevel@tonic-gate void	 packet_add_padding(u_char);
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate void	 tty_make_modes(int, struct termios *);
1077c478bd9Sstevel@tonic-gate void	 tty_parse_modes(int, int *);
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate extern int max_packet_size;
1107c478bd9Sstevel@tonic-gate int      packet_set_maxsize(int);
1117c478bd9Sstevel@tonic-gate #define  packet_get_maxsize() max_packet_size
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate /* don't allow remaining bytes after the end of the message */
1147c478bd9Sstevel@tonic-gate #define packet_check_eom() \
1157c478bd9Sstevel@tonic-gate do { \
1167c478bd9Sstevel@tonic-gate 	int _len = packet_remaining(); \
1177c478bd9Sstevel@tonic-gate 	if (_len > 0) { \
1187c478bd9Sstevel@tonic-gate 		log("Packet integrity error (%d bytes remaining) at %s:%d", \
1197c478bd9Sstevel@tonic-gate 		    _len ,__FILE__, __LINE__); \
1207c478bd9Sstevel@tonic-gate 		packet_disconnect("Packet integrity error."); \
1217c478bd9Sstevel@tonic-gate 	} \
1227c478bd9Sstevel@tonic-gate } while (0)
1237c478bd9Sstevel@tonic-gate 
124*9a8058b5Sjp161948 int	 packet_need_rekeying(void);
125*9a8058b5Sjp161948 void     packet_set_rekey_limit(u_int32_t);
126*9a8058b5Sjp161948 
1277c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1287c478bd9Sstevel@tonic-gate }
1297c478bd9Sstevel@tonic-gate #endif
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate #endif /* _PACKET_H */
132