Main Page | Namespace List | Class List | Directories | File List | Class Members | File Members

channels.h

Go to the documentation of this file.
00001 /*      $OpenBSD: channels.h,v 1.83 2005/12/30 15:56:37 reyk Exp $      */
00002 
00003 /*
00004  * Author: Tatu Ylonen <ylo@cs.hut.fi>
00005  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
00006  *                    All rights reserved
00007  *
00008  * As far as I am concerned, the code I have written for this software
00009  * can be used freely for any purpose.  Any derived versions of this
00010  * software must be clearly marked as such, and if the derived work is
00011  * incompatible with the protocol description in the RFC file, it must be
00012  * called by a name other than "ssh" or "Secure Shell".
00013  */
00014 /*
00015  * Copyright (c) 1999, 2000, 2001, 2002 Markus Friedl.  All rights reserved.
00016  *
00017  * Redistribution and use in source and binary forms, with or without
00018  * modification, are permitted provided that the following conditions
00019  * are met:
00020  * 1. Redistributions of source code must retain the above copyright
00021  *    notice, this list of conditions and the following disclaimer.
00022  * 2. Redistributions in binary form must reproduce the above copyright
00023  *    notice, this list of conditions and the following disclaimer in the
00024  *    documentation and/or other materials provided with the distribution.
00025  *
00026  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00027  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00028  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00029  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00030  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00031  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00032  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00033  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00034  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00035  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036  */
00037 
00038 #ifndef CHANNEL_H
00039 #define CHANNEL_H
00040 
00041 #include "buffer.h"
00042 
00043 /* Definitions for channel types. */
00044 #define SSH_CHANNEL_X11_LISTENER        1       /* Listening for inet X11 conn. */
00045 #define SSH_CHANNEL_PORT_LISTENER       2       /* Listening on a port. */
00046 #define SSH_CHANNEL_OPENING             3       /* waiting for confirmation */
00047 #define SSH_CHANNEL_OPEN                4       /* normal open two-way channel */
00048 #define SSH_CHANNEL_CLOSED              5       /* waiting for close confirmation */
00049 #define SSH_CHANNEL_AUTH_SOCKET         6       /* authentication socket */
00050 #define SSH_CHANNEL_X11_OPEN            7       /* reading first X11 packet */
00051 #define SSH_CHANNEL_INPUT_DRAINING      8       /* sending remaining data to conn */
00052 #define SSH_CHANNEL_OUTPUT_DRAINING     9       /* sending remaining data to app */
00053 #define SSH_CHANNEL_LARVAL              10      /* larval session */
00054 #define SSH_CHANNEL_RPORT_LISTENER      11      /* Listening to a R-style port  */
00055 #define SSH_CHANNEL_CONNECTING          12
00056 #define SSH_CHANNEL_DYNAMIC             13
00057 #define SSH_CHANNEL_ZOMBIE              14      /* Almost dead. */
00058 #define SSH_CHANNEL_MAX_TYPE            15
00059 
00060 #define SSH_CHANNEL_PATH_LEN            256
00061 
00062 struct Channel;
00063 typedef struct Channel Channel;
00064 
00065 typedef void channel_callback_fn(int, void *);
00066 typedef int channel_infilter_fn(struct Channel *, char *, int);
00067 typedef u_char *channel_outfilter_fn(struct Channel *, u_char **, u_int *);
00068 
00069 struct Channel {
00070         int     type;           /* channel type/state */
00071         int     self;           /* my own channel identifier */
00072         int     remote_id;      /* channel identifier for remote peer */
00073         u_int   istate;         /* input from channel (state of receive half) */
00074         u_int   ostate;         /* output to channel  (state of transmit half) */
00075         int     flags;          /* close sent/rcvd */
00076         int     rfd;            /* read fd */
00077         int     wfd;            /* write fd */
00078         int     efd;            /* extended fd */
00079         int     sock;           /* sock fd */
00080         int     ctl_fd;         /* control fd (client sharing) */
00081         int     isatty;         /* rfd is a tty */
00082         int     wfd_isatty;     /* wfd is a tty */
00083         int     client_tty;     /* (client) TTY has been requested */
00084         int     force_drain;    /* force close on iEOF */
00085         int     delayed;                /* fdset hack */
00086         Buffer  input;          /* data read from socket, to be sent over
00087                                  * encrypted connection */
00088         Buffer  output;         /* data received over encrypted connection for
00089                                  * send on socket */
00090         Buffer  extended;
00091         char    path[SSH_CHANNEL_PATH_LEN];
00092                 /* path for unix domain sockets, or host name for forwards */
00093         int     listening_port; /* port being listened for forwards */
00094         int     host_port;      /* remote port to connect for forwards */
00095         char   *remote_name;    /* remote hostname */
00096 
00097         u_int   remote_window;
00098         u_int   remote_maxpacket;
00099         u_int   local_window;
00100         u_int   local_window_max;
00101         u_int   local_consumed;
00102         u_int   local_maxpacket;
00103         int     extended_usage;
00104         int     single_connection;
00105 
00106         char   *ctype;          /* type */
00107 
00108         /* callback */
00109         channel_callback_fn     *confirm;
00110         void                    *confirm_ctx;
00111         channel_callback_fn     *detach_user;
00112         int                     detach_close;
00113 
00114         /* filter */
00115         channel_infilter_fn     *input_filter;
00116         channel_outfilter_fn    *output_filter;
00117 
00118         int     datagram;       /* keep boundaries */
00119 };
00120 
00121 #define CHAN_EXTENDED_IGNORE            0
00122 #define CHAN_EXTENDED_READ              1
00123 #define CHAN_EXTENDED_WRITE             2
00124 
00125 /* default window/packet sizes for tcp/x11-fwd-channel */
00126 #define CHAN_SES_PACKET_DEFAULT (32*1024)
00127 #define CHAN_SES_WINDOW_DEFAULT (4*CHAN_SES_PACKET_DEFAULT)
00128 #define CHAN_TCP_PACKET_DEFAULT (32*1024)
00129 #define CHAN_TCP_WINDOW_DEFAULT (4*CHAN_TCP_PACKET_DEFAULT)
00130 #define CHAN_X11_PACKET_DEFAULT (16*1024)
00131 #define CHAN_X11_WINDOW_DEFAULT (4*CHAN_X11_PACKET_DEFAULT)
00132 
00133 /* possible input states */
00134 #define CHAN_INPUT_OPEN                 0
00135 #define CHAN_INPUT_WAIT_DRAIN           1
00136 #define CHAN_INPUT_WAIT_OCLOSE          2
00137 #define CHAN_INPUT_CLOSED               3
00138 
00139 /* possible output states */
00140 #define CHAN_OUTPUT_OPEN                0
00141 #define CHAN_OUTPUT_WAIT_DRAIN          1
00142 #define CHAN_OUTPUT_WAIT_IEOF           2
00143 #define CHAN_OUTPUT_CLOSED              3
00144 
00145 #define CHAN_CLOSE_SENT                 0x01
00146 #define CHAN_CLOSE_RCVD                 0x02
00147 #define CHAN_EOF_SENT                   0x04
00148 #define CHAN_EOF_RCVD                   0x08
00149 
00150 #define CHAN_RBUF       16*1024
00151 
00152 /* check whether 'efd' is still in use */
00153 #define CHANNEL_EFD_INPUT_ACTIVE(c) \
00154         (compat20 && c->extended_usage == CHAN_EXTENDED_READ && \
00155         (c->efd != -1 || \
00156         buffer_len(&c->extended) > 0))
00157 #define CHANNEL_EFD_OUTPUT_ACTIVE(c) \
00158         (compat20 && c->extended_usage == CHAN_EXTENDED_WRITE && \
00159         c->efd != -1 && (!(c->flags & (CHAN_EOF_RCVD|CHAN_CLOSE_RCVD)) || \
00160         buffer_len(&c->extended) > 0))
00161 
00162 /* channel management */
00163 
00164 Channel *channel_by_id(int);
00165 Channel *channel_lookup(int);
00166 Channel *channel_new(char *, int, int, int, int, u_int, u_int, int, char *, int);
00167 void     channel_set_fds(int, int, int, int, int, int, u_int);
00168 void     channel_free(Channel *);
00169 void     channel_free_all(void);
00170 void     channel_stop_listening(void);
00171 
00172 void     channel_send_open(int);
00173 void     channel_request_start(int, char *, int);
00174 void     channel_register_cleanup(int, channel_callback_fn *, int);
00175 void     channel_register_confirm(int, channel_callback_fn *, void *);
00176 void     channel_register_filter(int, channel_infilter_fn *, channel_outfilter_fn *);
00177 void     channel_cancel_cleanup(int);
00178 int      channel_close_fd(int *);
00179 void     channel_send_window_changes(void);
00180 
00181 /* protocol handler */
00182 
00183 void     channel_input_close(int, u_int32_t, void *);
00184 void     channel_input_close_confirmation(int, u_int32_t, void *);
00185 void     channel_input_data(int, u_int32_t, void *);
00186 void     channel_input_extended_data(int, u_int32_t, void *);
00187 void     channel_input_ieof(int, u_int32_t, void *);
00188 void     channel_input_oclose(int, u_int32_t, void *);
00189 void     channel_input_open_confirmation(int, u_int32_t, void *);
00190 void     channel_input_open_failure(int, u_int32_t, void *);
00191 void     channel_input_port_open(int, u_int32_t, void *);
00192 void     channel_input_window_adjust(int, u_int32_t, void *);
00193 
00194 /* file descriptor handling (read/write) */
00195 
00196 void     channel_prepare_select(fd_set **, fd_set **, int *, u_int*, int);
00197 void     channel_after_select(fd_set *, fd_set *);
00198 void     channel_output_poll(void);
00199 
00200 int      channel_not_very_much_buffered_data(void);
00201 void     channel_close_all(void);
00202 int      channel_still_open(void);
00203 char    *channel_open_message(void);
00204 int      channel_find_open(void);
00205 
00206 /* tcp forwarding */
00207 void     channel_set_af(int af);
00208 void     channel_permit_all_opens(void);
00209 void     channel_add_permitted_opens(char *, int);
00210 void     channel_clear_permitted_opens(void);
00211 void     channel_input_port_forward_request(int, int);
00212 int      channel_connect_to(const char *, u_short);
00213 int      channel_connect_by_listen_address(u_short);
00214 void     channel_request_remote_forwarding(const char *, u_short,
00215              const char *, u_short);
00216 int      channel_setup_local_fwd_listener(const char *, u_short,
00217              const char *, u_short, int);
00218 void     channel_request_rforward_cancel(const char *host, u_short port);
00219 int      channel_setup_remote_fwd_listener(const char *, u_short, int);
00220 int      channel_cancel_rport_listener(const char *, u_short);
00221 
00222 /* x11 forwarding */
00223 
00224 int      x11_connect_display(void);
00225 int      x11_create_display_inet(int, int, int, u_int *, int **);
00226 void     x11_input_open(int, u_int32_t, void *);
00227 void     x11_request_forwarding_with_spoofing(int, const char *, const char *,
00228             const char *);
00229 void     deny_input_open(int, u_int32_t, void *);
00230 
00231 /* agent forwarding */
00232 
00233 void     auth_request_forwarding(void);
00234 
00235 /* channel close */
00236 
00237 int      chan_is_dead(Channel *, int);
00238 void     chan_mark_dead(Channel *);
00239 
00240 /* channel events */
00241 
00242 void     chan_rcvd_oclose(Channel *);
00243 void     chan_read_failed(Channel *);
00244 void     chan_ibuf_empty(Channel *);
00245 
00246 void     chan_rcvd_ieof(Channel *);
00247 void     chan_write_failed(Channel *);
00248 void     chan_obuf_empty(Channel *);
00249 
00250 #endif

© sourcejam.com 2005-2008