diff --git a/components/esp_netif/lwip/esp_netif_lwip.c b/components/esp_netif/lwip/esp_netif_lwip.c index c3db13c5d5..ca9fd8fe02 100644 --- a/components/esp_netif/lwip/esp_netif_lwip.c +++ b/components/esp_netif/lwip/esp_netif_lwip.c @@ -1857,37 +1857,64 @@ esp_err_t esp_netif_dhcps_option(esp_netif_t *esp_netif, esp_netif_dhcp_option_m break; } case ESP_NETIF_SUBNET_MASK: { + esp_netif_ip_info_t *default_ip = esp_netif->ip_info; + ip4_addr_t *config_netmask = (ip4_addr_t *)opt_val; + if (!memcmp(&default_ip->netmask, config_netmask, sizeof(struct ip4_addr))) { + ESP_LOGE(TAG, "Please use esp_netif_set_ip_info interface to configure subnet mask"); + /* + * This API directly changes the subnet mask of dhcp server + * but the subnet mask of the network interface has not changed + * If you need to change the subnet mask of dhcp server + * you need to change the subnet mask of the network interface first. + * If the subnet mask of dhcp server is changed + * and the subnet mask of network interface is inconsistent + * with the subnet mask of dhcp sever, it may lead to the failure of sending packets. + * If want to configure the subnet mask of dhcp server + * please use esp_netif_set_ip_info to change the subnet mask of network interface first. + */ + return ESP_ERR_ESP_NETIF_INVALID_PARAMS; + } memcpy(opt_info, opt_val, opt_len); break; } case REQUESTED_IP_ADDRESS: { esp_netif_ip_info_t info; - uint32_t softap_ip = 0; + uint32_t server_ip = 0; uint32_t start_ip = 0; uint32_t end_ip = 0; + uint32_t range_start_ip = 0; + uint32_t range_end_ip = 0; dhcps_lease_t *poll = opt_val; if (poll->enable) { memset(&info, 0x00, sizeof(esp_netif_ip_info_t)); esp_netif_get_ip_info(esp_netif, &info); - softap_ip = htonl(info.ip.addr); + server_ip = htonl(info.ip.addr); + range_start_ip = server_ip & htonl(info.netmask.addr); + range_end_ip = range_start_ip | ~htonl(info.netmask.addr); + if (server_ip == range_start_ip || server_ip == range_end_ip) { + return ESP_ERR_ESP_NETIF_INVALID_PARAMS; + } start_ip = htonl(poll->start_ip.addr); end_ip = htonl(poll->end_ip.addr); /*config ip information can't contain local ip*/ - if ((start_ip <= softap_ip) && (softap_ip <= end_ip)) { + if ((server_ip >= start_ip) && (server_ip <= end_ip)) { return ESP_ERR_ESP_NETIF_INVALID_PARAMS; } /*config ip information must be in the same segment as the local ip*/ - softap_ip >>= 8; - if ((start_ip >> 8 != softap_ip) - || (end_ip >> 8 != softap_ip)) { + if (start_ip <= range_start_ip || start_ip >= range_end_ip) { return ESP_ERR_ESP_NETIF_INVALID_PARAMS; } - if (end_ip - start_ip > DHCPS_MAX_LEASE) { + if (end_ip <= range_start_ip || end_ip >= range_end_ip) { + return ESP_ERR_ESP_NETIF_INVALID_PARAMS; + } + + /*The number of configured ip is less than DHCPS_MAX_LEASE*/ + if ((end_ip - start_ip + 1 > DHCPS_MAX_LEASE) || (start_ip >= end_ip)) { return ESP_ERR_ESP_NETIF_INVALID_PARAMS; } } diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index 336567cb83..5f3de77bc2 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -448,7 +448,7 @@ menu "LWIP" Can be set lower to save RAM, the default value 1460(ipv4)/1440(ipv6) will give best throughput. IPv4 TCP_MSS Range: 576 <= TCP_MSS <= 1460 - IPv6 TCP_MSS Range: 1220<= TCP_mSS <= 1440 + IPv6 TCP_MSS Range: 1220<= TCP_MSS <= 1440 config LWIP_TCP_TMR_INTERVAL int "TCP timer interval(ms)" @@ -473,7 +473,7 @@ menu "LWIP" config LWIP_TCP_SND_BUF_DEFAULT int "Default send buffer size" - default 5744 # 4 * default MSS + default 5760 # 4 * default MSS range 2440 65535 if !LWIP_WND_SCALE range 2440 1024000 if LWIP_WND_SCALE help @@ -490,7 +490,7 @@ menu "LWIP" config LWIP_TCP_WND_DEFAULT int "Default receive window size" - default 5744 # 4 * default MSS + default 5760 # 4 * default MSS range 2440 65535 if !LWIP_WND_SCALE range 2440 1024000 if LWIP_WND_SCALE help @@ -532,6 +532,41 @@ menu "LWIP" Disable this option to save some RAM during TCP sessions, at the expense of increased retransmissions if segments arrive out of order. + + config LWIP_TCP_OOSEQ_TIMEOUT + int "Timeout for each pbuf queued in TCP OOSEQ, in RTOs." + depends on LWIP_TCP_QUEUE_OOSEQ + range 1 30 + default 6 + help + The timeout value is TCP_OOSEQ_TIMEOUT * RTO. + + config LWIP_TCP_OOSEQ_MAX_PBUFS + int "The maximum number of pbufs queued on OOSEQ per pcb" + depends on LWIP_TCP_QUEUE_OOSEQ + range 0 12 + default 4 + help + If LWIP_TCP_OOSEQ_MAX_PBUFS = 0, TCP will not control the number of OOSEQ pbufs. + + In a poor network environment, many out-of-order tcp pbufs will be received. + These out-of-order pbufs will be cached in the TCP out-of-order queue which will + cause Wi-Fi/Ethernet fail to release RX buffer in time. + It is possible that all RX buffers for MAC layer are used by OOSEQ. + + Control the number of out-of-order pbufs to ensure that the MAC layer + has enough RX buffer to receive packets. + + In the Wi-Fi scenario, recommended OOSEQ PBUFS Range: + 0 <= TCP_OOSEQ_MAX_PBUFS <= CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM/(MAX_TCP_NUMBER + 1) + + In the Ethernet scenario,recommended Ethernet OOSEQ PBUFS Range: + 0 <= TCP_OOSEQ_MAX_PBUFS <= CONFIG_ETH_DMA_RX_BUFFER_NUM/(MAX_TCP_NUMBER + 1) + + Within the recommended value range, the larger the value, the better the performance. + + MAX_TCP_NUMBER represent Maximum number of TCP connections in Wi-Fi(STA+SoftAP) and Ethernet scenario. + config LWIP_TCP_SACK_OUT bool "Support sending selective acknowledgements" default n diff --git a/components/lwip/apps/dhcpserver/dhcpserver.c b/components/lwip/apps/dhcpserver/dhcpserver.c index 82ddf80e0d..ca7c575a15 100644 --- a/components/lwip/apps/dhcpserver/dhcpserver.c +++ b/components/lwip/apps/dhcpserver/dhcpserver.c @@ -1116,7 +1116,7 @@ static void dhcps_poll_set(u32_t ip) end_ip = htonl(dhcps_poll.end_ip.addr); /*config ip information can't contain local ip*/ - if ((start_ip <= server_ip) && (server_ip <= end_ip)) { + if ((server_ip >= start_ip) && (server_ip <= end_ip)) { dhcps_poll.enable = false; } else { /*config ip information must be in the same segment as the local ip*/ @@ -1148,6 +1148,7 @@ static void dhcps_poll_set(u32_t ip) dhcps_poll.end_ip.addr = range_end_ip; dhcps_poll.start_ip.addr = htonl(dhcps_poll.start_ip.addr); dhcps_poll.end_ip.addr = htonl(dhcps_poll.end_ip.addr); + dhcps_poll.enable = true; } } diff --git a/components/lwip/lwip b/components/lwip/lwip index 4f24c9baf9..d3c89e938a 160000 --- a/components/lwip/lwip +++ b/components/lwip/lwip @@ -1 +1 @@ -Subproject commit 4f24c9baf9101634b7c690802f424b197b3bb685 +Subproject commit d3c89e938aac62c5cd2032628b05900787de5cc8 diff --git a/components/lwip/port/esp32/include/lwipopts.h b/components/lwip/port/esp32/include/lwipopts.h index 13f6b69fd1..2cd13d2cca 100644 --- a/components/lwip/port/esp32/include/lwipopts.h +++ b/components/lwip/port/esp32/include/lwipopts.h @@ -377,6 +377,21 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min) */ #define TCP_QUEUE_OOSEQ CONFIG_LWIP_TCP_QUEUE_OOSEQ +/** + * TCP_OOSEQ_MAX_PBUFS: The maximum number of pbufs + * queued on ooseq per pcb + */ +#if TCP_QUEUE_OOSEQ +#define TCP_OOSEQ_MAX_PBUFS CONFIG_LWIP_TCP_OOSEQ_MAX_PBUFS +#endif + +/** + * TCP_OOSEQ_TIMEOUT: Timeout for each pbuf queued in TCP OOSEQ, in RTOs. + */ +#if TCP_QUEUE_OOSEQ +#define TCP_OOSEQ_TIMEOUT CONFIG_LWIP_TCP_OOSEQ_TIMEOUT +#endif + /** * LWIP_TCP_SACK_OUT==1: TCP will support sending selective acknowledgements (SACKs). */