]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
DHCP: Put the message type option first dhcp_option_order
authorRoy Marples <roy@marples.name>
Thu, 19 Jun 2025 09:15:20 +0000 (10:15 +0100)
committerRoy Marples <roy@marples.name>
Thu, 19 Jun 2025 09:15:20 +0000 (10:15 +0100)
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

index 637f5a86aa6f1b119997c7bb91a768d65b10cbef..c4de0e4f08dc7349e0bc537bb4d401394972ece0 100644 (file)
@@ -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)