42 #define SSH_CHANNEL_X11_LISTENER    1    
   43 #define SSH_CHANNEL_PORT_LISTENER   2    
   44 #define SSH_CHANNEL_OPENING     3    
   45 #define SSH_CHANNEL_OPEN        4    
   46 #define SSH_CHANNEL_CLOSED      5    
   47 #define SSH_CHANNEL_AUTH_SOCKET     6    
   48 #define SSH_CHANNEL_X11_OPEN        7    
   49 #define SSH_CHANNEL_LARVAL      10   
   50 #define SSH_CHANNEL_RPORT_LISTENER  11   
   51 #define SSH_CHANNEL_CONNECTING      12 
   52 #define SSH_CHANNEL_DYNAMIC     13 
   53 #define SSH_CHANNEL_ZOMBIE      14   
   54 #define SSH_CHANNEL_MUX_LISTENER    15   
   55 #define SSH_CHANNEL_MUX_CLIENT      16   
   56 #define SSH_CHANNEL_ABANDONED       17   
   57 #define SSH_CHANNEL_UNIX_LISTENER   18   
   58 #define SSH_CHANNEL_RUNIX_LISTENER  19   
   59 #define SSH_CHANNEL_MUX_PROXY       20   
   60 #define SSH_CHANNEL_RDYNAMIC_OPEN   21   
   61 #define SSH_CHANNEL_RDYNAMIC_FINISH 22   
   62 #define SSH_CHANNEL_MAX_TYPE        23 
   64 #define CHANNEL_CANCEL_PORT_STATIC  -1 
   67 #define CHANNEL_NONBLOCK_LEAVE  0  
   68 #define CHANNEL_NONBLOCK_SET    1  
   69 #define CHANNEL_NONBLOCK_STDIO  2  
   72 #define CHANNEL_RESTORE_RFD 0x01 
   73 #define CHANNEL_RESTORE_WFD 0x02 
   74 #define CHANNEL_RESTORE_EFD 0x04 
   77 #define FORWARD_DENY        0 
   78 #define FORWARD_REMOTE      (1) 
   79 #define FORWARD_LOCAL       (1<<1) 
   80 #define FORWARD_ALLOW       (FORWARD_REMOTE|FORWARD_LOCAL) 
   82 #define FORWARD_ADM     0x100 
   83 #define FORWARD_USER        0x101 
   87 typedef struct Channel Channel;
 
   90 typedef void channel_open_fn(
struct ssh *, 
int, 
int, 
void *);
 
   91 typedef void channel_callback_fn(
struct ssh *, 
int, 
void *);
 
   92 typedef int channel_infilter_fn(
struct ssh *, 
struct Channel *, 
char *, 
int);
 
   93 typedef void channel_filter_cleanup_fn(
struct ssh *, 
int, 
void *);
 
   94 typedef u_char *channel_outfilter_fn(
struct ssh *, 
struct Channel *,
 
   98 typedef void channel_confirm_cb(
struct ssh *, 
int, 
struct Channel *, 
void *);
 
   99 typedef void channel_confirm_abandon_cb(
struct ssh *, 
struct Channel *, 
void *);
 
  100 struct channel_confirm {
 
  101     TAILQ_ENTRY(channel_confirm) entry;
 
  102     channel_confirm_cb *cb;
 
  103     channel_confirm_abandon_cb *abandon_cb;
 
  106 TAILQ_HEAD(channel_confirms, channel_confirm);
 
  109 struct channel_connect {
 
  112     struct addrinfo *ai, *aitop;
 
  116 typedef int mux_callback_fn(
struct ssh *, 
struct Channel *);
 
  153     struct sshbuf *input;   
 
  155     struct sshbuf *output;  
 
  157     struct sshbuf *extended;
 
  162     char   *listening_addr; 
 
  167     u_int   remote_maxpacket;
 
  169     u_int   local_window_max;
 
  170     u_int   local_consumed;
 
  171     u_int   local_maxpacket;
 
  174     int single_connection;
 
  180     channel_open_fn     *open_confirm;
 
  181     void            *open_confirm_ctx;
 
  182     channel_callback_fn *detach_user;
 
  184     struct channel_confirms status_confirms;
 
  187     channel_infilter_fn *input_filter;
 
  188     channel_outfilter_fn    *output_filter;
 
  190     channel_filter_cleanup_fn *filter_cleanup;
 
  197     struct channel_connect  connect_ctx;
 
  200     mux_callback_fn     *mux_rcb;
 
  203     int         mux_downstream_id;
 
  206 #define CHAN_EXTENDED_IGNORE        0 
  207 #define CHAN_EXTENDED_READ      1 
  208 #define CHAN_EXTENDED_WRITE     2 
  211 #define CHAN_SES_PACKET_DEFAULT (32*1024) 
  212 #define CHAN_SES_WINDOW_DEFAULT (64*CHAN_SES_PACKET_DEFAULT) 
  213 #define CHAN_TCP_PACKET_DEFAULT (32*1024) 
  214 #define CHAN_TCP_WINDOW_DEFAULT (64*CHAN_TCP_PACKET_DEFAULT) 
  215 #define CHAN_X11_PACKET_DEFAULT (16*1024) 
  216 #define CHAN_X11_WINDOW_DEFAULT (4*CHAN_X11_PACKET_DEFAULT) 
  219 #define CHAN_INPUT_OPEN         0 
  220 #define CHAN_INPUT_WAIT_DRAIN       1 
  221 #define CHAN_INPUT_WAIT_OCLOSE      2 
  222 #define CHAN_INPUT_CLOSED       3 
  225 #define CHAN_OUTPUT_OPEN        0 
  226 #define CHAN_OUTPUT_WAIT_DRAIN      1 
  227 #define CHAN_OUTPUT_WAIT_IEOF       2 
  228 #define CHAN_OUTPUT_CLOSED      3 
  230 #define CHAN_CLOSE_SENT         0x01 
  231 #define CHAN_CLOSE_RCVD         0x02 
  232 #define CHAN_EOF_SENT           0x04 
  233 #define CHAN_EOF_RCVD           0x08 
  234 #define CHAN_LOCAL          0x10 
  237 #define CHAN_RBUF   CHAN_SES_PACKET_DEFAULT 
  240 #define CHAN_INPUT_MAX  (16*1024*1024) 
  243 #define CHANNELS_MAX_CHANNELS   (16*1024) 
  246 #define CHANNEL_EFD_INPUT_ACTIVE(c) \ 
  247     (c->extended_usage == CHAN_EXTENDED_READ && \ 
  249     sshbuf_len(c->extended) > 0)) 
  250 #define CHANNEL_EFD_OUTPUT_ACTIVE(c) \ 
  251     (c->extended_usage == CHAN_EXTENDED_WRITE && \ 
  252     c->efd != -1 && (!(c->flags & (CHAN_EOF_RCVD|CHAN_CLOSE_RCVD)) || \ 
  253     sshbuf_len(c->extended) > 0)) 
  256 void channel_init_channels(
struct ssh *ssh);
 
  260 Channel *channel_by_id(
struct ssh *, 
int);
 
  261 Channel *channel_by_remote_id(
struct ssh *, u_int);
 
  262 Channel *channel_lookup(
struct ssh *, 
int);
 
  263 Channel *channel_new(
struct ssh *, 
char *, 
int, 
int, 
int, 
int,
 
  264         u_int, u_int, 
int, 
char *, 
int);
 
  265 void     channel_set_fds(
struct ssh *, 
int, 
int, 
int, 
int, 
int,
 
  267 void     channel_free(
struct ssh *, Channel *);
 
  268 void     channel_free_all(
struct ssh *);
 
  269 void     channel_stop_listening(
struct ssh *);
 
  271 void     channel_send_open(
struct ssh *, 
int);
 
  272 void     channel_request_start(
struct ssh *, 
int, 
char *, 
int);
 
  273 void     channel_register_cleanup(
struct ssh *, 
int,
 
  274         channel_callback_fn *, 
int);
 
  275 void     channel_register_open_confirm(
struct ssh *, 
int,
 
  276         channel_open_fn *, 
void *);
 
  277 void     channel_register_filter(
struct ssh *, 
int, channel_infilter_fn *,
 
  278         channel_outfilter_fn *, channel_filter_cleanup_fn *, 
void *);
 
  279 void     channel_register_status_confirm(
struct ssh *, 
int,
 
  280         channel_confirm_cb *, channel_confirm_abandon_cb *, 
void *);
 
  281 void     channel_cancel_cleanup(
struct ssh *, 
int);
 
  282 int  channel_close_fd(
struct ssh *, Channel *, 
int *);
 
  283 void     channel_send_window_changes(
struct ssh *);
 
  287 int  channel_proxy_downstream(
struct ssh *, Channel *mc);
 
  288 int  channel_proxy_upstream(Channel *, 
int, u_int32_t, 
struct ssh *);
 
  292 int  channel_input_data(
int, u_int32_t, 
struct ssh *);
 
  293 int  channel_input_extended_data(
int, u_int32_t, 
struct ssh *);
 
  294 int  channel_input_ieof(
int, u_int32_t, 
struct ssh *);
 
  295 int  channel_input_oclose(
int, u_int32_t, 
struct ssh *);
 
  296 int  channel_input_open_confirmation(
int, u_int32_t, 
struct ssh *);
 
  297 int  channel_input_open_failure(
int, u_int32_t, 
struct ssh *);
 
  298 int  channel_input_port_open(
int, u_int32_t, 
struct ssh *);
 
  299 int  channel_input_window_adjust(
int, u_int32_t, 
struct ssh *);
 
  300 int  channel_input_status_confirm(
int, u_int32_t, 
struct ssh *);
 
  304 void     channel_prepare_select(
struct ssh *, fd_set **, fd_set **, 
int *,
 
  306 void     channel_after_select(
struct ssh *, fd_set *, fd_set *);
 
  307 void     channel_output_poll(
struct ssh *);
 
  309 int      channel_not_very_much_buffered_data(
struct ssh *);
 
  310 void     channel_close_all(
struct ssh *);
 
  311 int      channel_still_open(
struct ssh *);
 
  312 const char *channel_format_extended_usage(
const Channel *);
 
  313 char    *channel_open_message(
struct ssh *);
 
  314 int  channel_find_open(
struct ssh *);
 
  318 struct ForwardOptions;
 
  319 void     channel_set_af(
struct ssh *, 
int af);
 
  320 void     channel_permit_all(
struct ssh *, 
int);
 
  321 void     channel_add_permission(
struct ssh *, 
int, 
int, 
char *, 
int);
 
  322 void     channel_clear_permission(
struct ssh *, 
int, 
int);
 
  323 void     channel_disable_admin(
struct ssh *, 
int);
 
  324 void     channel_update_permission(
struct ssh *, 
int, 
int);
 
  325 Channel *channel_connect_to_port(
struct ssh *, 
const char *, u_short,
 
  326         char *, 
char *, 
int *, 
const char **);
 
  327 Channel *channel_connect_to_path(
struct ssh *, 
const char *, 
char *, 
char *);
 
  328 Channel *channel_connect_stdio_fwd(
struct ssh *, 
const char*,
 
  329         u_short, 
int, 
int, 
int);
 
  330 Channel *channel_connect_by_listen_address(
struct ssh *, 
const char *,
 
  331         u_short, 
char *, 
char *);
 
  332 Channel *channel_connect_by_listen_path(
struct ssh *, 
const char *,
 
  334 int  channel_request_remote_forwarding(
struct ssh *, 
struct Forward *);
 
  335 int  channel_setup_local_fwd_listener(
struct ssh *, 
struct Forward *,
 
  336         struct ForwardOptions *);
 
  337 int  channel_request_rforward_cancel(
struct ssh *, 
struct Forward *);
 
  338 int  channel_setup_remote_fwd_listener(
struct ssh *, 
struct Forward *,
 
  339         int *, 
struct ForwardOptions *);
 
  340 int  channel_cancel_rport_listener(
struct ssh *, 
struct Forward *);
 
  341 int  channel_cancel_lport_listener(
struct ssh *, 
struct Forward *,
 
  342         int, 
struct ForwardOptions *);
 
  343 int  permitopen_port(
const char *);
 
  347 void     channel_set_x11_refuse_time(
struct ssh *, u_int);
 
  348 int  x11_connect_display(
struct ssh *);
 
  349 int  x11_create_display_inet(
struct ssh *, 
int, 
int, 
int, 
int, u_int *, 
int **);
 
  350 void     x11_request_forwarding_with_spoofing(
struct ssh *, 
int,
 
  351         const char *, 
const char *, 
const char *, 
int);
 
  355 int  chan_is_dead(
struct ssh *, Channel *, 
int);
 
  356 void     chan_mark_dead(
struct ssh *, Channel *);
 
  360 void     chan_rcvd_oclose(
struct ssh *, Channel *);
 
  361 void     chan_rcvd_eow(
struct ssh *, Channel *);
 
  362 void     chan_read_failed(
struct ssh *, Channel *);
 
  363 void     chan_ibuf_empty(
struct ssh *, Channel *);
 
  364 void     chan_rcvd_ieof(
struct ssh *, Channel *);
 
  365 void     chan_write_failed(
struct ssh *, Channel *);
 
  366 void     chan_obuf_empty(
struct ssh *, Channel *);
 
  369 void     channel_set_hpn(
int, 
int);