]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add da->vendor
authorAlan T. DeKok <aland@freeradius.org>
Mon, 13 Jan 2020 12:57:36 +0000 (07:57 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 13 Jan 2020 12:59:26 +0000 (07:59 -0500)
which is now a pointer to the vendor definition.

src/lib/util/dict.h
src/lib/util/dict_tokenize.c

index 59f6b7f9e295e564bf310f76fc682dddd2d7ed26..d24d16abc86d0fffc01bbe083b03d034c3f680a4 100644 (file)
@@ -111,6 +111,7 @@ struct dict_attr {
         */
        union {
                struct {
+                       fr_dict_attr_t const    *vendor;        //!< ancestor which has type FR_TYPE_VENDOR
                        fr_dict_attr_t const    **children;     //!< Children of this attribute.
                };
                struct {
@@ -332,15 +333,9 @@ static inline bool fr_dict_attr_is_top_level(fr_dict_attr_t const *da)
  */
 static inline uint32_t fr_dict_vendor_num_by_da(fr_dict_attr_t const *da)
 {
-       fr_dict_attr_t const *da_p = da;
+       if (!da->vendor) return 0;
 
-       while (da_p->parent) {
-               if (da_p->type == FR_TYPE_VENDOR) break;
-               da_p = da_p->parent;
-       }
-       if (da_p->type != FR_TYPE_VENDOR) return 0;
-
-       return da_p->attr;
+       return da->vendor->attr;
 }
 
 fr_dict_vendor_t const *fr_dict_vendor_by_da(fr_dict_attr_t const *da);
index fc9aadde3ea343b7d7d2a951a652191bc6673417..35cd26bbb7e7069953c36c523b01a8d078924e59 100644 (file)
@@ -758,6 +758,23 @@ static int dict_read_process_attribute(dict_tokenize_ctx_t *ctx, char **argv, in
                if (dict_gctx_push(ctx, da) < 0) return -1;
        }
 
+       /*
+        *      Point to the vendor definition.  Since ~90% of
+        *      attributes are VSAs, caching this pointer will help.
+        */
+       if (parent->type == FR_TYPE_VENDOR) {
+               fr_dict_attr_t *self;
+
+               memcpy(&self, &da, sizeof(self)); /* const issues */
+               self->vendor = parent;
+
+       } else if (parent->vendor) {
+               fr_dict_attr_t *self;
+
+               memcpy(&self, &da, sizeof(self)); /* const issues */
+               self->vendor = parent->vendor;
+       }
+
        return 0;
 }