*/
ssize_t fr_struct_from_network(TALLOC_CTX *ctx, fr_pair_list_t *out,
fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len,
- bool nested, void *decode_ctx,
+ void *decode_ctx,
fr_pair_decode_value_t decode_value, fr_pair_decode_value_t decode_tlv)
{
unsigned int child_num;
/*
* Start a child list.
*/
- if (!nested) {
- fr_pair_list_init(&child_list_head);
- child_list = &child_list_head;
- child_ctx = ctx;
- } else {
- fr_assert(parent->type == FR_TYPE_STRUCT);
-
- struct_vp = fr_pair_afrom_da(ctx, parent);
- if (!struct_vp) {
- fr_strerror_const("out of memory");
- return -1;
- }
+ fr_assert(parent->type == FR_TYPE_STRUCT);
- fr_pair_list_init(&child_list_head); /* still used elsewhere */
- child_list = &struct_vp->vp_group;
- child_ctx = struct_vp;
+ struct_vp = fr_pair_afrom_da(ctx, parent);
+ if (!struct_vp) {
+ fr_strerror_const("out of memory");
+ return -1;
}
+
+ fr_pair_list_init(&child_list_head); /* still used elsewhere */
+ child_list = &struct_vp->vp_group;
+ child_ctx = struct_vp;
child_num = 1;
key_vp = NULL;
FR_PROTO_TRACE("fr_struct_from_network - failed decoding child VP %s", vp->da->name);
talloc_free(vp);
unknown:
- if (nested) {
- TALLOC_FREE(struct_vp);
- } else {
- fr_pair_list_free(child_list);
- }
+ TALLOC_FREE(struct_vp);
slen = fr_pair_raw_from_network(ctx, out, parent, data, data_len);
if (slen < 0) return slen;
} else {
fr_assert(child->type == FR_TYPE_STRUCT);
- slen = fr_struct_from_network(child_ctx, child_list, child, p, end - p, nested,
+ slen = fr_struct_from_network(child_ctx, child_list, child, p, end - p,
decode_ctx, decode_value, decode_tlv);
if (slen <= 0) {
FR_PROTO_TRACE("substruct %s decoding failed", child->name);
}
done:
- if (!nested) {
- fr_pair_list_append(out, child_list); /* Wind to the end of the new pairs */
- } else {
- fr_assert(struct_vp != NULL);
- fr_pair_append(out, struct_vp);
- }
+ fr_assert(struct_vp != NULL);
+ fr_pair_append(out, struct_vp);
FR_PROTO_TRACE("used %zd bytes", data_len);
return p - data;
ssize_t fr_struct_from_network(TALLOC_CTX *ctx, fr_pair_list_t *out,
fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len,
- bool nested, void *decode_ctx,
+ void *decode_ctx,
fr_pair_decode_value_t decode_value, fr_pair_decode_value_t decode_tlv) CC_HINT(nonnull(2,3,4));
ssize_t fr_struct_to_network(fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth,
/*
* If the packet is too long, we discard any extra data.
*/
- return fr_struct_from_network(ctx, out, attr_arp_packet, packet, FR_ARP_PACKET_SIZE, true,
+ return fr_struct_from_network(ctx, out, attr_arp_packet, packet, FR_ARP_PACKET_SIZE,
NULL, NULL, NULL);
}
bfd = (bfd_packet_t const *) packet;
- slen = fr_struct_from_network(ctx, out, attr_bfd_packet, packet, bfd->length, true,
+ slen = fr_struct_from_network(ctx, out, attr_bfd_packet, packet, bfd->length,
&packet_ctx, decode_value, NULL);
if (slen < 0) return slen;
* Structs create their own VP wrapper.
*/
if (da->type == FR_TYPE_STRUCT) {
- slen = fr_struct_from_network(ctx, out, da, data, data_len, true,
+ slen = fr_struct_from_network(ctx, out, da, data, data_len,
decode_ctx, decode_value_trampoline, decode_tlv_trampoline);
if (slen < 0) return slen;
break;
case FR_TYPE_STRUCT:
- slen = fr_struct_from_network(ctx, out, parent, data, data_len, true,
+ slen = fr_struct_from_network(ctx, out, parent, data, data_len,
decode_ctx, decode_value_trampoline, decode_tlv_trampoline);
if (slen < 0) goto raw;
break;
case FR_TYPE_STRUCT:
- slen = fr_struct_from_network(ctx, out, parent, data, data_len, true,
+ slen = fr_struct_from_network(ctx, out, parent, data, data_len,
decode_ctx, decode_value_trampoline, NULL);
if (slen < 0) return slen;
return data_len;
FR_PROTO_HEX_DUMP(p, end - p, "fr_dns_decode - %s %d/%d", attr->name, i, count);
- slen = fr_struct_from_network(ctx, out, attr, p, end - p, true,
+ slen = fr_struct_from_network(ctx, out, attr, p, end - p,
packet_ctx, decode_value_trampoline, decode_tlv_trampoline);
if (slen < 0) return slen;
if (!slen) break;
/*
* Decode the header.
*/
- slen = fr_struct_from_network(ctx, out, attr_dns_packet, packet, DNS_HDR_LEN, true,
+ slen = fr_struct_from_network(ctx, out, attr_dns_packet, packet, DNS_HDR_LEN,
packet_ctx, decode_value_trampoline, NULL); /* no TLVs in the header */
if (slen < 0) {
fr_strerror_printf("Failed decoding DNS header - %s", fr_strerror());
return -1;
}
- slen = fr_struct_from_network(ctx, out, attr_dns_rr, data, data_len, true,
+ slen = fr_struct_from_network(ctx, out, attr_dns_rr, data, data_len,
decode_ctx, decode_value_trampoline, decode_tlv_trampoline);
if (slen < 0) return slen;
da = fr_dict_attr_child_by_num(parent, attr);
if (!da) {
+ fprintf(stderr, "RAW %d - %s %u\n", __LINE__, parent->name, attr);
+
da = fr_dict_attr_unknown_raw_afrom_num(packet_ctx->tmp_ctx, parent, attr);
if (!da) return PAIR_DECODE_FATAL_ERROR;
slen = fr_pair_raw_from_network(ctx, out, da, data + 2, len - 2);
* Child is unknown and not a TLV: build an unknown attr
*/
if (fr_radius_decode_tlv_ok(p + 2, p[1] - 2, 1, 1) < 0) {
+ fprintf(stderr, "RAW %d - %s %u\n", __LINE__, parent->name, p[0]);
child = fr_dict_attr_unknown_raw_afrom_num(packet_ctx->tmp_ctx, parent, p[0]);
if (!child) {
error:
* well formed, so we just go create a raw VP.
*/
} else if ((dv->length == 0) || (fr_radius_decode_tlv_ok(data + dv->type + dv->length, attrlen - (dv->type + dv->length), dv->type, dv->length) < 0)) {
+ fprintf(stderr, "RAW %d - %s %u\n", __LINE__, parent->name, attribute);
da = fr_dict_attr_unknown_raw_afrom_num(packet_ctx->tmp_ctx, parent, attribute);
if (!da) return -1;
* attribute, OR it's already been grouped
* into a contiguous memory buffer.
*/
- ret = fr_struct_from_network(ctx, out, parent, p, attr_len, true,
+ ret = fr_struct_from_network(ctx, out, parent, p, attr_len,
packet_ctx, decode_value_trampoline, decode_tlv_trampoline);
if (ret < 0) goto raw;
return attr_len;
/*
* Call the struct encoder to do the actual work.
*/
- if (fr_struct_from_network(ctx, out, attr_tacacs_packet, buffer, buffer_len, true, NULL, NULL, NULL) < 0) {
+ if (fr_struct_from_network(ctx, out, attr_tacacs_packet, buffer, buffer_len, NULL, NULL, NULL) < 0) {
fr_strerror_printf("Failed decoding TACACS header - %s", fr_strerror());
return -1;
}