The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
struct.c
Go to the documentation of this file.
1/*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/** Functions to encode / decode structures on the wire
18 *
19 * @file src/lib/util/struct.c
20 *
21 * @copyright 2018 The FreeRADIUS server project
22 * @copyright 2018 Alan DeKok (aland@freeradius.org)
23 */
24RCSID("$Id: 1d5c485e2f0e41785a8ae83394182402ec58d34b $")
25
26#include <freeradius-devel/util/struct.h>
27#include <freeradius-devel/io/pair.h>
28
29/** Convert a STRUCT to one or more VPs
30 *
31 */
33 fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len,
34 void *decode_ctx,
36{
37 unsigned int child_num;
38 uint8_t const *p = data, *end = data + data_len;
39 fr_dict_attr_t const *child, *substruct_da;
40 fr_pair_list_t child_list_head;
41 fr_pair_list_t *child_list;
42 fr_pair_t *vp, *key_vp, *struct_vp = NULL;
43 unsigned int offset = 0;
44 TALLOC_CTX *child_ctx;
45 ssize_t slen;
46 size_t child_length;
47
48 if (data_len == 0) {
49 fr_strerror_const("struct decoder was passed zero bytes of data");
50 return -1; /* at least one byte of data */
51 }
52
53 FR_PROTO_TRACE("Decoding struct %s", parent->name);
54 FR_PROTO_HEX_DUMP(data, data_len, "fr_struct_from_network");
55
56 /*
57 * Start a child list.
58 */
60
61 struct_vp = fr_pair_afrom_da(ctx, parent);
62 if (!struct_vp) {
63 return PAIR_DECODE_OOM;
64 }
65
66 fr_pair_list_init(&child_list_head); /* still used elsewhere */
67 child_list = &struct_vp->vp_group;
68 child_ctx = struct_vp;
69 key_vp = NULL;
70
71 /*
72 * Simplify the code by having a generic decode routine.
73 */
75
76 /*
77 * Decode structs with length prefixes.
78 */
80 size_t claimed_len, field_len, calc_len;
81
82 /*
83 * Set how many bytes there are in the "length" field.
84 */
86 field_len = 1;
87 } else {
89 field_len = 2;
90 }
91
92 if ((size_t) (end - p) < field_len) {
93 FR_PROTO_TRACE("Insufficient room for length field");
94
95 invalid_struct:
96 /*
97 * Some field could not be decoded. Nuke the entire struct, and just make the
98 * whole thing "raw".
99 */
100 TALLOC_FREE(struct_vp);
101
102 slen = fr_pair_raw_from_network(ctx, out, parent, data, data_len);
103 if (slen < 0) return slen;
104 return data_len;
105 }
106
107 claimed_len = p[0];
108 if (field_len > 1) {
109 claimed_len <<= 8;
110 claimed_len |= p[1];
111 }
112 p += field_len;
113
114 if (claimed_len < da_length_offset(parent)) {
115 FR_PROTO_TRACE("Length header (%zu) is smaller than minimum value (%u)",
116 claimed_len, parent->flags.type_size);
117 goto invalid_struct;
118 }
119
120 /*
121 * Get the calculated length of the actual data.
122 */
123 calc_len = claimed_len - da_length_offset(parent);
124
125 if (calc_len > (size_t) (end - p)) {
126 FR_PROTO_TRACE("Length header (%zu) is larger than remaining data (%zu)",
127 claimed_len + field_len, (size_t) (end - p));
128 goto invalid_struct;
129 }
130
131 /*
132 * Limit the size of the decoded structure to the correct length.
133 */
134 data_len = calc_len;
135 end = p + data_len;
136 }
137
138 /*
139 * @todo - If the struct is truncated on a MEMBER boundary, we silently omit
140 * the trailing members. Maybe this should be an error?
141 */
142 for (child_num = 1;
143 (p < end) && (child = fr_dict_attr_child_by_num(parent, child_num)) != NULL;
144 child_num++) {
145 FR_PROTO_TRACE("Decoding struct %s child %s (%d)", parent->name, child->name, child->attr);
146 FR_PROTO_HEX_DUMP(p, (end - p), "fr_struct_from_network - remaining %zu", (size_t) (end - p));
147
148 /*
149 * Check for bit fields.
150 */
151 if (da_is_bit_field(child)) {
152 uint8_t array[8];
153 unsigned int num_bits;
154 uint64_t value;
155
156 num_bits = offset + child->flags.length;
157 if ((size_t)(end - p) < fr_bytes_from_bits(num_bits)) {
158 FR_PROTO_TRACE("not enough data for bit decoder?");
159 goto remainder_raw;
160 }
161
162 memset(array, 0, sizeof(array));
163 memcpy(&array[0], p, fr_bytes_from_bits(num_bits));
164
165 if (offset > 0) array[0] &= (1 << (8 - offset)) - 1; /* mask off bits we don't care about */
166
167 memcpy(&value, &array[0], sizeof(value));
168 value = htonll(value);
169 value >>= (8 - offset); /* move it to the lower bits */
170 value >>= (56 - child->flags.length);
171
172 vp = fr_pair_afrom_da(child_ctx, child);
173 if (!vp) {
174 FR_PROTO_TRACE("fr_struct_from_network - failed allocating child VP");
175 oom:
176 talloc_free(struct_vp);
177 return PAIR_DECODE_OOM;
178 }
179
180 switch (child->type) {
181 case FR_TYPE_BOOL:
182 vp->vp_bool = value;
183 break;
184
185 case FR_TYPE_UINT8:
186 vp->vp_uint8 = value;
187 break;
188
189 case FR_TYPE_UINT16:
190 vp->vp_uint16 = value;
191 break;
192
193 case FR_TYPE_UINT32:
194 vp->vp_uint32 = value;
195 break;
196
197 case FR_TYPE_UINT64:
198 vp->vp_uint64 = value;
199 break;
200
201 default:
202 FR_PROTO_TRACE("Can't decode unknown type?");
203 goto remainder_raw;
204 }
205
206 vp->vp_tainted = true;
207 fr_pair_append(child_list, vp);
208
209 p += (num_bits >> 3); /* go to the LAST bit, not the byte AFTER the last bit */
210 offset = num_bits & 0x07;
211 continue;
212 }
213
214 fr_assert(offset == 0);
215 offset = 0; /* reset for non-bit-field attributes */
216
217 /*
218 * The child is either unknown width, OR known width with a length that is too large for
219 * the "length" field, OR is known width via some kind of protocol-specific length header.
220 */
221 if (!child->flags.length || child->flags.array) {
222 child_length = end - p;
223
224 } else {
225 child_length = child->flags.length;
226
227 /*
228 * If this field overflows the input, then *all*
229 * of the input is suspect.
230 */
231 if (child_length > (size_t) (end - p)) {
232 FR_PROTO_TRACE("fr_struct_from_network - child length %zu overflows buffer", child_length);
233 goto remainder_raw;
234 }
235 }
236
237 /*
238 * We only allow a limited number of data types
239 * inside of a struct.
240 */
241 switch (child->type) {
242 case FR_TYPE_INTERNAL:
243 case FR_TYPE_NULL:
244 FR_PROTO_TRACE("fr_struct_from_network - unknown child type");
245 goto remainder_raw;
246
247 case FR_TYPE_STRUCT:
248 case FR_TYPE_VSA:
249 case FR_TYPE_VENDOR:
250 case FR_TYPE_GROUP:
251 case FR_TYPE_LEAF:
252 break;
253
254 /*
255 * Decode child TLVs, according to the parent attribute.
256 */
257 case FR_TYPE_TLV:
258 fr_assert(!key_vp);
259
260 if (!decode_tlv) {
261 fr_strerror_const("Decoding TLVs requires a decode_tlv() function to be passed");
262 talloc_free(struct_vp);
263 return -(p - data);
264 }
265
266 /*
267 * Decode all of the remaining data as
268 * TLVs. Any malformed TLVs are appended
269 * as raw VP.
270 */
271 while (p < end) {
272 slen = decode_tlv(child_ctx, child_list, child, p, end - p, decode_ctx);
273 if (slen < 0) {
274 FR_PROTO_TRACE("failed decoding TLV?");
275 goto remainder_raw;
276 }
277 p += slen;
278 }
279
280 goto done;
281
282 /*
283 * The child is a union, it MUST be at the end of
284 * the struct, and we must have seen a key before
285 * we reach the union. See dict_tokenize.
286 */
287 case FR_TYPE_UNION:
289 if (!key_vp) {
290 remainder_raw:
291 child_length = end - p;
292 goto raw;
293 }
294
295 /*
296 * Create the union wrapper, and reset the child_ctx and child_list to it.
297 */
298 vp = fr_pair_afrom_da(child_ctx, child);
299 if (!vp) goto oom;
300
301 fr_pair_append(child_list, vp);
302 substruct_da = child;
303 child_ctx = vp;
304 child_list = &vp->vp_group;
305 goto substruct;
306 }
307
308 /*
309 * Magic values get the callback called.
310 *
311 * @todo - if this is an array of DNS labels, we
312 * need to do decompression checks on the entire
313 * block, and then decode each field
314 * individually.
315 */
316 if (child->flags.array) {
317 slen = fr_pair_array_from_network(child_ctx, child_list, child, p, child_length, decode_ctx, decode_value);
318 } else {
319 slen = decode_value(child_ctx, child_list, child, p, child_length, decode_ctx);
320 }
321 if (slen < 0) {
322 FR_PROTO_TRACE("Failed decoding value");
323
324 raw:
325 slen = fr_pair_raw_from_network(child_ctx, child_list, child, p, child_length);
326 if (slen < 0) {
327 talloc_free(struct_vp);
328 return slen;
329 }
330 }
331
332 p += slen; /* not always the same as child->flags.length */
333
334 if (fr_dict_attr_is_key_field(child)) {
335 fr_assert(!key_vp);
336 key_vp = fr_pair_list_tail(child_list);
337 }
338 }
339
340 /*
341 * Is there a substructure after this one? If so, go
342 * decode it.
343 */
344 if (key_vp) {
345 fr_dict_enum_value_t const *enumv;
346
347 substruct_da = key_vp->da;
348
349 substruct:
350 child = NULL;
351
352 FR_PROTO_TRACE("Key %s", key_vp->da->name);
353 FR_PROTO_HEX_DUMP(p, (end - p), "fr_struct_from_network - child structure");
354
355 /*
356 * Nothing more to decode, don't decode it.
357 */
358 if (p >= end) {
359 FR_PROTO_TRACE("Expected substruct, but there is none. We're done decoding this structure");
360 goto done;
361 }
362
363 enumv = fr_dict_enum_by_value(key_vp->da, &key_vp->data);
364 if (enumv) child = enumv->key_child_ref[0];
365
366 if (!child) {
367 FR_PROTO_TRACE("No matching child structure found");
368 unknown_child:
369 /*
370 * Always encode the unknown child as
371 * attribute number 0. Since the unknown
372 * children have no "real" number, and
373 * are all unique da's, they are
374 * incomparable. And thus can all be
375 * given the same number.
376 */
377 child = fr_dict_attr_unknown_raw_afrom_num(child_ctx, substruct_da, 0);
378 if (!child) {
379 FR_PROTO_TRACE("failed allocating unknown child for key VP %s - %s",
380 key_vp->da->name, fr_strerror());
381 goto oom;
382 }
383
384 slen = fr_pair_raw_from_network(child_ctx, child_list, child, p, end - p);
385 if (slen < 0) {
386 FR_PROTO_TRACE("Failed creating raw VP from malformed or unknown substruct for child %s", child->name);
388 return slen;
389 }
390
391 p = end;
392
393 } else {
394 switch (child->type) {
395 case FR_TYPE_STRUCT:
396 FR_PROTO_TRACE("Decoding child structure %s", child->name);
397 slen = fr_struct_from_network(child_ctx, child_list, child, p, end - p,
398 decode_ctx, decode_value, decode_tlv);
399 break;
400
401 case FR_TYPE_TLV:
402 if (!decode_tlv) {
403 FR_PROTO_TRACE("Failed to pass decode_tlv() for child tlv %s", child->name);
404 goto unknown_child;
405 }
406
407 FR_PROTO_TRACE("Decoding child tlv %s", child->name);
408
409 slen = decode_tlv(child_ctx, child_list, child, p, end - p, decode_ctx);
410 break;
411
412 case FR_TYPE_LEAF:
414
415 FR_PROTO_TRACE("Decoding child %s", child->name);
416
417 /*
418 * @todo - unify this code with the code above, but for now copying is
419 * easier.
420 */
421
422 /*
423 * The child is either unknown width, OR known width with a length that is too large for
424 * the "length" field, OR is known width via some kind of protocol-specific length header.
425 */
426 if (!child->flags.length || child->flags.array) {
427 child_length = end - p;
428
429 } else {
430 child_length = child->flags.length;
431
432 /*
433 * If this field overflows the input, then *all*
434 * of the input is suspect.
435 */
436 if (child_length > (size_t) (end - p)) {
437 FR_PROTO_TRACE("fr_struct_from_network - child length %zu overflows buffer", child_length);
438 goto remainder_raw;
439 }
440 }
441
442 if (child->flags.array) {
443 slen = fr_pair_array_from_network(child_ctx, child_list, child, p, child_length, decode_ctx, decode_value);
444 } else {
445 slen = decode_value(child_ctx, child_list, child, p, child_length, decode_ctx);
446 }
447 break;
448
449 default:
450 FR_PROTO_TRACE("Unknown data type %s in child %s", fr_type_to_str(child->type), child->name);
451 goto unknown_child;
452 }
453
454 if (slen <= 0) {
455 FR_PROTO_TRACE("failed decoding child %s", child->name);
456 goto unknown_child;
457 }
458 p += slen;
459 }
460
462 }
463
464done:
465 fr_assert(struct_vp != NULL);
466 fr_pair_append(out, struct_vp);
467
468 FR_PROTO_TRACE("used %zu bytes", data_len);
469 return p - data;
470}
471
472
473/** Put bits into an output dbuff
474 *
475 * @param dbuff where the bytes go
476 * @param p where leftover bits go
477 * @param start_bit start bit in the dbuff where the data goes, 0..7
478 * @param num_bits number of bits to write to the output, 0..55
479 * @param data data to write, all in the lower "num_bits" of the uint64_t variable
480 * @return
481 * >= 0 the next value to pass in for start_bit
482 * < 0 no space or invalid start_bit or num_bits parameter
483 */
484static int put_bits_dbuff(fr_dbuff_t *dbuff, uint8_t *p, int start_bit, uint8_t num_bits, uint64_t data)
485{
486 uint64_t used_bits;
487
488 if (start_bit < 0 || start_bit > 7) return -1;
489 if (num_bits < 1 || num_bits > 56) return -1;
490
491 /* Get bits buffered in *p */
492 used_bits = *p & (-256 >> start_bit);
493
494 /* Mask out all but the least significant num_bits bits of data */
495 data &= (((uint64_t) 1) << num_bits) - 1;
496
497 /* Move it towards the most significant end and put used_bits at the top */
498 data <<= (64 - (start_bit + num_bits));
499 data |= used_bits << 56;
500
501 data = htonll(data);
502
503 start_bit += num_bits;
504 if (start_bit > 7) FR_DBUFF_IN_MEMCPY_RETURN(dbuff, (uint8_t const *) &data, (size_t)(start_bit / 8));
505
506 *p = ((uint8_t *) &data)[start_bit / 8];
507 return start_bit % 8;
508}
509
510static int8_t pair_sort_increasing(void const *a, void const *b)
511{
512 fr_pair_t const *my_a = a;
513 fr_pair_t const *my_b = b;
514 int8_t ret;
515
516 /*
517 * Deeper attributes come later in the list.
518 */
519 ret = CMP_PREFER_SMALLER(my_a->da->depth, my_b->da->depth);
520 if (ret != 0) return ret;
521
522 return CMP_PREFER_SMALLER(my_a->da->attr, my_b->da->attr);
523}
524
525static void *struct_next_encodable(fr_dcursor_t *cursor, void *current, void *uctx)
526{
527 fr_pair_t *c = current;
528 fr_dict_attr_t *parent = talloc_get_type_abort(uctx, fr_dict_attr_t);
529
530 while ((c = fr_dlist_next(cursor->dlist, c))) {
531 PAIR_VERIFY(c);
532
533 if (c->da->dict != parent->dict || c->da->flags.internal) continue;
534 break;
535 }
536
537 return c;
538}
539
540static ssize_t encode_tlv(fr_dbuff_t *dbuff, fr_dict_attr_t const *tlv,
541 fr_da_stack_t *da_stack, unsigned int depth,
542 fr_dcursor_t *cursor, void *encode_ctx,
544
545{
546 fr_pair_t *vp;
547 fr_dcursor_t child_cursor;
548 fr_dbuff_t work_dbuff = FR_DBUFF(dbuff);
549
550 if (!encode_pair) {
551 fr_strerror_printf("Asked to encode child attribute %s, but we were not passed an encoding function",
552 tlv->name);
554 }
555
556 vp = fr_dcursor_current(cursor);
557 if (!vp || (vp->da != tlv)) return 0;
558
559 vp = fr_pair_dcursor_init(&child_cursor, &vp->vp_group);
560 if (vp) {
561 ssize_t slen;
562
563 FR_PROTO_TRACE("fr_struct_to_network trailing TLVs of %s", tlv->name);
564 fr_proto_da_stack_build(da_stack, vp->da);
565 FR_PROTO_STACK_PRINT(da_stack, depth);
566
567 slen = fr_pair_cursor_to_network(&work_dbuff, da_stack, depth + 1, &child_cursor, encode_ctx, encode_pair);
568 if (slen < 0) return slen;
569 }
570
571 return fr_dbuff_set(dbuff, &work_dbuff);
572}
573
574static ssize_t encode_union(fr_dbuff_t *dbuff, fr_dict_attr_t const *wrapper,
575 fr_dict_attr_t const *key_da, fr_pair_t const *key_vp, fr_dbuff_marker_t *key_m,
576 fr_da_stack_t *da_stack, unsigned int depth,
577 fr_dcursor_t *cursor, void *encode_ctx,
579
580{
581 ssize_t slen;
582 fr_pair_t *parent, *child, *found = NULL;
583 fr_dcursor_t child_cursor;
584 fr_dbuff_t work_dbuff = FR_DBUFF(dbuff);
585
586 if (!encode_pair) {
587 fr_strerror_printf("Asked to encode child attribute %s, but we were not passed an encoding function",
588 wrapper->name);
590 }
591
592 parent = fr_dcursor_current(cursor);
593 if (!parent || (parent->da != wrapper)) return 0;
594
595 fr_assert(key_vp); /* @todo */
596
597 child = fr_pair_dcursor_init(&child_cursor, &parent->vp_group);
598 if (!child) {
599 /*
600 * @todo - do we want to skip encoding the entire parent structure?
601 */
602 FR_PROTO_TRACE("fr_struct_to_network union %s has no children", key_da->name);
603 return 0;
604 }
605
606 /*
607 * There's a key VP, we find the matching child struct, and then set the cursor to encode just
608 * that child.
609 */
610 if (key_vp) {
611 fr_dict_enum_value_t const *enumv;
612
613 enumv = fr_dict_enum_by_value(key_da, &key_vp->data);
614 if (enumv) {
615 found = fr_pair_find_by_da(&parent->vp_group, NULL, enumv->key_child_ref[0]);
616 if (found) {
617 (void) fr_dcursor_set_current(&child_cursor, found);
618 }
619 }
620 }
621
622 /*
623 * No child matching the key vp was found. Either there's no key_vp, or the key_vp doesn't match
624 * the chld we have.
625 *
626 * We then update the key field so that it corresponds to the child that we found.
627 */
628 if (!found) {
629 fr_dict_enum_value_t const *enumv;
631 fr_dbuff_t key_dbuff;
632
633 /*
634 * Root through the enum values, looking for a child ref which matches the child we
635 * found.
636 */
637 for (enumv = fr_dict_enum_iter_init(key_da, &iter);
638 enumv != NULL;
639 enumv = fr_dict_enum_iter_next(key_da, &iter)) {
640 if (enumv->key_child_ref[0] == child->da) break;
641 }
642
643 /*
644 * There's a child, but no matching enum. That's a fatal error of the dictionary
645 * tokenizer.
646 */
647 if (!fr_cond_assert(enumv)) return PAIR_ENCODE_FATAL_ERROR;
648
649 /*
650 * Create a dbuff for the key, and encode the key.
651 *
652 * Note that enumv->value->vb_length is NOT set. That field is really only used for
653 * string / octet data types.
654 */
655 fr_assert(key_da->flags.length >= 1);
656 fr_assert(key_da->flags.length <= 4);
657
658 FR_DBUFF_INIT(&key_dbuff, fr_dbuff_current(key_m), (size_t) key_da->flags.length);
659
660 FR_PROTO_TRACE("fr_struct_to_network union %s encoding key %s for child %s",
661 parent->da->name, key_da->name, child->da->name);
662
663 if (fr_value_box_to_network(&key_dbuff, enumv->value) <= 0) return PAIR_ENCODE_FATAL_ERROR;
664 }
665
666 /*
667 * And finally encode the one child.
668 */
669 FR_PROTO_TRACE("fr_struct_to_network union %s encoding child %s", parent->da->name, child->da->name);
670 fr_proto_da_stack_build(da_stack, child->da);
671 FR_PROTO_STACK_PRINT(da_stack, depth);
672
673 switch (child->da->type) {
674 case FR_TYPE_STRUCT:
675 slen = fr_struct_to_network(&work_dbuff, da_stack, depth + 2,
676 &child_cursor, encode_ctx, encode_value, encode_pair);
677 break;
678
679 case FR_TYPE_TLV:
680 slen = encode_tlv(&work_dbuff, child->da, da_stack, depth + 2, &child_cursor, encode_ctx, encode_value, encode_pair);
681 break;
682
683 case FR_TYPE_LEAF:
684 slen = encode_value(&work_dbuff, da_stack, depth + 2, &child_cursor, encode_ctx);
685 break;
686
687 default:
688 slen = 0;
689 break;
690 }
691
692 if (slen < 0) return slen;
693
694 /*
695 * @todo - if there is more than one child of the union, that's an error!
696 */
697
698 return fr_dbuff_set(dbuff, &work_dbuff);
699}
700
702 fr_da_stack_t *da_stack, unsigned int depth,
703 fr_dcursor_t *cursor, void *encode_ctx,
705{
706 FR_PROTO_TRACE("fr_struct_to_network encoding key %s", vp->da->name);
707
708 /*
709 * We usually have a keyed struct for the child.
710 */
711 if (vp->vp_type == FR_TYPE_STRUCT) {
712 fr_proto_da_stack_build(da_stack, vp->da);
713 return fr_struct_to_network(dbuff, da_stack, depth + 2, /* note + 2 !!! */
715 }
716
717 /*
718 * If it's not a real child, then it's a raw something.
719 */
720 fr_assert(vp->vp_type == FR_TYPE_OCTETS);
721 fr_assert(vp->da->flags.is_unknown);
722
723 if (fr_value_box_to_network(dbuff, &vp->data) <= 0) return PAIR_ENCODE_FATAL_ERROR;
724 (void) fr_dcursor_next(cursor);
725 return 0;
726}
727
729 fr_da_stack_t *da_stack, unsigned int depth,
730 fr_dcursor_t *parent_cursor, void *encode_ctx,
732{
733 fr_dbuff_t work_dbuff;
735 int offset = 0;
736 unsigned int child_num;
737 bool do_length = false;
738 uint8_t bit_buffer = 0;
739 fr_pair_t const *vp = fr_dcursor_current(parent_cursor);
740 fr_pair_t const *key_vp = NULL;
741 fr_dict_attr_t const *child, *parent, *key_da = NULL;
742 fr_dcursor_t child_cursor, *cursor;
743 size_t prefix_length = 0;
744 ssize_t slen;
745 fr_dbuff_marker_t key_m;
746
747 if (!vp) {
748 fr_strerror_printf("%s: Can't encode empty struct", __FUNCTION__);
750 }
751
753 parent = da_stack->da[depth];
754
755 if (parent->type != FR_TYPE_STRUCT) {
756 fr_strerror_printf("%s: Expected type \"struct\" got \"%s\"", __FUNCTION__,
757 fr_type_to_str(parent->type));
759 }
760
761 /*
762 * If we get passed a struct VP, sort its children.
763 */
764 if (vp->vp_type == FR_TYPE_STRUCT) {
765 fr_pair_t *sorted = fr_dcursor_current(parent_cursor); /* NOT const */
766
767 fr_pair_list_sort(&sorted->vp_group, pair_sort_increasing);
768 fr_pair_dcursor_iter_init(&child_cursor, &sorted->vp_group, struct_next_encodable, parent);
769
770 /*
771 * Build the da_stack for the new structure.
772 */
773 vp = fr_dcursor_current(&child_cursor);
774 fr_proto_da_stack_build(da_stack, vp ? vp->da : NULL);
775
776 FR_PROTO_TRACE("fr_struct_to_network encoding nested with parent %s", parent->name);
777 cursor = &child_cursor;
778 } else {
779 FR_PROTO_TRACE("fr_struct_to_network encoding flat");
780 cursor = parent_cursor;
781 }
782
783 /*
784 * @todo - if we get a child which *eventually* has the
785 * given parent, then allow encoding of that struct, too.
786 * This allows us to encode structures automatically,
787 * even if key fields are omitted.
788 *
789 * Note that this check catches TLVs which are "flat" and
790 * not nested. We could fix that by adding a special
791 * case, but it's better to just fix everything to handle
792 * nested attributes.
793 */
794 if (vp && (vp->da->parent != parent)) {
795 fr_strerror_printf("%s: Asked to encode %s, but its parent %s is not the expected parent %s",
796 __FUNCTION__, vp->da->name, vp->da->parent->name, parent->name);
798 }
799
800 /*
801 * Some structs are prefixed by a 16-bit length.
802 */
804 work_dbuff = FR_DBUFF(dbuff);
805
806 } else if (da_is_length_field8(parent)) {
807 work_dbuff = FR_DBUFF_MAX(dbuff, UINT8_MAX);
808 fr_dbuff_marker(&hdr, &work_dbuff);
809
810 FR_DBUFF_ADVANCE_RETURN(&work_dbuff, 1);
811 prefix_length = 1;
812 do_length = true;
813
814 } else {
816
817 work_dbuff = FR_DBUFF_MAX(dbuff, UINT16_MAX);
818 fr_dbuff_marker(&hdr, &work_dbuff);
819
820 FR_DBUFF_ADVANCE_RETURN(&work_dbuff, 2);
821 prefix_length = 2;
822 do_length = true;
823 }
824
826
827 /*
828 * Loop over all children.
829 */
830 for (child_num = 1;
831 (child = fr_dict_attr_child_by_num(parent, child_num)) != NULL;
832 child_num++) {
833 /*
834 * The child attributes should be in order. If
835 * they're not, we fill the struct with zeroes.
836 *
837 * The caller will encode TLVs.
838 */
839 FR_PROTO_TRACE("fr_struct_to_network child %s", child->name);
840
841 /*
842 * The MEMBER may be raw, in which case it is encoded as octets.
843 *
844 * This can happen for the last MEMBER of a struct, such as when the last member is a TLV
845 * or GROUP, and the contents are malformed.
846 *
847 * It can also happen if a middle MEMBER has the right length, but the wrong contents.
848 * e.g. when the contents have to be a well-formed IP prefix, but the prefix values are
849 * out of the permitted range.
850 */
851 if (vp && (vp->da != child) && (vp->da->parent == parent) && (vp->da->attr == child_num)) {
852 fr_assert(vp->vp_raw);
853 fr_assert(vp->vp_type == FR_TYPE_OCTETS);
854 fr_assert(!da_is_bit_field(child));
855
856 goto encode_data; /* we may have a raw entry in an array :( */
857 }
858
859 /*
860 * Remember the key field. Note that we ignore raw key fields.
861 */
862 if (fr_dict_attr_is_key_field(child)) {
863 fr_assert(!key_da);
864
865 key_da = child;
866 key_vp = vp;
867 fr_dbuff_marker(&key_m, &work_dbuff);
868 }
869
870 /*
871 * Skipped a VP, or left one off at the end, fill the struct with zeros.
872 */
873 if (!vp || (vp->da != child)) {
874 FR_PROTO_HEX_DUMP(fr_dbuff_start(&work_dbuff), fr_dbuff_used(&work_dbuff), " no child %s", child->name);
875
876 /*
877 * Zero out the bit field.
878 */
879 if (da_is_bit_field(child)) {
880 offset = put_bits_dbuff(&work_dbuff, &bit_buffer, offset, child->flags.length, 0);
881 if (offset < 0) {
882 fr_strerror_printf("Failed encoding bit field %s", child->name);
883 return offset;
884 }
885 continue;
886 }
887
888 /*
889 * A child TLV is missing, we're done, and we don't encode any data.
890 *
891 * @todo - mark up the TLVs as required?
892 */
893 if (child->type == FR_TYPE_TLV) goto encode_length;
894
895 /*
896 * Zero out the unused field.
897 */
898 FR_DBUFF_MEMSET_RETURN(&work_dbuff, 0, child->flags.length);
899 continue;
900 }
901
902 /*
903 * The 'struct' encoder handles bit fields.
904 * They're just integers, so there's no need to
905 * call the protocol encoder.
906 *
907 * This limitation means that we can't have
908 * encrypted bit fields, but that's fine.
909 */
910 if (da_is_bit_field(child)) {
911 uint64_t value;
912
913 FR_PROTO_TRACE("child %s is a bit field", child->name);
914
915 switch (child->type) {
916 case FR_TYPE_BOOL:
917 value = vp->vp_bool;
918 break;
919
920 case FR_TYPE_UINT8:
921 value = vp->vp_uint8;
922 break;
923
924 case FR_TYPE_UINT16:
925 value = vp->vp_uint16;
926 break;
927
928 case FR_TYPE_UINT32:
929 value = vp->vp_uint32;
930 break;
931
932 case FR_TYPE_UINT64:
933 value = vp->vp_uint64;
934 break;
935
936 default:
937 fr_strerror_const("Invalid bit field");
939 }
940
941 offset = put_bits_dbuff(&work_dbuff, &bit_buffer, offset, child->flags.length, value);
942 if (offset < 0) {
943 fr_strerror_printf("Failed encoding bit field %s", child->name);
944 return offset;
945 }
946
947 vp = fr_dcursor_next(cursor);
948 /* We need to continue, there may be more fields to encode */
949
950 goto next;
951 }
952
953 /* Not a bit field; insist that no buffered bits remain. */
954 if (offset != 0) {
955 leftover_bits:
956 fr_strerror_const("leftover bits");
958 }
959
960 /*
961 * Encode child TLVs at the end of a struct.
962 *
963 * In order to encode the child TLVs, we need to
964 * know the length of "T" and "L", and we don't.
965 * So just let the caller do the work.
966 */
967 if (child->type == FR_TYPE_TLV) {
968 fr_assert(!key_da);
969
970 FR_PROTO_TRACE("child %s is a TLV field", child->name);
971 slen = encode_tlv(&work_dbuff, child, da_stack, depth, cursor,
973 if (slen < 0) return slen;
974 goto encode_length;
975 }
976
977 if (child->type == FR_TYPE_UNION) {
978 FR_PROTO_TRACE("child %s is a UNION field", child->name);
979
980 if (!key_da) {
981 FR_PROTO_TRACE("child %s is missing key_da", child->name);
982 goto encode_length;
983 }
984
985 slen = encode_union(&work_dbuff, child, key_da, key_vp, &key_m, da_stack, depth, cursor,
987 if (slen < 0) return slen;
988 goto encode_length;
989 }
990
991 FR_PROTO_TRACE("child %s encode_value", child->name);
992
993 /*
994 * Call the protocol encoder for non-bit fields.
995 */
997 fr_proto_da_stack_build(da_stack, child);
998
999 if (child->flags.array) {
1000 slen = fr_pair_array_to_network(&work_dbuff, da_stack, depth + 1, cursor, encode_ctx, encode_value);
1001 } else {
1002 slen = encode_value(&work_dbuff, da_stack, depth + 1, cursor, encode_ctx);
1003 }
1004 if (slen < 0) return slen;
1005 vp = fr_dcursor_current(cursor);
1006
1007 next:
1008 FR_PROTO_HEX_DUMP(fr_dbuff_start(&work_dbuff), fr_dbuff_used(&work_dbuff), "fr_struct_to_network after child %s", child->name);
1009 }
1010
1011 /* Check for leftover bits */
1012 if (offset != 0) goto leftover_bits;
1013
1014 /*
1015 * Check for keyed data to encode.
1016 */
1017 if (vp && key_da) {
1018 /*
1019 * We have no more "flat" VPs.
1020 */
1021 fr_assert(vp->da->parent == key_da);
1022
1023 slen = encode_keyed_struct(&work_dbuff, vp, da_stack, depth,
1025 if (slen < 0) return slen;
1026 }
1027
1028encode_length:
1029 if (do_length) {
1030 size_t length = fr_dbuff_used(&work_dbuff);
1031
1032#ifdef __COVERITY__
1033 /*
1034 * Coverity somehow can't infer that length
1035 * is at least as long as the prefix, instead
1036 * thinkings it's zero so that it underflows.
1037 * We therefore add a Coverity-only check to
1038 * reassure it.
1039 */
1040 if (length < prefix_length) return PAIR_ENCODE_FATAL_ERROR;
1041#endif
1043 length -= prefix_length;
1044
1045 length += da_length_offset(parent);
1046
1047 if (length > UINT8_MAX) return PAIR_ENCODE_FATAL_ERROR;
1048
1049 (void) fr_dbuff_in(&hdr, (uint8_t) length);
1050 } else {
1051 length -= prefix_length;
1052
1053 length += da_length_offset(parent);
1054
1055 if (length > UINT16_MAX) return PAIR_ENCODE_FATAL_ERROR;
1056
1057 (void) fr_dbuff_in(&hdr, (uint16_t) length);
1058 }
1059 }
1060
1061 /*
1062 * We've encoded the children, so tell the parent cursor
1063 * that we've encoded the parent.
1064 */
1065 if (cursor != parent_cursor) (void) fr_dcursor_next(parent_cursor);
1066
1067 FR_PROTO_HEX_DUMP(fr_dbuff_start(&work_dbuff), fr_dbuff_used(&work_dbuff), "Done fr_struct_to_network");
1068
1069 return fr_dbuff_set(dbuff, &work_dbuff);
1070}
#define RCSID(id)
Definition build.h:485
#define CMP_PREFER_SMALLER(_a, _b)
Evaluates to +1 for a > b, and -1 for a < b.
Definition build.h:104
#define UNUSED
Definition build.h:317
#define fr_dbuff_used(_dbuff_or_marker)
Return the number of bytes remaining between the start of the dbuff or marker and the current positio...
Definition dbuff.h:769
#define FR_DBUFF_ADVANCE_RETURN(_dbuff_or_marker, _len)
Advance the 'current' position in dbuff or marker by _len bytes returning if _len is out of range.
Definition dbuff.h:1091
struct fr_dbuff_marker_s fr_dbuff_marker_t
A position marker associated with a dbuff.
Definition dbuff.h:83
#define fr_dbuff_current(_dbuff_or_marker)
Return the 'current' position of a dbuff or marker.
Definition dbuff.h:913
#define fr_dbuff_set(_dst, _src)
Set the 'current' position in a dbuff or marker using another dbuff or marker, a char pointer,...
Definition dbuff.h:1006
#define fr_dbuff_start(_dbuff_or_marker)
Return the 'start' position of a dbuff or marker.
Definition dbuff.h:900
#define FR_DBUFF_INIT(_out, _start, _len_or_end)
Definition dbuff.h:379
#define FR_DBUFF_MEMSET_RETURN(_dbuff_or_marker, _c, _inlen)
Set _inlen bytes of a dbuff or marker to _c returning if there is insufficient space.
Definition dbuff.h:1511
static uint8_t * fr_dbuff_marker(fr_dbuff_marker_t *m, fr_dbuff_t *dbuff)
Initialises a new marker pointing to the 'current' position of the dbuff.
Definition dbuff.h:1195
#define FR_DBUFF_IN_MEMCPY_RETURN(_dbuff_or_marker, _in, _inlen)
Copy exactly _inlen bytes into dbuff or marker returning if there's insufficient space.
Definition dbuff.h:1385
#define fr_dbuff_in(_dbuff_or_marker, _in)
Copy data from a fixed sized C type into a dbuff or marker.
Definition dbuff.h:1570
#define FR_DBUFF(_dbuff_or_marker)
Create a new dbuff pointing to the same underlying buffer.
Definition dbuff.h:224
#define FR_DBUFF_MAX(_dbuff_or_marker, _max)
Limit the maximum number of bytes available in the dbuff when passing it to another function.
Definition dbuff.h:303
static void * fr_dcursor_next(fr_dcursor_t *cursor)
Advanced the cursor to the next item.
Definition dcursor.h:290
static void * fr_dcursor_set_current(fr_dcursor_t *cursor, void *item)
Set the cursor to a specified item.
Definition dcursor.h:355
static void * fr_dcursor_current(fr_dcursor_t *cursor)
Return the item the cursor current points to.
Definition dcursor.h:339
fr_dlist_head_t * dlist
Head of the doubly linked list being iterated over.
Definition dcursor.h:94
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
Definition debug.h:131
ssize_t(* fr_pair_decode_value_t)(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t const data_len, void *decode_ctx)
Decode a value from the network into an output fr_pair_list_t.
Definition decode.h:45
#define da_is_length_field16(_da)
Definition dict.h:173
#define da_length_offset(_da)
Definition dict.h:174
fr_dict_enum_value_t const * fr_dict_enum_iter_init(fr_dict_attr_t const *da, fr_dict_enum_iter_t *iter)
Iterate over all enumeration values for an attribute.
Definition dict_util.c:3445
#define da_is_length_field8(_da)
Definition dict.h:172
static fr_dict_attr_t * fr_dict_attr_unknown_raw_afrom_num(TALLOC_CTX *ctx, fr_dict_attr_t const *parent, unsigned int attr)
Definition dict.h:608
#define da_is_bit_field(_da)
Definition dict.h:170
fr_value_box_t const * value
Enum value (what name maps to).
Definition dict.h:250
fr_dict_enum_value_t const * fr_dict_enum_iter_next(fr_dict_attr_t const *da, fr_dict_enum_iter_t *iter)
Definition dict_util.c:3466
void fr_dict_attr_unknown_free(fr_dict_attr_t const **da)
Free dynamically allocated (unknown attributes)
fr_dict_enum_value_t const * fr_dict_enum_by_value(fr_dict_attr_t const *da, fr_value_box_t const *value)
Lookup the structure representing an enum value in a fr_dict_attr_t.
Definition dict_util.c:3486
#define da_is_length_field(_da)
Definition dict.h:171
fr_dict_attr_t const * fr_dict_attr_child_by_num(fr_dict_attr_t const *parent, unsigned int attr)
Check if a child attribute exists in a parent using an attribute number.
Definition dict_util.c:3424
fr_dict_attr_t const * key_child_ref[]
for key fields
Definition dict.h:254
#define fr_dict_attr_is_key_field(_da)
Definition dict.h:169
Value of an enumerated attribute.
Definition dict.h:246
Test enumeration values.
Definition dict_test.h:92
static void * fr_dlist_next(fr_dlist_head_t const *list_head, void const *ptr)
Get the next item in a list.
Definition dlist.h:555
ssize_t(* fr_encode_dbuff_t)(fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx)
Typedefs for simplifying the use and declaration of protocol encoders.
Definition encode.h:37
Stores the state of the current iteration operation.
Definition hash.h:41
#define PAIR_DECODE_OOM
Fatal error - Out of memory.
Definition pair.h:45
#define PAIR_ENCODE_FATAL_ERROR
Fatal encoding error.
Definition pair.h:36
static ssize_t encode_value(fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, int depth, fr_dcursor_t *cursor, void *encode_ctx)
Encodes the data portion of an attribute.
Definition encode.c:277
ssize_t fr_pair_decode_value(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t const data_len, UNUSED void *decode_ctx)
Generic decode value.
Definition decode.c:329
ssize_t fr_pair_raw_from_network(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *da, uint8_t const *data, size_t data_len)
Create a "raw" pair from malformed network data.
Definition decode.c:79
ssize_t fr_pair_array_from_network(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx, fr_pair_decode_value_t decode_value)
Decode an array of values from the network.
Definition decode.c:41
ssize_t fr_pair_array_to_network(fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, int depth, fr_dcursor_t *cursor, void *encode_ctx, fr_encode_dbuff_t encode_value)
Encode an array of values from the network.
Definition encode.c:42
ssize_t fr_pair_encode_value(fr_dbuff_t *dbuff, UNUSED fr_da_stack_t *da_stack, UNUSED unsigned int depth, fr_dcursor_t *cursor, UNUSED void *encode_ctx)
Generic encode value.
Definition encode.c:162
ssize_t fr_pair_cursor_to_network(fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx, fr_encode_dbuff_t encode_pair)
Definition encode.c:71
talloc_free(reap)
unsigned short uint16_t
@ FR_TYPE_TLV
Contains nested attributes.
@ FR_TYPE_NULL
Invalid (uninitialised) attribute type.
@ FR_TYPE_UINT16
16 Bit unsigned integer.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_STRUCT
like TLV, but without T or L, and fixed-width children
@ FR_TYPE_VENDOR
Attribute that represents a vendor in the attribute tree.
@ FR_TYPE_UINT64
64 Bit unsigned integer.
@ FR_TYPE_BOOL
A truth value.
@ FR_TYPE_VSA
Vendor-Specific, for RADIUS attribute 26.
@ FR_TYPE_OCTETS
Raw octets.
@ FR_TYPE_GROUP
A grouping of other attributes.
long int ssize_t
unsigned char uint8_t
#define UINT8_MAX
static uint8_t depth(fr_minmax_heap_index_t i)
Definition minmax_heap.c:83
static unsigned int fr_bytes_from_bits(unsigned int bits)
Convert bits (as in prefix length) to bytes, rounding up.
Definition nbo.h:237
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
Definition pair.c:708
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
Definition pair.c:1353
fr_pair_t * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute and assign a fr_dict_attr_t.
Definition pair.c:287
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
Definition pair.c:46
void fr_proto_da_stack_build(fr_da_stack_t *stack, fr_dict_attr_t const *da)
Build a complete DA stack from the da back to the root.
Definition proto.c:118
static fr_internal_encode_ctx_t encode_ctx
static ssize_t encode_pair(fr_dbuff_t *dbuff, fr_dcursor_t *cursor, UNUSED void *encode_ctx)
Definition base.c:39
#define decode_value
Definition decode.c:410
#define fr_assert(_expr)
Definition rad_assert.h:38
static rc_request_t * current
static bool done
Definition radclient.c:81
fr_pair_t * vp
static ssize_t encode_keyed_struct(fr_dbuff_t *dbuff, fr_pair_t const *vp, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx, fr_encode_dbuff_t encode_value, fr_encode_dbuff_t encode_pair)
Definition struct.c:701
static ssize_t encode_tlv(fr_dbuff_t *dbuff, fr_dict_attr_t const *tlv, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx, UNUSED fr_encode_dbuff_t encode_value, fr_encode_dbuff_t encode_pair)
Definition struct.c:540
ssize_t fr_struct_to_network(fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *parent_cursor, void *encode_ctx, fr_encode_dbuff_t encode_value, fr_encode_dbuff_t encode_pair)
Definition struct.c:728
static void * struct_next_encodable(fr_dcursor_t *cursor, void *current, void *uctx)
Definition struct.c:525
static ssize_t encode_union(fr_dbuff_t *dbuff, fr_dict_attr_t const *wrapper, fr_dict_attr_t const *key_da, fr_pair_t const *key_vp, fr_dbuff_marker_t *key_m, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx, UNUSED fr_encode_dbuff_t encode_value, fr_encode_dbuff_t encode_pair)
Definition struct.c:574
static int8_t pair_sort_increasing(void const *a, void const *b)
Definition struct.c:510
static int put_bits_dbuff(fr_dbuff_t *dbuff, uint8_t *p, int start_bit, uint8_t num_bits, uint64_t data)
Put bits into an output dbuff.
Definition struct.c:484
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, void *decode_ctx, fr_pair_decode_value_t decode_value, fr_pair_decode_value_t decode_tlv)
Convert a STRUCT to one or more VPs.
Definition struct.c:32
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
Definition pair.h:69
static ssize_t encode_data(char *p, uint8_t *output, size_t outlen)
#define fr_pair_dcursor_iter_init(_cursor, _list, _iter, _uctx)
Initialises a special dcursor with callbacks that will maintain the attr sublists correctly.
Definition pair.h:569
#define PAIR_VERIFY(_x)
Definition pair.h:193
void fr_pair_list_sort(fr_pair_list_t *list, fr_cmp_t cmp)
Sort a doubly linked list of fr_pair_ts using merge sort.
fr_pair_t * fr_pair_list_tail(fr_pair_list_t const *list)
Get the tail of a valuepair list.
Definition pair_inline.c:55
#define fr_pair_dcursor_init(_cursor, _list)
Initialises a special dcursor with callbacks that will maintain the attr sublists correctly.
Definition pair.h:589
static fr_slen_t parent
Definition pair.h:841
#define FR_PROTO_HEX_DUMP(_data, _data_len, _fmt,...)
Definition proto.h:42
#define FR_PROTO_TRACE(_fmt,...)
Definition proto.h:41
#define FR_PROTO_STACK_PRINT(_stack, _depth)
Definition proto.h:44
fr_dict_attr_t const * da[FR_DICT_MAX_TLV_STACK+1]
The stack.
Definition proto.h:57
Structure for holding the stack of dictionary attributes being encoded.
Definition proto.h:55
char const * fr_strerror(void)
Get the last library error.
Definition strerror.c:553
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
Definition strerror.h:64
#define fr_strerror_const(_msg)
Definition strerror.h:223
@ FR_TYPE_UNION
A union of limited children.
Definition types.h:82
#define FR_TYPE_INTERNAL
Definition types.h:320
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
Definition types.h:455
#define FR_TYPE_LEAF
Definition types.h:318
ssize_t fr_value_box_to_network(fr_dbuff_t *dbuff, fr_value_box_t const *value)
Encode a single value box, serializing its contents in generic network format.
Definition value.c:1516
static fr_slen_t data
Definition value.h:1293
static size_t char ** out
Definition value.h:1023