The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
dict.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/** Multi-protocol AVP dictionary API
19 *
20 * @file src/lib/util/dict.h
21 *
22 * @copyright 2015 The FreeRADIUS server project
23 */
24
25RCSIDH(dict_h, "$Id: 72ca2ba1a9a6f6a8a29d028b93fcc7e9d40058b8 $")
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#include <freeradius-devel/build.h>
32#include <freeradius-devel/missing.h>
33#include <freeradius-devel/util/dl.h>
34#include <freeradius-devel/util/ext.h>
35#include <freeradius-devel/util/hash.h>
36#include <freeradius-devel/util/rb.h>
37#include <freeradius-devel/util/sbuff.h>
38#include <freeradius-devel/util/table.h>
39#include <freeradius-devel/util/talloc.h>
40#include <freeradius-devel/util/types.h>
41
42
43/*
44 * Avoid circular type references.
45 */
47typedef struct fr_dict_s fr_dict_t;
48
50
51/*
52 * Allow public and private versions of the same structures
53 */
54#ifdef _CONST
55# error _CONST can only be defined in the local header
56#endif
57#ifndef _DICT_PRIVATE
58# define _CONST const
59#else
60# define _CONST
61#endif
62
63#ifdef WITH_VERIFY_PTR
64# define DA_VERIFY(_x) fr_dict_attr_verify(__FILE__, __LINE__, _x)
65#else
66# define DA_VERIFY(_x) fr_cond_assert(_x)
67#endif
68
71
72/** Values of the encryption flags
73 */
74typedef struct {
75 unsigned int is_root : 1; //!< Is root of a dictionary.
76
77 unsigned int is_unknown : 1; //!< This dictionary attribute is ephemeral
78 ///< and not part of the main dictionary.
79
80 unsigned int is_raw : 1; //!< This dictionary attribute was constructed
81 ///< from a known attribute to allow the user
82 ///< to assign octets values directly.
83 ///< See .is_unknown to determine if it is
84 ///< ephemeral.
85 unsigned int is_alias : 1; //!< This isn't a real attribute, it's a reference to
86 ///< to one.
87 unsigned int has_alias : 1; //!< this attribute has an alias.
88 unsigned int internal : 1; //!< Internal attribute, should not be received
89 ///< in protocol packets, should not be encoded.
90 unsigned int array : 1; //!< Pack multiples into 1 attr.
91
92 unsigned int is_known_width : 1; //!< is treated as if it has a known width for structs
93
94 unsigned int has_value : 1; //!< Has a value.
95
96 unsigned int is_unsigned : 1; //!< hackity hack for dates and time deltas
97
98 unsigned int counter : 1; //!< integer attribute is actually an impulse / counter
99
100 unsigned int name_only : 1; //!< this attribute should always be referred to by name.
101 ///< A number will be allocated, but the allocation scheme
102 ///< will depend on the parent, and definition type, and
103 ///< may not be stable in all instances.
104
105 unsigned int secret : 1; //!< this attribute should be omitted in debug mode
106
107 unsigned int unsafe : 1; //!< e.g. Cleartext-Password
108
109 unsigned int is_ref_target : 1; //!< is the target of a ref, and cannot be moved.
110
111 /*
112 * @todo - if we want to clean these fields up, make
113 * "subtype" and "type_size" both 4-bit bitfields. That
114 * gives us an extra 8 bits for adding new flags, and we
115 * can likely get rid of "extra", in order to save one
116 * more bit.
117 */
118 unsigned int extra : 1; //!< really "subtype is used by dict, not by protocol"
119
120 unsigned int local : 1; //!< is a local variable
121
122 unsigned int allow_flat : 1; //!< only for FR_TYPE_GROUP, can contain "flat" lists.
123
124 unsigned int has_fixup : 1; //! needs a fixup during dictionary parsing
125
126 /*
127 * main: extra is set, then this field is is key, bit, or a uint16 length field.
128 * radius: is one of 9 options for flags
129 * dhcp v4/v6: DNS label, or partial DNS label
130 */
131 uint8_t subtype; //!< protocol-specific values, OR key fields
132
133 /*
134 * TLVs: Number of bytes in the "type" field for TLVs (typically 1, 2, or 4)
135 *
136 * da_is_bit_field(da): offset in the byte where this bit
137 * field ends. This is only used as a caching mechanism
138 * during parsing of the dictionaries.
139 *
140 * time/time_delta: fr_time_res_t, which has 4 possible values.
141 *
142 * otherwise: unused.
143 */
144 uint8_t type_size; //!< Type size for TLVs
145
146 /*
147 * da_is_bit_field(da): Length of the field in bits.
148 *
149 * TLV: Number of bytes in the "length" field
150 *
151 * otherwise: Length in bytes
152 */
153 uint16_t length; //!< length of the attribute
155
156#define flag_time_res type_size
157#define flag_byte_offset type_size
158
159/** subtype values for the dictionary when extra=1
160 *
161 */
162enum {
163 FLAG_EXTRA_NONE = 0, //!< no extra meaning, should be invalid
164 FLAG_KEY_FIELD, //!< this is a key field for a subsequent struct
165 FLAG_BIT_FIELD, //!< bit field inside of a struct
166 FLAG_LENGTH_UINT8, //!< string / octets type is prefixed by uint8 of length
167 FLAG_LENGTH_UINT16, //!< string / octets type is prefixed by uint16 of length
168};
169
170#define fr_dict_attr_is_key_field(_da) ((_da)->flags.extra && ((_da)->flags.subtype == FLAG_KEY_FIELD))
171#define da_is_bit_field(_da) ((_da)->flags.extra && ((_da)->flags.subtype == FLAG_BIT_FIELD))
172#define da_is_length_field(_da) ((_da)->flags.extra && (((_da)->flags.subtype == FLAG_LENGTH_UINT8) || ((_da)->flags.subtype == FLAG_LENGTH_UINT16)))
173#define da_is_length_field8(_da) ((_da)->flags.extra && ((_da)->flags.subtype == FLAG_LENGTH_UINT8))
174#define da_is_length_field16(_da) ((_da)->flags.extra && ((_da)->flags.subtype == FLAG_LENGTH_UINT16))
175#define da_length_offset(_da) ((_da)->flags.type_size)
176
177/** Extension identifier
178 *
179 * @note New extension structures should also be added to the to the appropriate table in dict_ext.c
180 */
181typedef enum {
182 FR_DICT_ATTR_EXT_NAME = 0, //!< Name of the attribute.
183 FR_DICT_ATTR_EXT_CHILDREN, //!< Attribute has children.
184 FR_DICT_ATTR_EXT_REF, //!< Attribute references another
185 ///< attribute and/or dictionary.
186 FR_DICT_ATTR_EXT_KEY, //!< UNION attribute references a key
187 FR_DICT_ATTR_EXT_VENDOR, //!< Cached vendor pointer.
188 FR_DICT_ATTR_EXT_ENUMV, //!< Enumeration values.
189 FR_DICT_ATTR_EXT_NAMESPACE, //!< Attribute has its own namespace.
190 FR_DICT_ATTR_EXT_PROTOCOL_SPECIFIC, //!< Protocol specific extensions
193
194/** Dictionary attribute
195 */
197 fr_dict_t _CONST* _CONST dict; //!< Dict attribute belongs to.
198
199 char const *name; //!< Attribute name.
200 size_t name_len; //!< Length of the name.
201
202 unsigned int attr; //!< Attribute number.
203 unsigned int depth; //!< Depth of nesting for this attribute.
204
205 unsigned int last_child_attr; //!< highest value of last child attribute.
206
207 fr_type_t type; //!< Value type.
208
209 fr_dict_attr_t const *parent; //!< Immediate parent of this attribute.
210 fr_dict_attr_t const *next; //!< Next child in bin.
211
213
214 struct {
215 bool attr_set : 1; //!< Attribute number has been set.
216 //!< We need the full range of values 0-UINT32_MAX
217 ///< so we can't use any attr values to indicate
218 ///< "unsetness".
219
220 bool finalised : 1; //!< Attribute definition is complete and modifications
221 ///< that would change the address of the memory chunk
222 ///< of the attribute are no longer permitted.
224
225 char const *filename; //!< Where the attribute was defined.
226 ///< this buffer's lifetime is bound to the
227 ///< fr_dict_t.
228 int line; //!< Line number where the attribute was defined.
229
230 uint8_t ext[FR_DICT_ATTR_EXT_MAX]; //!< Extensions to the dictionary attribute.
231} CC_HINT(aligned(FR_EXT_ALIGNMENT));
232
233/** Extension identifier
234 *
235 * @note New extension structures should also be added to the appropriate table in dict_ext.c
236 */
237typedef enum {
238 FR_DICT_ENUM_EXT_ATTR_REF = 0, //!< Reference to a child attribute associated with this key value
241
242/** Enum extension - Sub-struct or union pointer
243 *
244 */
245typedef struct {
246 fr_dict_attr_t const *da; //!< the child structure referenced by this value of key
248
249/** Value of an enumerated attribute
250 *
251 * Maps one of more string values to integers and vice versa.
252 */
253typedef struct {
254 char const *name; //!< Enum name.
255 size_t name_len; //!< Allows for efficient name lookups when operating
256 ///< on partial buffers.
257 fr_value_box_t const *value; //!< Enum value (what name maps to).
258
259 uint8_t ext[FR_DICT_ENUM_EXT_MAX]; //!< Extensions to the dictionary attribute.
260} fr_dict_enum_value_t CC_HINT(aligned(FR_EXT_ALIGNMENT));
261
262/** Private enterprise
263 *
264 * Represents an IANA private enterprise allocation.
265 *
266 * The width of the private enterprise number must be the same for all protocols
267 * so we can represent a vendor with a single struct.
268 */
269typedef struct {
270 uint32_t pen; //!< Private enterprise number.
271 bool continuation; //!< we only have one flag for now, for WiMAX
272 size_t type; //!< Length of type data
273 size_t length; //!< Length of length data
274 char const *name; //!< Vendor name.
276
277/** Specifies a value which must be present for the module to function
278 *
279 */
280typedef struct {
281 fr_value_box_t const **out; //!< Enumeration value.
282 fr_dict_attr_t const **attr; //!< The protocol dictionary the attribute should
283 ///< be resolved in. ** so it's a compile time
284 ///< constant.
285 char const *name; //!< of the attribute.
287
288/** Specifies an attribute which must be present for the module to function
289 *
290 */
291typedef struct {
292 fr_dict_attr_t const **out; //!< Where to write a pointer to the resolved
293 //!< #fr_dict_attr_t.
294 fr_dict_t const **dict; //!< The protocol dictionary the attribute should
295 ///< be resolved in. ** so it's a compile time
296 ///< constant.
297 char const *name; //!< of the attribute.
298 fr_type_t type; //!< of the attribute. Mismatch is a fatal error.
300
301/** Specifies a dictionary which must be loaded/loadable for the module to function
302 *
303 */
304typedef struct {
305 fr_dict_t const **out; //!< Where to write a pointer to the loaded/resolved
306 //!< #fr_dict_t.
307 char const *base_dir; //!< Directory structure beneath share.
308 char const *proto; //!< The protocol dictionary name.
310
311#define DICT_AUTOLOAD_TERMINATOR { .out = NULL }
312
313
314/** Errors returned by attribute lookup functions
315 *
316 */
317typedef enum {
318 FR_DICT_ATTR_OK = 0, //!< No error.
319 FR_DICT_ATTR_NOTFOUND = -1, //!< Attribute couldn't be found.
320 FR_DICT_ATTR_PROTOCOL_NOTFOUND = -2, //!< Protocol couldn't be found.
321 FR_DICT_ATTR_PARSE_ERROR = -3, //!< Attribute string couldn't be parsed
322 FR_DICT_ATTR_INTERNAL_ERROR = -4, //!< Internal error occurred.
323 FR_DICT_ATTR_OOM = -5, //!< Memory allocation error.
324 FR_DICT_ATTR_NOT_DESCENDENT = -6, //!< Attribute is not a descendent of the parent
325 ///< attribute.
326 FR_DICT_ATTR_NOT_ANCESTOR = -7, //!< Attribute is not an ancestor of the child
327 ///< attribute.
328 FR_DICT_ATTR_NO_CHILDREN = -8, //!< Child lookup in attribute with no children.
329 FR_DICT_ATTR_EINVAL = -9 //!< Invalid arguments.
330
332
335
336/*
337 * Forward declarations to avoid circular references.
338 */
340typedef struct fr_dbuff_s fr_dbuff_t;
341
342/** A generic interface for decoding packets to fr_pair_ts
343 *
344 * A decoding function should decode a single top level packet from wire format.
345 *
346 * Note that unlike #fr_tp_proto_decode_t, this function is NOT passed an encode_ctx. That is because when we
347 * do cross-protocol encoding, the "outer" protocol has no information it can share with the "inner" protocol.
348 *
349 * @param[in] ctx to allocate new pairs in.
350 * @param[in] vps where new VPs will be added
351 * @param[in] data to decode.
352 * @param[in] data_len The length of the incoming data.
353 * @return
354 * - <= 0 on error. May be the offset (as a negative value) where the error occurred.
355 * - > 0 on success. How many bytes were decoded.
356 */
357typedef ssize_t (*fr_dict_attr_decode_func_t)(TALLOC_CTX *ctx, fr_pair_list_t *vps,
358 uint8_t const *data, size_t data_len);
359
360/** A generic interface for encoding fr_pair_ts to packets
361 *
362 * An encoding function should encode multiple VPs to a wire format packet
363 *
364 * Note that unlike #fr_tp_proto_encode_t, this function is NOT passed an encode_ctx. That is because when we
365 * do cross-protocol encoding, the "outer" protocol has no information it can share with the "inner" protocol.
366 *
367 * @param[in] vps vps to encode
368 * @param[in] dbuff buffer where data can be written
369 * @return
370 * - <= 0 on error. May be the offset (as a negative value) where the error occurred.
371 * - > 0 on success. How many bytes were encoded
372 */
374
375/** Init / free callbacks
376 *
377 * Only for "autoref" usage.
378 */
379typedef int (*fr_dict_protocol_init_t)(void);
380typedef void (*fr_dict_protocol_free_t)(void);
381
383
384/** Custom protocol-specific flag parsing function
385 *
386 * @note This function should be used to implement table based flag parsing.
387 *
388 * @param[in] da_p we're currently populating
389 * @param[in] value flag value to parse.
390 * @param[in] rule How to parse the flag.
391 */
393
395 fr_dict_flag_parse_func_t func; //!< Custom parsing function to convert a flag value string to a C type value.
396 void *uctx; //!< Use context to pass to the custom parsing function.
397 bool needs_value; //!< This parsing flag must have a value. Else we error.
398};
399
400/** Copy custom flags from one attribute to another
401 *
402 * @param[out] da_to attribute to copy to. Use for the talloc_ctx for any heap allocated flag values.
403 * @param[out] flags_to protocol specific flags struct to copy to.
404 * @param[in] flags_from protocol specific flags struct to copy from.
405 * @return
406 * - 0 on success.
407 * - -1 on error.
408 */
409typedef int (*fr_dict_flags_copy_func_t)(fr_dict_attr_t *da_to, void *flags_to, void *flags_from);
410
411/** Compare the protocol specific flags struct from two attributes
412 *
413 * @param[in] da_a first attribute to compare.
414 * @param[in] da_b second attribute to compare.
415 * @return
416 * - 0 if the flags are equal.
417 * - < 0 if da_a < da_b.
418 * - > 0 if da_a > da_b.
419 */
420 typedef int (*fr_dict_flags_cmp_func_t)(fr_dict_attr_t const *da_a, fr_dict_attr_t const *da_b);
421
422/** Protocol specific custom flag definitnion
423 *
424 */
425typedef struct {
426 fr_table_elem_name_t name; //!< Name of the flag
427 fr_dict_flag_parser_rule_t value; //!< Function and context to parse the flag.
429
430/** Define a flag setting function, which sets one bit in a fr_dict_attr_flags_t
431 *
432 * This is here, because AFAIK there's no completely portable way to get the bit
433 * offset of a bit field in a structure.
434 */
435#define FR_DICT_ATTR_FLAG_FUNC(_struct, _name) \
436static int dict_flag_##_name(fr_dict_attr_t **da_p, UNUSED char const *value, UNUSED fr_dict_flag_parser_rule_t const *rules)\
437{ \
438 _struct *flags = fr_dict_attr_ext(*da_p, FR_DICT_ATTR_EXT_PROTOCOL_SPECIFIC); \
439 flags->_name = 1; \
440 return 0; \
441}
442
443/** conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
444 *
445 * @param[in] _struct containing the field to write the result to.
446 * @param[in] _field to write the flag to
447 */
448# define FR_DICT_PROTOCOL_FLAG(_struct, _field) \
449 .type = FR_CTYPE_TO_TYPE((((_struct *)NULL)->_field)), \
450 .offset = offsetof(_struct, _field)
451
452/** Protocol-specific callbacks in libfreeradius-PROTOCOL
453 *
454 */
455typedef struct {
456 char const *name; //!< name of this protocol
457
458 int default_type_size; //!< how many octets are in "type" field
459 int default_type_length; //!< how many octets are in "length" field
460
461 struct {
462 /** Custom flags for this protocol
463 */
464 struct {
465 fr_dict_flag_parser_t const *table; //!< Flags for this protocol, an array of fr_dict_flag_parser_t
466 size_t table_len; //!< Length of protocol_flags table.
467
468 size_t len; //!< Length of the protocol specific flags structure.
469 ///< This is used to allocate a FR_DICT_ATTR_EXT_PROTOCOL_SPECIFIC
470 ///< extension of the specified length.
471
472 fr_dict_flags_copy_func_t copy; //!< Copy protocol-specific flags from one attribute to another.
473 ///< Called when copying attributes.
474
475 fr_dict_flags_cmp_func_t cmp; //!< Compare protocol-specific flags from two attributes.
476 ///< Called when comparing attributes by their fields.
477 } flags;
478
479 fr_dict_attr_type_parse_t type_parse; //!< parse unknown type names
480 fr_dict_attr_valid_func_t valid; //!< Validation function to ensure that
481 ///< new attributes are valid.
482 } attr;
483
484 fr_dict_protocol_init_t init; //!< initialize the library
485 fr_dict_protocol_free_t free; //!< free the library
486
487 fr_dict_attr_decode_func_t decode; //!< for decoding attributes. Used for implementing foreign
488 ///< protocol attributes.
489 fr_dict_attr_encode_func_t encode; //!< for encoding attributes. Used for implementing foreign
490 ///< protocol attributes.
492
494
495/*
496 * Dictionary constants
497 */
498#define FR_DICT_PROTO_MAX_NAME_LEN (128) //!< Maximum length of a protocol name.
499#define FR_DICT_ENUM_MAX_NAME_LEN (128) //!< Maximum length of a enum value.
500#define FR_DICT_VENDOR_MAX_NAME_LEN (128) //!< Maximum length of a vendor name.
501#define FR_DICT_ATTR_MAX_NAME_LEN (128) //!< Maximum length of a attribute name.
502
503/** Maximum level of TLV nesting allowed
504 */
505#define FR_DICT_TLV_NEST_MAX (24)
506
507/** Maximum TLV stack size
508 *
509 * The additional attributes are to account for
510 *
511 * Root + Vendor + NULL (top frame).
512 * Root + Embedded protocol + Root + Vendor + NULL.
513 *
514 * Code should ensure that it doesn't run off the end of the stack,
515 * as this could be remotely exploitable, using odd nesting.
516 */
517#define FR_DICT_MAX_TLV_STACK (FR_DICT_TLV_NEST_MAX + 5)
518
519/** Characters allowed in a single dictionary attribute name
520 *
521 */
523
524/** Characters allowed in a nested dictionary attribute name
525 *
526 */
528
529/** Characters that are allowed in dictionary enumeration value names
530 *
531 */
533
534/** @name Dictionary structure extensions
535 *
536 * @{
537 */
538#include <freeradius-devel/util/dict_ext.h>
539/** @} */
540
541/** @name Programmatically create dictionary attributes and values
542 *
543 * @{
544 */
546
547int fr_dict_attr_add(fr_dict_t *dict, fr_dict_attr_t const *parent, char const *name, unsigned int attr,
548 fr_type_t type, fr_dict_attr_flags_t const *flags) CC_HINT(nonnull(1,2,3));
549
551 char const *name, fr_type_t type, fr_dict_attr_flags_t const *flags) CC_HINT(nonnull(1,2,3));
552
553int fr_dict_enum_add_name(fr_dict_attr_t *da, char const *name,
554 fr_value_box_t const *value, bool coerce, bool replace);
555
556int fr_dict_enum_add_name_next(fr_dict_attr_t *da, char const *name) CC_HINT(nonnull);
557
558int fr_dict_str_to_argv(char *str, char **argv, int max_argc);
559
560int fr_dict_attr_acopy_local(fr_dict_attr_t const *dst, fr_dict_attr_t const *src) CC_HINT(nonnull);
561
562int fr_dict_attr_set_group(fr_dict_attr_t **da_p, fr_dict_attr_t const *ref) CC_HINT(nonnull);
563/** @} */
564
565/** @name Dict accessors
566 *
567 * @{
568 */
570/** @} */
571
572/** @name Unknown ephemeral attributes
573 *
574 * @{
575 */
576fr_dict_attr_t *fr_dict_attr_unknown_alloc(TALLOC_CTX *ctx, fr_dict_attr_t const *da, fr_type_t type) CC_HINT(nonnull(2));
577
579
581
582fr_dict_attr_t *fr_dict_attr_unknown_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da) CC_HINT(nonnull(2));
583
584static inline fr_dict_attr_t *fr_dict_attr_unknown_copy(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
585{
586 fr_assert(da->flags.is_unknown);
587
588 return fr_dict_attr_unknown_afrom_da(ctx, da);
589}
590
592 fr_dict_attr_t const *parent,
593 unsigned int num, fr_type_t type, bool raw)
594 CC_HINT(nonnull(2));
595
596static inline CC_HINT(nonnull(2)) fr_dict_attr_t *fr_dict_attr_unknown_typed_afrom_num(TALLOC_CTX *ctx,
597 fr_dict_attr_t const *parent,
598 unsigned int num, fr_type_t type)
599{
600 return fr_dict_attr_unknown_typed_afrom_num_raw(ctx, parent, num, type, false);
601}
602
603
604static inline CC_HINT(nonnull(2)) fr_dict_attr_t *fr_dict_attr_unknown_vendor_afrom_num(TALLOC_CTX *ctx,
605 fr_dict_attr_t const *parent,
606 unsigned int vendor)
607{
609}
610
611static inline CC_HINT(nonnull(2)) fr_dict_attr_t *fr_dict_attr_unknown_raw_afrom_num(TALLOC_CTX *ctx,
612 fr_dict_attr_t const *parent,
613 unsigned int attr)
614{
616}
617
618static inline CC_HINT(nonnull(2)) fr_dict_attr_t *fr_dict_attr_unknown_afrom_oid(TALLOC_CTX *ctx,
619 fr_dict_attr_t const *parent,
621{
622 uint32_t num;
624
625 fr_sbuff_out(&sberr, &num, in);
626 if (sberr != FR_SBUFF_PARSE_OK) return NULL;
627
629}
630
631static inline CC_HINT(nonnull(2)) fr_dict_attr_t *fr_dict_attr_unknown_raw_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
632{
634}
635
636
638 fr_dict_attr_t const **out,
639 fr_dict_attr_t const *parent,
641 CC_HINT(nonnull(2,3,4));
642
644
646/** @} */
647
648/** @name Attribute comparisons
649 *
650 * @{
651 */
653
654static inline CC_HINT(nonnull) int8_t fr_dict_attr_cmp(fr_dict_attr_t const *a, fr_dict_attr_t const *b)
655{
656 int8_t ret;
657
658 /*
659 * Comparing unknowns or raws is expensive
660 * because we need to check the lineage.
661 */
662 if (a->flags.is_unknown | a->flags.is_raw | b->flags.is_unknown | b->flags.is_raw) {
663 ret = CMP(a->depth, b->depth);
664 if (ret != 0) return ret;
665
666 ret = CMP(a->attr, b->attr);
667 if (ret != 0) return ret;
668
669 ret = (a->parent == NULL) - (b->parent == NULL);
670 if ((ret != 0) || !a->parent) return ret;
671
672 return fr_dict_attr_cmp(a->parent, b->parent);
673 }
674
675 /*
676 * Comparing knowns is cheap because the
677 * DAs are unique.
678 */
679 return CMP(a, b);
680}
681
682/** Compare two dictionary attributes by their contents
683 *
684 * @param[in] a First attribute to compare.
685 * @param[in] b Second attribute to compare.
686 * @return
687 * - 0 if the attributes are equal.
688 * - -1 if a < b.
689 * - +1 if a > b.
690 */
691static inline CC_HINT(nonnull) int8_t fr_dict_attr_cmp_fields(const fr_dict_attr_t *a, const fr_dict_attr_t *b)
692{
693 int8_t ret;
694 fr_dict_protocol_t const *a_proto = fr_dict_protocol(a->dict);
695
696 /*
697 * Technically this isn't a property of the attribute
698 * but we need them to be the same to be able to
699 * compare protocol specific flags successfully.
700 */
701 ret = CMP(a_proto, fr_dict_protocol(b->dict));
702 if (ret != 0) return ret;
703
704 ret = CMP(a->attr, b->attr);
705 if (ret != 0) return ret;
706
707 ret = CMP(a->parent, b->parent);
708 if (ret != 0) return ret;
709
711 if (ret != 0) return ret;
712
713 /*
714 * Compare protocol specific flags
715 */
716 if (a_proto->attr.flags.cmp && (ret = a_proto->attr.flags.cmp(a, b))) return ret;
717
718 return CMP(memcmp(&a->flags, &b->flags, sizeof(a->flags)), 0);
719}
720/** @} */
721
722/** @name Debugging functions
723 *
724 * @{
725 */
726void fr_dict_namespace_debug(FILE *fp, fr_dict_attr_t const *da);
727
728void fr_dict_attr_debug(FILE *fp, fr_dict_attr_t const *da);
729
730void fr_dict_debug(FILE *fp, fr_dict_t const *dict);
731
732void fr_dict_export(FILE *fp, fr_dict_t const *dict);
733
734void fr_dict_alias_export(FILE *fp, fr_dict_attr_t const *parent);
735/** @} */
736
737/** @name Attribute lineage
738 *
739 * @{
740 */
741fr_dict_attr_t const *fr_dict_attr_common_parent(fr_dict_attr_t const *a, fr_dict_attr_t const *b, bool is_ancestor);
742
743int fr_dict_oid_component_legacy(unsigned int *out, char const **oid);
744
746 fr_type_t type, fr_dict_attr_flags_t const *flags);
747
749 fr_dict_attr_t const *ancestor, fr_dict_attr_t const *da, bool numeric);
750#define FR_DICT_ATTR_OID_PRINT_RETURN(...) FR_SBUFF_RETURN(fr_dict_attr_oid_print, ##__VA_ARGS__)
751
753 unsigned int *attr, char const *oid) CC_HINT(nonnull);
754
756 fr_dict_attr_t const **out, fr_dict_attr_t const *parent,
757 fr_sbuff_t *in, fr_sbuff_term_t const *tt)
758 CC_HINT(nonnull(2,3,4));
759
761 fr_dict_attr_t const **out, fr_dict_attr_t const *parent,
762 fr_sbuff_t *in, fr_sbuff_term_t const *tt)
763 CC_HINT(nonnull(2,3,4));
764
766 fr_dict_attr_t const *parent, char const *oid)
767 CC_HINT(nonnull(2,3));
768
769bool fr_dict_attr_can_contain(fr_dict_attr_t const *parent, fr_dict_attr_t const *child) CC_HINT(nonnull);
770
771/** @} */
772
773/** @name Attribute, vendor and dictionary lookup
774 *
775 * @{
776 */
777
778/** @hidecallergraph */
779fr_dict_attr_t const *fr_dict_root(fr_dict_t const *dict) CC_HINT(nonnull);
780
781bool fr_dict_is_read_only(fr_dict_t const *dict);
782
783dl_t *fr_dict_dl(fr_dict_t const *dict);
784
786 fr_dict_t const **out, fr_sbuff_t *name, fr_dict_t const *dict_def);
787
788fr_dict_t const *fr_dict_by_protocol_name(char const *name);
789
790fr_dict_t const *fr_dict_by_protocol_num(unsigned int num);
791
792fr_dict_attr_t const *fr_dict_unlocal(fr_dict_attr_t const *da) CC_HINT(nonnull);
793
794fr_dict_t const *fr_dict_proto_dict(fr_dict_t const *dict) CC_HINT(nonnull);
795
796fr_dict_t const *fr_dict_by_da(fr_dict_attr_t const *da) CC_HINT(nonnull);
797
798fr_dict_t const *fr_dict_by_attr_name(fr_dict_attr_t const **found, char const *name);
799
800bool fr_dict_compatible(fr_dict_t const *dict1, fr_dict_t const *dict2) CC_HINT(nonnull);
801
802/** Return true if this attribute is parented directly off the dictionary root
803 *
804 * @param[in] da to check.
805 * @return
806 * - true if attribute is top level.
807 * - false if attribute is not top level.
808 */
809static inline bool fr_dict_attr_is_top_level(fr_dict_attr_t const *da)
810{
811 if (unlikely(!da) || unlikely(!da->parent)) return false;
812 return da->parent->flags.is_root;
813}
814
816
817fr_dict_vendor_t const *fr_dict_vendor_by_name(fr_dict_t const *dict, char const *name);
818
819fr_dict_vendor_t const *fr_dict_vendor_by_num(fr_dict_t const *dict, uint32_t vendor_pen);
820
821fr_dict_attr_t const *fr_dict_vendor_da_by_num(fr_dict_attr_t const *vendor_root, uint32_t vendor_pen);
822
824 fr_dict_t const *dict_def,
825 fr_sbuff_t *name, fr_sbuff_term_t const *tt,
826 bool internal, bool foreign)
827 CC_HINT(nonnull(2, 4));
828
830 fr_dict_t const *dict_def,
831 fr_sbuff_t *name, fr_sbuff_term_t const *tt,
832 bool internal, bool foreign)
833 CC_HINT(nonnull(2, 4));
834
836 fr_dict_t const *dict_def,
837 fr_sbuff_t *in, fr_sbuff_term_t const *tt,
838 bool internal, bool foreign)
839 CC_HINT(nonnull(2, 4));
840
842 fr_dict_t const *dict_def, char const *attr,
843 bool internal, bool foreign)
844 CC_HINT(nonnull(3));
845
847 fr_dict_t const *dict_def,
848 fr_sbuff_t *in, fr_sbuff_term_t const *tt,
849 bool internal, bool foreign)
850 CC_HINT(nonnull(2, 4));
851
853 fr_dict_attr_t const *parent,
854 fr_sbuff_t *name, fr_sbuff_term_t const *tt)
855 CC_HINT(nonnull(2,3,4));
856
858 char const *attr)
859 CC_HINT(nonnull(2,3));
860
861fr_dict_attr_t const *fr_dict_attr_child_by_num(fr_dict_attr_t const *parent, unsigned int attr);
862
863typedef fr_hash_iter_t fr_dict_enum_iter_t; /* Alias this in case we want to change it in future */
864
866
868
870
872
873fr_dict_enum_value_t const *fr_dict_enum_by_name(fr_dict_attr_t const *da, char const *name, ssize_t len);
874
876
878 fr_sbuff_t *in, fr_sbuff_term_t const *tt);
879
881 fr_sbuff_t *in, fr_sbuff_term_t const *tt)
883/** @} */
884
885/** @name Dictionary and protocol loading
886 *
887 * @{
888 */
889int fr_dict_internal_afrom_file(fr_dict_t **out, char const *dict_subdir,
890 char const *dependent) CC_HINT(nonnull(1,3));
891
892int fr_dict_protocol_afrom_file(fr_dict_t **out, char const *proto_name, char const *proto_dir,
893 char const *dependent) CC_HINT(nonnull(1,2,4));
894
896
897int fr_dict_protocol_reference(fr_dict_attr_t const **da_p, fr_dict_attr_t const *root, fr_sbuff_t *in) CC_HINT(nonnull);
898
899int fr_dict_read(fr_dict_t *dict, char const *dict_dir, char const *filename) CC_HINT(nonnull(3));
900
901bool fr_dict_filename_loaded(fr_dict_t const *dict, char const *dict_dir, char const *filename) CC_HINT(nonnull(2,3));
902/** @} */
903
904/** @name Autoloader interface
905 *
906 * @{
907 */
908int fr_dict_enum_autoload(fr_dict_enum_autoload_t const *to_load) CC_HINT(nonnull);
909
910int fr_dict_attr_autoload(fr_dict_attr_autoload_t const *to_load) CC_HINT(nonnull);
911
912#define fr_dict_autoload(_to_load) _fr_dict_autoload(_to_load, __FILE__)
913int _fr_dict_autoload(fr_dict_autoload_t const *to_load, char const *dependent);
914
915#define fr_dict_autofree(_to_free) _fr_dict_autofree(_to_free, __FILE__)
916int _fr_dict_autofree(fr_dict_autoload_t const *to_free, char const *dependent);
917
918#define fr_dict_autoload_talloc(_ctx, _dict_out, _proto) _fr_dict_autoload_talloc(_ctx, _dict_out, _proto, __FILE__)
919fr_dict_autoload_talloc_t *_fr_dict_autoload_talloc(TALLOC_CTX *ctx, fr_dict_t const **out, char const *proto, char const *dependent);
920
921int fr_dl_dict_enum_autoload(dl_t const *module, void *symbol, void *uctx) CC_HINT(nonnull(1,2));
922
923int fr_dl_dict_attr_autoload(dl_t const *module, void *symbol, void *uctx) CC_HINT(nonnull(1,2));
924
925int fr_dl_dict_autoload(dl_t const *module, void *symbol, void *uctx) CC_HINT(nonnull(1,2));
926
927void fr_dl_dict_autofree(dl_t const *module, void *symbol, void *uctx) CC_HINT(nonnull(1,2));
928/** @} */
929
930/** @name Allocating and freeing
931 *
932 * @{
933 */
934fr_dict_t *fr_dict_alloc(char const *proto_name, unsigned int proto_number) CC_HINT(nonnull);
935
936int fr_dict_dependent_add(fr_dict_t const *dict, char const *dependent) CC_HINT(nonnull);
937
938int fr_dict_free(fr_dict_t **dict, char const *dependent) CC_HINT(nonnull);
939
940int fr_dict_const_free(fr_dict_t const **dict, char const *dependent) CC_HINT(nonnull);
941/** @} */
942
943/** @name Global dictionary management
944 *
945 * @{
946 */
947fr_dict_gctx_t *fr_dict_global_ctx_init(TALLOC_CTX *ctx, bool free_at_exit, char const *dict_dir) CC_HINT(nonnull(3));
948
949void fr_dict_global_ctx_perm_check(fr_dict_gctx_t *gctx, bool enable) CC_HINT(nonnull);
950
951void fr_dict_global_ctx_set(fr_dict_gctx_t const *gctx) CC_HINT(nonnull);
952
953int fr_dict_global_ctx_free(fr_dict_gctx_t const *gctx) CC_HINT(nonnull);
954
955int fr_dict_global_ctx_dir_set(char const *dict_dir) CC_HINT(nonnull);
956
958
959void fr_dict_gctx_debug(FILE *fp, fr_dict_gctx_t const *gctx) CC_HINT(nonnull(1));
960
961char const *fr_dict_global_ctx_dir(void);
962
964
966
968
969fr_dict_t *fr_dict_unconst(fr_dict_t const *dict) CC_HINT(nonnull);
970
972
973fr_dict_t const *fr_dict_internal(void);
974
975/** @} */
976
977/** @name Dictionary testing and validation
978 *
979 * @{
980 */
981void dict_dctx_debug(dict_tokenize_ctx_t *dctx) CC_HINT(nonnull);
982
983int fr_dict_parse_str(fr_dict_t *dict, char const *str,
984 fr_dict_attr_t const *parent) CC_HINT(nonnull(2,3));
985
986ssize_t fr_dict_valid_name(char const *name, ssize_t len) CC_HINT(nonnull);
987
988ssize_t fr_dict_valid_oid_str(char const *name, ssize_t len) CC_HINT(nonnull);
989
991 fr_dict_attr_t const **prev) CC_HINT(nonnull);
992
993typedef int (*fr_dict_walk_t)(fr_dict_attr_t const *da, void *uctx);
994
995int fr_dict_walk(fr_dict_attr_t const *da, fr_dict_walk_t callback, void *uctx) CC_HINT(nonnull(1,2));
996
997void fr_dict_attr_verify(char const *file, int line, fr_dict_attr_t const *da) CC_HINT(nonnull);
998/** @} */
999
1000#undef _CONST
1001
1002#ifdef __cplusplus
1003}
1004#endif
int const char * file
Definition acutest.h:702
int const char int line
Definition acutest.h:702
#define RCSIDH(h, id)
Definition build.h:489
#define CMP(_a, _b)
Same as CMP_PREFER_SMALLER use when you don't really care about ordering, you just want an ordering.
Definition build.h:113
#define unlikely(_x)
Definition build.h:384
#define UNUSED
Definition build.h:318
fr_table_elem_name_t name
Name of the flag.
Definition dict.h:426
fr_dict_t * fr_dict_global_ctx_iter_next(fr_dict_global_ctx_iter_t *iter)
Definition dict_util.c:4892
bool continuation
we only have one flag for now, for WiMAX
Definition dict.h:271
size_t type
Length of type data.
Definition dict.h:272
fr_dict_t const * fr_dict_by_attr_name(fr_dict_attr_t const **found, char const *name)
int fr_dict_attr_set_group(fr_dict_attr_t **da_p, fr_dict_attr_t const *ref)
Definition dict_util.c:5283
fr_dict_protocol_free_t free
free the library
Definition dict.h:485
void fr_dict_namespace_debug(FILE *fp, fr_dict_attr_t const *da)
Definition dict_print.c:240
size_t name_len
Allows for efficient name lookups when operating on partial buffers.
Definition dict.h:255
fr_dict_attr_flags_t flags
Flags.
Definition dict.h:212
fr_dict_attr_decode_func_t decode
for decoding attributes.
Definition dict.h:487
int(* fr_dict_flag_parse_func_t)(fr_dict_attr_t **da_p, UNUSED char const *value, UNUSED fr_dict_flag_parser_rule_t const *rule)
Custom protocol-specific flag parsing function.
Definition dict.h:392
fr_slen_t fr_dict_attr_by_name_substr(fr_dict_attr_err_t *err, fr_dict_attr_t const **out, fr_dict_attr_t const *parent, fr_sbuff_t *name, fr_sbuff_term_t const *tt))
struct fr_dict_protocol_t::@124 attr
int fr_dict_attr_add_initialised(fr_dict_attr_t *da)
A variant of fr_dict_attr_t that allows a pre-allocated, populated fr_dict_attr_t to be added.
Definition dict_util.c:1845
char const * name
of the attribute.
Definition dict.h:297
unsigned int name_only
this attribute should always be referred to by name.
Definition dict.h:100
ssize_t fr_dict_valid_oid_str(char const *name, ssize_t len)
Definition dict_util.c:4981
int fr_dict_global_ctx_dir_set(char const *dict_dir)
Allow the default dict dir to be changed after initialisation.
Definition dict_util.c:4799
fr_slen_t fr_dict_enum_name_from_substr(fr_sbuff_t *out, fr_sbuff_parse_error_t *err, fr_sbuff_t *in, fr_sbuff_term_t const *tt)
Extract an enumeration name from a string.
Definition dict_util.c:3821
int fr_dict_enum_add_name(fr_dict_attr_t *da, char const *name, fr_value_box_t const *value, bool coerce, bool replace)
Add a value name.
Definition dict_util.c:2217
fr_dict_attr_t const * fr_dict_attr_search_by_qualified_oid(fr_dict_attr_err_t *err, fr_dict_t const *dict_def, char const *attr, bool internal, bool foreign))
Locate a qualified fr_dict_attr_t by its name and a dictionary qualifier.
Definition dict_util.c:3346
fr_dict_attr_t const * fr_dict_attr_unknown_resolve(fr_dict_t const *dict, fr_dict_attr_t const *da)
Check to see if we can convert a nested TLV structure to known attributes.
unsigned int has_value
Has a value.
Definition dict.h:94
fr_dict_enum_ext_t
Extension identifier.
Definition dict.h:237
@ FR_DICT_ENUM_EXT_MAX
Definition dict.h:239
@ FR_DICT_ENUM_EXT_ATTR_REF
Reference to a child attribute associated with this key value.
Definition dict.h:238
fr_slen_t fr_dict_attr_oid_print(fr_sbuff_t *out, fr_dict_attr_t const *ancestor, fr_dict_attr_t const *da, bool numeric)
Build the da_stack for the specified DA and encode the path by name in OID form.
int fr_dict_attr_add_name_only(fr_dict_t *dict, fr_dict_attr_t const *parent, char const *name, fr_type_t type, fr_dict_attr_flags_t const *flags))
Add an attribute to the dictionary.
Definition dict_util.c:2006
char const * name
Vendor name.
Definition dict.h:274
unsigned int is_ref_target
is the target of a ref, and cannot be moved.
Definition dict.h:109
char const * filename
Where the attribute was defined.
Definition dict.h:225
fr_dict_t * fr_dict_unconst(fr_dict_t const *dict)
Coerce to non-const.
Definition dict_util.c:4903
void * uctx
Use context to pass to the custom parsing function.
Definition dict.h:396
fr_dict_attr_t const ** attr
The protocol dictionary the attribute should be resolved in.
Definition dict.h:282
fr_dict_t const * fr_dict_by_da(fr_dict_attr_t const *da)
Attempt to locate the protocol dictionary containing an attribute.
Definition dict_util.c:2871
int fr_dl_dict_enum_autoload(dl_t const *module, void *symbol, void *uctx))
unsigned int is_root
Is root of a dictionary.
Definition dict.h:75
int fr_dict_enum_autoload(fr_dict_enum_autoload_t const *to_load)
Process a dict_attr_autoload element to load/verify a dictionary attribute.
Definition dict_util.c:4356
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:3614
int _fr_dict_autofree(fr_dict_autoload_t const *to_free, char const *dependent)
Decrement the reference count on a previously loaded dictionary.
Definition dict_util.c:4493
fr_dict_attr_t const * fr_dict_unlocal(fr_dict_attr_t const *da)
Definition dict_util.c:5260
bool const fr_dict_attr_nested_allowed_chars[SBUFF_CHAR_CLASS]
Characters allowed in a nested dictionary attribute name.
Definition dict_util.c:70
fr_dict_attr_t const * fr_dict_attr_common_parent(fr_dict_attr_t const *a, fr_dict_attr_t const *b, bool is_ancestor)
Find a common ancestor that two TLV type attributes share.
Definition dict_util.c:2313
bool const fr_dict_attr_allowed_chars[SBUFF_CHAR_CLASS]
Characters allowed in a single dictionary attribute name.
Definition dict_util.c:63
size_t name_len
Length of the name.
Definition dict.h:200
int line
Line number where the attribute was defined.
Definition dict.h:228
bool(* fr_dict_attr_valid_func_t)(fr_dict_attr_t *da)
Definition dict.h:333
static fr_slen_t err
Definition dict.h:882
fr_dict_t * fr_dict_alloc(char const *proto_name, unsigned int proto_number)
fr_dict_t const * fr_dict_proto_dict(fr_dict_t const *dict)
Definition dict_util.c:5276
unsigned int has_fixup
Definition dict.h:124
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
void fr_dict_alias_export(FILE *fp, fr_dict_attr_t const *parent)
Definition dict_print.c:324
static fr_dict_attr_t * fr_dict_attr_unknown_raw_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Definition dict.h:631
static fr_dict_attr_t * fr_dict_attr_unknown_afrom_oid(TALLOC_CTX *ctx, fr_dict_attr_t const *parent, fr_sbuff_t *in, fr_type_t type)
Definition dict.h:618
static fr_dict_attr_t * fr_dict_attr_unknown_copy(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Definition dict.h:584
int8_t fr_dict_attr_ordered_cmp(fr_dict_attr_t const *a, fr_dict_attr_t const *b)
Compare two attributes by total order.
Definition dict_util.c:228
fr_dict_protocol_t const * fr_dict_protocol(fr_dict_t const *dict)
Return the protocol descriptor for the dictionary.
Definition dict_util.c:5252
int fr_dict_protocol_reference(fr_dict_attr_t const **da_p, fr_dict_attr_t const *root, fr_sbuff_t *in)
Resolve a reference string to a dictionary attribute.
Definition dict_fixup.c:135
ssize_t(* fr_dict_attr_encode_func_t)(fr_dbuff_t *dbuff, fr_pair_list_t const *vps)
A generic interface for encoding fr_pair_ts to packets.
Definition dict.h:373
fr_dict_attr_t const * fr_dict_attr_unknown_add(fr_dict_t *dict, fr_dict_attr_t const *old)
Converts an unknown to a known by adding it to the internal dictionaries.
int fr_dict_attr_acopy_local(fr_dict_attr_t const *dst, fr_dict_attr_t const *src)
Definition dict_util.c:1129
fr_dict_attr_t const * fr_dict_attr_by_name(fr_dict_attr_err_t *err, fr_dict_attr_t const *parent, char const *attr))
Locate a fr_dict_attr_t by its name.
Definition dict_util.c:3528
int fr_dict_internal_afrom_file(fr_dict_t **out, char const *dict_subdir, char const *dependent))
(Re-)Initialize the special internal dictionary
fr_dict_autoload_talloc_t * _fr_dict_autoload_talloc(TALLOC_CTX *ctx, fr_dict_t const **out, char const *proto, char const *dependent)
Autoload a dictionary and bind the lifetime to a talloc chunk.
Definition dict_util.c:4544
bool const fr_dict_enum_allowed_chars[SBUFF_CHAR_CLASS]
Characters that are allowed in dictionary enumeration value names.
Definition dict_util.c:78
bool fr_dict_compatible(fr_dict_t const *dict1, fr_dict_t const *dict2)
See if two dictionaries have the same end parent.
Definition dict_util.c:2884
int(* fr_dict_flags_cmp_func_t)(fr_dict_attr_t const *da_a, fr_dict_attr_t const *da_b)
Compare the protocol specific flags struct from two attributes.
Definition dict.h:420
void fr_dict_debug(FILE *fp, fr_dict_t const *dict)
Definition dict_print.c:278
fr_value_box_t const ** out
Enumeration value.
Definition dict.h:281
fr_dict_attr_t * fr_dict_attr_unconst(fr_dict_attr_t const *da)
Coerce to non-const.
Definition dict_util.c:4915
fr_dict_attr_t * fr_dict_attr_unknown_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da))
Copy a known or unknown attribute to produce an unknown attribute with the specified name.
fr_dict_t const ** dict
The protocol dictionary the attribute should be resolved in.
Definition dict.h:294
fr_slen_t fr_dict_attr_by_oid_substr(fr_dict_attr_err_t *err, fr_dict_attr_t const **out, fr_dict_attr_t const *parent, fr_sbuff_t *in, fr_sbuff_term_t const *tt))
Resolve an attribute using an OID string.
Definition dict_util.c:2589
fr_dict_attr_t * fr_dict_attr_unknown_alloc(TALLOC_CTX *ctx, fr_dict_attr_t const *da, fr_type_t type))
Allocate an unknown DA.
void fr_dict_gctx_debug(FILE *fp, fr_dict_gctx_t const *gctx))
Dump information about currently loaded dictionaries.
Definition dict_util.c:4846
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
void fr_dict_attr_verify(char const *file, int line, fr_dict_attr_t const *da)
Definition dict_util.c:5099
int fr_dict_str_to_argv(char *str, char **argv, int max_argc)
bool fr_dict_attr_can_contain(fr_dict_attr_t const *parent, fr_dict_attr_t const *child)
See if a structural da is allowed to contain another da.
Definition dict_util.c:5189
fr_slen_t fr_dict_attr_by_oid_legacy(fr_dict_attr_t const **parent, unsigned int *attr, char const *oid)
Get the leaf attribute of an OID string.
Definition dict_util.c:2399
fr_slen_t fr_dict_attr_flags_print(fr_sbuff_t *out, fr_dict_t const *dict, fr_type_t type, fr_dict_attr_flags_t const *flags)
fr_dict_t * fr_dict_global_ctx_iter_init(fr_dict_global_ctx_iter_t *iter)
Iterate protocols by name.
Definition dict_util.c:4885
int(* fr_dict_walk_t)(fr_dict_attr_t const *da, void *uctx)
Definition dict.h:993
void fr_dl_dict_autofree(dl_t const *module, void *symbol, void *uctx))
unsigned int array
Pack multiples into 1 attr.
Definition dict.h:90
unsigned int secret
this attribute should be omitted in debug mode
Definition dict.h:105
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
Definition dict_util.c:2665
fr_dict_flag_parse_func_t func
Custom parsing function to convert a flag value string to a C type value.
Definition dict.h:395
int fr_dict_walk(fr_dict_attr_t const *da, fr_dict_walk_t callback, void *uctx))
Definition dict_util.c:5093
fr_dict_attr_t const * fr_dict_vendor_da_by_num(fr_dict_attr_t const *vendor_root, uint32_t vendor_pen)
Return vendor attribute for the specified dictionary and pen.
Definition dict_util.c:2960
unsigned int extra
really "subtype is used by dict, not by protocol"
Definition dict.h:118
unsigned int internal
Internal attribute, should not be received in protocol packets, should not be encoded.
Definition dict.h:88
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition dict.h:292
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:305
void fr_dict_global_ctx_set(fr_dict_gctx_t const *gctx)
Set a new, active, global dictionary context.
Definition dict_util.c:4769
fr_dict_attr_t const * next
Next child in bin.
Definition dict.h:210
fr_dict_t _CONST *_CONST dict
Dict attribute belongs to.
Definition dict.h:197
fr_slen_t fr_dict_attr_search_by_oid_substr(fr_dict_attr_err_t *err, fr_dict_attr_t const **out, fr_dict_t const *dict_def, fr_sbuff_t *in, fr_sbuff_term_t const *tt, bool internal, bool foreign))
Locate a qualified fr_dict_attr_t by a dictionary using a non-qualified OID string.
Definition dict_util.c:3327
char const * name
Attribute name.
Definition dict.h:199
unsigned int unsafe
e.g. Cleartext-Password
Definition dict.h:107
fr_dict_protocol_init_t init
initialize the library
Definition dict.h:484
unsigned int is_raw
This dictionary attribute was constructed from a known attribute to allow the user to assign octets v...
Definition dict.h:80
int fr_dict_attr_unknown_parent_to_known(fr_dict_attr_t *da, fr_dict_attr_t const *parent)
Fixup the parent of an unknown attribute using an equivalent known attribute.
char const * name
of the attribute.
Definition dict.h:285
dl_t * fr_dict_dl(fr_dict_t const *dict)
Definition dict_util.c:2675
fr_value_box_t const * value
Enum value (what name maps to).
Definition dict.h:257
void fr_dict_attr_debug(FILE *fp, fr_dict_attr_t const *da)
Definition dict_print.c:264
unsigned int attr
Attribute number.
Definition dict.h:202
int fr_dict_read(fr_dict_t *dict, char const *dict_dir, char const *filename))
Read supplementary attribute definitions into an existing dictionary.
char const * fr_dict_enum_name_by_value(fr_dict_attr_t const *da, fr_value_box_t const *value)
Lookup the name of an enum value in a fr_dict_attr_t.
Definition dict_util.c:3688
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:3635
int fr_dict_enum_add_name_next(fr_dict_attr_t *da, char const *name)
Add an name to an integer attribute hashing the name for the integer value.
Definition dict_util.c:2229
uint8_t ext[FR_DICT_ATTR_EXT_MAX]
Extensions to the dictionary attribute.
Definition dict.h:230
int(* fr_dict_flags_copy_func_t)(fr_dict_attr_t *da_to, void *flags_to, void *flags_from)
Copy custom flags from one attribute to another.
Definition dict.h:409
int default_type_size
how many octets are in "type" field
Definition dict.h:458
uint32_t pen
Private enterprise number.
Definition dict.h:270
int fr_dl_dict_attr_autoload(dl_t const *module, void *symbol, void *uctx))
int fr_dict_free(fr_dict_t **dict, char const *dependent)
Decrement the reference count on a previously loaded dictionary.
Definition dict_util.c:4329
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:3655
fr_type_t type
of the attribute. Mismatch is a fatal error.
Definition dict.h:298
fr_dict_flag_parser_rule_t value
Function and context to parse the flag.
Definition dict.h:427
#define _CONST
Definition dict.h:58
int fr_dict_oid_component_legacy(unsigned int *out, char const **oid)
Process a single OID component.
Definition dict_util.c:2356
fr_slen_t fr_dict_enum_by_name_substr(fr_dict_enum_value_t **out, fr_dict_attr_t const *da, fr_sbuff_t *in)
Definition dict_util.c:3727
void fr_dict_global_ctx_perm_check(fr_dict_gctx_t *gctx, bool enable)
Set whether we check dictionary file permissions.
Definition dict_util.c:4760
void fr_dict_global_ctx_read_only(void)
Mark all dictionaries and the global dictionary ctx as read only.
Definition dict_util.c:4819
uint8_t type_size
Type size for TLVs.
Definition dict.h:144
unsigned int depth
Depth of nesting for this attribute.
Definition dict.h:203
int fr_dict_const_free(fr_dict_t const **dict, char const *dependent)
Decrement the reference count on a previously loaded dictionary.
Definition dict_util.c:4313
int fr_dict_attr_autoload(fr_dict_attr_autoload_t const *to_load)
Process a dict_attr_autoload element to load/verify a dictionary attribute.
Definition dict_util.c:4395
fr_dict_t const * fr_dict_internal(void)
Definition dict_util.c:4928
bool(* fr_dict_attr_type_parse_t)(fr_type_t *type, fr_dict_attr_t **da_p, char const *name)
Definition dict.h:334
fr_slen_t fr_dict_by_protocol_substr(fr_dict_attr_err_t *err, fr_dict_t const **out, fr_sbuff_t *name, fr_dict_t const *dict_def)
Look up a protocol name embedded in another string.
Definition dict_util.c:2762
int fr_dict_dependent_add(fr_dict_t const *dict, char const *dependent)
Manually increase the reference count for a dictionary.
Definition dict_util.c:3996
fr_slen_t fr_dict_attr_search_by_qualified_name_substr(fr_dict_attr_err_t *err, fr_dict_attr_t const **out, fr_dict_t const *dict_def, fr_sbuff_t *name, fr_sbuff_term_t const *tt, bool internal, bool foreign))
Locate a qualified fr_dict_attr_t by its name and a dictionary qualifier.
Definition dict_util.c:3240
int fr_dict_protocol_afrom_file(fr_dict_t **out, char const *proto_name, char const *proto_dir, char const *dependent))
(Re)-initialize a protocol dictionary
bool fr_dict_filename_loaded(fr_dict_t const *dict, char const *dict_dir, char const *filename))
size_t length
Length of length data.
Definition dict.h:273
fr_dict_t const * fr_dict_by_protocol_name(char const *name)
Lookup a protocol by its name.
Definition dict_util.c:2842
bool fr_dict_is_read_only(fr_dict_t const *dict)
Definition dict_util.c:2670
char const * base_dir
Directory structure beneath share.
Definition dict.h:307
fr_dict_attr_t const * parent
Immediate parent of this attribute.
Definition dict.h:209
fr_slen_t fr_dict_attr_unknown_afrom_oid_substr(TALLOC_CTX *ctx, fr_dict_attr_t const **out, fr_dict_attr_t const *parent, fr_sbuff_t *in, fr_type_t type))
Create a fr_dict_attr_t from an ASCII attribute and value.
fr_slen_t fr_dict_attr_search_by_name_substr(fr_dict_attr_err_t *err, fr_dict_attr_t const **out, fr_dict_t const *dict_def, fr_sbuff_t *name, fr_sbuff_term_t const *tt, bool internal, bool foreign))
Locate a fr_dict_attr_t by its name in the top level namespace of a dictionary.
Definition dict_util.c:3269
static bool fr_dict_attr_is_top_level(fr_dict_attr_t const *da)
Return true if this attribute is parented directly off the dictionary root.
Definition dict.h:809
void(* fr_dict_protocol_free_t)(void)
Definition dict.h:380
uint16_t length
length of the attribute
Definition dict.h:153
fr_dict_attr_encode_func_t encode
for encoding attributes.
Definition dict.h:489
char const * fr_dict_global_ctx_dir(void)
Definition dict_util.c:4810
unsigned int local
is a local variable
Definition dict.h:120
fr_dict_attr_ext_t
Extension identifier.
Definition dict.h:181
@ FR_DICT_ATTR_EXT_PROTOCOL_SPECIFIC
Protocol specific extensions.
Definition dict.h:190
@ FR_DICT_ATTR_EXT_MAX
Definition dict.h:191
@ FR_DICT_ATTR_EXT_ENUMV
Enumeration values.
Definition dict.h:188
@ FR_DICT_ATTR_EXT_NAMESPACE
Attribute has its own namespace.
Definition dict.h:189
@ FR_DICT_ATTR_EXT_REF
Attribute references another attribute and/or dictionary.
Definition dict.h:184
@ FR_DICT_ATTR_EXT_KEY
UNION attribute references a key.
Definition dict.h:186
@ FR_DICT_ATTR_EXT_VENDOR
Cached vendor pointer.
Definition dict.h:187
@ FR_DICT_ATTR_EXT_NAME
Name of the attribute.
Definition dict.h:182
@ FR_DICT_ATTR_EXT_CHILDREN
Attribute has children.
Definition dict.h:183
static fr_slen_t fr_dict_enum_name_afrom_substr(TALLOC_CTX *ctx, char **out, fr_sbuff_parse_error_t *err, fr_sbuff_t *in, fr_sbuff_term_t const *tt) 1(fr_dict_enum_name_from_substr
unsigned int last_child_attr
highest value of last child attribute.
Definition dict.h:205
int fr_dict_global_ctx_free(fr_dict_gctx_t const *gctx)
Explicitly free all data associated with a global dictionary context.
Definition dict_util.c:4785
unsigned int is_known_width
is treated as if it has a known width for structs
Definition dict.h:92
int default_type_length
how many octets are in "length" field
Definition dict.h:459
fr_dict_attr_err_t
Errors returned by attribute lookup functions.
Definition dict.h:317
@ FR_DICT_ATTR_OK
No error.
Definition dict.h:318
@ FR_DICT_ATTR_NOT_ANCESTOR
Attribute is not an ancestor of the child attribute.
Definition dict.h:326
@ FR_DICT_ATTR_NOT_DESCENDENT
Attribute is not a descendent of the parent attribute.
Definition dict.h:324
@ FR_DICT_ATTR_NOTFOUND
Attribute couldn't be found.
Definition dict.h:319
@ FR_DICT_ATTR_EINVAL
Invalid arguments.
Definition dict.h:329
@ FR_DICT_ATTR_PROTOCOL_NOTFOUND
Protocol couldn't be found.
Definition dict.h:320
@ FR_DICT_ATTR_NO_CHILDREN
Child lookup in attribute with no children.
Definition dict.h:328
@ FR_DICT_ATTR_OOM
Memory allocation error.
Definition dict.h:323
@ FR_DICT_ATTR_PARSE_ERROR
Attribute string couldn't be parsed.
Definition dict.h:321
@ FR_DICT_ATTR_INTERNAL_ERROR
Internal error occurred.
Definition dict.h:322
fr_slen_t fr_dict_attr_search_by_qualified_oid_substr(fr_dict_attr_err_t *err, fr_dict_attr_t const **out, fr_dict_t const *dict_def, fr_sbuff_t *in, fr_sbuff_term_t const *tt, bool internal, bool foreign))
Locate a qualified fr_dict_attr_t by a dictionary qualified OID string.
Definition dict_util.c:3298
fr_dict_vendor_t const * fr_dict_vendor_by_name(fr_dict_t const *dict, char const *name)
Look up a vendor by its name.
Definition dict_util.c:2922
int(* fr_dict_protocol_init_t)(void)
Init / free callbacks.
Definition dict.h:379
bool needs_value
This parsing flag must have a value. Else we error.
Definition dict.h:397
fr_dict_attr_t const * fr_dict_attr_iterate_children(fr_dict_attr_t const *parent, fr_dict_attr_t const **prev)
Iterate over children of a DA.
Definition dict_util.c:5014
int fr_dict_attr_add(fr_dict_t *dict, fr_dict_attr_t const *parent, char const *name, unsigned int attr, fr_type_t type, fr_dict_attr_flags_t const *flags))
Add an attribute to the dictionary.
Definition dict_util.c:1967
int fr_dict_parse_str(fr_dict_t *dict, char const *str, fr_dict_attr_t const *parent))
fr_dict_attr_t const * fr_dict_attr_by_oid(fr_dict_attr_err_t *err, fr_dict_attr_t const *parent, char const *oid))
Resolve an attribute using an OID string.
Definition dict_util.c:2638
int _fr_dict_autoload(fr_dict_autoload_t const *to_load, char const *dependent)
Process a dict_autoload element to load a protocol.
Definition dict_util.c:4460
unsigned int is_unsigned
hackity hack for dates and time deltas
Definition dict.h:96
static fr_dict_attr_t * fr_dict_attr_unknown_typed_afrom_num(TALLOC_CTX *ctx, fr_dict_attr_t const *parent, unsigned int num, fr_type_t type)
Definition dict.h:596
fr_dict_vendor_t const * fr_dict_vendor_by_num(fr_dict_t const *dict, uint32_t vendor_pen)
Look up a vendor by its PEN.
Definition dict_util.c:2945
fr_hash_iter_t fr_dict_enum_iter_t
Definition dict.h:863
ssize_t fr_dict_valid_name(char const *name, ssize_t len)
Definition dict_util.c:4938
int fr_dl_dict_autoload(dl_t const *module, void *symbol, void *uctx))
fr_dict_t * fr_dict_protocol_alloc(fr_dict_t const *parent)
Allocate a new local dictionary.
Definition dict_util.c:4266
fr_slen_t fr_dict_oid_component(fr_dict_attr_err_t *err, fr_dict_attr_t const **out, fr_dict_attr_t const *parent, fr_sbuff_t *in, fr_sbuff_term_t const *tt))
Parse an OID component, resolving it to a defined attribute.
Definition dict_util.c:2490
ssize_t(* fr_dict_attr_decode_func_t)(TALLOC_CTX *ctx, fr_pair_list_t *vps, uint8_t const *data, size_t data_len)
A generic interface for decoding packets to fr_pair_ts.
Definition dict.h:357
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:3593
char const * proto
The protocol dictionary name.
Definition dict.h:308
fr_dict_gctx_t * fr_dict_global_ctx_init(TALLOC_CTX *ctx, bool free_at_exit, char const *dict_dir))
Initialise the global protocol hashes.
Definition dict_util.c:4713
fr_dict_attr_t * fr_dict_attr_unknown_typed_afrom_num_raw(TALLOC_CTX *ctx, fr_dict_attr_t const *parent, unsigned int num, fr_type_t type, bool raw))
Initialise a fr_dict_attr_t from a number and a data type.
fr_dict_enum_value_t const * fr_dict_enum_by_name(fr_dict_attr_t const *da, char const *name, ssize_t len)
Definition dict_util.c:3701
char const * name
Enum name.
Definition dict.h:254
@ FLAG_EXTRA_NONE
no extra meaning, should be invalid
Definition dict.h:163
@ FLAG_LENGTH_UINT8
string / octets type is prefixed by uint8 of length
Definition dict.h:166
@ FLAG_LENGTH_UINT16
string / octets type is prefixed by uint16 of length
Definition dict.h:167
@ FLAG_KEY_FIELD
this is a key field for a subsequent struct
Definition dict.h:164
@ FLAG_BIT_FIELD
bit field inside of a struct
Definition dict.h:165
static fr_slen_t in
Definition dict.h:882
fr_type_t type
Value type.
Definition dict.h:207
char const * name
name of this protocol
Definition dict.h:456
unsigned int has_alias
this attribute has an alias.
Definition dict.h:87
fr_dict_t const * fr_dict_by_protocol_num(unsigned int num)
Lookup a protocol by its number.
Definition dict_util.c:2855
uint8_t subtype
needs a fixup during dictionary parsing
Definition dict.h:131
static int8_t fr_dict_attr_cmp_fields(const fr_dict_attr_t *a, const fr_dict_attr_t *b)
Compare two dictionary attributes by their contents.
Definition dict.h:691
struct dict_attr_s::@123 state
unsigned int is_alias
This isn't a real attribute, it's a reference to to one.
Definition dict.h:85
fr_dict_vendor_t const * fr_dict_vendor_by_da(fr_dict_attr_t const *da)
Look up a vendor by one of its child attributes.
Definition dict_util.c:2900
unsigned int counter
integer attribute is actually an impulse / counter
Definition dict.h:98
unsigned int is_unknown
This dictionary attribute is ephemeral and not part of the main dictionary.
Definition dict.h:77
fr_dict_attr_t const * da
the child structure referenced by this value of key
Definition dict.h:246
unsigned int allow_flat
only for FR_TYPE_GROUP, can contain "flat" lists.
Definition dict.h:122
void dict_dctx_debug(dict_tokenize_ctx_t *dctx)
void fr_dict_export(FILE *fp, fr_dict_t const *dict)
Export in the standard form: ATTRIBUTE name oid flags.
Definition dict_print.c:319
static int8_t fr_dict_attr_cmp(fr_dict_attr_t const *a, fr_dict_attr_t const *b)
Definition dict.h:654
Dictionary attribute.
Definition dict.h:196
Specifies an attribute which must be present for the module to function.
Definition dict.h:291
Values of the encryption flags.
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:304
Specifies a value which must be present for the module to function.
Definition dict.h:280
Enum extension - Sub-struct or union pointer.
Definition dict.h:245
Value of an enumerated attribute.
Definition dict.h:253
Protocol specific custom flag definitnion.
Definition dict.h:425
Protocol-specific callbacks in libfreeradius-PROTOCOL.
Definition dict.h:455
Private enterprise.
Definition dict.h:269
static uint32_t fr_dict_vendor_num_by_da(fr_dict_attr_t const *da)
Return the vendor number for an attribute.
Definition dict_ext.h:176
fr_dict_t * internal
Magic internal dictionary.
Definition dict_priv.h:155
bool free_at_exit
This gctx will be freed on exit.
Definition dict_priv.h:130
Vendors and attribute names.
Definition dict_priv.h:85
Test enumeration values.
Definition dict_test.h:92
Structure used to managed the lifetime of a dictionary.
Definition dict_util.c:4517
Module handle.
Definition dl.h:57
#define FR_EXT_ALIGNMENT
The alignment of object extension structures.
Definition ext.h:54
Stores the state of the current iteration operation.
Definition hash.h:41
unsigned short uint16_t
fr_type_t
@ FR_TYPE_VENDOR
Attribute that represents a vendor in the attribute tree.
@ FR_TYPE_OCTETS
Raw octets.
unsigned int uint32_t
long int ssize_t
unsigned char bool
unsigned char uint8_t
ssize_t fr_slen_t
fr_sbuff_parse_error_t
@ FR_SBUFF_PARSE_OK
No error.
static int type_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
#define fr_assert(_expr)
Definition rad_assert.h:37
static char const * name
#define SBUFF_CHAR_CLASS
Definition sbuff.h:203
#define fr_sbuff_out(_err, _out, _in)
#define SBUFF_OUT_TALLOC_FUNC_NO_LEN_DEF(_func,...)
Set of terminal elements.
fr_aka_sim_id_type_t type
static fr_slen_t parent
Definition pair.h:858
static fr_slen_t data
Definition value.h:1340
int nonnull(2, 5))
static size_t char ** out
Definition value.h:1030
Union containing all data types supported by the server.
Definition value.h:188