xref: /titanic_50/usr/src/cmd/ssh/include/channels.h (revision 371387fa64d65a99a72f1ff81d0efd2220534d0b)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Author: Tatu Ylonen <ylo@cs.hut.fi>
37c478bd9Sstevel@tonic-gate  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
47c478bd9Sstevel@tonic-gate  *                    All rights reserved
57c478bd9Sstevel@tonic-gate  *
67c478bd9Sstevel@tonic-gate  * As far as I am concerned, the code I have written for this software
77c478bd9Sstevel@tonic-gate  * can be used freely for any purpose.  Any derived versions of this
87c478bd9Sstevel@tonic-gate  * software must be clearly marked as such, and if the derived work is
97c478bd9Sstevel@tonic-gate  * incompatible with the protocol description in the RFC file, it must be
107c478bd9Sstevel@tonic-gate  * called by a name other than "ssh" or "Secure Shell".
117c478bd9Sstevel@tonic-gate  */
127c478bd9Sstevel@tonic-gate /*
137c478bd9Sstevel@tonic-gate  * Copyright (c) 1999, 2000, 2001, 2002 Markus Friedl.  All rights reserved.
147c478bd9Sstevel@tonic-gate  *
157c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
167c478bd9Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
177c478bd9Sstevel@tonic-gate  * are met:
187c478bd9Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
197c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
207c478bd9Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
217c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
227c478bd9Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
237c478bd9Sstevel@tonic-gate  *
247c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
257c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
267c478bd9Sstevel@tonic-gate  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
277c478bd9Sstevel@tonic-gate  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
287c478bd9Sstevel@tonic-gate  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
297c478bd9Sstevel@tonic-gate  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
307c478bd9Sstevel@tonic-gate  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
317c478bd9Sstevel@tonic-gate  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
327c478bd9Sstevel@tonic-gate  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
337c478bd9Sstevel@tonic-gate  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
347c478bd9Sstevel@tonic-gate  */
359b03ea0fSjp161948 /*
368b0ef7edSZdenek Kotala  * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
379b03ea0fSjp161948  */
389b03ea0fSjp161948 /*	$OpenBSD: channels.h,v 1.70 2002/06/24 14:33:27 markus Exp $	*/
399b03ea0fSjp161948 
409b03ea0fSjp161948 
419b03ea0fSjp161948 #ifndef	_CHANNELS_H
429b03ea0fSjp161948 #define	_CHANNELS_H
439b03ea0fSjp161948 
449b03ea0fSjp161948 #ifdef __cplusplus
459b03ea0fSjp161948 extern "C" {
469b03ea0fSjp161948 #endif
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #include "buffer.h"
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate /* Definitions for channel types. */
517c478bd9Sstevel@tonic-gate #define SSH_CHANNEL_X11_LISTENER	1	/* Listening for inet X11 conn. */
527c478bd9Sstevel@tonic-gate #define SSH_CHANNEL_PORT_LISTENER	2	/* Listening on a port. */
537c478bd9Sstevel@tonic-gate #define SSH_CHANNEL_OPENING		3	/* waiting for confirmation */
547c478bd9Sstevel@tonic-gate #define SSH_CHANNEL_OPEN		4	/* normal open two-way channel */
557c478bd9Sstevel@tonic-gate #define SSH_CHANNEL_CLOSED		5	/* waiting for close confirmation */
567c478bd9Sstevel@tonic-gate #define SSH_CHANNEL_AUTH_SOCKET		6	/* authentication socket */
577c478bd9Sstevel@tonic-gate #define SSH_CHANNEL_X11_OPEN		7	/* reading first X11 packet */
587c478bd9Sstevel@tonic-gate #define SSH_CHANNEL_INPUT_DRAINING	8	/* sending remaining data to conn */
597c478bd9Sstevel@tonic-gate #define SSH_CHANNEL_OUTPUT_DRAINING	9	/* sending remaining data to app */
607c478bd9Sstevel@tonic-gate #define SSH_CHANNEL_LARVAL		10	/* larval session */
617c478bd9Sstevel@tonic-gate #define SSH_CHANNEL_RPORT_LISTENER	11	/* Listening to a R-style port  */
627c478bd9Sstevel@tonic-gate #define SSH_CHANNEL_CONNECTING		12
637c478bd9Sstevel@tonic-gate #define SSH_CHANNEL_DYNAMIC		13
647c478bd9Sstevel@tonic-gate #define SSH_CHANNEL_ZOMBIE		14	/* Almost dead. */
657c478bd9Sstevel@tonic-gate #define SSH_CHANNEL_MAX_TYPE		15
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate #define SSH_CHANNEL_PATH_LEN		256
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate struct Channel;
707c478bd9Sstevel@tonic-gate typedef struct Channel Channel;
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate typedef void channel_callback_fn(int, void *);
737c478bd9Sstevel@tonic-gate typedef int channel_filter_fn(struct Channel *, char *, int);
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate struct Channel {
767c478bd9Sstevel@tonic-gate 	int     type;		/* channel type/state */
777c478bd9Sstevel@tonic-gate 	int     self;		/* my own channel identifier */
787c478bd9Sstevel@tonic-gate 	int     remote_id;	/* channel identifier for remote peer */
797c478bd9Sstevel@tonic-gate 	u_int   istate;		/* input from channel (state of receive half) */
807c478bd9Sstevel@tonic-gate 	u_int   ostate;		/* output to channel  (state of transmit half) */
817c478bd9Sstevel@tonic-gate 	int	wait_for_exit;	/* no close till after exit-status is sent */
827c478bd9Sstevel@tonic-gate 	int     flags;		/* close sent/rcvd */
837c478bd9Sstevel@tonic-gate 	int     rfd;		/* read fd */
847c478bd9Sstevel@tonic-gate 	int     wfd;		/* write fd */
857c478bd9Sstevel@tonic-gate 	int     efd;		/* extended fd */
867c478bd9Sstevel@tonic-gate 	int     sock;		/* sock fd */
877c478bd9Sstevel@tonic-gate 	int     isatty;		/* rfd is a tty */
887c478bd9Sstevel@tonic-gate 	int     wfd_isatty;	/* wfd is a tty */
897c478bd9Sstevel@tonic-gate 	int     force_drain;	/* force close on iEOF */
908b0ef7edSZdenek Kotala 	int     delayed;	/* post-select handlers for newly created
918b0ef7edSZdenek Kotala 				 * channels are delayed until the first call
928b0ef7edSZdenek Kotala 				 * to a matching pre-select handler.
938b0ef7edSZdenek Kotala 				 * this way post-select handlers are not
948b0ef7edSZdenek Kotala 				 * accidenly called if a FD gets reused */
957c478bd9Sstevel@tonic-gate 	Buffer  input;		/* data read from socket, to be sent over
967c478bd9Sstevel@tonic-gate 				 * encrypted connection */
977c478bd9Sstevel@tonic-gate 	Buffer  output;		/* data received over encrypted connection for
987c478bd9Sstevel@tonic-gate 				 * send on socket */
997c478bd9Sstevel@tonic-gate 	Buffer  extended;
1007c478bd9Sstevel@tonic-gate 	char    path[SSH_CHANNEL_PATH_LEN];
1017c478bd9Sstevel@tonic-gate 		/* path for unix domain sockets, or host name for forwards */
1027c478bd9Sstevel@tonic-gate 	int     listening_port;	/* port being listened for forwards */
1037c478bd9Sstevel@tonic-gate 	int     host_port;	/* remote port to connect for forwards */
1047c478bd9Sstevel@tonic-gate 	char   *remote_name;	/* remote hostname */
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	u_int	remote_window;
1077c478bd9Sstevel@tonic-gate 	u_int	remote_maxpacket;
1087c478bd9Sstevel@tonic-gate 	u_int	local_window;
1097c478bd9Sstevel@tonic-gate 	u_int	local_window_max;
1107c478bd9Sstevel@tonic-gate 	u_int	local_consumed;
1117c478bd9Sstevel@tonic-gate 	u_int	local_maxpacket;
1127c478bd9Sstevel@tonic-gate 	int     extended_usage;
1137c478bd9Sstevel@tonic-gate 	int	single_connection;
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate 	char   *ctype;		/* type */
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 	/* callback */
1187c478bd9Sstevel@tonic-gate 	channel_callback_fn	*confirm;
1197c478bd9Sstevel@tonic-gate 	channel_callback_fn	*detach_user;
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 	/* filter */
1227c478bd9Sstevel@tonic-gate 	channel_filter_fn	*input_filter;
1237c478bd9Sstevel@tonic-gate };
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate #define CHAN_EXTENDED_IGNORE		0
1267c478bd9Sstevel@tonic-gate #define CHAN_EXTENDED_READ		1
1277c478bd9Sstevel@tonic-gate #define CHAN_EXTENDED_WRITE		2
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /* default window/packet sizes for tcp/x11-fwd-channel */
1307c478bd9Sstevel@tonic-gate #define CHAN_SES_PACKET_DEFAULT	(32*1024)
1317c478bd9Sstevel@tonic-gate #define CHAN_SES_WINDOW_DEFAULT	(4*CHAN_SES_PACKET_DEFAULT)
1327c478bd9Sstevel@tonic-gate #define CHAN_TCP_PACKET_DEFAULT	(32*1024)
1337c478bd9Sstevel@tonic-gate #define CHAN_TCP_WINDOW_DEFAULT	(4*CHAN_TCP_PACKET_DEFAULT)
1347c478bd9Sstevel@tonic-gate #define CHAN_X11_PACKET_DEFAULT	(16*1024)
1357c478bd9Sstevel@tonic-gate #define CHAN_X11_WINDOW_DEFAULT	(4*CHAN_X11_PACKET_DEFAULT)
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate /* possible input states */
1387c478bd9Sstevel@tonic-gate #define CHAN_INPUT_OPEN			0
1397c478bd9Sstevel@tonic-gate #define CHAN_INPUT_WAIT_DRAIN		1
1407c478bd9Sstevel@tonic-gate #define CHAN_INPUT_WAIT_OCLOSE		2
1417c478bd9Sstevel@tonic-gate #define CHAN_INPUT_CLOSED		3
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate /* possible output states */
1447c478bd9Sstevel@tonic-gate #define CHAN_OUTPUT_OPEN		0
1457c478bd9Sstevel@tonic-gate #define CHAN_OUTPUT_WAIT_DRAIN		1
1467c478bd9Sstevel@tonic-gate #define CHAN_OUTPUT_WAIT_IEOF		2
1477c478bd9Sstevel@tonic-gate #define CHAN_OUTPUT_CLOSED		3
1487c478bd9Sstevel@tonic-gate 
149d80e6060Sjp161948 /*
150d80e6060Sjp161948  * Other channel flag bits are specific to each type of channel and are
151d80e6060Sjp161948  * defined locally with the code that uses them.
152d80e6060Sjp161948  */
1537c478bd9Sstevel@tonic-gate #define CHAN_CLOSE_SENT			0x01
1547c478bd9Sstevel@tonic-gate #define CHAN_CLOSE_RCVD			0x02
1557c478bd9Sstevel@tonic-gate #define CHAN_EOF_SENT			0x04
1567c478bd9Sstevel@tonic-gate #define CHAN_EOF_RCVD			0x08
1577c478bd9Sstevel@tonic-gate 
158d92fc072SZdenek Kotala #define CHAN_RBUF			16*1024
159d92fc072SZdenek Kotala 
1607c478bd9Sstevel@tonic-gate /* check whether 'efd' is still in use */
1617c478bd9Sstevel@tonic-gate #define CHANNEL_EFD_INPUT_ACTIVE(c) \
1627c478bd9Sstevel@tonic-gate 	(compat20 && c->extended_usage == CHAN_EXTENDED_READ && \
1637c478bd9Sstevel@tonic-gate 	(c->efd != -1 || \
1647c478bd9Sstevel@tonic-gate 	buffer_len(&c->extended) > 0))
1657c478bd9Sstevel@tonic-gate #define CHANNEL_EFD_OUTPUT_ACTIVE(c) \
1667c478bd9Sstevel@tonic-gate 	(compat20 && c->extended_usage == CHAN_EXTENDED_WRITE && \
1677c478bd9Sstevel@tonic-gate 	((c->efd != -1 && !(c->flags & (CHAN_EOF_RCVD|CHAN_CLOSE_RCVD))) || \
1687c478bd9Sstevel@tonic-gate 	buffer_len(&c->extended) > 0))
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate /* channel management */
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate Channel	*channel_lookup(int);
1737c478bd9Sstevel@tonic-gate Channel *channel_new(char *, int, int, int, int, u_int, u_int, int, char *, int);
1747c478bd9Sstevel@tonic-gate void	 channel_set_fds(int, int, int, int, int, int, u_int);
1757c478bd9Sstevel@tonic-gate void	 channel_set_wait_for_exit(int, int);
1767c478bd9Sstevel@tonic-gate void	 channel_free(Channel *);
1777c478bd9Sstevel@tonic-gate void	 channel_free_all(void);
1787c478bd9Sstevel@tonic-gate void	 channel_stop_listening(void);
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate void	 channel_send_open(int);
1817c478bd9Sstevel@tonic-gate void	 channel_request_start(int, char *, int);
1827c478bd9Sstevel@tonic-gate void	 channel_register_cleanup(int, channel_callback_fn *);
1837c478bd9Sstevel@tonic-gate void	 channel_register_confirm(int, channel_callback_fn *);
1847c478bd9Sstevel@tonic-gate void	 channel_register_filter(int, channel_filter_fn *);
1857c478bd9Sstevel@tonic-gate void	 channel_cancel_cleanup(int);
1867c478bd9Sstevel@tonic-gate int	 channel_close_fd(int *);
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate /* protocol handler */
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate void	 channel_input_close(int, u_int32_t, void *);
1917c478bd9Sstevel@tonic-gate void	 channel_input_close_confirmation(int, u_int32_t, void *);
1927c478bd9Sstevel@tonic-gate void	 channel_input_data(int, u_int32_t, void *);
1937c478bd9Sstevel@tonic-gate void	 channel_input_extended_data(int, u_int32_t, void *);
1947c478bd9Sstevel@tonic-gate void	 channel_input_ieof(int, u_int32_t, void *);
1957c478bd9Sstevel@tonic-gate void	 channel_input_oclose(int, u_int32_t, void *);
1967c478bd9Sstevel@tonic-gate void	 channel_input_open_confirmation(int, u_int32_t, void *);
1977c478bd9Sstevel@tonic-gate void	 channel_input_open_failure(int, u_int32_t, void *);
1987c478bd9Sstevel@tonic-gate void	 channel_input_port_open(int, u_int32_t, void *);
1997c478bd9Sstevel@tonic-gate void	 channel_input_window_adjust(int, u_int32_t, void *);
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate /* file descriptor handling (read/write) */
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate void	 channel_prepare_select(fd_set **, fd_set **, int *, int*, int);
2047c478bd9Sstevel@tonic-gate void     channel_after_select(fd_set *, fd_set *);
2057c478bd9Sstevel@tonic-gate void     channel_output_poll(void);
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate int      channel_not_very_much_buffered_data(void);
2087c478bd9Sstevel@tonic-gate void     channel_close_all(void);
2097c478bd9Sstevel@tonic-gate int      channel_still_open(void);
2107c478bd9Sstevel@tonic-gate char	*channel_open_message(void);
2117c478bd9Sstevel@tonic-gate int	 channel_find_open(void);
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate /* tcp forwarding */
2147c478bd9Sstevel@tonic-gate void	 channel_set_af(int af);
2157c478bd9Sstevel@tonic-gate void     channel_permit_all_opens(void);
2167c478bd9Sstevel@tonic-gate void	 channel_add_permitted_opens(char *, int);
2177c478bd9Sstevel@tonic-gate void	 channel_clear_permitted_opens(void);
2187c478bd9Sstevel@tonic-gate void     channel_input_port_forward_request(int, int);
2197c478bd9Sstevel@tonic-gate int	 channel_connect_to(const char *, u_short);
2207c478bd9Sstevel@tonic-gate int	 channel_connect_by_listen_address(u_short);
2219b03ea0fSjp161948 int	 channel_request_remote_forwarding(const char *, u_short,
2229b03ea0fSjp161948 	     const char *, u_short);
2239b03ea0fSjp161948 int	 channel_setup_local_fwd_listener(const char *, u_short,
2249b03ea0fSjp161948 	     const char *, u_short, int);
2259b03ea0fSjp161948 void	 channel_request_rforward_cancel(const char *host, u_short port);
2267c478bd9Sstevel@tonic-gate int	 channel_setup_remote_fwd_listener(const char *, u_short, int);
2279b03ea0fSjp161948 int	 channel_cancel_rport_listener(const char *, u_short);
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate /* x11 forwarding */
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate int	 x11_connect_display(void);
2327c478bd9Sstevel@tonic-gate int	 x11_create_display_inet(int, int, int, u_int *);
2337c478bd9Sstevel@tonic-gate void     x11_input_open(int, u_int32_t, void *);
234383a1232Sjp161948 void	 x11_request_forwarding_with_spoofing(int, const char *, const char *,
235383a1232Sjp161948 	     const char *);
2367c478bd9Sstevel@tonic-gate void	 deny_input_open(int, u_int32_t, void *);
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate /* agent forwarding */
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate void	 auth_request_forwarding(void);
2417c478bd9Sstevel@tonic-gate void	 auth_input_open_request(int, u_int32_t, void *);
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate /* channel close */
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate int	 chan_is_dead(Channel *, int);
2467c478bd9Sstevel@tonic-gate void	 chan_mark_dead(Channel *);
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate /* channel events */
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate void	 chan_rcvd_oclose(Channel *);
251*371387faSAdam Stevko void	 chan_rcvd_eow(Channel *);      /* SSH2-only */
2527c478bd9Sstevel@tonic-gate void	 chan_read_failed(Channel *);
2537c478bd9Sstevel@tonic-gate void	 chan_ibuf_empty(Channel *);
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate void	 chan_rcvd_ieof(Channel *);
2567c478bd9Sstevel@tonic-gate void	 chan_write_failed(Channel *);
2577c478bd9Sstevel@tonic-gate void	 chan_obuf_empty(Channel *);
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2607c478bd9Sstevel@tonic-gate }
2617c478bd9Sstevel@tonic-gate #endif
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate #endif /* _CHANNELS_H */
264