2 * Copyright (c) 2015 Jiri Svoboda
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
32 /** @file TCP type definitions
42 #include <fibril_synch.h>
46 #include <inet/addr.h>
47 #include <inet/endpoint.h>
51 /** Connection state */
77 /** Error codes returned by TCP user calls (per the spec). */
81 /* Connection aborted due to user timeout */
83 /* Connection already exists */
85 /* Connection closing */
87 /* Connection does not exist */
89 /* Connection illegal for this process */
91 /* Connection not open */
93 /* Connection reset */
95 /* Remote endpoint unspecified */
97 /* Insufficient resources */
99 /* Precedence not allowed */
101 /* Security/compartment not allowed */
106 /** Transfer flags */
112 /** Control message bits
114 * Note this is not the actual on-the-wire encoding
123 /** Connection incoming segments queue */
125 struct tcp_conn
*conn
;
129 /** Active or passive connection */
135 /** Flags for TCP open operation */
137 tcp_open_nonblock
= 1
140 typedef struct tcp_conn tcp_conn_t
;
142 /** Connection state change callback function */
143 typedef void (*tcp_cstate_cb_t
)(tcp_conn_t
*, void *);
145 /** Connection callbacks */
147 void (*cstate_change
)(tcp_conn_t
*, void *, tcp_cstate_t
);
148 void (*recv_data
)(tcp_conn_t
*, void *);
151 /** Data returned by Status user call */
153 /** Connection state */
161 /** Segment sequence number */
163 /** Segment acknowledgement number */
165 /** Segment length in sequence space */
167 /** Segment window */
169 /** Segment urgent pointer */
172 /** Segment data, may be moved when trimming segment */
174 /** Segment data, original pointer used to free data */
178 /** Receive queue entry */
183 } tcp_rqueue_entry_t
;
185 /** Receive queue callbacks */
187 /** Segment received */
188 void (*seg_received
)(inet_ep2_t
*, tcp_segment_t
*);
191 /** NCSim queue entry */
197 } tcp_squeue_entry_t
;
199 /** Incoming queue entry */
203 } tcp_iqueue_entry_t
;
205 /** Retransmission queue entry */
210 } tcp_tqueue_entry_t
;
212 /** Retransmission queue callbacks */
214 /** Segment received */
215 void (*transmit_seg
)(inet_ep2_t
*, tcp_segment_t
*);
218 /** Retransmission queue */
220 struct tcp_conn
*conn
;
223 /** Retransmission timer */
224 fibril_timer_t
*timer
;
235 /** Connection callbacks function */
237 /** Argument to @c cstate_cb */
240 /** Connection identification (local and remote endpoint) */
242 /** Connection is in association map */
245 /** Active or passive connection */
248 /** Protects access to connection structure */
250 /** Reference count */
251 atomic_refcount_t refcnt
;
253 /** Connection state */
255 /** True if connection was reset */
257 /** True if connection was deleted by user */
259 /** Signalled when @c cstate changes */
260 fibril_condvar_t cstate_cv
;
262 /** Set when FIN is removed from the retransmission queue */
265 /** Queue of incoming segments */
266 tcp_iqueue_t incoming
;
268 /** Retransmission queue */
269 tcp_tqueue_t retransmit
;
271 /** Time-Wait timeout timer */
272 fibril_timer_t
*tw_timer
;
274 /** Receive buffer */
276 /** Receive buffer size */
278 /** Receive buffer number of bytes used */
280 /** Receive buffer contains FIN */
282 /** Receive buffer CV. Broadcast when new data is inserted */
283 fibril_condvar_t rcv_buf_cv
;
287 /** Send buffer size */
289 /** Send buffer number of bytes used */
291 /** Send buffer contains FIN */
293 /** Send buffer CV. Broadcast when space is made available in buffer */
294 fibril_condvar_t snd_buf_cv
;
296 /** Send unacknowledged */
302 /** Send urgent pointer */
304 /** Segment sequence number used for last window update */
306 /** Segment acknowledgement number used for last window update */
308 /** Initial send sequence number */
313 /** Receive window */
315 /** Receive urgent pointer */
317 /** Initial receive sequence number */
321 /** Continuation of processing.
323 * When processing incoming segment, are we done or should we continue
333 /** Source address */
335 /** Destination address */
337 /** Encoded header */
339 /** Encoded header size */
347 /** TCP client connection */
348 typedef struct tcp_cconn
{
351 /** Connection ID for the client */
354 struct tcp_client
*client
;
358 /** TCP client listener */
359 typedef struct tcp_clst
{
360 /** Local endpoint */
364 /** Listener ID for the client */
367 struct tcp_client
*client
;
368 /** Link to tcp_client_t.clst */
373 typedef struct tcp_client
{
374 /** Client callback session */
376 /** Client's connections */
377 list_t cconn
; /* of tcp_cconn_t */
378 /** Client's listeners */
382 /** Internal loopback type */
386 /** Segment loopback */