The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
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 RCSIDH(dict_h, "$Id: 4a6c6989443e9b12c2ff42c9c0a9c1bbf3dd6b38 $")
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #include <freeradius-devel/build.h>
31 #include <freeradius-devel/missing.h>
32 #include <freeradius-devel/util/dl.h>
33 #include <freeradius-devel/util/ext.h>
34 #include <freeradius-devel/util/rb.h>
35 #include <freeradius-devel/util/sbuff.h>
36 #include <freeradius-devel/util/table.h>
37 #include <freeradius-devel/util/talloc.h>
38 #include <freeradius-devel/util/types.h>
39 
40 #include <stdbool.h>
41 #include <stdint.h>
42 
43 /*
44  * Avoid circular type references.
45  */
46 typedef struct dict_attr_s fr_dict_attr_t;
47 typedef struct fr_dict_s fr_dict_t;
48 
49 typedef struct value_box_s fr_value_box_t;
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 
70 
71 /** Values of the encryption flags
72  */
73 typedef struct {
74  unsigned int is_root : 1; //!< Is root of a dictionary.
75 
76  unsigned int is_unknown : 1; //!< This dictionary attribute is ephemeral
77  ///< and not part of the main dictionary.
78 
79  unsigned int is_raw : 1; //!< This dictionary attribute was constructed
80  ///< from a known attribute to allow the user
81  ///< to assign octets values directly.
82  ///< See .is_unknown to determine if it is
83  ///< ephemeral.
84  unsigned int is_alias : 1; //!< This isn't a real attribute, it's a reference to
85  ///< to one.
86  unsigned int internal : 1; //!< Internal attribute, should not be received
87  ///< in protocol packets, should not be encoded.
88  unsigned int array : 1; //!< Pack multiples into 1 attr.
89 
90  unsigned int is_known_width : 1; //!< is treated as if it has a known width for structs
91 
92  unsigned int has_value : 1; //!< Has a value.
93 
94  unsigned int is_unsigned : 1; //!< hackity hack for dates and time deltas
95 
96  unsigned int counter : 1; //!< integer attribute is actually an impulse / counter
97 
98  unsigned int name_only : 1; //!< this attribute should always be referred to by name.
99  ///< A number will be allocated, but the allocation scheme
100  ///< will depend on the parent, and definition type, and
101  ///< may not be stable in all instances.
102 
103  unsigned int secret : 1; //!< this attribute should be omitted in debug mode
104 
105  /*
106  * @todo - if we want to clean these fields up, make
107  * "subtype" and "type_size" both 4-bit bitfields. That
108  * gives us an extra 8 bits for adding new flags, and we
109  * can likely get rid of "extra", in order to save one
110  * more bit.
111  */
112  unsigned int extra : 1; //!< really "subtype is used by dict, not by protocol"
113 
114  unsigned int local : 1; //!< is a local variable
115 
116  /*
117  * main: extra is set, then this field is is key, bit, or a uint16 length field.
118  * radius: is one of 9 options for flags
119  * dhcp v4/v6: DNS label, or partial DNS label
120  */
121  uint8_t subtype; //!< protocol-specific values, OR key fields
122 
123  /*
124  * Length in bytes for most attributes.
125  * Length in bits for da_is_bit_field(da)
126  */
127  uint8_t length; //!< length of the attribute
128 
129  /*
130  * TLVs: 1, 2, or 4.
131  * date / time types: fr_time_res_t, which has 4 possible values.
132  * bit fields: offset in the byte where this bit field ends, which is only
133  * used as a caching mechanism during parsing of the dictionaries.
134  */
135  uint8_t type_size; //!< For TLV2 and root attributes.
137 
138 #define flag_time_res type_size
139 #define flag_byte_offset type_size
140 
141 /** subtype values for the dictionary when extra=1
142  *
143  */
144 enum {
145  FLAG_EXTRA_NONE = 0, //!< no extra meaning, should be invalid
146  FLAG_KEY_FIELD, //!< this is a key field for a subsequent struct
147  FLAG_BIT_FIELD, //!< bit field inside of a struct
148  FLAG_LENGTH_UINT8, //!< string / octets type is prefixed by uint8 of length
149  FLAG_LENGTH_UINT16, //!< string / octets type is prefixed by uint16 of length
150 };
151 
152 #define fr_dict_attr_is_key_field(_da) ((_da)->flags.extra && ((_da)->flags.subtype == FLAG_KEY_FIELD))
153 #define da_is_bit_field(_da) ((_da)->flags.extra && ((_da)->flags.subtype == FLAG_BIT_FIELD))
154 #define da_is_length_field(_da) ((_da)->flags.extra && (((_da)->flags.subtype == FLAG_LENGTH_UINT8) || ((_da)->flags.subtype == FLAG_LENGTH_UINT16)))
155 #define da_length_offset(_da) ((_da)->flags.type_size)
156 
157 /** Extension identifier
158  *
159  * @note New extension structures should also be added to the to the appropriate table in dict_ext.c
160  */
161 typedef enum {
162  FR_DICT_ATTR_EXT_NAME = 0, //!< Name of the attribute.
163  FR_DICT_ATTR_EXT_CHILDREN, //!< Attribute has children.
164  FR_DICT_ATTR_EXT_REF, //!< Attribute references another
165  ///< attribute and/or dictionary.
166  FR_DICT_ATTR_EXT_VENDOR, //!< Cached vendor pointer.
167  FR_DICT_ATTR_EXT_DA_STACK, //!< Cached da stack.
168  FR_DICT_ATTR_EXT_ENUMV, //!< Enumeration values.
169  FR_DICT_ATTR_EXT_NAMESPACE, //!< Attribute has its own namespace.
170  FR_DICT_ATTR_EXT_PROTOCOL_SPECIFIC, //!< Protocol specific extensions
173 
174 /** Dictionary attribute
175  */
176 struct dict_attr_s {
177  fr_dict_t _CONST* _CONST dict; //!< Dict attribute belongs to.
178 
179  char const *name; //!< Attribute name.
180  size_t name_len; //!< Length of the name.
181 
182  unsigned int attr; //!< Attribute number.
183  unsigned int depth; //!< Depth of nesting for this attribute.
184 
185  unsigned int last_child_attr; //!< highest value of last child attribute.
186 
187  fr_type_t type; //!< Value type.
188 
189  fr_dict_attr_t const *parent; //!< Immediate parent of this attribute.
190  fr_dict_attr_t const *next; //!< Next child in bin.
191 
193 
194  struct {
195  bool attr_set : 1; //!< Attribute number has been set.
196  //!< We need the full range of values 0-UINT32_MAX
197  ///< so we can't use any attr values to indicate
198  ///< "unsetness".
199 
200  bool finalised : 1; //!< Attribute definition is complete and modifications
201  ///< that would change the address of the memory chunk
202  ///< of the attribute are no longer permitted.
203  } state;
204 
205  char const *filename; //!< Where the attribute was defined.
206  ///< this buffer's lifetime is bound to the
207  ///< fr_dict_t.
208  int line; //!< Line number where the attribute was defined.
209 
210  uint8_t ext[FR_DICT_ATTR_EXT_MAX]; //!< Extensions to the dictionary attribute.
211 } CC_HINT(aligned(FR_EXT_ALIGNMENT));
212 
213 /** Extension identifier
214  *
215  * @note New extension structures should also be added to the appropriate table in dict_ext.c
216  */
217 typedef enum {
218  FR_DICT_ENUM_EXT_UNION_REF = 0, //!< Reference to a union/subs-struct.
221 
222 /** Value of an enumerated attribute
223  *
224  * Maps one of more string values to integers and vice versa.
225  */
226 typedef struct {
227  char const *name; //!< Enum name.
228  size_t name_len; //!< Allows for efficient name lookups when operating
229  ///< on partial buffers.
230  fr_value_box_t const *value; //!< Enum value (what name maps to).
231 
232  uint8_t ext[FR_DICT_ENUM_EXT_MAX]; //!< Extensions to the dictionary attribute.
233 
234  fr_dict_attr_t const *child_struct[]; //!< for key fields
235 } fr_dict_enum_value_t CC_HINT(aligned(FR_EXT_ALIGNMENT));
236 
237 /** Private enterprise
238  *
239  * Represents an IANA private enterprise allocation.
240  *
241  * The width of the private enterprise number must be the same for all protocols
242  * so we can represent a vendor with a single struct.
243  */
244 typedef struct {
245  uint32_t pen; //!< Private enterprise number.
246  bool continuation; //!< we only have one flag for now, for WiMAX
247  size_t type; //!< Length of type data
248  size_t length; //!< Length of length data
249  char const *name; //!< Vendor name.
251 
252 /** Specifies a value which must be present for the module to function
253  *
254  */
255 typedef struct {
256  fr_value_box_t const **out; //!< Enumeration value.
257  fr_dict_attr_t const **attr; //!< The protocol dictionary the attribute should
258  ///< be resolved in. ** so it's a compile time
259  ///< constant.
260  char const *name; //!< of the attribute.
262 
263 /** Specifies an attribute which must be present for the module to function
264  *
265  */
266 typedef struct {
267  fr_dict_attr_t const **out; //!< Where to write a pointer to the resolved
268  //!< #fr_dict_attr_t.
269  fr_dict_t const **dict; //!< The protocol dictionary the attribute should
270  ///< be resolved in. ** so it's a compile time
271  ///< constant.
272  char const *name; //!< of the attribute.
273  fr_type_t type; //!< of the attribute. Mismatch is a fatal error.
275 
276 /** Specifies a dictionary which must be loaded/loadable for the module to function
277  *
278  */
279 typedef struct {
280  fr_dict_t const **out; //!< Where to write a pointer to the loaded/resolved
281  //!< #fr_dict_t.
282  char const *base_dir; //!< Directory structure beneath share.
283  char const *proto; //!< The protocol dictionary name.
285 
286 /** Errors returned by attribute lookup functions
287  *
288  */
289 typedef enum {
290  FR_DICT_ATTR_OK = 0, //!< No error.
291  FR_DICT_ATTR_NOTFOUND = -1, //!< Attribute couldn't be found.
292  FR_DICT_ATTR_PROTOCOL_NOTFOUND = -2, //!< Protocol couldn't be found.
293  FR_DICT_ATTR_PARSE_ERROR = -3, //!< Attribute string couldn't be parsed
294  FR_DICT_ATTR_INTERNAL_ERROR = -4, //!< Internal error occurred.
295  FR_DICT_ATTR_OOM = -5, //!< Memory allocation error.
296  FR_DICT_ATTR_NOT_DESCENDENT = -6, //!< Attribute is not a descendent of the parent
297  ///< attribute.
298  FR_DICT_ATTR_NOT_ANCESTOR = -7, //!< Attribute is not an ancestor of the child
299  ///< attribute.
300  FR_DICT_ATTR_NO_CHILDREN = -8, //!< Child lookup in attribute with no children.
301  FR_DICT_ATTR_EINVAL = -9 //!< Invalid arguments.
302 
304 
306 
307 /*
308  * Forward declarations to avoid circular references.
309  */
310 typedef struct pair_list_s fr_pair_list_t;
311 typedef struct fr_dbuff_s fr_dbuff_t;
312 
313 /** A generic interface for decoding packets to fr_pair_ts
314  *
315  * A decoding function should decode a single top level packet from wire format.
316  *
317  * Note that unlike #fr_tp_proto_decode_t, this function is NOT passed an encode_ctx. That is because when we
318  * do cross-protocol encoding, the "outer" protocol has no information it can share with the "inner" protocol.
319  *
320  * @param[in] ctx to allocate new pairs in.
321  * @param[in] vps where new VPs will be added
322  * @param[in] data to decode.
323  * @param[in] data_len The length of the incoming data.
324  * @return
325  * - <= 0 on error. May be the offset (as a negative value) where the error occurred.
326  * - > 0 on success. How many bytes were decoded.
327  */
328 typedef ssize_t (*fr_dict_attr_decode_func_t)(TALLOC_CTX *ctx, fr_pair_list_t *vps,
329  uint8_t const *data, size_t data_len);
330 
331 /** A generic interface for encoding fr_pair_ts to packets
332  *
333  * An encoding function should encode multiple VPs to a wire format packet
334  *
335  * Note that unlike #fr_tp_proto_encode_t, this function is NOT passed an encode_ctx. That is because when we
336  * do cross-protocol encoding, the "outer" protocol has no information it can share with the "inner" protocol.
337  *
338  * @param[in] vps vps to encode
339  * @param[in] dbuff buffer where data can be written
340  * @return
341  * - <= 0 on error. May be the offset (as a negative value) where the error occurred.
342  * - > 0 on success. How many bytes were encoded
343  */
345 
346 /** Init / free callbacks
347  *
348  * Only for "autoref" usage.
349  */
350 typedef int (*fr_dict_protocol_init_t)(void);
351 typedef void (*fr_dict_protocol_free_t)(void);
352 
354 
355 /** Custom protocol-specific flag parsing function
356  *
357  * @note This function should be used to implement table based flag parsing.
358  *
359  * @param[in] da_p we're currently populating
360  * @param[in] value flag value to parse.
361  * @param[in] rule How to parse the flag.
362  */
364 
366  fr_dict_flag_parse_func_t func; //!< Custom parsing function to convert a flag value string to a C type value.
367  void *uctx; //!< Use context to pass to the custom parsing function.
368  bool needs_value; //!< This parsing flag must have a value. Else we error.
369 };
370 
371 /** Copy custom flags from one attribute to another
372  *
373  * @param[out] da_to attribute to copy to. Use for the talloc_ctx for any heap allocated flag values.
374  * @param[out] flags_to protocol specific flags struct to copy to.
375  * @param[in] flags_from protocol specific flags struct to copy from.
376  * @return
377  * - 0 on success.
378  * - -1 on error.
379  */
380 typedef int (*fr_dict_flags_copy_func_t)(fr_dict_attr_t *da_to, void *flags_to, void *flags_from);
381 
382 /** Compare the protocol specific flags struct from two attributes
383  *
384  * @para[in] da_a first attribute to compare.
385  * @para[in] da_b second attribute to compare.
386  * @return
387  * - 0 if the flags are equal.
388  * - < 0 if da_a < da_b.
389  * - > 0 if da_a > da_b.
390  */
391  typedef int (*fr_dict_flags_cmp_func_t)(fr_dict_attr_t const *da_a, fr_dict_attr_t const *da_b);
392 
393 /** Protocol specific custom flag definitnion
394  *
395  */
396 typedef struct {
397  fr_table_elem_name_t name; //!< Name of the flag
398  fr_dict_flag_parser_rule_t value; //!< Function and context to parse the flag.
400 
401 /** Define a flag setting function, which sets one bit in a fr_dict_attr_flags_t
402  *
403  * This is here, because AFAIK there's no completely portable way to get the bit
404  * offset of a bit field in a structure.
405  */
406 #define FR_DICT_ATTR_FLAG_FUNC(_struct, _name) \
407 static int dict_flag_##_name(fr_dict_attr_t **da_p, UNUSED char const *value, UNUSED fr_dict_flag_parser_rule_t const *rules)\
408 { \
409  _struct *flags = fr_dict_attr_ext(*da_p, FR_DICT_ATTR_EXT_PROTOCOL_SPECIFIC); \
410  flags->_name = 1; \
411  return 0; \
412 }
413 
414 /** conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
415  *
416  * @param[in] _name of the flag search for.
417  * @param[in] _struct containing the field to write the result to.
418  * @param[in] _field to write the flag to
419  */
420 # define FR_DICT_PROTOCOL_FLAG(_struct, _field) \
421  .type = FR_CTYPE_TO_TYPE((((_struct *)NULL)->_field)), \
422  .offset = offsetof(_struct, _field)
423 
424 /** Protocol-specific callbacks in libfreeradius-PROTOCOL
425  *
426  */
427 typedef struct {
428  char const *name; //!< name of this protocol
429 
430  int default_type_size; //!< how many octets are in "type" field
431  int default_type_length; //!< how many octets are in "length" field
432 
433  struct {
434  /** Custom flags for this protocol
435  */
436  struct {
437  fr_dict_flag_parser_t const *table; //!< Flags for this protocol, an array of fr_dict_flag_parser_t
438  size_t table_len; //!< Length of protocol_flags table.
439 
440  size_t len; //!< Length of the protocol specific flags structure.
441  ///< This is used to allocate a FR_DICT_ATTR_EXT_PROTOCOL_SPECIFIC
442  ///< extension of the specified length.
443 
444  fr_dict_flags_copy_func_t copy; //!< Copy protocol-specific flags from one attribute to another.
445  ///< Called when copying attributes.
446 
447  fr_dict_flags_cmp_func_t cmp; //!< Compare protocol-specific flags from two attributes.
448  ///< Called when comparing attributes by their fields.
449  } flags;
450 
451  fr_dict_attr_valid_func_t valid; //!< Validation function to ensure that
452  ///< new attributes are valid.
453  } attr;
454 
455  fr_dict_protocol_init_t init; //!< initialize the library
456  fr_dict_protocol_free_t free; //!< free the library
457 
458  fr_dict_attr_decode_func_t decode; //!< for decoding attributes. Used for implementing foreign
459  ///< protocol attributes.
460  fr_dict_attr_encode_func_t encode; //!< for encoding attributes. Used for implementing foreign
461  ///< protocol attributes.
463 
464 typedef struct fr_dict_gctx_s fr_dict_gctx_t;
465 
466 /*
467  * Dictionary constants
468  */
469 #define FR_DICT_PROTO_MAX_NAME_LEN (128) //!< Maximum length of a protocol name.
470 #define FR_DICT_ENUM_MAX_NAME_LEN (128) //!< Maximum length of a enum value.
471 #define FR_DICT_VENDOR_MAX_NAME_LEN (128) //!< Maximum length of a vendor name.
472 #define FR_DICT_ATTR_MAX_NAME_LEN (128) //!< Maximum length of a attribute name.
473 
474 /** Maximum level of TLV nesting allowed
475  */
476 #define FR_DICT_TLV_NEST_MAX (24)
477 
478 /** Maximum level of da stack caching
479  */
480 #define FR_DICT_DA_STACK_CACHE_MAX (5)
481 
482 /** Maximum TLV stack size
483  *
484  * The additional attributes are to account for
485  *
486  * Root + Vendor + NULL (top frame).
487  * Root + Embedded protocol + Root + Vendor + NULL.
488  *
489  * Code should ensure that it doesn't run off the end of the stack,
490  * as this could be remotely exploitable, using odd nesting.
491  */
492 #define FR_DICT_MAX_TLV_STACK (FR_DICT_TLV_NEST_MAX + 5)
493 
494 /** Characters that are allowed in dictionary attribute names
495  *
496  */
497 extern bool const fr_dict_attr_allowed_chars[UINT8_MAX + 1];
498 
499 /** Characters that are allowed in dictionary enumeration value names
500  *
501  */
502 extern bool const fr_dict_enum_allowed_chars[UINT8_MAX + 1];
503 
504 /** @name Dictionary structure extensions
505  *
506  * @{
507  */
508 #include <freeradius-devel/util/dict_ext.h>
509 /** @} */
510 
511 /** @name Programmatically create dictionary attributes and values
512  *
513  * @{
514  */
516 
517 int fr_dict_attr_add(fr_dict_t *dict, fr_dict_attr_t const *parent, char const *name, unsigned int attr,
518  fr_type_t type, fr_dict_attr_flags_t const *flags) CC_HINT(nonnull(1,2,3));
519 
521  char const *name, fr_type_t type, fr_dict_attr_flags_t const *flags) CC_HINT(nonnull(1,2,3));
522 
523 int fr_dict_enum_add_name(fr_dict_attr_t *da, char const *name,
524  fr_value_box_t const *value, bool coerce, bool replace);
525 
526 int fr_dict_enum_add_name_next(fr_dict_attr_t *da, char const *name) CC_HINT(nonnull);
527 
528 int fr_dict_str_to_argv(char *str, char **argv, int max_argc);
529 
530 int fr_dict_attr_acopy_local(fr_dict_attr_t const *dst, fr_dict_attr_t const *src) CC_HINT(nonnull);
531 /** @} */
532 
533 /** @name Dict accessors
534  *
535  * @{
536  */
538 /** @} */
539 
540 /** @name Unknown ephemeral attributes
541  *
542  * @{
543  */
545 
547 
548 fr_dict_attr_t *fr_dict_attr_unknown_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da) CC_HINT(nonnull(2));
549 
550 static inline fr_dict_attr_t *fr_dict_attr_unknown_copy(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
551 {
552  fr_assert(da->flags.is_unknown);
553 
554  return fr_dict_attr_unknown_afrom_da(ctx, da);
555 }
556 
558  fr_dict_attr_t const *parent,
559  unsigned int num, fr_type_t type, bool raw)
560  CC_HINT(nonnull(2));
561 
562 static inline CC_HINT(nonnull(2)) fr_dict_attr_t *fr_dict_attr_unknown_typed_afrom_num(TALLOC_CTX *ctx,
563  fr_dict_attr_t const *parent,
564  unsigned int num, fr_type_t type)
565 {
566  return fr_dict_attr_unknown_typed_afrom_num_raw(ctx, parent, num, type, false);
567 }
568 
569 
570 static inline CC_HINT(nonnull(2)) fr_dict_attr_t *fr_dict_attr_unknown_vendor_afrom_num(TALLOC_CTX *ctx,
571  fr_dict_attr_t const *parent,
572  unsigned int vendor)
573 {
575 }
576 
577 static inline CC_HINT(nonnull(2)) fr_dict_attr_t *fr_dict_attr_unknown_raw_afrom_num(TALLOC_CTX *ctx,
578  fr_dict_attr_t const *parent,
579  unsigned int attr)
580 {
582 }
583 
585  CC_HINT(nonnull(2));
586 
587 
589  fr_dict_attr_t const **out,
590  fr_dict_attr_t const *parent,
592  CC_HINT(nonnull(2,3,4));
593 
595 
597 /** @} */
598 
599 /** @name Attribute comparisons
600  *
601  * @{
602  */
603 static inline CC_HINT(nonnull) int8_t fr_dict_attr_cmp(fr_dict_attr_t const *a, fr_dict_attr_t const *b)
604 {
605  int8_t ret;
606 
607  /*
608  * Comparing unknowns or raws is expensive
609  * because we need to check the lineage.
610  */
611  if (a->flags.is_unknown | a->flags.is_raw | b->flags.is_unknown | b->flags.is_raw) {
612  ret = CMP(a->depth, b->depth);
613  if (ret != 0) return ret;
614 
615  ret = CMP(a->attr, b->attr);
616  if (ret != 0) return ret;
617 
618  ret = (a->parent == NULL) - (b->parent == NULL);
619  if ((ret != 0) || !a->parent) return ret;
620 
621  return fr_dict_attr_cmp(a->parent, b->parent);
622  }
623 
624  /*
625  * Comparing knowns is cheap because the
626  * DAs are unique.
627  */
628  return CMP(a, b);
629 }
630 
631 /** Compare two dictionary attributes by their contents
632  *
633  * @param[in] a First attribute to compare.
634  * @param[in] b Second attribute to compare.
635  * @return
636  * - 0 if the attributes are equal.
637  * - -1 if a < b.
638  * - +1 if a > b.
639  */
640 static inline CC_HINT(nonnull) int8_t fr_dict_attr_cmp_fields(const fr_dict_attr_t *a, const fr_dict_attr_t *b)
641 {
642  int8_t ret;
643  fr_dict_protocol_t const *a_proto = fr_dict_protocol(a->dict);
644 
645  /*
646  * Technically this isn't a property of the attribute
647  * but we need them to be the same to be able to
648  * compare protocol specific flags successfully.
649  */
650  ret = CMP(a_proto, fr_dict_protocol(b->dict));
651  if (ret != 0) return ret;
652 
653  ret = CMP(a->attr, b->attr);
654  if (ret != 0) return ret;
655 
656  ret = CMP(a->parent, b->parent);
657  if (ret != 0) return ret;
658 
660  if (ret != 0) return ret;
661 
662  /*
663  * Compare protocol specific flags
664  */
665  if (a_proto->attr.flags.cmp && (ret = a_proto->attr.flags.cmp(a, b))) return ret;
666 
667  return CMP(memcmp(&a->flags, &b->flags, sizeof(a->flags)), 0);
668 }
669 /** @} */
670 
671 /** @name Debugging functions
672  *
673  * @{
674  */
676 
677 void fr_dict_attr_debug(fr_dict_attr_t const *da);
678 
679 void fr_dict_debug(fr_dict_t const *dict);
680 
681 void fr_dict_export(fr_dict_t const *dict);
682 /** @} */
683 
684 /** @name Attribute lineage
685  *
686  * @{
687  */
688 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);
689 
690 int fr_dict_oid_component_legacy(unsigned int *out, char const **oid);
691 
693  fr_type_t type, fr_dict_attr_flags_t const *flags);
694 
696  fr_dict_attr_t const *ancestor, fr_dict_attr_t const *da, bool numeric);
697 #define FR_DICT_ATTR_OID_PRINT_RETURN(...) FR_SBUFF_RETURN(fr_dict_attr_oid_print, ##__VA_ARGS__)
698 
700  unsigned int *attr, char const *oid) CC_HINT(nonnull);
701 
703  fr_dict_attr_t const **out, fr_dict_attr_t const *parent,
704  fr_sbuff_t *in, fr_sbuff_term_t const *tt)
705  CC_HINT(nonnull(2,3,4));
706 
708  fr_dict_attr_t const **out, fr_dict_attr_t const *parent,
709  fr_sbuff_t *in, fr_sbuff_term_t const *tt)
710  CC_HINT(nonnull(2,3,4));
711 
713  fr_dict_attr_t const *parent, char const *oid)
714  CC_HINT(nonnull(2,3));
715 
716 bool fr_dict_attr_can_contain(fr_dict_attr_t const *parent, fr_dict_attr_t const *child) CC_HINT(nonnull);
717 
718 /** @} */
719 
720 /** @name Attribute, vendor and dictionary lookup
721  *
722  * @{
723  */
724 
725 /** @hidecallergraph */
726 fr_dict_attr_t const *fr_dict_root(fr_dict_t const *dict) CC_HINT(nonnull);
727 
728 bool fr_dict_is_read_only(fr_dict_t const *dict);
729 
730 dl_t *fr_dict_dl(fr_dict_t const *dict);
731 
733  fr_dict_t const **out, fr_sbuff_t *name, fr_dict_t const *dict_def);
734 
735 fr_dict_t const *fr_dict_by_protocol_name(char const *name);
736 
737 fr_dict_t const *fr_dict_by_protocol_num(unsigned int num);
738 
739 fr_dict_attr_t const *fr_dict_unlocal(fr_dict_attr_t const *da) CC_HINT(nonnull);
740 
741 fr_dict_t const *fr_dict_by_da(fr_dict_attr_t const *da) CC_HINT(nonnull);
742 
743 fr_dict_t const *fr_dict_by_attr_name(fr_dict_attr_t const **found, char const *name);
744 
745 bool fr_dict_compatible(fr_dict_t const *dict1, fr_dict_t const *dict2) CC_HINT(nonnull);
746 
747 /** Return true if this attribute is parented directly off the dictionary root
748  *
749  * @param[in] da to check.
750  * @return
751  * - true if attribute is top level.
752  * - false if attribute is not top level.
753  */
754 static inline bool fr_dict_attr_is_top_level(fr_dict_attr_t const *da)
755 {
756  if (unlikely(!da) || unlikely(!da->parent)) return false;
757  return da->parent->flags.is_root;
758 }
759 
761 
762 fr_dict_vendor_t const *fr_dict_vendor_by_name(fr_dict_t const *dict, char const *name);
763 
765 
766 fr_dict_attr_t const *fr_dict_vendor_da_by_num(fr_dict_attr_t const *vendor_root, uint32_t vendor_pen);
767 
769  fr_dict_t const *dict_def,
770  fr_sbuff_t *name, fr_sbuff_term_t const *tt,
771  bool internal, bool foreign)
772  CC_HINT(nonnull(2, 4));
773 
775  fr_dict_t const *dict_def,
776  fr_sbuff_t *name, fr_sbuff_term_t const *tt,
777  bool internal, bool foreign)
778  CC_HINT(nonnull(2, 4));
779 
781  fr_dict_t const *dict_def,
782  fr_sbuff_t *in, fr_sbuff_term_t const *tt,
783  bool internal, bool foreign)
784  CC_HINT(nonnull(2, 4));
785 
787  fr_dict_t const *dict_def, char const *attr,
788  bool internal, bool foreign)
789  CC_HINT(nonnull(3));
790 
792  fr_dict_t const *dict_def,
793  fr_sbuff_t *in, fr_sbuff_term_t const *tt,
794  bool internal, bool foreign)
795  CC_HINT(nonnull(2, 4));
796 
798  fr_dict_attr_t const *parent,
799  fr_sbuff_t *name, fr_sbuff_term_t const *tt)
800  CC_HINT(nonnull(2,3,4));
801 
803  char const *attr)
804  CC_HINT(nonnull(2,3));
805 
806 fr_dict_attr_t const *fr_dict_attr_child_by_num(fr_dict_attr_t const *parent, unsigned int attr);
807 
809 
810 char const *fr_dict_enum_name_by_value(fr_dict_attr_t const *da, fr_value_box_t const *value);
811 
813 
815 
817  fr_sbuff_t *in, fr_sbuff_term_t const *tt);
818 
820  fr_sbuff_t *in, fr_sbuff_term_t const *tt)
822 /** @} */
823 
824 /** @name Dictionary and protocol loading
825  *
826  * @{
827  */
828 int fr_dict_internal_afrom_file(fr_dict_t **out, char const *internal_name,
829  char const *dependent);
830 
831 int fr_dict_protocol_afrom_file(fr_dict_t **out, char const *proto_name, char const *proto_dir,
832  char const *dependent);
833 
835 
836 int fr_dict_read(fr_dict_t *dict, char const *dict_dir, char const *filename);
837 /** @} */
838 
839 /** @name Autoloader interface
840  *
841  * @{
842  */
844 
846 
847 #define fr_dict_autoload(_to_load) _fr_dict_autoload(_to_load, __FILE__)
848 int _fr_dict_autoload(fr_dict_autoload_t const *to_load, char const *dependent);
849 
850 #define fr_dict_autofree(_to_free) _fr_dict_autofree(_to_free, __FILE__)
851 int _fr_dict_autofree(fr_dict_autoload_t const *to_free, char const *dependent);
852 
853 #define fr_dict_autoload_talloc(_ctx, _dict_out, _proto) _fr_dict_autoload_talloc(_ctx, _dict_out, _proto, __FILE__)
854 fr_dict_autoload_talloc_t *_fr_dict_autoload_talloc(TALLOC_CTX *ctx, fr_dict_t const **out, char const *proto, char const *dependent);
855 
856 int fr_dl_dict_enum_autoload(dl_t const *module, void *symbol, void *user_ctx);
857 
858 int fr_dl_dict_attr_autoload(dl_t const *module, void *symbol, void *user_ctx);
859 
860 int fr_dl_dict_autoload(dl_t const *module, void *symbol, void *user_ctx);
861 
862 void fr_dl_dict_autofree(dl_t const *module, void *symbol, void *user_ctx);
863 /** @} */
864 
865 /** @name Allocating and freeing
866  *
867  * @{
868  */
869 fr_dict_t *fr_dict_alloc(char const *proto_name, unsigned int proto_number) CC_HINT(nonnull);
870 
871 int fr_dict_dependent_add(fr_dict_t const *dict, char const *dependent) CC_HINT(nonnull);
872 
873 int fr_dict_free(fr_dict_t **dict, char const *dependent) CC_HINT(nonnull);
874 
875 int fr_dict_const_free(fr_dict_t const **dict, char const *dependent) CC_HINT(nonnull);
876 /** @} */
877 
878 /** @name Global dictionary management
879  *
880  * @{
881  */
882 fr_dict_gctx_t *fr_dict_global_ctx_init(TALLOC_CTX *ctx, bool free_at_exit, char const *dict_dir);
883 
884 void fr_dict_global_ctx_perm_check(fr_dict_gctx_t *gctx, bool enable);
885 
886 void fr_dict_global_ctx_set(fr_dict_gctx_t const *gctx);
887 
888 int fr_dict_global_ctx_free(fr_dict_gctx_t const *gctx);
889 
890 int fr_dict_global_ctx_dir_set(char const *dict_dir);
891 
893 
894 void fr_dict_global_ctx_debug(fr_dict_gctx_t const *gctx);
895 
896 char const *fr_dict_global_ctx_dir(void);
897 
899 
901 
903 
905 
907 
908 fr_dict_t const *fr_dict_internal(void);
909 
910 /** @} */
911 
912 /** @name Dictionary testing and validation
913  *
914  * @{
915  */
916 int fr_dict_parse_str(fr_dict_t *dict, char *buf,
917  fr_dict_attr_t const *parent);
918 
919 ssize_t fr_dict_valid_name(char const *name, ssize_t len);
920 
921 ssize_t fr_dict_valid_oid_str(char const *name, ssize_t len);
922 
924 
925 typedef int (*fr_dict_walk_t)(fr_dict_attr_t const *da, void *uctx);
926 
927 int fr_dict_walk(fr_dict_attr_t const *da, fr_dict_walk_t callback, void *uctx);
928 
929 void fr_dict_attr_verify(char const *file, int line, fr_dict_attr_t const *da);
930 /** @} */
931 
932 #undef _CONST
933 
934 #ifdef __cplusplus
935 }
936 #endif
int const char * file
Definition: acutest.h:702
int const char int line
Definition: acutest.h:702
static fr_dict_t * dict
Definition: fuzzer.c:46
#define RCSIDH(h, id)
Definition: build.h:482
#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:110
#define unlikely(_x)
Definition: build.h:379
#define UNUSED
Definition: build.h:313
fr_dcursor_eval_t void const * uctx
Definition: dcursor.h:546
fr_dcursor_iter_t iter
Definition: dcursor.h:147
fr_table_elem_name_t name
Name of the flag.
Definition: dict.h:397
bool continuation
we only have one flag for now, for WiMAX
Definition: dict.h:246
fr_dict_t * fr_dict_global_ctx_iter_init(fr_dict_global_ctx_iter_t *iter)
Iterate protocols by name.
Definition: dict_util.c:4567
size_t type
Length of type data.
Definition: dict.h:247
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:2373
void fr_dict_global_ctx_debug(fr_dict_gctx_t const *gctx)
Dump information about currently loaded dictionaries.
Definition: dict_util.c:4530
dl_t * fr_dict_dl(fr_dict_t const *dict)
Definition: dict_util.c:2410
static fr_dict_attr_t * fr_dict_attr_unknown_copy(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Definition: dict.h:550
char const * fr_dict_global_ctx_dir(void)
Definition: dict_util.c:4494
fr_dict_protocol_free_t free
free the library
Definition: dict.h:456
size_t name_len
Allows for efficient name lookups when operating on partial buffers.
Definition: dict.h:228
fr_dict_attr_flags_t flags
Flags.
Definition: dict.h:192
fr_dict_attr_decode_func_t decode
for decoding attributes.
Definition: dict.h:458
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:363
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))
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.
Definition: dict_unknown.c:38
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:1590
char const * name
of the attribute.
Definition: dict.h:272
@ FLAG_EXTRA_NONE
no extra meaning, should be invalid
Definition: dict.h:145
@ FLAG_LENGTH_UINT8
string / octets type is prefixed by uint8 of length
Definition: dict.h:148
@ FLAG_LENGTH_UINT16
string / octets type is prefixed by uint16 of length
Definition: dict.h:149
@ FLAG_KEY_FIELD
this is a key field for a subsequent struct
Definition: dict.h:146
@ FLAG_BIT_FIELD
bit field inside of a struct
Definition: dict.h:147
int fr_dict_internal_afrom_file(fr_dict_t **out, char const *internal_name, char const *dependent)
(Re-)Initialize the special internal dictionary
unsigned int name_only
this attribute should always be referred to by name.
Definition: dict.h:98
ssize_t fr_dict_valid_oid_str(char const *name, ssize_t len)
Definition: dict_util.c:4663
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:4483
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:3515
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:1941
unsigned int has_value
Has a value.
Definition: dict.h:92
fr_dict_enum_ext_t
Extension identifier.
Definition: dict.h:217
@ FR_DICT_ENUM_EXT_MAX
Definition: dict.h:219
@ FR_DICT_ENUM_EXT_UNION_REF
Reference to a union/subs-struct.
Definition: dict.h:218
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.
Definition: merged_model.c:188
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:1738
char const * name
Vendor name.
Definition: dict.h:249
fr_dict_attr_t * fr_dict_attr_unconst(fr_dict_attr_t const *da)
Coerce to non-const.
Definition: dict_util.c:4597
char const * filename
Where the attribute was defined.
Definition: dict.h:205
void * uctx
Use context to pass to the custom parsing function.
Definition: dict.h:367
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:3081
fr_dict_attr_t const ** attr
The protocol dictionary the attribute should be resolved in.
Definition: dict.h:257
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:2680
unsigned int is_root
Is root of a dictionary.
Definition: dict.h:74
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:4051
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:4172
int fr_dict_walk(fr_dict_attr_t const *da, fr_dict_walk_t callback, void *uctx)
Definition: dict_util.c:4777
fr_dict_t * fr_dict_protocol_alloc(fr_dict_t const *parent)
Allocate a new local dictionary.
Definition: dict_util.c:3961
size_t name_len
Length of the name.
Definition: dict.h:180
int line
Line number where the attribute was defined.
Definition: dict.h:208
bool(* fr_dict_attr_valid_func_t)(fr_dict_attr_t *da)
Definition: dict.h:305
int fr_dl_dict_enum_autoload(dl_t const *module, void *symbol, void *user_ctx)
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.
Definition: dict_unknown.c:229
void fr_dict_namespace_debug(fr_dict_attr_t const *da)
Definition: dict_print.c:230
static fr_slen_t err
Definition: dict.h:821
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:3263
fr_dict_t * fr_dict_alloc(char const *proto_name, unsigned int proto_number)
bool const fr_dict_attr_allowed_chars[UINT8_MAX+1]
Characters that are allowed in dictionary attribute names.
Definition: dict_util.c:51
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:344
int fr_dict_attr_acopy_local(fr_dict_attr_t const *dst, fr_dict_attr_t const *src)
Definition: dict_util.c:1060
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:2619
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:391
fr_value_box_t const ** out
Enumeration value.
Definition: dict.h:256
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:2037
fr_dict_t const ** dict
The protocol dictionary the attribute should be resolved in.
Definition: dict.h:269
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:2324
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:2695
void fr_dict_attr_verify(char const *file, int line, fr_dict_attr_t const *da)
Definition: dict_util.c:4783
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
int fr_dict_str_to_argv(char *str, char **argv, int max_argc)
Definition: dict_tokenize.c:86
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:4875
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:570
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)
Definition: merged_model.c:201
fr_dict_t const * fr_dict_by_protocol_num(unsigned int num)
Lookup a protocol by its number.
Definition: dict_util.c:2590
fr_dict_t const * fr_dict_by_protocol_name(char const *name)
Lookup a protocol by its name.
Definition: dict_util.c:2577
int(* fr_dict_walk_t)(fr_dict_attr_t const *da, void *uctx)
Definition: dict.h:925
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:4696
struct dict_attr_s::@120 state
unsigned int array
Pack multiples into 1 attr.
Definition: dict.h:88
fr_dict_enum_value_t * 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:3349
unsigned int secret
this attribute should be omitted in debug mode
Definition: dict.h:103
void fr_dict_debug(fr_dict_t const *dict)
Definition: dict_print.c:258
fr_dict_flag_parse_func_t func
Custom parsing function to convert a flag value string to a C type value.
Definition: dict.h:366
unsigned int extra
really "subtype is used by dict, not by protocol"
Definition: dict.h:112
unsigned int internal
Internal attribute, should not be received in protocol packets, should not be encoded.
Definition: dict.h:86
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition: dict.h:267
fr_dict_t const * fr_dict_by_attr_name(fr_dict_attr_t const **found, char const *name)
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition: dict.h:280
void fr_dict_global_ctx_set(fr_dict_gctx_t const *gctx)
Set a new, active, global dictionary context.
Definition: dict_util.c:4453
fr_dict_attr_t const * next
Next child in bin.
Definition: dict.h:190
fr_dict_t _CONST *_CONST dict
Dict attribute belongs to.
Definition: dict.h:177
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:3062
char const * name
Attribute name.
Definition: dict.h:179
fr_dict_protocol_init_t init
initialize the library
Definition: dict.h:455
unsigned int is_raw
This dictionary attribute was constructed from a known attribute to allow the user to assign octets v...
Definition: dict.h:79
fr_slen_t fr_dict_attr_by_oid_legacy(fr_dict_t const *dict, fr_dict_attr_t const **parent, unsigned int *attr, char const *oid)
Get the leaf attribute of an OID string.
Definition: dict_util.c:2125
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
Definition: dict_util.c:2400
bool const fr_dict_enum_allowed_chars[UINT8_MAX+1]
Characters that are allowed in dictionary enumeration value names.
Definition: dict_util.c:72
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.
Definition: dict_unknown.c:511
char const * name
of the attribute.
Definition: dict.h:260
fr_value_box_t const * value
Enum value (what name maps to).
Definition: dict.h:230
unsigned int attr
Attribute number.
Definition: dict.h:182
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:1953
uint8_t ext[FR_DICT_ATTR_EXT_MAX]
Extensions to the dictionary attribute.
Definition: dict.h:210
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:380
int default_type_size
how many octets are in "type" field
Definition: dict.h:430
uint32_t pen
Private enterprise number.
Definition: dict.h:245
int fr_dict_free(fr_dict_t **dict, char const *dependent)
Decrement the reference count on a previously loaded dictionary.
Definition: dict_util.c:4024
void fr_dict_attr_unknown_free(fr_dict_attr_t const **da)
Free dynamically allocated (unknown attributes)
Definition: dict_unknown.c:148
fr_type_t type
of the attribute. Mismatch is a fatal error.
Definition: dict.h:273
fr_dict_flag_parser_rule_t value
Function and context to parse the flag.
Definition: dict.h:398
#define _CONST
Definition: dict.h:58
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:2606
int fr_dict_oid_component_legacy(unsigned int *out, char const **oid)
Process a single OID component.
Definition: dict_util.c:2080
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:3421
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:4444
void fr_dict_global_ctx_read_only(void)
Mark all dictionaries and the global dictionary ctx as read only.
Definition: dict_util.c:4503
uint8_t type_size
For TLV2 and root attributes.
Definition: dict.h:135
unsigned int depth
Depth of nesting for this attribute.
Definition: dict.h:183
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:4008
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:4090
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:577
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:2497
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:3691
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:2975
size_t length
Length of length data.
Definition: dict.h:248
bool fr_dict_is_read_only(fr_dict_t const *dict)
Definition: dict_util.c:2405
char const * base_dir
Directory structure beneath share.
Definition: dict.h:282
fr_dict_attr_t const * parent
Immediate parent of this attribute.
Definition: dict.h:189
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.
Definition: dict_unknown.c:378
fr_dict_enum_value_t * fr_dict_enum_by_name(fr_dict_attr_t const *da, char const *name, ssize_t len)
Definition: dict_util.c:3395
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:562
fr_dict_attr_t * fr_dict_attr_unknown_raw_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da))
Initialise an octets type attribute from a da.
Definition: dict_unknown.c:352
fr_dict_t const * fr_dict_internal(void)
Definition: dict_util.c:4610
fr_dict_t * fr_dict_unconst(fr_dict_t const *dict)
Coerce to non-const.
Definition: dict_util.c:4585
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:3004
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:754
void(* fr_dict_protocol_free_t)(void)
Definition: dict.h:351
fr_dict_attr_encode_func_t encode
for encoding attributes.
Definition: dict.h:460
fr_dict_attr_ext_t
Extension identifier.
Definition: dict.h:161
@ FR_DICT_ATTR_EXT_PROTOCOL_SPECIFIC
Protocol specific extensions.
Definition: dict.h:170
@ FR_DICT_ATTR_EXT_MAX
Definition: dict.h:171
@ FR_DICT_ATTR_EXT_ENUMV
Enumeration values.
Definition: dict.h:168
@ FR_DICT_ATTR_EXT_NAMESPACE
Attribute has its own namespace.
Definition: dict.h:169
@ FR_DICT_ATTR_EXT_DA_STACK
Cached da stack.
Definition: dict.h:167
@ FR_DICT_ATTR_EXT_REF
Attribute references another attribute and/or dictionary.
Definition: dict.h:164
@ FR_DICT_ATTR_EXT_VENDOR
Cached vendor pointer.
Definition: dict.h:166
@ FR_DICT_ATTR_EXT_NAME
Name of the attribute.
Definition: dict.h:162
@ FR_DICT_ATTR_EXT_CHILDREN
Attribute has children.
Definition: dict.h:163
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:4223
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.
Definition: dict_unknown.c:564
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:185
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:4469
unsigned int is_known_width
is treated as if it has a known width for structs
Definition: dict.h:90
int fr_dict_parse_str(fr_dict_t *dict, char *buf, fr_dict_attr_t const *parent)
int fr_dict_read(fr_dict_t *dict, char const *dict_dir, char const *filename)
Read supplementary attribute definitions into an existing dictionary.
void fr_dl_dict_autofree(dl_t const *module, void *symbol, void *user_ctx)
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:2635
int default_type_length
how many octets are in "length" field
Definition: dict.h:431
fr_dict_attr_err_t
Errors returned by attribute lookup functions.
Definition: dict.h:289
@ FR_DICT_ATTR_OK
No error.
Definition: dict.h:290
@ FR_DICT_ATTR_NOT_ANCESTOR
Attribute is not an ancestor of the child attribute.
Definition: dict.h:298
@ FR_DICT_ATTR_NOT_DESCENDENT
Attribute is not a descendent of the parent attribute.
Definition: dict.h:296
@ FR_DICT_ATTR_NOTFOUND
Attribute couldn't be found.
Definition: dict.h:291
@ FR_DICT_ATTR_EINVAL
Invalid arguments.
Definition: dict.h:301
@ FR_DICT_ATTR_PROTOCOL_NOTFOUND
Protocol couldn't be found.
Definition: dict.h:292
@ FR_DICT_ATTR_NO_CHILDREN
Child lookup in attribute with no children.
Definition: dict.h:300
@ FR_DICT_ATTR_OOM
Memory allocation error.
Definition: dict.h:295
@ FR_DICT_ATTR_PARSE_ERROR
Attribute string couldn't be parsed.
Definition: dict.h:293
@ FR_DICT_ATTR_INTERNAL_ERROR
Internal error occurred.
Definition: dict.h:294
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:3033
int(* fr_dict_protocol_init_t)(void)
Init / free callbacks.
Definition: dict.h:350
bool needs_value
This parsing flag must have a value. Else we error.
Definition: dict.h:368
struct fr_dict_protocol_t::@121 attr
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:1712
fr_dict_attr_t const * fr_dict_unlocal(fr_dict_attr_t const *da)
Definition: dict_util.c:4956
fr_dict_t * fr_dict_global_ctx_iter_next(fr_dict_global_ctx_iter_t *iter)
Definition: dict_util.c:4574
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:4139
unsigned int is_unsigned
hackity hack for dates and time deltas
Definition: dict.h:94
int fr_dl_dict_autoload(dl_t const *module, void *symbol, void *user_ctx)
ssize_t fr_dict_valid_name(char const *name, ssize_t len)
Definition: dict_util.c:4620
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:2229
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:328
void fr_dict_export(fr_dict_t const *dict)
Export in the standard form: ATTRIBUTE name oid flags.
Definition: dict_print.c:295
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:3328
char const * proto
The protocol dictionary name.
Definition: dict.h:283
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:2657
void fr_dict_attr_debug(fr_dict_attr_t const *da)
Definition: dict_print.c:250
char const * name
Enum name.
Definition: dict.h:227
static fr_slen_t in
Definition: dict.h:821
fr_type_t type
Value type.
Definition: dict.h:187
fr_dict_protocol_t const * fr_dict_protocol(fr_dict_t const *dict)
Return the protocol descriptor for the dictionary.
Definition: dict_util.c:4948
char const * name
name of this protocol
Definition: dict.h:428
uint8_t subtype
protocol-specific values, OR key fields
Definition: dict.h:121
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:640
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.
Definition: dict_unknown.c:271
uint8_t length
length of the attribute
Definition: dict.h:127
unsigned int is_alias
This isn't a real attribute, it's a reference to to one.
Definition: dict.h:84
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:3382
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:4392
unsigned int counter
integer attribute is actually an impulse / counter
Definition: dict.h:96
unsigned int is_unknown
This dictionary attribute is ephemeral and not part of the main dictionary.
Definition: dict.h:76
int fr_dl_dict_attr_autoload(dl_t const *module, void *symbol, void *user_ctx)
static int8_t fr_dict_attr_cmp(fr_dict_attr_t const *a, fr_dict_attr_t const *b)
Definition: dict.h:603
Dictionary attribute.
Definition: dict.h:176
Specifies an attribute which must be present for the module to function.
Definition: dict.h:266
Values of the encryption flags.
Definition: merged_model.c:139
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition: dict.h:279
Specifies a value which must be present for the module to function.
Definition: dict.h:255
Value of an enumerated attribute.
Definition: dict.h:226
Protocol specific custom flag definitnion.
Definition: dict.h:396
Protocol-specific callbacks in libfreeradius-PROTOCOL.
Definition: dict.h:427
Private enterprise.
Definition: dict.h:244
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:212
bool free_at_exit
This gctx will be freed on exit.
Definition: dict_priv.h:126
Vendors and attribute names.
Definition: dict_priv.h:83
Test enumeration values.
Definition: dict_test.h:92
Structure used to managed the lifetime of a dictionary.
Definition: dict_util.c:4196
Module handle.
Definition: dl.h:58
#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
fr_type_t
Definition: merged_model.c:80
@ FR_TYPE_VENDOR
Attribute that represents a vendor in the attribute tree.
Definition: merged_model.c:122
@ FR_TYPE_OCTETS
Raw octets.
Definition: merged_model.c:84
unsigned int uint32_t
Definition: merged_model.c:33
long int ssize_t
Definition: merged_model.c:24
unsigned char bool
Definition: merged_model.c:19
unsigned char uint8_t
Definition: merged_model.c:30
ssize_t fr_slen_t
Definition: merged_model.c:35
#define UINT8_MAX
Definition: merged_model.c:32
fr_sbuff_parse_error_t
Definition: merged_model.c:45
static char const * proto(int id, int porttype)
Definition: radwho.c:85
static char const * name
#define SBUFF_OUT_TALLOC_FUNC_NO_LEN_DEF(_func,...)
Set of terminal elements.
Definition: merged_model.c:161
fr_assert(0)
fr_aka_sim_id_type_t type
static fr_slen_t parent
Definition: pair.h:851
static fr_slen_t data
Definition: value.h:1265
int nonnull(2, 5))
static size_t char ** out
Definition: value.h:997
Union containing all data types supported by the server.
Definition: value.h:170