From: Alan T. DeKok Date: Mon, 13 Jan 2020 12:57:36 +0000 (-0500) Subject: add da->vendor X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85a3cee9e08912ecde9f4101f37fa50e8cf37fc0;p=thirdparty%2Ffreeradius-server.git add da->vendor which is now a pointer to the vendor definition. --- diff --git a/src/lib/util/dict.h b/src/lib/util/dict.h index 59f6b7f9e29..d24d16abc86 100644 --- a/src/lib/util/dict.h +++ b/src/lib/util/dict.h @@ -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); diff --git a/src/lib/util/dict_tokenize.c b/src/lib/util/dict_tokenize.c index fc9aadde3ea..35cd26bbb7e 100644 --- a/src/lib/util/dict_tokenize.c +++ b/src/lib/util/dict_tokenize.c @@ -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; }