]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
rename field to more correctly describe it's function
authorAlan T. DeKok <aland@freeradius.org>
Sat, 16 Aug 2025 14:00:35 +0000 (10:00 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 16 Aug 2025 14:00:35 +0000 (10:00 -0400)
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.

src/lib/util/dict.h
src/lib/util/dict_ext.c
src/lib/util/dict_ext.h
src/lib/util/dict_util.c
src/lib/util/struct.c

index a6f34409fa9263e47b9f9522949b97f99a53a56d..897afcf43df5862401294773487ba0459443ccf0 100644 (file)
@@ -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
index b8c115a6281c46b4ee48b0b7d6a110dc31010d3d..f9b35ba37babc47f5c049f484c1ef02ae1aa2a44 100644 (file)
@@ -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]          = {}
index 5c6317ba0b8f84ae0b7abbff62799ad71819f18c..acf8c1b6485223a54104b39a460a31f65a589bfe 100644 (file)
@@ -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
  *
index 5f98054bea96b45312cfe9da18b0c1fb19979fdb..cb6c60f25d869cf6cc309cc1745530501d8d0c5e 100644 (file)
@@ -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;
 
index b338194bc288aecb6366a4d6918351d39d791de2..51fa2025229dd66cb16587e40aeb872b7ce9c470 100644 (file)
@@ -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: