From d574382d7b16e9c33eabe896e034c2fd5f6482c2 Mon Sep 17 00:00:00 2001 From: Abhik Roy Date: Mon, 29 Sep 2025 21:26:01 +0800 Subject: [PATCH] feat(lwip): Remove deprecated LWIP_DHCPS_ADD_DNS Kconfig option --- components/lwip/Kconfig | 14 ---------- components/lwip/apps/dhcpserver/dhcpserver.c | 17 +++++++---- .../release-6.x/6.0/networking.rst | 28 +++++++++++++++++++ .../release-6.x/6.0/networking.rst | 28 +++++++++++++++++++ 4 files changed, 67 insertions(+), 20 deletions(-) diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index 94f54f23e5..ae6bf83e69 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -452,20 +452,6 @@ 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 diff --git a/components/lwip/apps/dhcpserver/dhcpserver.c b/components/lwip/apps/dhcpserver/dhcpserver.c index 727bc5ec35..929af5e520 100644 --- a/components/lwip/apps/dhcpserver/dhcpserver.c +++ b/components/lwip/apps/dhcpserver/dhcpserver.c @@ -468,27 +468,32 @@ static u8_t *add_offer_options(dhcps_t *dhcps, u8_t *optptr) } } - // In order of preference - if (dhcps_dns_enabled(dhcps->dhcps_dns)) { - uint8_t size = 4; + // Add DNS option if either main or backup DNS is set + if (dhcps_dns_enabled(dhcps->dhcps_dns) && + (dhcps->dns_server[DNS_TYPE_MAIN].addr || dhcps->dns_server[DNS_TYPE_BACKUP].addr)) { + uint8_t size = 0; + + if (dhcps->dns_server[DNS_TYPE_MAIN].addr) { + size += 4; + } if (dhcps->dns_server[DNS_TYPE_BACKUP].addr) { size += 4; } *optptr++ = DHCP_OPTION_DNS_SERVER; *optptr++ = size; - optptr = dhcps_option_ip(optptr, &dhcps->dns_server[DNS_TYPE_MAIN]); + if (dhcps->dns_server[DNS_TYPE_MAIN].addr) { + optptr = dhcps_option_ip(optptr, &dhcps->dns_server[DNS_TYPE_MAIN]); + } if (dhcps->dns_server[DNS_TYPE_BACKUP].addr) { optptr = dhcps_option_ip(optptr, &dhcps->dns_server[DNS_TYPE_BACKUP]); } -#ifdef CONFIG_LWIP_DHCPS_ADD_DNS } else { *optptr++ = DHCP_OPTION_DNS_SERVER; *optptr++ = 4; optptr = dhcps_option_ip(optptr, &ipadd); -#endif /* CONFIG_LWIP_DHCPS_ADD_DNS */ } ip4_addr_t broadcast_addr = { .addr = (ipadd.addr & dhcps->dhcps_mask.addr) | ~dhcps->dhcps_mask.addr }; diff --git a/docs/en/migration-guides/release-6.x/6.0/networking.rst b/docs/en/migration-guides/release-6.x/6.0/networking.rst index c69a73e483..264ed6c7bb 100644 --- a/docs/en/migration-guides/release-6.x/6.0/networking.rst +++ b/docs/en/migration-guides/release-6.x/6.0/networking.rst @@ -108,3 +108,31 @@ Alternative (find with predicate): if (target) { // use "target" } + + +DHCP Server DNS Option Behavior +------------------------------- + +The ``LWIP_DHCPS_ADD_DNS`` macro has been removed. + +Previously, when running a DHCP server on SoftAP, if no DNS offer option was set, the server IP address was automatically advertised as the DNS server. + +**Current behavior:** + +From this release onward, the DHCP server includes DNS information in its offers only when explicitly configured using :cpp:func:`esp_netif_dhcps_option` with the ``ESP_NETIF_DOMAIN_NAME_SERVER`` option. In that case, the currently configured main and/or backup DNS addresses for the SoftAP interface are sent to clients. + +If the option is not enabled, the DHCP server's own IP address is sent as the DNS server, which preserves the previous default behavior. + +**Migration:** + +If applications rely on custom DNS settings, developers should: + +1. Enable the DHCP server to include DNS information in its offers using :cpp:func:`esp_netif_dhcps_option` with the ``ESP_NETIF_DOMAIN_NAME_SERVER`` option. +2. Configure one or more DNS server addresses for the SoftAP interface using :cpp:func:`esp_netif_set_dns_info`. +3. If no DNS information should be sent at all, configure :cpp:func:`esp_netif_dhcps_option` but set the DNS server address to ``0.0.0.0`` using :cpp:func:`esp_netif_set_dns_info`. + +This allows developers to: + +- replicate the old behavior (advertising the SoftAP IP), +- provide custom DNS servers (for example, public resolvers), or +- suppress DNS information entirely by setting the DNS server to ``0.0.0.0``. diff --git a/docs/zh_CN/migration-guides/release-6.x/6.0/networking.rst b/docs/zh_CN/migration-guides/release-6.x/6.0/networking.rst index 9ff614307d..a6a53a0aaf 100644 --- a/docs/zh_CN/migration-guides/release-6.x/6.0/networking.rst +++ b/docs/zh_CN/migration-guides/release-6.x/6.0/networking.rst @@ -108,3 +108,31 @@ ESP-NETIF if (target) { // 使用 "target" } + + +DHCP 服务器 DNS 选项行为 +------------------------- + +``LWIP_DHCPS_ADD_DNS`` 宏已被移除。 + +在此之前,在 SoftAP 上运行 DHCP 服务器时,如果没有设置 DNS 选项,则服务器的 IP 地址会被自动公布为 DNS 服务器。 + +**当前行为:** + +从本版本开始,DHCP 服务器只有在显式配置了 :cpp:func:`esp_netif_dhcps_option` 并启用了 ``ESP_NETIF_DOMAIN_NAME_SERVER`` 选项时,才会在 DHCP offer 报文中包含 DNS 信息。此时,SoftAP 接口当前配置的主 DNS 和/或备用 DNS 地址将被发送给客户端。 + +如果没有启用该选项,DHCP 服务器会将自己的 IP 地址作为 DNS 服务器发送给客户端,从而与之前的默认行为保持一致。 + +**迁移说明:** + +如果应用程序依赖自定义 DNS 设置,开发者应: + +1. 使用 :cpp:func:`esp_netif_dhcps_option` 并启用 ``ESP_NETIF_DOMAIN_NAME_SERVER`` 选项,让 DHCP 服务器在 offer 报文中包含 DNS 信息。 +2. 使用 :cpp:func:`esp_netif_set_dns_info` 为 SoftAP 接口配置一个或多个 DNS 服务器地址。 +3. 若需完全禁止发送 DNS 信息,仍需配置 :cpp:func:`esp_netif_dhcps_option`,但应通过 :cpp:func:`esp_netif_set_dns_info` 将 DNS 服务器地址设置为 ``0.0.0.0``。 + +这样开发者可以: + +- 复现旧的行为(通告 SoftAP IP), +- 提供自定义的 DNS 服务器(例如公共解析器), +- 通过将 DNS 地址设置为 ``0.0.0.0`` 来完全禁止 DNS 信息通告。