]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
coalesce VSAs at the same level
authorAlan T. DeKok <aland@freeradius.org>
Wed, 6 Sep 2023 12:18:25 +0000 (08:18 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 6 Sep 2023 12:23:25 +0000 (08:23 -0400)
src/protocols/dhcpv6/decode.c
src/tests/unit/protocols/dhcpv6/relay_forward.txt
src/tests/unit/protocols/dhcpv6/vendor.txt [new file with mode: 0644]

index df3cd65b575a90dcc4bce56c23fde5a74dab95fb..7111af6bc40042d3b35c851017e6923babdc4363 100644 (file)
@@ -254,6 +254,7 @@ static ssize_t decode_vsa(TALLOC_CTX *ctx, fr_pair_list_t *out,
 {
        uint32_t                pen;
        fr_dict_attr_t const    *da;
+       fr_pair_t               *vp;
        fr_dhcpv6_decode_ctx_t  *packet_ctx = decode_ctx;
 
        FR_PROTO_HEX_DUMP(data, data_len, "decode_vsa");
@@ -289,6 +290,11 @@ static ssize_t decode_vsa(TALLOC_CTX *ctx, fr_pair_list_t *out,
 
        FR_PROTO_TRACE("decode context %s -> %s", parent->name, da->name);
 
+       vp = fr_pair_find_by_da(out, NULL, da);
+       if (vp) {
+               return fr_pair_tlvs_from_network(vp, &vp->vp_group, da, data + 4, data_len - 4, decode_ctx, decode_option, NULL, false);
+       }
+
        return fr_pair_tlvs_from_network(ctx, out, da, data + 4, data_len - 4, decode_ctx, decode_option, NULL, true);
 }
 
index 0bc5bdd248196196244d57bb05b0fff9b14c77be..1cd242eb76e4af7db18b8363b5e0e5a14ccf2f6c 100644 (file)
@@ -11,42 +11,27 @@ proto dhcpv6
 proto-dictionary dhcpv6
 fuzzer-out dhcpv6
 
-encode-pair Vendor-Opts.Nokia-SR = { WAN-Pool = "LABOLT2-na", PFX-Pool = "LABOLT2-pd", PFX-Len = 63, Reserved-NA-Len = 64 }
-match 00 11 00 2a 00 00 19 7f 00 01 00 0a 4c 41 42 4f 4c 54 32 2d 6e 61 00 02 00 0a 4c 41 42 4f 4c 54 32 2d 70 64 00 03 00 01 3f 00 04 00 01 40
-
-decode-pair -
-match Vendor-Opts.Nokia-SR = { WAN-Pool = "LABOLT2-na", PFX-Pool = "LABOLT2-pd", PFX-Len = 63, Reserved-NA-Len = 64 }
-
-encode-pair Vendor-Opts.Nokia-SR = { WAN-Pool = "LABOLT2-na" }, Vendor-Opts.Nokia-SR = { PFX-Pool = "LABOLT2-pd" }, Vendor-Opts.Nokia-SR = { PFX-Len = 63 }, Vendor-Opts.Nokia-SR = { Reserved-NA-Len = 64 }
-match 00 11 00 12 00 00 19 7f 00 01 00 0a 4c 41 42 4f 4c 54 32 2d 6e 61 00 11 00 12 00 00 19 7f 00 02 00 0a 4c 41 42 4f 4c 54 32 2d 70 64 00 11 00 09 00 00 19 7f 00 03 00 01 3f 00 11 00 09 00 00 19 7f 00 04 00 01 40
-
 #
-#  @todo - the Nokia vendor opts should be decoded into the parent Vendor-Opts
+#  If this has issues, it's usually in the Vendor-Opts.  See vendor.txt for Vendor-Opts tests.
 #
-decode-pair -
-match Vendor-Opts.Nokia-SR = { WAN-Pool = "LABOLT2-na" }, Vendor-Opts.Nokia-SR = { PFX-Pool = "LABOLT2-pd" }, Vendor-Opts.Nokia-SR = { PFX-Len = 63 }, Vendor-Opts.Nokia-SR = { Reserved-NA-Len = 64 }
 
 decode-proto 0c 01 26 05 86 00 00 06 80 00 00 00 00 00 00 00 00 00 fe 80 00 00 00 00 00 00 02 50 56 ff fe a3 53 fe 00 09 00 c4 0c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fe 80 00 00 00 00 00 00 02 50 56 ff fe a3 53 fe 00 12 00 1c 4c 41 42 4f 4c 54 32 20 65 74 68 20 31 2f 31 2f 30 35 2f 30 31 2f 32 38 2f 31 2f 31 00 09 00 7e 01 11 41 d7 00 01 00 0e 00 01 00 01 26 b1 b7 f1 00 50 56 a3 53 fe 00 12 00 1c 4c 41 42 4f 4c 54 32 20 65 74 68 20 31 2f 31 2f 30 35 2f 30 31 2f 32 38 2f 31 2f 31 00 06 00 02 00 18 00 08 00 02 00 00 00 03 00 28 56 a3 53 fe 00 00 0e 10 00 00 15 18 00 05 00 18 26 05 86 00 00 06 40 00 00 00 00 00 00 00 00 01 00 00 1c 20 00 00 2a 30 00 19 00 0c 56 a3 53 fe 00 00 0e 10 00 00 15 18 00 25 00 12 00 00 19 7f 00 01 00 01 26 b1 b7 f1 00 50 56 a3 53 fe 00 11 00 2a 00 00 19 7f 00 01 00 0a 4c 41 42 4f 4c 54 32 2d 6e 61 00 02 00 0a 4c 41 42 4f 4c 54 32 2d 70 64 00 03 00 01 3f 00 04 00 01 40
 match Packet-Type = Relay-Forward, Hop-Count = 1, Relay-Link-Address = 2605:8600:6:8000::, Relay-Peer-Address = fe80::250:56ff:fea3:53fe, Relay-Message = { Packet-Type = Relay-Forward, Hop-Count = 0, Relay-Link-Address = ::, Relay-Peer-Address = fe80::250:56ff:fea3:53fe, Interface-ID = 0x4c41424f4c54322065746820312f312f30352f30312f32382f312f31, Relay-Message = { Packet-Type = Solicit, Transaction-ID = 0x1141d7, Client-ID = { DUID = LLT, DUID.LLT = { Hardware-Type = Ethernet, Time = "Jul 27 2020 16:06:09 UTC", Hardware-Type.Ethernet = { Address = 00:50:56:a3:53:fe } } }, Interface-ID = 0x4c41424f4c54322065746820312f312f30352f30312f32382f312f31, Option-Request = Domain-List, Elapsed-Time = 0, IA-NA = { IAID = 1453544446, T1 = 3600, T2 = 5400, Options = { IA-Addr = { IPv6-Address = 2605:8600:6:4000::1, Preferred-Lifetime = 7200, Valid-Lifetime = 10800 } } }, IA-PD = { IAID = 1453544446, T1 = 3600, T2 = 5400 } } }, Relay-Agent-Remote-ID = { Vendor = 6527, Value = 0x0001000126b1b7f1005056a353fe }, Vendor-Opts.Nokia-SR = { WAN-Pool = "LABOLT2-na", PFX-Pool = "LABOLT2-pd", PFX-Len = 63, Reserved-NA-Len = 64 }
 
-#
-#  @todo - encoding the above attributes results not in the input hex string, but the subsequent one. The Nokia-SR options are encoded differently.
-#  instead of encoding them all in one DHCPv6 option, they are encoded as separate ones.
-#
-#encode-proto -
-#match 0c 01 26 05 86 00 00 06 80 00 00 00 00 00 00 00 00 00 fe 80 00 00 00 00 00 00 02 50 56 ff fe a3 53 fe 00 09 00 c4 0c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fe 80 00 00 00 00 00 00 02 50 56 ff fe a3 53 fe 00 12 00 1c 4c 41 42 4f 4c 54 32 20 65 74 68 20 31 2f 31 2f 30 35 2f 30 31 2f 32 38 2f 31 2f 31 00 09 00 7e 01 11 41 d7 00 01 00 0e 00 01 00 01 26 b1 b7 f1 00 50 56 a3 53 fe 00 12 00 1c 4c 41 42 4f 4c 54 32 20 65 74 68 20 31 2f 31 2f 30 35 2f 30 31 2f 32 38 2f 31 2f 31 00 06 00 02 00 18 00 08 00 02 00 00 00 03 00 28 56 a3 53 fe 00 00 0e 10 00 00 15 18 00 05 00 18 26 05 86 00 00 06 40 00 00 00 00 00 00 00 00 01 00 00 1c 20 00 00 2a 30 00 19 00 0c 56 a3 53 fe 00 00 0e 10 00 00 15 18 00 25 00 12 00 00 19 7f 00 01 00 01 26 b1 b7 f1 00 50 56 a3 53 fe 00 11 00 2a 00 00 19 7f 00 01 00 0a 4c 41 42 4f 4c 54 32 2d 6e 61 00 02 00 0a 4c 41 42 4f 4c 54 32 2d 70 64 00 03 00 01 3f 00 04 00 01 40
-
 decode-proto 0c 01 26 05 86 00 00 06 80 00 00 00 00 00 00 00 00 00 fe 80 00 00 00 00 00 00 02 50 56 ff fe a3 53 fe 00 09 00 c4 0c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fe 80 00 00 00 00 00 00 02 50 56 ff fe a3 53 fe 00 12 00 1c 4c 41 42 4f 4c 54 32 20 65 74 68 20 31 2f 31 2f 30 35 2f 30 31 2f 32 38 2f 31 2f 31 00 09 00 7e 01 11 41 d7 00 01 00 0e 00 01 00 01 26 b1 b7 f1 00 50 56 a3 53 fe 00 12 00 1c 4c 41 42 4f 4c 54 32 20 65 74 68 20 31 2f 31 2f 30 35 2f 30 31 2f 32 38 2f 31 2f 31 00 06 00 02 00 18 00 08 00 02 00 00 00 03 00 28 56 a3 53 fe 00 00 0e 10 00 00 15 18 00 05 00 18 26 05 86 00 00 06 40 00 00 00 00 00 00 00 00 01 00 00 1c 20 00 00 2a 30 00 19 00 0c 56 a3 53 fe 00 00 0e 10 00 00 15 18 00 25 00 12 00 00 19 7f 00 01 00 01 26 b1 b7 f1 00 50 56 a3 53 fe 00 11 00 12 00 00 19 7f 00 01 00 0a 4c 41 42 4f 4c 54 32 2d 6e 61 00 11 00 12 00 00 19 7f 00 02 00 0a 4c 41 42 4f 4c 54 32 2d 70 64 00 11 00 09 00 00 19 7f 00 03 00 01 3f 00 11 00 09 00 00 19 7f 00 04 00 01 40
-match Packet-Type = Relay-Forward, Hop-Count = 1, Relay-Link-Address = 2605:8600:6:8000::, Relay-Peer-Address = fe80::250:56ff:fea3:53fe, Relay-Message = { Packet-Type = Relay-Forward, Hop-Count = 0, Relay-Link-Address = ::, Relay-Peer-Address = fe80::250:56ff:fea3:53fe, Interface-ID = 0x4c41424f4c54322065746820312f312f30352f30312f32382f312f31, Relay-Message = { Packet-Type = Solicit, Transaction-ID = 0x1141d7, Client-ID = { DUID = LLT, DUID.LLT = { Hardware-Type = Ethernet, Time = "Jul 27 2020 16:06:09 UTC", Hardware-Type.Ethernet = { Address = 00:50:56:a3:53:fe } } }, Interface-ID = 0x4c41424f4c54322065746820312f312f30352f30312f32382f312f31, Option-Request = Domain-List, Elapsed-Time = 0, IA-NA = { IAID = 1453544446, T1 = 3600, T2 = 5400, Options = { IA-Addr = { IPv6-Address = 2605:8600:6:4000::1, Preferred-Lifetime = 7200, Valid-Lifetime = 10800 } } }, IA-PD = { IAID = 1453544446, T1 = 3600, T2 = 5400 } } }, Relay-Agent-Remote-ID = { Vendor = 6527, Value = 0x0001000126b1b7f1005056a353fe }, Vendor-Opts.Nokia-SR = { WAN-Pool = "LABOLT2-na" }, Vendor-Opts.Nokia-SR = { PFX-Pool = "LABOLT2-pd" }, Vendor-Opts.Nokia-SR = { PFX-Len = 63 }, Vendor-Opts.Nokia-SR = { Reserved-NA-Len = 64 }
+match Packet-Type = Relay-Forward, Hop-Count = 1, Relay-Link-Address = 2605:8600:6:8000::, Relay-Peer-Address = fe80::250:56ff:fea3:53fe, Relay-Message = { Packet-Type = Relay-Forward, Hop-Count = 0, Relay-Link-Address = ::, Relay-Peer-Address = fe80::250:56ff:fea3:53fe, Interface-ID = 0x4c41424f4c54322065746820312f312f30352f30312f32382f312f31, Relay-Message = { Packet-Type = Solicit, Transaction-ID = 0x1141d7, Client-ID = { DUID = LLT, DUID.LLT = { Hardware-Type = Ethernet, Time = "Jul 27 2020 16:06:09 UTC", Hardware-Type.Ethernet = { Address = 00:50:56:a3:53:fe } } }, Interface-ID = 0x4c41424f4c54322065746820312f312f30352f30312f32382f312f31, Option-Request = Domain-List, Elapsed-Time = 0, IA-NA = { IAID = 1453544446, T1 = 3600, T2 = 5400, Options = { IA-Addr = { IPv6-Address = 2605:8600:6:4000::1, Preferred-Lifetime = 7200, Valid-Lifetime = 10800 } } }, IA-PD = { IAID = 1453544446, T1 = 3600, T2 = 5400 } } }, Relay-Agent-Remote-ID = { Vendor = 6527, Value = 0x0001000126b1b7f1005056a353fe }, Vendor-Opts.Nokia-SR = { WAN-Pool = "LABOLT2-na", PFX-Pool = "LABOLT2-pd", PFX-Len = 63, Reserved-NA-Len = 64 }
 
+#
+#  This doesn't encode to the longer string above, as we pack multiple Vendor-Opts into one option
+#
 encode-proto -
-match 0c 01 26 05 86 00 00 06 80 00 00 00 00 00 00 00 00 00 fe 80 00 00 00 00 00 00 02 50 56 ff fe a3 53 fe 00 09 00 c4 0c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fe 80 00 00 00 00 00 00 02 50 56 ff fe a3 53 fe 00 12 00 1c 4c 41 42 4f 4c 54 32 20 65 74 68 20 31 2f 31 2f 30 35 2f 30 31 2f 32 38 2f 31 2f 31 00 09 00 7e 01 11 41 d7 00 01 00 0e 00 01 00 01 26 b1 b7 f1 00 50 56 a3 53 fe 00 12 00 1c 4c 41 42 4f 4c 54 32 20 65 74 68 20 31 2f 31 2f 30 35 2f 30 31 2f 32 38 2f 31 2f 31 00 06 00 02 00 18 00 08 00 02 00 00 00 03 00 28 56 a3 53 fe 00 00 0e 10 00 00 15 18 00 05 00 18 26 05 86 00 00 06 40 00 00 00 00 00 00 00 00 01 00 00 1c 20 00 00 2a 30 00 19 00 0c 56 a3 53 fe 00 00 0e 10 00 00 15 18 00 25 00 12 00 00 19 7f 00 01 00 01 26 b1 b7 f1 00 50 56 a3 53 fe 00 11 00 12 00 00 19 7f 00 01 00 0a 4c 41 42 4f 4c 54 32 2d 6e 61 00 11 00 12 00 00 19 7f 00 02 00 0a 4c 41 42 4f 4c 54 32 2d 70 64 00 11 00 09 00 00 19 7f 00 03 00 01 3f 00 11 00 09 00 00 19 7f 00 04 00 01 40
+match  0c 01 26 05 86 00 00 06 80 00 00 00 00 00 00 00 00 00 fe 80 00 00 00 00 00 00 02 50 56 ff fe a3 53 fe 00 09 00 c4 0c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fe 80 00 00 00 00 00 00 02 50 56 ff fe a3 53 fe 00 12 00 1c 4c 41 42 4f 4c 54 32 20 65 74 68 20 31 2f 31 2f 30 35 2f 30 31 2f 32 38 2f 31 2f 31 00 09 00 7e 01 11 41 d7 00 01 00 0e 00 01 00 01 26 b1 b7 f1 00 50 56 a3 53 fe 00 12 00 1c 4c 41 42 4f 4c 54 32 20 65 74 68 20 31 2f 31 2f 30 35 2f 30 31 2f 32 38 2f 31 2f 31 00 06 00 02 00 18 00 08 00 02 00 00 00 03 00 28 56 a3 53 fe 00 00 0e 10 00 00 15 18 00 05 00 18 26 05 86 00 00 06 40 00 00 00 00 00 00 00 00 01 00 00 1c 20 00 00 2a 30 00 19 00 0c 56 a3 53 fe 00 00 0e 10 00 00 15 18 00 25 00 12 00 00 19 7f 00 01 00 01 26 b1 b7 f1 00 50 56 a3 53 fe 00 11 00 2a 00 00 19 7f 00 01 00 0a 4c 41 42 4f 4c 54 32 2d 6e 61 00 02 00 0a 4c 41 42 4f 4c 54 32 2d 70 64 00 03 00 01 3f 00 04 00 01 40
 
 #
 #  Yes, this is exactly the same massive text blob as above. :)
 #
 decode-proto -
-match Packet-Type = Relay-Forward, Hop-Count = 1, Relay-Link-Address = 2605:8600:6:8000::, Relay-Peer-Address = fe80::250:56ff:fea3:53fe, Relay-Message = { Packet-Type = Relay-Forward, Hop-Count = 0, Relay-Link-Address = ::, Relay-Peer-Address = fe80::250:56ff:fea3:53fe, Interface-ID = 0x4c41424f4c54322065746820312f312f30352f30312f32382f312f31, Relay-Message = { Packet-Type = Solicit, Transaction-ID = 0x1141d7, Client-ID = { DUID = LLT, DUID.LLT = { Hardware-Type = Ethernet, Time = "Jul 27 2020 16:06:09 UTC", Hardware-Type.Ethernet = { Address = 00:50:56:a3:53:fe } } }, Interface-ID = 0x4c41424f4c54322065746820312f312f30352f30312f32382f312f31, Option-Request = Domain-List, Elapsed-Time = 0, IA-NA = { IAID = 1453544446, T1 = 3600, T2 = 5400, Options = { IA-Addr = { IPv6-Address = 2605:8600:6:4000::1, Preferred-Lifetime = 7200, Valid-Lifetime = 10800 } } }, IA-PD = { IAID = 1453544446, T1 = 3600, T2 = 5400 } } }, Relay-Agent-Remote-ID = { Vendor = 6527, Value = 0x0001000126b1b7f1005056a353fe }, Vendor-Opts.Nokia-SR = { WAN-Pool = "LABOLT2-na" }, Vendor-Opts.Nokia-SR = { PFX-Pool = "LABOLT2-pd" }, Vendor-Opts.Nokia-SR = { PFX-Len = 63 }, Vendor-Opts.Nokia-SR = { Reserved-NA-Len = 64 }
+match Packet-Type = Relay-Forward, Hop-Count = 1, Relay-Link-Address = 2605:8600:6:8000::, Relay-Peer-Address = fe80::250:56ff:fea3:53fe, Relay-Message = { Packet-Type = Relay-Forward, Hop-Count = 0, Relay-Link-Address = ::, Relay-Peer-Address = fe80::250:56ff:fea3:53fe, Interface-ID = 0x4c41424f4c54322065746820312f312f30352f30312f32382f312f31, Relay-Message = { Packet-Type = Solicit, Transaction-ID = 0x1141d7, Client-ID = { DUID = LLT, DUID.LLT = { Hardware-Type = Ethernet, Time = "Jul 27 2020 16:06:09 UTC", Hardware-Type.Ethernet = { Address = 00:50:56:a3:53:fe } } }, Interface-ID = 0x4c41424f4c54322065746820312f312f30352f30312f32382f312f31, Option-Request = Domain-List, Elapsed-Time = 0, IA-NA = { IAID = 1453544446, T1 = 3600, T2 = 5400, Options = { IA-Addr = { IPv6-Address = 2605:8600:6:4000::1, Preferred-Lifetime = 7200, Valid-Lifetime = 10800 } } }, IA-PD = { IAID = 1453544446, T1 = 3600, T2 = 5400 } } }, Relay-Agent-Remote-ID = { Vendor = 6527, Value = 0x0001000126b1b7f1005056a353fe }, Vendor-Opts.Nokia-SR = { WAN-Pool = "LABOLT2-na", PFX-Pool = "LABOLT2-pd", PFX-Len = 63, Reserved-NA-Len = 64 }
 
 count
-match 19
+match 11
diff --git a/src/tests/unit/protocols/dhcpv6/vendor.txt b/src/tests/unit/protocols/dhcpv6/vendor.txt
new file mode 100644 (file)
index 0000000..4bfc062
--- /dev/null
@@ -0,0 +1,27 @@
+#  -*- text -*-
+#  Copyright (C) 2021 Network RADIUS SARL (legal@networkradius.com)
+#  This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0
+#
+#  Version $Id$
+#
+#  Test vectors for vendor options in the DHCPv6 protocol
+#
+
+proto dhcpv6
+proto-dictionary dhcpv6
+fuzzer-out dhcpv6
+
+encode-pair Vendor-Opts.Nokia-SR = { WAN-Pool = "LABOLT2-na", PFX-Pool = "LABOLT2-pd", PFX-Len = 63, Reserved-NA-Len = 64 }
+match 00 11 00 2a 00 00 19 7f 00 01 00 0a 4c 41 42 4f 4c 54 32 2d 6e 61 00 02 00 0a 4c 41 42 4f 4c 54 32 2d 70 64 00 03 00 01 3f 00 04 00 01 40
+
+decode-pair -
+match Vendor-Opts.Nokia-SR = { WAN-Pool = "LABOLT2-na", PFX-Pool = "LABOLT2-pd", PFX-Len = 63, Reserved-NA-Len = 64 }
+
+encode-pair Vendor-Opts.Nokia-SR = { WAN-Pool = "LABOLT2-na" }, Vendor-Opts.Nokia-SR = { PFX-Pool = "LABOLT2-pd" }, Vendor-Opts.Nokia-SR = { PFX-Len = 63 }, Vendor-Opts.Nokia-SR = { Reserved-NA-Len = 64 }
+match 00 11 00 12 00 00 19 7f 00 01 00 0a 4c 41 42 4f 4c 54 32 2d 6e 61 00 11 00 12 00 00 19 7f 00 02 00 0a 4c 41 42 4f 4c 54 32 2d 70 64 00 11 00 09 00 00 19 7f 00 03 00 01 3f 00 11 00 09 00 00 19 7f 00 04 00 01 40
+
+decode-pair -
+match Vendor-Opts.Nokia-SR = { WAN-Pool = "LABOLT2-na", PFX-Pool = "LABOLT2-pd", PFX-Len = 63, Reserved-NA-Len = 64 }
+
+count
+match 11