]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
skip internal attributes when encoding nested structs
authorAlan T. DeKok <aland@freeradius.org>
Mon, 21 Mar 2022 22:27:53 +0000 (18:27 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 21 Mar 2022 22:27:53 +0000 (18:27 -0400)
We really also want to skip any attributes which aren't parented
from the enclosing structure.  But doing so means that any child
structures which depend on "key" will likely get skipped, too.

So for now we just do this.

src/lib/util/struct.c

index 372f49f92abf8add5eb674be721d644af2ea4812..8f58f7b933aedbb7d5e4d1865814c47784262ccf 100644 (file)
@@ -477,6 +477,23 @@ static int8_t pair_sort_increasing(void const *a, void const *b)
        return CMP_PREFER_SMALLER(my_a->da->attr, my_b->da->attr);
 }
 
+static void *struct_next_encodable(fr_dlist_head_t *list, void *to_eval, void *uctx)
+{
+       fr_pair_t       *c;
+       fr_dict_attr_t  *parent = talloc_get_type_abort(uctx, fr_dict_attr_t);
+
+       if (!to_eval) return NULL;
+
+       for (c = to_eval; c; c = fr_dlist_next(list, c)) {
+               PAIR_VERIFY(c);
+
+               if (c->da->dict != parent->dict || c->da->flags.internal) continue;
+               break;
+       }
+
+       return c;
+}
+
 ssize_t fr_struct_to_network(fr_dbuff_t *dbuff,
                             fr_da_stack_t *da_stack, unsigned int depth,
                             fr_dcursor_t *parent_cursor, void *encode_ctx,
@@ -513,7 +530,7 @@ ssize_t fr_struct_to_network(fr_dbuff_t *dbuff,
                fr_pair_t *sorted = fr_dcursor_current(parent_cursor); /* NOT const */
 
                fr_pair_list_sort(&sorted->vp_group, pair_sort_increasing);
-               fr_pair_dcursor_init(&child_cursor, &sorted->vp_group);
+               fr_pair_dcursor_iter_init(&child_cursor, &sorted->vp_group, struct_next_encodable, parent);
 
                /*
                 *      Build the da_stack for the new structure.