netutils/dhcpc: Send the REQUEST before using the offered address. - #3806
Open
ErikkEnglund wants to merge 2 commits into
Open
ErikkEnglund wants to merge 2 commits into
ErikkEnglund wants to merge 2 commits into
Conversation
dhcpc_request() assigned the offered address to the interface as soon as the OFFER arrived, so that it could receive a unicast ACK. The REQUEST then went out with the offered address as IP source, while RFC 2131 section 4.1 requires 0.0.0.0 until the server has assigned the address. Some routers treat such a client as one with a static address; TP-Link Deco mesh routers, for example, list it as offline and do not offer address reservation for it. Send each REQUEST from the address the interface had before and only then use the offered address while waiting for the ACK, so unicast ACKs are still received. Also restore the old address when no ACK arrives instead of leaving the unconfirmed offered address in place. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Erik Englund <erik.englund@gmail.com>
Comment indentation in dhcpc_parseoptions() and missing blank lines after declarations. No functional change. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Erik Englund <erik.englund@gmail.com>
xiaoxiang781216
approved these changes
Oct 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: Please adhere to Contributing Guidelines.
Summary
dhcpc_request()assigned the offered address to the interface as soon as the OFFER arrived, so that it could receive a unicast ACK. As a side effect the REQUEST went out with the offered address as IP source. RFC 2131 section 4.1 says:and the client only obtains the address with the DHCPACK (section 3.1, step 5).
Most servers accept the REQUEST anyway, but some routers treat such a client as one with a statically configured address. A TP-Link Deco mesh router, for example, lists the device as offline and does not offer address reservation for it, even though it serves the lease.
This PR:
dhcpc.cin a separate commit (no functional change).Setting
CONFIG_NETUTILS_DHCPC_BOOTP_FLAGS=0x8000and not using the offered address at all would also avoid the wrong source address, but then the OFFER and ACK are broadcast, and broadcast frames on Wi-Fi are not retransmitted. In testing that made DHCP noticeably less reliable (see below), so this change keeps the unicast ACK.Impact
dhcpc_request()(netinit,netlib_obtain_ipv4addr(), therenewcommand): the REQUEST is sent from 0.0.0.0 on first configuration, or from the current address when renewing. No API or Kconfig changes.sendto()returning only after the REQUEST has been sent, which holds withoutCONFIG_NET_UDP_WRITE_BUFFERS. With UDP write buffers the REQUEST may still go out from the offered address, i.e. the same behaviour as before this change.Testing
Host: Fedora 44 (Linux 7.2.7, x86_64), xPack riscv-none-elf-gcc 13.2.0-2.
Target: ESP32-C3-DevKitC-02 (ESP32-C3 rev v0.3),
esp32c3-devkit:wifiwith netinit DHCP (CONFIG_NETINIT_DHCPC=y,CONFIG_NETINIT_THREAD=y,CONFIG_NET_UDP_WRITE_BUFFERSnot set), Wi-Fi station on a TP-Link Deco mesh (3 units) that runs the DHCP server.Base: nuttx c046c337c1, nuttx-apps 00b6e59.
DHCP was captured with tcpdump on another host on the same LAN.
Before, at boot: the REQUEST is sent from the offered address. The Deco app lists the device as offline and offers no address reservation.
After, at boot: DISCOVER and REQUEST are sent from 0.0.0.0, the unicast ACK is received and the address configured. The Deco app lists the device as online, and an address reservation could be created for it.
Reliability with this change:
renew wlan010 times in a row: 10/10 succeeded, about 0.1 s each.dhcpc_request()to renew the lease while the interface has its address (REQUEST from the current address) renewed successfully at the T1 time the server sent (3600 s for a 7200 s lease).For comparison, the broadcast-flag-only variant described in the summary:
renew wlan0succeeded 8/10 times, and a boot-time attempt failed with the board never seeing the broadcast OFFER.Not exercised on hardware: the new path that restores the old address when no ACK arrives at all.
tools/nxstylereports no issues fornetutils/dhcpc/dhcpc.cafter the second commit (six pre-existing issues before it).