From: Alan T. DeKok Date: Tue, 8 Jun 2021 13:25:01 +0000 (-0400) Subject: allow for nested VPs in one place X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9782a9399a4ff628e714e4d49382c5b84f84017d;p=thirdparty%2Ffreeradius-server.git allow for nested VPs in one place --- diff --git a/src/protocols/dhcpv4/encode.c b/src/protocols/dhcpv4/encode.c index 35613d63d3e..a13a9f31b7d 100644 --- a/src/protocols/dhcpv4/encode.c +++ b/src/protocols/dhcpv4/encode.c @@ -549,6 +549,47 @@ ssize_t fr_dhcpv4_encode_option(fr_dbuff_t *dbuff, fr_dcursor_t *cursor, void *e FR_PROTO_STACK_PRINT(&da_stack, depth); + if (!da_stack.da[depth + 1]) { + fr_dcursor_t child_cursor; + + switch (vp->da->type) { + case FR_TYPE_STRUCTURAL: + break; + + default: + fr_strerror_printf("Failed encoding attribute '%s' due to da_stack issue", vp->da->name); + (void)fr_dcursor_next(cursor); + return 0; + } + + fr_dcursor_init(&child_cursor, &vp->vp_group); + vp = fr_dcursor_current(&child_cursor); + fr_proto_da_stack_build(&da_stack, vp->da); + + switch (da_stack.da[depth]->type) { + case FR_TYPE_VSA: + len = encode_vsio_hdr(&work_dbuff, &da_stack, depth, &child_cursor, encode_ctx); + break; + + case FR_TYPE_TLV: + len = encode_tlv_hdr(&work_dbuff, &da_stack, depth, &child_cursor, encode_ctx); + break; + + default: + len = encode_rfc_hdr(&work_dbuff, &da_stack, depth, &child_cursor, encode_ctx); + break; + } + + if (len <= 0) return len; + + /* + * skip this VP, and re-build the da stack. + */ + vp = fr_dcursor_next(cursor); + fr_proto_da_stack_build(&da_stack, vp ? vp->da : NULL); + goto done; + } + /* * We only have two types of options in DHCPv4 */ @@ -568,6 +609,7 @@ ssize_t fr_dhcpv4_encode_option(fr_dbuff_t *dbuff, fr_dcursor_t *cursor, void *e if (len <= 0) return len; +done: FR_PROTO_TRACE("Complete option is %zu byte(s)", fr_dbuff_used(&work_dbuff)); FR_PROTO_HEX_DUMP(dbuff->p, fr_dbuff_used(&work_dbuff), NULL); diff --git a/src/tests/unit/protocols/dhcpv4/base.txt b/src/tests/unit/protocols/dhcpv4/base.txt index dc78d82075c..98ac15a9af7 100644 --- a/src/tests/unit/protocols/dhcpv4/base.txt +++ b/src/tests/unit/protocols/dhcpv4/base.txt @@ -13,6 +13,13 @@ match 52 0d 01 03 ab cd ef 02 06 01 02 03 04 05 06 decode-pair - match Relay-Agent-Information.Circuit-Id = 0xabcdef, Relay-Agent-Information.Remote-Id = 0x010203040506 +# +# And then again as nested pairs +# +encode-pair Relay-Agent-Information = { Circuit-Id = 0xabcdef, Remote-Id = 0x010203040506 } +match 52 0d 01 03 ab cd ef 02 06 01 02 03 04 05 06 + + encode-pair Subnet-Mask = 255.255.0.0 match 01 04 ff ff 00 00