]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
decode RADIUS structs as nested
authorAlan T. DeKok <aland@freeradius.org>
Thu, 14 Sep 2023 19:11:39 +0000 (15:11 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 14 Sep 2023 19:11:39 +0000 (15:11 -0400)
src/protocols/radius/decode.c
src/protocols/radius/radius.h
src/tests/unit/protocols/radius/struct.txt
src/tests/unit/protocols/radius/wimax.txt

index 5769ab032277c18aa82af43ba4e832b09c2ced1e..73399332d7c40682d94f225266f803e8b2515c7a 100644 (file)
@@ -1766,7 +1766,7 @@ ssize_t fr_radius_decode_pair_value(TALLOC_CTX *ctx, fr_pair_list_t *out,
                 *      attribute, OR it's already been grouped
                 *      into a contiguous memory buffer.
                 */
-               ret = fr_struct_from_network(ctx, out, parent, p, attr_len, packet_ctx->struct_nested,
+               ret = fr_struct_from_network(ctx, out, parent, p, attr_len, true,
                                             packet_ctx, decode_value_trampoline, decode_tlv_trampoline);
                if (ret < 0) goto raw;
                return attr_len;
index 7a897230ad790c6939ca5a2fe4360131835c9226..5b100eab8b6c049c8398a831604775b074ddd3c7 100644 (file)
@@ -171,7 +171,6 @@ typedef struct {
        int                     salt_offset;            //!< for tunnel passwords
        bool                    tunnel_password_zeros;  //!< check for trailing zeros on decode
        bool                    disallow_tunnel_passwords; //!< not all packets can have tunnel passwords
-       bool                    struct_nested;          //!< decode structs as nested
 
        uint8_t                 tag;                    //!< current tag for encoding
        fr_radius_tag_ctx_t     **tags;                 //!< for decoding tagged attributes
index 24563ff05c23e11a6ec7e646dd7a420d26fbf2b2..8572bd1b70daeadac069a04ea92b3a6226a451ad 100644 (file)
@@ -12,7 +12,10 @@ encode-pair Extended-Attribute-1.Unit-Ext-241-Struct1.Unit-Struct1-Int1 = 1, Ext
 match f1 10 f7 00 00 00 01 00 00 00 02 00 04 66 6f 6f
 
 decode-pair -
-match Extended-Attribute-1 = { Unit-Ext-241-Struct1.Unit-Struct1-Int1 = 1, Unit-Ext-241-Struct1.Unit-Struct1-Int2 = 2, Unit-Ext-241-Struct1.Unit-Struct1-Short = 4, Unit-Ext-241-Struct1.Unit-Struct1-String = "foo" }
+match Extended-Attribute-1 = { Unit-Ext-241-Struct1 = { Unit-Struct1-Int1 = 1, Unit-Struct1-Int2 = 2, Unit-Struct1-Short = 4, Unit-Struct1-String = "foo" } }
+
+encode-pair -
+match f1 10 f7 00 00 00 01 00 00 00 02 00 04 66 6f 6f
 
 pair Extended-Attribute-1.Unit-Ext-241-Struct2.Unit-Struct2-Int1 = 1, Extended-Attribute-1.Unit-Ext-241-Struct2.Unit-Struct2-Short = 4, Extended-Attribute-1.Unit-Ext-241-Struct2.Unit-Struct2-TLV.Unit-Struct2-TLV-Int1 = 6, Extended-Attribute-1.Unit-Ext-241-Struct2.Unit-Struct2-TLV.Unit-Struct2-TLV-Int2 = 7, Extended-Attribute-1.Unit-Ext-241-Struct2.Unit-Struct2-TLV.Unit-Struct2-TLV-String = "foo"
 match Extended-Attribute-1 = { Unit-Ext-241-Struct2 = { Unit-Struct2-Int1 = 1, Unit-Struct2-Short = 4, Unit-Struct2-TLV = { Unit-Struct2-TLV-Int1 = 6, Unit-Struct2-TLV-Int2 = 7, Unit-Struct2-TLV-String = "foo" } } }
@@ -32,13 +35,16 @@ encode-pair Extended-Attribute-1.Unit-Ext-241-Struct2.Unit-Struct2-Int1 = 1, Ext
 match f1 1a f8 00 00 00 01 00 04 01 06 00 00 00 06 02 06 00 00 00 07 03 05 66 6f 6f
 
 decode-pair -
-match Extended-Attribute-1 = { Unit-Ext-241-Struct2.Unit-Struct2-Int1 = 1, Unit-Ext-241-Struct2.Unit-Struct2-Short = 4, Unit-Ext-241-Struct2.Unit-Struct2-TLV = { Unit-Struct2-TLV-Int1 = 6, Unit-Struct2-TLV-Int2 = 7, Unit-Struct2-TLV-String = "foo" } }
+match Extended-Attribute-1 = { Unit-Ext-241-Struct2 = { Unit-Struct2-Int1 = 1, Unit-Struct2-Short = 4, Unit-Struct2-TLV = { Unit-Struct2-TLV-Int1 = 6, Unit-Struct2-TLV-Int2 = 7, Unit-Struct2-TLV-String = "foo" } } }
+
+encode-pair -
+match f1 1a f8 00 00 00 01 00 04 01 06 00 00 00 06 02 06 00 00 00 07 03 05 66 6f 6f
 
 encode-pair Extended-Attribute-1.Unit-Ext-241-Struct3.Unit-Struct3-Int = 1, Extended-Attribute-1.Unit-Ext-241-Struct3.Unit-Struct3-TLV.Unit-Struct3a.Unit-Struct3a-Ipaddr1 = 127.0.0.1, Extended-Attribute-1.Unit-Ext-241-Struct3.Unit-Struct3-TLV.Unit-Struct3a.Unit-Struct3a-Ipaddr2 = 8.8.8.8
 match f1 11 f9 00 00 00 01 01 0a 7f 00 00 01 08 08 08 08
 
 decode-pair -
-match Extended-Attribute-1 = { Unit-Ext-241-Struct3.Unit-Struct3-Int = 1, Unit-Ext-241-Struct3.Unit-Struct3-TLV = { Unit-Struct3a.Unit-Struct3a-Ipaddr1 = 127.0.0.1, Unit-Struct3a.Unit-Struct3a-Ipaddr2 = 8.8.8.8 } }
+match Extended-Attribute-1 = { Unit-Ext-241-Struct3 = { Unit-Struct3-Int = 1, Unit-Struct3-TLV = { Unit-Struct3a = { Unit-Struct3a-Ipaddr1 = 127.0.0.1, Unit-Struct3a-Ipaddr2 = 8.8.8.8 } } } }
 
 #
 #  Fixed size struct
@@ -47,28 +53,28 @@ encode-pair Extended-Attribute-1.Unit-Ext-241-Struct4.Unit-Struct4-Int1 = 1, Ext
 match f1 0d fa 00 00 00 01 00 00 00 02 00 04
 
 decode-pair -
-match Extended-Attribute-1 = { Unit-Ext-241-Struct4.Unit-Struct4-Int1 = 1, Unit-Ext-241-Struct4.Unit-Struct4-Int2 = 2, Unit-Ext-241-Struct4.Unit-Struct4-Short = 4 }
+match Extended-Attribute-1 = { Unit-Ext-241-Struct4 = { Unit-Struct4-Int1 = 1, Unit-Struct4-Int2 = 2, Unit-Struct4-Short = 4 } }
 
 #
 #  Wrong-sized struct (last field missing), it just decodes what it can.
 #
 decode-pair f1 0b fa 00 00 00 01 00 00 00 02
-match Extended-Attribute-1 = { Unit-Ext-241-Struct4.Unit-Struct4-Int1 = 1, Unit-Ext-241-Struct4.Unit-Struct4-Int2 = 2 }
+match Extended-Attribute-1 = { Unit-Ext-241-Struct4 = { Unit-Struct4-Int1 = 1, Unit-Struct4-Int2 = 2 } }
 
 #
 #  Wrong-sized struct (last two fields missing), it just decodes what it can.
 #
 decode-pair f1 07 fa 00 00 00 01
-match Extended-Attribute-1 = { Unit-Ext-241-Struct4.Unit-Struct4-Int1 = 1 }
+match Extended-Attribute-1 = { Unit-Ext-241-Struct4 = { Unit-Struct4-Int1 = 1 } }
 
 #
 #  Wrong-sized struct (data is too long), we ignore the extra data.
 #
 decode-pair f1 0e fa 00 00 00 01 00 00 00 02 00 04 00
-match Extended-Attribute-1 = { Unit-Ext-241-Struct4.Unit-Struct4-Int1 = 1, Unit-Ext-241-Struct4.Unit-Struct4-Int2 = 2, Unit-Ext-241-Struct4.Unit-Struct4-Short = 4 }
+match Extended-Attribute-1 = { Unit-Ext-241-Struct4 = { Unit-Struct4-Int1 = 1, Unit-Struct4-Int2 = 2, Unit-Struct4-Short = 4 } }
 
 decode-pair ff 09 01 00 00 1a 99 05 06
-match Test-Struct.Key-Field = Sub-Struct, Test-Struct.Filler = 6809, Test-Struct.Key-Field.Sub-Struct.Nested-Sub1 = 5, Test-Struct.Key-Field.Sub-Struct.Nested-Sub2 = 6
+match Test-Struct = { Key-Field = Sub-Struct, Filler = 6809, Key-Field.Sub-Struct = { Nested-Sub1 = 5, Nested-Sub2 = 6 } }
 
 encode-pair -
 match ff 09 01 00 00 1a 99 05 06
@@ -85,4 +91,4 @@ encode-pair -
 match ff 0d 02 00 00 1a 99 ff fe fd fc fb fa
 
 count
-match 41
+match 45
index 632f8c9337d2ac5f1253aacb062da8ee665832cb..b71e7f52bf9c07023676b27f4429515e849b9009 100644 (file)
@@ -250,11 +250,8 @@ match Vendor-Specific.WiMAX.Packet-Flow-Descriptor = { Packet-Data-Flow-Id = 32,
 encode-pair Vendor-Specific.WiMAX.Packet-Flow-Descriptor.Classifier.Src-Spec.IP-Address = 127.0.0.1, Vendor-Specific.WiMAX.Packet-Flow-Descriptor.Classifier.Src-Spec.Port = 2112, Vendor-Specific.WiMAX.Packet-Flow-Descriptor.Classifier.Src-Spec.Port-Range = { Start = 2112, End = 6809 }
 match 1a 1d 00 00 60 b5 1c 17 00 0b 14 05 12 01 06 7f 00 00 01 04 04 08 40 05 06 08 40 1a 99
 
-#
-#  Structs not yet decoded into sub-groups
-#
 decode-pair -
-match Vendor-Specific.WiMAX.Packet-Flow-Descriptor = { Classifier = { Src-Spec = { IP-Address = 127.0.0.1, Port = 2112, Port-Range.Start = 2112, Port-Range.End = 6809 } } }
+match Vendor-Specific.WiMAX.Packet-Flow-Descriptor = { Classifier = { Src-Spec = { IP-Address = 127.0.0.1, Port = 2112, Port-Range = { Start = 2112, End = 6809 } } } }
 
 encode-pair Vendor-Specific.WiMAX.DNS-Server = ::1
 match 1a 19 00 00 60 b5 34 13 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01