Skip to content

Commit

Permalink
fix(lwip/dhcps): Fallback DNS option to DHCP server's IP by default
Browse files Browse the repository at this point in the history
Adds backward compatibity option CONFIG_LWIP_DHCPS_ADD_DNS, which
prevents breaking changes.
This option should be removed in IDF v6.0

Merges #14132
  • Loading branch information
david-cermak authored and espressif-abhikroy committed Oct 7, 2024
1 parent 484a2d6 commit 649816d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions components/lwip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,20 @@ menu "LWIP"
Enabling this option allows DHCP server to support temporary static ARP entries
for DHCP Client. This will help the DHCP server to send the DHCP OFFER and DHCP ACK using IP unicast.

config LWIP_DHCPS_ADD_DNS
bool "Always add DNS option in DHCP responses"
default y
depends on LWIP_DHCPS
help
This allows the DNS option to be optional in the DHCP offers,
depending on the server's runtime configuration.
When enabled, the DHCP server will always add the DNS option to DHCP responses.
If a DNS server is not explicitly configured, the server's IP address will be used
as the fallback for the DNS option.
When disabled, the DHCP server will only include the DNS option in responses
if a DNS server has been explicitly configured.
This option will be removed in IDF v6.x

endmenu # DHCPS

menuconfig LWIP_AUTOIP
Expand Down
9 changes: 9 additions & 0 deletions components/lwip/apps/dhcpserver/dhcpserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,15 @@ static u8_t *add_offer_options(dhcps_t *dhcps, u8_t *optptr)
*optptr++ = ip4_addr2(&dhcps->dns_server);
*optptr++ = ip4_addr3(&dhcps->dns_server);
*optptr++ = ip4_addr4(&dhcps->dns_server);
#ifdef CONFIG_LWIP_DHCPS_ADD_DNS
}else {
*optptr++ = DHCP_OPTION_DNS_SERVER;
*optptr++ = 4;
*optptr++ = ip4_addr1(&ipadd);
*optptr++ = ip4_addr2(&ipadd);
*optptr++ = ip4_addr3(&ipadd);
*optptr++ = ip4_addr4(&ipadd);
#endif /* CONFIG_LWIP_DHCPS_ADD_DNS */
}

ip4_addr_t broadcast_addr = { .addr = (ipadd.addr & dhcps->dhcps_mask.addr) | ~dhcps->dhcps_mask.addr };
Expand Down

0 comments on commit 649816d

Please sign in to comment.