A minor rework compared to v2, addressing Daniel's comments on the list. The former patch 2/9 has been split up to first refactor the parse_dhcp_vendor() function, then later introduce the OVERLOAD functionality. The other minor nits should be fixed as well, also I added Daniel's Reviewed-by: tags. Again tested against a modern DHCP-only server and some legacy bootpd version.
Cheers, Andre. Original commit message: ---------------------------------- This patch adds support for native DHCPv4 and removes requirement for BOOTP compatibility support in DHCP server. There is no provision for selecting preferred server. We take the first OFFER and try to REQUEST configuration from it. If NAK was received, transaction is restarted, but if we hit timeout, configuration fails. It also handles pure BOOTP reply (detected by lack of DHCP message type option) and proceeds with configuration immedately. I could not test it because I do not have pure BOOTP server. Because we need access to DHCP options in multiple places now, it also factors out DHCP option processing, adding support for option overload. Timeout handling is now per-interface, with independent timeouts for both DISCOVER and REQUEST. It should make it more responsive if answer was delayed initially. Total timeout remains the same as originally, as well as backoff algorithm, but we poll in fixed 200ms ticks so notice (successful) reply earlier. Failure to send packet to interface now does not terminate command (and leaks memory) but rather simply ignores this interface and continues with remaining ones if present. Finally it adds net_dhcp alias with intention to deprecate net_bootp completely (it would be possible to make net_bootp to actually send BOOTP packet if someone thinks it is required). Features not implements: - DHCP server selection. We take first DHCPOFFER or BOOTPREPLY. No plans to implement. - DHCP option concatenation (RFC3396). I do not expect to hit it in real life and it rather complicates implementation, so let's wait for actual use case. - client identifier (RFC6842). So far we expect valid MAC address, which should be enough to uniquely identify client. It is also not clear how to generate unique client identifier if we ever need one. v2: change find_dhcp_option to use subscripts to avoid signed/unsigned comparison warning. Should fix "may be used uninitialized" warning (although I could not reproduce it). --------- This is a rebased version of Andrei's work from 2016 [1][2][3]. We have still this issue here where our company DHCP server does not support the BOOTP protocol, so grub doesn't get a valid IP address. I took v2 from Andrei of the list, and fixed the minor conflicts during the rebase. I can confirm that this patch makes the difference between DHCP working and not: grub-master> net_bootp error: couldn't autoconfigure efinet0. ... grub-patched> net_bootp grub-patched> net_ls_addr efinet0:dhcp 00:11:22:33:44:55 10.1.23.42 Also back in the days there were concerns about regressing BOOTP-only servers. So I took the CMU bootpd[4], disabled the DHCP extensions at compile time and still got IP addresses in both cases (patched/unpatched). dhclient on Linux on the other hand was not happy with that server and ignored the reply. I guess this is as close to a "BOOTP only server" as we can get in 2019. I would be very happy if we can get this merged now. Please let me know if you need more information or any help on this. Thanks! Andre. P.S. The original patch didn't have a Signed-off-by:, so I kept it that way. Added mine for legal reason, feel free to drop it. [1] http://lists.gnu.org/archive/html/grub-devel/2016-01/msg00035.html [2] http://lists.gnu.org/archive/html/grub-devel/2016-03/msg00276.html [3] http://lists.gnu.org/archive/html/grub-devel/2016-04/msg00066.html [4] https://packages.debian.org/jessie/bootp Andrei Borzenkov (10): net: dhcp: remove dead code net: dhcp: replace parse_dhcp_vendor() with find_dhcp_option() net: dhcp: Allow overloading legacy bootfile and name field net: dhcp: refactor DHCP packet transmission into separate function net: dhcp: make grub_net_process_dhcp take an interface net: dhcp: introduce per-interface timeout net: dhcp: use DHCP options for name and bootfile net: dhcp: allow receiving DHCP OFFER and ACK packets net: dhcp: actually send out DHCPv4 DISCOVER and REQUEST messages net: dhcp: add explicit net_dhcp command grub-core/net/bootp.c | 772 +++++++++++++++++++++++++++++------------- grub-core/net/ip.c | 2 +- include/grub/net.h | 14 +- 3 files changed, 543 insertions(+), 245 deletions(-) -- 2.17.1 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel