Skip to content

Commit 4b7065a

Browse files
committed
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 #522.
1 parent 4dd7ebe commit 4b7065a

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/dhcp.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -894,8 +894,20 @@ make_message(struct bootp **bootpm, const struct interface *ifp, uint8_t type)
894894
p += 4; \
895895
} while (0 /* CONSTCOND */)
896896

897-
/* Options are listed in numerical order as per RFC 7844 Section 3.1
898-
* XXX: They should be randomised. */
897+
/*
898+
* RFC 7844 3.1 says options should be randomised, but if not
899+
* then in numerical order.
900+
* RFC 2131 makes no mention of any ordering requirement by the client.
901+
* RFC 2132 says this about the Parameter Request List option:
902+
* The client MAY list the options in order of preference.
903+
*
904+
* Some DHCP servers sadly ignore this and require message type first.
905+
*/
906+
907+
AREA_CHECK(3);
908+
*p++ = DHO_MESSAGETYPE;
909+
*p++ = 1;
910+
*p++ = type;
899911

900912
bool putip = false;
901913
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)
910922
}
911923
}
912924

913-
AREA_CHECK(3);
914-
*p++ = DHO_MESSAGETYPE;
915-
*p++ = 1;
916-
*p++ = type;
917-
918925
if (lease->addr.s_addr && lease->cookie == htonl(MAGIC_COOKIE)) {
919926
if (type == DHCP_RELEASE || putip) {
920927
if (lease->server.s_addr)

0 commit comments

Comments
 (0)