summaryrefslogtreecommitdiff
path: root/channels.h
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2017-10-04 11:23:58 +0100
committerColin Watson <cjwatson@debian.org>2017-10-04 11:23:58 +0100
commit62f54f20bf351468e0124f63cc2902ee40d9b0e9 (patch)
tree3e090f2711b94ca5029d3fa3e8047b1ed1448b1f /channels.h
parent6fabaf6fd9b07cc8bc6a17c9c4a5b76849cfc874 (diff)
parent66bf74a92131b7effe49fb0eefe5225151869dc5 (diff)
Import openssh_7.6p1.orig.tar.gz
Diffstat (limited to 'channels.h')
-rw-r--r--channels.h228
1 files changed, 122 insertions, 106 deletions
diff --git a/channels.h b/channels.h
index ce43236d5..126b04345 100644
--- a/channels.h
+++ b/channels.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: channels.h,v 1.121 2017/02/01 02:59:09 dtucker Exp $ */ 1/* $OpenBSD: channels.h,v 1.130 2017/09/21 19:16:53 markus Exp $ */
2 2
3/* 3/*
4 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -46,8 +46,6 @@
46#define SSH_CHANNEL_CLOSED 5 /* waiting for close confirmation */ 46#define SSH_CHANNEL_CLOSED 5 /* waiting for close confirmation */
47#define SSH_CHANNEL_AUTH_SOCKET 6 /* authentication socket */ 47#define SSH_CHANNEL_AUTH_SOCKET 6 /* authentication socket */
48#define SSH_CHANNEL_X11_OPEN 7 /* reading first X11 packet */ 48#define SSH_CHANNEL_X11_OPEN 7 /* reading first X11 packet */
49#define SSH_CHANNEL_INPUT_DRAINING 8 /* sending remaining data to conn */
50#define SSH_CHANNEL_OUTPUT_DRAINING 9 /* sending remaining data to app */
51#define SSH_CHANNEL_LARVAL 10 /* larval session */ 49#define SSH_CHANNEL_LARVAL 10 /* larval session */
52#define SSH_CHANNEL_RPORT_LISTENER 11 /* Listening to a R-style port */ 50#define SSH_CHANNEL_RPORT_LISTENER 11 /* Listening to a R-style port */
53#define SSH_CHANNEL_CONNECTING 12 51#define SSH_CHANNEL_CONNECTING 12
@@ -59,22 +57,27 @@
59#define SSH_CHANNEL_UNIX_LISTENER 18 /* Listening on a domain socket. */ 57#define SSH_CHANNEL_UNIX_LISTENER 18 /* Listening on a domain socket. */
60#define SSH_CHANNEL_RUNIX_LISTENER 19 /* Listening to a R-style domain socket. */ 58#define SSH_CHANNEL_RUNIX_LISTENER 19 /* Listening to a R-style domain socket. */
61#define SSH_CHANNEL_MUX_PROXY 20 /* proxy channel for mux-slave */ 59#define SSH_CHANNEL_MUX_PROXY 20 /* proxy channel for mux-slave */
62#define SSH_CHANNEL_MAX_TYPE 21 60#define SSH_CHANNEL_RDYNAMIC_OPEN 21 /* reverse SOCKS, parsing request */
61#define SSH_CHANNEL_RDYNAMIC_FINISH 22 /* reverse SOCKS, finishing connect */
62#define SSH_CHANNEL_MAX_TYPE 23
63 63
64#define CHANNEL_CANCEL_PORT_STATIC -1 64#define CHANNEL_CANCEL_PORT_STATIC -1
65 65
66struct ssh;
66struct Channel; 67struct Channel;
67typedef struct Channel Channel; 68typedef struct Channel Channel;
69struct fwd_perm_list;
68 70
69typedef void channel_open_fn(int, int, void *); 71typedef void channel_open_fn(struct ssh *, int, int, void *);
70typedef void channel_callback_fn(int, void *); 72typedef void channel_callback_fn(struct ssh *, int, void *);
71typedef int channel_infilter_fn(struct Channel *, char *, int); 73typedef int channel_infilter_fn(struct ssh *, struct Channel *, char *, int);
72typedef void channel_filter_cleanup_fn(int, void *); 74typedef void channel_filter_cleanup_fn(struct ssh *, int, void *);
73typedef u_char *channel_outfilter_fn(struct Channel *, u_char **, u_int *); 75typedef u_char *channel_outfilter_fn(struct ssh *, struct Channel *,
76 u_char **, size_t *);
74 77
75/* Channel success/failure callbacks */ 78/* Channel success/failure callbacks */
76typedef void channel_confirm_cb(int, struct Channel *, void *); 79typedef void channel_confirm_cb(struct ssh *, int, struct Channel *, void *);
77typedef void channel_confirm_abandon_cb(struct Channel *, void *); 80typedef void channel_confirm_abandon_cb(struct ssh *, struct Channel *, void *);
78struct channel_confirm { 81struct channel_confirm {
79 TAILQ_ENTRY(channel_confirm) entry; 82 TAILQ_ENTRY(channel_confirm) entry;
80 channel_confirm_cb *cb; 83 channel_confirm_cb *cb;
@@ -91,12 +94,14 @@ struct channel_connect {
91}; 94};
92 95
93/* Callbacks for mux channels back into client-specific code */ 96/* Callbacks for mux channels back into client-specific code */
94typedef int mux_callback_fn(struct Channel *); 97typedef int mux_callback_fn(struct ssh *, struct Channel *);
95 98
96struct Channel { 99struct Channel {
97 int type; /* channel type/state */ 100 int type; /* channel type/state */
98 int self; /* my own channel identifier */ 101 int self; /* my own channel identifier */
99 int remote_id; /* channel identifier for remote peer */ 102 uint32_t remote_id; /* channel identifier for remote peer */
103 int have_remote_id; /* non-zero if remote_id is valid */
104
100 u_int istate; /* input from channel (state of receive half) */ 105 u_int istate; /* input from channel (state of receive half) */
101 u_int ostate; /* output to channel (state of transmit half) */ 106 u_int ostate; /* output to channel (state of transmit half) */
102 int flags; /* close sent/rcvd */ 107 int flags; /* close sent/rcvd */
@@ -117,11 +122,12 @@ struct Channel {
117 * to a matching pre-select handler. 122 * to a matching pre-select handler.
118 * this way post-select handlers are not 123 * this way post-select handlers are not
119 * accidentally called if a FD gets reused */ 124 * accidentally called if a FD gets reused */
120 Buffer input; /* data read from socket, to be sent over 125 struct sshbuf *input; /* data read from socket, to be sent over
121 * encrypted connection */ 126 * encrypted connection */
122 Buffer output; /* data received over encrypted connection for 127 struct sshbuf *output; /* data received over encrypted connection for
123 * send on socket */ 128 * send on socket */
124 Buffer extended; 129 struct sshbuf *extended;
130
125 char *path; 131 char *path;
126 /* path for unix domain sockets, or host name for forwards */ 132 /* path for unix domain sockets, or host name for forwards */
127 int listening_port; /* port being listened for forwards */ 133 int listening_port; /* port being listened for forwards */
@@ -157,6 +163,7 @@ struct Channel {
157 int datagram; 163 int datagram;
158 164
159 /* non-blocking connect */ 165 /* non-blocking connect */
166 /* XXX make this a pointer so the structure can be opaque */
160 struct channel_connect connect_ctx; 167 struct channel_connect connect_ctx;
161 168
162 /* multiplexing protocol hook, called for each packet received */ 169 /* multiplexing protocol hook, called for each packet received */
@@ -196,128 +203,137 @@ struct Channel {
196#define CHAN_EOF_RCVD 0x08 203#define CHAN_EOF_RCVD 0x08
197#define CHAN_LOCAL 0x10 204#define CHAN_LOCAL 0x10
198 205
199#define CHAN_RBUF 16*1024 206/* Read buffer size */
207#define CHAN_RBUF (16*1024)
208
209/* Hard limit on number of channels */
210#define CHANNELS_MAX_CHANNELS (16*1024)
200 211
201/* check whether 'efd' is still in use */ 212/* check whether 'efd' is still in use */
202#define CHANNEL_EFD_INPUT_ACTIVE(c) \ 213#define CHANNEL_EFD_INPUT_ACTIVE(c) \
203 (compat20 && c->extended_usage == CHAN_EXTENDED_READ && \ 214 (c->extended_usage == CHAN_EXTENDED_READ && \
204 (c->efd != -1 || \ 215 (c->efd != -1 || \
205 buffer_len(&c->extended) > 0)) 216 sshbuf_len(c->extended) > 0))
206#define CHANNEL_EFD_OUTPUT_ACTIVE(c) \ 217#define CHANNEL_EFD_OUTPUT_ACTIVE(c) \
207 (compat20 && c->extended_usage == CHAN_EXTENDED_WRITE && \ 218 (c->extended_usage == CHAN_EXTENDED_WRITE && \
208 c->efd != -1 && (!(c->flags & (CHAN_EOF_RCVD|CHAN_CLOSE_RCVD)) || \ 219 c->efd != -1 && (!(c->flags & (CHAN_EOF_RCVD|CHAN_CLOSE_RCVD)) || \
209 buffer_len(&c->extended) > 0)) 220 sshbuf_len(c->extended) > 0))
221
222/* Add channel management structures to SSH transport instance */
223void channel_init_channels(struct ssh *ssh);
210 224
211/* channel management */ 225/* channel management */
212 226
213Channel *channel_by_id(int); 227Channel *channel_by_id(struct ssh *, int);
214Channel *channel_by_remote_id(int); 228Channel *channel_by_remote_id(struct ssh *, u_int);
215Channel *channel_lookup(int); 229Channel *channel_lookup(struct ssh *, int);
216Channel *channel_new(char *, int, int, int, int, u_int, u_int, int, char *, int); 230Channel *channel_new(struct ssh *, char *, int, int, int, int,
217void channel_set_fds(int, int, int, int, int, int, int, u_int); 231 u_int, u_int, int, char *, int);
218void channel_free(Channel *); 232void channel_set_fds(struct ssh *, int, int, int, int, int,
219void channel_free_all(void); 233 int, int, u_int);
220void channel_stop_listening(void); 234void channel_free(struct ssh *, Channel *);
221 235void channel_free_all(struct ssh *);
222void channel_send_open(int); 236void channel_stop_listening(struct ssh *);
223void channel_request_start(int, char *, int); 237
224void channel_register_cleanup(int, channel_callback_fn *, int); 238void channel_send_open(struct ssh *, int);
225void channel_register_open_confirm(int, channel_open_fn *, void *); 239void channel_request_start(struct ssh *, int, char *, int);
226void channel_register_filter(int, channel_infilter_fn *, 240void channel_register_cleanup(struct ssh *, int,
227 channel_outfilter_fn *, channel_filter_cleanup_fn *, void *); 241 channel_callback_fn *, int);
228void channel_register_status_confirm(int, channel_confirm_cb *, 242void channel_register_open_confirm(struct ssh *, int,
229 channel_confirm_abandon_cb *, void *); 243 channel_open_fn *, void *);
230void channel_cancel_cleanup(int); 244void channel_register_filter(struct ssh *, int, channel_infilter_fn *,
231int channel_close_fd(int *); 245 channel_outfilter_fn *, channel_filter_cleanup_fn *, void *);
232void channel_send_window_changes(void); 246void channel_register_status_confirm(struct ssh *, int,
247 channel_confirm_cb *, channel_confirm_abandon_cb *, void *);
248void channel_cancel_cleanup(struct ssh *, int);
249int channel_close_fd(struct ssh *, int *);
250void channel_send_window_changes(struct ssh *);
233 251
234/* mux proxy support */ 252/* mux proxy support */
235 253
236int channel_proxy_downstream(Channel *mc); 254int channel_proxy_downstream(struct ssh *, Channel *mc);
237int channel_proxy_upstream(Channel *, int, u_int32_t, void *); 255int channel_proxy_upstream(Channel *, int, u_int32_t, struct ssh *);
238 256
239/* protocol handler */ 257/* protocol handler */
240 258
241int channel_input_close(int, u_int32_t, void *); 259int channel_input_data(int, u_int32_t, struct ssh *);
242int channel_input_close_confirmation(int, u_int32_t, void *); 260int channel_input_extended_data(int, u_int32_t, struct ssh *);
243int channel_input_data(int, u_int32_t, void *); 261int channel_input_ieof(int, u_int32_t, struct ssh *);
244int channel_input_extended_data(int, u_int32_t, void *); 262int channel_input_oclose(int, u_int32_t, struct ssh *);
245int channel_input_ieof(int, u_int32_t, void *); 263int channel_input_open_confirmation(int, u_int32_t, struct ssh *);
246int channel_input_oclose(int, u_int32_t, void *); 264int channel_input_open_failure(int, u_int32_t, struct ssh *);
247int channel_input_open_confirmation(int, u_int32_t, void *); 265int channel_input_port_open(int, u_int32_t, struct ssh *);
248int channel_input_open_failure(int, u_int32_t, void *); 266int channel_input_window_adjust(int, u_int32_t, struct ssh *);
249int channel_input_port_open(int, u_int32_t, void *); 267int channel_input_status_confirm(int, u_int32_t, struct ssh *);
250int channel_input_window_adjust(int, u_int32_t, void *);
251int channel_input_status_confirm(int, u_int32_t, void *);
252 268
253/* file descriptor handling (read/write) */ 269/* file descriptor handling (read/write) */
254 270
255void channel_prepare_select(fd_set **, fd_set **, int *, u_int*, 271void channel_prepare_select(struct ssh *, fd_set **, fd_set **, int *,
256 time_t*, int); 272 u_int*, time_t*);
257void channel_after_select(fd_set *, fd_set *); 273void channel_after_select(struct ssh *, fd_set *, fd_set *);
258void channel_output_poll(void); 274void channel_output_poll(struct ssh *);
259 275
260int channel_not_very_much_buffered_data(void); 276int channel_not_very_much_buffered_data(struct ssh *);
261void channel_close_all(void); 277void channel_close_all(struct ssh *);
262int channel_still_open(void); 278int channel_still_open(struct ssh *);
263char *channel_open_message(void); 279char *channel_open_message(struct ssh *);
264int channel_find_open(void); 280int channel_find_open(struct ssh *);
265 281
266/* tcp forwarding */ 282/* tcp forwarding */
267struct Forward; 283struct Forward;
268struct ForwardOptions; 284struct ForwardOptions;
269void channel_set_af(int af); 285void channel_set_af(struct ssh *, int af);
270void channel_permit_all_opens(void); 286void channel_permit_all_opens(struct ssh *);
271void channel_add_permitted_opens(char *, int); 287void channel_add_permitted_opens(struct ssh *, char *, int);
272int channel_add_adm_permitted_opens(char *, int); 288int channel_add_adm_permitted_opens(struct ssh *, char *, int);
273void channel_disable_adm_local_opens(void); 289void channel_copy_adm_permitted_opens(struct ssh *,
274void channel_update_permitted_opens(int, int); 290 const struct fwd_perm_list *);
275void channel_clear_permitted_opens(void); 291void channel_disable_adm_local_opens(struct ssh *);
276void channel_clear_adm_permitted_opens(void); 292void channel_update_permitted_opens(struct ssh *, int, int);
277void channel_print_adm_permitted_opens(void); 293void channel_clear_permitted_opens(struct ssh *);
278Channel *channel_connect_to_port(const char *, u_short, char *, char *, int *, 294void channel_clear_adm_permitted_opens(struct ssh *);
279 const char **); 295void channel_print_adm_permitted_opens(struct ssh *);
280Channel *channel_connect_to_path(const char *, char *, char *); 296Channel *channel_connect_to_port(struct ssh *, const char *, u_short,
281Channel *channel_connect_stdio_fwd(const char*, u_short, int, int); 297 char *, char *, int *, const char **);
282Channel *channel_connect_by_listen_address(const char *, u_short, 298Channel *channel_connect_to_path(struct ssh *, const char *, char *, char *);
283 char *, char *); 299Channel *channel_connect_stdio_fwd(struct ssh *, const char*,
284Channel *channel_connect_by_listen_path(const char *, char *, char *); 300 u_short, int, int);
285int channel_request_remote_forwarding(struct Forward *); 301Channel *channel_connect_by_listen_address(struct ssh *, const char *,
286int channel_setup_local_fwd_listener(struct Forward *, struct ForwardOptions *); 302 u_short, char *, char *);
287int channel_request_rforward_cancel(struct Forward *); 303Channel *channel_connect_by_listen_path(struct ssh *, const char *,
288int channel_setup_remote_fwd_listener(struct Forward *, int *, struct ForwardOptions *); 304 char *, char *);
289int channel_cancel_rport_listener(struct Forward *); 305int channel_request_remote_forwarding(struct ssh *, struct Forward *);
290int channel_cancel_lport_listener(struct Forward *, int, struct ForwardOptions *); 306int channel_setup_local_fwd_listener(struct ssh *, struct Forward *,
307 struct ForwardOptions *);
308int channel_request_rforward_cancel(struct ssh *, struct Forward *);
309int channel_setup_remote_fwd_listener(struct ssh *, struct Forward *,
310 int *, struct ForwardOptions *);
311int channel_cancel_rport_listener(struct ssh *, struct Forward *);
312int channel_cancel_lport_listener(struct ssh *, struct Forward *,
313 int, struct ForwardOptions *);
291int permitopen_port(const char *); 314int permitopen_port(const char *);
292 315
293/* x11 forwarding */ 316/* x11 forwarding */
294 317
295void channel_set_x11_refuse_time(u_int); 318void channel_set_x11_refuse_time(struct ssh *, u_int);
296int x11_connect_display(void); 319int x11_connect_display(struct ssh *);
297int x11_create_display_inet(int, int, int, u_int *, int **); 320int x11_create_display_inet(struct ssh *, int, int, int, u_int *, int **);
298int x11_input_open(int, u_int32_t, void *); 321void x11_request_forwarding_with_spoofing(struct ssh *, int,
299void x11_request_forwarding_with_spoofing(int, const char *, const char *, 322 const char *, const char *, const char *, int);
300 const char *, int);
301int deny_input_open(int, u_int32_t, void *);
302
303/* agent forwarding */
304
305void auth_request_forwarding(void);
306 323
307/* channel close */ 324/* channel close */
308 325
309int chan_is_dead(Channel *, int); 326int chan_is_dead(struct ssh *, Channel *, int);
310void chan_mark_dead(Channel *); 327void chan_mark_dead(struct ssh *, Channel *);
311 328
312/* channel events */ 329/* channel events */
313 330
314void chan_rcvd_oclose(Channel *); 331void chan_rcvd_oclose(struct ssh *, Channel *);
315void chan_rcvd_eow(Channel *); /* SSH2-only */ 332void chan_rcvd_eow(struct ssh *, Channel *);
316void chan_read_failed(Channel *); 333void chan_read_failed(struct ssh *, Channel *);
317void chan_ibuf_empty(Channel *); 334void chan_ibuf_empty(struct ssh *, Channel *);
318 335void chan_rcvd_ieof(struct ssh *, Channel *);
319void chan_rcvd_ieof(Channel *); 336void chan_write_failed(struct ssh *, Channel *);
320void chan_write_failed(Channel *); 337void chan_obuf_empty(struct ssh *, Channel *);
321void chan_obuf_empty(Channel *);
322 338
323#endif 339#endif