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,
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 *);
156 int restore_flags[3];
157 struct sshbuf *input;
159 struct sshbuf *output;
161 struct sshbuf *extended;
166 char *listening_addr;
171 u_int remote_maxpacket;
173 u_int local_window_max;
174 u_int local_consumed;
175 u_int local_maxpacket;
178 int single_connection;
185 channel_open_fn *open_confirm;
186 void *open_confirm_ctx;
187 channel_callback_fn *detach_user;
189 struct channel_confirms status_confirms;
192 channel_infilter_fn *input_filter;
193 channel_outfilter_fn *output_filter;
195 channel_filter_cleanup_fn *filter_cleanup;
202 struct channel_connect connect_ctx;
205 mux_callback_fn *mux_rcb;
208 int mux_downstream_id;
215 u_int inactive_deadline;
218 #define CHAN_EXTENDED_IGNORE 0
219 #define CHAN_EXTENDED_READ 1
220 #define CHAN_EXTENDED_WRITE 2
223 #define CHAN_SES_PACKET_DEFAULT (32*1024)
224 #define CHAN_SES_WINDOW_DEFAULT (64*CHAN_SES_PACKET_DEFAULT)
225 #define CHAN_TCP_PACKET_DEFAULT (32*1024)
226 #define CHAN_TCP_WINDOW_DEFAULT (64*CHAN_TCP_PACKET_DEFAULT)
227 #define CHAN_X11_PACKET_DEFAULT (16*1024)
228 #define CHAN_X11_WINDOW_DEFAULT (4*CHAN_X11_PACKET_DEFAULT)
231 #define CHAN_INPUT_OPEN 0
232 #define CHAN_INPUT_WAIT_DRAIN 1
233 #define CHAN_INPUT_WAIT_OCLOSE 2
234 #define CHAN_INPUT_CLOSED 3
237 #define CHAN_OUTPUT_OPEN 0
238 #define CHAN_OUTPUT_WAIT_DRAIN 1
239 #define CHAN_OUTPUT_WAIT_IEOF 2
240 #define CHAN_OUTPUT_CLOSED 3
242 #define CHAN_CLOSE_SENT 0x01
243 #define CHAN_CLOSE_RCVD 0x02
244 #define CHAN_EOF_SENT 0x04
245 #define CHAN_EOF_RCVD 0x08
246 #define CHAN_LOCAL 0x10
249 #define SSH_CHAN_IO_RFD 0x01
250 #define SSH_CHAN_IO_WFD 0x02
251 #define SSH_CHAN_IO_EFD_R 0x04
252 #define SSH_CHAN_IO_EFD_W 0x08
253 #define SSH_CHAN_IO_EFD (SSH_CHAN_IO_EFD_R|SSH_CHAN_IO_EFD_W)
254 #define SSH_CHAN_IO_SOCK_R 0x10
255 #define SSH_CHAN_IO_SOCK_W 0x20
256 #define SSH_CHAN_IO_SOCK (SSH_CHAN_IO_SOCK_R|SSH_CHAN_IO_SOCK_W)
259 #define CHAN_RBUF CHAN_SES_PACKET_DEFAULT
262 #define CHANNEL_MAX_READ CHAN_SES_PACKET_DEFAULT
265 #define CHAN_INPUT_MAX (16*1024*1024)
268 #define CHANNELS_MAX_CHANNELS (16*1024)
271 #define CHANNEL_EFD_INPUT_ACTIVE(c) \
272 (c->extended_usage == CHAN_EXTENDED_READ && \
274 sshbuf_len(c->extended) > 0))
275 #define CHANNEL_EFD_OUTPUT_ACTIVE(c) \
276 (c->extended_usage == CHAN_EXTENDED_WRITE && \
277 c->efd != -1 && (!(c->flags & (CHAN_EOF_RCVD|CHAN_CLOSE_RCVD)) || \
278 sshbuf_len(c->extended) > 0))
281 void channel_init_channels(
struct ssh *ssh);
285 Channel *channel_by_id(
struct ssh *,
int);
286 Channel *channel_by_remote_id(
struct ssh *, u_int);
287 Channel *channel_lookup(
struct ssh *,
int);
288 Channel *channel_new(
struct ssh *,
char *,
int,
int,
int,
int,
289 u_int, u_int,
int,
const char *,
int);
290 void channel_set_fds(
struct ssh *,
int,
int,
int,
int,
int,
292 void channel_free(
struct ssh *, Channel *);
293 void channel_free_all(
struct ssh *);
294 void channel_stop_listening(
struct ssh *);
295 void channel_force_close(
struct ssh *, Channel *,
int);
296 void channel_set_xtype(
struct ssh *,
int,
const char *);
298 void channel_send_open(
struct ssh *,
int);
299 void channel_request_start(
struct ssh *,
int,
char *,
int);
300 void channel_register_cleanup(
struct ssh *,
int,
301 channel_callback_fn *,
int);
302 void channel_register_open_confirm(
struct ssh *,
int,
303 channel_open_fn *,
void *);
304 void channel_register_filter(
struct ssh *,
int, channel_infilter_fn *,
305 channel_outfilter_fn *, channel_filter_cleanup_fn *,
void *);
306 void channel_register_status_confirm(
struct ssh *,
int,
307 channel_confirm_cb *, channel_confirm_abandon_cb *,
void *);
308 void channel_cancel_cleanup(
struct ssh *,
int);
309 int channel_close_fd(
struct ssh *, Channel *,
int *);
310 void channel_send_window_changes(
struct ssh *);
313 void channel_add_timeout(
struct ssh *,
const char *, u_int);
314 void channel_clear_timeouts(
struct ssh *);
318 int channel_proxy_downstream(
struct ssh *, Channel *mc);
319 int channel_proxy_upstream(Channel *,
int, u_int32_t,
struct ssh *);
323 int channel_input_data(
int, u_int32_t,
struct ssh *);
324 int channel_input_extended_data(
int, u_int32_t,
struct ssh *);
325 int channel_input_ieof(
int, u_int32_t,
struct ssh *);
326 int channel_input_oclose(
int, u_int32_t,
struct ssh *);
327 int channel_input_open_confirmation(
int, u_int32_t,
struct ssh *);
328 int channel_input_open_failure(
int, u_int32_t,
struct ssh *);
329 int channel_input_port_open(
int, u_int32_t,
struct ssh *);
330 int channel_input_window_adjust(
int, u_int32_t,
struct ssh *);
331 int channel_input_status_confirm(
int, u_int32_t,
struct ssh *);
337 void channel_prepare_poll(
struct ssh *,
struct pollfd **,
338 u_int *, u_int *, u_int,
struct timespec *);
339 void channel_after_poll(
struct ssh *,
struct pollfd *, u_int);
340 void channel_output_poll(
struct ssh *);
342 int channel_not_very_much_buffered_data(
struct ssh *);
343 void channel_close_all(
struct ssh *);
344 int channel_still_open(
struct ssh *);
345 const char *channel_format_extended_usage(
const Channel *);
346 char *channel_open_message(
struct ssh *);
347 int channel_find_open(
struct ssh *);
351 struct ForwardOptions;
352 void channel_set_af(
struct ssh *,
int af);
353 void channel_permit_all(
struct ssh *,
int);
354 void channel_add_permission(
struct ssh *,
int,
int,
char *,
int);
355 void channel_clear_permission(
struct ssh *,
int,
int);
356 void channel_disable_admin(
struct ssh *,
int);
357 void channel_update_permission(
struct ssh *,
int,
int);
358 Channel *channel_connect_to_port(
struct ssh *,
const char *, u_short,
359 char *,
char *,
int *,
const char **);
360 Channel *channel_connect_to_path(
struct ssh *,
const char *,
char *,
char *);
361 Channel *channel_connect_stdio_fwd(
struct ssh *,
const char*,
362 u_short,
int,
int,
int);
363 Channel *channel_connect_by_listen_address(
struct ssh *,
const char *,
364 u_short,
char *,
char *);
365 Channel *channel_connect_by_listen_path(
struct ssh *,
const char *,
367 int channel_request_remote_forwarding(
struct ssh *,
struct Forward *);
368 int channel_setup_local_fwd_listener(
struct ssh *,
struct Forward *,
369 struct ForwardOptions *);
370 int channel_request_rforward_cancel(
struct ssh *,
struct Forward *);
371 int channel_setup_remote_fwd_listener(
struct ssh *,
struct Forward *,
372 int *,
struct ForwardOptions *);
373 int channel_cancel_rport_listener(
struct ssh *,
struct Forward *);
374 int channel_cancel_lport_listener(
struct ssh *,
struct Forward *,
375 int,
struct ForwardOptions *);
376 int permitopen_port(
const char *);
380 void channel_set_x11_refuse_time(
struct ssh *, time_t);
381 int x11_connect_display(
struct ssh *);
382 int x11_create_display_inet(
struct ssh *,
int,
int,
int,
int, u_int *,
int **);
383 void x11_request_forwarding_with_spoofing(
struct ssh *,
int,
384 const char *,
const char *,
const char *,
int);
388 int chan_is_dead(
struct ssh *, Channel *,
int);
389 void chan_mark_dead(
struct ssh *, Channel *);
393 void chan_rcvd_oclose(
struct ssh *, Channel *);
394 void chan_rcvd_eow(
struct ssh *, Channel *);
395 void chan_read_failed(
struct ssh *, Channel *);
396 void chan_ibuf_empty(
struct ssh *, Channel *);
397 void chan_rcvd_ieof(
struct ssh *, Channel *);
398 void chan_write_failed(
struct ssh *, Channel *);
399 void chan_obuf_empty(
struct ssh *, Channel *);
402 void channel_set_hpn(
int,
int);