]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
DHCP: In the IP header set TTL of 128 and TOS to low delay dhcp_ip
authorRoy Marples <roy@marples.name>
Thu, 19 Jun 2025 10:28:58 +0000 (11:28 +0100)
committerRoy Marples <roy@marples.name>
Thu, 19 Jun 2025 10:28:58 +0000 (11:28 +0100)
And set ID to zero because DHCP cannot be fragmented and the
ID is only for re-assembly of fragmented packets.

This matches the behaviour of other DHCP clients.

Fixes #511

src/dhcp.c
src/dhcp.h

index 637f5a86aa6f1b119997c7bb91a768d65b10cbef..37ef48afbebbfb22068bc5b746fb146b74cbdf9c 100644 (file)
@@ -1786,10 +1786,16 @@ dhcp_makeudppacket(size_t *sz, const uint8_t *data, size_t length,
        ip->ip_len = udp->uh_ulen;
        udp->uh_sum = in_cksum(udpp, sizeof(*ip) + sizeof(*udp) + length, NULL);
 
+       /* RFC 6864 4.1
+        * The IPv4 ID field MUST NOT be used for purposes other than
+        * fragmentation and reassembly.
+        *
+        * DHCP cannot be fragmented.
+        */
        ip->ip_v = IPVERSION;
        ip->ip_hl = sizeof(*ip) >> 2;
-       ip->ip_id = (uint16_t)arc4random_uniform(UINT16_MAX);
-       ip->ip_ttl = IPDEFTTL;
+       ip->ip_tos = DHCP_TOS;
+       ip->ip_ttl = DHCP_TTL;
        ip->ip_len = htons((uint16_t)(sizeof(*ip) + sizeof(*udp) + length));
        ip->ip_sum = in_cksum(ip, sizeof(*ip), NULL);
        if (ip->ip_sum == 0)
index e8c2a1e3962dbac3d5f5269577a421242f0cbd8f..1f7552203650b4a9882f7ad06955e76bcaac237b 100644 (file)
 #include "auth.h"
 #include "dhcp-common.h"
 
+/* IP header values */
+#define DHCP_TTL               128     /* IPDEFTTL of 64 maybe to low */
+#define DHCP_TOS               IPTOS_LOWDELAY /* try to get DHCP fast */
+
 /* UDP port numbers for BOOTP */
 #define BOOTPS                 67
 #define BOOTPC                 68