Skip to content

init: make built-in DHCP client work with gvproxy and vmnet on macOS#598

Draft
mtjhrc wants to merge 3 commits intocontainers:mainfrom
mtjhrc:extend-dhcp-support
Draft

init: make built-in DHCP client work with gvproxy and vmnet on macOS#598
mtjhrc wants to merge 3 commits intocontainers:mainfrom
mtjhrc:extend-dhcp-support

Conversation

@mtjhrc
Copy link
Copy Markdown
Collaborator

@mtjhrc mtjhrc commented Mar 23, 2026

There seemed to be 2 issues preventing this from working:

  • the source IP of the packets should be 0.0.0.0 not 169.254.1.1. This is fixed by using SO_BINDTODEVICE, which is also much simpler.
  • Implement fallback if DHCP server doesn't support Rapid Commit

@mtjhrc
Copy link
Copy Markdown
Collaborator Author

mtjhrc commented Mar 23, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new standalone DHCP client implementation in init/dhcp.c and init/dhcp.h. The init.c file is updated to use this DHCP client to configure the eth0 interface if it exists, bringing it up first. The build script src/devices/build.rs has been modified to include the new DHCP source and header files in the build process. Feedback includes making the failure to open /etc/resolv.conf a critical error, enhancing netlink error messages with strerror output, and updating the do_dhcp function's documentation to reflect current implementation details.

Comment on lines +40 to +48
* 1. Sets up a temporary link-local address (169.254.1.1/16)
* 2. Sends a DHCP DISCOVER message with Rapid Commit option
* 3. Waits up to 100ms for a DHCP ACK response
* 4. Parses the response and configures:
* - IPv4 address with appropriate prefix length
* - Default gateway route
* - DNS servers (overwriting /etc/resolv.conf)
* - Interface MTU
* 5. Cleans up temporary configuration
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The documentation for do_dhcp is out of date. It mentions setting up and cleaning up a temporary link-local address, but the implementation was changed to use SO_BINDTODEVICE instead. The comment should be updated to accurately reflect the function's current behavior.

 * 1. Sends a DHCP DISCOVER message with the Rapid Commit option.
 * 2. Waits for a DHCP response (ACK or OFFER). If an OFFER is received, it
 *    completes the 4-way handshake by sending a REQUEST.
 * 3. Parses the final DHCP ACK and configures:
 *    - IPv4 address with appropriate prefix length
 *    - Default gateway route
 *    - DNS servers (overwriting /etc/resolv.conf)
 *    - Interface MTU

@mtjhrc mtjhrc force-pushed the extend-dhcp-support branch from aa3537d to bae9cc7 Compare March 23, 2026 17:32
@mtjhrc mtjhrc changed the title init: make built-in DHCP client with gvproxy and vmnet on macOS init: make built-in DHCP client work with gvproxy and vmnet on macOS Mar 23, 2026
slp and others added 3 commits March 23, 2026 19:22
If there's a eth0 interface present, configure it with DHCP.

Signed-off-by: Sergio Lopez <slp@redhat.com>
Replace the temporary link-local address (169.254.1.1) workaround with
SO_BINDTODEVICE.

The temp address caused the kernel to use 169.254.1.1 as the source IP in DHCP
packets; gvproxy then tried to reply to that address and failed with
"no route to host". With this change the source IP should be 0.0.0.0, which is
what RFC 2131 requires for DHCPDISCOVER.

Signed-off-by: Matej Hrica <mhrica@redhat.com>
When a server answers DHCPDISCOVER with DHCPOFFER instead of an immediate ACK,
send DHCPREQUEST for the and wait for the final ACK.

This makes DHCP work on macOS hosts when using gvproxy for networking.

Signed-off-by: Matej Hrica <mhrica@redhat.com>
@mtjhrc mtjhrc force-pushed the extend-dhcp-support branch from bae9cc7 to 65599c6 Compare March 23, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants