From: Alan T. DeKok Date: Sun, 10 Oct 2021 12:19:51 +0000 (-0400) Subject: decode TLVs as nested, and update tests to match X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db277e77379d03b46b01df42d70503a09c8c0783;p=thirdparty%2Ffreeradius-server.git decode TLVs as nested, and update tests to match --- diff --git a/src/protocols/dns/decode.c b/src/protocols/dns/decode.c index eba3a6431f7..fcbd4a3b890 100644 --- a/src/protocols/dns/decode.c +++ b/src/protocols/dns/decode.c @@ -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; } diff --git a/src/tests/unit/protocols/dns/opt41.txt b/src/tests/unit/protocols/dns/opt41.txt index c0996f3d59b..dcbcd160617 100644 --- a/src/tests/unit/protocols/dns/opt41.txt +++ b/src/tests/unit/protocols/dns/opt41.txt @@ -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