From: Alan T. DeKok Date: Sun, 28 Jan 2024 22:17:18 +0000 (-0500) Subject: added foreign decode to DHCPv6 and tests X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=254f5616a4aea9b6f22650023364f0809a87a336;p=thirdparty%2Ffreeradius-server.git added foreign decode to DHCPv6 and tests --- diff --git a/src/protocols/dhcpv6/decode.c b/src/protocols/dhcpv6/decode.c index 8ea258b98fa..72519fab701 100644 --- a/src/protocols/dhcpv6/decode.c +++ b/src/protocols/dhcpv6/decode.c @@ -73,6 +73,7 @@ static ssize_t decode_value(TALLOC_CTX *ctx, fr_pair_list_t *out, ssize_t slen; fr_pair_t *vp = NULL; uint8_t prefix_len; + fr_dict_attr_t const *ref; FR_PROTO_HEX_DUMP(data, data_len, "decode_value"); @@ -186,14 +187,31 @@ static ssize_t decode_value(TALLOC_CTX *ctx, fr_pair_list_t *out, vp = fr_pair_afrom_da(ctx, parent); if (!vp) return PAIR_DECODE_OOM; - /* - * Child VPs go into the child group, not in the main parent list. BUT, we start - * decoding attributes from the dictionary root, not from this parent. - */ - slen = fr_pair_tlvs_from_network(vp, &vp->vp_group, fr_dict_root(dict_dhcpv6), data, data_len, decode_ctx, decode_option, NULL, false); - if (slen < 0) { - talloc_free(vp); - goto raw; + ref = fr_dict_attr_ref(parent); + if (ref && (ref->dict != dict_dhcpv6)) { + fr_dict_protocol_t const *proto; + + proto = fr_dict_protocol(ref->dict); + fr_assert(proto != NULL); + + if (!proto->decode) { + raw_free: + talloc_free(vp); + goto raw; + } + + slen = proto->decode(vp, &vp->vp_group, data, data_len); + if (slen < 0) goto raw_free; + + vp->vp_tainted = true; + + } else { + /* + * Child VPs go into the child group, not in the main parent list. BUT, we start + * decoding attributes from the dictionary root, not from this parent. + */ + slen = fr_pair_tlvs_from_network(vp, &vp->vp_group, fr_dict_root(dict_dhcpv6), data, data_len, decode_ctx, decode_option, NULL, false); + if (slen < 0) goto raw_free; } fr_pair_append(out, vp); @@ -210,10 +228,7 @@ static ssize_t decode_value(TALLOC_CTX *ctx, fr_pair_list_t *out, slen = fr_value_box_from_network(vp, &vp->data, vp->vp_type, vp->da, &FR_DBUFF_TMP(data, sizeof(vp->vp_ipv6addr)), sizeof(vp->vp_ipv6addr), true); - if (slen < 0) { - talloc_free(vp); - goto raw; - } + if (slen < 0) goto raw_free; break; default: @@ -222,10 +237,7 @@ static ssize_t decode_value(TALLOC_CTX *ctx, fr_pair_list_t *out, slen = fr_value_box_from_network(vp, &vp->data, vp->vp_type, vp->da, &FR_DBUFF_TMP(data, data_len), data_len, true); - if (slen < 0) { - talloc_free(vp); - goto raw; - } + if (slen < 0) goto raw_free; break; } diff --git a/src/tests/unit/protocols/radius/foreign.txt b/src/tests/unit/protocols/radius/foreign.txt index 52c42b905f6..7fec09bb62c 100644 --- a/src/tests/unit/protocols/radius/foreign.txt +++ b/src/tests/unit/protocols/radius/foreign.txt @@ -50,8 +50,8 @@ match f5 11 03 00 00 0e 00 00 00 51 00 05 01 05 62 6f 62 # # Not yet # -#decode-pair - -#match Extended-Attribute-5 = { DHCPv6-Options = { RADIUS = { User-Name = "bob" } } } +decode-pair - +match Extended-Attribute-5 = { DHCPv6-Options = { Rapid-Commit = yes, RADIUS = { User-Name = "bob" } } } ###################################################################### # @@ -72,4 +72,4 @@ decode-proto 1f000260b50307ffededdef5ff04f504da0000026004ffedf53cfffffdff13daf50 match Packet-Type = Terminate-Session, Packet-Authentication-Vector = 0xb50307ffededdef5ff04f504da000002, raw.Framed-Interface-Id = 0xffed, Extended-Attribute-5 = { raw.255 = 0xfdff13daf504ffed000000000c0000180000000000000076e504ffdaf504ffecf504ffddf500ffed8104ffdaf504ff82f504ffda0bfaffda, raw.DHCPv4-Options = 0xed249e0038fffe0002ff2b3100bd001f000000810f02010004000f1b00549e00e402ef046b02cf04c05400046b02cf047d41cf04e7cf02040002fe147c02cf040205cf7d02cf00047d02cf04e802cf067d02cf7a007c02027dcfcf020404e8cf067d02cf04cf02040002fe147c02cf040205cf7d02cf00047d02cf04e802cf067d02cf7a047c02027dcfcf020404e8cf067d02cf047c02cf040302cf04e8023d02cf0024151c2a160000000000000000018303d67b0303023002cf03025902cf0306bd000014fb02cf03000000000076e504ffdaf504ffecf504ffddf500ff82f504ffda0bfaffdaf504ffdaf504ffecf504ff73f504ffddf504ff }, raw.Extended-Attribute-5 = 0xffdd, raw.Extended-Attribute-5 = 0xffed, raw.Extended-Attribute-5 = 0xffda, raw.237 = 0x04ffdaf5ff04f5ed249e0038fffe0002ff2b3100bd0000000000810ffeff0000000f1b00549e00e402ef046b02cf04c05400046b02cf047d41cf040000000000000076e504ffdaf504ffecf504ffddf500ffed8104ffdaf504ff82f504ffda0bfaffdaf504ffdaf504ffecf504ff73f504ffddf504ffedf504ffdaf5ff04f5ed249e0038fffe0002ff2b3100bd0000000000810ffeff0000000f1b00549e00e402ef046b02cf04c05400046b02cf047d41cf04e7cf02040002fe147c02cf040205cf7d02cf06bd02cf0302cc03030302cf03435d03594302cf02cf03025902cf03063d02cf2b063d0302cf03435902cf030302 count -match 27 +match 29