From: Roy Marples Date: Thu, 19 Jun 2025 10:28:58 +0000 (+0100) Subject: DHCP: In the IP header set TTL of 128 and TOS to low delay X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c2058b02e94ef6d2306c4108c8c7d705747e5cc;p=thirdparty%2Fdhcpcd.git DHCP: In the IP header set TTL of 128 and TOS to low delay 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 --- diff --git a/src/dhcp.c b/src/dhcp.c index 637f5a86..37ef48af 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -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) diff --git a/src/dhcp.h b/src/dhcp.h index e8c2a1e3..1f755220 100644 --- a/src/dhcp.h +++ b/src/dhcp.h @@ -45,6 +45,10 @@ #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