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

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

Determine local IP address, fill it in pseudo header.

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