diff options
Diffstat (limited to 'channels.h')
-rw-r--r-- | channels.h | 228 |
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 | ||
66 | struct ssh; | ||
66 | struct Channel; | 67 | struct Channel; |
67 | typedef struct Channel Channel; | 68 | typedef struct Channel Channel; |
69 | struct fwd_perm_list; | ||
68 | 70 | ||
69 | typedef void channel_open_fn(int, int, void *); | 71 | typedef void channel_open_fn(struct ssh *, int, int, void *); |
70 | typedef void channel_callback_fn(int, void *); | 72 | typedef void channel_callback_fn(struct ssh *, int, void *); |
71 | typedef int channel_infilter_fn(struct Channel *, char *, int); | 73 | typedef int channel_infilter_fn(struct ssh *, struct Channel *, char *, int); |
72 | typedef void channel_filter_cleanup_fn(int, void *); | 74 | typedef void channel_filter_cleanup_fn(struct ssh *, int, void *); |
73 | typedef u_char *channel_outfilter_fn(struct Channel *, u_char **, u_int *); | 75 | typedef 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 */ |
76 | typedef void channel_confirm_cb(int, struct Channel *, void *); | 79 | typedef void channel_confirm_cb(struct ssh *, int, struct Channel *, void *); |
77 | typedef void channel_confirm_abandon_cb(struct Channel *, void *); | 80 | typedef void channel_confirm_abandon_cb(struct ssh *, struct Channel *, void *); |
78 | struct channel_confirm { | 81 | struct 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 */ |
94 | typedef int mux_callback_fn(struct Channel *); | 97 | typedef int mux_callback_fn(struct ssh *, struct Channel *); |
95 | 98 | ||
96 | struct Channel { | 99 | struct 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 */ | ||
223 | void channel_init_channels(struct ssh *ssh); | ||
210 | 224 | ||
211 | /* channel management */ | 225 | /* channel management */ |
212 | 226 | ||
213 | Channel *channel_by_id(int); | 227 | Channel *channel_by_id(struct ssh *, int); |
214 | Channel *channel_by_remote_id(int); | 228 | Channel *channel_by_remote_id(struct ssh *, u_int); |
215 | Channel *channel_lookup(int); | 229 | Channel *channel_lookup(struct ssh *, int); |
216 | Channel *channel_new(char *, int, int, int, int, u_int, u_int, int, char *, int); | 230 | Channel *channel_new(struct ssh *, char *, int, int, int, int, |
217 | void channel_set_fds(int, int, int, int, int, int, int, u_int); | 231 | u_int, u_int, int, char *, int); |
218 | void channel_free(Channel *); | 232 | void channel_set_fds(struct ssh *, int, int, int, int, int, |
219 | void channel_free_all(void); | 233 | int, int, u_int); |
220 | void channel_stop_listening(void); | 234 | void channel_free(struct ssh *, Channel *); |
221 | 235 | void channel_free_all(struct ssh *); | |
222 | void channel_send_open(int); | 236 | void channel_stop_listening(struct ssh *); |
223 | void channel_request_start(int, char *, int); | 237 | |
224 | void channel_register_cleanup(int, channel_callback_fn *, int); | 238 | void channel_send_open(struct ssh *, int); |
225 | void channel_register_open_confirm(int, channel_open_fn *, void *); | 239 | void channel_request_start(struct ssh *, int, char *, int); |
226 | void channel_register_filter(int, channel_infilter_fn *, | 240 | void channel_register_cleanup(struct ssh *, int, |
227 | channel_outfilter_fn *, channel_filter_cleanup_fn *, void *); | 241 | channel_callback_fn *, int); |
228 | void channel_register_status_confirm(int, channel_confirm_cb *, | 242 | void channel_register_open_confirm(struct ssh *, int, |
229 | channel_confirm_abandon_cb *, void *); | 243 | channel_open_fn *, void *); |
230 | void channel_cancel_cleanup(int); | 244 | void channel_register_filter(struct ssh *, int, channel_infilter_fn *, |
231 | int channel_close_fd(int *); | 245 | channel_outfilter_fn *, channel_filter_cleanup_fn *, void *); |
232 | void channel_send_window_changes(void); | 246 | void channel_register_status_confirm(struct ssh *, int, |
247 | channel_confirm_cb *, channel_confirm_abandon_cb *, void *); | ||
248 | void channel_cancel_cleanup(struct ssh *, int); | ||
249 | int channel_close_fd(struct ssh *, int *); | ||
250 | void channel_send_window_changes(struct ssh *); | ||
233 | 251 | ||
234 | /* mux proxy support */ | 252 | /* mux proxy support */ |
235 | 253 | ||
236 | int channel_proxy_downstream(Channel *mc); | 254 | int channel_proxy_downstream(struct ssh *, Channel *mc); |
237 | int channel_proxy_upstream(Channel *, int, u_int32_t, void *); | 255 | int channel_proxy_upstream(Channel *, int, u_int32_t, struct ssh *); |
238 | 256 | ||
239 | /* protocol handler */ | 257 | /* protocol handler */ |
240 | 258 | ||
241 | int channel_input_close(int, u_int32_t, void *); | 259 | int channel_input_data(int, u_int32_t, struct ssh *); |
242 | int channel_input_close_confirmation(int, u_int32_t, void *); | 260 | int channel_input_extended_data(int, u_int32_t, struct ssh *); |
243 | int channel_input_data(int, u_int32_t, void *); | 261 | int channel_input_ieof(int, u_int32_t, struct ssh *); |
244 | int channel_input_extended_data(int, u_int32_t, void *); | 262 | int channel_input_oclose(int, u_int32_t, struct ssh *); |
245 | int channel_input_ieof(int, u_int32_t, void *); | 263 | int channel_input_open_confirmation(int, u_int32_t, struct ssh *); |
246 | int channel_input_oclose(int, u_int32_t, void *); | 264 | int channel_input_open_failure(int, u_int32_t, struct ssh *); |
247 | int channel_input_open_confirmation(int, u_int32_t, void *); | 265 | int channel_input_port_open(int, u_int32_t, struct ssh *); |
248 | int channel_input_open_failure(int, u_int32_t, void *); | 266 | int channel_input_window_adjust(int, u_int32_t, struct ssh *); |
249 | int channel_input_port_open(int, u_int32_t, void *); | 267 | int channel_input_status_confirm(int, u_int32_t, struct ssh *); |
250 | int channel_input_window_adjust(int, u_int32_t, void *); | ||
251 | int 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 | ||
255 | void channel_prepare_select(fd_set **, fd_set **, int *, u_int*, | 271 | void channel_prepare_select(struct ssh *, fd_set **, fd_set **, int *, |
256 | time_t*, int); | 272 | u_int*, time_t*); |
257 | void channel_after_select(fd_set *, fd_set *); | 273 | void channel_after_select(struct ssh *, fd_set *, fd_set *); |
258 | void channel_output_poll(void); | 274 | void channel_output_poll(struct ssh *); |
259 | 275 | ||
260 | int channel_not_very_much_buffered_data(void); | 276 | int channel_not_very_much_buffered_data(struct ssh *); |
261 | void channel_close_all(void); | 277 | void channel_close_all(struct ssh *); |
262 | int channel_still_open(void); | 278 | int channel_still_open(struct ssh *); |
263 | char *channel_open_message(void); | 279 | char *channel_open_message(struct ssh *); |
264 | int channel_find_open(void); | 280 | int channel_find_open(struct ssh *); |
265 | 281 | ||
266 | /* tcp forwarding */ | 282 | /* tcp forwarding */ |
267 | struct Forward; | 283 | struct Forward; |
268 | struct ForwardOptions; | 284 | struct ForwardOptions; |
269 | void channel_set_af(int af); | 285 | void channel_set_af(struct ssh *, int af); |
270 | void channel_permit_all_opens(void); | 286 | void channel_permit_all_opens(struct ssh *); |
271 | void channel_add_permitted_opens(char *, int); | 287 | void channel_add_permitted_opens(struct ssh *, char *, int); |
272 | int channel_add_adm_permitted_opens(char *, int); | 288 | int channel_add_adm_permitted_opens(struct ssh *, char *, int); |
273 | void channel_disable_adm_local_opens(void); | 289 | void channel_copy_adm_permitted_opens(struct ssh *, |
274 | void channel_update_permitted_opens(int, int); | 290 | const struct fwd_perm_list *); |
275 | void channel_clear_permitted_opens(void); | 291 | void channel_disable_adm_local_opens(struct ssh *); |
276 | void channel_clear_adm_permitted_opens(void); | 292 | void channel_update_permitted_opens(struct ssh *, int, int); |
277 | void channel_print_adm_permitted_opens(void); | 293 | void channel_clear_permitted_opens(struct ssh *); |
278 | Channel *channel_connect_to_port(const char *, u_short, char *, char *, int *, | 294 | void channel_clear_adm_permitted_opens(struct ssh *); |
279 | const char **); | 295 | void channel_print_adm_permitted_opens(struct ssh *); |
280 | Channel *channel_connect_to_path(const char *, char *, char *); | 296 | Channel *channel_connect_to_port(struct ssh *, const char *, u_short, |
281 | Channel *channel_connect_stdio_fwd(const char*, u_short, int, int); | 297 | char *, char *, int *, const char **); |
282 | Channel *channel_connect_by_listen_address(const char *, u_short, | 298 | Channel *channel_connect_to_path(struct ssh *, const char *, char *, char *); |
283 | char *, char *); | 299 | Channel *channel_connect_stdio_fwd(struct ssh *, const char*, |
284 | Channel *channel_connect_by_listen_path(const char *, char *, char *); | 300 | u_short, int, int); |
285 | int channel_request_remote_forwarding(struct Forward *); | 301 | Channel *channel_connect_by_listen_address(struct ssh *, const char *, |
286 | int channel_setup_local_fwd_listener(struct Forward *, struct ForwardOptions *); | 302 | u_short, char *, char *); |
287 | int channel_request_rforward_cancel(struct Forward *); | 303 | Channel *channel_connect_by_listen_path(struct ssh *, const char *, |
288 | int channel_setup_remote_fwd_listener(struct Forward *, int *, struct ForwardOptions *); | 304 | char *, char *); |
289 | int channel_cancel_rport_listener(struct Forward *); | 305 | int channel_request_remote_forwarding(struct ssh *, struct Forward *); |
290 | int channel_cancel_lport_listener(struct Forward *, int, struct ForwardOptions *); | 306 | int channel_setup_local_fwd_listener(struct ssh *, struct Forward *, |
307 | struct ForwardOptions *); | ||
308 | int channel_request_rforward_cancel(struct ssh *, struct Forward *); | ||
309 | int channel_setup_remote_fwd_listener(struct ssh *, struct Forward *, | ||
310 | int *, struct ForwardOptions *); | ||
311 | int channel_cancel_rport_listener(struct ssh *, struct Forward *); | ||
312 | int channel_cancel_lport_listener(struct ssh *, struct Forward *, | ||
313 | int, struct ForwardOptions *); | ||
291 | int permitopen_port(const char *); | 314 | int permitopen_port(const char *); |
292 | 315 | ||
293 | /* x11 forwarding */ | 316 | /* x11 forwarding */ |
294 | 317 | ||
295 | void channel_set_x11_refuse_time(u_int); | 318 | void channel_set_x11_refuse_time(struct ssh *, u_int); |
296 | int x11_connect_display(void); | 319 | int x11_connect_display(struct ssh *); |
297 | int x11_create_display_inet(int, int, int, u_int *, int **); | 320 | int x11_create_display_inet(struct ssh *, int, int, int, u_int *, int **); |
298 | int x11_input_open(int, u_int32_t, void *); | 321 | void x11_request_forwarding_with_spoofing(struct ssh *, int, |
299 | void x11_request_forwarding_with_spoofing(int, const char *, const char *, | 322 | const char *, const char *, const char *, int); |
300 | const char *, int); | ||
301 | int deny_input_open(int, u_int32_t, void *); | ||
302 | |||
303 | /* agent forwarding */ | ||
304 | |||
305 | void auth_request_forwarding(void); | ||
306 | 323 | ||
307 | /* channel close */ | 324 | /* channel close */ |
308 | 325 | ||
309 | int chan_is_dead(Channel *, int); | 326 | int chan_is_dead(struct ssh *, Channel *, int); |
310 | void chan_mark_dead(Channel *); | 327 | void chan_mark_dead(struct ssh *, Channel *); |
311 | 328 | ||
312 | /* channel events */ | 329 | /* channel events */ |
313 | 330 | ||
314 | void chan_rcvd_oclose(Channel *); | 331 | void chan_rcvd_oclose(struct ssh *, Channel *); |
315 | void chan_rcvd_eow(Channel *); /* SSH2-only */ | 332 | void chan_rcvd_eow(struct ssh *, Channel *); |
316 | void chan_read_failed(Channel *); | 333 | void chan_read_failed(struct ssh *, Channel *); |
317 | void chan_ibuf_empty(Channel *); | 334 | void chan_ibuf_empty(struct ssh *, Channel *); |
318 | 335 | void chan_rcvd_ieof(struct ssh *, Channel *); | |
319 | void chan_rcvd_ieof(Channel *); | 336 | void chan_write_failed(struct ssh *, Channel *); |
320 | void chan_write_failed(Channel *); | 337 | void chan_obuf_empty(struct ssh *, Channel *); |
321 | void chan_obuf_empty(Channel *); | ||
322 | 338 | ||
323 | #endif | 339 | #endif |