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

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

Revamp connection synchronization.

  • Property mode set to 100644
File size: 6.9 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 /** Protects access to connection structure */
165 fibril_mutex_t lock;
166 /** Reference count */
167 atomic_t refcnt;
168
169 /** Connection state */
170 tcp_cstate_t cstate;
171 /** True if connection was reset */
172 bool reset;
173 /** True if connection was deleted by user */
174 bool deleted;
175 /** Signalled when @c cstate changes */
176 fibril_condvar_t cstate_cv;
177
178 /** Set when FIN is removed from the retransmission queue */
179 bool fin_is_acked;
180
181 /** Queue of incoming segments */
182 tcp_iqueue_t incoming;
183
184 /** Retransmission queue */
185 tcp_tqueue_t retransmit;
186
187 /** Time-Wait timeout timer */
188 fibril_timer_t *tw_timer;
189
190 /** Receive buffer */
191 uint8_t *rcv_buf;
192 /** Receive buffer size */
193 size_t rcv_buf_size;
194 /** Receive buffer number of bytes used */
195 size_t rcv_buf_used;
196 /** Receive buffer contains FIN */
197 bool rcv_buf_fin;
198 /** Receive buffer CV. Broadcast when new data is inserted */
199 fibril_condvar_t rcv_buf_cv;
200
201 /** Send buffer */
202 uint8_t *snd_buf;
203 /** Send buffer size */
204 size_t snd_buf_size;
205 /** Send buffer number of bytes used */
206 size_t snd_buf_used;
207 /** Send buffer contains FIN */
208 bool snd_buf_fin;
209 /** Send buffer CV. Broadcast when space is made available in buffer */
210 fibril_condvar_t snd_buf_cv;
211
212 /** Send unacknowledged */
213 uint32_t snd_una;
214 /** Send next */
215 uint32_t snd_nxt;
216 /** Send window */
217 uint32_t snd_wnd;
218 /** Send urgent pointer */
219 uint32_t snd_up;
220 /** Segment sequence number used for last window update */
221 uint32_t snd_wl1;
222 /** Segment acknowledgement number used for last window update */
223 uint32_t snd_wl2;
224 /** Initial send sequence number */
225 uint32_t iss;
226
227 /** Receive next */
228 uint32_t rcv_nxt;
229 /** Receive window */
230 uint32_t rcv_wnd;
231 /** Receive urgent pointer */
232 uint32_t rcv_up;
233 /** Initial receive sequence number */
234 uint32_t irs;
235} tcp_conn_t;
236
237typedef struct {
238 unsigned dummy;
239} tcp_conn_status_t;
240
241typedef struct {
242 /** SYN, FIN */
243 tcp_control_t ctrl;
244
245 /** Segment sequence number */
246 uint32_t seq;
247 /** Segment acknowledgement number */
248 uint32_t ack;
249 /** Segment length in sequence space */
250 uint32_t len;
251 /** Segment window */
252 uint32_t wnd;
253 /** Segment urgent pointer */
254 uint32_t up;
255
256 /** Segment data, may be moved when trimming segment */
257 void *data;
258 /** Segment data, original pointer used to free data */
259 void *dfptr;
260} tcp_segment_t;
261
262
263typedef struct {
264 link_t link;
265 tcp_sockpair_t sp;
266 tcp_segment_t *seg;
267} tcp_rqueue_entry_t;
268
269/** NCSim queue entry */
270typedef struct {
271 link_t link;
272 suseconds_t delay;
273 tcp_sockpair_t sp;
274 tcp_segment_t *seg;
275} tcp_squeue_entry_t;
276
277typedef struct {
278 link_t link;
279 tcp_segment_t *seg;
280} tcp_iqueue_entry_t;
281
282/** Retransmission queue entry */
283typedef struct {
284 link_t link;
285 tcp_conn_t *conn;
286 tcp_segment_t *seg;
287} tcp_tqueue_entry_t;
288
289typedef enum {
290 cp_continue,
291 cp_done
292} cproc_t;
293
294/** Encoded PDU */
295typedef struct {
296 /** Source address */
297 netaddr_t src_addr;
298 /** Destination address */
299 netaddr_t dest_addr;
300
301 /** Encoded header */
302 void *header;
303 /** Encoded header size */
304 size_t header_size;
305 /** Text */
306 void *text;
307 /** Text size */
308 size_t text_size;
309} tcp_pdu_t;
310
311typedef struct {
312 async_sess_t *sess;
313 socket_cores_t sockets;
314} tcp_client_t;
315
316typedef struct {
317 /** Client */
318 tcp_client_t *client;
319 /** Connection */
320 tcp_conn_t *conn;
321 /** Local address */
322 netaddr_t laddr;
323} tcp_sockdata_t;
324
325#endif
326
327/** @}
328 */
Note: See TracBrowser for help on using the repository browser.