]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/blob - src/include/lwip/tcp.h
95d1febc37edfbb54651736a1b49dd327f973f52
[pes-rpp/rpp-lwip.git] / src / include / lwip / tcp.h
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_H__
33 #define __LWIP_TCP_H__
34
35 #include "lwip/sys.h"
36 #include "lwip/mem.h"
37
38 #include "lwip/pbuf.h"
39 #include "lwip/opt.h"
40 #include "lwip/ip.h"
41 #include "lwip/icmp.h"
42
43 #include "lwip/err.h"
44
45 struct tcp_pcb;
46
47 /* Functions for interfacing with TCP: */
48
49 /* Lower layer interface to TCP: */
50 void             tcp_init    (void);  /* Must be called first to
51            initialize TCP. */
52 void             tcp_tmr     (void);  /* Must be called every
53            TCP_TMR_INTERVAL
54            ms. (Typically 250 ms). */
55 /* Application program's interface: */
56 struct tcp_pcb * tcp_new     (void);
57 struct tcp_pcb * tcp_alloc   (u8_t prio);
58
59 void             tcp_arg     (struct tcp_pcb *pcb, void *arg);
60 void             tcp_accept  (struct tcp_pcb *pcb,
61             err_t (* accept)(void *arg, struct tcp_pcb *newpcb,
62                  err_t err));
63 void             tcp_recv    (struct tcp_pcb *pcb,
64             err_t (* recv)(void *arg, struct tcp_pcb *tpcb,
65           struct pbuf *p, err_t err));
66 void             tcp_sent    (struct tcp_pcb *pcb,
67             err_t (* sent)(void *arg, struct tcp_pcb *tpcb,
68                u16_t len));
69 void             tcp_poll    (struct tcp_pcb *pcb,
70             err_t (* poll)(void *arg, struct tcp_pcb *tpcb),
71             u8_t interval);
72 void             tcp_err     (struct tcp_pcb *pcb,
73             void (* err)(void *arg, err_t err));
74
75 #define          tcp_mss(pcb)      ((pcb)->mss)
76 #define          tcp_sndbuf(pcb)   ((pcb)->snd_buf)
77
78 void             tcp_recved  (struct tcp_pcb *pcb, u16_t len);
79 err_t            tcp_bind    (struct tcp_pcb *pcb, struct ip_addr *ipaddr,
80             u16_t port);
81 err_t            tcp_connect (struct tcp_pcb *pcb, struct ip_addr *ipaddr,
82             u16_t port, err_t (* connected)(void *arg,
83                     struct tcp_pcb *tpcb,
84                     err_t err));
85 struct tcp_pcb * tcp_listen  (struct tcp_pcb *pcb);
86 void             tcp_abort   (struct tcp_pcb *pcb);
87 err_t            tcp_close   (struct tcp_pcb *pcb);
88 err_t            tcp_write   (struct tcp_pcb *pcb, const void *dataptr, u16_t len,
89             u8_t copy);
90
91 void             tcp_setprio (struct tcp_pcb *pcb, u8_t prio);
92
93 #define TCP_PRIO_MIN    1
94 #define TCP_PRIO_NORMAL 64
95 #define TCP_PRIO_MAX    127
96
97 /* It is also possible to call these two functions at the right
98    intervals (instead of calling tcp_tmr()). */
99 void             tcp_slowtmr (void);
100 void             tcp_fasttmr (void);
101
102
103 /* Only used by IP to pass a TCP segment to TCP: */
104 void             tcp_input   (struct pbuf *p, struct netif *inp);
105 /* Used within the TCP code only: */
106 err_t            tcp_output  (struct tcp_pcb *pcb);
107 void             tcp_rexmit  (struct tcp_pcb *pcb);
108
109
110
111 #define TCP_SEQ_LT(a,b)     ((s32_t)((a)-(b)) < 0)
112 #define TCP_SEQ_LEQ(a,b)    ((s32_t)((a)-(b)) <= 0)
113 #define TCP_SEQ_GT(a,b)     ((s32_t)((a)-(b)) > 0)
114 #define TCP_SEQ_GEQ(a,b)    ((s32_t)((a)-(b)) >= 0)
115
116 #define TCP_FIN 0x01U
117 #define TCP_SYN 0x02U
118 #define TCP_RST 0x04U
119 #define TCP_PSH 0x08U
120 #define TCP_ACK 0x10U
121 #define TCP_URG 0x20U
122 #define TCP_ECE 0x40U
123 #define TCP_CWR 0x80U
124
125 #define TCP_FLAGS 0x3fU
126
127 /* Length of the TCP header, excluding options. */
128 #define TCP_HLEN 20
129
130 #ifndef TCP_TMR_INTERVAL
131 #define TCP_TMR_INTERVAL       250  /* The TCP timer interval in
132                                        milliseconds. */
133 #endif /* TCP_TMR_INTERVAL */
134
135 #ifndef TCP_FAST_INTERVAL
136 #define TCP_FAST_INTERVAL      TCP_TMR_INTERVAL /* the fine grained timeout in
137                                        milliseconds */
138 #endif /* TCP_FAST_INTERVAL */
139
140 #ifndef TCP_SLOW_INTERVAL
141 #define TCP_SLOW_INTERVAL      (2*TCP_TMR_INTERVAL)  /* the coarse grained timeout in
142                                        milliseconds */
143 #endif /* TCP_SLOW_INTERVAL */
144
145 #define TCP_FIN_WAIT_TIMEOUT 20000 /* milliseconds */
146 #define TCP_SYN_RCVD_TIMEOUT 20000 /* milliseconds */
147
148 #define TCP_OOSEQ_TIMEOUT        6 /* x RTO */
149
150 #define TCP_MSL 60000  /* The maximum segment lifetime in microseconds */
151
152 /*
153  * User-settable options (used with setsockopt).
154  */
155 #define TCP_NODELAY        0x01    /* don't delay send to coalesce packets */
156 #define TCP_KEEPALIVE  0x02    /* send KEEPALIVE probes when idle for pcb->keepalive miliseconds */
157
158 /* Keepalive values */
159 #define  TCP_KEEPDEFAULT   7200000                       /* KEEPALIVE timer in miliseconds */
160 #define  TCP_KEEPINTVL     75000                         /* Time between KEEPALIVE probes in miliseconds */
161 #define  TCP_KEEPCNT       9                             /* Counter for KEEPALIVE probes */
162 #define  TCP_MAXIDLE       TCP_KEEPCNT * TCP_KEEPINTVL   /* Maximum KEEPALIVE probe time */
163
164 struct tcp_hdr {
165   u16_t src;
166   u16_t dest;
167   u32_t seqno;
168   u32_t ackno;
169   u16_t _hdrlen_rsvd_flags;
170   u16_t wnd;
171   u16_t chksum;
172   u16_t urgp;
173 };
174
175 #define TCPH_OFFSET(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 8)
176 #define TCPH_HDRLEN(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 12)
177 #define TCPH_FLAGS(phdr)  (ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS)
178
179 #define TCPH_OFFSET_SET(phdr, offset) (phdr)->_hdrlen_rsvd_flags = htons(((offset) << 8) | TCPH_FLAGS(phdr))
180 #define TCPH_HDRLEN_SET(phdr, len) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | TCPH_FLAGS(phdr))
181 #define TCPH_FLAGS_SET(phdr, flags) (phdr)->_hdrlen_rsvd_flags = htons((ntohs((phdr)->_hdrlen_rsvd_flags) & ~TCP_FLAGS) | (flags))
182 #define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = htons(ntohs((phdr)->_hdrlen_rsvd_flags) | (flags))
183 #define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = htons(ntohs((phdr)->_hdrlen_rsvd_flags) | (TCPH_FLAGS(phdr) & ~(flags)) )
184
185 #define TCP_TCPLEN(seg) ((seg)->len + ((TCPH_FLAGS((seg)->tcphdr) & TCP_FIN || \
186           TCPH_FLAGS((seg)->tcphdr) & TCP_SYN)? 1: 0))
187
188 enum tcp_state {
189   CLOSED      = 0,
190   LISTEN      = 1,
191   SYN_SENT    = 2,
192   SYN_RCVD    = 3,
193   ESTABLISHED = 4,
194   FIN_WAIT_1  = 5,
195   FIN_WAIT_2  = 6,
196   CLOSE_WAIT  = 7,
197   CLOSING     = 8,
198   LAST_ACK    = 9,
199   TIME_WAIT   = 10
200 };
201
202
203 /* the TCP protocol control block */
204 struct tcp_pcb {
205 /* Common members of all PCB types */
206   IP_PCB;
207
208 /* Protocol specific PCB members */
209
210   struct tcp_pcb *next;   /* for the linked list */
211
212   enum tcp_state state;   /* TCP state */
213
214   u8_t prio;
215   void *callback_arg;
216
217   u16_t local_port;
218   u16_t remote_port;
219   
220   u8_t flags;
221 #define TF_ACK_DELAY (u8_t)0x01U   /* Delayed ACK. */
222 #define TF_ACK_NOW   (u8_t)0x02U   /* Immediate ACK. */
223 #define TF_INFR      (u8_t)0x04U   /* In fast recovery. */
224 #define TF_RESET     (u8_t)0x08U   /* Connection was reset. */
225 #define TF_CLOSED    (u8_t)0x10U   /* Connection was sucessfully closed. */
226 #define TF_GOT_FIN   (u8_t)0x20U   /* Connection was closed by the remote end. */
227 #define TF_NODELAY   (u8_t)0x40U   /* Disable Nagle algorithm */
228
229   /* receiver varables */
230   u32_t rcv_nxt;   /* next seqno expected */
231   u16_t rcv_wnd;   /* receiver window */
232   
233   /* Timers */
234   u32_t tmr;
235   u8_t polltmr, pollinterval;
236   
237   /* Retransmission timer. */
238   u16_t rtime;
239   
240   u16_t mss;   /* maximum segment size */
241   
242   /* RTT estimation variables. */
243   u16_t rttest; /* RTT estimate in 500ms ticks */
244   u32_t rtseq;  /* sequence number being timed */
245   s16_t sa, sv;
246
247   u16_t rto;    /* retransmission time-out */
248   u8_t nrtx;    /* number of retransmissions */
249
250   /* fast retransmit/recovery */
251   u32_t lastack; /* Highest acknowledged seqno. */
252   u8_t dupacks;
253   
254   /* congestion avoidance/control variables */
255   u16_t cwnd;  
256   u16_t ssthresh;
257
258   /* sender variables */
259   u32_t snd_nxt,       /* next seqno to be sent */
260     snd_max,       /* Highest seqno sent. */
261     snd_wnd,       /* sender window */
262     snd_wl1, snd_wl2, /* Sequence and acknowledgement numbers of last
263        window update. */
264     snd_lbb;       /* Sequence number of next byte to be buffered. */
265
266   u16_t acked;
267   
268   u16_t snd_buf;   /* Available buffer space for sending (in bytes). */
269   u8_t snd_queuelen; /* Available buffer space for sending (in tcp_segs). */
270   
271   
272   /* These are ordered by sequence number: */
273   struct tcp_seg *unsent;   /* Unsent (queued) segments. */
274   struct tcp_seg *unacked;  /* Sent but unacknowledged segments. */
275 #if TCP_QUEUE_OOSEQ  
276   struct tcp_seg *ooseq;    /* Received out of sequence segments. */
277 #endif /* TCP_QUEUE_OOSEQ */
278
279 #if LWIP_CALLBACK_API
280   /* Function to be called when more send buffer space is available. */
281   err_t (* sent)(void *arg, struct tcp_pcb *pcb, u16_t space);
282   
283   /* Function to be called when (in-sequence) data has arrived. */
284   err_t (* recv)(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);
285
286   /* Function to be called when a connection has been set up. */
287   err_t (* connected)(void *arg, struct tcp_pcb *pcb, err_t err);
288
289   /* Function to call when a listener has been connected. */
290   err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err);
291
292   /* Function which is called periodically. */
293   err_t (* poll)(void *arg, struct tcp_pcb *pcb);
294
295   /* Function to be called whenever a fatal error occurs. */
296   void (* errf)(void *arg, err_t err);
297 #endif /* LWIP_CALLBACK_API */
298
299   /* idle time before KEEPALIVE is sent */
300   u32_t keepalive;
301   
302   /* KEEPALIVE counter */
303   u8_t keep_cnt;
304 };
305
306 struct tcp_pcb_listen {  
307 /* Common members of all PCB types */
308   IP_PCB;
309
310 /* Protocol specific PCB members */
311   struct tcp_pcb_listen *next;   /* for the linked list */
312   
313   /* Even if state is obviously LISTEN this is here for
314    * field compatibility with tpc_pcb to which it is cast sometimes
315    * Until a cleaner solution emerges this is here.FIXME
316    */ 
317   enum tcp_state state;   /* TCP state */
318
319   u8_t prio;
320   void *callback_arg;
321   
322   u16_t local_port; 
323
324 #if LWIP_CALLBACK_API
325   /* Function to call when a listener has been connected. */
326   err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err);
327 #endif /* LWIP_CALLBACK_API */
328 };
329
330 #if LWIP_EVENT_API
331
332 enum lwip_event {
333   LWIP_EVENT_ACCEPT,
334   LWIP_EVENT_SENT,
335   LWIP_EVENT_RECV,
336   LWIP_EVENT_CONNECTED,
337   LWIP_EVENT_POLL,
338   LWIP_EVENT_ERR
339 };
340
341 err_t lwip_tcp_event(void *arg, struct tcp_pcb *pcb,
342          enum lwip_event,
343          struct pbuf *p,
344          u16_t size,
345          err_t err);
346
347 #define TCP_EVENT_ACCEPT(pcb,err,ret)    ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
348                 LWIP_EVENT_ACCEPT, NULL, 0, err)
349 #define TCP_EVENT_SENT(pcb,space,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
350                    LWIP_EVENT_SENT, NULL, space, ERR_OK)
351 #define TCP_EVENT_RECV(pcb,p,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
352                 LWIP_EVENT_RECV, (p), 0, (err))
353 #define TCP_EVENT_CONNECTED(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
354                 LWIP_EVENT_CONNECTED, NULL, 0, (err))
355 #define TCP_EVENT_POLL(pcb,ret)       ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
356                 LWIP_EVENT_POLL, NULL, 0, ERR_OK)
357 #define TCP_EVENT_ERR(errf,arg,err)  lwip_tcp_event((arg), NULL, \
358                 LWIP_EVENT_ERR, NULL, 0, (err))
359 #else /* LWIP_EVENT_API */
360 #define TCP_EVENT_ACCEPT(pcb,err,ret)     \
361                         if((pcb)->accept != NULL) \
362                         (ret = (pcb)->accept((pcb)->callback_arg,(pcb),(err)))
363 #define TCP_EVENT_SENT(pcb,space,ret) \
364                         if((pcb)->sent != NULL) \
365                         (ret = (pcb)->sent((pcb)->callback_arg,(pcb),(space)))
366 #define TCP_EVENT_RECV(pcb,p,err,ret) \
367                         if((pcb)->recv != NULL) \
368                         { ret = (pcb)->recv((pcb)->callback_arg,(pcb),(p),(err)); } else { \
369             pbuf_free(p); }
370 #define TCP_EVENT_CONNECTED(pcb,err,ret) \
371                         if((pcb)->connected != NULL) \
372                         (ret = (pcb)->connected((pcb)->callback_arg,(pcb),(err)))
373 #define TCP_EVENT_POLL(pcb,ret) \
374                         if((pcb)->poll != NULL) \
375                         (ret = (pcb)->poll((pcb)->callback_arg,(pcb)))
376 #define TCP_EVENT_ERR(errf,arg,err) \
377                         if((errf) != NULL) \
378                         (errf)((arg),(err))
379 #endif /* LWIP_EVENT_API */
380
381 /* This structure is used to repressent TCP segments when queued. */
382 struct tcp_seg {
383   struct tcp_seg *next;    /* used when putting segements on a queue */
384   struct pbuf *p;          /* buffer containing data + TCP header */
385   void *dataptr;           /* pointer to the TCP data in the pbuf */
386   u16_t len;               /* the TCP length of this segment */
387   struct tcp_hdr *tcphdr;  /* the TCP header */
388 };
389
390 /* Internal functions and global variables: */
391 struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb);
392 void tcp_pcb_purge(struct tcp_pcb *pcb);
393 void tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb);
394
395 u8_t tcp_segs_free(struct tcp_seg *seg);
396 u8_t tcp_seg_free(struct tcp_seg *seg);
397 struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg);
398
399 #define tcp_ack(pcb)     if((pcb)->flags & TF_ACK_DELAY) { \
400                             (pcb)->flags &= ~TF_ACK_DELAY; \
401                             (pcb)->flags |= TF_ACK_NOW; \
402                             tcp_output(pcb); \
403                          } else { \
404                             (pcb)->flags |= TF_ACK_DELAY; \
405                          }
406
407 #define tcp_ack_now(pcb) (pcb)->flags |= TF_ACK_NOW; \
408                          tcp_output(pcb)
409
410 err_t tcp_send_ctrl(struct tcp_pcb *pcb, u8_t flags);
411 err_t tcp_enqueue(struct tcp_pcb *pcb, void *dataptr, u16_t len,
412     u8_t flags, u8_t copy,
413                 u8_t *optdata, u8_t optlen);
414
415 void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg);
416
417 void tcp_rst(u32_t seqno, u32_t ackno,
418        struct ip_addr *local_ip, struct ip_addr *remote_ip,
419        u16_t local_port, u16_t remote_port);
420
421 u32_t tcp_next_iss(void);
422
423 void tcp_keepalive(struct tcp_pcb *pcb);
424
425 extern struct tcp_pcb *tcp_input_pcb;
426 extern u32_t tcp_ticks;
427
428 #if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG
429 void tcp_debug_print(struct tcp_hdr *tcphdr);
430 void tcp_debug_print_flags(u8_t flags);
431 void tcp_debug_print_state(enum tcp_state s);
432 void tcp_debug_print_pcbs(void);
433 int tcp_pcbs_sane(void);
434 #else
435 #  define tcp_debug_print(tcphdr)
436 #  define tcp_debug_print_flags(flags)
437 #  define tcp_debug_print_state(s)
438 #  define tcp_debug_print_pcbs()
439 #  define tcp_pcbs_sane() 1
440 #endif /* TCP_DEBUG */
441
442 #if NO_SYS
443 #define tcp_timer_needed()
444 #else
445 void tcp_timer_needed(void);
446 #endif
447
448 /* The TCP PCB lists. */
449 union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */
450         struct tcp_pcb_listen *listen_pcbs; 
451         struct tcp_pcb *pcbs;
452 };
453 extern union tcp_listen_pcbs_t tcp_listen_pcbs;
454 extern struct tcp_pcb *tcp_active_pcbs;  /* List of all TCP PCBs that are in a
455               state in which they accept or send
456               data. */
457 extern struct tcp_pcb *tcp_tw_pcbs;      /* List of all TCP PCBs in TIME-WAIT. */
458
459 extern struct tcp_pcb *tcp_tmp_pcb;      /* Only used for temporary storage. */
460
461 /* Axioms about the above lists:   
462    1) Every TCP PCB that is not CLOSED is in one of the lists.
463    2) A PCB is only in one of the lists.
464    3) All PCBs in the tcp_listen_pcbs list is in LISTEN state.
465    4) All PCBs in the tcp_tw_pcbs list is in TIME-WAIT state.
466 */
467
468 /* Define two macros, TCP_REG and TCP_RMV that registers a TCP PCB
469    with a PCB list or removes a PCB from a list, respectively. */
470 #if 0
471 #define TCP_REG(pcbs, npcb) do {\
472                             LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", npcb, npcb->local_port)); \
473                             for(tcp_tmp_pcb = *pcbs; \
474           tcp_tmp_pcb != NULL; \
475         tcp_tmp_pcb = tcp_tmp_pcb->next) { \
476                                 LWIP_ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != npcb); \
477                             } \
478                             LWIP_ASSERT("TCP_REG: pcb->state != CLOSED", npcb->state != CLOSED); \
479                             npcb->next = *pcbs; \
480                             LWIP_ASSERT("TCP_REG: npcb->next != npcb", npcb->next != npcb); \
481                             *(pcbs) = npcb; \
482                             LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \
483               tcp_timer_needed(); \
484                             } while(0)
485 #define TCP_RMV(pcbs, npcb) do { \
486                             LWIP_ASSERT("TCP_RMV: pcbs != NULL", *pcbs != NULL); \
487                             LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", npcb, *pcbs)); \
488                             if(*pcbs == npcb) { \
489                                *pcbs = (*pcbs)->next; \
490                             } else for(tcp_tmp_pcb = *pcbs; tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \
491                                if(tcp_tmp_pcb->next != NULL && tcp_tmp_pcb->next == npcb) { \
492                                   tcp_tmp_pcb->next = npcb->next; \
493                                   break; \
494                                } \
495                             } \
496                             npcb->next = NULL; \
497                             LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \
498                             LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", npcb, *pcbs)); \
499                             } while(0)
500
501 #else /* LWIP_DEBUG */
502 #define TCP_REG(pcbs, npcb) do { \
503                             npcb->next = *pcbs; \
504                             *(pcbs) = npcb; \
505               tcp_timer_needed(); \
506                             } while(0)
507 #define TCP_RMV(pcbs, npcb) do { \
508                             if(*(pcbs) == npcb) { \
509                                (*(pcbs)) = (*pcbs)->next; \
510                             } else for(tcp_tmp_pcb = *pcbs; tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \
511                                if(tcp_tmp_pcb->next != NULL && tcp_tmp_pcb->next == npcb) { \
512                                   tcp_tmp_pcb->next = npcb->next; \
513                                   break; \
514                                } \
515                             } \
516                             npcb->next = NULL; \
517                             } while(0)
518 #endif /* LWIP_DEBUG */
519 #endif /* __LWIP_TCP_H__ */
520
521
522