1 | /*
|
---|
2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without modification,
|
---|
6 | * are permitted provided that the following conditions are met:
|
---|
7 | *
|
---|
8 | * 1. Redistributions of source code must retain the above copyright notice,
|
---|
9 | * this list of conditions and the following disclaimer.
|
---|
10 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
11 | * this list of conditions and the following disclaimer in the documentation
|
---|
12 | * and/or other materials provided with the distribution.
|
---|
13 | * 3. The name of the author may not be used to endorse or promote products
|
---|
14 | * derived from this software without specific prior written permission.
|
---|
15 | *
|
---|
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
---|
17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
---|
18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
---|
19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
---|
21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
---|
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
---|
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
---|
24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
---|
25 | * OF SUCH DAMAGE.
|
---|
26 | *
|
---|
27 | * This file is part of the lwIP TCP/IP stack.
|
---|
28 | *
|
---|
29 | * Author: Adam Dunkels <adam@sics.se>
|
---|
30 | *
|
---|
31 | */
|
---|
32 | #ifndef __LWIP_TCP_IMPL_H__
|
---|
33 | #define __LWIP_TCP_IMPL_H__
|
---|
34 |
|
---|
35 | #include "lwip/opt.h"
|
---|
36 |
|
---|
37 | #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
|
---|
38 |
|
---|
39 | #include "lwip/tcp.h"
|
---|
40 | #include "lwip/mem.h"
|
---|
41 | #include "lwip/pbuf.h"
|
---|
42 | #include "lwip/ip.h"
|
---|
43 | #include "lwip/icmp.h"
|
---|
44 | #include "lwip/err.h"
|
---|
45 |
|
---|
46 | #ifdef __cplusplus
|
---|
47 | extern "C" {
|
---|
48 | #endif
|
---|
49 |
|
---|
50 | /* Functions for interfacing with TCP: */
|
---|
51 |
|
---|
52 | /* Lower layer interface to TCP: */
|
---|
53 | void tcp_init (void); /* Initialize this module. */
|
---|
54 | void tcp_tmr (void); /* Must be called every
|
---|
55 | TCP_TMR_INTERVAL
|
---|
56 | ms. (Typically 250 ms). */
|
---|
57 | /* It is also possible to call these two functions at the right
|
---|
58 | intervals (instead of calling tcp_tmr()). */
|
---|
59 | void tcp_slowtmr (void);
|
---|
60 | void tcp_fasttmr (void);
|
---|
61 |
|
---|
62 |
|
---|
63 | /* Only used by IP to pass a TCP segment to TCP: */
|
---|
64 | void tcp_input (struct pbuf *p, struct netif *inp);
|
---|
65 | /* Used within the TCP code only: */
|
---|
66 | struct tcp_pcb * tcp_alloc (u8_t prio);
|
---|
67 | void tcp_abandon (struct tcp_pcb *pcb, int reset);
|
---|
68 | err_t tcp_send_empty_ack(struct tcp_pcb *pcb);
|
---|
69 | void tcp_rexmit (struct tcp_pcb *pcb);
|
---|
70 | void tcp_rexmit_rto (struct tcp_pcb *pcb);
|
---|
71 | void tcp_rexmit_fast (struct tcp_pcb *pcb);
|
---|
72 | u32_t tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb);
|
---|
73 | err_t tcp_process_refused_data(struct tcp_pcb *pcb);
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * This is the Nagle algorithm: try to combine user data to send as few TCP
|
---|
77 | * segments as possible. Only send if
|
---|
78 | * - no previously transmitted data on the connection remains unacknowledged or
|
---|
79 | * - the TF_NODELAY flag is set (nagle algorithm turned off for this pcb) or
|
---|
80 | * - the only unsent segment is at least pcb->mss bytes long (or there is more
|
---|
81 | * than one unsent segment - with lwIP, this can happen although unsent->len < mss)
|
---|
82 | * - or if we are in fast-retransmit (TF_INFR)
|
---|
83 | */
|
---|
84 | #define tcp_do_output_nagle(tpcb) ((((tpcb)->unacked == NULL) || \
|
---|
85 | ((tpcb)->flags & (TF_NODELAY | TF_INFR)) || \
|
---|
86 | (((tpcb)->unsent != NULL) && (((tpcb)->unsent->next != NULL) || \
|
---|
87 | ((tpcb)->unsent->len >= (tpcb)->mss))) || \
|
---|
88 | ((tcp_sndbuf(tpcb) == 0) || (tcp_sndqueuelen(tpcb) >= TCP_SND_QUEUELEN)) \
|
---|
89 | ) ? 1 : 0)
|
---|
90 | #define tcp_output_nagle(tpcb) (tcp_do_output_nagle(tpcb) ? tcp_output(tpcb) : ERR_OK)
|
---|
91 |
|
---|
92 |
|
---|
93 | #define TCP_SEQ_LT(a,b) ((s32_t)((u32_t)(a) - (u32_t)(b)) < 0)
|
---|
94 | #define TCP_SEQ_LEQ(a,b) ((s32_t)((u32_t)(a) - (u32_t)(b)) <= 0)
|
---|
95 | #define TCP_SEQ_GT(a,b) ((s32_t)((u32_t)(a) - (u32_t)(b)) > 0)
|
---|
96 | #define TCP_SEQ_GEQ(a,b) ((s32_t)((u32_t)(a) - (u32_t)(b)) >= 0)
|
---|
97 | /* is b<=a<=c? */
|
---|
98 | #if 0 /* see bug #10548 */
|
---|
99 | #define TCP_SEQ_BETWEEN(a,b,c) ((c)-(b) >= (a)-(b))
|
---|
100 | #endif
|
---|
101 | #define TCP_SEQ_BETWEEN(a,b,c) (TCP_SEQ_GEQ(a,b) && TCP_SEQ_LEQ(a,c))
|
---|
102 | #define TCP_FIN 0x01U
|
---|
103 | #define TCP_SYN 0x02U
|
---|
104 | #define TCP_RST 0x04U
|
---|
105 | #define TCP_PSH 0x08U
|
---|
106 | #define TCP_ACK 0x10U
|
---|
107 | #define TCP_URG 0x20U
|
---|
108 | #define TCP_ECE 0x40U
|
---|
109 | #define TCP_CWR 0x80U
|
---|
110 |
|
---|
111 | #define TCP_FLAGS 0x3fU
|
---|
112 |
|
---|
113 | /* Length of the TCP header, excluding options. */
|
---|
114 | #define TCP_HLEN 20
|
---|
115 |
|
---|
116 | #ifndef TCP_TMR_INTERVAL
|
---|
117 | #define TCP_TMR_INTERVAL 250 /* The TCP timer interval in milliseconds. */
|
---|
118 | #endif /* TCP_TMR_INTERVAL */
|
---|
119 |
|
---|
120 | #ifndef TCP_FAST_INTERVAL
|
---|
121 | #define TCP_FAST_INTERVAL TCP_TMR_INTERVAL /* the fine grained timeout in milliseconds */
|
---|
122 | #endif /* TCP_FAST_INTERVAL */
|
---|
123 |
|
---|
124 | #ifndef TCP_SLOW_INTERVAL
|
---|
125 | #define TCP_SLOW_INTERVAL (2*TCP_TMR_INTERVAL) /* the coarse grained timeout in milliseconds */
|
---|
126 | #endif /* TCP_SLOW_INTERVAL */
|
---|
127 |
|
---|
128 | #define TCP_FIN_WAIT_TIMEOUT 20000 /* milliseconds */
|
---|
129 | #define TCP_SYN_RCVD_TIMEOUT 20000 /* milliseconds */
|
---|
130 |
|
---|
131 | #define TCP_OOSEQ_TIMEOUT 6U /* x RTO */
|
---|
132 |
|
---|
133 | #ifndef TCP_MSL
|
---|
134 | #define TCP_MSL 60000UL /* The maximum segment lifetime in milliseconds */
|
---|
135 | #endif
|
---|
136 |
|
---|
137 | /* Keepalive values, compliant with RFC 1122. Don't change this unless you know what you're doing */
|
---|
138 | #ifndef TCP_KEEPIDLE_DEFAULT
|
---|
139 | #define TCP_KEEPIDLE_DEFAULT 7200000UL /* Default KEEPALIVE timer in milliseconds */
|
---|
140 | #endif
|
---|
141 |
|
---|
142 | #ifndef TCP_KEEPINTVL_DEFAULT
|
---|
143 | #define TCP_KEEPINTVL_DEFAULT 75000UL /* Default Time between KEEPALIVE probes in milliseconds */
|
---|
144 | #endif
|
---|
145 |
|
---|
146 | #ifndef TCP_KEEPCNT_DEFAULT
|
---|
147 | #define TCP_KEEPCNT_DEFAULT 9U /* Default Counter for KEEPALIVE probes */
|
---|
148 | #endif
|
---|
149 |
|
---|
150 | #define TCP_MAXIDLE TCP_KEEPCNT_DEFAULT * TCP_KEEPINTVL_DEFAULT /* Maximum KEEPALIVE probe time */
|
---|
151 |
|
---|
152 | /* Fields are (of course) in network byte order.
|
---|
153 | * Some fields are converted to host byte order in tcp_input().
|
---|
154 | */
|
---|
155 | #ifdef PACK_STRUCT_USE_INCLUDES
|
---|
156 | # include "arch/bpstruct.h"
|
---|
157 | #endif
|
---|
158 | PACK_STRUCT_BEGIN
|
---|
159 | struct tcp_hdr {
|
---|
160 | PACK_STRUCT_FIELD(u16_t src);
|
---|
161 | PACK_STRUCT_FIELD(u16_t dest);
|
---|
162 | PACK_STRUCT_FIELD(u32_t seqno);
|
---|
163 | PACK_STRUCT_FIELD(u32_t ackno);
|
---|
164 | PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags);
|
---|
165 | PACK_STRUCT_FIELD(u16_t wnd);
|
---|
166 | PACK_STRUCT_FIELD(u16_t chksum);
|
---|
167 | PACK_STRUCT_FIELD(u16_t urgp);
|
---|
168 | } PACK_STRUCT_STRUCT;
|
---|
169 | PACK_STRUCT_END
|
---|
170 | #ifdef PACK_STRUCT_USE_INCLUDES
|
---|
171 | # include "arch/epstruct.h"
|
---|
172 | #endif
|
---|
173 |
|
---|
174 | #define TCPH_HDRLEN(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 12)
|
---|
175 | #define TCPH_FLAGS(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS)
|
---|
176 |
|
---|
177 | #define TCPH_HDRLEN_SET(phdr, len) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | TCPH_FLAGS(phdr))
|
---|
178 | #define TCPH_FLAGS_SET(phdr, flags) (phdr)->_hdrlen_rsvd_flags = (((phdr)->_hdrlen_rsvd_flags & PP_HTONS((u16_t)(~(u16_t)(TCP_FLAGS)))) | htons(flags))
|
---|
179 | #define TCPH_HDRLEN_FLAGS_SET(phdr, len, flags) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | (flags))
|
---|
180 |
|
---|
181 | #define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | htons(flags))
|
---|
182 | #define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = htons(ntohs((phdr)->_hdrlen_rsvd_flags) | (TCPH_FLAGS(phdr) & ~(flags)) )
|
---|
183 |
|
---|
184 | #define TCP_TCPLEN(seg) ((seg)->len + ((TCPH_FLAGS((seg)->tcphdr) & (TCP_FIN | TCP_SYN)) != 0))
|
---|
185 |
|
---|
186 | /** Flags used on input processing, not on pcb->flags
|
---|
187 | */
|
---|
188 | #define TF_RESET (u8_t)0x08U /* Connection was reset. */
|
---|
189 | #define TF_CLOSED (u8_t)0x10U /* Connection was sucessfully closed. */
|
---|
190 | #define TF_GOT_FIN (u8_t)0x20U /* Connection was closed by the remote end. */
|
---|
191 |
|
---|
192 |
|
---|
193 | #if LWIP_EVENT_API
|
---|
194 |
|
---|
195 | #define TCP_EVENT_ACCEPT(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
|
---|
196 | LWIP_EVENT_ACCEPT, NULL, 0, err)
|
---|
197 | #define TCP_EVENT_SENT(pcb,space,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
|
---|
198 | LWIP_EVENT_SENT, NULL, space, ERR_OK)
|
---|
199 | #define TCP_EVENT_RECV(pcb,p,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
|
---|
200 | LWIP_EVENT_RECV, (p), 0, (err))
|
---|
201 | #define TCP_EVENT_CLOSED(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
|
---|
202 | LWIP_EVENT_RECV, NULL, 0, ERR_OK)
|
---|
203 | #define TCP_EVENT_CONNECTED(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
|
---|
204 | LWIP_EVENT_CONNECTED, NULL, 0, (err))
|
---|
205 | #define TCP_EVENT_POLL(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
|
---|
206 | LWIP_EVENT_POLL, NULL, 0, ERR_OK)
|
---|
207 | #define TCP_EVENT_ERR(errf,arg,err) lwip_tcp_event((arg), NULL, \
|
---|
208 | LWIP_EVENT_ERR, NULL, 0, (err))
|
---|
209 |
|
---|
210 | #else /* LWIP_EVENT_API */
|
---|
211 |
|
---|
212 | #define TCP_EVENT_ACCEPT(pcb,err,ret) \
|
---|
213 | do { \
|
---|
214 | if((pcb)->accept != NULL) \
|
---|
215 | (ret) = (pcb)->accept((pcb)->callback_arg,(pcb),(err)); \
|
---|
216 | else (ret) = ERR_ARG; \
|
---|
217 | } while (0)
|
---|
218 |
|
---|
219 | #define TCP_EVENT_SENT(pcb,space,ret) \
|
---|
220 | do { \
|
---|
221 | if((pcb)->sent != NULL) \
|
---|
222 | (ret) = (pcb)->sent((pcb)->callback_arg,(pcb),(space)); \
|
---|
223 | else (ret) = ERR_OK; \
|
---|
224 | } while (0)
|
---|
225 |
|
---|
226 | #define TCP_EVENT_RECV(pcb,p,err,ret) \
|
---|
227 | do { \
|
---|
228 | if((pcb)->recv != NULL) { \
|
---|
229 | (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),(p),(err));\
|
---|
230 | } else { \
|
---|
231 | (ret) = tcp_recv_null(NULL, (pcb), (p), (err)); \
|
---|
232 | } \
|
---|
233 | } while (0)
|
---|
234 |
|
---|
235 | #define TCP_EVENT_CLOSED(pcb,ret) \
|
---|
236 | do { \
|
---|
237 | if(((pcb)->recv != NULL)) { \
|
---|
238 | (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),NULL,ERR_OK);\
|
---|
239 | } else { \
|
---|
240 | (ret) = ERR_OK; \
|
---|
241 | } \
|
---|
242 | } while (0)
|
---|
243 |
|
---|
244 | #define TCP_EVENT_CONNECTED(pcb,err,ret) \
|
---|
245 | do { \
|
---|
246 | if((pcb)->connected != NULL) \
|
---|
247 | (ret) = (pcb)->connected((pcb)->callback_arg,(pcb),(err)); \
|
---|
248 | else (ret) = ERR_OK; \
|
---|
249 | } while (0)
|
---|
250 |
|
---|
251 | #define TCP_EVENT_POLL(pcb,ret) \
|
---|
252 | do { \
|
---|
253 | if((pcb)->poll != NULL) \
|
---|
254 | (ret) = (pcb)->poll((pcb)->callback_arg,(pcb)); \
|
---|
255 | else (ret) = ERR_OK; \
|
---|
256 | } while (0)
|
---|
257 |
|
---|
258 | #define TCP_EVENT_ERR(errf,arg,err) \
|
---|
259 | do { \
|
---|
260 | if((errf) != NULL) \
|
---|
261 | (errf)((arg),(err)); \
|
---|
262 | } while (0)
|
---|
263 |
|
---|
264 | #endif /* LWIP_EVENT_API */
|
---|
265 |
|
---|
266 | /** Enabled extra-check for TCP_OVERSIZE if LWIP_DEBUG is enabled */
|
---|
267 | #if TCP_OVERSIZE && defined(LWIP_DEBUG)
|
---|
268 | #define TCP_OVERSIZE_DBGCHECK 1
|
---|
269 | #else
|
---|
270 | #define TCP_OVERSIZE_DBGCHECK 0
|
---|
271 | #endif
|
---|
272 |
|
---|
273 | /** Don't generate checksum on copy if CHECKSUM_GEN_TCP is disabled */
|
---|
274 | #define TCP_CHECKSUM_ON_COPY (LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_TCP)
|
---|
275 |
|
---|
276 | /* This structure represents a TCP segment on the unsent, unacked and ooseq queues */
|
---|
277 | struct tcp_seg {
|
---|
278 | struct tcp_seg *next; /* used when putting segements on a queue */
|
---|
279 | struct pbuf *p; /* buffer containing data + TCP header */
|
---|
280 | u16_t len; /* the TCP length of this segment */
|
---|
281 | #if TCP_OVERSIZE_DBGCHECK
|
---|
282 | u16_t oversize_left; /* Extra bytes available at the end of the last
|
---|
283 | pbuf in unsent (used for asserting vs.
|
---|
284 | tcp_pcb.unsent_oversized only) */
|
---|
285 | #endif /* TCP_OVERSIZE_DBGCHECK */
|
---|
286 | #if TCP_CHECKSUM_ON_COPY
|
---|
287 | u16_t chksum;
|
---|
288 | u8_t chksum_swapped;
|
---|
289 | #endif /* TCP_CHECKSUM_ON_COPY */
|
---|
290 | u8_t flags;
|
---|
291 | #define TF_SEG_OPTS_MSS (u8_t)0x01U /* Include MSS option. */
|
---|
292 | #define TF_SEG_OPTS_TS (u8_t)0x02U /* Include timestamp option. */
|
---|
293 | #define TF_SEG_DATA_CHECKSUMMED (u8_t)0x04U /* ALL data (not the header) is
|
---|
294 | checksummed into 'chksum' */
|
---|
295 | struct tcp_hdr *tcphdr; /* the TCP header */
|
---|
296 | };
|
---|
297 |
|
---|
298 | #define LWIP_TCP_OPT_LENGTH(flags) \
|
---|
299 | (flags & TF_SEG_OPTS_MSS ? 4 : 0) + \
|
---|
300 | (flags & TF_SEG_OPTS_TS ? 12 : 0)
|
---|
301 |
|
---|
302 | /** This returns a TCP header option for MSS in an u32_t */
|
---|
303 | #define TCP_BUILD_MSS_OPTION(mss) htonl(0x02040000 | ((mss) & 0xFFFF))
|
---|
304 |
|
---|
305 | /* Global variables: */
|
---|
306 | extern struct tcp_pcb *tcp_input_pcb;
|
---|
307 | extern u32_t tcp_ticks;
|
---|
308 | extern u8_t tcp_active_pcbs_changed;
|
---|
309 |
|
---|
310 | /* The TCP PCB lists. */
|
---|
311 | union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */
|
---|
312 | struct tcp_pcb_listen *listen_pcbs;
|
---|
313 | struct tcp_pcb *pcbs;
|
---|
314 | };
|
---|
315 | extern struct tcp_pcb *tcp_bound_pcbs;
|
---|
316 | extern union tcp_listen_pcbs_t tcp_listen_pcbs;
|
---|
317 | extern struct tcp_pcb *tcp_active_pcbs; /* List of all TCP PCBs that are in a
|
---|
318 | state in which they accept or send
|
---|
319 | data. */
|
---|
320 | extern struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in TIME-WAIT. */
|
---|
321 |
|
---|
322 | extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */
|
---|
323 |
|
---|
324 | /* Axioms about the above lists:
|
---|
325 | 1) Every TCP PCB that is not CLOSED is in one of the lists.
|
---|
326 | 2) A PCB is only in one of the lists.
|
---|
327 | 3) All PCBs in the tcp_listen_pcbs list is in LISTEN state.
|
---|
328 | 4) All PCBs in the tcp_tw_pcbs list is in TIME-WAIT state.
|
---|
329 | */
|
---|
330 | /* Define two macros, TCP_REG and TCP_RMV that registers a TCP PCB
|
---|
331 | with a PCB list or removes a PCB from a list, respectively. */
|
---|
332 | #ifndef TCP_DEBUG_PCB_LISTS
|
---|
333 | #define TCP_DEBUG_PCB_LISTS 0
|
---|
334 | #endif
|
---|
335 | #if TCP_DEBUG_PCB_LISTS
|
---|
336 | #define TCP_REG(pcbs, npcb) do {\
|
---|
337 | LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", (npcb), (npcb)->local_port)); \
|
---|
338 | for(tcp_tmp_pcb = *(pcbs); \
|
---|
339 | tcp_tmp_pcb != NULL; \
|
---|
340 | tcp_tmp_pcb = tcp_tmp_pcb->next) { \
|
---|
341 | LWIP_ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != (npcb)); \
|
---|
342 | } \
|
---|
343 | LWIP_ASSERT("TCP_REG: pcb->state != CLOSED", ((pcbs) == &tcp_bound_pcbs) || ((npcb)->state != CLOSED)); \
|
---|
344 | (npcb)->next = *(pcbs); \
|
---|
345 | LWIP_ASSERT("TCP_REG: npcb->next != npcb", (npcb)->next != (npcb)); \
|
---|
346 | *(pcbs) = (npcb); \
|
---|
347 | LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \
|
---|
348 | tcp_timer_needed(); \
|
---|
349 | } while(0)
|
---|
350 | #define TCP_RMV(pcbs, npcb) do { \
|
---|
351 | LWIP_ASSERT("TCP_RMV: pcbs != NULL", *(pcbs) != NULL); \
|
---|
352 | LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", (npcb), *(pcbs))); \
|
---|
353 | if(*(pcbs) == (npcb)) { \
|
---|
354 | *(pcbs) = (*pcbs)->next; \
|
---|
355 | } else for(tcp_tmp_pcb = *(pcbs); tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \
|
---|
356 | if(tcp_tmp_pcb->next == (npcb)) { \
|
---|
357 | tcp_tmp_pcb->next = (npcb)->next; \
|
---|
358 | break; \
|
---|
359 | } \
|
---|
360 | } \
|
---|
361 | (npcb)->next = NULL; \
|
---|
362 | LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \
|
---|
363 | LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", (npcb), *(pcbs))); \
|
---|
364 | } while(0)
|
---|
365 |
|
---|
366 | #else /* LWIP_DEBUG */
|
---|
367 |
|
---|
368 | #define TCP_REG(pcbs, npcb) \
|
---|
369 | do { \
|
---|
370 | (npcb)->next = *pcbs; \
|
---|
371 | *(pcbs) = (npcb); \
|
---|
372 | tcp_timer_needed(); \
|
---|
373 | } while (0)
|
---|
374 |
|
---|
375 | #define TCP_RMV(pcbs, npcb) \
|
---|
376 | do { \
|
---|
377 | if(*(pcbs) == (npcb)) { \
|
---|
378 | (*(pcbs)) = (*pcbs)->next; \
|
---|
379 | } \
|
---|
380 | else { \
|
---|
381 | for(tcp_tmp_pcb = *pcbs; \
|
---|
382 | tcp_tmp_pcb != NULL; \
|
---|
383 | tcp_tmp_pcb = tcp_tmp_pcb->next) { \
|
---|
384 | if(tcp_tmp_pcb->next == (npcb)) { \
|
---|
385 | tcp_tmp_pcb->next = (npcb)->next; \
|
---|
386 | break; \
|
---|
387 | } \
|
---|
388 | } \
|
---|
389 | } \
|
---|
390 | (npcb)->next = NULL; \
|
---|
391 | } while(0)
|
---|
392 |
|
---|
393 | #endif /* LWIP_DEBUG */
|
---|
394 |
|
---|
395 | #define TCP_REG_ACTIVE(npcb) \
|
---|
396 | do { \
|
---|
397 | TCP_REG(&tcp_active_pcbs, npcb); \
|
---|
398 | tcp_active_pcbs_changed = 1; \
|
---|
399 | } while (0)
|
---|
400 |
|
---|
401 | #define TCP_RMV_ACTIVE(npcb) \
|
---|
402 | do { \
|
---|
403 | TCP_RMV(&tcp_active_pcbs, npcb); \
|
---|
404 | tcp_active_pcbs_changed = 1; \
|
---|
405 | } while (0)
|
---|
406 |
|
---|
407 | #define TCP_PCB_REMOVE_ACTIVE(pcb) \
|
---|
408 | do { \
|
---|
409 | tcp_pcb_remove(&tcp_active_pcbs, pcb); \
|
---|
410 | tcp_active_pcbs_changed = 1; \
|
---|
411 | } while (0)
|
---|
412 |
|
---|
413 |
|
---|
414 | /* Internal functions: */
|
---|
415 | struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb);
|
---|
416 | void tcp_pcb_purge(struct tcp_pcb *pcb);
|
---|
417 | void tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb);
|
---|
418 |
|
---|
419 | void tcp_segs_free(struct tcp_seg *seg);
|
---|
420 | void tcp_seg_free(struct tcp_seg *seg);
|
---|
421 | struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg);
|
---|
422 |
|
---|
423 | #define tcp_ack(pcb) \
|
---|
424 | do { \
|
---|
425 | if((pcb)->flags & TF_ACK_DELAY) { \
|
---|
426 | (pcb)->flags &= ~TF_ACK_DELAY; \
|
---|
427 | (pcb)->flags |= TF_ACK_NOW; \
|
---|
428 | } \
|
---|
429 | else { \
|
---|
430 | (pcb)->flags |= TF_ACK_DELAY; \
|
---|
431 | } \
|
---|
432 | } while (0)
|
---|
433 |
|
---|
434 | #define tcp_ack_now(pcb) \
|
---|
435 | do { \
|
---|
436 | (pcb)->flags |= TF_ACK_NOW; \
|
---|
437 | } while (0)
|
---|
438 |
|
---|
439 | err_t tcp_send_fin(struct tcp_pcb *pcb);
|
---|
440 | err_t tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags);
|
---|
441 |
|
---|
442 | void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg);
|
---|
443 |
|
---|
444 | void tcp_rst(u32_t seqno, u32_t ackno,
|
---|
445 | ip_addr_t *local_ip, ip_addr_t *remote_ip,
|
---|
446 | u16_t local_port, u16_t remote_port);
|
---|
447 |
|
---|
448 | u32_t tcp_next_iss(void);
|
---|
449 |
|
---|
450 | void tcp_keepalive(struct tcp_pcb *pcb);
|
---|
451 | void tcp_zero_window_probe(struct tcp_pcb *pcb);
|
---|
452 |
|
---|
453 | #if TCP_CALCULATE_EFF_SEND_MSS
|
---|
454 | u16_t tcp_eff_send_mss(u16_t sendmss, ip_addr_t *addr);
|
---|
455 | #endif /* TCP_CALCULATE_EFF_SEND_MSS */
|
---|
456 |
|
---|
457 | #if LWIP_CALLBACK_API
|
---|
458 | err_t tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);
|
---|
459 | #endif /* LWIP_CALLBACK_API */
|
---|
460 |
|
---|
461 | #if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG
|
---|
462 | void tcp_debug_print(struct tcp_hdr *tcphdr);
|
---|
463 | void tcp_debug_print_flags(u8_t flags);
|
---|
464 | void tcp_debug_print_state(enum tcp_state s);
|
---|
465 | void tcp_debug_print_pcbs(void);
|
---|
466 | s16_t tcp_pcbs_sane(void);
|
---|
467 | #else
|
---|
468 | # define tcp_debug_print(tcphdr)
|
---|
469 | # define tcp_debug_print_flags(flags)
|
---|
470 | # define tcp_debug_print_state(s)
|
---|
471 | # define tcp_debug_print_pcbs()
|
---|
472 | # define tcp_pcbs_sane() 1
|
---|
473 | #endif /* TCP_DEBUG */
|
---|
474 |
|
---|
475 | /** External function (implemented in timers.c), called when TCP detects
|
---|
476 | * that a timer is needed (i.e. active- or time-wait-pcb found). */
|
---|
477 | void tcp_timer_needed(void);
|
---|
478 |
|
---|
479 |
|
---|
480 | #ifdef __cplusplus
|
---|
481 | }
|
---|
482 | #endif
|
---|
483 |
|
---|
484 | #endif /* LWIP_TCP */
|
---|
485 |
|
---|
486 | #endif /* __LWIP_TCP_H__ */
|
---|