comparison channel.h @ 285:1b9e69c058d2

propagate from branch 'au.asn.ucc.matt.ltc.dropbear' (head 20dccfc09627970a312d77fb41dc2970b62689c3) to branch 'au.asn.ucc.matt.dropbear' (head fdf4a7a3b97ae5046139915de7e40399cceb2c01)
author Matt Johnston <matt@ucc.asn.au>
date Wed, 08 Mar 2006 13:23:58 +0000
parents 84925eceeb13
children 78518751cb82
comparison
equal deleted inserted replaced
281:997e6f7dc01e 285:1b9e69c058d2
1 /*
2 * Dropbear - a SSH2 server
3 *
4 * Copyright (c) 2002,2003 Matt Johnston
5 * All rights reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE. */
24
25 #ifndef _CHANNEL_H_
26 #define _CHANNEL_H_
27
28 #include "includes.h"
29 #include "buffer.h"
30 #include "circbuffer.h"
31
32 /* channel->type values */
33 #define CHANNEL_ID_NONE 0
34 #define CHANNEL_ID_SESSION 1
35 #define CHANNEL_ID_X11 2
36 #define CHANNEL_ID_AGENT 3
37 #define CHANNEL_ID_TCPDIRECT 4
38 #define CHANNEL_ID_TCPFORWARDED 5
39
40 #define SSH_OPEN_ADMINISTRATIVELY_PROHIBITED 1
41 #define SSH_OPEN_CONNECT_FAILED 2
42 #define SSH_OPEN_UNKNOWN_CHANNEL_TYPE 3
43 #define SSH_OPEN_RESOURCE_SHORTAGE 4
44
45 /* Not a real type */
46 #define SSH_OPEN_IN_PROGRESS 99
47
48 #define MAX_CHANNELS 100 /* simple mem restriction, includes each tcp/x11
49 connection, so can't be _too_ small */
50
51 #define CHAN_EXTEND_SIZE 3 /* how many extra slots to add when we need more */
52
53 #define RECV_MAXWINDOW 8000 /* tweak */
54 #define RECV_WINDOWEXTEND 1000 /* We send a "window extend" every
55 RECV_WINDOWEXTEND bytes */
56 #define RECV_MAXPACKET RECV_MAXWINDOW /* tweak */
57
58 struct ChanType;
59
60 struct Channel {
61
62 unsigned int index; /* the local channel index */
63 unsigned int remotechan;
64 unsigned int recvwindow, transwindow;
65 unsigned int recvdonelen;
66 unsigned int recvmaxpacket, transmaxpacket;
67 void* typedata; /* a pointer to type specific data */
68 int writefd; /* read from wire, written to insecure side */
69 int readfd; /* read from insecure size, written to wire */
70 int errfd; /* used like writefd or readfd, depending if it's client or server.
71 Doesn't exactly belong here, but is cleaner here */
72 circbuffer *writebuf; /* data from the wire, for local consumption */
73 circbuffer *extrabuf; /* extended-data for the program - used like writebuf
74 but for stderr */
75
76 int sentclosed, recvclosed;
77
78 /* this is set when we receive/send a channel eof packet */
79 int recveof, senteof;
80
81 int initconn; /* used for TCP forwarding, whether the channel has been
82 fully initialised */
83
84 int await_open; /* flag indicating whether we've sent an open request
85 for this channel (and are awaiting a confirmation
86 or failure). */
87
88 const struct ChanType* type;
89
90 };
91
92 struct ChanType {
93
94 int sepfds; /* Whether this channel has seperate pipes for in/out or not */
95 char *name;
96 int (*inithandler)(struct Channel*);
97 int (*checkclose)(struct Channel*);
98 void (*reqhandler)(struct Channel*);
99 void (*closehandler)(struct Channel*);
100
101 };
102
103 void chaninitialise(const struct ChanType *chantypes[]);
104 void chancleanup();
105 void setchannelfds(fd_set *readfd, fd_set *writefd);
106 void channelio(fd_set *readfd, fd_set *writefd);
107 struct Channel* getchannel();
108 struct Channel* newchannel(unsigned int remotechan,
109 const struct ChanType *type,
110 unsigned int transwindow, unsigned int transmaxpacket);
111
112 void recv_msg_channel_open();
113 void recv_msg_channel_request();
114 void send_msg_channel_failure(struct Channel *channel);
115 void send_msg_channel_success(struct Channel *channel);
116 void recv_msg_channel_data();
117 void recv_msg_channel_extended_data();
118 void recv_msg_channel_window_adjust();
119 void recv_msg_channel_close();
120 void recv_msg_channel_eof();
121
122 void common_recv_msg_channel_data(struct Channel *channel, int fd,
123 circbuffer * buf);
124
125 #ifdef DROPBEAR_CLIENT
126 extern const struct ChanType clichansess;
127 #endif
128
129 #if defined(USING_LISTENERS) || defined(DROPBEAR_CLIENT)
130 int send_msg_channel_open_init(int fd, const struct ChanType *type);
131 void recv_msg_channel_open_confirmation();
132 void recv_msg_channel_open_failure();
133 #endif
134
135 #endif /* _CHANNEL_H_ */