]> The Tcpdump Group git mirrors - tcpdump/commitdiff
DHCP: Fix printing IP address pairs options
authorFrancois-Xavier Le Bail <[email protected]>
Sat, 22 Mar 2025 09:53:34 +0000 (10:53 +0100)
committerFrancois-Xavier Le Bail <[email protected]>
Sun, 23 Mar 2025 09:04:36 +0000 (10:04 +0100)
'p' is used by the options Policy Filter (21) and Static Route (33).
They have a minimum length of 8 and the length MUST be a multiple of 8.
Check that.

Add a test file for option 33 (lengths: 8, 16, 24, 3, 0), build with
scapy.

(cherry picked from commit a4508ee9abc27eb8e08191a206fb57edd8996273)

print-bootp.c
tests/TESTLIST
tests/dhcp-option-33.out [new file with mode: 0644]
tests/dhcp-option-33.pcap [new file with mode: 0644]

index 10f4280cc69f913302dd880e0821e80772cd66db..10048b4e53a3c5ffc82853ecf4af17c8673c1335 100644 (file)
@@ -703,6 +703,14 @@ rfc1048_print(netdissect_options *ndo,
 
                case 'p':
                        /* IP address pairs */
+                       /* this option should be N x 8 bytes long */
+                       if (len < 8 || len % 8 != 0) {
+                               ND_PRINT("%s[length != N x 8 bytes]",
+                                        len == 0 ? " " : "");
+                               bp += len;
+                               len = 0;
+                               break;
+                       }
                        while (len >= 2*4) {
                                if (!first)
                                        ND_PRINT(",");
index 827aeba2a3f01cfc8fe89aaf343d68cf7d2b2727..b5dd42c2c1c6b5142422ac121fb6878e696e38d4 100644 (file)
@@ -451,6 +451,7 @@ dhcp-rfc3004        dhcp-rfc3004.pcap       dhcp-rfc3004-v.out      -v
 dhcp-rfc4388   dhcp-rfc4388.pcap       dhcp-rfc4388.out        -v
 dhcp-rfc5859   dhcp-rfc5859.pcap       dhcp-rfc5859-v.out      -v
 dhcp-mud       dhcp-mud.pcap           dhcp-mud.out    -vv
+dhcp-option-33 dhcp-option-33.pcap     dhcp-option-33.out      -vvv
 
 # VXLAN tests
 vxlan  vxlan.pcap  vxlan.out -e
diff --git a/tests/dhcp-option-33.out b/tests/dhcp-option-33.out
new file mode 100644 (file)
index 0000000..cd772e7
--- /dev/null
@@ -0,0 +1,60 @@
+    1  2025-03-22 09:05:13.138257 IP (tos 0x0, ttl 64, id 1, offset 0, flags [none], proto UDP (17), length 294)
+    192.168.1.1.67 > 255.255.255.255.68: [udp sum ok] BOOTP/DHCP, Reply, length 266, xid 0x12345678, Flags [none] (0x0000)
+         Your-IP 192.168.1.100
+         Server-IP 192.168.1.1
+         Client-Ethernet-Address 00:11:22:33:44:55
+         Vendor-rfc1048 Extensions
+           Magic Cookie 0x63825363
+           DHCP-Message (53), length 1: Offer
+           Server-ID (54), length 4: 192.168.1.1
+           Lease-Time (51), length 4: 86400
+           Static-Route (33), length 8: (10.0.0.1:10.0.0.2)
+           END (255), length 0
+    2  2025-03-22 09:05:13.141437 IP (tos 0x0, ttl 64, id 1, offset 0, flags [none], proto UDP (17), length 302)
+    192.168.1.1.67 > 255.255.255.255.68: [udp sum ok] BOOTP/DHCP, Reply, length 274, xid 0x12345678, Flags [none] (0x0000)
+         Your-IP 192.168.1.100
+         Server-IP 192.168.1.1
+         Client-Ethernet-Address 00:11:22:33:44:55
+         Vendor-rfc1048 Extensions
+           Magic Cookie 0x63825363
+           DHCP-Message (53), length 1: Offer
+           Server-ID (54), length 4: 192.168.1.1
+           Lease-Time (51), length 4: 86400
+           Static-Route (33), length 16: (10.0.0.1:10.0.0.2),(10.0.0.3:10.0.0.4)
+           END (255), length 0
+    3  2025-03-22 09:05:13.144047 IP (tos 0x0, ttl 64, id 1, offset 0, flags [none], proto UDP (17), length 310)
+    192.168.1.1.67 > 255.255.255.255.68: [udp sum ok] BOOTP/DHCP, Reply, length 282, xid 0x12345678, Flags [none] (0x0000)
+         Your-IP 192.168.1.100
+         Server-IP 192.168.1.1
+         Client-Ethernet-Address 00:11:22:33:44:55
+         Vendor-rfc1048 Extensions
+           Magic Cookie 0x63825363
+           DHCP-Message (53), length 1: Offer
+           Server-ID (54), length 4: 192.168.1.1
+           Lease-Time (51), length 4: 86400
+           Static-Route (33), length 24: (10.0.0.1:10.0.0.2),(10.0.0.3:10.0.0.4),(10.0.0.5:10.0.0.6)
+           END (255), length 0
+    4  2025-03-22 09:05:13.146056 IP (tos 0x0, ttl 64, id 1, offset 0, flags [none], proto UDP (17), length 289)
+    192.168.1.1.67 > 255.255.255.255.68: [udp sum ok] BOOTP/DHCP, Reply, length 261, xid 0x12345678, Flags [none] (0x0000)
+         Your-IP 192.168.1.100
+         Server-IP 192.168.1.1
+         Client-Ethernet-Address 00:11:22:33:44:55
+         Vendor-rfc1048 Extensions
+           Magic Cookie 0x63825363
+           DHCP-Message (53), length 1: Offer
+           Server-ID (54), length 4: 192.168.1.1
+           Lease-Time (51), length 4: 86400
+           Static-Route (33), length 3: [length != N x 8 bytes]
+           END (255), length 0
+    5  2025-03-22 09:05:13.148070 IP (tos 0x0, ttl 64, id 1, offset 0, flags [none], proto UDP (17), length 286)
+    192.168.1.1.67 > 255.255.255.255.68: [udp sum ok] BOOTP/DHCP, Reply, length 258, xid 0x12345678, Flags [none] (0x0000)
+         Your-IP 192.168.1.100
+         Server-IP 192.168.1.1
+         Client-Ethernet-Address 00:11:22:33:44:55
+         Vendor-rfc1048 Extensions
+           Magic Cookie 0x63825363
+           DHCP-Message (53), length 1: Offer
+           Server-ID (54), length 4: 192.168.1.1
+           Lease-Time (51), length 4: 86400
+           Static-Route (33), length 0 [length != N x 8 bytes]
+           END (255), length 0
diff --git a/tests/dhcp-option-33.pcap b/tests/dhcp-option-33.pcap
new file mode 100644 (file)
index 0000000..9f82bfa
Binary files /dev/null and b/tests/dhcp-option-33.pcap differ