10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * Author: Tatu Ylonen <ylo@cs.hut.fi> 30Sstevel@tonic-gate * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 40Sstevel@tonic-gate * All rights reserved 50Sstevel@tonic-gate * 60Sstevel@tonic-gate * As far as I am concerned, the code I have written for this software 70Sstevel@tonic-gate * can be used freely for any purpose. Any derived versions of this 80Sstevel@tonic-gate * software must be clearly marked as such, and if the derived work is 90Sstevel@tonic-gate * incompatible with the protocol description in the RFC file, it must be 100Sstevel@tonic-gate * called by a name other than "ssh" or "Secure Shell". 110Sstevel@tonic-gate */ 120Sstevel@tonic-gate /* 130Sstevel@tonic-gate * Copyright (c) 1999, 2000, 2001, 2002 Markus Friedl. All rights reserved. 140Sstevel@tonic-gate * 150Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 160Sstevel@tonic-gate * modification, are permitted provided that the following conditions 170Sstevel@tonic-gate * are met: 180Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 190Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 200Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 210Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 220Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 230Sstevel@tonic-gate * 240Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 250Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 260Sstevel@tonic-gate * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 270Sstevel@tonic-gate * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 280Sstevel@tonic-gate * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 290Sstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 300Sstevel@tonic-gate * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 310Sstevel@tonic-gate * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 320Sstevel@tonic-gate * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 330Sstevel@tonic-gate * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 340Sstevel@tonic-gate */ 355334Sjp161948 /* 36*12551SZdenek.Kotala@Sun.COM * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. 375334Sjp161948 */ 385334Sjp161948 /* $OpenBSD: channels.h,v 1.70 2002/06/24 14:33:27 markus Exp $ */ 395334Sjp161948 405334Sjp161948 415334Sjp161948 #ifndef _CHANNELS_H 425334Sjp161948 #define _CHANNELS_H 435334Sjp161948 445334Sjp161948 #ifdef __cplusplus 455334Sjp161948 extern "C" { 465334Sjp161948 #endif 470Sstevel@tonic-gate 480Sstevel@tonic-gate #include "buffer.h" 490Sstevel@tonic-gate 500Sstevel@tonic-gate /* Definitions for channel types. */ 510Sstevel@tonic-gate #define SSH_CHANNEL_X11_LISTENER 1 /* Listening for inet X11 conn. */ 520Sstevel@tonic-gate #define SSH_CHANNEL_PORT_LISTENER 2 /* Listening on a port. */ 530Sstevel@tonic-gate #define SSH_CHANNEL_OPENING 3 /* waiting for confirmation */ 540Sstevel@tonic-gate #define SSH_CHANNEL_OPEN 4 /* normal open two-way channel */ 550Sstevel@tonic-gate #define SSH_CHANNEL_CLOSED 5 /* waiting for close confirmation */ 560Sstevel@tonic-gate #define SSH_CHANNEL_AUTH_SOCKET 6 /* authentication socket */ 570Sstevel@tonic-gate #define SSH_CHANNEL_X11_OPEN 7 /* reading first X11 packet */ 580Sstevel@tonic-gate #define SSH_CHANNEL_INPUT_DRAINING 8 /* sending remaining data to conn */ 590Sstevel@tonic-gate #define SSH_CHANNEL_OUTPUT_DRAINING 9 /* sending remaining data to app */ 600Sstevel@tonic-gate #define SSH_CHANNEL_LARVAL 10 /* larval session */ 610Sstevel@tonic-gate #define SSH_CHANNEL_RPORT_LISTENER 11 /* Listening to a R-style port */ 620Sstevel@tonic-gate #define SSH_CHANNEL_CONNECTING 12 630Sstevel@tonic-gate #define SSH_CHANNEL_DYNAMIC 13 640Sstevel@tonic-gate #define SSH_CHANNEL_ZOMBIE 14 /* Almost dead. */ 650Sstevel@tonic-gate #define SSH_CHANNEL_MAX_TYPE 15 660Sstevel@tonic-gate 670Sstevel@tonic-gate #define SSH_CHANNEL_PATH_LEN 256 680Sstevel@tonic-gate 690Sstevel@tonic-gate struct Channel; 700Sstevel@tonic-gate typedef struct Channel Channel; 710Sstevel@tonic-gate 720Sstevel@tonic-gate typedef void channel_callback_fn(int, void *); 730Sstevel@tonic-gate typedef int channel_filter_fn(struct Channel *, char *, int); 740Sstevel@tonic-gate 750Sstevel@tonic-gate struct Channel { 760Sstevel@tonic-gate int type; /* channel type/state */ 770Sstevel@tonic-gate int self; /* my own channel identifier */ 780Sstevel@tonic-gate int remote_id; /* channel identifier for remote peer */ 790Sstevel@tonic-gate u_int istate; /* input from channel (state of receive half) */ 800Sstevel@tonic-gate u_int ostate; /* output to channel (state of transmit half) */ 810Sstevel@tonic-gate int wait_for_exit; /* no close till after exit-status is sent */ 820Sstevel@tonic-gate int flags; /* close sent/rcvd */ 830Sstevel@tonic-gate int rfd; /* read fd */ 840Sstevel@tonic-gate int wfd; /* write fd */ 850Sstevel@tonic-gate int efd; /* extended fd */ 860Sstevel@tonic-gate int sock; /* sock fd */ 870Sstevel@tonic-gate int isatty; /* rfd is a tty */ 880Sstevel@tonic-gate int wfd_isatty; /* wfd is a tty */ 890Sstevel@tonic-gate int force_drain; /* force close on iEOF */ 90*12551SZdenek.Kotala@Sun.COM int delayed; /* post-select handlers for newly created 91*12551SZdenek.Kotala@Sun.COM * channels are delayed until the first call 92*12551SZdenek.Kotala@Sun.COM * to a matching pre-select handler. 93*12551SZdenek.Kotala@Sun.COM * this way post-select handlers are not 94*12551SZdenek.Kotala@Sun.COM * accidenly called if a FD gets reused */ 950Sstevel@tonic-gate Buffer input; /* data read from socket, to be sent over 960Sstevel@tonic-gate * encrypted connection */ 970Sstevel@tonic-gate Buffer output; /* data received over encrypted connection for 980Sstevel@tonic-gate * send on socket */ 990Sstevel@tonic-gate Buffer extended; 1000Sstevel@tonic-gate char path[SSH_CHANNEL_PATH_LEN]; 1010Sstevel@tonic-gate /* path for unix domain sockets, or host name for forwards */ 1020Sstevel@tonic-gate int listening_port; /* port being listened for forwards */ 1030Sstevel@tonic-gate int host_port; /* remote port to connect for forwards */ 1040Sstevel@tonic-gate char *remote_name; /* remote hostname */ 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate u_int remote_window; 1070Sstevel@tonic-gate u_int remote_maxpacket; 1080Sstevel@tonic-gate u_int local_window; 1090Sstevel@tonic-gate u_int local_window_max; 1100Sstevel@tonic-gate u_int local_consumed; 1110Sstevel@tonic-gate u_int local_maxpacket; 1120Sstevel@tonic-gate int extended_usage; 1130Sstevel@tonic-gate int single_connection; 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate char *ctype; /* type */ 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate /* callback */ 1180Sstevel@tonic-gate channel_callback_fn *confirm; 1190Sstevel@tonic-gate channel_callback_fn *detach_user; 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate /* filter */ 1220Sstevel@tonic-gate channel_filter_fn *input_filter; 1230Sstevel@tonic-gate }; 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate #define CHAN_EXTENDED_IGNORE 0 1260Sstevel@tonic-gate #define CHAN_EXTENDED_READ 1 1270Sstevel@tonic-gate #define CHAN_EXTENDED_WRITE 2 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate /* default window/packet sizes for tcp/x11-fwd-channel */ 1300Sstevel@tonic-gate #define CHAN_SES_PACKET_DEFAULT (32*1024) 1310Sstevel@tonic-gate #define CHAN_SES_WINDOW_DEFAULT (4*CHAN_SES_PACKET_DEFAULT) 1320Sstevel@tonic-gate #define CHAN_TCP_PACKET_DEFAULT (32*1024) 1330Sstevel@tonic-gate #define CHAN_TCP_WINDOW_DEFAULT (4*CHAN_TCP_PACKET_DEFAULT) 1340Sstevel@tonic-gate #define CHAN_X11_PACKET_DEFAULT (16*1024) 1350Sstevel@tonic-gate #define CHAN_X11_WINDOW_DEFAULT (4*CHAN_X11_PACKET_DEFAULT) 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate /* possible input states */ 1380Sstevel@tonic-gate #define CHAN_INPUT_OPEN 0 1390Sstevel@tonic-gate #define CHAN_INPUT_WAIT_DRAIN 1 1400Sstevel@tonic-gate #define CHAN_INPUT_WAIT_OCLOSE 2 1410Sstevel@tonic-gate #define CHAN_INPUT_CLOSED 3 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate /* possible output states */ 1440Sstevel@tonic-gate #define CHAN_OUTPUT_OPEN 0 1450Sstevel@tonic-gate #define CHAN_OUTPUT_WAIT_DRAIN 1 1460Sstevel@tonic-gate #define CHAN_OUTPUT_WAIT_IEOF 2 1470Sstevel@tonic-gate #define CHAN_OUTPUT_CLOSED 3 1480Sstevel@tonic-gate 1494764Sjp161948 /* 1504764Sjp161948 * Other channel flag bits are specific to each type of channel and are 1514764Sjp161948 * defined locally with the code that uses them. 1524764Sjp161948 */ 1530Sstevel@tonic-gate #define CHAN_CLOSE_SENT 0x01 1540Sstevel@tonic-gate #define CHAN_CLOSE_RCVD 0x02 1550Sstevel@tonic-gate #define CHAN_EOF_SENT 0x04 1560Sstevel@tonic-gate #define CHAN_EOF_RCVD 0x08 1570Sstevel@tonic-gate 15810876SZdenek.Kotala@Sun.COM #define CHAN_RBUF 16*1024 15910876SZdenek.Kotala@Sun.COM 1600Sstevel@tonic-gate /* check whether 'efd' is still in use */ 1610Sstevel@tonic-gate #define CHANNEL_EFD_INPUT_ACTIVE(c) \ 1620Sstevel@tonic-gate (compat20 && c->extended_usage == CHAN_EXTENDED_READ && \ 1630Sstevel@tonic-gate (c->efd != -1 || \ 1640Sstevel@tonic-gate buffer_len(&c->extended) > 0)) 1650Sstevel@tonic-gate #define CHANNEL_EFD_OUTPUT_ACTIVE(c) \ 1660Sstevel@tonic-gate (compat20 && c->extended_usage == CHAN_EXTENDED_WRITE && \ 1670Sstevel@tonic-gate ((c->efd != -1 && !(c->flags & (CHAN_EOF_RCVD|CHAN_CLOSE_RCVD))) || \ 1680Sstevel@tonic-gate buffer_len(&c->extended) > 0)) 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate /* channel management */ 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate Channel *channel_lookup(int); 1730Sstevel@tonic-gate Channel *channel_new(char *, int, int, int, int, u_int, u_int, int, char *, int); 1740Sstevel@tonic-gate void channel_set_fds(int, int, int, int, int, int, u_int); 1750Sstevel@tonic-gate void channel_set_wait_for_exit(int, int); 1760Sstevel@tonic-gate void channel_free(Channel *); 1770Sstevel@tonic-gate void channel_free_all(void); 1780Sstevel@tonic-gate void channel_stop_listening(void); 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate void channel_send_open(int); 1810Sstevel@tonic-gate void channel_request_start(int, char *, int); 1820Sstevel@tonic-gate void channel_register_cleanup(int, channel_callback_fn *); 1830Sstevel@tonic-gate void channel_register_confirm(int, channel_callback_fn *); 1840Sstevel@tonic-gate void channel_register_filter(int, channel_filter_fn *); 1850Sstevel@tonic-gate void channel_cancel_cleanup(int); 1860Sstevel@tonic-gate int channel_close_fd(int *); 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate /* protocol handler */ 1890Sstevel@tonic-gate 1900Sstevel@tonic-gate void channel_input_close(int, u_int32_t, void *); 1910Sstevel@tonic-gate void channel_input_close_confirmation(int, u_int32_t, void *); 1920Sstevel@tonic-gate void channel_input_data(int, u_int32_t, void *); 1930Sstevel@tonic-gate void channel_input_extended_data(int, u_int32_t, void *); 1940Sstevel@tonic-gate void channel_input_ieof(int, u_int32_t, void *); 1950Sstevel@tonic-gate void channel_input_oclose(int, u_int32_t, void *); 1960Sstevel@tonic-gate void channel_input_open_confirmation(int, u_int32_t, void *); 1970Sstevel@tonic-gate void channel_input_open_failure(int, u_int32_t, void *); 1980Sstevel@tonic-gate void channel_input_port_open(int, u_int32_t, void *); 1990Sstevel@tonic-gate void channel_input_window_adjust(int, u_int32_t, void *); 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate /* file descriptor handling (read/write) */ 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate void channel_prepare_select(fd_set **, fd_set **, int *, int*, int); 2040Sstevel@tonic-gate void channel_after_select(fd_set *, fd_set *); 2050Sstevel@tonic-gate void channel_output_poll(void); 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate int channel_not_very_much_buffered_data(void); 2080Sstevel@tonic-gate void channel_close_all(void); 2090Sstevel@tonic-gate int channel_still_open(void); 2100Sstevel@tonic-gate char *channel_open_message(void); 2110Sstevel@tonic-gate int channel_find_open(void); 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate /* tcp forwarding */ 2140Sstevel@tonic-gate void channel_set_af(int af); 2150Sstevel@tonic-gate void channel_permit_all_opens(void); 2160Sstevel@tonic-gate void channel_add_permitted_opens(char *, int); 2170Sstevel@tonic-gate void channel_clear_permitted_opens(void); 2180Sstevel@tonic-gate void channel_input_port_forward_request(int, int); 2190Sstevel@tonic-gate int channel_connect_to(const char *, u_short); 2200Sstevel@tonic-gate int channel_connect_by_listen_address(u_short); 2215334Sjp161948 int channel_request_remote_forwarding(const char *, u_short, 2225334Sjp161948 const char *, u_short); 2235334Sjp161948 int channel_setup_local_fwd_listener(const char *, u_short, 2245334Sjp161948 const char *, u_short, int); 2255334Sjp161948 void channel_request_rforward_cancel(const char *host, u_short port); 2260Sstevel@tonic-gate int channel_setup_remote_fwd_listener(const char *, u_short, int); 2275334Sjp161948 int channel_cancel_rport_listener(const char *, u_short); 2280Sstevel@tonic-gate 2290Sstevel@tonic-gate /* x11 forwarding */ 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate int x11_connect_display(void); 2320Sstevel@tonic-gate int x11_create_display_inet(int, int, int, u_int *); 2330Sstevel@tonic-gate void x11_input_open(int, u_int32_t, void *); 2344907Sjp161948 void x11_request_forwarding_with_spoofing(int, const char *, const char *, 2354907Sjp161948 const char *); 2360Sstevel@tonic-gate void deny_input_open(int, u_int32_t, void *); 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate /* agent forwarding */ 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate void auth_request_forwarding(void); 2410Sstevel@tonic-gate void auth_input_open_request(int, u_int32_t, void *); 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate /* channel close */ 2440Sstevel@tonic-gate 2450Sstevel@tonic-gate int chan_is_dead(Channel *, int); 2460Sstevel@tonic-gate void chan_mark_dead(Channel *); 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate /* channel events */ 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate void chan_rcvd_oclose(Channel *); 2510Sstevel@tonic-gate void chan_read_failed(Channel *); 2520Sstevel@tonic-gate void chan_ibuf_empty(Channel *); 2530Sstevel@tonic-gate 2540Sstevel@tonic-gate void chan_rcvd_ieof(Channel *); 2550Sstevel@tonic-gate void chan_write_failed(Channel *); 2560Sstevel@tonic-gate void chan_obuf_empty(Channel *); 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate #ifdef __cplusplus 2590Sstevel@tonic-gate } 2600Sstevel@tonic-gate #endif 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate #endif /* _CHANNELS_H */ 263