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

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

TCP retransmission (WIP). Allow setting timer in timer handler.
Simulate packet drop. Fixes.

  • Property mode set to 100644
File size: 5.2 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
70typedef enum {
71 XF_PUSH = 0x1,
72 XF_URGENT = 0x2
73} xflags_t;
74
75typedef enum {
76 CTL_SYN = 0x1,
77 CTL_FIN = 0x2,
78 CTL_RST = 0x4,
79 CTL_ACK = 0x8
80} tcp_control_t;
81
82typedef struct {
83 uint32_t ipv4;
84} netaddr_t;
85
86typedef struct {
87 netaddr_t addr;
88 uint16_t port;
89} tcp_sock_t;
90
91typedef struct {
92 tcp_sock_t local;
93 tcp_sock_t foreign;
94} tcp_sockpair_t;
95
96/** Connection incoming segments queue */
97typedef struct {
98 struct tcp_conn *conn;
99 list_t list;
100} tcp_iqueue_t;
101
102/** Retransmission queue */
103typedef struct {
104 struct tcp_conn *conn;
105 list_t list;
106
107 /** Retransmission timer */
108 fibril_timer_t *timer;
109} tcp_tqueue_t;
110
111typedef struct tcp_conn {
112 char *name;
113 link_t link;
114
115 /** Connection identification (local and foreign socket) */
116 tcp_sockpair_t ident;
117
118 /** Connection state */
119 tcp_cstate_t cstate;
120
121 /** Set when FIN is removed from the retransmission queue */
122 bool fin_is_acked;
123
124 /** Queue of incoming segments */
125 tcp_iqueue_t incoming;
126
127 /** Retransmission queue */
128 tcp_tqueue_t retransmit;
129
130 /** Time-Wait timeout timer */
131 fibril_timer_t *tw_timer;
132
133 /** Receive buffer */
134 uint8_t *rcv_buf;
135 /** Receive buffer size */
136 size_t rcv_buf_size;
137 /** Receive buffer number of bytes used */
138 size_t rcv_buf_used;
139 /** Receive buffer contains FIN */
140 bool rcv_buf_fin;
141 /** Receive buffer lock */
142 fibril_mutex_t rcv_buf_lock;
143 /** Receive buffer CV. Broadcast when new data is inserted */
144 fibril_condvar_t rcv_buf_cv;
145
146 /** Send buffer */
147 uint8_t *snd_buf;
148 /** Send buffer size */
149 size_t snd_buf_size;
150 /** Send buffer number of bytes used */
151 size_t snd_buf_used;
152 /** Send buffer contains FIN */
153 bool snd_buf_fin;
154
155 /** Send unacknowledged */
156 uint32_t snd_una;
157 /** Send next */
158 uint32_t snd_nxt;
159 /** Send window */
160 uint32_t snd_wnd;
161 /** Send urgent pointer */
162 uint32_t snd_up;
163 /** Segment sequence number used for last window update */
164 uint32_t snd_wl1;
165 /** Segment acknowledgement number used for last window update */
166 uint32_t snd_wl2;
167 /** Initial send sequence number */
168 uint32_t iss;
169
170 /** Receive next */
171 uint32_t rcv_nxt;
172 /** Receive window */
173 uint32_t rcv_wnd;
174 /** Receive urgent pointer */
175 uint32_t rcv_up;
176 /** Initial receive sequence number */
177 uint32_t irs;
178} tcp_conn_t;
179
180typedef struct {
181 unsigned dummy;
182} tcp_conn_status_t;
183
184typedef struct {
185 /** SYN, FIN */
186 tcp_control_t ctrl;
187
188 /** Segment sequence number */
189 uint32_t seq;
190 /** Segment acknowledgement number */
191 uint32_t ack;
192 /** Segment length in sequence space */
193 uint32_t len;
194 /** Segment window */
195 uint32_t wnd;
196 /** Segment urgent pointer */
197 uint32_t up;
198
199 /** Segment data, may be moved when trimming segment */
200 void *data;
201 /** Segment data, original pointer used to free data */
202 void *dfptr;
203} tcp_segment_t;
204
205typedef enum {
206 ap_active,
207 ap_passive
208} acpass_t;
209
210typedef struct {
211 link_t link;
212 tcp_sockpair_t sp;
213 tcp_segment_t *seg;
214} tcp_rqueue_entry_t;
215
216/** NCSim queue entry */
217typedef struct {
218 link_t link;
219 suseconds_t delay;
220 tcp_sockpair_t sp;
221 tcp_segment_t *seg;
222} tcp_squeue_entry_t;
223
224typedef struct {
225 link_t link;
226 tcp_segment_t *seg;
227} tcp_iqueue_entry_t;
228
229/** Retransmission queue entry */
230typedef struct {
231 link_t link;
232 tcp_conn_t *conn;
233 tcp_segment_t *seg;
234} tcp_tqueue_entry_t;
235
236typedef enum {
237 cp_continue,
238 cp_done
239} cproc_t;
240
241#endif
242
243/** @}
244 */
Note: See TracBrowser for help on using the repository browser.