From 90811d9656076796557f47749815f2eb3157c0cc Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Thu, 19 Jun 2025 10:15:20 +0100 Subject: [PATCH] DHCP: Put the message type option first There is no ordering requirement from any RFC other than the recommendations in RFC 7844. But it seems some DHCP servers really want the message type as the first option. Fixes #511. --- src/dhcp.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/dhcp.c b/src/dhcp.c index 637f5a86..c4de0e4f 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -894,8 +894,20 @@ make_message(struct bootp **bootpm, const struct interface *ifp, uint8_t type) p += 4; \ } while (0 /* CONSTCOND */) - /* Options are listed in numerical order as per RFC 7844 Section 3.1 - * XXX: They should be randomised. */ + /* + * RFC 7844 3.1 says options should be randomised, but if not + * then in numerical order. + * RFC 2131 makes no mention of any ordering requirement by the client. + * RFC 2132 says this about the Parameter Request List option: + * The client MAY list the options in order of preference. + * + * Some DHCP servers sadly ignore this and require message type first. + */ + + AREA_CHECK(3); + *p++ = DHO_MESSAGETYPE; + *p++ = 1; + *p++ = type; bool putip = false; if (lease->addr.s_addr && lease->cookie == htonl(MAGIC_COOKIE)) { @@ -910,11 +922,6 @@ make_message(struct bootp **bootpm, const struct interface *ifp, uint8_t type) } } - AREA_CHECK(3); - *p++ = DHO_MESSAGETYPE; - *p++ = 1; - *p++ = type; - if (lease->addr.s_addr && lease->cookie == htonl(MAGIC_COOKIE)) { if (type == DHCP_RELEASE || putip) { if (lease->server.s_addr) -- 2.47.2