source: mainline/uspace/srv/net/tl/tcp/tcp_type.h@ d9e14fa4

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since d9e14fa4 was d9e14fa4, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Implement RST processing.

  • Property mode set to 100644
File size: 6.7 KB
Line 
1/*
2 * Copyright (c) 2011 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup tcp
30 * @{
31 */
32/** @file TCP type definitions
33 */
34
35#ifndef TCP_TYPE_H
36#define TCP_TYPE_H
37
38#include <adt/list.h>
39#include <async.h>
40#include <bool.h>
41#include <fibril_synch.h>
42#include <socket_core.h>
43#include <sys/types.h>
44
45struct tcp_conn;
46
47typedef enum {
48 /** Listen */
49 st_listen,
50 /** Syn-sent */
51 st_syn_sent,
52 /** Syn-received */
53 st_syn_received,
54 /** Established */
55 st_established,
56 /** Fin-wait-1 */
57 st_fin_wait_1,
58 /** Fin-wait-2 */
59 st_fin_wait_2,
60 /** Close-wait */
61 st_close_wait,
62 /** Closing */
63 st_closing,
64 /** Last-ack */
65 st_last_ack,
66 /** Time-wait */
67 st_time_wait,
68 /** Closed */
69 st_closed
70} tcp_cstate_t;
71
72/** Error codes returned by TCP user calls (per the spec). */
73typedef enum {
74 /* OK */
75 TCP_EOK,
76 /* Connection aborted due to user timeout */
77 TCP_EABORTED,
78 /* Connection already exists */
79 TCP_EEXISTS,
80 /* Connection closing */
81 TCP_ECLOSING,
82 /* Connection does not exist */
83 TCP_ENOTEXIST,
84 /* Connection illegal for this process */
85 TCP_EILLEGAL,
86 /* Connection not open */
87 TCP_ENOTOPEN,
88 /* Connection reset */
89 TCP_ERESET,
90 /* Foreign socket unspecified */
91 TCP_EUNSPEC,
92 /* Insufficient resources */
93 TCP_ENORES,
94 /* Precedence not allowed */
95 TCP_EINVPREC,
96 /* Security/compartment not allowed */
97 TCP_EINVCOMP
98} tcp_error_t;
99
100typedef enum {
101 XF_PUSH = 0x1,
102 XF_URGENT = 0x2
103} xflags_t;
104
105typedef enum {
106 CTL_SYN = 0x1,
107 CTL_FIN = 0x2,
108 CTL_RST = 0x4,
109 CTL_ACK = 0x8
110} tcp_control_t;
111
112typedef struct {
113 uint32_t ipv4;
114} netaddr_t;
115
116typedef struct {
117 netaddr_t addr;
118 uint16_t port;
119} tcp_sock_t;
120
121enum netaddr {
122 TCP_IPV4_ANY = 0
123};
124
125enum tcp_port {
126 TCP_PORT_ANY = 0
127};
128
129typedef struct {
130 tcp_sock_t local;
131 tcp_sock_t foreign;
132} tcp_sockpair_t;
133
134/** Connection incoming segments queue */
135typedef struct {
136 struct tcp_conn *conn;
137 list_t list;
138} tcp_iqueue_t;
139
140/** Retransmission queue */
141typedef struct {
142 struct tcp_conn *conn;
143 list_t list;
144
145 /** Retransmission timer */
146 fibril_timer_t *timer;
147} tcp_tqueue_t;
148
149typedef enum {
150 ap_active,
151 ap_passive
152} acpass_t;
153
154typedef struct tcp_conn {
155 char *name;
156 link_t link;
157
158 /** Connection identification (local and foreign socket) */
159 tcp_sockpair_t ident;
160
161 /** Active or passive connection */
162 acpass_t ap;
163
164 /** Connection state */
165 tcp_cstate_t cstate;
166 /** True if connection was reset */
167 bool reset;
168 /** Protects @c cstate */
169 fibril_mutex_t cstate_lock;
170 /** Signalled when @c cstate changes */
171 fibril_condvar_t cstate_cv;
172
173 /** Set when FIN is removed from the retransmission queue */
174 bool fin_is_acked;
175
176 /** Queue of incoming segments */
177 tcp_iqueue_t incoming;
178
179 /** Retransmission queue */
180 tcp_tqueue_t retransmit;
181
182 /** Time-Wait timeout timer */
183 fibril_timer_t *tw_timer;
184
185 /** Receive buffer */
186 uint8_t *rcv_buf;
187 /** Receive buffer size */
188 size_t rcv_buf_size;
189 /** Receive buffer number of bytes used */
190 size_t rcv_buf_used;
191 /** Receive buffer contains FIN */
192 bool rcv_buf_fin;
193 /** Receive buffer lock */
194 fibril_mutex_t rcv_buf_lock;
195 /** Receive buffer CV. Broadcast when new data is inserted */
196 fibril_condvar_t rcv_buf_cv;
197
198 /** Send buffer */
199 uint8_t *snd_buf;
200 /** Send buffer size */
201 size_t snd_buf_size;
202 /** Send buffer number of bytes used */
203 size_t snd_buf_used;
204 /** Send buffer contains FIN */
205 bool snd_buf_fin;
206
207 /** Send unacknowledged */
208 uint32_t snd_una;
209 /** Send next */
210 uint32_t snd_nxt;
211 /** Send window */
212 uint32_t snd_wnd;
213 /** Send urgent pointer */
214 uint32_t snd_up;
215 /** Segment sequence number used for last window update */
216 uint32_t snd_wl1;
217 /** Segment acknowledgement number used for last window update */
218 uint32_t snd_wl2;
219 /** Initial send sequence number */
220 uint32_t iss;
221
222 /** Receive next */
223 uint32_t rcv_nxt;
224 /** Receive window */
225 uint32_t rcv_wnd;
226 /** Receive urgent pointer */
227 uint32_t rcv_up;
228 /** Initial receive sequence number */
229 uint32_t irs;
230} tcp_conn_t;
231
232typedef struct {
233 unsigned dummy;
234} tcp_conn_status_t;
235
236typedef struct {
237 /** SYN, FIN */
238 tcp_control_t ctrl;
239
240 /** Segment sequence number */
241 uint32_t seq;
242 /** Segment acknowledgement number */
243 uint32_t ack;
244 /** Segment length in sequence space */
245 uint32_t len;
246 /** Segment window */
247 uint32_t wnd;
248 /** Segment urgent pointer */
249 uint32_t up;
250
251 /** Segment data, may be moved when trimming segment */
252 void *data;
253 /** Segment data, original pointer used to free data */
254 void *dfptr;
255} tcp_segment_t;
256
257
258typedef struct {
259 link_t link;
260 tcp_sockpair_t sp;
261 tcp_segment_t *seg;
262} tcp_rqueue_entry_t;
263
264/** NCSim queue entry */
265typedef struct {
266 link_t link;
267 suseconds_t delay;
268 tcp_sockpair_t sp;
269 tcp_segment_t *seg;
270} tcp_squeue_entry_t;
271
272typedef struct {
273 link_t link;
274 tcp_segment_t *seg;
275} tcp_iqueue_entry_t;
276
277/** Retransmission queue entry */
278typedef struct {
279 link_t link;
280 tcp_conn_t *conn;
281 tcp_segment_t *seg;
282} tcp_tqueue_entry_t;
283
284typedef enum {
285 cp_continue,
286 cp_done
287} cproc_t;
288
289/** Encoded PDU */
290typedef struct {
291 /** Source address */
292 netaddr_t src_addr;
293 /** Destination address */
294 netaddr_t dest_addr;
295
296 /** Encoded header */
297 void *header;
298 /** Encoded header size */
299 size_t header_size;
300 /** Text */
301 void *text;
302 /** Text size */
303 size_t text_size;
304} tcp_pdu_t;
305
306typedef struct {
307 async_sess_t *sess;
308 socket_cores_t sockets;
309} tcp_client_t;
310
311typedef struct {
312 /** Client */
313 tcp_client_t *client;
314 /** Connection */
315 tcp_conn_t *conn;
316 /** Local address */
317 netaddr_t laddr;
318} tcp_sockdata_t;
319
320#endif
321
322/** @}
323 */
Note: See TracBrowser for help on using the repository browser.