]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-dhcp-relay: fix off-by-one when discarding BOOTREQUEST messages by hops count main
authorhanjinpeng <hanjinpeng@kylinos.cn>
Wed, 8 Jul 2026 07:05:51 +0000 (03:05 -0400)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 14 Jul 2026 23:44:31 +0000 (08:44 +0900)
According to RFC specifications
```
RFC 1542 section 4.1.1 states:
The relay agent MUST silently discard BOOTREQUEST messages whose 'hops'
   field exceeds the value 16."
```

"Exceeds the value 16" means hops > 16, i.e. a message that arrives with
hops == 16 is still valid and must be relayed (after which its hops field
becomes 17). The code used ">= 16", which silently dropped a valid message
that had legitimately traversed exactly 16 relay agents, one hop too early.

This matches the wording of the adjacent comment, which already says
"exceeds the value 16".

src/libsystemd-network/dhcp-relay-downstream.c
src/libsystemd-network/test-dhcp-relay.c

index 5c3311d979aa05709d3a6c0aabc114e3a745d811..eca140a92cf12f7b79dd9946dd78c50f06c869d6 100644 (file)
@@ -303,7 +303,7 @@ int downstream_process_message(
 
         /* RFC 1542 section 4.1.1:
          * The relay agent MUST silently discard BOOTREQUEST messages whose 'hops' field exceeds the value 16. */
-        if (message->header.hops >= 16)
+        if (message->header.hops > 16)
                 return 0;
         message->header.hops++;
 
index 2a7131e59b5a2504fc38f7f43a241fb41c2ae548..74ccbb9dc9da1a3d2371306ecbde96a71c9702a6 100644 (file)
@@ -314,7 +314,7 @@ TEST(forwarding) {
 
         /* Invalid message (too large hops). */
         ASSERT_OK(dhcp_message_append_option_u8(m, SD_DHCP_OPTION_MESSAGE_TYPE, 101));
-        m->header.hops = 16;
+        m->header.hops = 17;
         send_message(downstream_fd[1], m);
         dhcp_message_remove_option(m, SD_DHCP_OPTION_MESSAGE_TYPE);
         m->header.hops = 0;