From: Alan T. DeKok Date: Sat, 16 Aug 2025 14:00:35 +0000 (-0400) Subject: rename field to more correctly describe it's function X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07c8ae14fb574aba6b7f294a3545cdd48c5b7334;p=thirdparty%2Ffreeradius-server.git rename field to more correctly describe it's function arguably we should also use dict_ext instead of hard-coded thing, but that involves a little more work which we will avoid for now. --- diff --git a/src/lib/util/dict.h b/src/lib/util/dict.h index a6f34409fa9..897afcf43df 100644 --- a/src/lib/util/dict.h +++ b/src/lib/util/dict.h @@ -223,7 +223,7 @@ struct dict_attr_s { * @note New extension structures should also be added to the appropriate table in dict_ext.c */ typedef enum { - FR_DICT_ENUM_EXT_UNION_REF = 0, //!< Reference to a union/subs-struct. + FR_DICT_ENUM_EXT_KEY_CHILD_REF = 0, //!< Reference to a child associated with this key FR_DICT_ENUM_EXT_MAX } fr_dict_enum_ext_t; @@ -239,7 +239,7 @@ typedef struct { uint8_t ext[FR_DICT_ENUM_EXT_MAX]; //!< Extensions to the dictionary attribute. - fr_dict_attr_t const *child_struct[]; //!< for key fields + fr_dict_attr_t const *key_child_ref[]; //!< for key fields } fr_dict_enum_value_t CC_HINT(aligned(FR_EXT_ALIGNMENT)); /** Private enterprise diff --git a/src/lib/util/dict_ext.c b/src/lib/util/dict_ext.c index b8c115a6281..f9b35ba37ba 100644 --- a/src/lib/util/dict_ext.c +++ b/src/lib/util/dict_ext.c @@ -77,28 +77,28 @@ static int fr_dict_attr_ext_enumv_copy(UNUSED int ext, for (enumv = fr_hash_table_iter_init(src_ext->value_by_name, &iter); enumv; enumv = fr_hash_table_iter_next(src_ext->value_by_name, &iter)) { - fr_dict_attr_t *child_struct; + fr_dict_attr_t *key_child_ref; if (!has_child) { - child_struct = NULL; + key_child_ref = NULL; } else { - fr_dict_t *dict = dict_by_da(enumv->child_struct[0]); + fr_dict_t *dict = dict_by_da(enumv->key_child_ref[0]); /* - * Copy the child_struct, and all if it's children recursively. + * Copy the key_child_ref, and all if it's children recursively. */ - child_struct = dict_attr_acopy(dict->pool, enumv->child_struct[0], NULL); - if (!child_struct) return -1; + key_child_ref = dict_attr_acopy(dict->pool, enumv->key_child_ref[0], NULL); + if (!key_child_ref) return -1; - child_struct->parent = da_dst; /* we need to re-parent this attribute */ + key_child_ref->parent = da_dst; /* we need to re-parent this attribute */ - if (dict_attr_children(enumv->child_struct[0])) { - if (dict_attr_acopy_children(dict, child_struct, enumv->child_struct[0]) < 0) return -1; + if (dict_attr_children(enumv->key_child_ref[0])) { + if (dict_attr_acopy_children(dict, key_child_ref, enumv->key_child_ref[0]) < 0) return -1; } } if (dict_attr_enum_add_name(da_dst, enumv->name, enumv->value, - true, true, child_struct) < 0) return -1; + true, true, key_child_ref) < 0) return -1; } return 0; @@ -264,7 +264,7 @@ fr_ext_t const fr_dict_attr_ext_def = { }; static fr_table_num_ordered_t const dict_enum_ext_table[] = { - { L("union_ref"), FR_DICT_ENUM_EXT_UNION_REF } + { L("key_child_ref"), FR_DICT_ENUM_EXT_KEY_CHILD_REF } }; static size_t dict_enum_ext_table_len = NUM_ELEMENTS(dict_enum_ext_table); @@ -282,8 +282,8 @@ fr_ext_t const fr_dict_enum_ext_def = { .name_table_len = &dict_enum_ext_table_len, .max = FR_DICT_ENUM_EXT_MAX, .info = (fr_ext_info_t[]){ /* -Wgnu-flexible-array-initializer */ - [FR_DICT_ENUM_EXT_UNION_REF] = { - .min = sizeof(fr_dict_enum_ext_union_ref_t), + [FR_DICT_ENUM_EXT_KEY_CHILD_REF] = { + .min = sizeof(fr_dict_enum_ext_key_child_ref_t), .can_copy = true }, [FR_DICT_ENUM_EXT_MAX] = {} diff --git a/src/lib/util/dict_ext.h b/src/lib/util/dict_ext.h index 5c6317ba0b8..acf8c1b6485 100644 --- a/src/lib/util/dict_ext.h +++ b/src/lib/util/dict_ext.h @@ -122,8 +122,8 @@ typedef struct { * */ typedef struct { - fr_dict_attr_t const *union_ref; //!< The union da this value points into. -} fr_dict_enum_ext_union_ref_t; + fr_dict_attr_t const *ref; //!< the child structure referenced by this value of key +} fr_dict_enum_ext_key_child_ref_t; /** @name Add extension structures to attributes * diff --git a/src/lib/util/dict_util.c b/src/lib/util/dict_util.c index 5f98054bea9..cb6c60f25d8 100644 --- a/src/lib/util/dict_util.c +++ b/src/lib/util/dict_util.c @@ -1828,7 +1828,7 @@ int fr_dict_attr_add_name_only(fr_dict_t *dict, fr_dict_attr_t const *parent, int dict_attr_enum_add_name(fr_dict_attr_t *da, char const *name, fr_value_box_t const *value, bool coerce, bool takes_precedence, - fr_dict_attr_t const *child_struct) + fr_dict_attr_t const *key_child_ref) { size_t len; fr_dict_enum_value_t *enumv = NULL; @@ -1854,11 +1854,27 @@ int dict_attr_enum_add_name(fr_dict_attr_t *da, char const *name, /* * If the parent isn't a key field, then we CANNOT add a child struct. */ - if (!fr_dict_attr_is_key_field(da) && child_struct) { - fr_strerror_const("Child structures cannot be defined for VALUEs which are not for 'key' attributes"); + if (!fr_dict_attr_is_key_field(da) && key_child_ref) { + fr_strerror_const("Child attributes cannot be defined for VALUEs which are not 'key' attributes"); return -1; } +#if 0 + /* + * Commented out becuase of share/dictionary/dhcpv6/dictionary.rfc6607. + * + * That dictionary defines a value which is associated with a zero-sized child. + * In order to enforce this check, we need to support zero-sized structures. + * + * Perhaps this can be done as a special case after we convert to UNIONs? Because then + * we can allow ATTRIBUTE Global-VPN 255 struct[0]. + */ + if (fr_dict_attr_is_key_field(da) && !key_child_ref) { + fr_strerror_const("Child attribute must be defined for VALUEs associated with a 'key' attribute"); + return -1; + } +#endif + if (fr_type_is_structural(da->type) || (da->type == FR_TYPE_STRING)) { fr_strerror_printf("Enumeration names cannot be added for data type '%s'", fr_type_to_str(da->type)); return -1; @@ -1898,7 +1914,7 @@ int dict_attr_enum_add_name(fr_dict_attr_t *da, char const *name, * Allocate a structure to map between * the name and value. */ - enumv = talloc_zero_size(da, sizeof(fr_dict_enum_value_t) + sizeof(enumv->child_struct[0]) * fr_dict_attr_is_key_field(da)); + enumv = talloc_zero_size(da, sizeof(fr_dict_enum_value_t) + sizeof(enumv->key_child_ref[0]) * fr_dict_attr_is_key_field(da)); if (!enumv) { oom: fr_strerror_printf("%s: Out of memory", __FUNCTION__); @@ -1909,7 +1925,7 @@ int dict_attr_enum_add_name(fr_dict_attr_t *da, char const *name, enumv->name = talloc_typed_strdup(enumv, name); enumv->name_len = len; - if (child_struct) enumv->child_struct[0] = child_struct; + if (key_child_ref) enumv->key_child_ref[0] = key_child_ref; enum_value = fr_value_box_alloc(enumv, da->type, NULL); if (!enum_value) goto oom; diff --git a/src/lib/util/struct.c b/src/lib/util/struct.c index b338194bc28..51fa2025229 100644 --- a/src/lib/util/struct.c +++ b/src/lib/util/struct.c @@ -348,7 +348,7 @@ ssize_t fr_struct_from_network(TALLOC_CTX *ctx, fr_pair_list_t *out, } enumv = fr_dict_enum_by_value(key_vp->da, &key_vp->data); - if (enumv) child = enumv->child_struct[0]; + if (enumv) child = enumv->key_child_ref[0]; if (!child) { unknown_child: