dhcp: fix buffer length after adding new option 72/41272/2
authorArtem Glazychev <[email protected]>
Wed, 17 Jul 2024 09:48:45 +0000 (16:48 +0700)
committerMatthew Smith <[email protected]>
Wed, 23 Oct 2024 13:44:09 +0000 (13:44 +0000)
The size of dhcp option should be o.length + 2 additional bytes of the header.
Incorrect offset results in an extra byte at the end of the packet:
...
0120  04 00 00 00 04 05 04 AC 10 04 01 FF 00
...
RFC2131 says the last should be the 'end' option (ff)

Type: fix

Change-Id: I056d755d29465aab8c1c55a0b930f65ece6fafce
Signed-off-by: Artem Glazychev <[email protected]>
src/plugins/dhcp/dhcp4_proxy_node.c
test/test_dhcp.py

index 2b49d49..740ae80 100644 (file)
@@ -321,7 +321,8 @@ dhcp_proxy_to_server_input (vlib_main_t * vm,
                  o->length += id_len + 5;
                }
 
-             len = o->length + 3;
+             /* 2 bytes for option header 82+len */
+             len = o->length + 2;
              b0->current_length += len;
              /* Fix IP header length and checksum */
              old_l0 = ip0->length;
index e668b7b..15af323 100644 (file)
@@ -327,6 +327,9 @@ class TestDHCP(VppTestCase):
                     is_discover = True
         self.assertTrue(is_discover)
 
+        # The last option must always be the 'end' option
+        self.assertEqual(dhcp.options[-1], "end")
+
         data = self.validate_relay_options(
             pkt, src_intf, src_intf.local_ip4, vpn_id, fib_id, oui
         )