The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Private Multi-protocol AVP dictionary API. More...
#include <freeradius-devel/protocol/base.h>
#include <freeradius-devel/util/dict.h>
#include <freeradius-devel/util/dict_ext_priv.h>
#include <freeradius-devel/util/dl.h>
#include <freeradius-devel/util/hash.h>
#include <freeradius-devel/util/value.h>
Go to the source code of this file.
Data Structures | |
struct | dict_attr_args_t |
Optional arguments for initialising/allocating attributes. More... | |
struct | fr_dict_dependent_t |
Entry recording dictionary reference holders by file. More... | |
struct | fr_dict_filename_t |
Entry in the filename list of files associated with this dictionary. More... | |
struct | fr_dict_gctx_s |
struct | fr_dict_s |
Vendors and attribute names. More... | |
Macros | |
#define | _DICT_PRIVATE 1 |
#define | DICT_FIXUP_POOL_SIZE (1024) |
#define | DICT_POOL_SIZE (1024 * 1024 * 2) |
#define | INTERNAL_IF_NULL(_dict, _ret) |
Set the internal dictionary if none was provided. | |
Functions | |
fr_dict_t * | dict_alloc (TALLOC_CTX *ctx) |
Allocate a new dictionary. | |
fr_dict_attr_t * | dict_attr_acopy (TALLOC_CTX *ctx, fr_dict_attr_t const *in, char const *new_name) |
Copy a an existing attribute. | |
int | dict_attr_acopy_children (fr_dict_t *dict, fr_dict_attr_t *dst, fr_dict_attr_t const *src) |
Copy the children of an existing attribute. | |
int | dict_attr_acopy_enumv (fr_dict_attr_t *dst, fr_dict_attr_t const *src) |
Copy the VALUEs of an existing attribute, by casting them. | |
int | dict_attr_add_to_namespace (fr_dict_attr_t const *parent, fr_dict_attr_t *da) |
Add an attribute to the name table for an attribute. | |
int | dict_attr_alias_add (fr_dict_attr_t const *parent, char const *alias, fr_dict_attr_t const *ref) |
Add an alias to an existing attribute. | |
fr_dict_attr_t * | dict_attr_by_name (fr_dict_attr_err_t *err, fr_dict_attr_t const *parent, char const *name) |
bool | dict_attr_can_have_children (fr_dict_attr_t const *da) |
See if a fr_dict_attr_t can have children. | |
int | dict_attr_child_add (fr_dict_attr_t *parent, fr_dict_attr_t *child) |
Add a child to a parent. | |
fr_dict_attr_t * | dict_attr_child_by_num (fr_dict_attr_t const *parent, unsigned int attr) |
Internal version of fr_dict_attr_child_by_num. | |
int | dict_attr_enum_add_name (fr_dict_attr_t *da, char const *name, fr_value_box_t const *value, bool coerce, bool replace, fr_dict_attr_t const *child_struct) |
bool | dict_attr_flags_valid (fr_dict_attr_t *da)) |
Validate a set of flags. | |
bool | dict_attr_valid (fr_dict_attr_t *da) |
Validate a new attribute definition. | |
fr_dict_t * | dict_by_da (fr_dict_attr_t const *da) |
Internal version of fr_dict_by_da. | |
fr_dict_t * | dict_by_protocol_name (char const *name) |
Internal version of fr_dict_by_protocol_name. | |
fr_dict_t * | dict_by_protocol_num (unsigned int num) |
Internal version of fr_dict_by_protocol_num. | |
fr_slen_t | dict_by_protocol_substr (fr_dict_attr_err_t *err, fr_dict_t **out, fr_sbuff_t *name, fr_dict_t const *dict_def) |
int | dict_dependent_add (fr_dict_t *dict, char const *dependent) |
Record a new dependency on a dictionary. | |
int | dict_dependent_remove (fr_dict_t *dict, char const *dependent) |
Decrement ref count for a dependent in a dictionary. | |
int | dict_dlopen (fr_dict_t *dict, char const *name) |
bool | dict_has_dependents (fr_dict_t *dict) |
Check if a dictionary still has dependents. | |
int | dict_protocol_add (fr_dict_t *dict) |
Add a protocol to the global protocol table. | |
int | dict_vendor_add (fr_dict_t *dict, char const *name, unsigned int num) |
Add a vendor to the dictionary. | |
Variables | |
fr_dict_gctx_t * | dict_gctx |
Top level structure containing global dictionary state. | |
fr_dict_attr_t * | _dict_attr_alloc (char const *filename, int line, TALLOC_CTX *ctx, fr_dict_attr_t const *parent, char const *name, int attr, fr_type_t type, dict_attr_args_t const *args)) |
Allocate a dictionary attribute on the heap. | |
fr_dict_attr_t * | _dict_attr_alloc_root (char const *filename, int line, TALLOC_CTX *ctx, fr_dict_t const *dict, char const *name, int attr, dict_attr_args_t const *args)) |
Allocate a dictionary root attribute on the heap. | |
int | _dict_attr_init (char const *filename, int line, fr_dict_attr_t **da_p, fr_dict_attr_t const *parent, char const *name, unsigned int attr, fr_type_t type, dict_attr_args_t const *args)) |
Initialise fields in a dictionary attribute structure. | |
int | _dict_attr_init_name_only (char const *filename, int line, fr_dict_attr_t **da_p, fr_dict_attr_t const *parent, char const *name, fr_type_t type, dict_attr_args_t const *args)) |
Initialise fields in a dictionary attribute structure. | |
#define | dict_attr_alloc(_ctx, _parent, _name, _attr, _type, _args) _dict_attr_alloc(__FILE__, __LINE__, _ctx, _parent, _name, _attr, _type, (_args)) |
#define | dict_attr_alloc_root(_ctx, _dict, _name, _attr, _args) _dict_attr_alloc_root(__FILE__, __LINE__, _ctx, _dict, _name, _attr, _args) |
#define | dict_attr_init(_da_p, _parent, _name, _attr, _type, _args) _dict_attr_init(__FILE__, __LINE__, _da_p, _parent, _name, _attr, _type, _args) |
Full initialisation functions. | |
#define | dict_attr_init_name_only(_da_p, _parent, _name, _type, _args) _dict_attr_init_name_only(__FILE__, __LINE__, _da_p, _parent, _name, _type, _args) |
fr_dict_attr_t * | dict_attr_alloc_null (TALLOC_CTX *ctx, fr_dict_protocol_t const *dict) |
Partial initialisation functions. | |
int | dict_attr_finalise (fr_dict_attr_t **da_p, char const *name) |
Set remaining fields in a dictionary attribute before insertion. | |
void | dict_attr_location_init (fr_dict_attr_t *da, char const *filename, int line) |
Set where the dictionary attribute was defined. | |
int | dict_attr_num_init (fr_dict_attr_t *da, unsigned int num) |
Set the attribute number (if any) | |
int | dict_attr_num_init_name_only (fr_dict_attr_t *da) |
Set the attribute number (if any) | |
int | dict_attr_parent_init (fr_dict_attr_t **da_p, fr_dict_attr_t const *parent) |
Initialise fields which depend on a parent attribute. | |
int | dict_attr_type_init (fr_dict_attr_t **da_p, fr_type_t type) |
Initialise type specific fields within the dictionary attribute. | |
Private Multi-protocol AVP dictionary API.
Definition in file dict_priv.h.
struct dict_attr_args_t |
Optional arguments for initialising/allocating attributes.
Definition at line 171 of file dict_priv.h.
Data Fields | ||
---|---|---|
fr_dict_attr_flags_t const * | flags | Any flags to assign to the attribute. |
fr_dict_attr_t const * | ref | This attribute is a reference to another attribute. |
struct fr_dict_dependent_t |
Entry recording dictionary reference holders by file.
Definition at line 58 of file dict_priv.h.
Data Fields | ||
---|---|---|
int | count |
How many references are held by this file. Signed to help figure out when things go wrong... |
char const * | dependent | File holding the reference. |
fr_rb_node_t | node |
struct fr_dict_filename_t |
Entry in the filename list of files associated with this dictionary.
Mainly used for debugging.
Definition at line 69 of file dict_priv.h.
Data Fields | ||
---|---|---|
fr_dlist_t | entry | Entry in the list of filenames. |
char * | filename | Name of the file the dictionary was loaded on. |
struct fr_dict_gctx_s |
Definition at line 125 of file dict_priv.h.
Data Fields | ||
---|---|---|
fr_dict_attr_t const * | attr_protocol_encapsulation | |
char * | dict_dir_default | The default location for loading dictionaries if one wasn't provided. |
dl_loader_t * | dict_loader | for protocol validation |
bool | free_at_exit | This gctx will be freed on exit. |
fr_dict_t * | internal |
Magic internal dictionary. Internal dictionary is checked in addition to the protocol dictionary when resolving attribute names. This is because internal attributes are valid for every protocol. |
bool | perm_check | Whether we should check dictionary file permissions as they're loaded. |
fr_hash_table_t * | protocol_by_name | Hash containing names of all the registered protocols. |
fr_hash_table_t * | protocol_by_num | Hash containing numbers of all the registered protocols. |
bool | read_only |
struct fr_dict_s |
Vendors and attribute names.
It's very likely that the same vendors will operate in multiple protocol spaces, but number their attributes differently, so we need per protocol dictionaries.
There would also be conflicts for DHCP(v6)/RADIUS attributes etc...
Definition at line 83 of file dict_priv.h.
Data Fields | ||
---|---|---|
fr_hash_table_t * | autoref | other dictionaries that we loaded via references |
fr_rb_tree_t * | dependents | Which files are using this dictionary. |
dl_t * | dl | for validation |
fr_dlist_head_t | filenames | Files that this dictionary was loaded from. |
fr_dict_attr_t ** | fixups | Attributes that need fixing up. |
fr_dict_gctx_t * | gctx | Global dictionary context this dictionary was allocated in. |
bool | in_protocol_by_name | Whether the dictionary has been inserted into the protocol_by_name hash. |
bool | in_protocol_by_num | Whether the dictionary has been inserted into the protocol_by_num table. |
bool | loaded | from fr_dict_protocol_afrom_file(); |
bool | loading | from fr_dict_protocol_afrom_file(); |
fr_dict_t const * | next | for attribute overloading |
TALLOC_CTX * | pool |
Talloc memory pool to reduce allocs. in the dictionary. |
fr_dict_protocol_t const * | proto | protocol-specific validation functions |
bool | read_only | If true, disallow modifications. |
fr_dict_attr_t * | root | Root attribute of this dictionary. |
bool | string_based | TACACS, etc. |
fr_hash_table_t * | vendors_by_name | Lookup vendor by name. |
fr_hash_table_t * | vendors_by_num | Lookup vendor by PEN. |
unsigned int | vsa_parent | varies with different protocols. |
#define _DICT_PRIVATE 1 |
Definition at line 28 of file dict_priv.h.
#define dict_attr_alloc | ( | _ctx, | |
_parent, | |||
_name, | |||
_attr, | |||
_type, | |||
_args | |||
) | _dict_attr_alloc(__FILE__, __LINE__, _ctx, _parent, _name, _attr, _type, (_args)) |
Definition at line 235 of file dict_priv.h.
#define dict_attr_alloc_root | ( | _ctx, | |
_dict, | |||
_name, | |||
_attr, | |||
_args | |||
) | _dict_attr_alloc_root(__FILE__, __LINE__, _ctx, _dict, _name, _attr, _args) |
Definition at line 227 of file dict_priv.h.
#define dict_attr_init | ( | _da_p, | |
_parent, | |||
_name, | |||
_attr, | |||
_type, | |||
_args | |||
) | _dict_attr_init(__FILE__, __LINE__, _da_p, _parent, _name, _attr, _type, _args) |
Full initialisation functions.
These functions either initialise, or allocate and then initialise a complete dictionary attribute.
The output of these functions can be added into a dictionary immediately
Definition at line 211 of file dict_priv.h.
#define dict_attr_init_name_only | ( | _da_p, | |
_parent, | |||
_name, | |||
_type, | |||
_args | |||
) | _dict_attr_init_name_only(__FILE__, __LINE__, _da_p, _parent, _name, _type, _args) |
Definition at line 219 of file dict_priv.h.
#define DICT_FIXUP_POOL_SIZE (1024) |
Definition at line 38 of file dict_priv.h.
#define DICT_POOL_SIZE (1024 * 1024 * 2) |
Definition at line 37 of file dict_priv.h.
#define INTERNAL_IF_NULL | ( | _dict, | |
_ret | |||
) |
Set the internal dictionary if none was provided.
_dict | Dict pointer to check/set. |
_ret | Value to return if no dictionaries are available. |
Definition at line 45 of file dict_priv.h.
fr_dict_attr_t * _dict_attr_alloc | ( | char const * | filename, |
int | line, | ||
TALLOC_CTX * | ctx, | ||
fr_dict_attr_t const * | parent, | ||
char const * | name, | ||
int | attr, | ||
fr_type_t | type, | ||
dict_attr_args_t const * | args | ||
) |
Allocate a dictionary attribute on the heap.
[in] | ctx | to allocate the attribute in. |
[in] | parent | of the attribute. |
[in] | name | of the attribute. If NULL an OID string will be created and set as the name. |
[in] | attr | number. |
[in] | type | of the attribute. |
[in] | args | optional initialisation arguments. |
Definition at line 988 of file dict_util.c.
fr_dict_attr_t * _dict_attr_alloc_root | ( | char const * | filename, |
int | line, | ||
TALLOC_CTX * | ctx, | ||
fr_dict_t const * | dict, | ||
char const * | name, | ||
int | proto_number, | ||
dict_attr_args_t const * | args | ||
) |
Allocate a dictionary root attribute on the heap.
[in] | ctx | to allocate the attribute in. |
[in] | dict | the attribute will be used in. |
[in] | name | of the attribute. If NULL an OID string will be created and set as the name. |
[in] | proto_number | number. This should be |
[in] | args | optional initialisation arguments. |
Definition at line 956 of file dict_util.c.
int _dict_attr_init | ( | char const * | filename, |
int | line, | ||
fr_dict_attr_t ** | da_p, | ||
fr_dict_attr_t const * | parent, | ||
char const * | name, | ||
unsigned int | attr, | ||
fr_type_t | type, | ||
dict_attr_args_t const * | args | ||
) |
Initialise fields in a dictionary attribute structure.
This function is a wrapper around the other initialisation functions.
The reason for the separation, is that sometimes we're initialising a dictionary attribute by parsing an actual dictionary file, and other times we're copying attribute, or initialising them programatically.
This function should only be used for the second case, where we have a complet attribute definition already.
[in] | filename | file. |
[in] | line | number. |
[in] | da_p | to initialise. |
[in] | parent | of the attribute, if none, this attribute will be initialised as a dictionary root. |
[in] | name | of attribute. Pass NULL for auto-generated name. |
[in] | attr | number. |
[in] | type | of the attribute. |
[in] | args | optional initialisation arguments. |
Definition at line 824 of file dict_util.c.
int _dict_attr_init_name_only | ( | char const * | filename, |
int | line, | ||
fr_dict_attr_t ** | da_p, | ||
fr_dict_attr_t const * | parent, | ||
char const * | name, | ||
fr_type_t | type, | ||
dict_attr_args_t const * | args | ||
) |
Initialise fields in a dictionary attribute structure.
This function is a wrapper around the other initialisation functions.
The reason for the separation, is that sometimes we're initialising a dictionary attribute by parsing an actual dictionary file, and other times we're copying attribute, or initialising them programatically.
This function should only be used for the second case, where we have a complet attribute definition already.
[in] | filename | file. |
[in] | line | number. |
[in] | da_p | to initialise. |
[in] | parent | of the attribute, if none, this attribute will be initialised as a dictionary root. |
[in] | name | of attribute. Pass NULL for auto-generated name. automatically generated. |
[in] | type | of the attribute. |
[in] | args | optional initialisation arguments. |
Definition at line 865 of file dict_util.c.
fr_dict_t * dict_alloc | ( | TALLOC_CTX * | ctx | ) |
Allocate a new dictionary.
[in] | ctx | to allocate dictionary in. |
Definition at line 3872 of file dict_util.c.
fr_dict_attr_t * dict_attr_acopy | ( | TALLOC_CTX * | ctx, |
fr_dict_attr_t const * | in, | ||
char const * | new_name | ||
) |
Copy a an existing attribute.
[in] | ctx | to allocate new attribute in. |
[in] | in | attribute to copy. |
[in] | new_name | to assign to the attribute. If NULL the existing name will be used. |
Definition at line 1017 of file dict_util.c.
int dict_attr_acopy_children | ( | fr_dict_t * | dict, |
fr_dict_attr_t * | dst, | ||
fr_dict_attr_t const * | src | ||
) |
Copy the children of an existing attribute.
[in] | dict | to allocate the children in |
[in] | dst | where to copy the children to |
[in] | src | where to copy the children from |
Definition at line 1087 of file dict_util.c.
int dict_attr_acopy_enumv | ( | fr_dict_attr_t * | dst, |
fr_dict_attr_t const * | src | ||
) |
Copy the VALUEs of an existing attribute, by casting them.
[in] | dst | where to cast the VALUEs to |
[in] | src | where to cast the VALUEs from |
Definition at line 1145 of file dict_util.c.
int dict_attr_add_to_namespace | ( | fr_dict_attr_t const * | parent, |
fr_dict_attr_t * | da | ||
) |
Add an attribute to the name table for an attribute.
[in] | parent | containing the namespace to add this attribute to. |
[in] | da | to add to the name lookup tables. |
Definition at line 1524 of file dict_util.c.
int dict_attr_alias_add | ( | fr_dict_attr_t const * | parent, |
char const * | alias, | ||
fr_dict_attr_t const * | ref | ||
) |
Add an alias to an existing attribute.
Definition at line 1174 of file dict_util.c.
fr_dict_attr_t * dict_attr_alloc_null | ( | TALLOC_CTX * | ctx, |
fr_dict_protocol_t const * | proto | ||
) |
Partial initialisation functions.
These functions are used to initialise attributes in stages, i.e. when parsing a dictionary.
The finalise function must be called to complete the initialisation.
All functions must be called to fully initialise a dictionary attribute, except dict_attr_parent_init this is not necessary for root attributes.
Partial initialisation functions.
This is useful in some instances where we need to pre-allocate the attribute for talloc hierarchy reasons, but want to finish initialising it with dict_attr_init later.
[in] | ctx | to allocate attribute in. |
[in] | proto | protocol specific extensions. |
Definition at line 917 of file dict_util.c.
fr_dict_attr_t * dict_attr_by_name | ( | fr_dict_attr_err_t * | err, |
fr_dict_attr_t const * | parent, | ||
char const * | name | ||
) |
Definition at line 3217 of file dict_util.c.
bool dict_attr_can_have_children | ( | fr_dict_attr_t const * | da | ) |
See if a fr_dict_attr_t can have children.
The check for children is complicated by the need for "int" types to have children, when they are key
fields in a struct
. This situation occurs when a struct has multiple sub-structures, which are selected based on a key
field.
There is no other place for the sub-structures to go. In the future, we may extend the functionality of the key
field, by allowing non-integer data types. That would require storing keys as fr_dict_enum_value_t, and then placing the child (i.e. sub) structures there. But that would involve adding children to enums, which is currently not supported.
da | the dictionary attribute to check. |
Definition at line 1391 of file dict_util.c.
int dict_attr_child_add | ( | fr_dict_attr_t * | parent, |
fr_dict_attr_t * | child | ||
) |
Add a child to a parent.
[in] | parent | we're adding a child to. |
[in] | child | to add to parent. |
Definition at line 1425 of file dict_util.c.
fr_dict_attr_t * dict_attr_child_by_num | ( | fr_dict_attr_t const * | parent, |
unsigned int | attr | ||
) |
Internal version of fr_dict_attr_child_by_num.
Definition at line 3281 of file dict_util.c.
int dict_attr_enum_add_name | ( | fr_dict_attr_t * | da, |
char const * | name, | ||
fr_value_box_t const * | value, | ||
bool | coerce, | ||
bool | replace, | ||
fr_dict_attr_t const * | child_struct | ||
) |
Definition at line 1752 of file dict_util.c.
int dict_attr_finalise | ( | fr_dict_attr_t ** | da_p, |
char const * | name | ||
) |
Set remaining fields in a dictionary attribute before insertion.
[in] | da_p | to finalise. |
[in] | name | of the attribute. |
Definition at line 709 of file dict_util.c.
bool dict_attr_flags_valid | ( | fr_dict_attr_t * | da | ) |
Validate a set of flags.
[in] | da | to check. |
Definition at line 35 of file dict_validate.c.
void dict_attr_location_init | ( | fr_dict_attr_t * | da, |
char const * | filename, | ||
int | line | ||
) |
Set where the dictionary attribute was defined.
Definition at line 695 of file dict_util.c.
int dict_attr_num_init | ( | fr_dict_attr_t * | da, |
unsigned int | num | ||
) |
Set the attribute number (if any)
[in] | da | to set the attribute number for. |
[in] | num | to set. |
Definition at line 665 of file dict_util.c.
int dict_attr_num_init_name_only | ( | fr_dict_attr_t * | da | ) |
Set the attribute number (if any)
[in] | da | to set the attribute number for. |
Definition at line 683 of file dict_util.c.
int dict_attr_parent_init | ( | fr_dict_attr_t ** | da_p, |
fr_dict_attr_t const * | parent | ||
) |
Initialise fields which depend on a parent attribute.
[in,out] | da_p | to initialise. |
[in] | parent | of the attribute. |
Definition at line 613 of file dict_util.c.
int dict_attr_type_init | ( | fr_dict_attr_t ** | da_p, |
fr_type_t | type | ||
) |
Initialise type specific fields within the dictionary attribute.
Call when the type of the attribute is known.
[in,out] | da_p | to set the type for. |
[in] | type | to set. |
Definition at line 519 of file dict_util.c.
bool dict_attr_valid | ( | fr_dict_attr_t * | da | ) |
Validate a new attribute definition.
[in] | da | to validate. |
Definition at line 603 of file dict_validate.c.
fr_dict_t * dict_by_da | ( | fr_dict_attr_t const * | da | ) |
Internal version of fr_dict_by_da.
Attempt to locate the protocol dictionary containing an attribute.
Definition at line 2536 of file dict_util.c.
fr_dict_t * dict_by_protocol_name | ( | char const * | name | ) |
Internal version of fr_dict_by_protocol_name.
Lookup a protocol by its name.
Definition at line 2508 of file dict_util.c.
fr_dict_t * dict_by_protocol_num | ( | unsigned int | num | ) |
Internal version of fr_dict_by_protocol_num.
Lookup a protocol by its number.
Definition at line 2522 of file dict_util.c.
fr_slen_t dict_by_protocol_substr | ( | fr_dict_attr_err_t * | err, |
fr_dict_t ** | out, | ||
fr_sbuff_t * | name, | ||
fr_dict_t const * | dict_def | ||
) |
Definition at line 2415 of file dict_util.c.
int dict_dependent_add | ( | fr_dict_t * | dict, |
char const * | dependent | ||
) |
Record a new dependency on a dictionary.
These are used to determine what is currently depending on a dictionary.
[in] | dict | to record dependency on. |
[in] | dependent | Either C src file, or another dictionary. |
Definition at line 3647 of file dict_util.c.
int dict_dependent_remove | ( | fr_dict_t * | dict, |
char const * | dependent | ||
) |
Decrement ref count for a dependent in a dictionary.
[in] | dict | to remove dependency from. |
[in] | dependent | Either C src, or another dictionary dependent. What depends on this dictionary. |
Definition at line 3706 of file dict_util.c.
int dict_dlopen | ( | fr_dict_t * | dict, |
char const * | name | ||
) |
Definition at line 3555 of file dict_util.c.
Check if a dictionary still has dependents.
[in] | dict | to check |
Definition at line 3738 of file dict_util.c.
int dict_protocol_add | ( | fr_dict_t * | dict | ) |
Add a protocol to the global protocol table.
Inserts a protocol into the global protocol table. Uses the root attributes of the dictionary for comparisons.
[in] | dict | of protocol we're inserting. |
Definition at line 1236 of file dict_util.c.
int dict_vendor_add | ( | fr_dict_t * | dict, |
char const * | name, | ||
unsigned int | num | ||
) |
Add a vendor to the dictionary.
Inserts a vendor entry into the vendor hash table. This must be done before adding attributes under a VSA.
[in] | dict | of protocol context we're operating in. If NULL the internal dictionary will be used. |
[in] | name | of the vendor. |
[in] | num | Vendor's Private Enterprise Number. |
Definition at line 1309 of file dict_util.c.
|
extern |
Top level structure containing global dictionary state.
Definition at line 46 of file dict_util.c.