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 */ 35*5334Sjp161948 /* 36*5334Sjp161948 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 37*5334Sjp161948 * Use is subject to license terms. 38*5334Sjp161948 */ 39*5334Sjp161948 /* $OpenBSD: channels.h,v 1.70 2002/06/24 14:33:27 markus Exp $ */ 40*5334Sjp161948 41*5334Sjp161948 42*5334Sjp161948 #ifndef _CHANNELS_H 43*5334Sjp161948 #define _CHANNELS_H 44*5334Sjp161948 45*5334Sjp161948 #pragma ident "%Z%%M% %I% %E% SMI" 46*5334Sjp161948 47*5334Sjp161948 #ifdef __cplusplus 48*5334Sjp161948 extern "C" { 49*5334Sjp161948 #endif 500Sstevel@tonic-gate 510Sstevel@tonic-gate #include "buffer.h" 520Sstevel@tonic-gate 530Sstevel@tonic-gate /* Definitions for channel types. */ 540Sstevel@tonic-gate #define SSH_CHANNEL_X11_LISTENER 1 /* Listening for inet X11 conn. */ 550Sstevel@tonic-gate #define SSH_CHANNEL_PORT_LISTENER 2 /* Listening on a port. */ 560Sstevel@tonic-gate #define SSH_CHANNEL_OPENING 3 /* waiting for confirmation */ 570Sstevel@tonic-gate #define SSH_CHANNEL_OPEN 4 /* normal open two-way channel */ 580Sstevel@tonic-gate #define SSH_CHANNEL_CLOSED 5 /* waiting for close confirmation */ 590Sstevel@tonic-gate #define SSH_CHANNEL_AUTH_SOCKET 6 /* authentication socket */ 600Sstevel@tonic-gate #define SSH_CHANNEL_X11_OPEN 7 /* reading first X11 packet */ 610Sstevel@tonic-gate #define SSH_CHANNEL_INPUT_DRAINING 8 /* sending remaining data to conn */ 620Sstevel@tonic-gate #define SSH_CHANNEL_OUTPUT_DRAINING 9 /* sending remaining data to app */ 630Sstevel@tonic-gate #define SSH_CHANNEL_LARVAL 10 /* larval session */ 640Sstevel@tonic-gate #define SSH_CHANNEL_RPORT_LISTENER 11 /* Listening to a R-style port */ 650Sstevel@tonic-gate #define SSH_CHANNEL_CONNECTING 12 660Sstevel@tonic-gate #define SSH_CHANNEL_DYNAMIC 13 670Sstevel@tonic-gate #define SSH_CHANNEL_ZOMBIE 14 /* Almost dead. */ 680Sstevel@tonic-gate #define SSH_CHANNEL_MAX_TYPE 15 690Sstevel@tonic-gate 700Sstevel@tonic-gate #define SSH_CHANNEL_PATH_LEN 256 710Sstevel@tonic-gate 720Sstevel@tonic-gate struct Channel; 730Sstevel@tonic-gate typedef struct Channel Channel; 740Sstevel@tonic-gate 750Sstevel@tonic-gate typedef void channel_callback_fn(int, void *); 760Sstevel@tonic-gate typedef int channel_filter_fn(struct Channel *, char *, int); 770Sstevel@tonic-gate 780Sstevel@tonic-gate struct Channel { 790Sstevel@tonic-gate int type; /* channel type/state */ 800Sstevel@tonic-gate int self; /* my own channel identifier */ 810Sstevel@tonic-gate int remote_id; /* channel identifier for remote peer */ 820Sstevel@tonic-gate u_int istate; /* input from channel (state of receive half) */ 830Sstevel@tonic-gate u_int ostate; /* output to channel (state of transmit half) */ 840Sstevel@tonic-gate int wait_for_exit; /* no close till after exit-status is sent */ 850Sstevel@tonic-gate int flags; /* close sent/rcvd */ 860Sstevel@tonic-gate int rfd; /* read fd */ 870Sstevel@tonic-gate int wfd; /* write fd */ 880Sstevel@tonic-gate int efd; /* extended fd */ 890Sstevel@tonic-gate int sock; /* sock fd */ 900Sstevel@tonic-gate int isatty; /* rfd is a tty */ 910Sstevel@tonic-gate int wfd_isatty; /* wfd is a tty */ 920Sstevel@tonic-gate int force_drain; /* force close on iEOF */ 930Sstevel@tonic-gate int delayed; /* fdset hack */ 940Sstevel@tonic-gate Buffer input; /* data read from socket, to be sent over 950Sstevel@tonic-gate * encrypted connection */ 960Sstevel@tonic-gate Buffer output; /* data received over encrypted connection for 970Sstevel@tonic-gate * send on socket */ 980Sstevel@tonic-gate Buffer extended; 990Sstevel@tonic-gate char path[SSH_CHANNEL_PATH_LEN]; 1000Sstevel@tonic-gate /* path for unix domain sockets, or host name for forwards */ 1010Sstevel@tonic-gate int listening_port; /* port being listened for forwards */ 1020Sstevel@tonic-gate int host_port; /* remote port to connect for forwards */ 1030Sstevel@tonic-gate char *remote_name; /* remote hostname */ 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate u_int remote_window; 1060Sstevel@tonic-gate u_int remote_maxpacket; 1070Sstevel@tonic-gate u_int local_window; 1080Sstevel@tonic-gate u_int local_window_max; 1090Sstevel@tonic-gate u_int local_consumed; 1100Sstevel@tonic-gate u_int local_maxpacket; 1110Sstevel@tonic-gate int extended_usage; 1120Sstevel@tonic-gate int single_connection; 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate char *ctype; /* type */ 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate /* callback */ 1170Sstevel@tonic-gate channel_callback_fn *confirm; 1180Sstevel@tonic-gate channel_callback_fn *detach_user; 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate /* filter */ 1210Sstevel@tonic-gate channel_filter_fn *input_filter; 1220Sstevel@tonic-gate }; 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate #define CHAN_EXTENDED_IGNORE 0 1250Sstevel@tonic-gate #define CHAN_EXTENDED_READ 1 1260Sstevel@tonic-gate #define CHAN_EXTENDED_WRITE 2 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate /* default window/packet sizes for tcp/x11-fwd-channel */ 1290Sstevel@tonic-gate #define CHAN_SES_PACKET_DEFAULT (32*1024) 1300Sstevel@tonic-gate #define CHAN_SES_WINDOW_DEFAULT (4*CHAN_SES_PACKET_DEFAULT) 1310Sstevel@tonic-gate #define CHAN_TCP_PACKET_DEFAULT (32*1024) 1320Sstevel@tonic-gate #define CHAN_TCP_WINDOW_DEFAULT (4*CHAN_TCP_PACKET_DEFAULT) 1330Sstevel@tonic-gate #define CHAN_X11_PACKET_DEFAULT (16*1024) 1340Sstevel@tonic-gate #define CHAN_X11_WINDOW_DEFAULT (4*CHAN_X11_PACKET_DEFAULT) 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate /* possible input states */ 1370Sstevel@tonic-gate #define CHAN_INPUT_OPEN 0 1380Sstevel@tonic-gate #define CHAN_INPUT_WAIT_DRAIN 1 1390Sstevel@tonic-gate #define CHAN_INPUT_WAIT_OCLOSE 2 1400Sstevel@tonic-gate #define CHAN_INPUT_CLOSED 3 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate /* possible output states */ 1430Sstevel@tonic-gate #define CHAN_OUTPUT_OPEN 0 1440Sstevel@tonic-gate #define CHAN_OUTPUT_WAIT_DRAIN 1 1450Sstevel@tonic-gate #define CHAN_OUTPUT_WAIT_IEOF 2 1460Sstevel@tonic-gate #define CHAN_OUTPUT_CLOSED 3 1470Sstevel@tonic-gate 1484764Sjp161948 /* 1494764Sjp161948 * Other channel flag bits are specific to each type of channel and are 1504764Sjp161948 * defined locally with the code that uses them. 1514764Sjp161948 */ 1520Sstevel@tonic-gate #define CHAN_CLOSE_SENT 0x01 1530Sstevel@tonic-gate #define CHAN_CLOSE_RCVD 0x02 1540Sstevel@tonic-gate #define CHAN_EOF_SENT 0x04 1550Sstevel@tonic-gate #define CHAN_EOF_RCVD 0x08 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate /* check whether 'efd' is still in use */ 1580Sstevel@tonic-gate #define CHANNEL_EFD_INPUT_ACTIVE(c) \ 1590Sstevel@tonic-gate (compat20 && c->extended_usage == CHAN_EXTENDED_READ && \ 1600Sstevel@tonic-gate (c->efd != -1 || \ 1610Sstevel@tonic-gate buffer_len(&c->extended) > 0)) 1620Sstevel@tonic-gate #define CHANNEL_EFD_OUTPUT_ACTIVE(c) \ 1630Sstevel@tonic-gate (compat20 && c->extended_usage == CHAN_EXTENDED_WRITE && \ 1640Sstevel@tonic-gate ((c->efd != -1 && !(c->flags & (CHAN_EOF_RCVD|CHAN_CLOSE_RCVD))) || \ 1650Sstevel@tonic-gate buffer_len(&c->extended) > 0)) 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate /* channel management */ 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate Channel *channel_lookup(int); 1700Sstevel@tonic-gate Channel *channel_new(char *, int, int, int, int, u_int, u_int, int, char *, int); 1710Sstevel@tonic-gate void channel_set_fds(int, int, int, int, int, int, u_int); 1720Sstevel@tonic-gate void channel_set_wait_for_exit(int, int); 1730Sstevel@tonic-gate void channel_free(Channel *); 1740Sstevel@tonic-gate void channel_free_all(void); 1750Sstevel@tonic-gate void channel_stop_listening(void); 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate void channel_send_open(int); 1780Sstevel@tonic-gate void channel_request_start(int, char *, int); 1790Sstevel@tonic-gate void channel_register_cleanup(int, channel_callback_fn *); 1800Sstevel@tonic-gate void channel_register_confirm(int, channel_callback_fn *); 1810Sstevel@tonic-gate void channel_register_filter(int, channel_filter_fn *); 1820Sstevel@tonic-gate void channel_cancel_cleanup(int); 1830Sstevel@tonic-gate int channel_close_fd(int *); 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate /* protocol handler */ 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate void channel_input_close(int, u_int32_t, void *); 1880Sstevel@tonic-gate void channel_input_close_confirmation(int, u_int32_t, void *); 1890Sstevel@tonic-gate void channel_input_data(int, u_int32_t, void *); 1900Sstevel@tonic-gate void channel_input_extended_data(int, u_int32_t, void *); 1910Sstevel@tonic-gate void channel_input_ieof(int, u_int32_t, void *); 1920Sstevel@tonic-gate void channel_input_oclose(int, u_int32_t, void *); 1930Sstevel@tonic-gate void channel_input_open_confirmation(int, u_int32_t, void *); 1940Sstevel@tonic-gate void channel_input_open_failure(int, u_int32_t, void *); 1950Sstevel@tonic-gate void channel_input_port_open(int, u_int32_t, void *); 1960Sstevel@tonic-gate void channel_input_window_adjust(int, u_int32_t, void *); 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate /* file descriptor handling (read/write) */ 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate void channel_prepare_select(fd_set **, fd_set **, int *, int*, int); 2010Sstevel@tonic-gate void channel_after_select(fd_set *, fd_set *); 2020Sstevel@tonic-gate void channel_output_poll(void); 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate int channel_not_very_much_buffered_data(void); 2050Sstevel@tonic-gate void channel_close_all(void); 2060Sstevel@tonic-gate int channel_still_open(void); 2070Sstevel@tonic-gate char *channel_open_message(void); 2080Sstevel@tonic-gate int channel_find_open(void); 2090Sstevel@tonic-gate 2100Sstevel@tonic-gate /* tcp forwarding */ 2110Sstevel@tonic-gate void channel_set_af(int af); 2120Sstevel@tonic-gate void channel_permit_all_opens(void); 2130Sstevel@tonic-gate void channel_add_permitted_opens(char *, int); 2140Sstevel@tonic-gate void channel_clear_permitted_opens(void); 2150Sstevel@tonic-gate void channel_input_port_forward_request(int, int); 2160Sstevel@tonic-gate int channel_connect_to(const char *, u_short); 2170Sstevel@tonic-gate int channel_connect_by_listen_address(u_short); 218*5334Sjp161948 int channel_request_remote_forwarding(const char *, u_short, 219*5334Sjp161948 const char *, u_short); 220*5334Sjp161948 int channel_setup_local_fwd_listener(const char *, u_short, 221*5334Sjp161948 const char *, u_short, int); 222*5334Sjp161948 void channel_request_rforward_cancel(const char *host, u_short port); 2230Sstevel@tonic-gate int channel_setup_remote_fwd_listener(const char *, u_short, int); 224*5334Sjp161948 int channel_cancel_rport_listener(const char *, u_short); 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate /* x11 forwarding */ 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate int x11_connect_display(void); 2290Sstevel@tonic-gate int x11_create_display_inet(int, int, int, u_int *); 2300Sstevel@tonic-gate void x11_input_open(int, u_int32_t, void *); 2314907Sjp161948 void x11_request_forwarding_with_spoofing(int, const char *, const char *, 2324907Sjp161948 const char *); 2330Sstevel@tonic-gate void deny_input_open(int, u_int32_t, void *); 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate /* agent forwarding */ 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate void auth_request_forwarding(void); 2380Sstevel@tonic-gate void auth_input_open_request(int, u_int32_t, void *); 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate /* channel close */ 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate int chan_is_dead(Channel *, int); 2430Sstevel@tonic-gate void chan_mark_dead(Channel *); 2440Sstevel@tonic-gate 2450Sstevel@tonic-gate /* channel events */ 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate void chan_rcvd_oclose(Channel *); 2480Sstevel@tonic-gate void chan_read_failed(Channel *); 2490Sstevel@tonic-gate void chan_ibuf_empty(Channel *); 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate void chan_rcvd_ieof(Channel *); 2520Sstevel@tonic-gate void chan_write_failed(Channel *); 2530Sstevel@tonic-gate void chan_obuf_empty(Channel *); 2540Sstevel@tonic-gate 2550Sstevel@tonic-gate #ifdef __cplusplus 2560Sstevel@tonic-gate } 2570Sstevel@tonic-gate #endif 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate #endif /* _CHANNELS_H */ 260