From 626ad5f5776d44bae8e3831fb1bf10ed4ff84824 Mon Sep 17 00:00:00 2001 From: Krzysztof Bociurko Date: Tue, 31 Oct 2017 19:13:04 +0100 Subject: [PATCH] dhcpserver: Option to change lease time multiplier and number of max stations connected to it. Merges: https://github.com/espressif/esp-idf/pull/1206 --- components/lwip/Kconfig | 22 +++++++++++++++++++ components/lwip/apps/dhcpserver.c | 14 ++++++------ .../lwip/include/lwip/apps/dhcpserver.h | 4 +++- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index 8c52706f2..a0b947863 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -111,6 +111,28 @@ config LWIP_DHCP_DOES_ARP_CHECK Enabling this option performs a check (via ARP request) if the offered IP address is not already in use by another host on the network. +menu "DHCP server" + +config LWIP_DHCPS_LEASE_UNIT + int "Multiplier for lease time, in seconds" + range 1 3600 + default 60 + help + The DHCP server is calculating lease time multiplying the sent + and received times by this number of seconds per unit. + The default is 60, that equals one minute. + +config LWIP_DHCPS_MAX_STATION_NUM + int "Maximum number of stations" + range 1 64 + default 8 + help + The maximum number of DHCP clients that are connected to the server. + After this number is exceeded, DHCP server removes of the oldest device + from it's address pool, without notification. + +endmenu # DHCPS + menuconfig LWIP_AUTOIP bool "Enable IPV4 Link-Local Addressing (AUTOIP)" default n diff --git a/components/lwip/apps/dhcpserver.c b/components/lwip/apps/dhcpserver.c index 7062b4456..af55fa9d0 100644 --- a/components/lwip/apps/dhcpserver.c +++ b/components/lwip/apps/dhcpserver.c @@ -63,7 +63,7 @@ #define DHCPS_DEBUG 0 #define DHCPS_LOG printf -#define MAX_STATION_NUM 8 +#define MAX_STATION_NUM CONFIG_LWIP_DHCPS_MAX_STATION_NUM #define DHCPS_STATE_OFFER 1 #define DHCPS_STATE_DECLINE 2 @@ -311,10 +311,10 @@ static u8_t *add_offer_options(u8_t *optptr) *optptr++ = DHCP_OPTION_LEASE_TIME; *optptr++ = 4; - *optptr++ = ((dhcps_lease_time * 60) >> 24) & 0xFF; - *optptr++ = ((dhcps_lease_time * 60) >> 16) & 0xFF; - *optptr++ = ((dhcps_lease_time * 60) >> 8) & 0xFF; - *optptr++ = ((dhcps_lease_time * 60) >> 0) & 0xFF; + *optptr++ = ((dhcps_lease_time * DHCPS_LEASE_UNIT) >> 24) & 0xFF; + *optptr++ = ((dhcps_lease_time * DHCPS_LEASE_UNIT) >> 16) & 0xFF; + *optptr++ = ((dhcps_lease_time * DHCPS_LEASE_UNIT) >> 8) & 0xFF; + *optptr++ = ((dhcps_lease_time * DHCPS_LEASE_UNIT) >> 0) & 0xFF; *optptr++ = DHCP_OPTION_SERVER_ID; *optptr++ = 4; @@ -800,8 +800,8 @@ static u8_t parse_options(u8_t *optptr, s16_t len) *******************************************************************************/ static s16_t parse_msg(struct dhcps_msg *m, u16_t len) { - u32_t lease_timer = (dhcps_lease_time * 60)/DHCPS_COARSE_TIMER_SECS; - + u32_t lease_timer = (dhcps_lease_time * DHCPS_LEASE_UNIT)/DHCPS_COARSE_TIMER_SECS; + if (memcmp((char *)m->options, &magic_cookie, sizeof(magic_cookie)) == 0) { #if DHCPS_DEBUG DHCPS_LOG("dhcps: len = %d\n", len); diff --git a/components/lwip/include/lwip/apps/dhcpserver.h b/components/lwip/include/lwip/apps/dhcpserver.h index 943f02a91..015ffe6e0 100644 --- a/components/lwip/include/lwip/apps/dhcpserver.h +++ b/components/lwip/include/lwip/apps/dhcpserver.h @@ -14,6 +14,7 @@ #ifndef __DHCPS_H__ #define __DHCPS_H__ +#include "sdkconfig.h" #include "lwip/ip_addr.h" typedef struct dhcps_state{ @@ -50,7 +51,8 @@ enum dhcps_offer_option{ #define DHCPS_COARSE_TIMER_SECS 1 #define DHCPS_MAX_LEASE 0x64 -#define DHCPS_LEASE_TIME_DEF (120) +#define DHCPS_LEASE_TIME_DEF (120) +#define DHCPS_LEASE_UNIT CONFIG_LWIP_DHCPS_LEASE_UNIT struct dhcps_pool{ ip4_addr_t ip;