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

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

Make active OPEN wait for connection establishment (or reset).

  • Property mode set to 100644
File size: 6.0 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 <bool.h>
40#include <fibril_synch.h>
41#include <sys/types.h>
42
43struct tcp_conn;
44
45typedef enum {
46 /** Listen */
47 st_listen,
48 /** Syn-sent */
49 st_syn_sent,
50 /** Syn-received */
51 st_syn_received,
52 /** Established */
53 st_established,
54 /** Fin-wait-1 */
55 st_fin_wait_1,
56 /** Fin-wait-2 */
57 st_fin_wait_2,
58 /** Close-wait */
59 st_close_wait,
60 /** Closing */
61 st_closing,
62 /** Last-ack */
63 st_last_ack,
64 /** Time-wait */
65 st_time_wait,
66 /** Closed */
67 st_closed
68} tcp_cstate_t;
69
70/** Error codes returned by TCP user calls (per the spec). */
71typedef enum {
72 /* OK */
73 TCP_EOK,
74 /* Connection aborted due to user timeout */
75 TCP_EABORTED,
76 /* Connection already exists */
77 TCP_EEXISTS,
78 /* Connection closing */
79 TCP_ECLOSING,
80 /* Connection does not exist */
81 TCP_ENOTEXIST,
82 /* Connection illegal for this process */
83 TCP_EILLEGAL,
84 /* Connection not open */
85 TCP_ENOTOPEN,
86 /* Connection reset */
87 TCP_ERESET,
88 /* Foreign socket unspecified */
89 TCP_EUNSPEC,
90 /* Insufficient resources */
91 TCP_ENORES,
92 /* Precedence not allowed */
93 TCP_EINVPREC,
94 /* Security/compartment not allowed */
95 TCP_EINVCOMP
96} tcp_error_t;
97
98typedef enum {
99 XF_PUSH = 0x1,
100 XF_URGENT = 0x2
101} xflags_t;
102
103typedef enum {
104 CTL_SYN = 0x1,
105 CTL_FIN = 0x2,
106 CTL_RST = 0x4,
107 CTL_ACK = 0x8
108} tcp_control_t;
109
110typedef struct {
111 uint32_t ipv4;
112} netaddr_t;
113
114typedef struct {
115 netaddr_t addr;
116 uint16_t port;
117} tcp_sock_t;
118
119typedef struct {
120 tcp_sock_t local;
121 tcp_sock_t foreign;
122} tcp_sockpair_t;
123
124/** Connection incoming segments queue */
125typedef struct {
126 struct tcp_conn *conn;
127 list_t list;
128} tcp_iqueue_t;
129
130/** Retransmission queue */
131typedef struct {
132 struct tcp_conn *conn;
133 list_t list;
134
135 /** Retransmission timer */
136 fibril_timer_t *timer;
137} tcp_tqueue_t;
138
139typedef struct tcp_conn {
140 char *name;
141 link_t link;
142
143 /** Connection identification (local and foreign socket) */
144 tcp_sockpair_t ident;
145
146 /** Connection state */
147 tcp_cstate_t cstate;
148 /** Protects @c cstate */
149 fibril_mutex_t cstate_lock;
150 /** Signalled when @c cstate changes */
151 fibril_condvar_t cstate_cv;
152
153 /** Set when FIN is removed from the retransmission queue */
154 bool fin_is_acked;
155
156 /** Queue of incoming segments */
157 tcp_iqueue_t incoming;
158
159 /** Retransmission queue */
160 tcp_tqueue_t retransmit;
161
162 /** Time-Wait timeout timer */
163 fibril_timer_t *tw_timer;
164
165 /** Receive buffer */
166 uint8_t *rcv_buf;
167 /** Receive buffer size */
168 size_t rcv_buf_size;
169 /** Receive buffer number of bytes used */
170 size_t rcv_buf_used;
171 /** Receive buffer contains FIN */
172 bool rcv_buf_fin;
173 /** Receive buffer lock */
174 fibril_mutex_t rcv_buf_lock;
175 /** Receive buffer CV. Broadcast when new data is inserted */
176 fibril_condvar_t rcv_buf_cv;
177
178 /** Send buffer */
179 uint8_t *snd_buf;
180 /** Send buffer size */
181 size_t snd_buf_size;
182 /** Send buffer number of bytes used */
183 size_t snd_buf_used;
184 /** Send buffer contains FIN */
185 bool snd_buf_fin;
186
187 /** Send unacknowledged */
188 uint32_t snd_una;
189 /** Send next */
190 uint32_t snd_nxt;
191 /** Send window */
192 uint32_t snd_wnd;
193 /** Send urgent pointer */
194 uint32_t snd_up;
195 /** Segment sequence number used for last window update */
196 uint32_t snd_wl1;
197 /** Segment acknowledgement number used for last window update */
198 uint32_t snd_wl2;
199 /** Initial send sequence number */
200 uint32_t iss;
201
202 /** Receive next */
203 uint32_t rcv_nxt;
204 /** Receive window */
205 uint32_t rcv_wnd;
206 /** Receive urgent pointer */
207 uint32_t rcv_up;
208 /** Initial receive sequence number */
209 uint32_t irs;
210} tcp_conn_t;
211
212typedef struct {
213 unsigned dummy;
214} tcp_conn_status_t;
215
216typedef struct {
217 /** SYN, FIN */
218 tcp_control_t ctrl;
219
220 /** Segment sequence number */
221 uint32_t seq;
222 /** Segment acknowledgement number */
223 uint32_t ack;
224 /** Segment length in sequence space */
225 uint32_t len;
226 /** Segment window */
227 uint32_t wnd;
228 /** Segment urgent pointer */
229 uint32_t up;
230
231 /** Segment data, may be moved when trimming segment */
232 void *data;
233 /** Segment data, original pointer used to free data */
234 void *dfptr;
235} tcp_segment_t;
236
237typedef enum {
238 ap_active,
239 ap_passive
240} acpass_t;
241
242typedef struct {
243 link_t link;
244 tcp_sockpair_t sp;
245 tcp_segment_t *seg;
246} tcp_rqueue_entry_t;
247
248/** NCSim queue entry */
249typedef struct {
250 link_t link;
251 suseconds_t delay;
252 tcp_sockpair_t sp;
253 tcp_segment_t *seg;
254} tcp_squeue_entry_t;
255
256typedef struct {
257 link_t link;
258 tcp_segment_t *seg;
259} tcp_iqueue_entry_t;
260
261/** Retransmission queue entry */
262typedef struct {
263 link_t link;
264 tcp_conn_t *conn;
265 tcp_segment_t *seg;
266} tcp_tqueue_entry_t;
267
268typedef enum {
269 cp_continue,
270 cp_done
271} cproc_t;
272
273#endif
274
275/** @}
276 */
Note: See TracBrowser for help on using the repository browser.