]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
decode TLVs as nested, and update tests to match
authorAlan T. DeKok <aland@freeradius.org>
Sun, 10 Oct 2021 12:19:51 +0000 (08:19 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 10 Oct 2021 12:24:08 +0000 (08:24 -0400)
src/protocols/dns/decode.c
src/tests/unit/protocols/dns/opt41.txt

index eba3a6431f794e5b61364c2bda7954c88aa70a60..fcbd4a3b890744ba7d774912242e897bee92a7e6 100644 (file)
@@ -465,6 +465,7 @@ static ssize_t decode_tlvs(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const
                           uint8_t const *data, size_t const data_len, void *decode_ctx, bool do_raw)
 {
        uint8_t const *p, *end;
+       fr_pair_t *vp;
 
        FR_PROTO_HEX_DUMP(data, data_len, "decode_tlvs");
 
@@ -474,14 +475,17 @@ static ssize_t decode_tlvs(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const
        p = data;
        end = data + data_len;
 
+       vp = fr_pair_afrom_da(ctx, parent);
+       if (!vp) return PAIR_DECODE_OOM;
+
        while (p < end) {
                ssize_t slen;
 
-               slen = decode_option(ctx, out, dict, parent, p, (end - p), decode_ctx);
+               slen = decode_option(vp, &vp->vp_group, dict, parent, p, (end - p), decode_ctx);
                if (slen <= 0) {
                        if (!do_raw) return slen;
 
-                       slen = decode_raw(ctx, out, dict, parent, p, (end - p), decode_ctx);
+                       slen = decode_raw(vp, &vp->vp_group, dict, parent, p, (end - p), decode_ctx);
                        if (slen <= 0) return slen;
                        break;
                }
@@ -489,6 +493,7 @@ static ssize_t decode_tlvs(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const
                p += slen;
        }
 
+       fr_pair_append(out, vp);
        return data_len;
 }
 
index c0996f3d59b501532220a8c9c3cf980ba2f7bd47..dcbcd1606170f64b07a1fa63c9ad1a6d434c68f0 100644 (file)
@@ -5,13 +5,10 @@ proto dns
 proto-dictionary dns
 
 decode-proto f6 ab 01 20 00 01 00 00 00 00 00 01 00 00 06 00 01 00 00 29 10 00 00 00 00 00 00 0c 00 0a 00 08 36 bf 11 1f ef 2e 01 09
-match packet = { id = 63147, query = query, opcode = query, authoritative = no, truncated-response = no, recursion-desired = yes, recursion-available = no, reserved = no, authentic-data = yes, checking-disabled = no, rcode = no-error, qdcount = 1, ancount = 0, nscount = 0, arcount = 1 }, question = { qname = ".", qtype = 6, qclass = internet }, ar = { name = ".", type = opt, class = 4096, ttl = 0, type.opt = { options.padding = 0x000836bf111fef2e0109 } }
+match packet = { id = 63147, query = query, opcode = query, authoritative = no, truncated-response = no, recursion-desired = yes, recursion-available = no, reserved = no, authentic-data = yes, checking-disabled = no, rcode = no-error, qdcount = 1, ancount = 0, nscount = 0, arcount = 1 }, question = { qname = ".", qtype = 6, qclass = internet }, ar = { name = ".", type = opt, class = 4096, ttl = 0, type.opt = { options = { padding = 0x000836bf111fef2e0109 } } }
 
-#
-#  Doesn't quite work yet.  Maybe the struct decoding isn't quite correct.
-#
-#encode-proto -
-#match f6 ab 01 20 00 01 00 00 00 00 00 01 00 00 06 00 01 00 00 29 10 00 00 00 00 00 00 0c 00 0a 00 08 36 bf 11 1f ef 2e 01 09
+encode-proto -
+match f6 ab 01 20 00 01 00 00 00 00 00 01 00 00 06 00 01 00 00 29 10 00 00 00 00 00 00 0c 00 0a 00 08 36 bf 11 1f ef 2e 01 09
 
 count
-match 4
+match 6