From: Roy Marples Date: Thu, 19 Jun 2025 09:15:20 +0000 (+0100) Subject: DHCP: Put the message type option first X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fdhcp_option_order;p=thirdparty%2Fdhcpcd.git 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. --- 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)