The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
decode.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/**
18 * $Id: 85e1cdf59923173579798d0f0ce5826c3386c2d8 $
19 *
20 * @file protocols/dhcpv6/decode.c
21 * @brief Functions to decode DHCP options.
22 *
23 * @author Arran Cudbard-Bell (a.cudbardb@freeradius.org)
24 *
25 * @copyright 2018 The FreeRADIUS server project
26 * @copyright 2018 NetworkRADIUS SARL (legal@networkradius.com)
27 */
28#include <stdint.h>
29#include <stddef.h>
30
31#include <freeradius-devel/io/test_point.h>
32#include <freeradius-devel/util/dns.h>
33#include <freeradius-devel/util/proto.h>
34#include <freeradius-devel/util/struct.h>
35
36#include "dhcpv6.h"
37#include "attrs.h"
38
39/*
40 * RFC 8415 Section 21.7 defines option codes that MUST NOT appear
41 * in an Option Request option. We convert the attributes to a
42 * 64-bit number which can be easily checked.
43 */
44#define DHCPV6_ORO_FORBIDDEN \
45 ((1ULL << 1) | /* OPTION_CLIENTID */ \
46 (1ULL << 2) | /* OPTION_SERVERID */ \
47 (1ULL << 3) | /* OPTION_IA_NA */ \
48 (1ULL << 4) | /* OPTION_IA_TA */ \
49 (1ULL << 5) | /* OPTION_IAADDR */ \
50 (1ULL << 6) | /* OPTION_ORO */ \
51 (1ULL << 7) | /* OPTION_PREFERENCE */ \
52 (1ULL << 8) | /* OPTION_ELAPSED_TIME */ \
53 (1ULL << 9) | /* OPTION_RELAY_MSG */ \
54 (1ULL << 11) | /* OPTION_AUTH */ \
55 (1ULL << 12) | /* OPTION_UNICAST */ \
56 (1ULL << 13) | /* OPTION_STATUS_CODE */ \
57 (1ULL << 14) | /* OPTION_RAPID_COMMIT */ \
58 (1ULL << 15) | /* OPTION_USER_CLASS */ \
59 (1ULL << 16) | /* OPTION_VENDOR_CLASS */ \
60 (1ULL << 18) | /* OPTION_INTERFACE_ID */ \
61 (1ULL << 19) | /* OPTION_RECONF_MSG */ \
62 (1ULL << 20) | /* OPTION_RECONF_ACCEPT */ \
63 (1ULL << 25) | /* OPTION_IA_PD */ \
64 (1ULL << 26)) /* OPTION_IAPREFIX */
65
66static ssize_t decode_option(TALLOC_CTX *ctx, fr_pair_list_t *out,
68 uint8_t const *data, size_t const data_len, void *decode_ctx);
69
72 uint8_t const *data, size_t const data_len, void *decode_ctx)
73{
74 return fr_pair_tlvs_from_network(ctx, out, parent, data, data_len, decode_ctx, decode_option, NULL, true);
75}
76
77static ssize_t decode_value(TALLOC_CTX *ctx, fr_pair_list_t *out,
79 uint8_t const *data, size_t const data_len, void *decode_ctx);
80
81/** Handle arrays of DNS labels for fr_struct_from_network()
82 *
83 */
86 uint8_t const *data, size_t const data_len, void *decode_ctx)
87{
89 return fr_pair_dns_labels_from_network(ctx, out, parent, data, data, data_len, NULL, false);
90 }
91
92 return decode_value(ctx, out, parent, data, data_len, decode_ctx);
93}
94
95
96static ssize_t decode_value(TALLOC_CTX *ctx, fr_pair_list_t *out,
98 uint8_t const *data, size_t const data_len, void *decode_ctx)
99{
100 ssize_t slen;
101 fr_pair_t *vp = NULL;
102 fr_dict_attr_t const *ref;
103
104 FR_PROTO_HEX_DUMP(data, data_len, "decode_value");
105
106 switch (parent->type) {
107 case FR_TYPE_ATTR:
108 /*
109 * Force the length of the data to be two,
110 * otherwise the "from network" call complains.
111 * Because we pass in the enumv as the _parent_
112 * and not the da. The da is marked as "array",
113 * but the parent is not.
114 */
115 if (data_len < 2) goto raw;
116
117 /*
118 * Run-time checks rather than assertions.
119 */
120 if (!parent->parent->flags.is_root) return -1;
121
122 vp = fr_pair_afrom_da(ctx, parent);
123 if (!vp) return PAIR_DECODE_OOM;
125
126 slen = fr_value_box_from_network(vp, &vp->data, vp->vp_type, parent->parent,
127 &FR_DBUFF_TMP(data, 2), 2, true);
128 if (slen <= 0) {
129 TALLOC_FREE(vp);
130 goto raw;
131 }
132
133 vp->vp_tainted = true;
135 return 2;
136
137 /*
138 * Address MAY be shorter than 16 bytes.
139 */
141 if (data_len == 0) {
142 raw:
143 return fr_pair_raw_from_network(ctx, out, parent, data, data_len);
144
145 }
146
147 vp = fr_pair_afrom_da(ctx, parent);
148 if (!vp) return PAIR_DECODE_OOM;
150
151 slen = fr_value_box_ipaddr_from_network(&vp->data, parent->type, parent,
152 data[0], data + 1, data_len - 1,
153 (parent->parent->type == FR_TYPE_STRUCT), true);
154 if (slen < 0) goto raw_free;
155
156 slen++; /* account for the prefix */
157 break;
158
159 /*
160 * A bool is encoded as an empty option if it's
161 * true. A bool is omitted entirely if it's
162 * false.
163 */
164 case FR_TYPE_BOOL:
165 if (data_len != 0) goto raw;
166 vp = fr_pair_afrom_da(ctx, parent);
167 if (!vp) return PAIR_DECODE_OOM;
169
170 vp->vp_bool = true;
171 slen = 0;
172 break;
173
174 /*
175 * A standard 32bit integer, but unlike normal UNIX timestamps
176 * starts from the 1st of January 2000.
177 *
178 * In the encoder we subtract 30 years to any values, so
179 * here we need to add that to the time here.
180 */
181 case FR_TYPE_DATE:
182 vp = fr_pair_afrom_da(ctx, parent);
183 if (!vp) return PAIR_DECODE_OOM;
185
186 slen = fr_value_box_from_network(vp, &vp->data, vp->vp_type, vp->da,
187 &FR_DBUFF_TMP(data, data_len), data_len, true);
188 if (slen < 0) {
190 goto raw;
191 }
193 break;
194
195 case FR_TYPE_STRUCT:
196 slen = fr_struct_from_network(ctx, out, parent, data, data_len,
198 if (slen < 0) goto raw;
199
200 if (parent->flags.array) return slen;
201 return data_len;
202
203 case FR_TYPE_GROUP:
204 vp = fr_pair_afrom_da(ctx, parent);
205 if (!vp) return PAIR_DECODE_OOM;
207
209 if (ref && (ref->dict != dict_dhcpv6)) {
210 fr_dict_protocol_t const *proto;
211
212 proto = fr_dict_protocol(ref->dict);
213 fr_assert(proto != NULL);
214
215 if (!proto->decode) {
216 raw_free:
218 goto raw;
219 }
220
221 slen = proto->decode(vp, &vp->vp_group, data, data_len);
222 if (slen < 0) goto raw_free;
223
224 vp->vp_tainted = true;
225
226 } else {
227 if (!ref) ref = fr_dict_root(dict_dhcpv6);
228
229 /*
230 * Child VPs go into the child group, not in the main parent list. BUT, we start
231 * decoding attributes from the ref, and not from the group parent.
232 */
233 slen = fr_pair_tlvs_from_network(vp, &vp->vp_group, ref, data, data_len, decode_ctx, decode_option, NULL, false);
234 if (slen < 0) goto raw_free;
235 }
236
238 return data_len;
239
241 vp = fr_pair_afrom_da(ctx, parent);
242 if (!vp) return PAIR_DECODE_OOM;
244
245 slen = fr_value_box_ipaddr_from_network(&vp->data, parent->type, parent,
246 128, data, data_len,
247 true, true);
248 if (slen < 0) goto raw_free;
249 break;
250
251 default:
252 vp = fr_pair_afrom_da(ctx, parent);
253 if (!vp) return PAIR_DECODE_OOM;
255
256 slen = fr_value_box_from_network(vp, &vp->data, vp->vp_type, vp->da,
257 &FR_DBUFF_TMP(data, data_len), data_len, true);
258 if (slen < 0) goto raw_free;
259 break;
260 }
261
262 /*
263 * The input is larger than the decoded value, re-do it as a raw attribute.
264 */
265 if (!parent->flags.array && ((size_t) slen < data_len)) {
267 goto raw;
268 }
269
270 fr_assert(vp != NULL);
271
272 vp->vp_tainted = true;
274
275 if (parent->flags.array) return slen;
276
277 return data_len;
278}
279
280
281static ssize_t decode_option(TALLOC_CTX *ctx, fr_pair_list_t *out,
282 fr_dict_attr_t const *parent,
283 uint8_t const *data, size_t const data_len, void *decode_ctx)
284{
285 unsigned int option;
286 size_t len;
287 ssize_t slen;
288 fr_dict_attr_t const *da;
289 fr_dhcpv6_decode_ctx_t *packet_ctx = decode_ctx;
290
291#ifdef STATIC_ANALYZER
292 if (!packet_ctx || !packet_ctx->tmp_ctx) return PAIR_DECODE_FATAL_ERROR;
293#endif
294
295 /*
296 * Must have at least an option header.
297 */
298 if (data_len < 4) {
299 fr_strerror_printf("%s: Insufficient data", __FUNCTION__);
300 return -(data_len);
301 }
302
303 option = DHCPV6_GET_OPTION_NUM(data);
305 if (len > (data_len - 4)) {
306 fr_strerror_printf("%s: Option overflows input. "
307 "Optional length must be less than %zu bytes, got %zu bytes",
308 __FUNCTION__, data_len - 4, len);
310 }
311
312 da = fr_dict_attr_child_by_num(parent, option);
313 if (!da) {
314 da = fr_dict_attr_unknown_raw_afrom_num(packet_ctx->tmp_ctx, parent, option);
315 if (!da) return PAIR_DECODE_FATAL_ERROR;
316 }
317 FR_PROTO_TRACE("decode context changed %s -> %s",da->parent->name, da->name);
318
319 /*
320 * Relay messages are weird, and contain complete DHCPv6
321 * packets, copied verbatim from the DHCPv6 client.
322 */
323 if (da == attr_relay_message) {
324 fr_pair_t *vp;
325
327 if (!vp) return PAIR_DECODE_FATAL_ERROR;
329
330 /*
331 * Check if the relayed packet is OK. If not, it's an error.
332 */
333 if (!fr_dhcpv6_ok(data + 4, len, 200)) return -1;
334
335 slen = fr_dhcpv6_decode(vp, &vp->vp_group, data + 4, len);
336 if (slen < 0) {
338 raw:
339 slen = fr_pair_raw_from_network(ctx, out, da, data + 4, len);
340 if (slen < 0) return slen;
341 return 4 + slen;
342 }
343
345
346 } else if ((da->type == FR_TYPE_STRING) && fr_dhcpv6_flag_any_dns_label(da)) {
347 slen = fr_pair_dns_labels_from_network(ctx, out, da, data + 4, data + 4, len, NULL, true);
348 if (slen < 0) return slen;
349
350 } else if (da->flags.array) {
351 if (da == attr_option_request) {
352 uint8_t const *p;
353
354 if ((len < 2) || ((len & 0x01) != 0)) {
355 fr_strerror_const("Invalid Option-Request, length is not a multiple of 2");
356 return -1;
357 }
358
359 /*
360 * Check for the forbidden options.
361 */
362 for (p = data + 4; p < (data + 4 + len); p += 2) {
363 if (*p) continue;
364
365 if (*p > 26) continue;
366
367 if ((1 << *p) & DHCPV6_ORO_FORBIDDEN) {
368 fr_strerror_printf("Option %u is forbidden inside of Option-Request", *p);
369 return -1;
370 }
371 }
372 }
373
374 slen = fr_pair_array_from_network(ctx, out, da, data + 4, len, decode_ctx, decode_value);
375
376 } else if (da->type == FR_TYPE_VSA) {
377 bool append_vsa = false;
378 bool append_vp = false;
379 uint32_t pen;
380 fr_dict_attr_t const *vendor;
381 fr_pair_t *vsa, *vp;
382 fr_pair_list_t list;
383
384 /*
385 * Insufficient room for a 4-octet enterprise
386 * code, plus at least one option header.
387 */
388 if (len < 8) goto raw;
389
390 pen = fr_nbo_to_uint32(data + 4);
391
392 /*
393 * Verify that the VSA contains a vendor.
394 *
395 * If it doesn't then this vendor is unknown, but we know
396 * vendor attributes have a standard format, so we can
397 * decode the data anyway.
398 */
399 vendor = fr_dict_attr_child_by_num(da, pen);
400 if (!vendor) {
402
403 n = fr_dict_attr_unknown_vendor_afrom_num(packet_ctx->tmp_ctx, da, pen);
404 if (!n) return PAIR_DECODE_OOM;
405 vendor = n;
406 }
407
408 vsa = fr_pair_find_by_da(out, NULL, da);
409 if (!vsa) {
410 vsa = fr_pair_afrom_da(ctx, da);
411 if (!vsa) return PAIR_DECODE_FATAL_ERROR;
412 PAIR_ALLOCED(vsa);
413
414 append_vsa = true;
415 }
416
417 vp = NULL;
418 if (!append_vsa) vp = fr_pair_find_by_da(&vsa->vp_group, NULL, vendor);
419
420 if (!vp) {
421 vp = fr_pair_afrom_da(vsa, vendor);
422 if (!vp) return PAIR_DECODE_FATAL_ERROR;
424
425 append_vp = true;
426 }
427
428 fr_pair_list_init(&list);
429 slen = fr_pair_tlvs_from_network(vp, &vp->vp_group, vendor, data + 8, len - 4,
430 decode_ctx, decode_option, NULL, false);
431
432 if (slen < 0) {
433 fr_pair_list_free(&list);
434 if (append_vp) talloc_free(vp);
435 if (append_vsa) talloc_free(vsa);
436 goto raw;
437 }
438
439 /*
440 * The child list contains vendors, and we have to merge the vendors
441 */
442 fr_pair_list_append(&vp->vp_group, &list);
443 if (append_vp) fr_pair_append(&vsa->vp_group, vp);
444 if (append_vsa) fr_pair_append(out, vsa);
445
446 } else if (da->type == FR_TYPE_TLV) {
447 slen = fr_pair_tlvs_from_network(ctx, out, da, data + 4, len, decode_ctx, decode_option, NULL, true);
448
449 } else if (da == attr_auth) {
450 /*
451 * See RFC 8415 Section 18 (option format), and Section 20 (functionality).
452 *
453 * The Auth option can be sent from a server to client in a Reply message, and contains a
454 * 128-bit secret key that is recorded somewhere on the server side.
455 *
456 * The Auth option can be sent from a server to a client in a Reconfigure message, and
457 * contains an HMAC-MD5 of the packet and the secret key.
458 *
459 * We are not currently a DHCPv6 client, so we do not support the Auth option, or
460 * Reconfigure messages. See verify_to_client() in base.c.
461 */
462 fr_strerror_const("The 'Auth' option is not supported");
463 return -1;
464
465 } else {
466 slen = decode_value(ctx, out, da, data + 4, len, decode_ctx);
467 }
468
469 if (slen < 0) goto raw;
470
471 return len + 4;
472}
473
474
475/** Create a "normal" fr_pair_t from the given data
476 *
477 * 0 1 2 3
478 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
479 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
480 * | option-code | option-len |
481 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
482 */
484 uint8_t const *data, size_t data_len, void *decode_ctx)
485{
486 FR_PROTO_HEX_DUMP(data, data_len, "fr_dhcpv6_decode_pair");
487
488 /*
489 * The API changes, so we just bounce directly to the
490 * decode_option() function.
491 *
492 * All options including VSAs in DHCPv6 MUST follow the
493 * standard format.
494 */
495 return decode_option(ctx, out, fr_dict_root(dict_dhcpv6), data, data_len, decode_ctx);
496}
497
499 uint8_t const *data, size_t data_len)
500{
501 ssize_t slen;
502 uint8_t const *attr, *end;
503
504 fr_dhcpv6_decode_ctx_t decode_ctx = {};
505
506 fr_assert(dict_dhcpv6 != NULL);
507
508 decode_ctx.tmp_ctx = talloc(ctx, uint8_t);
509
510 attr = data;
511 end = data + data_len;
512
513 while (attr < end) {
514 slen = fr_dhcpv6_decode_option(ctx, out, attr, (end - attr), &decode_ctx);
515 if (slen < 0) {
516 talloc_free(decode_ctx.tmp_ctx);
517 return slen;
518 }
519
520 /*
521 * If slen is larger than the room in the packet,
522 * all kinds of bad things happen.
523 */
524 if (!fr_cond_assert(slen <= (end - attr))) {
525 talloc_free(decode_ctx.tmp_ctx);
526 return -slen - (attr - data);
527 }
528
529 attr += slen;
530 talloc_free_children(decode_ctx.tmp_ctx);
531 }
532
533 talloc_free(decode_ctx.tmp_ctx);
534 return data_len;
535}
536
537static int decode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict,
539{
540 fr_dhcpv6_decode_ctx_t *test_ctx;
541
542 test_ctx = talloc_zero(ctx, fr_dhcpv6_decode_ctx_t);
543 if (!test_ctx) return -1;
544
545 test_ctx->tmp_ctx = talloc(test_ctx, uint8_t);
546
547 *out = test_ctx;
548
549 return 0;
550}
551
552static ssize_t fr_dhcpv6_decode_proto(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len, UNUSED void *proto_ctx)
553{
554 size_t packet_len = data_len;
555// fr_dhcpv6_decode_ctx_t *test_ctx = talloc_get_type_abort(proto_ctx, fr_dhcpv6_decode_ctx_t);
556
557 if (!fr_dhcpv6_ok(data, packet_len, 200)) return -1;
558
559 return fr_dhcpv6_decode(ctx, out, data, packet_len);
560}
561
562
564 uint8_t const *data, size_t data_len, void *decode_ctx)
565{
567
568 return decode_option(ctx, out, fr_dict_root(dict_dhcpv6), data, data_len, decode_ctx);
569}
570
571/*
572 * Test points
573 */
579
int n
Definition acutest.h:577
#define NDEBUG_UNUSED
Definition build.h:347
#define UNUSED
Definition build.h:336
fr_dict_attr_t const * root_da
Definition common.c:32
#define FR_DBUFF_TMP(_start, _len_or_end)
Creates a compound literal to pass into functions which accept a dbuff.
Definition dbuff.h:522
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
Definition debug.h:131
Implementation of the DHCPv6 protocol.
#define DHCPV6_GET_OPTION_NUM(_x)
Definition dhcpv6.h:47
#define DHCPV6_GET_OPTION_LEN(_x)
Definition dhcpv6.h:48
static bool fr_dhcpv6_flag_any_dns_label(fr_dict_attr_t const *da)
Definition dhcpv6.h:152
#define DHCPV6_DATE_OFFSET
Definition dhcpv6.h:124
TALLOC_CTX * tmp_ctx
for temporary things cleaned up during decoding
Definition dhcpv6.h:133
fr_dict_attr_decode_func_t decode
for decoding attributes.
Definition dict.h:487
static fr_dict_attr_t * fr_dict_attr_unknown_vendor_afrom_num(TALLOC_CTX *ctx, fr_dict_attr_t const *parent, unsigned int vendor)
Definition dict.h:604
fr_dict_protocol_t const * fr_dict_protocol(fr_dict_t const *dict)
Return the protocol descriptor for the dictionary.
Definition dict_util.c:5229
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:611
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
Definition dict_util.c:2639
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:3570
Protocol-specific callbacks in libfreeradius-PROTOCOL.
Definition dict.h:455
static fr_dict_attr_t const * fr_dict_attr_ref(fr_dict_attr_t const *da)
Return the reference associated with a group type attribute.
Definition dict_ext.h:148
talloc_free(hp)
#define PAIR_DECODE_OOM
Fatal error - Out of memory.
Definition pair.h:45
#define PAIR_DECODE_FATAL_ERROR
Fatal error - Failed decoding the packet.
Definition pair.h:49
ssize_t fr_pair_tlvs_from_network(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, fr_pair_decode_value_t decode_tlv, fr_pair_tlvs_verify_t verify_tlvs, bool nested)
Decode a list of pairs from the network.
Definition decode.c:156
ssize_t fr_pair_dns_labels_from_network(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *start, uint8_t const *data, size_t const data_len, fr_dns_labels_t *lb, bool exact)
Decode a DNS label or a list of DNS labels from the network.
Definition decode.c:253
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:86
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
@ FR_TYPE_TLV
Contains nested attributes.
@ FR_TYPE_IPV6_PREFIX
IPv6 Prefix.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_DATE
Unix time stamp, always has value >2^31.
@ FR_TYPE_STRUCT
like TLV, but without T or L, and fixed-width children
@ FR_TYPE_IPV6_ADDR
128 Bit IPv6 Address.
@ FR_TYPE_BOOL
A truth value.
@ FR_TYPE_VSA
Vendor-Specific, for RADIUS attribute 26.
@ FR_TYPE_GROUP
A grouping of other attributes.
unsigned int uint32_t
long int ssize_t
unsigned char uint8_t
static uint32_t fr_nbo_to_uint32(uint8_t const data[static sizeof(uint32_t)])
Read an unsigned 32bit integer from wire format (big endian)
Definition nbo.h:167
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:707
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:1352
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:290
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
Definition pair.c:46
static fr_dict_t const * dict_dhcpv6
static fr_dict_attr_t const * attr_relay_message
static int decode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict, UNUSED fr_dict_attr_t const *root_da)
Definition decode.c:102
static ssize_t decode_option(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)
Definition decode.c:482
static ssize_t decode_value_trampoline(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)
Handle arrays of DNS labels for fr_struct_from_network()
Definition decode.c:70
static ssize_t decode_tlv_trampoline(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)
Definition decode.c:57
HIDDEN fr_dict_attr_t const * attr_option_request
Definition base.c:55
HIDDEN fr_dict_attr_t const * attr_auth
Definition base.c:56
bool fr_dhcpv6_ok(uint8_t const *packet, size_t packet_len, uint32_t max_attributes)
See if the data pointed to by PTR is a valid DHCPv6 packet.
Definition base.c:237
ssize_t fr_dhcpv6_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *packet, size_t packet_len)
Decode a DHCPv6 packet.
Definition base.c:636
ssize_t fr_dhcpv6_decode_option(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len, void *decode_ctx)
Create a "normal" fr_pair_t from the given data.
Definition decode.c:483
fr_test_point_pair_decode_t dhcpv6_tp_decode_pair
Definition decode.c:575
fr_test_point_proto_decode_t dhcpv6_tp_decode_proto
Definition decode.c:581
#define DHCPV6_ORO_FORBIDDEN
Definition decode.c:44
ssize_t fr_dhcpv6_decode_foreign(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len)
Definition decode.c:498
static ssize_t fr_dhcpv6_decode_proto(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len, UNUSED void *proto_ctx)
Definition decode.c:552
static ssize_t decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, NDEBUG_UNUSED fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx)
Definition decode.c:563
#define decode_value
Definition decode.c:411
VQP attributes.
#define fr_assert(_expr)
Definition rad_assert.h:37
fr_pair_t * vp
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
fr_test_point_ctx_alloc_t test_ctx
Allocate a test ctx for the encoder.
Definition test_point.h:86
fr_test_point_ctx_alloc_t test_ctx
Allocate a test ctx for the encoder.
Definition test_point.h:68
Entry point for pair decoders.
Definition test_point.h:85
Entry point for protocol decoders.
Definition test_point.h:67
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
Definition time.h:590
#define fr_unix_time_add(_a, _b)
Add a time/time delta together.
Definition time.h:324
#define PAIR_ALLOCED(_x)
Definition pair.h:212
void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
void fr_pair_list_append(fr_pair_list_t *dst, fr_pair_list_t *src)
Appends a list of fr_pair_t from a temporary list to a destination list.
static fr_slen_t parent
Definition pair.h:858
#define FR_PROTO_HEX_DUMP(_data, _data_len, _fmt,...)
Definition proto.h:42
#define FR_PROTO_TRACE(_fmt,...)
Definition proto.h:41
#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_ATTR
A contains an attribute reference.
Definition types.h:83
ssize_t fr_value_box_from_network(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t type, fr_dict_attr_t const *enumv, fr_dbuff_t *dbuff, size_t len, bool tainted)
Decode a fr_value_box_t from serialized binary data.
Definition value.c:1892
ssize_t fr_value_box_ipaddr_from_network(fr_value_box_t *dst, fr_type_t type, fr_dict_attr_t const *enumv, int prefix_len, uint8_t const *data, size_t data_len, bool fixed, bool tainted)
Decode a fr_value_box_t of type IP address / prefix.
Definition value.c:2296
static fr_slen_t data
Definition value.h:1340
static size_t char ** out
Definition value.h:1030