ReactOS 0.4.16-dev-732-g2d1144a
tcp.c
Go to the documentation of this file.
1
68/*
69 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
70 * All rights reserved.
71 *
72 * Redistribution and use in source and binary forms, with or without modification,
73 * are permitted provided that the following conditions are met:
74 *
75 * 1. Redistributions of source code must retain the above copyright notice,
76 * this list of conditions and the following disclaimer.
77 * 2. Redistributions in binary form must reproduce the above copyright notice,
78 * this list of conditions and the following disclaimer in the documentation
79 * and/or other materials provided with the distribution.
80 * 3. The name of the author may not be used to endorse or promote products
81 * derived from this software without specific prior written permission.
82 *
83 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
84 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
85 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
86 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
87 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
88 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
89 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
90 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
91 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
92 * OF SUCH DAMAGE.
93 *
94 * This file is part of the lwIP TCP/IP stack.
95 *
96 * Author: Adam Dunkels <adam@sics.se>
97 *
98 */
99
100#include "lwip/opt.h"
101
102#if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
103
104#include "lwip/def.h"
105#include "lwip/mem.h"
106#include "lwip/memp.h"
107#include "lwip/tcp.h"
108#include "lwip/priv/tcp_priv.h"
109#include "lwip/debug.h"
110#include "lwip/stats.h"
111#include "lwip/ip6.h"
112#include "lwip/ip6_addr.h"
113#include "lwip/nd6.h"
114
115#include <string.h>
116
117#ifdef LWIP_HOOK_FILENAME
118#include LWIP_HOOK_FILENAME
119#endif
120
121#ifndef TCP_LOCAL_PORT_RANGE_START
122/* From http://www.iana.org/assignments/port-numbers:
123 "The Dynamic and/or Private Ports are those from 49152 through 65535" */
124#define TCP_LOCAL_PORT_RANGE_START 0xc000
125#define TCP_LOCAL_PORT_RANGE_END 0xffff
126#define TCP_ENSURE_LOCAL_PORT_RANGE(port) ((u16_t)(((port) & (u16_t)~TCP_LOCAL_PORT_RANGE_START) + TCP_LOCAL_PORT_RANGE_START))
127#endif
128
129#if LWIP_TCP_KEEPALIVE
130#define TCP_KEEP_DUR(pcb) ((pcb)->keep_cnt * (pcb)->keep_intvl)
131#define TCP_KEEP_INTVL(pcb) ((pcb)->keep_intvl)
132#else /* LWIP_TCP_KEEPALIVE */
133#define TCP_KEEP_DUR(pcb) TCP_MAXIDLE
134#define TCP_KEEP_INTVL(pcb) TCP_KEEPINTVL_DEFAULT
135#endif /* LWIP_TCP_KEEPALIVE */
136
137/* As initial send MSS, we use TCP_MSS but limit it to 536. */
138#if TCP_MSS > 536
139#define INITIAL_MSS 536
140#else
141#define INITIAL_MSS TCP_MSS
142#endif
143
144static const char *const tcp_state_str[] = {
145 "CLOSED",
146 "LISTEN",
147 "SYN_SENT",
148 "SYN_RCVD",
149 "ESTABLISHED",
150 "FIN_WAIT_1",
151 "FIN_WAIT_2",
152 "CLOSE_WAIT",
153 "CLOSING",
154 "LAST_ACK",
155 "TIME_WAIT"
156};
157
158/* last local TCP port */
159static u16_t tcp_port = TCP_LOCAL_PORT_RANGE_START;
160
161/* Incremented every coarse grained timer shot (typically every 500 ms). */
162u32_t tcp_ticks;
163static const u8_t tcp_backoff[13] =
164{ 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7};
165/* Times per slowtmr hits */
166static const u8_t tcp_persist_backoff[7] = { 3, 6, 12, 24, 48, 96, 120 };
167
168/* The TCP PCB lists. */
169
171struct tcp_pcb *tcp_bound_pcbs;
173union tcp_listen_pcbs_t tcp_listen_pcbs;
176struct tcp_pcb *tcp_active_pcbs;
178struct tcp_pcb *tcp_tw_pcbs;
179
181struct tcp_pcb **const tcp_pcb_lists[] = {&tcp_listen_pcbs.pcbs, &tcp_bound_pcbs,
182 &tcp_active_pcbs, &tcp_tw_pcbs
183};
184
185u8_t tcp_active_pcbs_changed;
186
188static u8_t tcp_timer;
189static u8_t tcp_timer_ctr;
190static u16_t tcp_new_port(void);
191
192static err_t tcp_close_shutdown_fin(struct tcp_pcb *pcb);
193#if LWIP_TCP_PCB_NUM_EXT_ARGS
194static void tcp_ext_arg_invoke_callbacks_destroyed(struct tcp_pcb_ext_args *ext_args);
195#endif
196
200void
201tcp_init(void)
202{
203#ifdef LWIP_RAND
204 tcp_port = TCP_ENSURE_LOCAL_PORT_RANGE(LWIP_RAND());
205#endif /* LWIP_RAND */
206}
207
209void
210tcp_free(struct tcp_pcb *pcb)
211{
212 LWIP_ASSERT("tcp_free: LISTEN", pcb->state != LISTEN);
213#if LWIP_TCP_PCB_NUM_EXT_ARGS
214 tcp_ext_arg_invoke_callbacks_destroyed(pcb->ext_args);
215#endif
216 memp_free(MEMP_TCP_PCB, pcb);
217}
218
220static void
221tcp_free_listen(struct tcp_pcb *pcb)
222{
223 LWIP_ASSERT("tcp_free_listen: !LISTEN", pcb->state != LISTEN);
224#if LWIP_TCP_PCB_NUM_EXT_ARGS
225 tcp_ext_arg_invoke_callbacks_destroyed(pcb->ext_args);
226#endif
227 memp_free(MEMP_TCP_PCB_LISTEN, pcb);
228}
229
233void
234tcp_tmr(void)
235{
236 /* Call tcp_fasttmr() every 250 ms */
237 tcp_fasttmr();
238
239 if (++tcp_timer & 1) {
240 /* Call tcp_slowtmr() every 500 ms, i.e., every other timer
241 tcp_tmr() is called. */
242 tcp_slowtmr();
243 }
244}
245
246#if LWIP_CALLBACK_API || TCP_LISTEN_BACKLOG
250static void
251tcp_remove_listener(struct tcp_pcb *list, struct tcp_pcb_listen *lpcb)
252{
253 struct tcp_pcb *pcb;
254
255 LWIP_ASSERT("tcp_remove_listener: invalid listener", lpcb != NULL);
256
257 for (pcb = list; pcb != NULL; pcb = pcb->next) {
258 if (pcb->listener == lpcb) {
259 pcb->listener = NULL;
260 }
261 }
262}
263#endif
264
268static void
269tcp_listen_closed(struct tcp_pcb *pcb)
270{
271#if LWIP_CALLBACK_API || TCP_LISTEN_BACKLOG
272 size_t i;
273 LWIP_ASSERT("pcb != NULL", pcb != NULL);
274 LWIP_ASSERT("pcb->state == LISTEN", pcb->state == LISTEN);
275 for (i = 1; i < LWIP_ARRAYSIZE(tcp_pcb_lists); i++) {
276 tcp_remove_listener(*tcp_pcb_lists[i], (struct tcp_pcb_listen *)pcb);
277 }
278#endif
279 LWIP_UNUSED_ARG(pcb);
280}
281
282#if TCP_LISTEN_BACKLOG
293void
294tcp_backlog_delayed(struct tcp_pcb *pcb)
295{
296 LWIP_ASSERT("pcb != NULL", pcb != NULL);
298 if ((pcb->flags & TF_BACKLOGPEND) == 0) {
299 if (pcb->listener != NULL) {
300 pcb->listener->accepts_pending++;
301 LWIP_ASSERT("accepts_pending != 0", pcb->listener->accepts_pending != 0);
302 tcp_set_flags(pcb, TF_BACKLOGPEND);
303 }
304 }
305}
306
316void
317tcp_backlog_accepted(struct tcp_pcb *pcb)
318{
319 LWIP_ASSERT("pcb != NULL", pcb != NULL);
321 if ((pcb->flags & TF_BACKLOGPEND) != 0) {
322 if (pcb->listener != NULL) {
323 LWIP_ASSERT("accepts_pending != 0", pcb->listener->accepts_pending != 0);
324 pcb->listener->accepts_pending--;
325 tcp_clear_flags(pcb, TF_BACKLOGPEND);
326 }
327 }
328}
329#endif /* TCP_LISTEN_BACKLOG */
330
347static err_t
348tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data)
349{
350 LWIP_ASSERT("tcp_close_shutdown: invalid pcb", pcb != NULL);
351
352 if (rst_on_unacked_data && ((pcb->state == ESTABLISHED) || (pcb->state == CLOSE_WAIT))) {
353 if ((pcb->refused_data != NULL) || (pcb->rcv_wnd != TCP_WND_MAX(pcb))) {
354 /* Not all data received by application, send RST to tell the remote
355 side about this. */
356 LWIP_ASSERT("pcb->flags & TF_RXCLOSED", pcb->flags & TF_RXCLOSED);
357
358 /* don't call tcp_abort here: we must not deallocate the pcb since
359 that might not be expected when calling tcp_close */
360 tcp_rst(pcb, pcb->snd_nxt, pcb->rcv_nxt, &pcb->local_ip, &pcb->remote_ip,
361 pcb->local_port, pcb->remote_port);
362
363 tcp_pcb_purge(pcb);
364 TCP_RMV_ACTIVE(pcb);
365 /* Deallocate the pcb since we already sent a RST for it */
366 if (tcp_input_pcb == pcb) {
367 /* prevent using a deallocated pcb: free it from tcp_input later */
368 tcp_trigger_input_pcb_close();
369 } else {
370 tcp_free(pcb);
371 }
372 return ERR_OK;
373 }
374 }
375
376 /* - states which free the pcb are handled here,
377 - states which send FIN and change state are handled in tcp_close_shutdown_fin() */
378 switch (pcb->state) {
379 case CLOSED:
380 /* Closing a pcb in the CLOSED state might seem erroneous,
381 * however, it is in this state once allocated and as yet unused
382 * and the user needs some way to free it should the need arise.
383 * Calling tcp_close() with a pcb that has already been closed, (i.e. twice)
384 * or for a pcb that has been used and then entered the CLOSED state
385 * is erroneous, but this should never happen as the pcb has in those cases
386 * been freed, and so any remaining handles are bogus. */
387 if (pcb->local_port != 0) {
388 TCP_RMV(&tcp_bound_pcbs, pcb);
389 }
390 tcp_free(pcb);
391 break;
392 case LISTEN:
393 tcp_listen_closed(pcb);
394 tcp_pcb_remove(&tcp_listen_pcbs.pcbs, pcb);
395 tcp_free_listen(pcb);
396 break;
397 case SYN_SENT:
398 TCP_PCB_REMOVE_ACTIVE(pcb);
399 tcp_free(pcb);
400 MIB2_STATS_INC(mib2.tcpattemptfails);
401 break;
402 default:
403 return tcp_close_shutdown_fin(pcb);
404 }
405 return ERR_OK;
406}
407
408static err_t
409tcp_close_shutdown_fin(struct tcp_pcb *pcb)
410{
411 err_t err;
412 LWIP_ASSERT("pcb != NULL", pcb != NULL);
413
414 switch (pcb->state) {
415 case SYN_RCVD:
416 err = tcp_send_fin(pcb);
417 if (err == ERR_OK) {
418 tcp_backlog_accepted(pcb);
419 MIB2_STATS_INC(mib2.tcpattemptfails);
420 pcb->state = FIN_WAIT_1;
421 }
422 break;
423 case ESTABLISHED:
424 err = tcp_send_fin(pcb);
425 if (err == ERR_OK) {
426 MIB2_STATS_INC(mib2.tcpestabresets);
427 pcb->state = FIN_WAIT_1;
428 }
429 break;
430 case CLOSE_WAIT:
431 err = tcp_send_fin(pcb);
432 if (err == ERR_OK) {
433 MIB2_STATS_INC(mib2.tcpestabresets);
434 pcb->state = LAST_ACK;
435 }
436 break;
437 default:
438 /* Has already been closed, do nothing. */
439 return ERR_OK;
440 }
441
442 if (err == ERR_OK) {
443 /* To ensure all data has been sent when tcp_close returns, we have
444 to make sure tcp_output doesn't fail.
445 Since we don't really have to ensure all data has been sent when tcp_close
446 returns (unsent data is sent from tcp timer functions, also), we don't care
447 for the return value of tcp_output for now. */
448 tcp_output(pcb);
449 } else if (err == ERR_MEM) {
450 /* Mark this pcb for closing. Closing is retried from tcp_tmr. */
451 tcp_set_flags(pcb, TF_CLOSEPEND);
452 /* We have to return ERR_OK from here to indicate to the callers that this
453 pcb should not be used any more as it will be freed soon via tcp_tmr.
454 This is OK here since sending FIN does not guarantee a time frime for
455 actually freeing the pcb, either (it is left in closure states for
456 remote ACK or timeout) */
457 return ERR_OK;
458 }
459 return err;
460}
461
483err_t
484tcp_close(struct tcp_pcb *pcb)
485{
487
488 LWIP_ERROR("tcp_close: invalid pcb", pcb != NULL, return ERR_ARG);
489 LWIP_DEBUGF(TCP_DEBUG, ("tcp_close: closing in "));
490
491 tcp_debug_print_state(pcb->state);
492
493 if (pcb->state != LISTEN) {
494 /* Set a flag not to receive any more data... */
495 tcp_set_flags(pcb, TF_RXCLOSED);
496 }
497 /* ... and close */
498 return tcp_close_shutdown(pcb, 1);
499}
500
514err_t
515tcp_shutdown(struct tcp_pcb *pcb, int shut_rx, int shut_tx)
516{
518
519 LWIP_ERROR("tcp_shutdown: invalid pcb", pcb != NULL, return ERR_ARG);
520
521 if (pcb->state == LISTEN) {
522 return ERR_CONN;
523 }
524 if (shut_rx) {
525 /* shut down the receive side: set a flag not to receive any more data... */
526 tcp_set_flags(pcb, TF_RXCLOSED);
527 if (shut_tx) {
528 /* shutting down the tx AND rx side is the same as closing for the raw API */
529 return tcp_close_shutdown(pcb, 1);
530 }
531 /* ... and free buffered data */
532 if (pcb->refused_data != NULL) {
533 pbuf_free(pcb->refused_data);
534 pcb->refused_data = NULL;
535 }
536 }
537 if (shut_tx) {
538 /* This can't happen twice since if it succeeds, the pcb's state is changed.
539 Only close in these states as the others directly deallocate the PCB */
540 switch (pcb->state) {
541 case SYN_RCVD:
542 case ESTABLISHED:
543 case CLOSE_WAIT:
544 return tcp_close_shutdown(pcb, (u8_t)shut_rx);
545 default:
546 /* Not (yet?) connected, cannot shutdown the TX side as that would bring us
547 into CLOSED state, where the PCB is deallocated. */
548 return ERR_CONN;
549 }
550 }
551 return ERR_OK;
552}
553
562void
563tcp_abandon(struct tcp_pcb *pcb, int reset)
564{
565 u32_t seqno, ackno;
566#if LWIP_CALLBACK_API
567 tcp_err_fn errf;
568#endif /* LWIP_CALLBACK_API */
569 void *errf_arg;
570
572
573 LWIP_ERROR("tcp_abandon: invalid pcb", pcb != NULL, return);
574
575 /* pcb->state LISTEN not allowed here */
576 LWIP_ASSERT("don't call tcp_abort/tcp_abandon for listen-pcbs",
577 pcb->state != LISTEN);
578 /* Figure out on which TCP PCB list we are, and remove us. If we
579 are in an active state, call the receive function associated with
580 the PCB with a NULL argument, and send an RST to the remote end. */
581 if (pcb->state == TIME_WAIT) {
582 tcp_pcb_remove(&tcp_tw_pcbs, pcb);
583 tcp_free(pcb);
584 } else {
585 int send_rst = 0;
586 u16_t local_port = 0;
587 enum tcp_state last_state;
588 seqno = pcb->snd_nxt;
589 ackno = pcb->rcv_nxt;
590#if LWIP_CALLBACK_API
591 errf = pcb->errf;
592#endif /* LWIP_CALLBACK_API */
593 errf_arg = pcb->callback_arg;
594 if (pcb->state == CLOSED) {
595 if (pcb->local_port != 0) {
596 /* bound, not yet opened */
597 TCP_RMV(&tcp_bound_pcbs, pcb);
598 }
599 } else {
600 send_rst = reset;
601 local_port = pcb->local_port;
602 TCP_PCB_REMOVE_ACTIVE(pcb);
603 }
604 if (pcb->unacked != NULL) {
605 tcp_segs_free(pcb->unacked);
606 }
607 if (pcb->unsent != NULL) {
608 tcp_segs_free(pcb->unsent);
609 }
610#if TCP_QUEUE_OOSEQ
611 if (pcb->ooseq != NULL) {
612 tcp_segs_free(pcb->ooseq);
613 }
614#endif /* TCP_QUEUE_OOSEQ */
615 tcp_backlog_accepted(pcb);
616 if (send_rst) {
617 LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_abandon: sending RST\n"));
618 tcp_rst(pcb, seqno, ackno, &pcb->local_ip, &pcb->remote_ip, local_port, pcb->remote_port);
619 }
620 last_state = pcb->state;
621 tcp_free(pcb);
622 TCP_EVENT_ERR(last_state, errf, errf_arg, ERR_ABRT);
623 }
624}
625
637void
638tcp_abort(struct tcp_pcb *pcb)
639{
640 tcp_abandon(pcb, 1);
641}
642
661err_t
662tcp_bind(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
663{
664 int i;
665 int max_pcb_list = NUM_TCP_PCB_LISTS;
666 struct tcp_pcb *cpcb;
667#if LWIP_IPV6 && LWIP_IPV6_SCOPES
668 ip_addr_t zoned_ipaddr;
669#endif /* LWIP_IPV6 && LWIP_IPV6_SCOPES */
670
672
673#if LWIP_IPV4
674 /* Don't propagate NULL pointer (IPv4 ANY) to subsequent functions */
675 if (ipaddr == NULL) {
676 ipaddr = IP4_ADDR_ANY;
677 }
678#else /* LWIP_IPV4 */
679 LWIP_ERROR("tcp_bind: invalid ipaddr", ipaddr != NULL, return ERR_ARG);
680#endif /* LWIP_IPV4 */
681
682 LWIP_ERROR("tcp_bind: invalid pcb", pcb != NULL, return ERR_ARG);
683
684 LWIP_ERROR("tcp_bind: can only bind in state CLOSED", pcb->state == CLOSED, return ERR_VAL);
685
686#if SO_REUSE
687 /* Unless the REUSEADDR flag is set,
688 we have to check the pcbs in TIME-WAIT state, also.
689 We do not dump TIME_WAIT pcb's; they can still be matched by incoming
690 packets using both local and remote IP addresses and ports to distinguish.
691 */
692 if (ip_get_option(pcb, SOF_REUSEADDR)) {
693 max_pcb_list = NUM_TCP_PCB_LISTS_NO_TIME_WAIT;
694 }
695#endif /* SO_REUSE */
696
697#if LWIP_IPV6 && LWIP_IPV6_SCOPES
698 /* If the given IP address should have a zone but doesn't, assign one now.
699 * This is legacy support: scope-aware callers should always provide properly
700 * zoned source addresses. Do the zone selection before the address-in-use
701 * check below; as such we have to make a temporary copy of the address. */
702 if (IP_IS_V6(ipaddr) && ip6_addr_lacks_zone(ip_2_ip6(ipaddr), IP6_UNICAST)) {
703 ip_addr_copy(zoned_ipaddr, *ipaddr);
704 ip6_addr_select_zone(ip_2_ip6(&zoned_ipaddr), ip_2_ip6(&zoned_ipaddr));
705 ipaddr = &zoned_ipaddr;
706 }
707#endif /* LWIP_IPV6 && LWIP_IPV6_SCOPES */
708
709 if (port == 0) {
710 port = tcp_new_port();
711 if (port == 0) {
712 return ERR_BUF;
713 }
714 } else {
715 /* Check if the address already is in use (on all lists) */
716 for (i = 0; i < max_pcb_list; i++) {
717 for (cpcb = *tcp_pcb_lists[i]; cpcb != NULL; cpcb = cpcb->next) {
718 if (cpcb->local_port == port) {
719#if SO_REUSE
720 /* Omit checking for the same port if both pcbs have REUSEADDR set.
721 For SO_REUSEADDR, the duplicate-check for a 5-tuple is done in
722 tcp_connect. */
723 if (!ip_get_option(pcb, SOF_REUSEADDR) ||
725#endif /* SO_REUSE */
726 {
727 /* @todo: check accept_any_ip_version */
728 if ((IP_IS_V6(ipaddr) == IP_IS_V6_VAL(cpcb->local_ip)) &&
729 (ip_addr_isany(&cpcb->local_ip) ||
730 ip_addr_isany(ipaddr) ||
731 ip_addr_eq(&cpcb->local_ip, ipaddr))) {
732 return ERR_USE;
733 }
734 }
735 }
736 }
737 }
738 }
739
740 if (!ip_addr_isany(ipaddr)
741#if LWIP_IPV4 && LWIP_IPV6
742 || (IP_GET_TYPE(ipaddr) != IP_GET_TYPE(&pcb->local_ip))
743#endif /* LWIP_IPV4 && LWIP_IPV6 */
744 ) {
745 ip_addr_set(&pcb->local_ip, ipaddr);
746 }
747 pcb->local_port = port;
748 TCP_REG(&tcp_bound_pcbs, pcb);
749 LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: bind to port %"U16_F"\n", port));
750 return ERR_OK;
751}
752
763void
764tcp_bind_netif(struct tcp_pcb *pcb, const struct netif *netif)
765{
767 if (netif != NULL) {
768 pcb->netif_idx = netif_get_index(netif);
769 } else {
770 pcb->netif_idx = NETIF_NO_INDEX;
771 }
772}
773
774#if LWIP_CALLBACK_API
778static err_t
779tcp_accept_null(void *arg, struct tcp_pcb *pcb, err_t err)
780{
783
784 LWIP_ASSERT("tcp_accept_null: invalid pcb", pcb != NULL);
785
786 tcp_abort(pcb);
787
788 return ERR_ABRT;
789}
790#endif /* LWIP_CALLBACK_API */
791
825struct tcp_pcb *
826tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog)
827{
829 return tcp_listen_with_backlog_and_err(pcb, backlog, NULL);
830}
831
848struct tcp_pcb *
849tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u8_t backlog, err_t *err)
850{
851 struct tcp_pcb_listen *lpcb = NULL;
852 err_t res;
853
854 LWIP_UNUSED_ARG(backlog);
855
857
858 LWIP_ERROR("tcp_listen_with_backlog_and_err: invalid pcb", pcb != NULL, res = ERR_ARG; goto done);
859 LWIP_ERROR("tcp_listen_with_backlog_and_err: pcb already connected", pcb->state == CLOSED, res = ERR_CLSD; goto done);
860
861 /* already listening? */
862 if (pcb->state == LISTEN) {
863 lpcb = (struct tcp_pcb_listen *)pcb;
865 goto done;
866 }
867#if SO_REUSE
868 if (ip_get_option(pcb, SOF_REUSEADDR)) {
869 /* Since SOF_REUSEADDR allows reusing a local address before the pcb's usage
870 is declared (listen-/connection-pcb), we have to make sure now that
871 this port is only used once for every local IP. */
872 for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
873 if ((lpcb->local_port == pcb->local_port) &&
874 ip_addr_eq(&lpcb->local_ip, &pcb->local_ip)) {
875 /* this address/port is already used */
876 lpcb = NULL;
877 res = ERR_USE;
878 goto done;
879 }
880 }
881 }
882#endif /* SO_REUSE */
883 lpcb = (struct tcp_pcb_listen *)memp_malloc(MEMP_TCP_PCB_LISTEN);
884 if (lpcb == NULL) {
885 res = ERR_MEM;
886 goto done;
887 }
888 lpcb->callback_arg = pcb->callback_arg;
889 lpcb->local_port = pcb->local_port;
890 lpcb->state = LISTEN;
891 lpcb->prio = pcb->prio;
892 lpcb->so_options = pcb->so_options;
893 lpcb->netif_idx = pcb->netif_idx;
894 lpcb->ttl = pcb->ttl;
895 lpcb->tos = pcb->tos;
896#if LWIP_VLAN_PCP
897 lpcb->netif_hints.tci = pcb->netif_hints.tci;
898#endif /* LWIP_VLAN_PCP */
899#if LWIP_IPV4 && LWIP_IPV6
900 IP_SET_TYPE_VAL(lpcb->remote_ip, pcb->local_ip.type);
901#endif /* LWIP_IPV4 && LWIP_IPV6 */
902 ip_addr_copy(lpcb->local_ip, pcb->local_ip);
903 if (pcb->local_port != 0) {
904 TCP_RMV(&tcp_bound_pcbs, pcb);
905 }
906#if LWIP_TCP_PCB_NUM_EXT_ARGS
907 /* copy over ext_args to listening pcb */
908 memcpy(&lpcb->ext_args, &pcb->ext_args, sizeof(pcb->ext_args));
909#endif
910 tcp_free(pcb);
911#if LWIP_CALLBACK_API
912 lpcb->accept = tcp_accept_null;
913#endif /* LWIP_CALLBACK_API */
914#if TCP_LISTEN_BACKLOG
915 lpcb->accepts_pending = 0;
916 tcp_backlog_set(lpcb, backlog);
917#endif /* TCP_LISTEN_BACKLOG */
918 TCP_REG(&tcp_listen_pcbs.pcbs, (struct tcp_pcb *)lpcb);
919 res = ERR_OK;
920done:
921 if (err != NULL) {
922 *err = res;
923 }
924 return (struct tcp_pcb *)lpcb;
925}
926
933u32_t
934tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb)
935{
936 u32_t new_right_edge;
937
938 LWIP_ASSERT("tcp_update_rcv_ann_wnd: invalid pcb", pcb != NULL);
939 new_right_edge = pcb->rcv_nxt + pcb->rcv_wnd;
940
941 if (TCP_SEQ_GEQ(new_right_edge, pcb->rcv_ann_right_edge + LWIP_MIN((TCP_WND / 2), pcb->mss))) {
942 /* we can advertise more window */
943 pcb->rcv_ann_wnd = pcb->rcv_wnd;
944 return new_right_edge - pcb->rcv_ann_right_edge;
945 } else {
946 if (TCP_SEQ_GT(pcb->rcv_nxt, pcb->rcv_ann_right_edge)) {
947 /* Can happen due to other end sending out of advertised window,
948 * but within actual available (but not yet advertised) window */
949 pcb->rcv_ann_wnd = 0;
950 } else {
951 /* keep the right edge of window constant */
952 u32_t new_rcv_ann_wnd = pcb->rcv_ann_right_edge - pcb->rcv_nxt;
953#if !LWIP_WND_SCALE
954 LWIP_ASSERT("new_rcv_ann_wnd <= 0xffff", new_rcv_ann_wnd <= 0xffff);
955#endif
956 pcb->rcv_ann_wnd = (tcpwnd_size_t)new_rcv_ann_wnd;
957 }
958 return 0;
959 }
960}
961
971void
972tcp_recved(struct tcp_pcb *pcb, u16_t len)
973{
974 u32_t wnd_inflation;
975 tcpwnd_size_t rcv_wnd;
976
978
979 LWIP_ERROR("tcp_recved: invalid pcb", pcb != NULL, return);
980
981 /* pcb->state LISTEN not allowed here */
982 LWIP_ASSERT("don't call tcp_recved for listen-pcbs",
983 pcb->state != LISTEN);
984
985 rcv_wnd = (tcpwnd_size_t)(pcb->rcv_wnd + len);
986 if ((rcv_wnd > TCP_WND_MAX(pcb)) || (rcv_wnd < pcb->rcv_wnd)) {
987 /* window got too big or tcpwnd_size_t overflow */
988 LWIP_DEBUGF(TCP_DEBUG, ("tcp_recved: window got too big or tcpwnd_size_t overflow\n"));
989 pcb->rcv_wnd = TCP_WND_MAX(pcb);
990 } else {
991 pcb->rcv_wnd = rcv_wnd;
992 }
993
994 wnd_inflation = tcp_update_rcv_ann_wnd(pcb);
995
996 /* If the change in the right edge of window is significant (default
997 * watermark is TCP_WND/4), then send an explicit update now.
998 * Otherwise wait for a packet to be sent in the normal course of
999 * events (or more window to be available later) */
1000 if (wnd_inflation >= TCP_WND_UPDATE_THRESHOLD) {
1001 tcp_ack_now(pcb);
1002 tcp_output(pcb);
1003 }
1004
1005 LWIP_DEBUGF(TCP_DEBUG, ("tcp_recved: received %"U16_F" bytes, wnd %"TCPWNDSIZE_F" (%"TCPWNDSIZE_F").\n",
1006 len, pcb->rcv_wnd, (u16_t)(TCP_WND_MAX(pcb) - pcb->rcv_wnd)));
1007}
1008
1014static u16_t
1015tcp_new_port(void)
1016{
1017 u8_t i;
1018 u16_t n = 0;
1019 struct tcp_pcb *pcb;
1020
1021again:
1022 tcp_port++;
1023 if (tcp_port == TCP_LOCAL_PORT_RANGE_END) {
1024 tcp_port = TCP_LOCAL_PORT_RANGE_START;
1025 }
1026 /* Check all PCB lists. */
1027 for (i = 0; i < NUM_TCP_PCB_LISTS; i++) {
1028 for (pcb = *tcp_pcb_lists[i]; pcb != NULL; pcb = pcb->next) {
1029 if (pcb->local_port == tcp_port) {
1030 n++;
1031 if (n > (TCP_LOCAL_PORT_RANGE_END - TCP_LOCAL_PORT_RANGE_START)) {
1032 return 0;
1033 }
1034 goto again;
1035 }
1036 }
1037 }
1038 return tcp_port;
1039}
1040
1070err_t
1071tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port,
1072 tcp_connected_fn connected)
1073{
1074 struct netif *netif = NULL;
1075 err_t ret;
1076 u32_t iss;
1077 u16_t old_local_port;
1078
1080
1081 LWIP_ERROR("tcp_connect: invalid pcb", pcb != NULL, return ERR_ARG);
1082 LWIP_ERROR("tcp_connect: invalid ipaddr", ipaddr != NULL, return ERR_ARG);
1083
1084 LWIP_ERROR("tcp_connect: can only connect from state CLOSED", pcb->state == CLOSED, return ERR_ISCONN);
1085
1086 LWIP_DEBUGF(TCP_DEBUG, ("tcp_connect to port %"U16_F"\n", port));
1087 ip_addr_set(&pcb->remote_ip, ipaddr);
1088 pcb->remote_port = port;
1089
1090 if (pcb->netif_idx != NETIF_NO_INDEX) {
1091 netif = netif_get_by_index(pcb->netif_idx);
1092 } else {
1093 /* check if we have a route to the remote host */
1094 netif = ip_route(&pcb->local_ip, &pcb->remote_ip);
1095 }
1096 if (netif == NULL) {
1097 /* Don't even try to send a SYN packet if we have no route since that will fail. */
1098 return ERR_RTE;
1099 }
1100
1101 /* check if local IP has been assigned to pcb, if not, get one */
1102 if (ip_addr_isany(&pcb->local_ip)) {
1103 const ip_addr_t *local_ip = ip_netif_get_local_ip(netif, ipaddr);
1104 if (local_ip == NULL) {
1105 return ERR_RTE;
1106 }
1107 ip_addr_copy(pcb->local_ip, *local_ip);
1108 }
1109
1110#if LWIP_IPV6 && LWIP_IPV6_SCOPES
1111 /* If the given IP address should have a zone but doesn't, assign one now.
1112 * Given that we already have the target netif, this is easy and cheap. */
1113 if (IP_IS_V6(&pcb->remote_ip) &&
1114 ip6_addr_lacks_zone(ip_2_ip6(&pcb->remote_ip), IP6_UNICAST)) {
1115 ip6_addr_assign_zone(ip_2_ip6(&pcb->remote_ip), IP6_UNICAST, netif);
1116 }
1117#endif /* LWIP_IPV6 && LWIP_IPV6_SCOPES */
1118
1119 old_local_port = pcb->local_port;
1120 if (pcb->local_port == 0) {
1121 pcb->local_port = tcp_new_port();
1122 if (pcb->local_port == 0) {
1123 return ERR_BUF;
1124 }
1125 } else {
1126#if SO_REUSE
1127 if (ip_get_option(pcb, SOF_REUSEADDR)) {
1128 /* Since SOF_REUSEADDR allows reusing a local address, we have to make sure
1129 now that the 5-tuple is unique. */
1130 struct tcp_pcb *cpcb;
1131 int i;
1132 /* Don't check listen- and bound-PCBs, check active- and TIME-WAIT PCBs. */
1133 for (i = 2; i < NUM_TCP_PCB_LISTS; i++) {
1134 for (cpcb = *tcp_pcb_lists[i]; cpcb != NULL; cpcb = cpcb->next) {
1135 if ((cpcb->local_port == pcb->local_port) &&
1136 (cpcb->remote_port == port) &&
1137 ip_addr_eq(&cpcb->local_ip, &pcb->local_ip) &&
1138 ip_addr_eq(&cpcb->remote_ip, ipaddr)) {
1139 /* linux returns EISCONN here, but ERR_USE should be OK for us */
1140 return ERR_USE;
1141 }
1142 }
1143 }
1144 }
1145#endif /* SO_REUSE */
1146 }
1147
1148 iss = tcp_next_iss(pcb);
1149 pcb->rcv_nxt = 0;
1150 pcb->snd_nxt = iss;
1151 pcb->lastack = iss - 1;
1152 pcb->snd_wl2 = iss - 1;
1153 pcb->snd_lbb = iss - 1;
1154 /* Start with a window that does not need scaling. When window scaling is
1155 enabled and used, the window is enlarged when both sides agree on scaling. */
1156 pcb->rcv_wnd = pcb->rcv_ann_wnd = TCPWND_MIN16(TCP_WND);
1157 pcb->rcv_ann_right_edge = pcb->rcv_nxt;
1158 pcb->snd_wnd = TCP_WND;
1159 /* As initial send MSS, we use TCP_MSS but limit it to 536.
1160 The send MSS is updated when an MSS option is received. */
1161 pcb->mss = INITIAL_MSS;
1162#if TCP_CALCULATE_EFF_SEND_MSS
1163 pcb->mss = tcp_eff_send_mss_netif(pcb->mss, netif, &pcb->remote_ip);
1164#endif /* TCP_CALCULATE_EFF_SEND_MSS */
1165 pcb->cwnd = 1;
1166#if LWIP_CALLBACK_API
1167 pcb->connected = connected;
1168#else /* LWIP_CALLBACK_API */
1170#endif /* LWIP_CALLBACK_API */
1171
1172 /* Send a SYN together with the MSS option. */
1173 ret = tcp_enqueue_flags(pcb, TCP_SYN);
1174 if (ret == ERR_OK) {
1175 /* SYN segment was enqueued, changed the pcbs state now */
1176 pcb->state = SYN_SENT;
1177 if (old_local_port != 0) {
1178 TCP_RMV(&tcp_bound_pcbs, pcb);
1179 }
1180 TCP_REG_ACTIVE(pcb);
1181 MIB2_STATS_INC(mib2.tcpactiveopens);
1182
1183 tcp_output(pcb);
1184 }
1185 return ret;
1186}
1187
1195void
1196tcp_slowtmr(void)
1197{
1198 struct tcp_pcb *pcb, *prev;
1199 tcpwnd_size_t eff_wnd;
1200 u8_t pcb_remove; /* flag if a PCB should be removed */
1201 u8_t pcb_reset; /* flag if a RST should be sent when removing */
1202 err_t err;
1203
1204 err = ERR_OK;
1205
1206 ++tcp_ticks;
1207 ++tcp_timer_ctr;
1208
1209tcp_slowtmr_start:
1210 /* Steps through all of the active PCBs. */
1211 prev = NULL;
1212 pcb = tcp_active_pcbs;
1213 if (pcb == NULL) {
1214 LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: no active pcbs\n"));
1215 }
1216 while (pcb != NULL) {
1217 LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: processing active pcb\n"));
1218 LWIP_ASSERT("tcp_slowtmr: active pcb->state != CLOSED", pcb->state != CLOSED);
1219 LWIP_ASSERT("tcp_slowtmr: active pcb->state != LISTEN", pcb->state != LISTEN);
1220 LWIP_ASSERT("tcp_slowtmr: active pcb->state != TIME-WAIT", pcb->state != TIME_WAIT);
1221 if (pcb->last_timer == tcp_timer_ctr) {
1222 /* skip this pcb, we have already processed it */
1223 prev = pcb;
1224 pcb = pcb->next;
1225 continue;
1226 }
1227 pcb->last_timer = tcp_timer_ctr;
1228
1229 pcb_remove = 0;
1230 pcb_reset = 0;
1231
1232 if (pcb->state == SYN_SENT && pcb->nrtx >= TCP_SYNMAXRTX) {
1233 ++pcb_remove;
1234 LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: max SYN retries reached\n"));
1235 } else if (pcb->nrtx >= TCP_MAXRTX) {
1236 ++pcb_remove;
1237 LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: max DATA retries reached\n"));
1238 } else {
1239 if (pcb->persist_backoff > 0) {
1240 LWIP_ASSERT("tcp_slowtimr: persist ticking with in-flight data", pcb->unacked == NULL);
1241 LWIP_ASSERT("tcp_slowtimr: persist ticking with empty send buffer", pcb->unsent != NULL);
1242 if (pcb->persist_probe >= TCP_MAXRTX) {
1243 ++pcb_remove; /* max probes reached */
1244 } else {
1245 u8_t backoff_cnt = tcp_persist_backoff[pcb->persist_backoff - 1];
1246 if (pcb->persist_cnt < backoff_cnt) {
1247 pcb->persist_cnt++;
1248 }
1249 if (pcb->persist_cnt >= backoff_cnt) {
1250 int next_slot = 1; /* increment timer to next slot */
1251 /* If snd_wnd is zero, send 1 byte probes */
1252 if (pcb->snd_wnd == 0) {
1253 if (tcp_zero_window_probe(pcb) != ERR_OK) {
1254 next_slot = 0; /* try probe again with current slot */
1255 }
1256 /* snd_wnd not fully closed, split unsent head and fill window */
1257 } else {
1258 if (tcp_split_unsent_seg(pcb, (u16_t)pcb->snd_wnd) == ERR_OK) {
1259 if (tcp_output(pcb) == ERR_OK) {
1260 /* sending will cancel persist timer, else retry with current slot */
1261 next_slot = 0;
1262 }
1263 }
1264 }
1265 if (next_slot) {
1266 pcb->persist_cnt = 0;
1267 if (pcb->persist_backoff < sizeof(tcp_persist_backoff)) {
1268 pcb->persist_backoff++;
1269 }
1270 }
1271 }
1272 }
1273 } else {
1274 /* Increase the retransmission timer if it is running */
1275 if ((pcb->rtime >= 0) && (pcb->rtime < 0x7FFF)) {
1276 ++pcb->rtime;
1277 }
1278
1279 if (pcb->rtime >= pcb->rto) {
1280 /* Time for a retransmission. */
1281 LWIP_DEBUGF(TCP_RTO_DEBUG, ("tcp_slowtmr: rtime %"S16_F
1282 " pcb->rto %"S16_F"\n",
1283 pcb->rtime, pcb->rto));
1284 /* If prepare phase fails but we have unsent data but no unacked data,
1285 still execute the backoff calculations below, as this means we somehow
1286 failed to send segment. */
1287 if ((tcp_rexmit_rto_prepare(pcb) == ERR_OK) || ((pcb->unacked == NULL) && (pcb->unsent != NULL))) {
1288 /* Double retransmission time-out unless we are trying to
1289 * connect to somebody (i.e., we are in SYN_SENT). */
1290 if (pcb->state != SYN_SENT) {
1291 u8_t backoff_idx = LWIP_MIN(pcb->nrtx, sizeof(tcp_backoff) - 1);
1292 int calc_rto = ((pcb->sa >> 3) + pcb->sv) << tcp_backoff[backoff_idx];
1293 pcb->rto = (s16_t)LWIP_MIN(calc_rto, 0x7FFF);
1294 }
1295
1296 /* Reset the retransmission timer. */
1297 pcb->rtime = 0;
1298
1299 /* Reduce congestion window and ssthresh. */
1300 eff_wnd = LWIP_MIN(pcb->cwnd, pcb->snd_wnd);
1301 pcb->ssthresh = eff_wnd >> 1;
1302 if (pcb->ssthresh < (tcpwnd_size_t)(pcb->mss << 1)) {
1303 pcb->ssthresh = (tcpwnd_size_t)(pcb->mss << 1);
1304 }
1305 pcb->cwnd = pcb->mss;
1306 LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_slowtmr: cwnd %"TCPWNDSIZE_F
1307 " ssthresh %"TCPWNDSIZE_F"\n",
1308 pcb->cwnd, pcb->ssthresh));
1309 pcb->bytes_acked = 0;
1310
1311 /* The following needs to be called AFTER cwnd is set to one
1312 mss - STJ */
1313 tcp_rexmit_rto_commit(pcb);
1314 }
1315 }
1316 }
1317 }
1318 /* Check if this PCB has stayed too long in FIN-WAIT-2 */
1319 if (pcb->state == FIN_WAIT_2) {
1320 /* If this PCB is in FIN_WAIT_2 because of SHUT_WR don't let it time out. */
1321 if (pcb->flags & TF_RXCLOSED) {
1322 /* PCB was fully closed (either through close() or SHUT_RDWR):
1323 normal FIN-WAIT timeout handling. */
1324 if ((u32_t)(tcp_ticks - pcb->tmr) >
1325 TCP_FIN_WAIT_TIMEOUT / TCP_SLOW_INTERVAL) {
1326 ++pcb_remove;
1327 LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in FIN-WAIT-2\n"));
1328 }
1329 }
1330 }
1331
1332 /* Check if KEEPALIVE should be sent */
1333 if (ip_get_option(pcb, SOF_KEEPALIVE) &&
1334 ((pcb->state == ESTABLISHED) ||
1335 (pcb->state == CLOSE_WAIT))) {
1336 if ((u32_t)(tcp_ticks - pcb->tmr) >
1337 (pcb->keep_idle + TCP_KEEP_DUR(pcb)) / TCP_SLOW_INTERVAL) {
1338 LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: KEEPALIVE timeout. Aborting connection to "));
1339 ip_addr_debug_print_val(TCP_DEBUG, pcb->remote_ip);
1340 LWIP_DEBUGF(TCP_DEBUG, ("\n"));
1341
1342 ++pcb_remove;
1343 ++pcb_reset;
1344 } else if ((u32_t)(tcp_ticks - pcb->tmr) >
1345 (pcb->keep_idle + pcb->keep_cnt_sent * TCP_KEEP_INTVL(pcb))
1346 / TCP_SLOW_INTERVAL) {
1347 err = tcp_keepalive(pcb);
1348 if (err == ERR_OK) {
1349 pcb->keep_cnt_sent++;
1350 }
1351 }
1352 }
1353
1354 /* If this PCB has queued out of sequence data, but has been
1355 inactive for too long, will drop the data (it will eventually
1356 be retransmitted). */
1357#if TCP_QUEUE_OOSEQ
1358 if (pcb->ooseq != NULL &&
1359 (tcp_ticks - pcb->tmr >= (u32_t)pcb->rto * TCP_OOSEQ_TIMEOUT)) {
1360 LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_slowtmr: dropping OOSEQ queued data\n"));
1361 tcp_free_ooseq(pcb);
1362 }
1363#endif /* TCP_QUEUE_OOSEQ */
1364
1365 /* Check if this PCB has stayed too long in SYN-RCVD */
1366 if (pcb->state == SYN_RCVD) {
1367 if ((u32_t)(tcp_ticks - pcb->tmr) >
1368 TCP_SYN_RCVD_TIMEOUT / TCP_SLOW_INTERVAL) {
1369 ++pcb_remove;
1370 LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in SYN-RCVD\n"));
1371 }
1372 }
1373
1374 /* Check if this PCB has stayed too long in LAST-ACK */
1375 if (pcb->state == LAST_ACK) {
1376 if ((u32_t)(tcp_ticks - pcb->tmr) > 2 * TCP_MSL / TCP_SLOW_INTERVAL) {
1377 ++pcb_remove;
1378 LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in LAST-ACK\n"));
1379 }
1380 }
1381
1382 /* If the PCB should be removed, do it. */
1383 if (pcb_remove) {
1384 struct tcp_pcb *pcb2;
1385#if LWIP_CALLBACK_API
1386 tcp_err_fn err_fn = pcb->errf;
1387#endif /* LWIP_CALLBACK_API */
1388 void *err_arg;
1389 enum tcp_state last_state;
1390 tcp_pcb_purge(pcb);
1391 /* Remove PCB from tcp_active_pcbs list. */
1392 if (prev != NULL) {
1393 LWIP_ASSERT("tcp_slowtmr: middle tcp != tcp_active_pcbs", pcb != tcp_active_pcbs);
1394 prev->next = pcb->next;
1395 } else {
1396 /* This PCB was the first. */
1397 LWIP_ASSERT("tcp_slowtmr: first pcb == tcp_active_pcbs", tcp_active_pcbs == pcb);
1398 tcp_active_pcbs = pcb->next;
1399 }
1400
1401 if (pcb_reset) {
1402 tcp_rst(pcb, pcb->snd_nxt, pcb->rcv_nxt, &pcb->local_ip, &pcb->remote_ip,
1403 pcb->local_port, pcb->remote_port);
1404 }
1405
1406 err_arg = pcb->callback_arg;
1407 last_state = pcb->state;
1408 pcb2 = pcb;
1409 pcb = pcb->next;
1410 tcp_free(pcb2);
1411
1412 tcp_active_pcbs_changed = 0;
1413 TCP_EVENT_ERR(last_state, err_fn, err_arg, ERR_ABRT);
1414 if (tcp_active_pcbs_changed) {
1415 goto tcp_slowtmr_start;
1416 }
1417 } else {
1418 /* get the 'next' element now and work with 'prev' below (in case of abort) */
1419 prev = pcb;
1420 pcb = pcb->next;
1421
1422 /* We check if we should poll the connection. */
1423 ++prev->polltmr;
1424 if (prev->polltmr >= prev->pollinterval) {
1425 prev->polltmr = 0;
1426 LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: polling application\n"));
1427 tcp_active_pcbs_changed = 0;
1428 TCP_EVENT_POLL(prev, err);
1429 if (tcp_active_pcbs_changed) {
1430 goto tcp_slowtmr_start;
1431 }
1432 /* if err == ERR_ABRT, 'prev' is already deallocated */
1433 if (err == ERR_OK) {
1434 tcp_output(prev);
1435 }
1436 }
1437 }
1438 }
1439
1440
1441 /* Steps through all of the TIME-WAIT PCBs. */
1442 prev = NULL;
1443 pcb = tcp_tw_pcbs;
1444 while (pcb != NULL) {
1445 LWIP_ASSERT("tcp_slowtmr: TIME-WAIT pcb->state == TIME-WAIT", pcb->state == TIME_WAIT);
1446 pcb_remove = 0;
1447
1448 /* Check if this PCB has stayed long enough in TIME-WAIT */
1449 if ((u32_t)(tcp_ticks - pcb->tmr) > 2 * TCP_MSL / TCP_SLOW_INTERVAL) {
1450 ++pcb_remove;
1451 }
1452
1453 /* If the PCB should be removed, do it. */
1454 if (pcb_remove) {
1455 struct tcp_pcb *pcb2;
1456 tcp_pcb_purge(pcb);
1457 /* Remove PCB from tcp_tw_pcbs list. */
1458 if (prev != NULL) {
1459 LWIP_ASSERT("tcp_slowtmr: middle tcp != tcp_tw_pcbs", pcb != tcp_tw_pcbs);
1460 prev->next = pcb->next;
1461 } else {
1462 /* This PCB was the first. */
1463 LWIP_ASSERT("tcp_slowtmr: first pcb == tcp_tw_pcbs", tcp_tw_pcbs == pcb);
1464 tcp_tw_pcbs = pcb->next;
1465 }
1466 pcb2 = pcb;
1467 pcb = pcb->next;
1468 tcp_free(pcb2);
1469 } else {
1470 prev = pcb;
1471 pcb = pcb->next;
1472 }
1473 }
1474}
1475
1482void
1483tcp_fasttmr(void)
1484{
1485 struct tcp_pcb *pcb;
1486
1487 ++tcp_timer_ctr;
1488
1489tcp_fasttmr_start:
1490 pcb = tcp_active_pcbs;
1491
1492 while (pcb != NULL) {
1493 if (pcb->last_timer != tcp_timer_ctr) {
1494 struct tcp_pcb *next;
1495 pcb->last_timer = tcp_timer_ctr;
1496 /* send delayed ACKs */
1497 if (pcb->flags & TF_ACK_DELAY) {
1498 LWIP_DEBUGF(TCP_DEBUG, ("tcp_fasttmr: delayed ACK\n"));
1499 tcp_ack_now(pcb);
1500 tcp_output(pcb);
1501 tcp_clear_flags(pcb, TF_ACK_DELAY | TF_ACK_NOW);
1502 }
1503 /* send pending FIN */
1504 if (pcb->flags & TF_CLOSEPEND) {
1505 LWIP_DEBUGF(TCP_DEBUG, ("tcp_fasttmr: pending FIN\n"));
1506 tcp_clear_flags(pcb, TF_CLOSEPEND);
1507 tcp_close_shutdown_fin(pcb);
1508 }
1509
1510 next = pcb->next;
1511
1512 /* If there is data which was previously "refused" by upper layer */
1513 if (pcb->refused_data != NULL) {
1514 tcp_active_pcbs_changed = 0;
1515 tcp_process_refused_data(pcb);
1516 if (tcp_active_pcbs_changed) {
1517 /* application callback has changed the pcb list: restart the loop */
1518 goto tcp_fasttmr_start;
1519 }
1520 }
1521 pcb = next;
1522 } else {
1523 pcb = pcb->next;
1524 }
1525 }
1526}
1527
1529void
1530tcp_txnow(void)
1531{
1532 struct tcp_pcb *pcb;
1533
1534 for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
1535 if (pcb->flags & TF_NAGLEMEMERR) {
1536 tcp_output(pcb);
1537 }
1538 }
1539}
1540
1542err_t
1543tcp_process_refused_data(struct tcp_pcb *pcb)
1544{
1545#if TCP_QUEUE_OOSEQ && LWIP_WND_SCALE
1546 struct pbuf *rest;
1547#endif /* TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */
1548
1549 LWIP_ERROR("tcp_process_refused_data: invalid pcb", pcb != NULL, return ERR_ARG);
1550
1551#if TCP_QUEUE_OOSEQ && LWIP_WND_SCALE
1552 while (pcb->refused_data != NULL)
1553#endif /* TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */
1554 {
1555 err_t err;
1556 u8_t refused_flags = pcb->refused_data->flags;
1557 /* set pcb->refused_data to NULL in case the callback frees it and then
1558 closes the pcb */
1559 struct pbuf *refused_data = pcb->refused_data;
1560#if TCP_QUEUE_OOSEQ && LWIP_WND_SCALE
1561 pbuf_split_64k(refused_data, &rest);
1562 pcb->refused_data = rest;
1563#else /* TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */
1564 pcb->refused_data = NULL;
1565#endif /* TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */
1566 /* Notify again application with data previously received. */
1567 LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: notify kept packet\n"));
1568 TCP_EVENT_RECV(pcb, refused_data, ERR_OK, err);
1569 if (err == ERR_OK) {
1570 /* did refused_data include a FIN? */
1571 if ((refused_flags & PBUF_FLAG_TCP_FIN)
1573 && (rest == NULL)
1574#endif /* TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */
1575 ) {
1576 /* correct rcv_wnd as the application won't call tcp_recved()
1577 for the FIN's seqno */
1578 if (pcb->rcv_wnd != TCP_WND_MAX(pcb)) {
1579 pcb->rcv_wnd++;
1580 }
1581 TCP_EVENT_CLOSED(pcb, err);
1582 if (err == ERR_ABRT) {
1583 return ERR_ABRT;
1584 }
1585 }
1586 } else if (err == ERR_ABRT) {
1587 /* if err == ERR_ABRT, 'pcb' is already deallocated */
1588 /* Drop incoming packets because pcb is "full" (only if the incoming
1589 segment contains data). */
1590 LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: drop incoming packets, because pcb is \"full\"\n"));
1591 return ERR_ABRT;
1592 } else {
1593 /* data is still refused, pbuf is still valid (go on for ACK-only packets) */
1594#if TCP_QUEUE_OOSEQ && LWIP_WND_SCALE
1595 if (rest != NULL) {
1596 pbuf_cat(refused_data, rest);
1597 }
1598#endif /* TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */
1599 pcb->refused_data = refused_data;
1600 return ERR_INPROGRESS;
1601 }
1602 }
1603 return ERR_OK;
1604}
1605
1611void
1612tcp_segs_free(struct tcp_seg *seg)
1613{
1614 while (seg != NULL) {
1615 struct tcp_seg *next = seg->next;
1616 tcp_seg_free(seg);
1617 seg = next;
1618 }
1619}
1620
1626void
1627tcp_seg_free(struct tcp_seg *seg)
1628{
1629 if (seg != NULL) {
1630 if (seg->p != NULL) {
1631 pbuf_free(seg->p);
1632#if TCP_DEBUG
1633 seg->p = NULL;
1634#endif /* TCP_DEBUG */
1635 }
1636 memp_free(MEMP_TCP_SEG, seg);
1637 }
1638}
1639
1647void
1648tcp_setprio(struct tcp_pcb *pcb, u8_t prio)
1649{
1651
1652 LWIP_ERROR("tcp_setprio: invalid pcb", pcb != NULL, return);
1653
1654 pcb->prio = prio;
1655}
1656
1657#if TCP_QUEUE_OOSEQ
1665struct tcp_seg *
1666tcp_seg_copy(struct tcp_seg *seg)
1667{
1668 struct tcp_seg *cseg;
1669
1670 LWIP_ASSERT("tcp_seg_copy: invalid seg", seg != NULL);
1671
1672 cseg = (struct tcp_seg *)memp_malloc(MEMP_TCP_SEG);
1673 if (cseg == NULL) {
1674 return NULL;
1675 }
1676 SMEMCPY((u8_t *)cseg, (const u8_t *)seg, sizeof(struct tcp_seg));
1677 pbuf_ref(cseg->p);
1678 return cseg;
1679}
1680#endif /* TCP_QUEUE_OOSEQ */
1681
1682#if LWIP_CALLBACK_API
1687err_t
1688tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
1689{
1691
1692 LWIP_ERROR("tcp_recv_null: invalid pcb", pcb != NULL, return ERR_ARG);
1693
1694 if (p != NULL) {
1695 tcp_recved(pcb, p->tot_len);
1696 pbuf_free(p);
1697 } else if (err == ERR_OK) {
1698 return tcp_close(pcb);
1699 }
1700 return ERR_OK;
1701}
1702#endif /* LWIP_CALLBACK_API */
1703
1709static void
1710tcp_kill_prio(u8_t prio)
1711{
1712 struct tcp_pcb *pcb, *inactive;
1713 u32_t inactivity;
1714 u8_t mprio;
1715
1716 mprio = LWIP_MIN(TCP_PRIO_MAX, prio);
1717
1718 /* We want to kill connections with a lower prio, so bail out if
1719 * supplied prio is 0 - there can never be a lower prio
1720 */
1721 if (mprio == 0) {
1722 return;
1723 }
1724
1725 /* We only want kill connections with a lower prio, so decrement prio by one
1726 * and start searching for oldest connection with same or lower priority than mprio.
1727 * We want to find the connections with the lowest possible prio, and among
1728 * these the one with the longest inactivity time.
1729 */
1730 mprio--;
1731
1732 inactivity = 0;
1733 inactive = NULL;
1734 for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
1735 /* lower prio is always a kill candidate */
1736 if ((pcb->prio < mprio) ||
1737 /* longer inactivity is also a kill candidate */
1738 ((pcb->prio == mprio) && ((u32_t)(tcp_ticks - pcb->tmr) >= inactivity))) {
1739 inactivity = tcp_ticks - pcb->tmr;
1740 inactive = pcb;
1741 mprio = pcb->prio;
1742 }
1743 }
1744 if (inactive != NULL) {
1745 LWIP_DEBUGF(TCP_DEBUG, ("tcp_kill_prio: killing oldest PCB %p (%"S32_F")\n",
1746 (void *)inactive, inactivity));
1747 tcp_abort(inactive);
1748 }
1749}
1750
1755static void
1756tcp_kill_state(enum tcp_state state)
1757{
1758 struct tcp_pcb *pcb, *inactive;
1759 u32_t inactivity;
1760
1761 LWIP_ASSERT("invalid state", (state == CLOSING) || (state == LAST_ACK));
1762
1763 inactivity = 0;
1764 inactive = NULL;
1765 /* Go through the list of active pcbs and get the oldest pcb that is in state
1766 CLOSING/LAST_ACK. */
1767 for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
1768 if (pcb->state == state) {
1769 if ((u32_t)(tcp_ticks - pcb->tmr) >= inactivity) {
1770 inactivity = tcp_ticks - pcb->tmr;
1771 inactive = pcb;
1772 }
1773 }
1774 }
1775 if (inactive != NULL) {
1776 LWIP_DEBUGF(TCP_DEBUG, ("tcp_kill_closing: killing oldest %s PCB %p (%"S32_F")\n",
1777 tcp_state_str[state], (void *)inactive, inactivity));
1778 /* Don't send a RST, since no data is lost. */
1779 tcp_abandon(inactive, 0);
1780 }
1781}
1782
1787static void
1788tcp_kill_timewait(void)
1789{
1790 struct tcp_pcb *pcb, *inactive;
1791 u32_t inactivity;
1792
1793 inactivity = 0;
1794 inactive = NULL;
1795 /* Go through the list of TIME_WAIT pcbs and get the oldest pcb. */
1796 for (pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
1797 if ((u32_t)(tcp_ticks - pcb->tmr) >= inactivity) {
1798 inactivity = tcp_ticks - pcb->tmr;
1799 inactive = pcb;
1800 }
1801 }
1802 if (inactive != NULL) {
1803 LWIP_DEBUGF(TCP_DEBUG, ("tcp_kill_timewait: killing oldest TIME-WAIT PCB %p (%"S32_F")\n",
1804 (void *)inactive, inactivity));
1805 tcp_abort(inactive);
1806 }
1807}
1808
1809/* Called when allocating a pcb fails.
1810 * In this case, we want to handle all pcbs that want to close first: if we can
1811 * now send the FIN (which failed before), the pcb might be in a state that is
1812 * OK for us to now free it.
1813 */
1814static void
1815tcp_handle_closepend(void)
1816{
1817 struct tcp_pcb *pcb = tcp_active_pcbs;
1818
1819 while (pcb != NULL) {
1820 struct tcp_pcb *next = pcb->next;
1821 /* send pending FIN */
1822 if (pcb->flags & TF_CLOSEPEND) {
1823 LWIP_DEBUGF(TCP_DEBUG, ("tcp_handle_closepend: pending FIN\n"));
1824 tcp_clear_flags(pcb, TF_CLOSEPEND);
1825 tcp_close_shutdown_fin(pcb);
1826 }
1827 pcb = next;
1828 }
1829}
1830
1837struct tcp_pcb *
1838tcp_alloc(u8_t prio)
1839{
1840 struct tcp_pcb *pcb;
1841
1843
1844 pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB);
1845 if (pcb == NULL) {
1846 /* Try to send FIN for all pcbs stuck in TF_CLOSEPEND first */
1847 tcp_handle_closepend();
1848
1849 /* Try killing oldest connection in TIME-WAIT. */
1850 LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing off oldest TIME-WAIT connection\n"));
1851 tcp_kill_timewait();
1852 /* Try to allocate a tcp_pcb again. */
1853 pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB);
1854 if (pcb == NULL) {
1855 /* Try killing oldest connection in LAST-ACK (these wouldn't go to TIME-WAIT). */
1856 LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing off oldest LAST-ACK connection\n"));
1857 tcp_kill_state(LAST_ACK);
1858 /* Try to allocate a tcp_pcb again. */
1859 pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB);
1860 if (pcb == NULL) {
1861 /* Try killing oldest connection in CLOSING. */
1862 LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing off oldest CLOSING connection\n"));
1863 tcp_kill_state(CLOSING);
1864 /* Try to allocate a tcp_pcb again. */
1865 pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB);
1866 if (pcb == NULL) {
1867 /* Try killing oldest active connection with lower priority than the new one. */
1868 LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing oldest connection with prio lower than %d\n", prio));
1869 tcp_kill_prio(prio);
1870 /* Try to allocate a tcp_pcb again. */
1871 pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB);
1872 if (pcb != NULL) {
1873 /* adjust err stats: memp_malloc failed multiple times before */
1874 MEMP_STATS_DEC(err, MEMP_TCP_PCB);
1875 }
1876 }
1877 if (pcb != NULL) {
1878 /* adjust err stats: memp_malloc failed multiple times before */
1879 MEMP_STATS_DEC(err, MEMP_TCP_PCB);
1880 }
1881 }
1882 if (pcb != NULL) {
1883 /* adjust err stats: memp_malloc failed multiple times before */
1884 MEMP_STATS_DEC(err, MEMP_TCP_PCB);
1885 }
1886 }
1887 if (pcb != NULL) {
1888 /* adjust err stats: memp_malloc failed above */
1889 MEMP_STATS_DEC(err, MEMP_TCP_PCB);
1890 }
1891 }
1892 if (pcb != NULL) {
1893 /* zero out the whole pcb, so there is no need to initialize members to zero */
1894 memset(pcb, 0, sizeof(struct tcp_pcb));
1895 pcb->prio = prio;
1896 pcb->snd_buf = TCP_SND_BUF;
1897 /* Start with a window that does not need scaling. When window scaling is
1898 enabled and used, the window is enlarged when both sides agree on scaling. */
1899 pcb->rcv_wnd = pcb->rcv_ann_wnd = TCPWND_MIN16(TCP_WND);
1900 pcb->ttl = TCP_TTL;
1901 /* As initial send MSS, we use TCP_MSS but limit it to 536.
1902 The send MSS is updated when an MSS option is received. */
1903 pcb->mss = INITIAL_MSS;
1904 /* Set initial TCP's retransmission timeout to 3000 ms by default.
1905 This value could be configured in lwipopts */
1906 pcb->rto = LWIP_TCP_RTO_TIME / TCP_SLOW_INTERVAL;
1907 pcb->sv = LWIP_TCP_RTO_TIME / TCP_SLOW_INTERVAL;
1908 pcb->rtime = -1;
1909 pcb->cwnd = 1;
1910 pcb->tmr = tcp_ticks;
1911 pcb->last_timer = tcp_timer_ctr;
1912
1913 /* RFC 5681 recommends setting ssthresh arbitrarily high and gives an example
1914 of using the largest advertised receive window. We've seen complications with
1915 receiving TCPs that use window scaling and/or window auto-tuning where the
1916 initial advertised window is very small and then grows rapidly once the
1917 connection is established. To avoid these complications, we set ssthresh to the
1918 largest effective cwnd (amount of in-flight data) that the sender can have. */
1919 pcb->ssthresh = TCP_SND_BUF;
1920
1921#if LWIP_CALLBACK_API
1922 pcb->recv = tcp_recv_null;
1923#endif /* LWIP_CALLBACK_API */
1924
1925 /* Init KEEPALIVE timer */
1926 pcb->keep_idle = TCP_KEEPIDLE_DEFAULT;
1927
1928#if LWIP_TCP_KEEPALIVE
1929 pcb->keep_intvl = TCP_KEEPINTVL_DEFAULT;
1930 pcb->keep_cnt = TCP_KEEPCNT_DEFAULT;
1931#endif /* LWIP_TCP_KEEPALIVE */
1932 pcb_tci_init(pcb);
1933 }
1934 return pcb;
1935}
1936
1952struct tcp_pcb *
1953tcp_new(void)
1954{
1955 return tcp_alloc(TCP_PRIO_NORMAL);
1956}
1957
1970struct tcp_pcb *
1971tcp_new_ip_type(u8_t type)
1972{
1973 struct tcp_pcb *pcb;
1974 pcb = tcp_alloc(TCP_PRIO_NORMAL);
1975#if LWIP_IPV4 && LWIP_IPV6
1976 if (pcb != NULL) {
1977 IP_SET_TYPE_VAL(pcb->local_ip, type);
1978 IP_SET_TYPE_VAL(pcb->remote_ip, type);
1979 }
1980#else
1982#endif /* LWIP_IPV4 && LWIP_IPV6 */
1983 return pcb;
1984}
1985
1996void
1997tcp_arg(struct tcp_pcb *pcb, void *arg)
1998{
2000 /* This function is allowed to be called for both listen pcbs and
2001 connection pcbs. */
2002 if (pcb != NULL) {
2003 pcb->callback_arg = arg;
2004 }
2005}
2006#if LWIP_CALLBACK_API
2007
2019void
2020tcp_recv(struct tcp_pcb *pcb, tcp_recv_fn recv)
2021{
2023 if (pcb != NULL) {
2024 LWIP_ASSERT("invalid socket state for recv callback", pcb->state != LISTEN);
2025 pcb->recv = recv;
2026 }
2027}
2028
2039void
2040tcp_sent(struct tcp_pcb *pcb, tcp_sent_fn sent)
2041{
2043 if (pcb != NULL) {
2044 LWIP_ASSERT("invalid socket state for sent callback", pcb->state != LISTEN);
2045 pcb->sent = sent;
2046 }
2047}
2048
2065void
2066tcp_err(struct tcp_pcb *pcb, tcp_err_fn err)
2067{
2069 if (pcb != NULL) {
2070 LWIP_ASSERT("invalid socket state for err callback", pcb->state != LISTEN);
2071 pcb->errf = err;
2072 }
2073}
2074
2085void
2086tcp_accept(struct tcp_pcb *pcb, tcp_accept_fn accept)
2087{
2089 if ((pcb != NULL) && (pcb->state == LISTEN)) {
2090 struct tcp_pcb_listen *lpcb = (struct tcp_pcb_listen *)pcb;
2091 lpcb->accept = accept;
2092 }
2093}
2094#endif /* LWIP_CALLBACK_API */
2095
2096
2114void
2115tcp_poll(struct tcp_pcb *pcb, tcp_poll_fn poll, u8_t interval)
2116{
2118
2119 LWIP_ERROR("tcp_poll: invalid pcb", pcb != NULL, return);
2120 LWIP_ASSERT("invalid socket state for poll", pcb->state != LISTEN);
2121
2122#if LWIP_CALLBACK_API
2123 pcb->poll = poll;
2124#else /* LWIP_CALLBACK_API */
2126#endif /* LWIP_CALLBACK_API */
2127 pcb->pollinterval = interval;
2128}
2129
2136void
2137tcp_pcb_purge(struct tcp_pcb *pcb)
2138{
2139 LWIP_ERROR("tcp_pcb_purge: invalid pcb", pcb != NULL, return);
2140
2141 if (pcb->state != CLOSED &&
2142 pcb->state != TIME_WAIT &&
2143 pcb->state != LISTEN) {
2144
2145 LWIP_DEBUGF(TCP_DEBUG, ("tcp_pcb_purge\n"));
2146
2147 tcp_backlog_accepted(pcb);
2148
2149 if (pcb->refused_data != NULL) {
2150 LWIP_DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: data left on ->refused_data\n"));
2151 pbuf_free(pcb->refused_data);
2152 pcb->refused_data = NULL;
2153 }
2154 if (pcb->unsent != NULL) {
2155 LWIP_DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: not all data sent\n"));
2156 }
2157 if (pcb->unacked != NULL) {
2158 LWIP_DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: data left on ->unacked\n"));
2159 }
2160#if TCP_QUEUE_OOSEQ
2161 if (pcb->ooseq != NULL) {
2162 LWIP_DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: data left on ->ooseq\n"));
2163 tcp_free_ooseq(pcb);
2164 }
2165#endif /* TCP_QUEUE_OOSEQ */
2166
2167 /* Stop the retransmission timer as it will expect data on unacked
2168 queue if it fires */
2169 pcb->rtime = -1;
2170
2171 tcp_segs_free(pcb->unsent);
2172 tcp_segs_free(pcb->unacked);
2173 pcb->unacked = pcb->unsent = NULL;
2174#if TCP_OVERSIZE
2175 pcb->unsent_oversize = 0;
2176#endif /* TCP_OVERSIZE */
2177 }
2178}
2179
2186void
2187tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb)
2188{
2189 LWIP_ASSERT("tcp_pcb_remove: invalid pcb", pcb != NULL);
2190 LWIP_ASSERT("tcp_pcb_remove: invalid pcblist", pcblist != NULL);
2191
2192 TCP_RMV(pcblist, pcb);
2193
2194 tcp_pcb_purge(pcb);
2195
2196 /* if there is an outstanding delayed ACKs, send it */
2197 if ((pcb->state != TIME_WAIT) &&
2198 (pcb->state != LISTEN) &&
2199 (pcb->flags & TF_ACK_DELAY)) {
2200 tcp_ack_now(pcb);
2201 tcp_output(pcb);
2202 }
2203
2204 if (pcb->state != LISTEN) {
2205 LWIP_ASSERT("unsent segments leaking", pcb->unsent == NULL);
2206 LWIP_ASSERT("unacked segments leaking", pcb->unacked == NULL);
2207#if TCP_QUEUE_OOSEQ
2208 LWIP_ASSERT("ooseq segments leaking", pcb->ooseq == NULL);
2209#endif /* TCP_QUEUE_OOSEQ */
2210 }
2211
2212 pcb->state = CLOSED;
2213 /* reset the local port to prevent the pcb from being 'bound' */
2214 pcb->local_port = 0;
2215
2216 LWIP_ASSERT("tcp_pcb_remove: tcp_pcbs_sane()", tcp_pcbs_sane());
2217}
2218
2224u32_t
2225tcp_next_iss(struct tcp_pcb *pcb)
2226{
2227#ifdef LWIP_HOOK_TCP_ISN
2228 LWIP_ASSERT("tcp_next_iss: invalid pcb", pcb != NULL);
2229 return LWIP_HOOK_TCP_ISN(&pcb->local_ip, pcb->local_port, &pcb->remote_ip, pcb->remote_port);
2230#else /* LWIP_HOOK_TCP_ISN */
2231 static u32_t iss = 6510;
2232
2233 LWIP_ASSERT("tcp_next_iss: invalid pcb", pcb != NULL);
2234 LWIP_UNUSED_ARG(pcb);
2235
2236 iss += tcp_ticks; /* XXX */
2237 return iss;
2238#endif /* LWIP_HOOK_TCP_ISN */
2239}
2240
2241#if TCP_CALCULATE_EFF_SEND_MSS
2247u16_t
2248tcp_eff_send_mss_netif(u16_t sendmss, struct netif *outif, const ip_addr_t *dest)
2249{
2250 u16_t mss_s;
2251 u16_t mtu;
2252
2253 LWIP_UNUSED_ARG(dest); /* in case IPv6 is disabled */
2254
2255 LWIP_ASSERT("tcp_eff_send_mss_netif: invalid dst_ip", dest != NULL);
2256
2257#if LWIP_IPV6
2258#if LWIP_IPV4
2259 if (IP_IS_V6(dest))
2260#endif /* LWIP_IPV4 */
2261 {
2262 /* First look in destination cache, to see if there is a Path MTU. */
2263 mtu = nd6_get_destination_mtu(ip_2_ip6(dest), outif);
2264 }
2265#if LWIP_IPV4
2266 else
2267#endif /* LWIP_IPV4 */
2268#endif /* LWIP_IPV6 */
2269#if LWIP_IPV4
2270 {
2271 if (outif == NULL) {
2272 return sendmss;
2273 }
2274 mtu = outif->mtu;
2275 }
2276#endif /* LWIP_IPV4 */
2277
2278 if (mtu != 0) {
2279 u16_t offset;
2280#if LWIP_IPV6
2281#if LWIP_IPV4
2282 if (IP_IS_V6(dest))
2283#endif /* LWIP_IPV4 */
2284 {
2286 }
2287#if LWIP_IPV4
2288 else
2289#endif /* LWIP_IPV4 */
2290#endif /* LWIP_IPV6 */
2291#if LWIP_IPV4
2292 {
2294 }
2295#endif /* LWIP_IPV4 */
2296 mss_s = (mtu > offset) ? (u16_t)(mtu - offset) : 0;
2297 /* RFC 1122, chap 4.2.2.6:
2298 * Eff.snd.MSS = min(SendMSS+20, MMS_S) - TCPhdrsize - IPoptionsize
2299 * We correct for TCP options in tcp_write(), and don't support IP options.
2300 */
2301 sendmss = LWIP_MIN(sendmss, mss_s);
2302 }
2303 return sendmss;
2304}
2305#endif /* TCP_CALCULATE_EFF_SEND_MSS */
2306
2308static void
2309tcp_netif_ip_addr_changed_pcblist(const ip_addr_t *old_addr, struct tcp_pcb *pcb_list)
2310{
2311 struct tcp_pcb *pcb;
2312 pcb = pcb_list;
2313
2314 LWIP_ASSERT("tcp_netif_ip_addr_changed_pcblist: invalid old_addr", old_addr != NULL);
2315
2316 while (pcb != NULL) {
2317 /* PCB bound to current local interface address? */
2318 if (ip_addr_eq(&pcb->local_ip, old_addr)
2319#if LWIP_AUTOIP
2320 /* connections to link-local addresses must persist (RFC3927 ch. 1.9) */
2321 && (!IP_IS_V4_VAL(pcb->local_ip) || !ip4_addr_islinklocal(ip_2_ip4(&pcb->local_ip)))
2322#endif /* LWIP_AUTOIP */
2323 ) {
2324 /* this connection must be aborted */
2325 struct tcp_pcb *next = pcb->next;
2326 LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_set_ipaddr: aborting TCP pcb %p\n", (void *)pcb));
2327 tcp_abort(pcb);
2328 pcb = next;
2329 } else {
2330 pcb = pcb->next;
2331 }
2332 }
2333}
2334
2340void
2341tcp_netif_ip_addr_changed(const ip_addr_t *old_addr, const ip_addr_t *new_addr)
2342{
2343 struct tcp_pcb_listen *lpcb;
2344
2345 if (!ip_addr_isany(old_addr)) {
2346 tcp_netif_ip_addr_changed_pcblist(old_addr, tcp_active_pcbs);
2347 tcp_netif_ip_addr_changed_pcblist(old_addr, tcp_bound_pcbs);
2348
2349 if (!ip_addr_isany(new_addr)) {
2350 /* PCB bound to current local interface address? */
2351 for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
2352 /* PCB bound to current local interface address? */
2353 if (ip_addr_eq(&lpcb->local_ip, old_addr)) {
2354 /* The PCB is listening to the old ipaddr and
2355 * is set to listen to the new one instead */
2356 ip_addr_copy(lpcb->local_ip, *new_addr);
2357 }
2358 }
2359 }
2360 }
2361}
2362
2363const char *
2364tcp_debug_state_str(enum tcp_state s)
2365{
2366 return tcp_state_str[s];
2367}
2368
2369err_t
2370tcp_tcp_get_tcp_addrinfo(struct tcp_pcb *pcb, int local, ip_addr_t *addr, u16_t *port)
2371{
2372 if (pcb) {
2373 if (local) {
2374 if (addr) {
2375 *addr = pcb->local_ip;
2376 }
2377 if (port) {
2378 *port = pcb->local_port;
2379 }
2380 } else {
2381 if (addr) {
2382 *addr = pcb->remote_ip;
2383 }
2384 if (port) {
2385 *port = pcb->remote_port;
2386 }
2387 }
2388 return ERR_OK;
2389 }
2390 return ERR_VAL;
2391}
2392
2393#if TCP_QUEUE_OOSEQ
2394/* Free all ooseq pbufs (and possibly reset SACK state) */
2395void
2396tcp_free_ooseq(struct tcp_pcb *pcb)
2397{
2398 if (pcb->ooseq) {
2399 tcp_segs_free(pcb->ooseq);
2400 pcb->ooseq = NULL;
2401#if LWIP_TCP_SACK_OUT
2402 memset(pcb->rcv_sacks, 0, sizeof(pcb->rcv_sacks));
2403#endif /* LWIP_TCP_SACK_OUT */
2404 }
2405}
2406#endif /* TCP_QUEUE_OOSEQ */
2407
2408#if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG
2414void
2415tcp_debug_print(struct tcp_hdr *tcphdr)
2416{
2417 LWIP_DEBUGF(TCP_DEBUG, ("TCP header:\n"));
2418 LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
2419 LWIP_DEBUGF(TCP_DEBUG, ("| %5"U16_F" | %5"U16_F" | (src port, dest port)\n",
2421 LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
2422 LWIP_DEBUGF(TCP_DEBUG, ("| %010"U32_F" | (seq no)\n",
2423 lwip_ntohl(tcphdr->seqno)));
2424 LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
2425 LWIP_DEBUGF(TCP_DEBUG, ("| %010"U32_F" | (ack no)\n",
2426 lwip_ntohl(tcphdr->ackno)));
2427 LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
2428 LWIP_DEBUGF(TCP_DEBUG, ("| %2"U16_F" | |%"U16_F"%"U16_F"%"U16_F"%"U16_F"%"U16_F"%"U16_F"| %5"U16_F" | (hdrlen, flags (",
2430 (u16_t)(TCPH_FLAGS(tcphdr) >> 5 & 1),
2431 (u16_t)(TCPH_FLAGS(tcphdr) >> 4 & 1),
2432 (u16_t)(TCPH_FLAGS(tcphdr) >> 3 & 1),
2433 (u16_t)(TCPH_FLAGS(tcphdr) >> 2 & 1),
2434 (u16_t)(TCPH_FLAGS(tcphdr) >> 1 & 1),
2435 (u16_t)(TCPH_FLAGS(tcphdr) & 1),
2436 lwip_ntohs(tcphdr->wnd)));
2437 tcp_debug_print_flags(TCPH_FLAGS(tcphdr));
2438 LWIP_DEBUGF(TCP_DEBUG, ("), win)\n"));
2439 LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
2440 LWIP_DEBUGF(TCP_DEBUG, ("| 0x%04"X16_F" | %5"U16_F" | (chksum, urgp)\n",
2441 lwip_ntohs(tcphdr->chksum), lwip_ntohs(tcphdr->urgp)));
2442 LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
2443}
2444
2450void
2451tcp_debug_print_state(enum tcp_state s)
2452{
2453 LWIP_DEBUGF(TCP_DEBUG, ("State: %s\n", tcp_state_str[s]));
2454}
2455
2461void
2462tcp_debug_print_flags(u8_t flags)
2463{
2464 if (flags & TCP_FIN) {
2465 LWIP_DEBUGF(TCP_DEBUG, ("FIN "));
2466 }
2467 if (flags & TCP_SYN) {
2468 LWIP_DEBUGF(TCP_DEBUG, ("SYN "));
2469 }
2470 if (flags & TCP_RST) {
2471 LWIP_DEBUGF(TCP_DEBUG, ("RST "));
2472 }
2473 if (flags & TCP_PSH) {
2474 LWIP_DEBUGF(TCP_DEBUG, ("PSH "));
2475 }
2476 if (flags & TCP_ACK) {
2477 LWIP_DEBUGF(TCP_DEBUG, ("ACK "));
2478 }
2479 if (flags & TCP_URG) {
2480 LWIP_DEBUGF(TCP_DEBUG, ("URG "));
2481 }
2482 if (flags & TCP_ECE) {
2483 LWIP_DEBUGF(TCP_DEBUG, ("ECE "));
2484 }
2485 if (flags & TCP_CWR) {
2486 LWIP_DEBUGF(TCP_DEBUG, ("CWR "));
2487 }
2488 LWIP_DEBUGF(TCP_DEBUG, ("\n"));
2489}
2490
2494void
2495tcp_debug_print_pcbs(void)
2496{
2497 struct tcp_pcb *pcb;
2498 struct tcp_pcb_listen *pcbl;
2499
2500 LWIP_DEBUGF(TCP_DEBUG, ("Active PCB states:\n"));
2501 for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
2502 LWIP_DEBUGF(TCP_DEBUG, ("Local port %"U16_F", foreign port %"U16_F" snd_nxt %"U32_F" rcv_nxt %"U32_F" ",
2503 pcb->local_port, pcb->remote_port,
2504 pcb->snd_nxt, pcb->rcv_nxt));
2505 tcp_debug_print_state(pcb->state);
2506 }
2507
2508 LWIP_DEBUGF(TCP_DEBUG, ("Listen PCB states:\n"));
2509 for (pcbl = tcp_listen_pcbs.listen_pcbs; pcbl != NULL; pcbl = pcbl->next) {
2510 LWIP_DEBUGF(TCP_DEBUG, ("Local port %"U16_F" ", pcbl->local_port));
2511 tcp_debug_print_state(pcbl->state);
2512 }
2513
2514 LWIP_DEBUGF(TCP_DEBUG, ("TIME-WAIT PCB states:\n"));
2515 for (pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
2516 LWIP_DEBUGF(TCP_DEBUG, ("Local port %"U16_F", foreign port %"U16_F" snd_nxt %"U32_F" rcv_nxt %"U32_F" ",
2517 pcb->local_port, pcb->remote_port,
2518 pcb->snd_nxt, pcb->rcv_nxt));
2519 tcp_debug_print_state(pcb->state);
2520 }
2521}
2522
2526s16_t
2527tcp_pcbs_sane(void)
2528{
2529 struct tcp_pcb *pcb;
2530 for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
2531 LWIP_ASSERT("tcp_pcbs_sane: active pcb->state != CLOSED", pcb->state != CLOSED);
2532 LWIP_ASSERT("tcp_pcbs_sane: active pcb->state != LISTEN", pcb->state != LISTEN);
2533 LWIP_ASSERT("tcp_pcbs_sane: active pcb->state != TIME-WAIT", pcb->state != TIME_WAIT);
2534 }
2535 for (pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
2536 LWIP_ASSERT("tcp_pcbs_sane: tw pcb->state == TIME-WAIT", pcb->state == TIME_WAIT);
2537 }
2538 return 1;
2539}
2540#endif /* TCP_DEBUG */
2541
2542#if LWIP_TCP_PCB_NUM_EXT_ARGS
2560static u8_t tcp_ext_arg_id;
2561
2580u8_t
2581tcp_ext_arg_alloc_id(void)
2582{
2583 u8_t result = tcp_ext_arg_id;
2584 tcp_ext_arg_id++;
2585
2587
2588#if LWIP_TCP_PCB_NUM_EXT_ARGS >= 255
2589#error LWIP_TCP_PCB_NUM_EXT_ARGS
2590#endif
2591 LWIP_ASSERT("Increase LWIP_TCP_PCB_NUM_EXT_ARGS in lwipopts.h", result < LWIP_TCP_PCB_NUM_EXT_ARGS);
2592 return result;
2593}
2594
2603void
2604tcp_ext_arg_set_callbacks(struct tcp_pcb *pcb, u8_t id, const struct tcp_ext_arg_callbacks * const callbacks)
2605{
2606 LWIP_ASSERT("pcb != NULL", pcb != NULL);
2607 LWIP_ASSERT("id < LWIP_TCP_PCB_NUM_EXT_ARGS", id < LWIP_TCP_PCB_NUM_EXT_ARGS);
2608 LWIP_ASSERT("callbacks != NULL", callbacks != NULL);
2609
2611
2612 pcb->ext_args[id].callbacks = callbacks;
2613}
2614
2623void tcp_ext_arg_set(struct tcp_pcb *pcb, u8_t id, void *arg)
2624{
2625 LWIP_ASSERT("pcb != NULL", pcb != NULL);
2626 LWIP_ASSERT("id < LWIP_TCP_PCB_NUM_EXT_ARGS", id < LWIP_TCP_PCB_NUM_EXT_ARGS);
2627
2629
2630 pcb->ext_args[id].data = arg;
2631}
2632
2641void *tcp_ext_arg_get(const struct tcp_pcb *pcb, u8_t id)
2642{
2643 LWIP_ASSERT("pcb != NULL", pcb != NULL);
2644 LWIP_ASSERT("id < LWIP_TCP_PCB_NUM_EXT_ARGS", id < LWIP_TCP_PCB_NUM_EXT_ARGS);
2645
2647
2648 return pcb->ext_args[id].data;
2649}
2650
2654static void
2655tcp_ext_arg_invoke_callbacks_destroyed(struct tcp_pcb_ext_args *ext_args)
2656{
2657 int i;
2658 LWIP_ASSERT("ext_args != NULL", ext_args != NULL);
2659
2660 for (i = 0; i < LWIP_TCP_PCB_NUM_EXT_ARGS; i++) {
2661 if (ext_args[i].callbacks != NULL) {
2662 if (ext_args[i].callbacks->destroy != NULL) {
2663 ext_args[i].callbacks->destroy((u8_t)i, ext_args[i].data);
2664 }
2665 }
2666 }
2667}
2668
2675err_t
2676tcp_ext_arg_invoke_callbacks_passive_open(struct tcp_pcb_listen *lpcb, struct tcp_pcb *cpcb)
2677{
2678 int i;
2679 LWIP_ASSERT("lpcb != NULL", lpcb != NULL);
2680 LWIP_ASSERT("cpcb != NULL", cpcb != NULL);
2681
2682 for (i = 0; i < LWIP_TCP_PCB_NUM_EXT_ARGS; i++) {
2683 if (lpcb->ext_args[i].callbacks != NULL) {
2684 if (lpcb->ext_args[i].callbacks->passive_open != NULL) {
2685 err_t err = lpcb->ext_args[i].callbacks->passive_open((u8_t)i, lpcb, cpcb);
2686 if (err != ERR_OK) {
2687 return err;
2688 }
2689 }
2690 }
2691 }
2692 return ERR_OK;
2693}
2694#endif /* LWIP_TCP_PCB_NUM_EXT_ARGS */
2695
2696#endif /* LWIP_TCP */
@ sent
Definition: SystemMenu.c:27
static int state
Definition: maze.c:121
STREAM tcp_recv(STREAM s, uint32 length)
Definition: tcp.c:344
RD_BOOL tcp_connect(char *server)
Definition: tcp.c:717
STREAM tcp_init(uint32 maxlen)
Definition: tcp.c:82
static int next_slot(PBTRFS_INFO BtrFsInfo, struct btrfs_disk_key *key, struct btrfs_path *path)
Definition: btrfs.c:384
Definition: list.h:37
#define LWIP_ARRAYSIZE(x)
Definition: def.h:69
#define lwip_ntohl(x)
Definition: def.h:89
#define LWIP_MIN(x, y)
Definition: def.h:66
#define lwip_ntohs(x)
Definition: def.h:87
#define NULL
Definition: types.h:112
static UINT mib2[]
Definition: main.c:83
USHORT port
Definition: uri.c:228
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
#define X16_F
Definition: cc.h:21
#define S32_F
Definition: cc.h:23
#define U16_F
Definition: cc.h:19
#define S16_F
Definition: cc.h:20
#define U32_F
Definition: cc.h:22
static const char *const tcp_state_str[]
Definition: tcp.c:6
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:158
#define LWIP_ERROR(message, expression, handler)
Definition: debug.h:130
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:116
#define SOF_KEEPALIVE
Definition: ip.h:111
#define ip_get_option(pcb, opt)
Definition: ip.h:228
#define SOF_REUSEADDR
Definition: ip.h:110
#define pcb_tci_init(pcb)
Definition: ip.h:104
#define ERR_MEM
Definition: fontsub.h:52
#define local
Definition: zutil.h:30
int connected
Definition: main.c:61
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLdouble s
Definition: gl.h:2039
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble n
Definition: glext.h:7729
GLboolean reset
Definition: glext.h:5666
GLuint res
Definition: glext.h:9613
GLintptr offset
Definition: glext.h:5920
GLbitfield flags
Definition: glext.h:7161
GLenum const GLvoid * addr
Definition: glext.h:9621
GLuint64EXT * result
Definition: glext.h:11304
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
GLuint id
Definition: glext.h:5910
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
uint32_t u32_t
Definition: arch.h:129
uint8_t u8_t
Definition: arch.h:125
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:373
uint16_t u16_t
Definition: arch.h:127
int16_t s16_t
Definition: arch.h:128
#define LWIP_DBG_STATE
Definition: debug.h:85
s8_t err_t
Definition: err.h:96
@ ERR_BUF
Definition: err.h:59
@ ERR_INPROGRESS
Definition: err.h:65
@ ERR_USE
Definition: err.h:71
@ ERR_ISCONN
Definition: err.h:75
@ ERR_RTE
Definition: err.h:63
@ ERR_OK
Definition: err.h:55
@ ERR_CLSD
Definition: err.h:86
@ ERR_VAL
Definition: err.h:67
@ ERR_CONN
Definition: err.h:77
@ ERR_ARG
Definition: err.h:88
@ ERR_ALREADY
Definition: err.h:73
@ ERR_ABRT
Definition: err.h:82
#define LWIP_AUTOIP
Definition: opt.h:997
#define NETIF_DEBUG
Definition: opt.h:3336
#define TCP_RST_DEBUG
Definition: opt.h:3491
#define TCP_CWND_DEBUG
Definition: opt.h:3470
#define TCP_RTO_DEBUG
Definition: opt.h:3463
#define TCP_INPUT_DEBUG
Definition: opt.h:3448
#define LWIP_IPV4
Definition: opt.h:734
#define LWIP_IPV6
Definition: opt.h:2440
#define LWIP_ASSERT_CORE_LOCKED()
Definition: opt.h:227
#define SMEMCPY(dst, src, len)
Definition: opt.h:145
#define LWIP_TCP_PCB_NUM_EXT_ARGS
Definition: opt.h:1530
#define TCP_WND_UPDATE_THRESHOLD
Definition: opt.h:1489
#define LWIP_WND_SCALE
Definition: opt.h:1520
#define TCP_QUEUE_OOSEQ
Definition: opt.h:1303
#define TCP_TTL
Definition: opt.h:1270
#define LWIP_TCP_RTO_TIME
Definition: opt.h:1357
struct netif * netif_get_by_index(u8_t idx)
Definition: netif.c:1730
void pbuf_ref(struct pbuf *p)
Definition: pbuf.c:831
void pbuf_cat(struct pbuf *h, struct pbuf *t)
Definition: pbuf.c:855
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:727
#define TCP_MAXRTX
Definition: lwipopts.h:52
#define TCP_DEBUG
Definition: lwipopts.h:77
#define TCP_SYNMAXRTX
Definition: lwipopts.h:54
#define TCP_WND
Definition: lwipopts.h:48
#define TCP_SND_BUF
Definition: lwipopts.h:50
#define ip_2_ip6(ipaddr)
Definition: ip_addr.h:356
#define IP_IS_V6_VAL(ipaddr)
Definition: ip_addr.h:348
#define ip_addr_isany(ipaddr)
Definition: ip_addr.h:377
#define ip_addr_set(dest, src)
Definition: ip_addr.h:363
#define ip_addr_eq(addr1, addr2)
Definition: ip_addr.h:374
#define ip_addr_copy(dest, src)
Definition: ip_addr.h:360
ip6_addr_t ip_addr_t
Definition: ip_addr.h:344
#define IP_IS_V6(ipaddr)
Definition: ip_addr.h:350
#define IP_GET_TYPE(ipaddr)
Definition: ip_addr.h:354
#define IP_SET_TYPE_VAL(ipaddr, iptype)
Definition: ip_addr.h:352
#define IP_IS_V4_VAL(ipaddr)
Definition: ip_addr.h:347
#define ip_addr_debug_print_val(debug, ipaddr)
Definition: ip_addr.h:384
#define TCP_PSH
Definition: tcp.h:75
#define TCP_ACK
Definition: tcp.h:76
#define TCP_HLEN
Definition: tcp.h:47
#define TCPH_HDRLEN(phdr)
Definition: tcp.h:85
#define TCP_RST
Definition: tcp.h:74
#define TCP_SYN
Definition: tcp.h:73
#define TCP_CWR
Definition: tcp.h:79
#define TCP_FIN
Definition: tcp.h:72
#define TCP_URG
Definition: tcp.h:77
#define TCPH_FLAGS(phdr)
Definition: tcp.h:87
#define TCP_ECE
Definition: tcp.h:78
void * memp_malloc(memp_t type)
Definition: memp.c:337
void memp_free(memp_t type, void *mem)
Definition: memp.c:420
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static char * dest
Definition: rtl.c:135
#define NETIF_NO_INDEX
Definition: netif.h:579
#define netif_get_index(netif)
Definition: netif.h:578
#define PBUF_FLAG_TCP_FIN
Definition: pbuf.h:183
#define IP_HLEN
Definition: ip4.h:64
#define IP6_HLEN
Definition: ip6.h:64
static unsigned __int64 next
Definition: rand_nt.c:6
#define err(...)
#define memset(x, y, z)
Definition: compat.h:39
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23
#define MIB2_STATS_INC(x)
Definition: stats.h:467
#define MEMP_STATS_DEC(x, i)
Definition: stats.h:407
struct define * next
Definition: compiler.c:65
Definition: netif.h:269
u16_t mtu
Definition: netif.h:344
Definition: pbuf.h:186
Definition: tcp.h:56
Definition: tcpdef.h:22
__u16 dest
Definition: tcpdef.h:24
void tcp_close(struct sock *sk, long timeout)
struct sock * tcp_accept(struct sock *sk, int flags, int *err)
void tcp_shutdown(struct sock *sk, int how)
void tcp_send_fin(struct sock *sk)
unsigned int tcp_poll(struct file *file, struct socket *sock, struct poll_table_struct *wait)
int ret
void * arg
Definition: msvc.h:10
#define poll
Definition: wintirpc.h:59
static int callbacks
Definition: xmllint.c:838