00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef CHANNEL_H
00039 #define CHANNEL_H
00040
00041 #include "buffer.h"
00042
00043
00044 #define SSH_CHANNEL_X11_LISTENER 1
00045 #define SSH_CHANNEL_PORT_LISTENER 2
00046 #define SSH_CHANNEL_OPENING 3
00047 #define SSH_CHANNEL_OPEN 4
00048 #define SSH_CHANNEL_CLOSED 5
00049 #define SSH_CHANNEL_AUTH_SOCKET 6
00050 #define SSH_CHANNEL_X11_OPEN 7
00051 #define SSH_CHANNEL_INPUT_DRAINING 8
00052 #define SSH_CHANNEL_OUTPUT_DRAINING 9
00053 #define SSH_CHANNEL_LARVAL 10
00054 #define SSH_CHANNEL_RPORT_LISTENER 11
00055 #define SSH_CHANNEL_CONNECTING 12
00056 #define SSH_CHANNEL_DYNAMIC 13
00057 #define SSH_CHANNEL_ZOMBIE 14
00058 #define SSH_CHANNEL_MAX_TYPE 15
00059
00060 #define SSH_CHANNEL_PATH_LEN 256
00061
00062 struct Channel;
00063 typedef struct Channel Channel;
00064
00065 typedef void channel_callback_fn(int, void *);
00066 typedef int channel_infilter_fn(struct Channel *, char *, int);
00067 typedef u_char *channel_outfilter_fn(struct Channel *, u_char **, u_int *);
00068
00069 struct Channel {
00070 int type;
00071 int self;
00072 int remote_id;
00073 u_int istate;
00074 u_int ostate;
00075 int flags;
00076 int rfd;
00077 int wfd;
00078 int efd;
00079 int sock;
00080 int ctl_fd;
00081 int isatty;
00082 int wfd_isatty;
00083 int client_tty;
00084 int force_drain;
00085 int delayed;
00086 Buffer input;
00087
00088 Buffer output;
00089
00090 Buffer extended;
00091 char path[SSH_CHANNEL_PATH_LEN];
00092
00093 int listening_port;
00094 int host_port;
00095 char *remote_name;
00096
00097 u_int remote_window;
00098 u_int remote_maxpacket;
00099 u_int local_window;
00100 u_int local_window_max;
00101 u_int local_consumed;
00102 u_int local_maxpacket;
00103 int extended_usage;
00104 int single_connection;
00105
00106 char *ctype;
00107
00108
00109 channel_callback_fn *confirm;
00110 void *confirm_ctx;
00111 channel_callback_fn *detach_user;
00112 int detach_close;
00113
00114
00115 channel_infilter_fn *input_filter;
00116 channel_outfilter_fn *output_filter;
00117
00118 int datagram;
00119 };
00120
00121 #define CHAN_EXTENDED_IGNORE 0
00122 #define CHAN_EXTENDED_READ 1
00123 #define CHAN_EXTENDED_WRITE 2
00124
00125
00126 #define CHAN_SES_PACKET_DEFAULT (32*1024)
00127 #define CHAN_SES_WINDOW_DEFAULT (4*CHAN_SES_PACKET_DEFAULT)
00128 #define CHAN_TCP_PACKET_DEFAULT (32*1024)
00129 #define CHAN_TCP_WINDOW_DEFAULT (4*CHAN_TCP_PACKET_DEFAULT)
00130 #define CHAN_X11_PACKET_DEFAULT (16*1024)
00131 #define CHAN_X11_WINDOW_DEFAULT (4*CHAN_X11_PACKET_DEFAULT)
00132
00133
00134 #define CHAN_INPUT_OPEN 0
00135 #define CHAN_INPUT_WAIT_DRAIN 1
00136 #define CHAN_INPUT_WAIT_OCLOSE 2
00137 #define CHAN_INPUT_CLOSED 3
00138
00139
00140 #define CHAN_OUTPUT_OPEN 0
00141 #define CHAN_OUTPUT_WAIT_DRAIN 1
00142 #define CHAN_OUTPUT_WAIT_IEOF 2
00143 #define CHAN_OUTPUT_CLOSED 3
00144
00145 #define CHAN_CLOSE_SENT 0x01
00146 #define CHAN_CLOSE_RCVD 0x02
00147 #define CHAN_EOF_SENT 0x04
00148 #define CHAN_EOF_RCVD 0x08
00149
00150 #define CHAN_RBUF 16*1024
00151
00152
00153 #define CHANNEL_EFD_INPUT_ACTIVE(c) \
00154 (compat20 && c->extended_usage == CHAN_EXTENDED_READ && \
00155 (c->efd != -1 || \
00156 buffer_len(&c->extended) > 0))
00157 #define CHANNEL_EFD_OUTPUT_ACTIVE(c) \
00158 (compat20 && c->extended_usage == CHAN_EXTENDED_WRITE && \
00159 c->efd != -1 && (!(c->flags & (CHAN_EOF_RCVD|CHAN_CLOSE_RCVD)) || \
00160 buffer_len(&c->extended) > 0))
00161
00162
00163
00164 Channel *channel_by_id(int);
00165 Channel *channel_lookup(int);
00166 Channel *channel_new(char *, int, int, int, int, u_int, u_int, int, char *, int);
00167 void channel_set_fds(int, int, int, int, int, int, u_int);
00168 void channel_free(Channel *);
00169 void channel_free_all(void);
00170 void channel_stop_listening(void);
00171
00172 void channel_send_open(int);
00173 void channel_request_start(int, char *, int);
00174 void channel_register_cleanup(int, channel_callback_fn *, int);
00175 void channel_register_confirm(int, channel_callback_fn *, void *);
00176 void channel_register_filter(int, channel_infilter_fn *, channel_outfilter_fn *);
00177 void channel_cancel_cleanup(int);
00178 int channel_close_fd(int *);
00179 void channel_send_window_changes(void);
00180
00181
00182
00183 void channel_input_close(int, u_int32_t, void *);
00184 void channel_input_close_confirmation(int, u_int32_t, void *);
00185 void channel_input_data(int, u_int32_t, void *);
00186 void channel_input_extended_data(int, u_int32_t, void *);
00187 void channel_input_ieof(int, u_int32_t, void *);
00188 void channel_input_oclose(int, u_int32_t, void *);
00189 void channel_input_open_confirmation(int, u_int32_t, void *);
00190 void channel_input_open_failure(int, u_int32_t, void *);
00191 void channel_input_port_open(int, u_int32_t, void *);
00192 void channel_input_window_adjust(int, u_int32_t, void *);
00193
00194
00195
00196 void channel_prepare_select(fd_set **, fd_set **, int *, u_int*, int);
00197 void channel_after_select(fd_set *, fd_set *);
00198 void channel_output_poll(void);
00199
00200 int channel_not_very_much_buffered_data(void);
00201 void channel_close_all(void);
00202 int channel_still_open(void);
00203 char *channel_open_message(void);
00204 int channel_find_open(void);
00205
00206
00207 void channel_set_af(int af);
00208 void channel_permit_all_opens(void);
00209 void channel_add_permitted_opens(char *, int);
00210 void channel_clear_permitted_opens(void);
00211 void channel_input_port_forward_request(int, int);
00212 int channel_connect_to(const char *, u_short);
00213 int channel_connect_by_listen_address(u_short);
00214 void channel_request_remote_forwarding(const char *, u_short,
00215 const char *, u_short);
00216 int channel_setup_local_fwd_listener(const char *, u_short,
00217 const char *, u_short, int);
00218 void channel_request_rforward_cancel(const char *host, u_short port);
00219 int channel_setup_remote_fwd_listener(const char *, u_short, int);
00220 int channel_cancel_rport_listener(const char *, u_short);
00221
00222
00223
00224 int x11_connect_display(void);
00225 int x11_create_display_inet(int, int, int, u_int *, int **);
00226 void x11_input_open(int, u_int32_t, void *);
00227 void x11_request_forwarding_with_spoofing(int, const char *, const char *,
00228 const char *);
00229 void deny_input_open(int, u_int32_t, void *);
00230
00231
00232
00233 void auth_request_forwarding(void);
00234
00235
00236
00237 int chan_is_dead(Channel *, int);
00238 void chan_mark_dead(Channel *);
00239
00240
00241
00242 void chan_rcvd_oclose(Channel *);
00243 void chan_read_failed(Channel *);
00244 void chan_ibuf_empty(Channel *);
00245
00246 void chan_rcvd_ieof(Channel *);
00247 void chan_write_failed(Channel *);
00248 void chan_obuf_empty(Channel *);
00249
00250 #endif