]> granicus.if.org Git - esp-idf/commitdiff
dhcpserver: Option to change lease time multiplier and number of max
authorKrzysztof Bociurko <git@chanibal.pl>
Tue, 31 Oct 2017 18:13:04 +0000 (19:13 +0100)
committerAngus Gratton <gus@projectgus.com>
Tue, 28 Nov 2017 04:58:03 +0000 (15:58 +1100)
stations connected to it.

Merges: https://github.com/espressif/esp-idf/pull/1206

components/lwip/Kconfig
components/lwip/apps/dhcpserver.c
components/lwip/include/lwip/apps/dhcpserver.h

index 8c52706f23887965736562aa8ccd1cc4e7bf1ef1..a0b947863eb906c398c9a468ac97dc9e55d4d342 100644 (file)
@@ -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
index 7062b4456edf79e0c79d4a219a21cc940d8555cd..af55fa9d0e5873ab57fdbd0f6924ce3c43b2aa54 100644 (file)
@@ -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);
index 943f02a917119299e26fbd5145a36861a2598a88..015ffe6e0987d627973e213d9e0644d7173df522 100644 (file)
@@ -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;