From 03e3b137bfcc88d521f56be4d0a26c10256215af Mon Sep 17 00:00:00 2001 From: qiyueixa Date: Sun, 22 Jan 2017 20:32:39 +0800 Subject: [PATCH] lwip: optimize the dhcp client 1. modify the discover retry backoff time from (2,4,8,16,32,60,60)s to (500m,1,2,4,8,15,15)s. 2. add DHCP_DOES_ARP_CHECK to menuconfig for users to specify if do a ARP check on the offered address. If enable, one more second will be taken in obtaining IP address. 3. update wifi libs --- components/esp32/lib | 2 +- components/lwip/Kconfig | 7 +++++++ components/lwip/core/ipv4/dhcp.c | 7 ++++++- components/lwip/include/lwip/port/lwipopts.h | 5 +++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/components/esp32/lib b/components/esp32/lib index fc92f2e5b..6e50eb85a 160000 --- a/components/esp32/lib +++ b/components/esp32/lib @@ -1 +1 @@ -Subproject commit fc92f2e5bcd34fa945445e8cad47cbf1f2a4bdb6 +Subproject commit 6e50eb85a07d12ded45d8765fc82bb7ab929e441 diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index f7bae3258..0070ef466 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -82,6 +82,13 @@ config TCP_SYNMAXRTX help Set maximum number of retransmissions of SYN segments. +config LWIP_DHCP_DOES_ARP_CHECK + bool "Enable an ARP check on the offered address" + default 1 + help + Enabling this option allows check if the offered IP address is not already + in use by another host on the network. + endmenu diff --git a/components/lwip/core/ipv4/dhcp.c b/components/lwip/core/ipv4/dhcp.c index 887af91fe..86336d4f7 100755 --- a/components/lwip/core/ipv4/dhcp.c +++ b/components/lwip/core/ipv4/dhcp.c @@ -1029,7 +1029,12 @@ dhcp_discover(struct netif *netif) autoip_start(netif); } #endif /* LWIP_DHCP_AUTOIP_COOP */ - msecs = (dhcp->tries < 6 ? 1 << dhcp->tries : 60) * 1000; + + /* 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. + * Original msecs = (dhcp->tries < 6 ? 1 << dhcp->tries : 60) * 1000; + */ + msecs = (dhcp->tries < 6 ? 1 << dhcp->tries : 60) * 250; dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_discover(): set request timeout %"U16_F" msecs\n", msecs)); return result; diff --git a/components/lwip/include/lwip/port/lwipopts.h b/components/lwip/include/lwip/port/lwipopts.h index 638c1f740..dc8264947 100644 --- a/components/lwip/include/lwip/port/lwipopts.h +++ b/components/lwip/include/lwip/port/lwipopts.h @@ -206,6 +206,11 @@ #define DHCP_MAXRTX 0 +/** + * DHCP_DOES_ARP_CHECK==1: Do an ARP check on the offered address. + */ +#define DHCP_DOES_ARP_CHECK CONFIG_LWIP_DHCP_DOES_ARP_CHECK + /* ------------------------------------ ---------- AUTOIP options ----------