espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.81k stars 7.32k forks source link

Question relates to `DHCPS_LEASE_UNIT` option and how to change the dhcp server lease time. (IDFGH-13342) #14258

Open wuyuanyi135 opened 3 months ago

wuyuanyi135 commented 3 months ago

Answers checklist.

General issue report

DHCPS_LEASE_UNIT was defined in https://github.com/espressif/esp-idf/blob/bdb9f972c6a1f1c5ca50b1be2e7211ec7c24e881/components/lwip/include/apps/dhcpserver/dhcpserver.h#L68 DHCPS_LEASE_UNIT's usage: https://github.com/espressif/esp-idf/blob/bdb9f972c6a1f1c5ca50b1be2e7211ec7c24e881/components/lwip/apps/dhcpserver/dhcpserver.c#L429-L432

It seems the configured dhcps->dhcps_lease_time was multiplied by a factor when offering. Wouldn't this cause mismatch of the LWIP DHCP pool retention time and the client lease time? i.e., LWIP only offers 5 minutes of lease but the client was told the lease time is 300 minutes.


If I want to change the default lease time, what is the correct way?

  1. call esp_netif_dhcps_option

    uint32_t dhcp_lease_time = 864000;
    esp_netif_dhcps_option(usb_netif, ESP_NETIF_OP_SET, ESP_NETIF_IP_ADDRESS_LEASE_TIME, &dhcp_lease_time, sizeof(dhcp_lease_time));
  2. idf.py menuconfig and set LWIP_DHCPS_LEASE_UNIT to 7200 (because the default lease time is 120, 864000/120 ==7200)


P.S. The description of LWIP_DHCPS_LEASE_UNIT is not very clear to me:

 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.

what is the sent and received times?

wuyuanyi135 commented 3 months ago

According to the FAQ, the unit of ESP_NETIF_IP_ADDRESS_LEASE_TIME is minute. I will stick to this method. But it does not answer whether the dhcp server and client would having different lease time.