init: make built-in DHCP client work with gvproxy and vmnet on macOS#598
init: make built-in DHCP client work with gvproxy and vmnet on macOS#598mtjhrc wants to merge 3 commits intocontainers:mainfrom
Conversation
|
/gemini review |
There was a problem hiding this comment.
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.
| * 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 |
There was a problem hiding this comment.
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 MTUaa3537d to
bae9cc7
Compare
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>
bae9cc7 to
65599c6
Compare
There seemed to be 2 issues preventing this from working:
169.254.1.1. This is fixed by usingSO_BINDTODEVICE, which is also much simpler.