From 6abb3eb0b443377470978c8d6eadbe79ebb43994 Mon Sep 17 00:00:00 2001 From: xueyunfei Date: Wed, 31 Aug 2022 17:28:17 +0800 Subject: [PATCH] Lwip:Backport some lwip bugs to 4.3 * Update submodule: git log --oneline 76303df2386902e0d7873be4217f1d9d1b50f982..6fa02bd30daa656f896c7a36248253fb3b97660d Detailed description of the changes: - dhcp: reduce the DHCP Request timeout(esp-lwip@6fa02bd3) - dhcp: optimization fine timer when dhcp start(esp-lwip@79182163) - ip6 timer: optimization lwip ip6 reassembly timer (esp-lwip@c943fc5a) - ip4 timer: optimization lwip ip4 reassembly timer (esp-lwip@17f41c9f) - dns timer: optimization lwip dns timer (esp-lwip@7f5ab42c) - napt: Fix clean compilation (espressif/esp-lwip@6132c975) - Lwip:add TCP Fin2 timeout configuration (espressif/esp-lwip@15b4400e) - napt: Fix IP forwarding when forward netif enable NAPT (espressif/esp-lwip@c950063f) - napt/stats: Move some napt counters to stats module (espressif/esp-lwip@475d658a) - ip_napt_maint: Fix timestamp overflow handling (espressif/esp-lwip@2e904508) - napt: Fixes and improvements (espressif/esp-lwip@fb1f3552) --- components/lwip/Kconfig | 8 ++++- components/lwip/lwip | 2 +- components/lwip/port/esp32/include/lwipopts.h | 31 +++++++++++++++++-- .../lwip/test_afl_host/sdkconfig.defaults | 1 + docs/en/api-guides/lwip.rst | 1 + 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index 1ad7a8b037..d44f876f02 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -429,7 +429,13 @@ menu "LWIP" int "Maximum segment lifetime (MSL)" default 60000 help - Set maximum segment lifetime in in milliseconds. + Set maximum segment lifetime in milliseconds. + + config LWIP_TCP_FIN_WAIT_TIMEOUT + int "Maximum FIN segment lifetime" + default 20000 + help + Set maximum segment lifetime in milliseconds. config LWIP_TCP_SND_BUF_DEFAULT int "Default send buffer size" diff --git a/components/lwip/lwip b/components/lwip/lwip index 76303df238..6fa02bd30d 160000 --- a/components/lwip/lwip +++ b/components/lwip/lwip @@ -1 +1 @@ -Subproject commit 76303df2386902e0d7873be4217f1d9d1b50f982 +Subproject commit 6fa02bd30daa656f896c7a36248253fb3b97660d diff --git a/components/lwip/port/esp32/include/lwipopts.h b/components/lwip/port/esp32/include/lwipopts.h index e32802ad13..329690bda4 100644 --- a/components/lwip/port/esp32/include/lwipopts.h +++ b/components/lwip/port/esp32/include/lwipopts.h @@ -254,6 +254,14 @@ */ #define ESP_DHCP_DISABLE_CLIENT_ID CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID +#define DHCP_DEFINE_CUSTOM_TIMEOUTS 1 +/* Since for embedded devices it's not that hard to miss a discover packet, so lower + * the discover retry backoff time from (2,4,8,16,32,60,60)s to (500m,1,2,4,8,15,15)s. + */ + #define DHCP_REQUEST_TIMEOUT_SEQUENCE(state, tries) (state == DHCP_STATE_REQUESTING ? \ + (uint16_t)(1 * 1000) : \ + (uint16_t)(((tries) < 6 ? 1 << (tries) : 60) * 250)) + /** * CONFIG_LWIP_DHCP_RESTORE_LAST_IP==1: Last valid IP address obtained from DHCP server * is restored after reset/power-up. @@ -376,6 +384,11 @@ */ #define TCP_MSL CONFIG_LWIP_TCP_MSL +/** + * TCP_FIN_WAIT_TIMEOUT: The maximum FIN segment lifetime in milliseconds + */ +#define TCP_FIN_WAIT_TIMEOUT CONFIG_LWIP_TCP_FIN_WAIT_TIMEOUT + /** * TCP_MAXRTX: Maximum number of retransmissions of data segments. */ @@ -996,9 +1009,23 @@ #ifdef CONFIG_LWIP_TIMERS_ONDEMAND #define ESP_LWIP_IGMP_TIMERS_ONDEMAND 1 #define ESP_LWIP_MLD6_TIMERS_ONDEMAND 1 +#define ESP_LWIP_DHCP_FINE_TIMERS_ONDEMAND 1 +#define ESP_LWIP_DNS_TIMERS_ONDEMAND 1 +#if IP_REASSEMBLY +#define ESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND 1 +#endif /* IP_REASSEMBLY */ +#if LWIP_IPV6_REASS +#define ESP_LWIP_IP6_REASSEMBLY_TIMERS_ONDEMAND 1 +#endif /* LWIP_IPV6_REASS */ #else -#define ESP_LWIP_IGMP_TIMERS_ONDEMAND 0 -#define ESP_LWIP_MLD6_TIMERS_ONDEMAND 0 +#define ESP_LWIP_DHCP_FINE_TIMERS_ONDEMAND 0 +#define ESP_LWIP_DNS_TIMERS_ONDEMAND 0 +#if IP_REASSEMBLY +#define ESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND 0 +#endif /* IP_REASSEMBLY */ +#if LWIP_IPV6_REASS +#define ESP_LWIP_IP6_REASSEMBLY_TIMERS_ONDEMAND 0 +#endif /* LWIP_IPV6_REASS */ #endif #define TCP_SND_BUF CONFIG_LWIP_TCP_SND_BUF_DEFAULT diff --git a/components/lwip/test_afl_host/sdkconfig.defaults b/components/lwip/test_afl_host/sdkconfig.defaults index ec02309aec..dd7f02c667 100644 --- a/components/lwip/test_afl_host/sdkconfig.defaults +++ b/components/lwip/test_afl_host/sdkconfig.defaults @@ -1 +1,2 @@ CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=n +CONFIG_LWIP_TIMERS_ONDEMAND=n diff --git a/docs/en/api-guides/lwip.rst b/docs/en/api-guides/lwip.rst index c5215a5b0e..684ab08684 100644 --- a/docs/en/api-guides/lwip.rst +++ b/docs/en/api-guides/lwip.rst @@ -383,6 +383,7 @@ Most lwIP RAM usage is on-demand, as RAM is allocated from the heap as needed. T - Reducing :ref:`CONFIG_LWIP_MAX_SOCKETS` reduces the maximum number of sockets in the system. This will also cause TCP sockets in the ``WAIT_CLOSE`` state to be closed and recycled more rapidly (if needed to open a new socket), further reducing peak RAM usage. - Reducing :ref:`CONFIG_LWIP_TCPIP_RECVMBOX_SIZE`, :ref:`CONFIG_LWIP_TCP_RECVMBOX_SIZE` and :ref:`CONFIG_LWIP_UDP_RECVMBOX_SIZE` reduce memory usage at the expense of throughput, depending on usage. +- Reducing :ref:`CONFIG_LWIP_TCP_MSL`, :ref:`CONFIG_LWIP_TCP_FIN_WAIT_TIMEOUT` reduces the maximum segment lifetime in the system. This will also cause TCP sockets in the ``TIME_WAIT``, ``FIN_WAIT_2`` state to be closed and recycled more rapidly - Disable :ref:`CONFIG_LWIP_IPV6` can save about 39 KB for firmware size and 2KB RAM when system power up and 7KB RAM when TCPIP stack running. If there is no requirement for supporting IPV6 then it can be disabled to save flash and RAM footprint. If using Wi-Fi, please also refer to :ref:`wifi-buffer-usage`.