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 2009 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_raw(const void *buf, u_int len);
  63 void     packet_send(void);
  64 
  65 void     packet_put_utf8_string(const char *str, uint_t len);
  66 void     packet_put_utf8_cstring(const char *str);
  67 
  68 int      packet_read(void);
  69 void     packet_read_expect(int type);
  70 int      packet_read_poll(void);
  71 void     packet_process_incoming(const char *buf, u_int len);
  72 int      packet_read_seqnr(u_int32_t *seqnr_p);
  73 int      packet_read_poll_seqnr(u_int32_t *seqnr_p);
  74 
  75 u_int    packet_get_char(void);
  76 u_int    packet_get_int(void);
  77 void     packet_get_bignum(BIGNUM * value);
  78 void     packet_get_bignum2(BIGNUM * value);
  79 void    *packet_get_raw(u_int *length_ptr);
  80 void    *packet_get_string(u_int *length_ptr);
  81 char    *packet_get_utf8_string(uint_t *length_ptr);
  82 void     packet_disconnect(const char *fmt,...) __attribute__((format(printf, 1, 2)));
  83 void     packet_send_debug(const char *fmt,...) __attribute__((format(printf, 1, 2)));
  84 
  85 void     set_newkeys(int mode);
  86 void     free_keys(Newkeys *keys);
  87 
  88 void     packet_write_poll(void);
  89 void     packet_write_wait(void);
  90 int      packet_have_data_to_write(void);
  91 int      packet_not_very_much_data_to_write(void);
  92 
  93 int      packet_connection_is_on_socket(void);
  94 int      packet_connection_is_ipv4(void);
  95 int      packet_remaining(void);
  96 void     packet_send_ignore(int);
  97 void     packet_add_padding(u_char);
  98 
  99 void     tty_make_modes(int, struct termios *);
 100 void     tty_parse_modes(int, int *);
 101 
 102 extern int max_packet_size;
 103 int      packet_set_maxsize(int);
 104 #define  packet_get_maxsize() max_packet_size
 105 
 106 /* don't allow remaining bytes after the end of the message */
 107 #define packet_check_eom() \
 108 do { \
 109         int _len = packet_remaining(); \
 110         if (_len > 0) { \
 111                 log("Packet integrity error (%d bytes remaining) at %s:%d", \
 112                     _len ,__FILE__, __LINE__); \
 113                 packet_disconnect("Packet integrity error."); \
 114         } \
 115 } while (0)
 116 
 117 int      packet_need_rekeying(void);
 118 void     packet_set_rekey_limit(u_int32_t);
 119 
 120 /* see a comment attached to will_daemonize in packet.c for more information */
 121 #define NOT_DAEMONIZING                 0
 122 #define DAEMONIZING_REQUESTED           1
 123 #define FIRST_NEWKEYS_PROCESSED         2
 124 #define SECOND_NEWKEYS_PROCESSED        3
 125 
 126 #ifdef __cplusplus
 127 }
 128 #endif
 129 
 130 #endif /* _PACKET_H */