1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Lwip addons (#2260)

* Add multicast TTL to UDP and rework UdpContext

* Add limit for TCP TIME_WAIT pcbs

* Add liblwip_gcc.a

* Make the changes be backward compatible with the current xcc version
This commit is contained in:
Me No Dev 2016-07-11 16:07:45 +03:00 committed by Ivan Grokhotkov
parent 86067333f5
commit 07f4d4c241
10 changed files with 297 additions and 229 deletions

View File

@ -1680,7 +1680,7 @@ coredev.build.lwip_flags=
coredev.menu.LwIPVariant.Espressif=Espressif (xcc)
coredev.menu.LwIPVariant.Espressif.build.lwip_lib=-llwip
coredev.menu.LwIPVariant.Espressif.build.lwip_flags=
coredev.menu.LwIPVariant.Espressif.build.lwip_flags=-DLWIP_MAYBE_XCC
coredev.menu.LwIPVariant.Prebuilt=Prebuilt Source (gcc)
coredev.menu.LwIPVariant.Prebuilt.build.lwip_lib=-llwip_gcc
coredev.menu.LwIPVariant.Prebuilt.build.lwip_flags=-DLWIP_OPEN_SRC

View File

@ -44,11 +44,11 @@ public:
, _tx_buf_head(0)
, _tx_buf_cur(0)
, _tx_buf_offset(0)
, _multicast_ttl(1)
, _dest_port(0)
{
_pcb = udp_new();
_dest_addr.addr = 0;
#ifdef LWIP_MAYBE_XCC
_mcast_ttl = 1;
#endif
}
~UdpContext()
@ -87,8 +87,8 @@ public:
bool connect(ip_addr_t addr, uint16_t port)
{
_dest_addr = addr;
_dest_port = port;
ip_addr_copy(_pcb->remote_ip, addr);
_pcb->remote_port = port;
return true;
}
@ -106,17 +106,16 @@ public:
void setMulticastInterface(ip_addr_t addr)
{
// newer versions of lwip have a macro to set the multicast ip
// udp_set_multicast_netif_addr(_pcb, addr);
_pcb->multicast_ip = addr;
udp_set_multicast_netif_addr(_pcb, addr);
}
void setMulticastTTL(int ttl)
{
// newer versions of lwip have an additional field (mcast_ttl) for this purpose
// and a macro to set it instead of direct field access
// udp_set_multicast_ttl(_pcb, ttl);
_multicast_ttl = ttl;
#ifdef LWIP_MAYBE_XCC
_mcast_ttl = ttl;
#else
udp_set_multicast_ttl(_pcb, ttl);
#endif
}
// warning: handler is called from tcp stack context
@ -275,20 +274,22 @@ public:
if (!addr) {
addr = &_dest_addr;
port = _dest_port;
addr = &_pcb->remote_ip;
port = _pcb->remote_port;
}
#ifdef LWIP_MAYBE_XCC
uint16_t old_ttl = _pcb->ttl;
if (ip_addr_ismulticast(addr)) {
_pcb->ttl = _multicast_ttl;
_pcb->ttl = _mcast_ttl;
}
#endif
err_t err = udp_sendto(_pcb, tx_copy, addr, port);
if (err != ERR_OK) {
DEBUGV(":ust rc=%d\r\n", err);
}
#ifdef LWIP_MAYBE_XCC
_pcb->ttl = old_ttl;
#endif
pbuf_free(tx_copy);
return err == ERR_OK;
}
@ -365,10 +366,10 @@ private:
pbuf* _tx_buf_head;
pbuf* _tx_buf_cur;
size_t _tx_buf_offset;
uint16_t _multicast_ttl;
uint16_t _dest_port;
ip_addr_t _dest_addr;
rxhandler_t _on_rx;
#ifdef LWIP_MAYBE_XCC
uint16_t _mcast_ttl;
#endif
};

Binary file not shown.

View File

@ -1,8 +1,8 @@
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
@ -11,21 +11,21 @@
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
@ -284,7 +284,7 @@ struct tcp_seg {
u16_t oversize_left; /* Extra bytes available at the end of the last
pbuf in unsent (used for asserting vs.
tcp_pcb.unsent_oversized only) */
#endif /* TCP_OVERSIZE_DBGCHECK */
#endif /* TCP_OVERSIZE_DBGCHECK */
#if TCP_CHECKSUM_ON_COPY
u16_t chksum;
u8_t chksum_swapped;
@ -313,7 +313,7 @@ extern u32_t tcp_ticks;
/* The TCP PCB lists. */
union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */
struct tcp_pcb_listen *listen_pcbs;
struct tcp_pcb_listen *listen_pcbs;
struct tcp_pcb *pcbs;
};
extern struct tcp_pcb *tcp_bound_pcbs;
@ -325,7 +325,7 @@ extern struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in TIME-WAIT. *
extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */
/* Axioms about the above lists:
/* Axioms about the above lists:
1) Every TCP PCB that is not CLOSED is in one of the lists.
2) A PCB is only in one of the lists.
3) All PCBs in the tcp_listen_pcbs list is in LISTEN state.
@ -396,6 +396,26 @@ extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */
#endif /* LWIP_DEBUG */
#define TCP_TW_LIMIT(l) \
do { \
u32_t tcp_tmp_pcbs_count = 0; \
tcp_tmp_pcb = tcp_tw_pcbs; \
while(tcp_tmp_pcb != NULL) { \
if(++tcp_tmp_pcbs_count == (l)) { \
struct tcp_pcb *_tcp_tmp_pcb = tcp_tmp_pcb->next; \
tcp_tmp_pcb->next = NULL; \
tcp_tmp_pcb = _tcp_tmp_pcb; \
while(tcp_tmp_pcb != NULL) { \
_tcp_tmp_pcb = tcp_tmp_pcb; \
tcp_pcb_purge(tcp_tmp_pcb); \
tcp_tmp_pcb = tcp_tmp_pcb->next; \
memp_free(MEMP_TCP_PCB, _tcp_tmp_pcb); \
} \
break; \
} \
tcp_tmp_pcb = tcp_tmp_pcb->next; \
} \
} while(0)
/* Internal functions: */
struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;

View File

@ -1,8 +1,8 @@
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
@ -11,21 +11,21 @@
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
@ -103,6 +103,10 @@ struct udp_pcb {
#if LWIP_IGMP
/** outgoing network interface for multicast packets */
ip_addr_t multicast_ip;
#ifndef LWIP_MAYBE_XCC
/** TTL for outgoing multicast packets */
u8_t mcast_ttl;
#endif /* LWIP_MAYBE_XCC */
#endif /* LWIP_IGMP */
#if LWIP_UDPLITE
@ -113,7 +117,7 @@ struct udp_pcb {
/** receive callback function */
udp_recv_fn recv;
/** user-supplied argument for the recv callback */
void *recv_arg;
void *recv_arg;
};
/* udp_pcbs export for exernal reference (e.g. SNMP agent) */
extern struct udp_pcb *udp_pcbs;
@ -156,6 +160,15 @@ void udp_input (struct pbuf *p, struct netif *inp)ICACHE_FLASH_
#define udp_init() /* Compatibility define, not init needed. */
#if LWIP_IGMP
#define udp_set_multicast_netif_addr(pcb, ipaddr) ip_addr_copy((pcb)->multicast_ip, (ipaddr))
#define udp_get_multicast_netif_addr(pcb) ((pcb)->multicast_ip)
#ifndef LWIP_MAYBE_XCC
#define udp_set_multicast_ttl(pcb, value) do { (pcb)->mcast_ttl = value; } while(0)
#define udp_get_multicast_ttl(pcb) ((pcb)->mcast_ttl)
#endif /* LWIP_MAYBE_XCC */
#endif /* LWIP_IGMP */
#if UDP_DEBUG
void udp_debug_print(struct udp_hdr *udphdr)ICACHE_FLASH_ATTR;
#else

View File

@ -6,9 +6,9 @@
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
@ -17,21 +17,21 @@
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
@ -56,7 +56,7 @@
#define SYS_LIGHTWEIGHT_PROT 0
#endif
/**
/**
* NO_SYS==1: Provides VERY minimal functionality. Otherwise,
* use lwIP facilities.
*/
@ -179,8 +179,8 @@
/**
* MEMP_USE_CUSTOM_POOLS==1: whether to include a user file lwippools.h
* that defines additional pools beyond the "standard" ones required
* by lwIP. If you set this to 1, you must have lwippools.h in your
* inlude path somewhere.
* by lwIP. If you set this to 1, you must have lwippools.h in your
* inlude path somewhere.
*/
#ifndef MEMP_USE_CUSTOM_POOLS
#define MEMP_USE_CUSTOM_POOLS 0
@ -255,6 +255,14 @@
#define MEMP_NUM_TCP_PCB_LISTEN 2
#endif
/**
* MEMP_NUM_TCP_PCB_TIME_WAIT: the number of TCP pcbs in TIME_WAIT state.
* (requires the LWIP_TCP option, 0 = disabled)
*/
#ifndef MEMP_NUM_TCP_PCB_TIME_WAIT
#define MEMP_NUM_TCP_PCB_TIME_WAIT 5
#endif
/**
* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP segments.
* (requires the LWIP_TCP option)
@ -328,7 +336,7 @@
/**
* MEMP_NUM_TCPIP_MSG_API: the number of struct tcpip_msg, which are used
* for callback/timeout API communication.
* for callback/timeout API communication.
* (only needed if you use tcpip.c)
*/
#ifndef MEMP_NUM_TCPIP_MSG_API
@ -337,7 +345,7 @@
/**
* MEMP_NUM_TCPIP_MSG_INPKT: the number of struct tcpip_msg, which are used
* for incoming packets.
* for incoming packets.
* (only needed if you use tcpip.c)
*/
#ifndef MEMP_NUM_TCPIP_MSG_INPKT
@ -402,7 +410,7 @@
#endif
/**
* PBUF_POOL_SIZE: the number of buffers in the pbuf pool.
* PBUF_POOL_SIZE: the number of buffers in the pbuf pool.
*/
#ifndef PBUF_POOL_SIZE
#define PBUF_POOL_SIZE 10
@ -714,7 +722,7 @@
/**
* SNMP_CONCURRENT_REQUESTS: Number of concurrent requests the module will
* allow. At least one request buffer is required.
* allow. At least one request buffer is required.
*/
#ifndef SNMP_CONCURRENT_REQUESTS
#define SNMP_CONCURRENT_REQUESTS 0
@ -729,7 +737,7 @@
#endif
/**
* SNMP_PRIVATE_MIB:
* SNMP_PRIVATE_MIB:
*/
#ifndef SNMP_PRIVATE_MIB
#define SNMP_PRIVATE_MIB 0
@ -775,7 +783,7 @@
----------------------------------
*/
/**
* LWIP_IGMP==1: Turn on IGMP module.
* LWIP_IGMP==1: Turn on IGMP module.
*/
#ifndef LWIP_IGMP
#define LWIP_IGMP 1
@ -903,12 +911,12 @@
#endif
/**
* TCP_WND: The size of a TCP window. This must be at least
* TCP_WND: The size of a TCP window. This must be at least
* (2 * TCP_MSS) for things to work well
*/
#ifndef TCP_WND
#define TCP_WND (*(volatile uint32*)0x600011F0)
#endif
#endif
/**
* TCP_MAXRTX: Maximum number of retransmissions of data segments.
@ -973,7 +981,7 @@
/**
* TCP_SND_BUF: TCP sender buffer space (bytes).
* TCP_SND_BUF: TCP sender buffer space (bytes).
*/
#ifndef TCP_SND_BUF
#define TCP_SND_BUF 2 * TCP_MSS
@ -1064,7 +1072,7 @@
#ifndef LWIP_EVENT_API
#define LWIP_EVENT_API 0
#define LWIP_CALLBACK_API 1
#else
#else
#define LWIP_EVENT_API 1
#define LWIP_CALLBACK_API 0
#endif
@ -1762,28 +1770,28 @@
#ifndef CHECKSUM_GEN_IP
#define CHECKSUM_GEN_IP 1
#endif
/**
* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.
*/
#ifndef CHECKSUM_GEN_UDP
#define CHECKSUM_GEN_UDP 1
#endif
/**
* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.
*/
#ifndef CHECKSUM_GEN_TCP
#define CHECKSUM_GEN_TCP 1
#endif
/**
* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.
*/
#ifndef CHECKSUM_CHECK_IP
#define CHECKSUM_CHECK_IP 1
#endif
/**
* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.
*/

View File

@ -28,5 +28,8 @@ all: $(LWIP_LIB)
install: all
cp -f $(LWIP_LIB) $(SDK_PATH)/lib/$(LWIP_LIB)
release: all
cp -f $(LWIP_LIB) $(SDK_PATH)/lib/liblwip_gcc.a
clean:
@rm -rf $(BUILD_PATH) $(LWIP_LIB)

View File

@ -10,9 +10,9 @@
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
@ -21,21 +21,21 @@
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
@ -61,17 +61,17 @@ static const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__;
#if TCP_DEBUG
const char tcp_state_str_rodata[][12] ICACHE_RODATA_ATTR = {
"CLOSED",
"LISTEN",
"SYN_SENT",
"SYN_RCVD",
"ESTABLISHED",
"FIN_WAIT_1",
"FIN_WAIT_2",
"CLOSE_WAIT",
"CLOSING",
"LAST_ACK",
"TIME_WAIT"
"CLOSED",
"LISTEN",
"SYN_SENT",
"SYN_RCVD",
"ESTABLISHED",
"FIN_WAIT_1",
"FIN_WAIT_2",
"CLOSE_WAIT",
"CLOSING",
"LAST_ACK",
"TIME_WAIT"
};
char tcp_state_str[12];
@ -105,7 +105,7 @@ struct tcp_pcb ** const tcp_pcb_lists[] ICACHE_RODATA_ATTR = {&tcp_listen_pcbs.p
/** Only used for temporary storage. */
struct tcp_pcb *tcp_tmp_pcb;
/** Timer counter to handle calling slow-timer from tcp_tmr() */
/** Timer counter to handle calling slow-timer from tcp_tmr() */
static u8_t tcp_timer;
static u16_t tcp_new_port(void);//<2F><><EFBFBD><EFBFBD>µ<EFBFBD>tcp<63><70><EFBFBD>ض˿<D8B6>
@ -166,7 +166,9 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data)
TCP_RMV(&tcp_active_pcbs, pcb);
pcb->state = TIME_WAIT;
TCP_REG(&tcp_tw_pcbs, pcb);
#if MEMP_NUM_TCP_PCB_TIME_WAIT
TCP_TW_LIMIT(MEMP_NUM_TCP_PCB_TIME_WAIT);
#endif
return ERR_OK;
}
}
@ -177,24 +179,24 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data)
* however, it is in this state once allocated and as yet unused
* and the user needs some way to free it should the need arise.
* Calling tcp_close() with a pcb that has already been closed, (i.e. twice)
* or for a pcb that has been used and then entered the CLOSED state
* or for a pcb that has been used and then entered the CLOSED state
* is erroneous, but this should never happen as the pcb has in those cases
* been freed, and so any remaining handles are bogus. */
/*<2A><>CLOSED״̬<D7B4>¹ر<C2B9>һ<EFBFBD><D2BB>pcb<63>ƺ<EFBFBD><C6BA>Ǵ<EFBFBD><C7B4><EFBFBD>ģ<EFBFBD>
*<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD><EFBFBD>һ<EFBFBD>û<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>,<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>ҪһЩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD>
*<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBF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BD><D0B1><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD>Ӧ<EFBFBD><D3A6>pcb
tcp_pcb_remove(&tcp_listen_pcbs.pcbs, pcb);//<2F>Ӽ<EFBFBD><D3BC><EFBFBD><EFBFBD>PCB<43>б<EFBFBD><D0B1><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD>Ӧ<EFBFBD><D3A6>pcb
memp_free(MEMP_TCP_PCB_LISTEN, pcb);//<2F><>MEMP_TCP_PCB_LISTEN<45>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷŵ<CDB7>pcb<63><62>Ԫֵ ,<2C>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
pcb = NULL;
break;
@ -261,14 +263,14 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data)
* @return ERR_OK if connection has been closed
* another err_t if closing failed and pcb is not freed
*/
/*
*ͨ<EFBFBD><EFBFBD>PCB<EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>pcbӦ<EFBFBD>ñ<EFBFBD><EFBFBD>ͷŵģ<EFBFBD>Ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԶҲ<EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*<EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳû<EFBFBD>б<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>pcbӦ<EFBFBD>ñ<EFBFBD><EFBFBD>ͷŵ<EFBFBD>
*<EFBFBD><EFBFBD><EFBFBD>һ<EF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FBFBD><EFBFBD>Ҳû<EFBFBD>б<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>pcbӦ<EFBFBD>ñ<EFBFBD><EFBFBD>ͷŵ<EFBFBD>
*<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>SYN<EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ջ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD>е<EFBFBD>״̬)
*<EFBFBD><EFBFBD><EFBFBD>ӱ<EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD>ˣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڹرյ<EFBFBD>״̬
*pcb<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD>tcp_slowtmr()<EFBFBD>ͷ<EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><EFBFBD>
*/
err_t
tcp_close(struct tcp_pcb *pcb)
{
@ -341,7 +343,7 @@ tcp_abandon(struct tcp_pcb *pcb, int reset)
u32_t seqno, ackno;
u16_t remote_port, local_port;
ip_addr_t remote_ip, local_ip;
#if LWIP_CALLBACK_API
#if LWIP_CALLBACK_API
tcp_err_fn errf;
#endif /* LWIP_CALLBACK_API */
void *errf_arg;
@ -373,7 +375,7 @@ tcp_abandon(struct tcp_pcb *pcb, int reset)
if (pcb->unsent != NULL) {
tcp_segs_free(pcb->unsent);
}
#if TCP_QUEUE_OOSEQ
#if TCP_QUEUE_OOSEQ
if (pcb->ooseq != NULL) {
tcp_segs_free(pcb->ooseq);
}
@ -555,7 +557,7 @@ tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog)
return (struct tcp_pcb *)lpcb;
}
/**
/**
* Update the state that tracks the available window space to advertise.
*
* Returns how much extra window would be advertised if we sent an
@ -636,7 +638,7 @@ tcp_new_port(void)
#define TCP_LOCAL_PORT_RANGE_END 0x7fff
#endif
static u16_t port = TCP_LOCAL_PORT_RANGE_START;
again:
// if (++port >= TCP_LOCAL_PORT_RANGE_END) {
// port = TCP_LOCAL_PORT_RANGE_START;
@ -646,7 +648,7 @@ tcp_new_port(void)
if (port < TCP_LOCAL_PORT_RANGE_START)
port += TCP_LOCAL_PORT_RANGE_START;
/* Check all PCB lists. */
for (i = 0; i < NUM_TCP_PCB_LISTS; i++) {
for (i = 0; i < NUM_TCP_PCB_LISTS; i++) {
for(pcb = *tcp_pcb_lists[i]; pcb != NULL; pcb = pcb->next) {
if (pcb->local_port == port) {
goto again;
@ -743,7 +745,7 @@ tcp_connect(struct tcp_pcb *pcb, ip_addr_t *ipaddr, u16_t port,
pcb->ssthresh = pcb->mss * 10;
#if LWIP_CALLBACK_API
pcb->connected = connected;//ע<><D7A2>connected<65>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
#else /* LWIP_CALLBACK_API */
#else /* LWIP_CALLBACK_API */
LWIP_UNUSED_ARG(connected);
#endif /* LWIP_CALLBACK_API */
@ -849,7 +851,7 @@ tcp_slowtmr(void)
LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_slowtmr: cwnd %"U16_F
" ssthresh %"U16_F"\n",
pcb->cwnd, pcb->ssthresh));
/* The following needs to be called AFTER cwnd is set to one
mss - STJ */
tcp_rexmit_rto(pcb);
@ -873,7 +875,7 @@ tcp_slowtmr(void)
if((u32_t)(tcp_ticks - pcb->tmr) >
(pcb->keep_idle + (pcb->keep_cnt*pcb->keep_intvl))
/ TCP_SLOW_INTERVAL)
#else
#else
if((u32_t)(tcp_ticks - pcb->tmr) >
(pcb->keep_idle + TCP_MAXIDLE) / TCP_SLOW_INTERVAL)
#endif /* LWIP_TCP_KEEPALIVE */
@ -881,17 +883,17 @@ tcp_slowtmr(void)
LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: KEEPALIVE timeout. Aborting connection to %"U16_F".%"U16_F".%"U16_F".%"U16_F".\n",
ip4_addr1_16(&pcb->remote_ip), ip4_addr2_16(&pcb->remote_ip),
ip4_addr3_16(&pcb->remote_ip), ip4_addr4_16(&pcb->remote_ip)));
++pcb_remove;
++pcb_reset;
}
#if LWIP_TCP_KEEPALIVE
else if((u32_t)(tcp_ticks - pcb->tmr) >
else if((u32_t)(tcp_ticks - pcb->tmr) >
(pcb->keep_idle + pcb->keep_cnt_sent * pcb->keep_intvl)
/ TCP_SLOW_INTERVAL)
#else
else if((u32_t)(tcp_ticks - pcb->tmr) >
(pcb->keep_idle + pcb->keep_cnt_sent * TCP_KEEPINTVL_DEFAULT)
else if((u32_t)(tcp_ticks - pcb->tmr) >
(pcb->keep_idle + pcb->keep_cnt_sent * TCP_KEEPINTVL_DEFAULT)
/ TCP_SLOW_INTERVAL)
#endif /* LWIP_TCP_KEEPALIVE */
{
@ -942,12 +944,12 @@ tcp_slowtmr(void)
LWIP_ASSERT("tcp_slowtmr: first pcb == tcp_active_pcbs", tcp_active_pcbs == pcb);
tcp_active_pcbs = pcb->next;
}
if (pcb_reset) {
tcp_rst(pcb->snd_nxt, pcb->rcv_nxt, &pcb->local_ip, &pcb->remote_ip,
pcb->local_port, pcb->remote_port);
}
TCP_EVENT_ERR(pcb->errf, pcb->callback_arg, ERR_ABRT);
pcb2 = pcb;
pcb = pcb->next;
@ -971,7 +973,7 @@ tcp_slowtmr(void)
}
}
/* Steps through all of the TIME-WAIT PCBs. */
prev = NULL;
pcb = tcp_tw_pcbs;
@ -983,7 +985,7 @@ tcp_slowtmr(void)
if ((u32_t)(tcp_ticks - pcb->tmr) > 2 * TCP_MSL / TCP_SLOW_INTERVAL) {
++pcb_remove;
}
/* If the PCB should be removed, do it. */
@ -1101,7 +1103,7 @@ tcp_setprio(struct tcp_pcb *pcb, u8_t prio)
*
* @param seg the old tcp_seg
* @return a copy of seg
*/
*/
struct tcp_seg *
tcp_seg_copy(struct tcp_seg *seg)
{
@ -1111,7 +1113,7 @@ tcp_seg_copy(struct tcp_seg *seg)
if (cseg == NULL) {
return NULL;
}
SMEMCPY((u8_t *)cseg, (const u8_t *)seg, sizeof(struct tcp_seg));
SMEMCPY((u8_t *)cseg, (const u8_t *)seg, sizeof(struct tcp_seg));
pbuf_ref(cseg->p);
return cseg;
}
@ -1150,7 +1152,7 @@ tcp_kill_prio(u8_t prio)
mprio = TCP_PRIO_MAX;
/* We kill the oldest active connection that has lower priority than prio. */
inactivity = 0;
inactive = NULL;
@ -1207,7 +1209,7 @@ tcp_alloc(u8_t prio)
{
struct tcp_pcb *pcb;
u32_t iss;
pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB);//<2F><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>ؿռ<D8BF>
if (pcb == NULL) {
//os_printf("tcp_pcb memory is fail\n");
@ -1253,18 +1255,18 @@ tcp_alloc(u8_t prio)
pcb->snd_wl2 = iss; //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CDB4>ڸ<EFBFBD><DAB8><EFBFBD><EFBFBD>ֶ<EFBFBD>
pcb->snd_nxt = iss;
pcb->lastack = iss;
pcb->snd_lbb = iss;
pcb->snd_lbb = iss;
pcb->tmr = tcp_ticks; //<2F><>¼<EFBFBD><C2BC><EFBFBD>ƿ鴴<C6BF><E9B4B4>ϵͳʱ<CDB3><CAB1>
pcb->polltmr = 0; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ʱ<EFBFBD><CAB1>
#if LWIP_CALLBACK_API
pcb->recv = tcp_recv_null; //ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD>ϲ<CFB2><E3BAAF>
#endif /* LWIP_CALLBACK_API */
#endif /* LWIP_CALLBACK_API */
/* Init KEEPALIVE timer */
pcb->keep_idle = TCP_KEEPIDLE_DEFAULT;
#if LWIP_TCP_KEEPALIVE
pcb->keep_intvl = TCP_KEEPINTVL_DEFAULT;
pcb->keep_cnt = TCP_KEEPCNT_DEFAULT;
@ -1300,10 +1302,10 @@ tcp_new(void)
* <EFBFBD><EFBFBD><EFBFBD>ֶν<EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param pcb tcp_pcb to set the callback argument
* @param arg void pointer argument to pass to callback functions
*/
*/
void
tcp_arg(struct tcp_pcb *pcb, void *arg)
{
{
pcb->callback_arg = arg;
}
#if LWIP_CALLBACK_API
@ -1314,7 +1316,7 @@ tcp_arg(struct tcp_pcb *pcb, void *arg)
*<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƿ<EFBFBD><EFBFBD>recv<EFBFBD>ֶ<EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ص<EFBFBD>
* @param pcb tcp_pcb to set the recv callback
* @param recv callback function to call for this pcb when data is received
*/
*/
void
tcp_recv(struct tcp_pcb *pcb, tcp_recv_fn recv)
{
@ -1327,7 +1329,7 @@ tcp_recv(struct tcp_pcb *pcb, tcp_recv_fn recv)
*<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƿ<EFBFBD>send <EFBFBD>ֶ<EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><EFBFBD>ͳɹ<EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>
* @param pcb tcp_pcb to set the sent callback
* @param sent callback function to call for this pcb when data is successfully sent
*/
*/
void
tcp_sent(struct tcp_pcb *pcb, tcp_sent_fn sent)
{
@ -1341,7 +1343,7 @@ tcp_sent(struct tcp_pcb *pcb, tcp_sent_fn sent)
* @param pcb tcp_pcb to set the err callback
* @param err callback function to call for this pcb when a fatal error
* has occured on the connection
*/
*/
void
tcp_err(struct tcp_pcb *pcb, tcp_err_fn err)
{
@ -1355,7 +1357,7 @@ tcp_err(struct tcp_pcb *pcb, tcp_err_fn err)
* @param pcb tcp_pcb to set the accept callback
* @param accept callback function to call for this pcb when LISTENing
* connection has been connected to another host
*/
*/
void
tcp_accept(struct tcp_pcb *pcb, tcp_accept_fn accept)
{
@ -1369,15 +1371,15 @@ tcp_accept(struct tcp_pcb *pcb, tcp_accept_fn accept)
* from TCP. The interval is specified in terms of the TCP coarse
* timer interval, which is called twice a second.
*<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƿ<EFBFBD><EFBFBD>POLL<EFBFBD>ֶ<EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
*/
void
tcp_poll(struct tcp_pcb *pcb, tcp_poll_fn poll, u8_t interval)
{
#if LWIP_CALLBACK_API
pcb->poll = poll;
#else /* LWIP_CALLBACK_API */
#else /* LWIP_CALLBACK_API */
LWIP_UNUSED_ARG(poll);
#endif /* LWIP_CALLBACK_API */
#endif /* LWIP_CALLBACK_API */
pcb->pollinterval = interval;
}
@ -1461,7 +1463,7 @@ tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb)
TCP_RMV(pcblist, pcb);
tcp_pcb_purge(pcb);
/* if there is an outstanding delayed ACKs, send it */
if (pcb->state != TIME_WAIT &&
pcb->state != LISTEN &&
@ -1492,7 +1494,7 @@ u32_t
tcp_next_iss(void)
{
static u32_t iss = 6510;
again:
iss += tcp_ticks; /* XXX */
if (iss == 0)
@ -1632,21 +1634,21 @@ tcp_debug_print_pcbs(void)
pcb->local_port, pcb->remote_port,
pcb->snd_nxt, pcb->rcv_nxt));
tcp_debug_print_state(pcb->state);
}
}
LWIP_DEBUGF(TCP_DEBUG, ("Listen PCB states:\n"));
for(pcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; pcb != NULL; pcb = pcb->next) {
LWIP_DEBUGF(TCP_DEBUG, ("Local port %"U16_F", foreign port %"U16_F" snd_nxt %"U32_F" rcv_nxt %"U32_F" ",
pcb->local_port, pcb->remote_port,
pcb->snd_nxt, pcb->rcv_nxt));
tcp_debug_print_state(pcb->state);
}
}
LWIP_DEBUGF(TCP_DEBUG, ("TIME-WAIT PCB states:\n"));
for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
LWIP_DEBUGF(TCP_DEBUG, ("Local port %"U16_F", foreign port %"U16_F" snd_nxt %"U32_F" rcv_nxt %"U32_F" ",
pcb->local_port, pcb->remote_port,
pcb->snd_nxt, pcb->rcv_nxt));
tcp_debug_print_state(pcb->state);
}
}
}
/**

View File

@ -6,7 +6,7 @@
*
* These functions are generally called in the order (ip_input() ->)
* tcp_input() -> * tcp_process() -> tcp_receive() (-> application).
*
*
*/
/*
@ -92,12 +92,12 @@ static err_t tcp_timewait_input(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
* @param p received TCP segment to process (p->payload pointing to the IP header)
* @param inp network interface on which this segment was received
*/
/**
* TCP<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?<EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD>TCPͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD>p:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD>TCP<EFBFBD><EFBFBD>(ָ<EFBFBD><EFBFBD>IPͷ<EFBFBD>ĸ<EFBFBD><EFBFBD><EFBFBD>)
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD>inp:<EFBFBD><EFBFBD><EFBFBD>նε<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
*/
/**
* TCP<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?<EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD>TCPͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD>p:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD>TCP<EFBFBD><EFBFBD>(ָ<EFBFBD><EFBFBD>IPͷ<EFBFBD>ĸ<EFBFBD><EFBFBD><EFBFBD>)
* @<EFBFBD><EFBFBD><EFBFBD><EFBFBD>inp:<EFBFBD><EFBFBD><EFBFBD>նε<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
*/
void
tcp_input(struct pbuf *p, struct netif *inp)
{
@ -112,15 +112,15 @@ tcp_input(struct pbuf *p, struct netif *inp)
PERF_START;
TCP_STATS_INC(tcp.recv); //״̬<D7B4><CCAC>1
TCP_STATS_INC(tcp.recv); //״̬<D7B4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ݱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><EFBFBD>ֵ<EFBFBD>ƫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*IPv4<EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>20<EFBFBD><EFBFBD><EFBFBD>ֽڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>IHL<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶε<EFBFBD><EFBFBD><EFBFBD>Сֵ<EFBFBD><EFBFBD>ʮ<EFBFBD><EFBFBD><EFBFBD>Ʊ<EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>5 (5x4 = 20<EFBFBD>ֽ<EFBFBD>)<EFBFBD><EFBFBD>
*<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD>İ<EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>4<EFBFBD>ֽڵı<EFBFBD><EFBFBD><EFBFBD>
*/
tcphdr = (struct tcp_hdr *)((u8_t *)p->payload + IPH_HL(iphdr) * 4);
@ -135,7 +135,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
TCP_STATS_INC(tcp.lenerr);//<2F><><EFBFBD>󳤶ȼ<F3B3A4B6><C8BC><EFBFBD>
TCP_STATS_INC(tcp.drop);//<2F><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
snmp_inc_tcpinerrs();
pbuf_free(p);//<2F>ͷ<EFBFBD>buffer
pbuf_free(p);//<2F>ͷ<EFBFBD>buffer
return;
}
@ -183,23 +183,23 @@ tcp_input(struct pbuf *p, struct netif *inp)
/* Convert fields in TCP header to host byte order. */
tcphdr->src = ntohs(tcphdr->src); //ת<><D7AA>Դ<EFBFBD><D4B4>ַ
tcphdr->dest = ntohs(tcphdr->dest); //ת<><D7AA>Ŀ<EFBFBD>ĵ<EFBFBD>ַ
seqno = tcphdr->seqno = ntohl(tcphdr->seqno); //ת<><D7AA><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD>
seqno = tcphdr->seqno = ntohl(tcphdr->seqno); //ת<><D7AA><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD>
ackno = tcphdr->ackno = ntohl(tcphdr->ackno); //ת<><D7AA>Ӧ<EFBFBD><D3A6><EFBFBD>
tcphdr->wnd = ntohs(tcphdr->wnd); //ת<><D7AA>tcp<63><70><EFBFBD><EFBFBD>
flags = TCPH_FLAGS(tcphdr);//<2F>õ<EFBFBD>tcp header<65>ı<EFBFBD>־
/*
*<EFBFBD><EFBFBD>־<EFBFBD><EFBFBD>3λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶΣ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>1λ
* <EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>λ<EFBFBD><EFBFBD>1λ<EFBFBD><EFBFBD>ȡֵ<EFBFBD><EFBFBD>0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD>ֶΣ<EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶܷΣ<EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>1λ<EFBFBD><EFBFBD>ȡֵ<EFBFBD><EFBFBD>0<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>а<EFBFBD>1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD><EFBFBD>İ<EFBFBD>
*/
flags = TCPH_FLAGS(tcphdr);//<2F>õ<EFBFBD>tcp header<65>ı<EFBFBD>־
/*
*<EFBFBD><EFBFBD>־<EFBFBD><EFBFBD>3λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶΣ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>1λ
* <EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>λ<EFBFBD><EFBFBD>1λ<EFBFBD><EFBFBD>ȡֵ<EFBFBD><EFBFBD>0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD>ֶΣ<EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶܷΣ<EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>1λ<EFBFBD><EFBFBD>ȡֵ<EFBFBD><EFBFBD>0<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>а<EFBFBD>1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD><EFBFBD>İ<EFBFBD>
*/
tcplen = p->tot_len + ((flags & (TCP_FIN | TCP_SYN)) ? 1 : 0);//TCP_FIN <20><> TCP_SYN <20><>λ<EFBFBD><CEBB>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
/* Demultiplex an incoming segment. First, we check if it is destined
for an active connection. <EFBFBD><EFBFBD><EFBFBD>ȣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>һ<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
////////////////////////////////////////////////////////////////////////////////////////
prev = NULL;
prev = NULL;
for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
LWIP_ASSERT("tcp_input: active pcb->state != CLOSED", pcb->state != CLOSED);
LWIP_ASSERT("tcp_input: active pcb->state != TIME-WAIT", pcb->state != TIME_WAIT);
@ -286,9 +286,9 @@ tcp_input(struct pbuf *p, struct netif *inp)
/* put this listening pcb at the head of the listening list */
tcp_listen_pcbs.listen_pcbs = lpcb;
}
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packed for LISTENing connection.\n"));
tcp_listen_input(lpcb);//<2F><><EFBFBD><EFBFBD>tcp<63><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>
tcp_listen_input(lpcb);//<2F><><EFBFBD><EFBFBD>tcp<63><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>
pbuf_free(p);
return;
}
@ -385,7 +385,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
//PSH<53><48>־ PSH <20><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
//<2F><>PSH=1ʱ<31><CAB1>Ҫ<EFBFBD><D2AA><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7>͸÷ֶΣ<D6B6>
//<2F><><EFBFBD><EFBFBD>շ<EFBFBD><D5B7><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD>Ӧ<EFBFBD>ò㣬<C3B2><E3A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4>?
if (flags & TCP_PSH) {
recv_data->flags |= PBUF_FLAG_PUSH;//<2F><><EFBFBD>bufferӦ<72><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
@ -411,7 +411,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
if (pcb->rcv_wnd != TCP_WND) {
pcb->rcv_wnd++;
}
TCP_EVENT_CLOSED(pcb, err);
if (err == ERR_ABRT) {
goto aborted;
@ -595,21 +595,21 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
static err_t
tcp_timewait_input(struct tcp_pcb *pcb)
{
if (flags & TCP_RST) { //RST<53><54>λ<EFBFBD><CEBB>ֱ<EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD>
return ERR_OK;
}
if (flags & TCP_SYN) { //<2F><>SYN<59><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD>ڽ<EFBFBD><DABD>մ<EFBFBD><D5B4><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD>RST<53><54><EFBFBD><EFBFBD>
if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt, pcb->rcv_nxt+pcb->rcv_wnd)) {
tcp_rst(ackno, seqno + tcplen, ip_current_dest_addr(), ip_current_src_addr(),
tcphdr->dest, tcphdr->src);
return ERR_OK;
}
} else if (flags & TCP_FIN) { //<2F><><EFBFBD>İ<EFBFBD>FIN<49><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
pcb->tmr = tcp_ticks; //<2F><>λ<EFBFBD>ȴ<EFBFBD>2MSLʱ<4C><EFBFBD><E4A3AC><EFBFBD>ƿ<EFBFBD><C6BF><EFBFBD><EFBFBD>µȴ<C2B5>2MSL
}
@ -648,7 +648,7 @@ tcp_process(struct tcp_pcb *pcb)
acceptable = 1;
}
} else {
if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt,
if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt,
pcb->rcv_nxt+pcb->rcv_wnd)) {
acceptable = 1;
}
@ -669,12 +669,12 @@ tcp_process(struct tcp_pcb *pcb)
}
}
if ((flags & TCP_SYN) && (pcb->state != SYN_SENT && pcb->state != SYN_RCVD)) {
if ((flags & TCP_SYN) && (pcb->state != SYN_SENT && pcb->state != SYN_RCVD)) {
/* Cope with new connection attempt after remote end crashed */
tcp_ack_now(pcb);
return ERR_OK;
}
if ((pcb->flags & TF_RXCLOSED) == 0) {
/* Update the PCB (in)activity timer unless rx is closed (see tcp_shutdown) */
pcb->tmr = tcp_ticks;
@ -808,6 +808,9 @@ tcp_process(struct tcp_pcb *pcb)
TCP_RMV(&tcp_active_pcbs, pcb);
pcb->state = TIME_WAIT;
TCP_REG(&tcp_tw_pcbs, pcb);
#if MEMP_NUM_TCP_PCB_TIME_WAIT
TCP_TW_LIMIT(MEMP_NUM_TCP_PCB_TIME_WAIT);
#endif
} else {
tcp_ack_now(pcb);
pcb->state = CLOSING;
@ -825,6 +828,9 @@ tcp_process(struct tcp_pcb *pcb)
TCP_RMV(&tcp_active_pcbs, pcb);
pcb->state = TIME_WAIT;
TCP_REG(&tcp_tw_pcbs, pcb);
#if MEMP_NUM_TCP_PCB_TIME_WAIT
TCP_TW_LIMIT(MEMP_NUM_TCP_PCB_TIME_WAIT);
#endif
}
break;
case CLOSING:
@ -835,6 +841,9 @@ tcp_process(struct tcp_pcb *pcb)
TCP_RMV(&tcp_active_pcbs, pcb);
pcb->state = TIME_WAIT;
TCP_REG(&tcp_tw_pcbs, pcb);
#if MEMP_NUM_TCP_PCB_TIME_WAIT
TCP_TW_LIMIT(MEMP_NUM_TCP_PCB_TIME_WAIT);
#endif
}
break;
case LAST_ACK:
@ -939,7 +948,7 @@ tcp_receive(struct tcp_pcb *pcb)
#if TCP_WND_DEBUG
} else {
if (pcb->snd_wnd != tcphdr->wnd) {
LWIP_DEBUGF(TCP_WND_DEBUG,
LWIP_DEBUGF(TCP_WND_DEBUG,
("tcp_receive: no window update lastack %"U32_F" ackno %"
U32_F" wl1 %"U32_F" seqno %"U32_F" wl2 %"U32_F"\n",
pcb->lastack, ackno, pcb->snd_wl1, seqno, pcb->snd_wl2));
@ -954,12 +963,12 @@ tcp_receive(struct tcp_pcb *pcb)
* 3) the advertised window hasn't changed <EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>и<EFBFBD><EFBFBD><EFBFBD>
* 4) There is outstanding unacknowledged data (retransmission timer running)<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵȴ<EFBFBD>ȷ<EFBFBD><EFBFBD>
* 5) The ACK is == biggest ACK sequence number so far seen (snd_una) ackno = lastack
*
* If it passes all five, should process as a dupack:
* a) dupacks < 3: do nothing
* b) dupacks == 3: fast retransmit
* c) dupacks > 3: increase cwnd
*
*
* If it passes all five, should process as a dupack:
* a) dupacks < 3: do nothing
* b) dupacks == 3: fast retransmit
* c) dupacks > 3: increase cwnd
*
* If it only passes 1-3, should reset dupack counter (and add to
* stats, which we don't do in lwIP)
*
@ -1002,10 +1011,10 @@ tcp_receive(struct tcp_pcb *pcb)
}
} else if (TCP_SEQ_BETWEEN(ackno, pcb->lastack+1, pcb->snd_nxt)){//ackno<6E><6F>lastack+1<><31>snd_nxt֮<74><EFBFBD>жϷ<D0B6><CFB7>ʹ<EFBFBD><CDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/* We come here when the ACK acknowledges new data. */
if (pcb->flags & TF_INFR) {
pcb->flags &= ~TF_INFR;// Reset the "IN Fast Retransmit" flag,since we are no longer in fast retransmit
pcb->cwnd = pcb->ssthresh;//Reset the congestion window to the "slow start threshold".
pcb->cwnd = pcb->ssthresh;//Reset the congestion window to the "slow start threshold".
}
/* Reset the number of retransmissions. */
@ -1047,7 +1056,7 @@ tcp_receive(struct tcp_pcb *pcb)
ntohl(pcb->unacked->tcphdr->seqno) + TCP_TCPLEN(pcb->unacked): 0));
/* Remove segment from the unacknowledged list if the incoming
ACK acknowlegdes them.
ACK acknowlegdes them.
*<EFBFBD>ͷ<EFBFBD>unacked<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD>ȷ<EFBFBD>ϵı<EFBFBD><EFBFBD>ĶΣ<EFBFBD>
*ֱ<EFBFBD><EFBFBD>unacked<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>ֹͣ*/
while (pcb->unacked != NULL &&
@ -1068,7 +1077,7 @@ tcp_receive(struct tcp_pcb *pcb)
pcb->acked--;
}
pcb->snd_queuelen -= pbuf_clen(next->p);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>pbufs<66><73><EFBFBD><EFBFBD>
pcb->snd_queuelen -= pbuf_clen(next->p);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>pbufs<66><73><EFBFBD><EFBFBD>
tcp_seg_free(next);//<2F>ͷ<EFBFBD>tcp<63><70>
LWIP_DEBUGF(TCP_QLEN_DEBUG, ("%"U16_F" (after freeing unacked)\n", (u16_t)pcb->snd_queuelen));
@ -1099,13 +1108,13 @@ tcp_receive(struct tcp_pcb *pcb)
in fact have been sent once. */
/** unsent<6E><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ܱ<EFBFBD>acknoȷ<6F>ϵı<CFB5><C4B1>ĶΣ<C4B6><CEA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>**/
while (pcb->unsent != NULL &&
TCP_SEQ_BETWEEN(ackno, ntohl(pcb->unsent->tcphdr->seqno) +
TCP_SEQ_BETWEEN(ackno, ntohl(pcb->unsent->tcphdr->seqno) +
TCP_TCPLEN(pcb->unsent), pcb->snd_nxt)) {
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: removing %"U32_F":%"U32_F" from pcb->unsent\n",
ntohl(pcb->unsent->tcphdr->seqno), ntohl(pcb->unsent->tcphdr->seqno) +
TCP_TCPLEN(pcb->unsent)));
next = pcb->unsent;//pcbδ<62><CEB4><EFBFBD>ͱ<EFBFBD>־
next = pcb->unsent;//pcbδ<62><CEB4><EFBFBD>ͱ<EFBFBD>־
pcb->unsent = pcb->unsent->next;//δ<><CEB4><EFBFBD>͵<EFBFBD><CDB5><EFBFBD>һ<EFBFBD><D2BB>
LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_receive: queuelen %"U16_F" ... ", (u16_t)pcb->snd_queuelen));
LWIP_ASSERT("pcb->snd_queuelen >= pbuf_clen(next->p)", (pcb->snd_queuelen >= pbuf_clen(next->p)));
@ -1252,7 +1261,7 @@ tcp_receive(struct tcp_pcb *pcb)
/* The sequence number must be within the window (above rcv_nxt
and below rcv_nxt + rcv_wnd) in order to be further
processed. */
if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt,
if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt,
pcb->rcv_nxt + pcb->rcv_wnd - 1)){//rcv_nxt < seqno < rcv_nxt + rcv_wnd - 1,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><DABD>շ<EFBFBD>Χ<EFBFBD><CEA7>
if (pcb->rcv_nxt == seqno) {
/* The incoming segment is the next in sequence. We check if
@ -1261,12 +1270,12 @@ tcp_receive(struct tcp_pcb *pcb)
tcplen = TCP_TCPLEN(&inseg);//<2F><><EFBFBD><EFBFBD>Ķγ<C4B6><CEB3><EFBFBD>
if (tcplen > pcb->rcv_wnd) {//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>մ<EFBFBD><D5B4>ڴ<EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><CEB2><EFBFBD>ض<EFBFBD>
LWIP_DEBUGF(TCP_INPUT_DEBUG,
LWIP_DEBUGF(TCP_INPUT_DEBUG,
("tcp_receive: other end overran receive window"
"seqno %"U32_F" len %"U16_F" right edge %"U32_F"\n",
seqno, tcplen, pcb->rcv_nxt + pcb->rcv_wnd));
if (TCPH_FLAGS(inseg.tcphdr) & TCP_FIN) {
/* Must remove the FIN from the header as we're trimming
/* Must remove the FIN from the header as we're trimming
* that byte of sequence-space from the packet */
TCPH_FLAGS_SET(inseg.tcphdr, TCPH_FLAGS(inseg.tcphdr) &~ TCP_FIN);
}
@ -1286,7 +1295,7 @@ tcp_receive(struct tcp_pcb *pcb)
- inseq overlaps with ooseq */
if (pcb->ooseq != NULL) {
if (TCPH_FLAGS(inseg.tcphdr) & TCP_FIN) {
LWIP_DEBUGF(TCP_INPUT_DEBUG,
LWIP_DEBUGF(TCP_INPUT_DEBUG,
("tcp_receive: received in-order FIN, binning ooseq queue\n"));
/* Received in-order FIN means anything that was received
* out of order must now have been received in-order, so
@ -1394,7 +1403,7 @@ tcp_receive(struct tcp_pcb *pcb)
recv_flags |= TF_GOT_FIN;
if (pcb->state == ESTABLISHED) { /* force passive close or we can move to active close */
pcb->state = CLOSE_WAIT;
}
}
}
pcb->ooseq = cseg->next;
@ -1507,12 +1516,12 @@ tcp_receive(struct tcp_pcb *pcb)
}
/* check if the remote side overruns our receive window */
if ((u32_t)tcplen + seqno > pcb->rcv_nxt + (u32_t)pcb->rcv_wnd) {
LWIP_DEBUGF(TCP_INPUT_DEBUG,
LWIP_DEBUGF(TCP_INPUT_DEBUG,
("tcp_receive: other end overran receive window"
"seqno %"U32_F" len %"U16_F" right edge %"U32_F"\n",
seqno, tcplen, pcb->rcv_nxt + pcb->rcv_wnd));
if (TCPH_FLAGS(next->next->tcphdr) & TCP_FIN) {
/* Must remove the FIN from the header as we're trimming
/* Must remove the FIN from the header as we're trimming
* that byte of sequence-space from the packet */
TCPH_FLAGS_SET(next->next->tcphdr, TCPH_FLAGS(next->next->tcphdr) &~ TCP_FIN);
}
@ -1549,7 +1558,7 @@ tcp_receive(struct tcp_pcb *pcb)
}
/**
* Parses the options contained in the incoming segment.
* Parses the options contained in the incoming segment.
*
* Called from tcp_listen_input() and tcp_process().
* Currently, only the MSS option is supported!
@ -1606,7 +1615,7 @@ tcp_parseopt(struct tcp_pcb *pcb)
return;
}
/* TCP timestamp option with valid length */
tsval = (opts[c+2]) | (opts[c+3] << 8) |
tsval = (opts[c+2]) | (opts[c+3] << 8) |
(opts[c+4] << 16) | (opts[c+5] << 24);
if (flags & TCP_SYN) {
pcb->ts_recent = ntohl(tsval);

View File

@ -144,7 +144,7 @@ udp_input(struct pbuf *p, struct netif *inp)
/* all packets for DHCP_CLIENT_PORT not coming from DHCP_SERVER_PORT are dropped! */
if (src == DHCP_SERVER_PORT) {
if ((inp->dhcp != NULL) && (inp->dhcp->pcb != NULL)) {
/* accept the packe if
/* accept the packe if
(- broadcast or directed to us) -> DHCP is link-layer-addressed, local ip is always ANY!
- inp->dhcp->pcb->remote == ANY or iphdr->src */
if ((ip_addr_isany(&inp->dhcp->pcb->remote_ip) ||
@ -196,7 +196,7 @@ udp_input(struct pbuf *p, struct netif *inp)
(broadcast))) {
#endif /* IP_SOF_BROADCAST_RECV */
local_match = 1;
if ((uncon_pcb == NULL) &&
if ((uncon_pcb == NULL) &&
((pcb->flags & UDP_FLAGS_CONNECTED) == 0)) {
/* the first unconnected matching PCB */
uncon_pcb = pcb;
@ -422,7 +422,7 @@ udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
*
* If the PCB already has a remote address association, it will
* be restored after the data is sent.
*
*
* @return lwIP error code (@see udp_send for possible error codes)
*
* @see udp_disconnect() udp_send()
@ -504,6 +504,7 @@ udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip,
ip_addr_t *src_ip;
err_t err;
struct pbuf *q; /* q will be sent down the stack */
u8_t ttl;
#if IP_SOF_BROADCAST
/* broadcast filter? */
@ -553,11 +554,11 @@ udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip,
udphdr->src = htons(pcb->local_port);
udphdr->dest = htons(dst_port);
/* in UDP, 0 checksum means 'no checksum' */
udphdr->chksum = 0x0000;
udphdr->chksum = 0x0000;
/* Multicast Loop? */
#if LWIP_IGMP
if (ip_addr_ismulticast(dst_ip) && ((pcb->flags & UDP_FLAGS_MULTICAST_LOOP) != 0)) {
if (((pcb->flags & UDP_FLAGS_MULTICAST_LOOP) != 0) && ip_addr_ismulticast(dst_ip)) {
q->flags |= PBUF_FLAG_MCASTLOOP;
}
#endif /* LWIP_IGMP */
@ -665,13 +666,21 @@ udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip,
udphdr->chksum = udpchksum;
}
#endif /* CHECKSUM_GEN_UDP */
/* Determine TTL to use */
#if LWIP_IGMP
ttl = (ip_addr_ismulticast(dst_ip) ? pcb->mcast_ttl : pcb->ttl);
#else /* LWIP_IGMP */
ttl = pcb->ttl;
#endif /* LWIP_IGMP */
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP checksum 0x%04"X16_F"\n", udphdr->chksum));
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,IP_PROTO_UDP,)\n"));
/* output to IP */
#if LWIP_NETIF_HWADDRHINT
netif->addr_hint = &(pcb->addr_hint);
#endif /* LWIP_NETIF_HWADDRHINT*/
err = ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDP, netif);
err = ip_output_if(q, src_ip, dst_ip, ttl, pcb->tos, IP_PROTO_UDP, netif);
#if LWIP_NETIF_HWADDRHINT
netif->addr_hint = NULL;
#endif /* LWIP_NETIF_HWADDRHINT*/
@ -950,6 +959,9 @@ udp_new(void)
/* initialize PCB to all zeroes */
os_memset(pcb, 0, sizeof(struct udp_pcb));
pcb->ttl = UDP_TTL;
#if LWIP_IGMP
pcb->mcast_ttl = UDP_TTL;
#endif
}
return pcb;
}