I'm using ESP-IF v4.1
I have noticed that the Lwip DHCP server is allocating an IP address that is already allocated to another device.
I have run Wireshark on my device configured as both a DHCP server with other clients, and as DHCP Client with another DHCP server on the network. When running tests with my ESP32 device as a DHCP client with other DHCP Server sources, I see the DHCP Servers sending an ARP (Who has x.x.x.x? Tell y.y.y.y) request to test if the IP address it is about to offer is in use.
I've even looked at buildroot's udhcpd source code and it does an ARP request before offering an IP address by DHCP.
Is there a configuration option in the ESP-IF dhcpserver that I can set to make the DHCP server check for the existence of an IP address before making an offer or is this a bug in the ESP-IF?
ESP-IF DHCP Server Does Not Check if IP Address is Already in Use Before Offering a Lease
Re: ESP-IF DHCP Server Does Not Check if IP Address is Already in Use Before Offering a Lease
Yes, ESP-IDF indeed has this problem. This is an known issue and we will fix this in future release version.
Re: ESP-IF DHCP Server Does Not Check if IP Address is Already in Use Before Offering a Lease
I've encountered a similar problem.
I have two instances of my ESP-IDF app, one running as esp-netif DHCP server and one running as DHCP client. The instance running as client is correctly sending a DHCP Decline when it realises the IP address is already in use. However when the DHCP client performs another 'DORA' request, the DHCP server is offering the same IP address again. It should be picking another one from the pool.
The lwip apps dhcpserver isn't handling a DHCP decline in the way I would expect.
The same issue occurs when my desktop PC DHCP client requests an IP address and it declines it because it realises it is in use.
Is this a known issue? If so has it been fixed?
I have two instances of my ESP-IDF app, one running as esp-netif DHCP server and one running as DHCP client. The instance running as client is correctly sending a DHCP Decline when it realises the IP address is already in use. However when the DHCP client performs another 'DORA' request, the DHCP server is offering the same IP address again. It should be picking another one from the pool.
The lwip apps dhcpserver isn't handling a DHCP decline in the way I would expect.
The same issue occurs when my desktop PC DHCP client requests an IP address and it declines it because it realises it is in use.
Is this a known issue? If so has it been fixed?
Re: ESP-IF DHCP Server Does Not Check if IP Address is Already in Use Before Offering a Lease
Hello,
I've produced a fix to your dhcpserver.c which is solving my perpetual DHCPS address lease and decline issue. This code (diff below) increments the offered IP address when a Decline is received to an already ACKed IP address lease.
[Codebox]
[/Codebox]
Regards,
Peter
I've produced a fix to your dhcpserver.c which is solving my perpetual DHCPS address lease and decline issue. This code (diff below) increments the offered IP address when a Decline is received to an already ACKed IP address lease.
[Codebox]
- diff --git a/components/lwip/apps/dhcpserver/dhcpserver.c b/components/lwip/apps/dhcpserver/dhcpserver.c
- index 8a4bc00bb..d93b823aa 100644
- --- a/components/lwip/apps/dhcpserver/dhcpserver.c
- +++ b/components/lwip/apps/dhcpserver/dhcpserver.c
- @@ -782,16 +782,16 @@ static u8_t parse_options(u8_t *optptr, s16_t len)
- break;
- case DHCPDECLINE://4
- - s.state = DHCPS_STATE_IDLE;
- + s.state = DHCPS_STATE_DECLINE;
- #if DHCPS_DEBUG
- - DHCPS_LOG("dhcps: DHCPD_STATE_IDLE\n");
- + DHCPS_LOG("dhcps: DHCPS_STATE_DECLINE\n");
- #endif
- break;
- case DHCPRELEASE://7
- s.state = DHCPS_STATE_RELEASE;
- #if DHCPS_DEBUG
- - DHCPS_LOG("dhcps: DHCPD_STATE_IDLE\n");
- + DHCPS_LOG("dhcps: DHCPD_STATE_RELEASE\n");
- #endif
- break;
- }
- @@ -913,7 +913,7 @@ POOL_CHECK:
- s16_t ret = parse_options(&m->options[4], len);;
- - if (ret == DHCPS_STATE_RELEASE || ret == DHCPS_STATE_NAK) {
- + if (ret == DHCPS_STATE_RELEASE || ret == DHCPS_STATE_NAK || ret == DHCPS_STATE_DECLINE) {
- if (pnode != NULL) {
- node_remove_from_list(&plist, pnode);
- free(pnode);
- @@ -926,6 +926,34 @@ POOL_CHECK:
- }
- memset(&client_address, 0x0, sizeof(client_address));
- +
- + if(ret == DHCPS_STATE_DECLINE)
- + {
- + // IP address is in use increment the start ip address
- + // of the pool of free addresses.
- + addr_tmp.addr = htonl(dhcps_poll.start_ip.addr);
- + addr_tmp.addr++;
- + dhcps_poll.start_ip.addr = htonl(addr_tmp.addr);
- +
- +#if DHCPS_DEBUG
- + DHCPS_LOG("IP address declined. DHCPS pool is now %x to %x\n",
- + dhcps_poll.start_ip.addr,
- + dhcps_poll.end_ip.addr);
- +#endif
- +
- + if(dhcps_poll.start_ip.addr == dhcps_poll.end_ip.addr)
- + {
- + addr_tmp.addr = htonl(server_address.addr);
- + addr_tmp.addr++;
- + dhcps_poll.start_ip.addr = htonl(addr_tmp.addr);
- +
- +#if DHCPS_DEBUG
- + DHCPS_LOG("Exhausted ip address pool. Start afresh from %x to %x\n",
- + dhcps_poll.start_ip.addr,
- + dhcps_poll.end_ip.addr);
- +#endif
- + }
- + }
- }
- #if DHCPS_DEBUG
Regards,
Peter
Who is online
Users browsing this forum: axellin, Bing [Bot] and 91 guests