23 RCSID(
"$Id: 312858ec7b631038798ee2c34ca4ced2a0ad3465 $")
25 #include <freeradius-devel/util/dict_priv.h>
45 uint32_t shift_is_root, shift_internal;
46 uint32_t shift_array, shift_has_value;
58 #define SET_FLAG(_flag) do { shift_ ## _flag = 1 << ++bit; if (flags->_flag) all_flags |= (1 << bit); } while (0)
67 #define FORBID_OTHER_FLAGS(_flag) do { if (all_flags & ~shift_ ## _flag) { fr_strerror_printf("The '" STRINGIFY(_flag) "' flag cannot be used with any other flag"); return false; } } while (0)
68 #define ALLOW_FLAG(_flag) do { all_flags &= ~shift_ ## _flag; } while (0)
85 fr_strerror_const(
"The 'unknown' flag cannot be set for attributes in the dictionary.");
146 "of type 'integer'");
160 fr_strerror_const(
"The 'key' and 'length' flags cannot be used with any other flags.");
171 fr_strerror_const(
"Invalid type (not 'key' field or 'bit' field) for extra flag.");
323 if ((flags->
length != 1) &&
326 fr_strerror_const(
"The 'length' flag can only be used for attributes of type 'vendor' with lengths of 1,2 or 4");
352 if ((flags->
length != 1) &&
355 fr_strerror_const(
"The 'length' flag can only be used for attributes of type 'tlv' with lengths of 1,2 or 4");
366 for (v =
parent; v != NULL; v = v->parent) {
386 flags->
length = v->flags.length;
408 if (flags->
length > 253) {
432 }
else if (!flags->
extra) {
434 fr_strerror_const(
"The 'format=' flag can only be used with attributes of type 'tlv'");
441 fr_strerror_const(
"The 'format=' flag can only be used with attributes of type size 1,2 or 4");
470 fr_strerror_const(
"Variable-sized fields cannot be used within a 'struct' which is 'array'");
507 "numbered consecutively %u.",
515 if (!sibling->flags.length && !sibling->flags.is_known_width) {
516 fr_strerror_const(
"No other field can follow a struct MEMBER which is variable sized");
523 if (sibling->flags.array) {
534 for (i = 1; i < *attr; i++) {
544 fr_strerror_printf(
"Duplicate key attributes '%s' and '%s' in 'struct' type attribute %s are forbidden",
638 if (v->type !=
type) {
639 fr_strerror_printf(
"Conflicting type (asked %s, found %s) for re-definition for attribute %s",
651 if (memcmp(&cmp, flags,
sizeof(*flags)) != 0) {
659 *attr = ++
mutable->last_child_attr;
661 }
else if (*attr < 0) {
662 fr_strerror_printf(
"ATTRIBUTE number %i is invalid, must be greater than zero", *attr);
665 }
else if ((
unsigned int) *attr > mutable->last_child_attr) {
666 mutable->last_child_attr = *attr;
675 if ((uint64_t) *attr >= (((uint64_t)1) << (8 *
parent->flags.type_size))) flags->
internal =
true;
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
size_t type
Length of type data.
unsigned int name_only
this attribute should always be referred to by name, not by number
unsigned int has_value
Has a value.
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.
unsigned int is_root
Is root of a dictionary.
@ FLAG_LENGTH_UINT8
string / octets type is prefixed by uint8 of length
@ FLAG_LENGTH_UINT16
string / octets type is prefixed by uint16 of length
@ FLAG_KEY_FIELD
this is a key field for a subsequent struct
@ FLAG_BIT_FIELD
bit field inside of a struct
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.
unsigned int array
Pack multiples into 1 attr.
unsigned int extra
really "subtype is used by dict, not by protocol"
unsigned int internal
Internal attribute, should not be received in protocol packets, should not be encoded.
uint8_t type_size
For TLV2 and root attributes.
size_t length
Length of length data.
unsigned int is_known_width
is treated as if it has a known width for structs
ssize_t fr_dict_valid_name(char const *name, ssize_t len)
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.
#define fr_dict_attr_is_key_field(_da)
uint8_t subtype
protocol-specific values, OR key fields
uint8_t length
length of the attribute
unsigned int counter
integer attribute is actually an impulse / counter
unsigned int is_unknown
This dictionary attribute is ephemeral and not part of the main dictionary.
Values of the encryption flags.
bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent, char const *name, int *attr, fr_type_t type, fr_dict_attr_flags_t *flags)
Validate a set of flags.
#define ALLOW_FLAG(_flag)
#define FORBID_OTHER_FLAGS(_flag)
bool dict_attr_fields_valid(fr_dict_t *dict, fr_dict_attr_t const *parent, char const *name, int *attr, fr_type_t type, fr_dict_attr_flags_t *flags)
Validate a new attribute definition.
@ FR_TYPE_TIME_DELTA
A period of time measured in nanoseconds.
@ FR_TYPE_FLOAT32
Single precision floating point.
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
@ FR_TYPE_TLV
Contains nested attributes.
@ FR_TYPE_ETHERNET
48 Bit Mac-Address.
@ FR_TYPE_IPV6_PREFIX
IPv6 Prefix.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_NULL
Invalid (uninitialised) attribute type.
@ FR_TYPE_UINT16
16 Bit unsigned integer.
@ FR_TYPE_DATE
Unix time stamp, always has value >2^31.
@ FR_TYPE_COMBO_IP_PREFIX
IPv4 or IPv6 address prefix depending on length.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_STRUCT
like TLV, but without T or L, and fixed-width children
@ FR_TYPE_INT32
32 Bit signed integer.
@ FR_TYPE_VENDOR
Attribute that represents a vendor in the attribute tree.
@ FR_TYPE_UINT64
64 Bit unsigned integer.
@ FR_TYPE_IPV6_ADDR
128 Bit IPv6 Address.
@ FR_TYPE_IPV4_PREFIX
IPv4 Prefix.
@ FR_TYPE_BOOL
A truth value.
@ FR_TYPE_SIZE
Unsigned integer capable of representing any memory address on the local system.
@ FR_TYPE_VSA
Vendor-Specific, for RADIUS attribute 26.
@ FR_TYPE_COMBO_IP_ADDR
IPv4 or IPv6 address depending on length.
@ FR_TYPE_IFID
Interface ID.
@ FR_TYPE_OCTETS
Raw octets.
@ FR_TYPE_FLOAT64
Double precision floating point.
static size_t array[MY_ARRAY_SIZE]
fr_aka_sim_id_type_t type
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
#define fr_strerror_const(_msg)
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
#define fr_type_is_variable_size(_x)
#define fr_type_is_signed(_x)
#define fr_type_is_leaf(_x)
#define fr_type_is_integer(_x)
#define FR_TYPE_FIXED_SIZE
size_t fr_value_box_network_length(fr_value_box_t const *value)
Get the size of the value held by the fr_value_box_t.
#define fr_value_box_init(_vb, _type, _enumv, _tainted)
Initialise a fr_value_box_t.