The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
encode.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: c25bb47c7b065b3c74cd43712d049f87b21e72cf $
19 *
20 * @file protocols/dns/encode.c
21 * @brief Functions to encode DNS packets
22 *
23 * @author Alan DeKok (aland@freeradius.org)
24 *
25 * @copyright 2021 NetworkRADIUS SARL (legal@networkradius.com)
26 */
27#include <freeradius-devel/io/test_point.h>
28#include <freeradius-devel/util/dbuff.h>
29#include <freeradius-devel/util/dns.h>
30#include <freeradius-devel/util/proto.h>
31#include <freeradius-devel/util/struct.h>
32
33#include "dns.h"
34#include "attrs.h"
35
36#define DNS_OPT_HDR_LEN (4)
37
38static ssize_t encode_value(fr_dbuff_t *dbuff,
39 fr_da_stack_t *da_stack, unsigned int depth,
40 fr_dcursor_t *cursor, void *encode_ctx);
41
42static ssize_t encode_rfc(fr_dbuff_t *dbuff,
43 fr_da_stack_t *da_stack, unsigned int depth,
44 fr_dcursor_t *cursor, void *encode_ctx);
45
46static ssize_t encode_tlv(fr_dbuff_t *dbuff,
47 fr_da_stack_t *da_stack, unsigned int depth,
48 fr_dcursor_t *cursor, void *encode_ctx);
49
50static ssize_t encode_child(fr_dbuff_t *dbuff,
51 fr_da_stack_t *da_stack, unsigned int depth,
52 fr_dcursor_t *cursor, void *encode_ctx);
53
54/** Macro-like function for encoding an option header
55 *
56 * 0 1 2 3
57 * 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
58 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
59 * | option-code | option-len |
60 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
61 *
62 * @param[out] m Where to write the 4 byte option header.
63 * @param[in] option The option number (host byte order).
64 * @param[in] data_len The length of the option (host byte order).
65 * @return
66 * - <0 How much data would have been required as a negative value.
67 * - 4 The length of data written.
68 */
69static inline ssize_t encode_option_hdr(fr_dbuff_marker_t *m, uint16_t option, size_t data_len)
70{
71 FR_DBUFF_IN_RETURN(m, option);
72 FR_DBUFF_IN_RETURN(m, (uint16_t) data_len);
73
74 return sizeof(option) + sizeof(uint16_t);
75}
76
77
79 fr_da_stack_t *da_stack, unsigned int depth,
80 fr_dcursor_t *cursor, void *encode_ctx)
81{
82 ssize_t slen;
83 fr_dbuff_t work_dbuff = FR_DBUFF(dbuff);
84 fr_pair_t const *vp = fr_dcursor_current(cursor);
85 fr_dict_attr_t const *da = da_stack->da[depth];
86 fr_dns_ctx_t *packet_ctx = encode_ctx;
87
89 FR_PROTO_STACK_PRINT(da_stack, depth);
90
91 /*
92 * Nested structs
93 */
94 if (vp->vp_type == FR_TYPE_STRUCT) {
95 fr_dcursor_t child_cursor;
96
97 fr_pair_dcursor_child_iter_init(&child_cursor, &vp->vp_group, cursor);
98
99 slen = fr_struct_to_network(&work_dbuff, da_stack, depth, &child_cursor, encode_ctx, encode_value, encode_child);
100 if (slen < 0) return slen;
101
102 /*
103 * Rebuild the da_stack for the next option.
104 */
105 vp = fr_dcursor_next(cursor);
106 fr_proto_da_stack_build(da_stack, vp ? vp->da : NULL);
107 return fr_dbuff_set(dbuff, &work_dbuff);
108 }
109
110 /*
111 * Flat-list
112 */
113 if (da->type == FR_TYPE_STRUCT) {
114 slen = fr_struct_to_network(&work_dbuff, da_stack, depth, cursor, encode_ctx, encode_value, encode_child);
115 if (slen <= 0) return slen;
116
117 /*
118 * Rebuild the da_stack for the next option.
119 */
120 vp = fr_dcursor_current(cursor);
121 fr_proto_da_stack_build(da_stack, vp ? vp->da : NULL);
122 return fr_dbuff_set(dbuff, &work_dbuff);
123 }
124 /*
125 * If it's not a TLV, it should be a value type RFC
126 * attribute make sure that it is.
127 */
128 if (da_stack->da[depth + 1] != NULL) {
129 fr_strerror_printf("%s: Encoding value but not at top of stack", __FUNCTION__);
131 }
132
133 if (vp->da != da) {
134 fr_strerror_printf("%s: Top of stack does not match vp->da", __FUNCTION__);
136 }
137
138 switch (vp->vp_type) {
139 case FR_TYPE_TLV:
140 case FR_TYPE_VENDOR:
141 case FR_TYPE_VSA:
142 case FR_TYPE_GROUP:
143 fr_strerror_printf("%s: Called with structural type %s", __FUNCTION__,
144 fr_type_to_str(da->type));
146
147 case FR_TYPE_STRING:
148 /*
149 * DNS labels get a special encoder.
150 */
152 FR_PROTO_TRACE("encode DNS label %s", vp->vp_strvalue);
154 &vp->data, packet_ctx->lb);
155 if (slen < 0) return slen;
156 break;
157 }
158 goto to_network;
159
160 /*
161 * Common encoder might add scope byte, so we just copy the address portion
162 */
164 FR_DBUFF_IN_MEMCPY_RETURN(&work_dbuff, vp->vp_ipv6addr, sizeof(vp->vp_ipv6addr));
165 break;
166
168 fr_strerror_const("invalid data type - ipv4prefix");
170
172 fr_strerror_const("invalid data type - ipv6prefix");
174
175 case FR_TYPE_BOOL:
176 /*
177 * Don't encode anything! The mere existence of
178 * the attribute signifies a "true" value.
179 */
180 break;
181
182 /*
183 * The value_box functions will take care of fixed-width
184 * "string" and "octets" options.
185 */
186 to_network:
187 case FR_TYPE_OCTETS:
188 /*
189 * Hack until we find all places that don't set data.enumv
190 */
191 if (vp->da->flags.length && (vp->data.enumv != vp->da)) {
192 fr_dict_attr_t const * const *c = &vp->data.enumv;
193 fr_dict_attr_t **u;
194
195 memcpy(&u, &c, sizeof(c)); /* const issues */
196 memcpy(u, &vp->da, sizeof(vp->da));
197 }
199
200 default:
201 slen = fr_value_box_to_network(&work_dbuff, &vp->data);
202 if (slen < 0) return PAIR_ENCODE_FATAL_ERROR;
203 break;
204 }
205
206 /*
207 * Rebuilds the TLV stack for encoding the next attribute
208 */
209 vp = fr_dcursor_next(cursor);
210 fr_proto_da_stack_build(da_stack, vp ? vp->da : NULL);
211
212 FR_PROTO_HEX_DUMP(fr_dbuff_start(&work_dbuff), fr_dbuff_used(&work_dbuff), "done value");
213
214 return fr_dbuff_set(dbuff, &work_dbuff);
215}
216
218 fr_da_stack_t *da_stack, unsigned int depth,
219 fr_dcursor_t *cursor, void *encode_ctx)
220{
221 ssize_t len;
223 fr_dcursor_t child_cursor;
224 fr_dbuff_t work_dbuff;
225
226 if (da_stack->da[depth]) {
227 /*
228 * Determine the nested type and call the appropriate encoder
229 */
230 switch (da_stack->da[depth]->type) {
231 case FR_TYPE_TLV:
232 if (!da_stack->da[depth + 1]) break;
233
234 return encode_tlv(dbuff, da_stack, depth, cursor, encode_ctx);
235
236 case FR_TYPE_GROUP:
237 if (!da_stack->da[depth + 1]) break;
239
240 default:
241 return encode_rfc(dbuff, da_stack, depth, cursor, encode_ctx);
242 }
243 }
244
246
247 fr_pair_dcursor_child_iter_init(&child_cursor, &vp->vp_group, cursor);
248 work_dbuff = FR_DBUFF(dbuff);
249
250 while ((vp = fr_dcursor_current(&child_cursor)) != NULL) {
251 fr_proto_da_stack_build(da_stack, vp->da);
252
253 switch (da_stack->da[depth]->type) {
254 case FR_TYPE_TLV:
255 len = encode_tlv(&work_dbuff, da_stack, depth, &child_cursor, encode_ctx);
256 break;
257
258 default:
259 len = encode_rfc(&work_dbuff, da_stack, depth, &child_cursor, encode_ctx);
260 break;
261 }
262
263 if (len <= 0) return len;
264 }
265
266 /*
267 * Skip over the attribute we just encoded.
268 */
269 vp = fr_dcursor_next(cursor);
270 fr_proto_da_stack_build(da_stack, vp ? vp->da : NULL);
271
272 return fr_dbuff_set(dbuff, &work_dbuff);
273}
274
275/** Encode an RFC format TLV.
276 *
277 * This could be a standard attribute, or a TLV data type.
278 * If it's a standard attribute, then vp->da->attr == attribute.
279 * Otherwise, attribute may be something else.
280 */
282 fr_da_stack_t *da_stack, unsigned int depth,
283 fr_dcursor_t *cursor, void *encode_ctx)
284{
285 fr_dbuff_t work_dbuff = FR_DBUFF(dbuff);
287 fr_dict_attr_t const *da = da_stack->da[depth];
288 ssize_t len;
289
290 FR_PROTO_STACK_PRINT(da_stack, depth);
291 fr_dbuff_marker(&hdr, &work_dbuff);
292
293 /*
294 * Make space for the header...
295 */
297 fr_dbuff_advance(&work_dbuff, DNS_OPT_HDR_LEN);
298
299 /*
300 * Write out the option's value
301 */
302 if (da->flags.array) {
303 len = fr_pair_array_to_network(&work_dbuff, da_stack, depth, cursor, encode_ctx, encode_value);
304 } else {
305 len = encode_value(&work_dbuff, da_stack, depth, cursor, encode_ctx);
306 }
307 if (len < 0) return len;
308
309 /*
310 * Write out the option number and length (before the value we just wrote)
311 */
312 (void) encode_option_hdr(&hdr, (uint16_t)da->attr, (uint16_t) (fr_dbuff_used(&work_dbuff) - DNS_OPT_HDR_LEN));
313
314 FR_PROTO_HEX_DUMP(fr_dbuff_start(&work_dbuff), fr_dbuff_used(&work_dbuff), "Done RFC header");
315
316 return fr_dbuff_set(dbuff, &work_dbuff);
317}
318
320 fr_da_stack_t *da_stack, unsigned int depth,
321 fr_dcursor_t *cursor, void *encode_ctx)
322{
323 fr_dbuff_t work_dbuff = FR_DBUFF(dbuff);
325 fr_dict_attr_t const *da = da_stack->da[depth];
326 ssize_t len;
327
328 fr_dbuff_marker(&hdr, &work_dbuff);
330 FR_PROTO_STACK_PRINT(da_stack, depth);
331
332 if (da_stack->da[depth]->type != FR_TYPE_TLV) {
333 fr_strerror_printf("%s: Expected type \"tlv\" got \"%s\"", __FUNCTION__,
334 fr_type_to_str(da_stack->da[depth]->type));
336 }
337
338 if (!da_stack->da[depth + 1]) {
339 fr_assert(0);
340 fr_strerror_printf("%s: Can't encode empty TLV", __FUNCTION__);
342 }
343
344 FR_DBUFF_ADVANCE_RETURN(&work_dbuff, DNS_OPT_HDR_LEN); /* Make room for option header */
345
346 len = fr_pair_cursor_to_network(&work_dbuff, da_stack, depth, cursor, encode_ctx, encode_child);
347 if (len < 0) return len;
348
349 /*
350 * 0 1 2 3
351 * 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
352 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
353 * | option-code | option-len |
354 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
355 */
356 (void) encode_option_hdr(&hdr, (uint16_t)da->attr, (uint16_t) (fr_dbuff_used(&work_dbuff) - DNS_OPT_HDR_LEN));
357
358 FR_PROTO_HEX_DUMP(fr_dbuff_start(&work_dbuff), fr_dbuff_used(&work_dbuff), "Done TLV header");
359
360 return fr_dbuff_set(dbuff, &work_dbuff);
361}
362
363
364/** Encode a Dns option and any sub-options.
365 *
366 * This function is only used by the test harness.
367 *
368 * @param[out] dbuff Where to write encoded DHCP attributes.
369 * @param[in] cursor with current VP set to the option to be encoded.
370 * Will be advanced to the next option to encode.
371 * @param[in] encode_ctx containing parameters for the encoder.
372 * @return
373 * - > 0 length of data written.
374 * - < 0 error.
375 */
377{
378 ssize_t slen;
379 fr_pair_t *vp;
380 fr_dcursor_t child_cursor;
381 fr_da_stack_t da_stack;
382 fr_dbuff_t work_dbuff = FR_DBUFF_MAX(dbuff, UINT16_MAX);
383
385 FR_PROTO_STACK_PRINT(&da_stack, 0);
386
387 FR_PROTO_TRACE("encode_rr -- remaining %zd", fr_dbuff_remaining(&work_dbuff));
388
389 vp = fr_dcursor_current(cursor);
390 if (!vp) return 0;
391
392 fr_assert(vp->vp_type == FR_TYPE_STRUCT);
393
394 fr_pair_dcursor_child_iter_init(&child_cursor, &vp->vp_group, cursor);
395
396 slen = fr_struct_to_network(&work_dbuff, &da_stack, 0, &child_cursor, encode_ctx, encode_value, encode_child);
397 if (slen <= 0) return slen;
398 (void) fr_dcursor_next(cursor);
399
400 FR_PROTO_TRACE("Complete rr is %zu byte(s)", fr_dbuff_used(&work_dbuff));
401 FR_PROTO_HEX_DUMP(fr_dbuff_start(&work_dbuff), fr_dbuff_used(&work_dbuff), NULL);
402
403 return fr_dbuff_set(dbuff, &work_dbuff);
404}
405
407 fr_dict_attr_t const *attr, fr_dns_ctx_t *packet_ctx, uint8_t *counter)
408{
409 int count;
410 fr_pair_t *vp;
411 fr_dbuff_t work_dbuff = FR_DBUFF(dbuff);
412 fr_dcursor_t cursor;
413
414 vp = fr_pair_dcursor_by_da_init(&cursor, vps, attr);
415 if (!vp) {
416 FR_PROTO_TRACE(" %s not found in list", attr->name);
417 counter[0] = counter[1] = 0;
418 return 0;
419 }
420
421 fr_proto_da_stack_build(da_stack, attr);
422
423 count = 0;
424 while (count < 65535) {
425 ssize_t slen;
426 fr_dcursor_t child_cursor;
427
428 fr_pair_dcursor_init(&child_cursor, &vp->vp_group);
429 slen = fr_struct_to_network(&work_dbuff, da_stack, 0, &child_cursor, packet_ctx, encode_value, encode_child);
430 if (slen <= 0) return slen;
431
432 count++;
433 vp = fr_dcursor_next(&cursor);
434 if (!vp) break;
435 }
436
437 fr_nbo_from_uint16(counter, count);
438 FR_PROTO_TRACE(" %s encoded %d records", attr->name, count);
439
440 return fr_dbuff_set(dbuff, &work_dbuff);
441}
442
443/** Encode a DNS packet
444 *
445 */
447{
448 fr_dbuff_t work_dbuff = FR_DBUFF(dbuff);
449 ssize_t slen;
450 uint8_t *packet;
451 fr_pair_t *vp;
452 fr_dcursor_t cursor;
453 fr_da_stack_t da_stack;
454
455 packet = fr_dbuff_current(&work_dbuff);
456 fr_assert(packet == packet_ctx->packet);
457
458 /*
459 * @todo - find maximum packet length, and limit work_dbuff to that.
460 */
462 if (!vp) {
464
465 fr_strerror_const("attribute list does not include DNS packet header");
466 return -1;
467 }
468
469 /*
470 * Encode the header.
471 */
473
474 slen = fr_struct_to_network(&work_dbuff, &da_stack, 0, &cursor, packet_ctx, encode_value, NULL);
475 if (slen <= 0) return slen;
476
477 fr_assert(slen == DNS_HDR_LEN);
478
479 /*
480 * Encode questions
481 */
482 slen = encode_record(&work_dbuff, &da_stack, vps, attr_dns_question, packet_ctx, packet + 4);
483 if (slen < 0) return FR_DBUFF_ERROR_OFFSET(slen, fr_dbuff_used(&work_dbuff));
484
485 /*
486 * Encode answers
487 */
488 slen = encode_record(&work_dbuff, &da_stack, vps, attr_dns_rr, packet_ctx, packet + 6);
489 if (slen < 0) return FR_DBUFF_ERROR_OFFSET(slen, fr_dbuff_used(&work_dbuff));
490
491 /*
492 * Encode NS records
493 */
494 slen = encode_record(&work_dbuff, &da_stack, vps, attr_dns_ns, packet_ctx, packet + 8);
495 if (slen < 0) return FR_DBUFF_ERROR_OFFSET(slen, fr_dbuff_used(&work_dbuff));
496
497 /*
498 * Encode additional records
499 */
500 slen = encode_record(&work_dbuff, &da_stack, vps, attr_dns_ar, packet_ctx, packet + 10);
501 if (slen < 0) return FR_DBUFF_ERROR_OFFSET(slen, fr_dbuff_used(&work_dbuff));
502
503 return fr_dbuff_set(dbuff, &work_dbuff);
504}
505
506static int encode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict,
507 UNUSED fr_dict_attr_t const *root_da)
508{
509 fr_dns_ctx_t *test_ctx;
510
511 test_ctx = talloc_zero(ctx, fr_dns_ctx_t);
512 if (!test_ctx) return -1;
513
514 test_ctx->tmp_ctx = talloc(test_ctx, uint8_t);
515
516 *out = test_ctx;
517
518 return 0;
519}
520
521static ssize_t fr_dns_encode_proto(UNUSED TALLOC_CTX *ctx, fr_pair_list_t *vps, uint8_t *data, size_t data_len, void *proto_ctx)
522{
523 ssize_t slen;
524 fr_dns_ctx_t *packet_ctx = (fr_dns_ctx_t *) proto_ctx;
525
526 packet_ctx->packet = data;
527 packet_ctx->packet_len = data_len;
528 packet_ctx->lb = fr_dns_labels_get(data, data_len, false);
529 fr_assert(packet_ctx->lb != NULL);
530
531 slen = fr_dns_encode(&FR_DBUFF_TMP(data, data_len), vps, packet_ctx);
532
533#ifndef NDEBUG
534 if (slen <= 0) return slen;
535
536 if (fr_debug_lvl > 2) {
537// fr_dns_print_hex(stdout, data, slen);
538 }
539#endif
540
541 return slen;
542}
543
544/*
545 * Test points
546 */
552
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
Definition build.h:343
#define UNUSED
Definition build.h:336
#define fr_dbuff_advance(_dbuff_or_marker, _len)
Advance 'current' position in dbuff or marker by _len bytes.
Definition dbuff.h:1081
#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:775
#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:1097
#define FR_DBUFF_EXTEND_LOWAT_OR_RETURN(_dbuff_or_marker, _lowat)
Extend if we're below _lowat and return if we can't extend above _lowat.
Definition dbuff.h:681
struct fr_dbuff_marker_s fr_dbuff_marker_t
A position marker associated with a dbuff.
Definition dbuff.h:81
#define fr_dbuff_current(_dbuff_or_marker)
Return the 'current' position of a dbuff or marker.
Definition dbuff.h:919
#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:1012
#define fr_dbuff_start(_dbuff_or_marker)
Return the 'start' position of a dbuff or marker.
Definition dbuff.h:906
#define fr_dbuff_remaining(_dbuff_or_marker)
Return the number of bytes remaining between the dbuff or marker and the end of the buffer.
Definition dbuff.h:751
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:1201
#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:1391
#define FR_DBUFF_ERROR_OFFSET(_slen, _offset)
Generic wrapper to return an error and an offset from encoding.
Definition dbuff.h:196
#define FR_DBUFF_IN_RETURN(_dbuff_or_marker, _in)
Copy data from a fixed sized C type into a dbuff returning if there is insufficient space.
Definition dbuff.h:1594
#define FR_DBUFF(_dbuff_or_marker)
Create a new dbuff pointing to the same underlying buffer.
Definition dbuff.h:230
#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:309
#define FR_DBUFF_TMP(_start, _len_or_end)
Creates a compound literal to pass into functions which accept a dbuff.
Definition dbuff.h:522
static void * fr_dcursor_next(fr_dcursor_t *cursor)
Advanced the cursor to the next item.
Definition dcursor.h:288
static void * fr_dcursor_current(fr_dcursor_t *cursor)
Return the item the cursor current points to.
Definition dcursor.h:337
ssize_t fr_dns_label_from_value_box_dbuff(fr_dbuff_t *dbuff, bool compression, fr_value_box_t const *value, fr_dns_labels_t *lb)
Encode a single value box of type string, serializing its contents to a dns label in a dbuff.
Definition dns.c:603
#define DNS_HDR_LEN
Definition dns_tests.c:29
#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
static ssize_t encode_tlv(fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx)
Definition encode.c:741
static ssize_t encode_rfc(fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx)
Encode an RFC format attribute header.
Definition encode.c:592
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:41
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:73
int fr_debug_lvl
Definition log.c:40
fr_log_t default_log
Definition log.c:288
unsigned short uint16_t
@ FR_TYPE_TLV
Contains nested attributes.
@ FR_TYPE_IPV6_PREFIX
IPv6 Prefix.
@ FR_TYPE_STRING
String of printable characters.
@ 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_IPV6_ADDR
128 Bit IPv6 Address.
@ FR_TYPE_IPV4_PREFIX
IPv4 Prefix.
@ 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
static uint8_t depth(fr_minmax_heap_index_t i)
Definition minmax_heap.c:83
static void fr_nbo_from_uint16(uint8_t out[static sizeof(uint16_t)], uint16_t num)
Write out an unsigned 16bit integer in wire format (big endian)
Definition nbo.h:38
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 int encode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict, UNUSED fr_dict_attr_t const *root_da)
Definition encode.c:165
static ssize_t encode_child(fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx)
Definition encode.c:357
static ssize_t encode_option_hdr(fr_dbuff_marker_t *m, uint16_t option, size_t data_len)
Macro-like function for encoding an option header.
Definition encode.c:70
HIDDEN fr_dict_attr_t const * attr_dns_ar
Definition base.c:56
HIDDEN fr_dict_attr_t const * attr_dns_ns
Definition base.c:55
HIDDEN fr_dict_attr_t const * attr_dns_packet
Definition base.c:52
HIDDEN fr_dict_attr_t const * attr_dns_question
Definition base.c:53
HIDDEN fr_dict_attr_t const * attr_dns_rr
Definition base.c:54
fr_dns_labels_t * fr_dns_labels_get(uint8_t const *packet, size_t packet_len, bool init_mark)
Definition base.c:420
Implementation of the DNS protocol.
#define fr_dns_flag_dns_label(_da)
Definition dns.h:153
size_t packet_len
Definition dns.h:76
static bool fr_dns_flag_dns_label_any(fr_dict_attr_t const *da)
Definition dns.h:146
TALLOC_CTX * tmp_ctx
for temporary things cleaned up during decoding
Definition dns.h:74
uint8_t const * packet
DNS labels can point anywhere in the packet :(.
Definition dns.h:75
fr_dns_labels_t * lb
Definition dns.h:77
fr_test_point_proto_encode_t dns_tp_encode_proto
Definition encode.c:554
#define DNS_OPT_HDR_LEN
Definition encode.c:36
fr_test_point_pair_encode_t dns_tp_encode_pair
Definition encode.c:548
static ssize_t fr_dns_encode_rr(fr_dbuff_t *dbuff, fr_dcursor_t *cursor, void *encode_ctx)
Encode a Dns option and any sub-options.
Definition encode.c:376
static ssize_t fr_dns_encode_proto(UNUSED TALLOC_CTX *ctx, fr_pair_list_t *vps, uint8_t *data, size_t data_len, void *proto_ctx)
Definition encode.c:521
static ssize_t encode_record(fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, fr_pair_list_t *vps, fr_dict_attr_t const *attr, fr_dns_ctx_t *packet_ctx, uint8_t *counter)
Definition encode.c:406
ssize_t fr_dns_encode(fr_dbuff_t *dbuff, fr_pair_list_t *vps, fr_dns_ctx_t *packet_ctx)
Encode a DNS packet.
Definition encode.c:446
VQP attributes.
#define fr_assert(_expr)
Definition rad_assert.h:37
return count
Definition module.c:155
fr_pair_t * vp
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:753
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:94
fr_test_point_ctx_alloc_t test_ctx
Allocate a test ctx for the encoder.
Definition test_point.h:76
Entry point for pair encoders.
Definition test_point.h:93
Entry point for protocol encoders.
Definition test_point.h:75
static fr_pair_t * fr_pair_dcursor_child_iter_init(fr_dcursor_t *cursor, fr_pair_list_t const *list, fr_dcursor_t const *parent)
Initializes a child dcursor from a parent cursor, with an iteration function.
Definition pair.h:622
#define fr_pair_dcursor_by_da_init(_cursor, _list, _da)
Initialise a cursor that will return only attributes matching the specified fr_dict_attr_t.
Definition pair.h:639
#define PAIR_VERIFY(_x)
Definition pair.h:204
#define fr_pair_list_log(_log, _lvl, _list)
Definition pair.h:864
#define fr_pair_dcursor_init(_cursor, _list)
Initialises a special dcursor with callbacks that will maintain the attr sublists correctly.
Definition pair.h:604
#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
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
Definition strerror.h:64
#define fr_strerror_const(_msg)
Definition strerror.h:223
#define fr_type_is_structural(_x)
Definition types.h:392
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
Definition types.h:454
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:1495
static fr_slen_t data
Definition value.h:1340
static size_t char ** out
Definition value.h:1030