]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add alias for children of UNION
authorAlan T. DeKok <aland@freeradius.org>
Mon, 27 Oct 2025 21:35:57 +0000 (17:35 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 28 Oct 2025 13:07:53 +0000 (09:07 -0400)
so if we have:

foo  struct
  bar union
    baz  struct
            blag uint32

We do need to store that internally as the full hierarchy.

However, as a special case, we add an alias for each child:

foo struct
  bar union
    baz struct
    blag uint32

  baz ALIAS bar.baz
  blag ALIAS bar.blag

this lets the user type in something reasonable, i.e. without the
intermediate UNION.

src/lib/util/dict_tokenize.c
src/tests/unit/protocols/radius/union.txt

index 0a093f48c59057315a3489b0653a95866fe4e6c4..66b8fdbc2529222bb4d4edf9763415d3d93bd939 100644 (file)
@@ -1627,6 +1627,19 @@ static int dict_read_process_attribute(dict_tokenize_ctx_t *dctx, char **argv, i
                break;
        }
 
+       /*
+        *      While UNIONs are named, it's nicer to hide them.
+        *      Therefore we automatically add an ALIAS in the unions
+        *      parent, for the child in the union.
+        */
+       if (parent->type == FR_TYPE_UNION) {
+               fr_assert(parent->parent);
+
+               if (dict_attr_alias_add(parent->parent, da->name, da) < 0) {
+                       goto error;
+               }
+       }
+
        return 0;
 }
 
@@ -1901,7 +1914,7 @@ static int dict_read_process_define(dict_tokenize_ctx_t *dctx, char **argv, int
        }
 
        if (parent->type == FR_TYPE_UNION) {
-               fr_strerror_printf("Parent attribute %s is of type 'union', and can only have STRUCT children",
+               fr_strerror_printf("Parent attribute %s is of type 'union', and cannot use DEFINE for children",
                                   parent->name);
                return -1;
        }
index 7bdbf01c850628ca94bedae059730116e1b99dff..bec9babdda899619c383826d361562191af127a7 100644 (file)
@@ -1,3 +1,4 @@
+
 #
 #  UNION tests
 #
@@ -52,6 +53,15 @@ match fd 05 01 21 12
 encode-pair Test-Struct2 = { Data = { Sub-Struct = { Nested-Uint1 = 33, Nested-Uint2 = 18 } } }
 match fd 05 01 21 12
 
+#
+#  Skip the UNION
+#
+pair Test-Struct2 = { Sub-Struct = { Nested-Uint1 = 33, Nested-Uint2 = 18 } }
+match Test-Struct2 = { Data = { Sub-Struct = { Nested-Uint1 = 33, Nested-Uint2 = 18 } } }
+
+encode-pair Test-Struct2 = { Sub-Struct = { Nested-Uint1 = 33, Nested-Uint2 = 18 } }
+match fd 05 01 21 12
+
 #
 #  Wrong Key-Field - it gets over-written
 #
@@ -71,4 +81,4 @@ match fd 05 02 43 41
 #
 
 count
-match 24
+match 28