Problem with Option82 sub-options encoding
Hi Alan and FR team, I found a bug in the 3.2.10 version (tried also against built v3.2.x HEAD) concerning Option82 sub-options encoding in the response. - fr_dhcp_encode sorts the reply attributes with fr_dhcp_attr_cmp - fr_dhcp_encode_option writes one Option 82 header and fr_dhcp_vp2data_tlv then packs sub-options only while they are next to each other in the sorted list - any other attribute that sorts between Relay-Circuit-Id and Relay-Remote-Id ends the run, and the next sub-option starts a second Option 82 For example DHCP-Your-IP-Address (attribute 264) is a packet header field, not an option - the encoder skips it, but it sits between the two sub-options, so they go out as two Option 82 instances. Here is a patch to fix it: diff --git a/src/modules/proto_dhcp/dhcp.c b/src/modules/proto_dhcp/dhcp.c index d6dc71446c..adf79d94c7 100644 --- a/src/modules/proto_dhcp/dhcp.c +++ b/src/modules/proto_dhcp/dhcp.c @@ -1245,13 +1245,13 @@ int8_t fr_dhcp_attr_cmp(void const *a, void const *b) * If the attr is a TLV, first compare on the parent */ base_a = my_a->da->flags.is_tlv ? DHCP_BASE_ATTR(my_a->da->attr) : my_a->da->attr; - base_b = my_b->da->flags.is_tlv ? DHCP_BASE_ATTR(my_b->da->attr) : my_a->da->attr; + base_b = my_b->da->flags.is_tlv ? DHCP_BASE_ATTR(my_b->da->attr) : my_b->da->attr; /* * Relay-Agent is last */ if ((base_a == PW_DHCP_OPTION_82) && (base_b != PW_DHCP_OPTION_82)) return +1; - if ((base_a != PW_DHCP_OPTION_82) && (my_b->da->attr == base_b)) return -1; + if ((base_a != PW_DHCP_OPTION_82) && (base_b == PW_DHCP_OPTION_82)) return -1; if (base_a < base_b) return -1; if (base_a > base_b) return 1; diff --git a/src/tests/unit/dhcp.txt b/src/tests/unit/dhcp.txt index 5661604b58..eacf449934 100644 --- a/src/tests/unit/dhcp.txt +++ b/src/tests/unit/dhcp.txt @@ -45,3 +45,7 @@ data 7d 1e 00 00 0d e9 19 01 06 30 30 30 31 39 46 02 0a 52 4e 56 35 30 34 35 39 encode-dhcp DHCP-Relay-Circuit-Id = 0xacdb489f87af, DHCP-DHCP-Maximum-Msg-Size = 1500, DHCP-Vendor-Specific-Information = 0x0000118b060104010203010000061b34030a444d5a2d434f532d3032010e4554492d5250442d504f52542d300207756e69636173740e07000100000079000d040a666f07, DHCP-Client-Identifier = 0xff489f87af00030001acdb489f87af, DHCP-Relay-Remote-Id = 0xacdb489f87af data 39 02 05 dc 3d 0f ff 48 9f 87 af 00 03 00 01 ac db 48 9f 87 af 52 56 01 06 ac db 48 9f 87 af 02 06 ac db 48 9f 87 af 09 44 00 00 11 8b 06 01 04 01 02 03 01 00 00 06 1b 34 03 0a 44 4d 5a 2d 43 4f 53 2d 30 32 01 0e 45 54 49 2d 52 50 44 2d 50 4f 52 54 2d 30 02 07 75 6e 69 63 61 73 74 0e 07 00 01 00 00 00 79 00 0d 04 0a 66 6f 07 + +# Option 82 sub-options must be encoded as ONE option even when the pairs also contain a packet header field (DHCP-Your-IP-Address) +encode-dhcp DHCP-Relay-Remote-Id = 0xacdb489f87b0, DHCP-Domain-Name-Server = 8.8.8.8, DHCP-Router-Address = 10.9.9.1, DHCP-Subnet-Mask = 255.255.255.0, DHCP-TFTP-Server-Name = "tftp.example", DHCP-Your-IP-Address = 10.9.9.50, DHCP-Relay-Circuit-Id = 0xacdb489f87af +data 01 04 ff ff ff 00 03 04 0a 09 09 01 06 04 08 08 08 08 42 0c 74 66 74 70 2e 65 78 61 6d 70 6c 65 52 10 01 06 ac db 48 9f 87 af 02 06 ac db 48 9f 87 b0 Freeradius debug log with a minimal reproducer: --- FreeRADIUS Version 3.2.10 Copyright (C) 1999-2026 The FreeRADIUS server project and contributors There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE You may redistribute copies of FreeRADIUS under the terms of the GNU General Public License For more information about these matters, see the file named COPYRIGHT FreeRADIUS is developed, maintained, and supported by InkBridge Networks. For commercial support, please email sales@inkbridgenetworks.com https://inkbridgenetworks.com/ Starting - reading configuration files ... including dictionary file /usr/share/freeradius/dictionary including dictionary file /usr/share/freeradius/dictionary.dhcp including dictionary file /usr/share/freeradius/dictionary.vqp including configuration file /repro-raddb/radiusd.conf including files in directory /repro-raddb/sites-enabled/ including configuration file /repro-raddb/sites-enabled/dhcp main { security { allow_core_dumps = no } name = "radiusd" prefix = "/usr" localstatedir = "/var" logdir = "/var/log/freeradius" run_dir = "/var/run/radiusd" } main { name = "radiusd" prefix = "/usr" localstatedir = "/var" sbindir = "/usr/sbin" logdir = "/var/log/freeradius" run_dir = "/var/run/radiusd" libdir = "/usr/lib/freeradius" radacctdir = "/var/log/freeradius/radacct" hostname_lookups = no max_request_time = 30 proxy_dedup_window = 1 cleanup_delay = 5 max_requests = 1024 max_fds = 512 postauth_client_lost = no pidfile = "/var/run/radiusd/radiusd.pid" checkrad = "/usr/sbin/checkrad" debug_level = 0 proxy_requests = yes log { stripped_names = no auth = no auth_badpass = no auth_goodpass = no colourise = no msg_denied = "You are already logged in - access denied" suppress_secrets = yes } resources { } security { max_attributes = 0 reject_delay = 0.000000 delay_proxy_rejects = no status_server = no require_message_authenticator = "auto" limit_proxy_state = "auto" } unlang { group_stop_return = no policy_stop_return = no improved_state_tracking = no proxy_null_listener = no } } radiusd: #### Loading Realms and Home Servers #### radiusd: #### Loading Clients #### Debug state unknown (cap_sys_ptrace capability not set) Configuration version: 8c64-7017-a7c8-1341 systemd watchdog is disabled Cannot find a "modules" section in the configuration file! radiusd: #### Instantiating modules #### modules { } # modules radiusd: #### Loading Virtual Servers #### server { # from file /repro-raddb/radiusd.conf } # server server dhcp { # from file /repro-raddb/sites-enabled/dhcp # Loading dhcp DHCP-Discover {...} Compiling dhcp DHCP-Discover for attr DHCP-Message-Type } # server dhcp radiusd: #### Opening IP addresses and Ports #### listen { type = "dhcp" ipaddr = * port = 67 No "interface" setting is defined. Only unicast DHCP will work } Listening on dhcp address * port 67 bound to server dhcp All secret information will be replaced with the string '<<secret>>' To see the contents of passwords, set `suppress_secrets=no` in the main configuration file. Ready to process requests Received DHCP-Discover of Id 4f503832 from 10.251.80.3:67 to 10.251.80.2:67 DHCP-Opcode = Client-Message DHCP-Hardware-Type = Ethernet DHCP-Hardware-Address-Length = 6 DHCP-Hop-Count = 1 DHCP-Transaction-Id = 1330657330 DHCP-Number-of-Seconds = 0 DHCP-Flags = Broadcast DHCP-Client-IP-Address = 0.0.0.0 DHCP-Your-IP-Address = 0.0.0.0 DHCP-Server-IP-Address = 0.0.0.0 DHCP-Gateway-IP-Address = 10.251.80.3 DHCP-Client-Hardware-Address = ac:db:48:9f:87:af DHCP-Message-Type = DHCP-Discover DHCP-Relay-Circuit-Id = 0xacdb489f87af DHCP-Relay-Remote-Id = 0xacdb489f87b0 DHCP-Network-Subnet = 10.251.80.3/32 (0) Received code 1025 Id 1330657330 from 10.251.80.3:67 to 10.251.80.2:67 length 262 (0) DHCP-Opcode = Client-Message (0) DHCP-Hardware-Type = Ethernet (0) DHCP-Hardware-Address-Length = 6 (0) DHCP-Hop-Count = 1 (0) DHCP-Transaction-Id = 1330657330 (0) DHCP-Number-of-Seconds = 0 (0) DHCP-Flags = Broadcast (0) DHCP-Client-IP-Address = 0.0.0.0 (0) DHCP-Your-IP-Address = 0.0.0.0 (0) DHCP-Server-IP-Address = 0.0.0.0 (0) DHCP-Gateway-IP-Address = 10.251.80.3 (0) DHCP-Client-Hardware-Address = ac:db:48:9f:87:af (0) DHCP-Message-Type = DHCP-Discover (0) DHCP-Relay-Circuit-Id = 0xacdb489f87af (0) DHCP-Relay-Remote-Id = 0xacdb489f87b0 (0) DHCP-Network-Subnet = 10.251.80.3/32 Trying sub-section dhcp DHCP-Discover {...} (0) dhcp DHCP-Discover { (0) update reply { (0) DHCP-Message-Type = DHCP-Offer (0) DHCP-Relay-Remote-Id = 0xacdb489f87b0 (0) DHCP-Domain-Name-Server = 8.8.8.8 (0) DHCP-Router-Address = 10.9.9.1 (0) DHCP-Subnet-Mask = 255.255.255.0 (0) DHCP-TFTP-Server-Name = "tftp.example" (0) DHCP-Your-IP-Address = 10.9.9.50 (0) DHCP-Relay-Circuit-Id = 0xacdb489f87af (0) } # update reply = noop (0) } # dhcp DHCP-Discover = noop (0) DHCP: Reply will be unicast to giaddr from original packet (0) Sent code 1026 Id 1330657330 from 10.251.80.2:67 to 10.251.80.3:67 length 0 (0) DHCP-Relay-IP-Address = 10.251.80.3 (0) DHCP-Message-Type = DHCP-Offer (0) DHCP-Relay-Remote-Id = 0xacdb489f87b0 (0) DHCP-Domain-Name-Server = 8.8.8.8 (0) DHCP-Router-Address = 10.9.9.1 (0) DHCP-Subnet-Mask = 255.255.255.0 (0) DHCP-TFTP-Server-Name = "tftp.example" (0) DHCP-Your-IP-Address = 10.9.9.50 (0) DHCP-Relay-Circuit-Id = 0xacdb489f87af (0) DHCP-Opcode = Server-Message (0) DHCP-Hardware-Type = Ethernet (0) DHCP-Hardware-Address-Length = 6 (0) DHCP-Hop-Count = 1 (0) DHCP-Transaction-Id = 1330657330 (0) DHCP-Flags = Broadcast (0) DHCP-Client-IP-Address = 0.0.0.0 (0) DHCP-Gateway-IP-Address = 10.251.80.3 (0) DHCP-Client-Hardware-Address = ac:db:48:9f:87:af DHCP-Opcode = Server-Message DHCP-Hardware-Type = Ethernet DHCP-Hardware-Address-Length = 6 DHCP-Hop-Count = 1 DHCP-Transaction-Id = 1330657330 DHCP-Number-of-Seconds = 0 DHCP-Flags = Broadcast DHCP-Client-IP-Address = 0.0.0.0 DHCP-Your-IP-Address = 10.9.9.50 DHCP-Server-IP-Address = 0.0.0.0 DHCP-Gateway-IP-Address = 10.251.80.3 DHCP-Client-Hardware-Address = ac:db:48:9f:87:af DHCP-Server-Host-Name = "" DHCP-Boot-Filename = "" DHCP-Domain-Name-Server = 8.8.8.8 DHCP-Router-Address = 10.9.9.1 DHCP-Subnet-Mask = 255.255.255.0 DHCP-TFTP-Server-Name = "tftp.example" DHCP-Relay-Circuit-Id = 0xacdb489f87af DHCP-Relay-Remote-Id = 0xacdb489f87b0 Sending DHCP-Offer Id 4f503832 from 10.251.80.2:67 to 10.251.80.3:67 (0) Finished request (0) Cleaning up request packet ID 1330657330 with timestamp +4 due to done Ready to process requests Ready to process requests Signalled to terminate Exiting normally --- Request and response packet captures (human readable and hex): --- reading from file /tmp/capture.pcap, link-type EN10MB (Ethernet), snapshot length 262144 2026-11-09 10:26:11.603713 IP (tos 0x0, ttl 64, id 7203, offset 0, flags [DF], proto UDP (17), length 290) 10.251.80.3.67 > 10.251.80.2.67: [bad udp cksum 0xb71a -> 0x006e!] BOOTP/DHCP, Request from ac:db:48:9f:87:af, length 262, hops 1, xid 0x4f503832, Flags [Broadcast] (0x8000) Gateway-IP 10.251.80.3 Client-Ethernet-Address ac:db:48:9f:87:af Vendor-rfc1048 Extensions Magic Cookie 0x63825363 DHCP-Message (53), length 1: Discover Agent-Information (82), length 16: Circuit-ID SubOption 1, length 6: M-,M-[HM-^_M-^GM-/ Remote-ID SubOption 2, length 6: M-,M-[HM-^_M-^GM-0 END (255), length 0 2026-11-09 10:26:11.604051 IP (tos 0x0, ttl 64, id 48267, offset 0, flags [none], proto UDP (17), length 328) 10.251.80.2.67 > 10.251.80.3.67: [bad udp cksum 0xb740 -> 0x43bd!] BOOTP/DHCP, Reply, length 300, hops 1, xid 0x4f503832, Flags [Broadcast] (0x8000) Your-IP 10.9.9.50 Gateway-IP 10.251.80.3 Client-Ethernet-Address ac:db:48:9f:87:af Vendor-rfc1048 Extensions Magic Cookie 0x63825363 DHCP-Message (53), length 1: Offer Domain-Name-Server (6), length 4: 8.8.8.8 Default-Gateway (3), length 4: 10.9.9.1 Subnet-Mask (1), length 4: 255.255.255.0 TFTP (66), length 12: "tftp.example" Agent-Information (82), length 8: Circuit-ID SubOption 1, length 6: M-,M-[HM-^_M-^GM-/ Agent-Information (82), length 8: Remote-ID SubOption 2, length 6: M-,M-[HM-^_M-^GM-0 END (255), length 0 PAD (0), length 0, occurs 4 --- reading from file /tmp/capture.pcap, link-type EN10MB (Ethernet), snapshot length 262144 10:26:11.603713 IP 10.251.80.3.67 > 10.251.80.2.67: BOOTP/DHCP, Request from ac:db:48:9f:87:af, length 262 0x0000: 367f 9ce8 0fb3 6627 0f42 f719 0800 4500 6.....f'.B....E. 0x0010: 0122 1c23 4000 4011 67ad 0afb 5003 0afb .".#@.@.g...P... 0x0020: 5002 0043 0043 010e b71a 0101 0601 4f50 P..C.C........OP 0x0030: 3832 0000 8000 0000 0000 0000 0000 0000 82.............. 0x0040: 0000 0afb 5003 acdb 489f 87af 0000 0000 ....P...H....... 0x0050: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x0060: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x0070: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x0080: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x0090: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x00a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x00b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x00c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x00d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x00e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x00f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x0100: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x0110: 0000 0000 0000 6382 5363 3501 0152 1001 ......c.Sc5..R.. 0x0120: 06ac db48 9f87 af02 06ac db48 9f87 b0ff ...H.......H.... 10:26:11.604051 IP 10.251.80.2.67 > 10.251.80.3.67: BOOTP/DHCP, Reply, length 300 0x0000: 6627 0f42 f719 367f 9ce8 0fb3 0800 4500 f'.B..6.......E. 0x0010: 0148 bc8b 0000 4011 071f 0afb 5002 0afb .H....@.....P... 0x0020: 5003 0043 0043 0134 b740 0201 0601 4f50 P..C.C.4.@....OP 0x0030: 3832 0000 8000 0000 0000 0a09 0932 0000 82...........2.. 0x0040: 0000 0afb 5003 acdb 489f 87af 0000 0000 ....P...H....... 0x0050: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x0060: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x0070: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x0080: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x0090: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x00a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x00b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x00c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x00d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x00e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x00f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x0100: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x0110: 0000 0000 0000 6382 5363 3501 0206 0408 ......c.Sc5..... 0x0120: 0808 0803 040a 0909 0101 04ff ffff 0042 ...............B 0x0130: 0c74 6674 702e 6578 616d 706c 6552 0801 .tftp.exampleR.. 0x0140: 06ac db48 9f87 af52 0802 06ac db48 9f87 ...H...R.....H.. 0x0150: b0ff 0000 0000 ...... Best regards, Ludo
On Nov 9, 2026, at 6:19 AM, Ľudovít Mikula via Freeradius-Users <freeradius-users@lists.freeradius.org> wrote:
I found a bug in the 3.2.10 version (tried also against built v3.2.x HEAD) concerning Option82 sub-options encoding in the response.
- fr_dhcp_encode sorts the reply attributes with fr_dhcp_attr_cmp - fr_dhcp_encode_option writes one Option 82 header and fr_dhcp_vp2data_tlv then packs sub-options only while they are next to each other in the sorted list - any other attribute that sorts between Relay-Circuit-Id and Relay-Remote-Id ends the run, and the next sub-option starts a second Option 82
For example DHCP-Your-IP-Address (attribute 264) is a packet header field, not an option - the encoder skips it, but it sits between the two sub-options, so they go out as two Option 82 instances.
Here is a patch to fix it:
Thanks. I've committed the patch, and added a test. Alan DeKok.
participants (2)
-
Alan DeKok -
Ľudovít Mikula