2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
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.
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
27 * This file is part of the lwIP TCP/IP stack.
29 * Author: Adam Dunkels <adam@sics.se>
32 #ifndef __LWIP_TCP_H__
33 #define __LWIP_TCP_H__
37 #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
41 #include "lwip/pbuf.h"
43 #include "lwip/icmp.h"
52 /* Functions for interfacing with TCP: */
54 /* Lower layer interface to TCP: */
55 #define tcp_init() /* Compatibility define, not init needed. */
56 void tcp_tmr (void); /* Must be called every
58 ms. (Typically 250 ms). */
59 /* Application program's interface: */
60 struct tcp_pcb * tcp_new (void);
61 struct tcp_pcb * tcp_alloc (u8_t prio);
63 void tcp_arg (struct tcp_pcb *pcb, void *arg);
64 void tcp_accept (struct tcp_pcb *pcb,
65 err_t (* accept)(void *arg, struct tcp_pcb *newpcb,
67 void tcp_recv (struct tcp_pcb *pcb,
68 err_t (* recv)(void *arg, struct tcp_pcb *tpcb,
69 struct pbuf *p, err_t err));
70 void tcp_sent (struct tcp_pcb *pcb,
71 err_t (* sent)(void *arg, struct tcp_pcb *tpcb,
73 void tcp_poll (struct tcp_pcb *pcb,
74 err_t (* poll)(void *arg, struct tcp_pcb *tpcb),
76 void tcp_err (struct tcp_pcb *pcb,
77 void (* err)(void *arg, err_t err));
79 #define tcp_mss(pcb) ((pcb)->mss)
80 #define tcp_sndbuf(pcb) ((pcb)->snd_buf)
82 void tcp_recved (struct tcp_pcb *pcb, u16_t len);
83 err_t tcp_bind (struct tcp_pcb *pcb, struct ip_addr *ipaddr,
85 err_t tcp_connect (struct tcp_pcb *pcb, struct ip_addr *ipaddr,
86 u16_t port, err_t (* connected)(void *arg,
89 struct tcp_pcb * tcp_listen (struct tcp_pcb *pcb);
90 void tcp_abort (struct tcp_pcb *pcb);
91 err_t tcp_close (struct tcp_pcb *pcb);
92 err_t tcp_write (struct tcp_pcb *pcb, const void *dataptr, u16_t len,
95 void tcp_setprio (struct tcp_pcb *pcb, u8_t prio);
97 #define TCP_PRIO_MIN 1
98 #define TCP_PRIO_NORMAL 64
99 #define TCP_PRIO_MAX 127
101 /* It is also possible to call these two functions at the right
102 intervals (instead of calling tcp_tmr()). */
103 void tcp_slowtmr (void);
104 void tcp_fasttmr (void);
107 /* Only used by IP to pass a TCP segment to TCP: */
108 void tcp_input (struct pbuf *p, struct netif *inp);
109 /* Used within the TCP code only: */
110 err_t tcp_output (struct tcp_pcb *pcb);
111 void tcp_rexmit (struct tcp_pcb *pcb);
112 void tcp_rexmit_rto (struct tcp_pcb *pcb);
115 * This is the Nagle algorithm: inhibit the sending of new TCP
116 * segments when new outgoing data arrives from the user if any
117 * previously transmitted data on the connection remains
120 #define tcp_output_nagle(tpcb) ((((tpcb)->unacked == NULL) || \
121 ((tpcb)->flags & TF_NODELAY) || \
122 (((tpcb)->unsent != NULL) && ((tpcb)->unsent->next != NULL))) ? \
123 tcp_output(tpcb) : ERR_OK)
127 #define TCP_SEQ_LT(a,b) ((s32_t)((a)-(b)) < 0)
128 #define TCP_SEQ_LEQ(a,b) ((s32_t)((a)-(b)) <= 0)
129 #define TCP_SEQ_GT(a,b) ((s32_t)((a)-(b)) > 0)
130 #define TCP_SEQ_GEQ(a,b) ((s32_t)((a)-(b)) >= 0)
132 #if 0 /* see bug #10548 */
133 #define TCP_SEQ_BETWEEN(a,b,c) ((c)-(b) >= (a)-(b))
135 #define TCP_SEQ_BETWEEN(a,b,c) (TCP_SEQ_GEQ(a,b) && TCP_SEQ_LEQ(a,c))
136 #define TCP_FIN 0x01U
137 #define TCP_SYN 0x02U
138 #define TCP_RST 0x04U
139 #define TCP_PSH 0x08U
140 #define TCP_ACK 0x10U
141 #define TCP_URG 0x20U
142 #define TCP_ECE 0x40U
143 #define TCP_CWR 0x80U
145 #define TCP_FLAGS 0x3fU
147 /* Length of the TCP header, excluding options. */
150 #ifndef TCP_TMR_INTERVAL
151 #define TCP_TMR_INTERVAL 250 /* The TCP timer interval in milliseconds. */
152 #endif /* TCP_TMR_INTERVAL */
154 #ifndef TCP_FAST_INTERVAL
155 #define TCP_FAST_INTERVAL TCP_TMR_INTERVAL /* the fine grained timeout in milliseconds */
156 #endif /* TCP_FAST_INTERVAL */
158 #ifndef TCP_SLOW_INTERVAL
159 #define TCP_SLOW_INTERVAL (2*TCP_TMR_INTERVAL) /* the coarse grained timeout in milliseconds */
160 #endif /* TCP_SLOW_INTERVAL */
162 #define TCP_FIN_WAIT_TIMEOUT 20000 /* milliseconds */
163 #define TCP_SYN_RCVD_TIMEOUT 20000 /* milliseconds */
165 #define TCP_OOSEQ_TIMEOUT 6U /* x RTO */
167 #define TCP_MSL 60000U /* The maximum segment lifetime in microseconds */
169 /* Keepalive values, compliant with RFC 1122. Don't change this unless you know what you're doing */
170 #ifndef TCP_KEEPIDLE_DEFAULT
171 #define TCP_KEEPIDLE_DEFAULT 7200000UL /* Default KEEPALIVE timer in milliseconds */
174 #ifndef TCP_KEEPINTVL_DEFAULT
175 #define TCP_KEEPINTVL_DEFAULT 75000UL /* Default Time between KEEPALIVE probes in milliseconds */
178 #ifndef TCP_KEEPCNT_DEFAULT
179 #define TCP_KEEPCNT_DEFAULT 9U /* Default Counter for KEEPALIVE probes */
182 #define TCP_MAXIDLE TCP_KEEPCNT_DEFAULT * TCP_KEEPINTVL_DEFAULT /* Maximum KEEPALIVE probe time */
184 /* Fields are (of course) in network byte order.
185 * Some fields are converted to host byte order in tcp_input().
187 #ifdef PACK_STRUCT_USE_INCLUDES
188 # include "arch/bpstruct.h"
192 PACK_STRUCT_FIELD(u16_t src);
193 PACK_STRUCT_FIELD(u16_t dest);
194 PACK_STRUCT_FIELD(u32_t seqno);
195 PACK_STRUCT_FIELD(u32_t ackno);
196 PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags);
197 PACK_STRUCT_FIELD(u16_t wnd);
198 PACK_STRUCT_FIELD(u16_t chksum);
199 PACK_STRUCT_FIELD(u16_t urgp);
200 } PACK_STRUCT_STRUCT;
202 #ifdef PACK_STRUCT_USE_INCLUDES
203 # include "arch/epstruct.h"
206 #define TCPH_OFFSET(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 8)
207 #define TCPH_HDRLEN(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 12)
208 #define TCPH_FLAGS(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS)
210 #define TCPH_OFFSET_SET(phdr, offset) (phdr)->_hdrlen_rsvd_flags = htons(((offset) << 8) | TCPH_FLAGS(phdr))
211 #define TCPH_HDRLEN_SET(phdr, len) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | TCPH_FLAGS(phdr))
212 #define TCPH_FLAGS_SET(phdr, flags) (phdr)->_hdrlen_rsvd_flags = htons((ntohs((phdr)->_hdrlen_rsvd_flags) & ~TCP_FLAGS) | (flags))
213 #define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = htons(ntohs((phdr)->_hdrlen_rsvd_flags) | (flags))
214 #define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = htons(ntohs((phdr)->_hdrlen_rsvd_flags) | (TCPH_FLAGS(phdr) & ~(flags)) )
216 #define TCP_TCPLEN(seg) ((seg)->len + ((TCPH_FLAGS((seg)->tcphdr) & TCP_FIN || \
217 TCPH_FLAGS((seg)->tcphdr) & TCP_SYN)? 1: 0))
234 * members common to struct tcp_pcb and struct tcp_listen_pcb
236 #define TCP_PCB_COMMON(type) \
237 type *next; /* for the linked list */ \
238 enum tcp_state state; /* TCP state */ \
240 void *callback_arg; \
241 /* ports are in host byte order */ \
244 /* the TCP protocol control block */
246 /** common PCB members */
248 /** protocol specific PCB members */
249 TCP_PCB_COMMON(struct tcp_pcb);
251 /* ports are in host byte order */
255 #define TF_ACK_DELAY (u8_t)0x01U /* Delayed ACK. */
256 #define TF_ACK_NOW (u8_t)0x02U /* Immediate ACK. */
257 #define TF_INFR (u8_t)0x04U /* In fast recovery. */
258 #define TF_RESET (u8_t)0x08U /* Connection was reset. */
259 #define TF_CLOSED (u8_t)0x10U /* Connection was sucessfully closed. */
260 #define TF_GOT_FIN (u8_t)0x20U /* Connection was closed by the remote end. */
261 #define TF_NODELAY (u8_t)0x40U /* Disable Nagle algorithm */
263 /* the rest of the fields are in host byte order
264 as we have to do some math with them */
265 /* receiver variables */
266 u32_t rcv_nxt; /* next seqno expected */
267 u16_t rcv_wnd; /* receiver window */
271 u8_t polltmr, pollinterval;
273 /* Retransmission timer. */
276 u16_t mss; /* maximum segment size */
278 /* RTT (round trip time) estimation variables */
279 u32_t rttest; /* RTT estimate in 500ms ticks */
280 u32_t rtseq; /* sequence number being timed */
281 s16_t sa, sv; /* @todo document this */
283 s16_t rto; /* retransmission time-out */
284 u8_t nrtx; /* number of retransmissions */
286 /* fast retransmit/recovery */
287 u32_t lastack; /* Highest acknowledged seqno. */
290 /* congestion avoidance/control variables */
294 /* sender variables */
295 u32_t snd_nxt, /* next seqno to be sent */
296 snd_max; /* Highest seqno sent. */
297 u16_t snd_wnd; /* sender window */
298 u32_t snd_wl1, snd_wl2, /* Sequence and acknowledgement numbers of last
300 snd_lbb; /* Sequence number of next byte to be buffered. */
304 u16_t snd_buf; /* Available buffer space for sending (in bytes). */
305 #define TCP_SNDQUEUELEN_OVERFLOW (0xffff-3)
306 u16_t snd_queuelen; /* Available buffer space for sending (in tcp_segs). */
309 /* These are ordered by sequence number: */
310 struct tcp_seg *unsent; /* Unsent (queued) segments. */
311 struct tcp_seg *unacked; /* Sent but unacknowledged segments. */
313 struct tcp_seg *ooseq; /* Received out of sequence segments. */
314 #endif /* TCP_QUEUE_OOSEQ */
316 #if LWIP_CALLBACK_API
317 /* Function to be called when more send buffer space is available.
318 * @param arg user-supplied argument (tcp_pcb.callback_arg)
319 * @param pcb the tcp_pcb which has send buffer space available
320 * @param space the amount of bytes available
321 * @return ERR_OK: try to send some data by calling tcp_output
323 err_t (* sent)(void *arg, struct tcp_pcb *pcb, u16_t space);
325 /* Function to be called when (in-sequence) data has arrived.
326 * @param arg user-supplied argument (tcp_pcb.callback_arg)
327 * @param pcb the tcp_pcb for which data has arrived
328 * @param p the packet buffer which arrived
329 * @param err an error argument (TODO: that is current always ERR_OK?)
330 * @return ERR_OK: try to send some data by calling tcp_output
332 err_t (* recv)(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);
334 /* Function to be called when a connection has been set up.
335 * @param arg user-supplied argument (tcp_pcb.callback_arg)
336 * @param pcb the tcp_pcb that now is connected
337 * @param err an error argument (TODO: that is current always ERR_OK?)
338 * @return value is currently ignored
340 err_t (* connected)(void *arg, struct tcp_pcb *pcb, err_t err);
342 /* Function to call when a listener has been connected.
343 * @param arg user-supplied argument (tcp_pcb.callback_arg)
344 * @param pcb a new tcp_pcb that now is connected
345 * @param err an error argument (TODO: that is current always ERR_OK?)
346 * @return ERR_OK: accept the new connection,
347 * any other err_t abortsthe new connection
349 err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err);
351 /* Function which is called periodically.
352 * The period can be adjusted in multiples of the TCP slow timer interval
353 * by changing tcp_pcb.polltmr.
354 * @param arg user-supplied argument (tcp_pcb.callback_arg)
355 * @param pcb the tcp_pcb to poll for
356 * @return ERR_OK: try to send some data by calling tcp_output
358 err_t (* poll)(void *arg, struct tcp_pcb *pcb);
360 /* Function to be called whenever a fatal error occurs.
361 * There is no pcb parameter since most of the times, the pcb is
362 * already deallocated (or there is no pcb) when this function is called.
363 * @param arg user-supplied argument (tcp_pcb.callback_arg)
364 * @param err an indication why the error callback is called:
365 * ERR_ABRT: aborted through tcp_abort or by a TCP timer
366 * ERR_RST: the connection was reset by the remote host
368 void (* errf)(void *arg, err_t err);
369 #endif /* LWIP_CALLBACK_API */
371 /* idle time before KEEPALIVE is sent */
373 #if LWIP_TCP_KEEPALIVE
376 #endif /* LWIP_TCP_KEEPALIVE */
378 /* KEEPALIVE counter */
382 struct tcp_pcb_listen {
383 /* Common members of all PCB types */
385 /* Protocol specific PCB members */
386 TCP_PCB_COMMON(struct tcp_pcb_listen);
388 #if LWIP_CALLBACK_API
389 /* Function to call when a listener has been connected.
390 * @param arg user-supplied argument (tcp_pcb.callback_arg)
391 * @param pcb a new tcp_pcb that now is connected
392 * @param err an error argument (TODO: that is current always ERR_OK?)
393 * @return ERR_OK: accept the new connection,
394 * any other err_t abortsthe new connection
396 err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err);
397 #endif /* LWIP_CALLBACK_API */
406 LWIP_EVENT_CONNECTED,
411 err_t lwip_tcp_event(void *arg, struct tcp_pcb *pcb,
417 #define TCP_EVENT_ACCEPT(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
418 LWIP_EVENT_ACCEPT, NULL, 0, err)
419 #define TCP_EVENT_SENT(pcb,space,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
420 LWIP_EVENT_SENT, NULL, space, ERR_OK)
421 #define TCP_EVENT_RECV(pcb,p,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
422 LWIP_EVENT_RECV, (p), 0, (err))
423 #define TCP_EVENT_CONNECTED(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
424 LWIP_EVENT_CONNECTED, NULL, 0, (err))
425 #define TCP_EVENT_POLL(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
426 LWIP_EVENT_POLL, NULL, 0, ERR_OK)
427 #define TCP_EVENT_ERR(errf,arg,err) lwip_tcp_event((arg), NULL, \
428 LWIP_EVENT_ERR, NULL, 0, (err))
429 #else /* LWIP_EVENT_API */
430 #define TCP_EVENT_ACCEPT(pcb,err,ret) \
431 if((pcb)->accept != NULL) \
432 (ret = (pcb)->accept((pcb)->callback_arg,(pcb),(err)))
433 #define TCP_EVENT_SENT(pcb,space,ret) \
434 if((pcb)->sent != NULL) \
435 (ret = (pcb)->sent((pcb)->callback_arg,(pcb),(space)))
436 #define TCP_EVENT_RECV(pcb,p,err,ret) \
437 if((pcb)->recv != NULL) \
438 { ret = (pcb)->recv((pcb)->callback_arg,(pcb),(p),(err)); } else { \
439 if (p) pbuf_free(p); }
440 #define TCP_EVENT_CONNECTED(pcb,err,ret) \
441 if((pcb)->connected != NULL) \
442 (ret = (pcb)->connected((pcb)->callback_arg,(pcb),(err)))
443 #define TCP_EVENT_POLL(pcb,ret) \
444 if((pcb)->poll != NULL) \
445 (ret = (pcb)->poll((pcb)->callback_arg,(pcb)))
446 #define TCP_EVENT_ERR(errf,arg,err) \
449 #endif /* LWIP_EVENT_API */
451 /* This structure represents a TCP segment on the unsent and unacked queues */
453 struct tcp_seg *next; /* used when putting segements on a queue */
454 struct pbuf *p; /* buffer containing data + TCP header */
455 void *dataptr; /* pointer to the TCP data in the pbuf */
456 u16_t len; /* the TCP length of this segment */
457 struct tcp_hdr *tcphdr; /* the TCP header */
460 /* Internal functions and global variables: */
461 struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb);
462 void tcp_pcb_purge(struct tcp_pcb *pcb);
463 void tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb);
465 u8_t tcp_segs_free(struct tcp_seg *seg);
466 u8_t tcp_seg_free(struct tcp_seg *seg);
467 struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg);
469 #define tcp_ack(pcb) if((pcb)->flags & TF_ACK_DELAY) { \
470 (pcb)->flags &= ~TF_ACK_DELAY; \
471 (pcb)->flags |= TF_ACK_NOW; \
474 (pcb)->flags |= TF_ACK_DELAY; \
477 #define tcp_ack_now(pcb) (pcb)->flags |= TF_ACK_NOW; \
480 err_t tcp_send_ctrl(struct tcp_pcb *pcb, u8_t flags);
481 err_t tcp_enqueue(struct tcp_pcb *pcb, void *dataptr, u16_t len,
482 u8_t flags, u8_t copy,
483 u8_t *optdata, u8_t optlen);
485 void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg);
487 void tcp_rst(u32_t seqno, u32_t ackno,
488 struct ip_addr *local_ip, struct ip_addr *remote_ip,
489 u16_t local_port, u16_t remote_port);
491 u32_t tcp_next_iss(void);
493 void tcp_keepalive(struct tcp_pcb *pcb);
495 extern struct tcp_pcb *tcp_input_pcb;
496 extern u32_t tcp_ticks;
498 #if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG
499 void tcp_debug_print(struct tcp_hdr *tcphdr);
500 void tcp_debug_print_flags(u8_t flags);
501 void tcp_debug_print_state(enum tcp_state s);
502 void tcp_debug_print_pcbs(void);
503 s16_t tcp_pcbs_sane(void);
505 # define tcp_debug_print(tcphdr)
506 # define tcp_debug_print_flags(flags)
507 # define tcp_debug_print_state(s)
508 # define tcp_debug_print_pcbs()
509 # define tcp_pcbs_sane() 1
510 #endif /* TCP_DEBUG */
513 #define tcp_timer_needed()
515 void tcp_timer_needed(void);
518 /* The TCP PCB lists. */
519 union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */
520 struct tcp_pcb_listen *listen_pcbs;
521 struct tcp_pcb *pcbs;
523 extern union tcp_listen_pcbs_t tcp_listen_pcbs;
524 extern struct tcp_pcb *tcp_active_pcbs; /* List of all TCP PCBs that are in a
525 state in which they accept or send
527 extern struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in TIME-WAIT. */
529 extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */
531 /* Axioms about the above lists:
532 1) Every TCP PCB that is not CLOSED is in one of the lists.
533 2) A PCB is only in one of the lists.
534 3) All PCBs in the tcp_listen_pcbs list is in LISTEN state.
535 4) All PCBs in the tcp_tw_pcbs list is in TIME-WAIT state.
538 /* Define two macros, TCP_REG and TCP_RMV that registers a TCP PCB
539 with a PCB list or removes a PCB from a list, respectively. */
541 #define TCP_REG(pcbs, npcb) do {\
542 LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", npcb, npcb->local_port)); \
543 for(tcp_tmp_pcb = *pcbs; \
544 tcp_tmp_pcb != NULL; \
545 tcp_tmp_pcb = tcp_tmp_pcb->next) { \
546 LWIP_ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != npcb); \
548 LWIP_ASSERT("TCP_REG: pcb->state != CLOSED", npcb->state != CLOSED); \
549 npcb->next = *pcbs; \
550 LWIP_ASSERT("TCP_REG: npcb->next != npcb", npcb->next != npcb); \
552 LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \
553 tcp_timer_needed(); \
555 #define TCP_RMV(pcbs, npcb) do { \
556 LWIP_ASSERT("TCP_RMV: pcbs != NULL", *pcbs != NULL); \
557 LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", npcb, *pcbs)); \
558 if(*pcbs == npcb) { \
559 *pcbs = (*pcbs)->next; \
560 } else for(tcp_tmp_pcb = *pcbs; tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \
561 if(tcp_tmp_pcb->next != NULL && tcp_tmp_pcb->next == npcb) { \
562 tcp_tmp_pcb->next = npcb->next; \
567 LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \
568 LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", npcb, *pcbs)); \
571 #else /* LWIP_DEBUG */
572 #define TCP_REG(pcbs, npcb) do { \
573 npcb->next = *pcbs; \
575 tcp_timer_needed(); \
577 #define TCP_RMV(pcbs, npcb) do { \
578 if(*(pcbs) == npcb) { \
579 (*(pcbs)) = (*pcbs)->next; \
580 } else for(tcp_tmp_pcb = *pcbs; tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \
581 if(tcp_tmp_pcb->next != NULL && tcp_tmp_pcb->next == npcb) { \
582 tcp_tmp_pcb->next = npcb->next; \
588 #endif /* LWIP_DEBUG */
594 #endif /* LWIP_TCP */
596 #endif /* __LWIP_TCP_H__ */