2 * dict.c Routines to read the dictionary file.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * Copyright 2000,2006 The FreeRADIUS server project
23 #include <freeradius-devel/ident.h>
26 #include <freeradius-devel/libradius.h>
34 #ifdef HAVE_SYS_STAT_H
38 #define DICT_VALUE_MAX_NAME_LEN (128)
39 #define DICT_VENDOR_MAX_NAME_LEN (128)
40 #define DICT_ATTR_MAX_NAME_LEN (128)
42 static fr_hash_table_t *vendors_byname = NULL;
43 static fr_hash_table_t *vendors_byvalue = NULL;
45 static fr_hash_table_t *attributes_byname = NULL;
46 static fr_hash_table_t *attributes_byvalue = NULL;
48 static fr_hash_table_t *values_byvalue = NULL;
49 static fr_hash_table_t *values_byname = NULL;
51 static DICT_ATTR *dict_base_attrs[256];
54 * For faster HUP's, we cache the stat information for
55 * files we've $INCLUDEd
57 typedef struct dict_stat_t {
58 struct dict_stat_t *next;
63 static char *stat_root_dir = NULL;
64 static char *stat_root_file = NULL;
66 static dict_stat_t *stat_head = NULL;
67 static dict_stat_t *stat_tail = NULL;
69 typedef struct value_fixup_t {
70 char attrstr[DICT_ATTR_MAX_NAME_LEN];
72 struct value_fixup_t *next;
77 * So VALUEs in the dictionary can have forward references.
79 static value_fixup_t *value_fixup = NULL;
81 static const FR_NAME_NUMBER type_table[] = {
82 { "integer", PW_TYPE_INTEGER },
83 { "string", PW_TYPE_STRING },
84 { "ipaddr", PW_TYPE_IPADDR },
85 { "date", PW_TYPE_DATE },
86 { "abinary", PW_TYPE_ABINARY },
87 { "octets", PW_TYPE_OCTETS },
88 { "ifid", PW_TYPE_IFID },
89 { "ipv6addr", PW_TYPE_IPV6ADDR },
90 { "ipv6prefix", PW_TYPE_IPV6PREFIX },
91 { "byte", PW_TYPE_BYTE },
92 { "short", PW_TYPE_SHORT },
93 { "ether", PW_TYPE_ETHERNET },
94 { "combo-ip", PW_TYPE_COMBO_IP },
95 { "tlv", PW_TYPE_TLV },
96 { "signed", PW_TYPE_SIGNED },
97 { "extended", PW_TYPE_EXTENDED },
98 { "extended-flags", PW_TYPE_EXTENDED_FLAGS },
99 { "evs", PW_TYPE_EVS },
100 { "uint8", PW_TYPE_BYTE },
101 { "uint16", PW_TYPE_SHORT },
102 { "uint32", PW_TYPE_INTEGER },
103 { "int32", PW_TYPE_SIGNED },
111 #define MAX_TLV_NEST (4)
115 * 8 bits for nested TLV 1
116 * 8 bits for nested TLV 2
117 * 5 bits for nested TLV 3
118 * 3 bits for nested TLV 4
120 const int fr_attr_max_tlv = MAX_TLV_NEST;
121 const int fr_attr_shift[MAX_TLV_NEST + 1] = {
125 const int fr_attr_mask[MAX_TLV_NEST + 1] = {
126 0xff, 0xff, 0xff, 0x1f, 0x07
131 * Create the hash of the name.
133 * We copy the hash function here because it's substantially faster.
135 #define FNV_MAGIC_INIT (0x811c9dc5)
136 #define FNV_MAGIC_PRIME (0x01000193)
138 static uint32_t dict_hashname(const char *name)
140 uint32_t hash = FNV_MAGIC_INIT;
143 for (p = name; *p != '\0'; p++) {
144 int c = *(const unsigned char *) p;
145 if (isalpha(c)) c = tolower(c);
147 hash *= FNV_MAGIC_PRIME;
148 hash ^= (uint32_t ) (c & 0xff);
156 * Hash callback functions.
158 static uint32_t dict_attr_name_hash(const void *data)
160 return dict_hashname(((const DICT_ATTR *)data)->name);
163 static int dict_attr_name_cmp(const void *one, const void *two)
165 const DICT_ATTR *a = one;
166 const DICT_ATTR *b = two;
168 return strcasecmp(a->name, b->name);
171 static uint32_t dict_attr_value_hash(const void *data)
174 const DICT_ATTR *attr = data;
176 hash = fr_hash(&attr->vendor, sizeof(attr->vendor));
177 return fr_hash_update(&attr->attr, sizeof(attr->attr), hash);
180 static int dict_attr_value_cmp(const void *one, const void *two)
182 const DICT_ATTR *a = one;
183 const DICT_ATTR *b = two;
185 if (a->vendor < b->vendor) return -1;
186 if (a->vendor > b->vendor) return +1;
188 return a->attr - b->attr;
191 static uint32_t dict_vendor_name_hash(const void *data)
193 return dict_hashname(((const DICT_VENDOR *)data)->name);
196 static int dict_vendor_name_cmp(const void *one, const void *two)
198 const DICT_VENDOR *a = one;
199 const DICT_VENDOR *b = two;
201 return strcasecmp(a->name, b->name);
204 static uint32_t dict_vendor_value_hash(const void *data)
206 return fr_hash(&(((const DICT_VENDOR *)data)->vendorpec),
207 sizeof(((const DICT_VENDOR *)data)->vendorpec));
210 static int dict_vendor_value_cmp(const void *one, const void *two)
212 const DICT_VENDOR *a = one;
213 const DICT_VENDOR *b = two;
215 return a->vendorpec - b->vendorpec;
218 static uint32_t dict_value_name_hash(const void *data)
221 const DICT_VALUE *dval = data;
223 hash = dict_hashname(dval->name);
224 hash = fr_hash_update(&dval->vendor, sizeof(dval->vendor), hash);
225 return fr_hash_update(&dval->attr, sizeof(dval->attr), hash);
228 static int dict_value_name_cmp(const void *one, const void *two)
231 const DICT_VALUE *a = one;
232 const DICT_VALUE *b = two;
234 rcode = a->attr - b->attr;
235 if (rcode != 0) return rcode;
237 rcode = a->vendor - b->vendor;
238 if (rcode != 0) return rcode;
240 return strcasecmp(a->name, b->name);
243 static uint32_t dict_value_value_hash(const void *data)
246 const DICT_VALUE *dval = data;
248 hash = fr_hash(&dval->attr, sizeof(dval->attr));
249 hash = fr_hash_update(&dval->vendor, sizeof(dval->vendor), hash);
250 return fr_hash_update(&dval->value, sizeof(dval->value), hash);
253 static int dict_value_value_cmp(const void *one, const void *two)
256 const DICT_VALUE *a = one;
257 const DICT_VALUE *b = two;
259 if (a->vendor < b->vendor) return -1;
260 if (a->vendor > b->vendor) return +1;
262 rcode = a->attr - b->attr;
263 if (rcode != 0) return rcode;
265 return a->value - b->value;
270 * Free the list of stat buffers
272 static void dict_stat_free(void)
274 dict_stat_t *this, *next;
277 stat_root_dir = NULL;
278 free(stat_root_file);
279 stat_root_file = NULL;
286 for (this = stat_head; this != NULL; this = next) {
292 stat_head = stat_tail = NULL;
297 * Add an entry to the list of stat buffers.
299 static void dict_stat_add(const char *name, const struct stat *stat_buf)
303 this = malloc(sizeof(*this));
305 memset(this, 0, sizeof(*this));
307 this->name = strdup(name);
308 this->mtime = stat_buf->st_mtime;
311 stat_head = stat_tail = this;
313 stat_tail->next = this;
320 * See if any dictionaries have changed. If not, don't
323 static int dict_stat_check(const char *root_dir, const char *root_file)
328 if (!stat_root_dir) return 0;
329 if (!stat_root_file) return 0;
331 if (strcmp(root_dir, stat_root_dir) != 0) return 0;
332 if (strcmp(root_file, stat_root_file) != 0) return 0;
334 if (!stat_head) return 0; /* changed, reload */
336 for (this = stat_head; this != NULL; this = this->next) {
337 if (stat(this->name, &buf) < 0) return 0;
339 if (buf.st_mtime != this->mtime) return 0;
345 typedef struct fr_pool_t {
348 struct fr_pool_t *page_free;
349 struct fr_pool_t *page_next;
352 #define FR_POOL_SIZE (32768)
353 #define FR_ALLOC_ALIGN (8)
355 static fr_pool_t *dict_pool = NULL;
357 static fr_pool_t *fr_pool_create(void)
359 fr_pool_t *fp = malloc(FR_POOL_SIZE);
361 if (!fp) return NULL;
363 memset(fp, 0, FR_POOL_SIZE);
365 fp->page_end = ((uint8_t *) fp) + FR_POOL_SIZE;
366 fp->free_ptr = ((uint8_t *) fp) + sizeof(*fp);
368 fp->page_next = NULL;
372 static void fr_pool_delete(fr_pool_t **pfp)
374 fr_pool_t *fp, *next;
376 if (!pfp || !*pfp) return;
378 for (fp = *pfp; fp != NULL; fp = next) {
379 next = fp->page_next;
380 fp->page_next = NULL;
387 static void *fr_pool_alloc(size_t size)
391 if (size == 0) return NULL;
393 if (size > 256) return NULL; /* shouldn't happen */
396 dict_pool = fr_pool_create();
397 if (!dict_pool) return NULL;
400 if ((size & (FR_ALLOC_ALIGN - 1)) != 0) {
401 size += FR_ALLOC_ALIGN - (size & (FR_ALLOC_ALIGN - 1));
404 if ((((uint8_t *) dict_pool->page_free->free_ptr) + size) > (uint8_t *) dict_pool->page_free->page_end) {
405 dict_pool->page_free->page_next = fr_pool_create();
406 if (!dict_pool->page_free->page_next) return NULL;
407 dict_pool->page_free = dict_pool->page_free->page_next;
410 ptr = dict_pool->page_free->free_ptr;
411 dict_pool->page_free->free_ptr = ((uint8_t *) dict_pool->page_free->free_ptr) + size;
417 static void fr_pool_free(UNUSED void *ptr)
420 * Place-holder for later code.
425 * Free the dictionary_attributes and dictionary_values lists.
432 fr_hash_table_free(vendors_byname);
433 fr_hash_table_free(vendors_byvalue);
434 vendors_byname = NULL;
435 vendors_byvalue = NULL;
437 fr_hash_table_free(attributes_byname);
438 fr_hash_table_free(attributes_byvalue);
439 attributes_byname = NULL;
440 attributes_byvalue = NULL;
442 fr_hash_table_free(values_byname);
443 fr_hash_table_free(values_byvalue);
444 values_byname = NULL;
445 values_byvalue = NULL;
447 memset(dict_base_attrs, 0, sizeof(dict_base_attrs));
449 fr_pool_delete(&dict_pool);
456 * Add vendor to the list.
458 int dict_addvendor(const char *name, unsigned int value)
463 if (value > FR_MAX_VENDOR) {
464 fr_strerror_printf("dict_addvendor: Cannot handle vendor ID larger than 2^24");
468 if ((length = strlen(name)) >= DICT_VENDOR_MAX_NAME_LEN) {
469 fr_strerror_printf("dict_addvendor: vendor name too long");
473 if ((dv = fr_pool_alloc(sizeof(*dv) + length)) == NULL) {
474 fr_strerror_printf("dict_addvendor: out of memory");
478 strcpy(dv->name, name);
479 dv->vendorpec = value;
480 dv->type = dv->length = 1; /* defaults */
482 if (!fr_hash_table_insert(vendors_byname, dv)) {
485 old_dv = fr_hash_table_finddata(vendors_byname, dv);
487 fr_strerror_printf("dict_addvendor: Failed inserting vendor name %s", name);
490 if (old_dv->vendorpec != dv->vendorpec) {
491 fr_strerror_printf("dict_addvendor: Duplicate vendor name %s", name);
496 * Already inserted. Discard the duplicate entry.
503 * Insert the SAME pointer (not free'd when this table is
504 * deleted), into another table.
506 * We want this behaviour because we want OLD names for
507 * the attributes to be read from the configuration
508 * files, but when we're printing them, (and looking up
509 * by value) we want to use the NEW name.
511 if (!fr_hash_table_replace(vendors_byvalue, dv)) {
512 fr_strerror_printf("dict_addvendor: Failed inserting vendor %s",
521 * Add an attribute to the dictionary.
523 int dict_addattr(const char *name, int attr, unsigned int vendor, int type,
527 static int max_attr = 0;
530 namelen = strlen(name);
531 if (namelen >= DICT_ATTR_MAX_NAME_LEN) {
532 fr_strerror_printf("dict_addattr: attribute name too long");
537 * If the attr is '-1', that means use a pre-existing
538 * one (if it already exists). If one does NOT already exist,
539 * then create a new attribute, with a non-conflicting value,
543 if (dict_attrbyname(name)) {
544 return 0; /* exists, don't add it again */
549 } else if (vendor == 0) {
553 if (attr > max_attr) {
559 * Additional checks for extended attributes.
561 if (flags.extended || flags.extended_flags || flags.evs) {
563 fr_strerror_printf("dict_addattr: VSAs cannot use the \"extended\" or \"evs\" attribute formats.");
566 vendor = VENDORPEC_EXTENDED;
572 || (flags.encrypt != FLAG_ENCRYPT_NONE)) {
573 fr_strerror_printf("dict_addattr: The \"extended\" attributes MUST NOT have any flags set.");
579 if (!(flags.extended || flags.extended_flags)) {
580 fr_strerror_printf("dict_addattr: Attributes of type \"evs\" MUST have a parent of type \"extended\"");
584 if (vendor <= FR_MAX_VENDOR) {
585 fr_strerror_printf("dict_addattr: Attribute of type \"evs\" fails internal sanity check");
591 fr_strerror_printf("dict_addattr: ATTRIBUTE has invalid number (less than zero)");
595 if (flags.has_tlv && flags.length) {
596 fr_strerror_printf("TLVs cannot have a fixed length");
600 if (vendor && (vendor != VENDORPEC_EXTENDED)) {
602 static DICT_VENDOR *last_vendor = NULL;
604 if (flags.has_tlv && (flags.encrypt != FLAG_ENCRYPT_NONE)) {
605 fr_strerror_printf("TLV's cannot be encrypted");
609 if (flags.is_tlv && flags.has_tag) {
610 fr_strerror_printf("Sub-TLV's cannot have a tag");
614 if (flags.has_tlv && flags.has_tag) {
615 fr_strerror_printf("TLV's cannot have a tag");
620 * Most ATTRIBUTEs are bunched together by
621 * VENDOR. We can save a lot of lookups on
622 * dictionary initialization by caching the last
626 ((vendor & (FR_MAX_VENDOR - 1)) == last_vendor->vendorpec)) {
630 * Ignore the high byte (sigh)
632 dv = dict_vendorbyvalue(vendor & (FR_MAX_VENDOR - 1));
637 * If the vendor isn't defined, die.
640 fr_strerror_printf("dict_addattr: Unknown vendor %u",
646 * FIXME: Switch over dv->type, and limit things
649 if ((dv->type == 1) && (attr >= 256) && !flags.is_tlv) {
650 fr_strerror_printf("dict_addattr: ATTRIBUTE has invalid number (larger than 255).");
652 } /* else 256..65535 are allowed */
655 * Set the extended flags as appropriate.
657 if (vendor > FR_MAX_VENDOR) {
660 myattr = (vendor >> 24) & 0xff;
661 myattr |= PW_VENDOR_SPECIFIC << 8;
663 da = dict_attrbyvalue(myattr, VENDORPEC_EXTENDED);
665 fr_strerror_printf("dict_addattr: ATTRIBUTE refers to unknown \"evs\" type.");
668 flags.extended = da->flags.extended;
669 flags.extended_flags = da->flags.extended_flags;
670 flags.evs = da->flags.evs;
674 * <sigh> Alvarion, being *again* a horribly
675 * broken vendor, has re-used the WiMAX format in
676 * their proprietary vendor space. This re-use
677 * means that there are *multiple* conflicting
678 * Alvarion dictionaries.
680 flags.wimax = dv->flags;
684 * Create a new attribute for the list
686 if ((da = fr_pool_alloc(sizeof(*da) + namelen)) == NULL) {
687 fr_strerror_printf("dict_addattr: out of memory");
691 memcpy(da->name, name, namelen);
692 da->name[namelen] = '\0';
699 * Insert the attribute, only if it's not a duplicate.
701 if (!fr_hash_table_insert(attributes_byname, da)) {
705 * If the attribute has identical number, then
706 * ignore the duplicate.
708 a = fr_hash_table_finddata(attributes_byname, da);
709 if (a && (strcasecmp(a->name, da->name) == 0)) {
710 if (a->attr != da->attr) {
711 fr_strerror_printf("dict_addattr: Duplicate attribute name %s", name);
717 * Same name, same vendor, same attr,
718 * maybe the flags and/or type is
719 * different. Let the new value
720 * over-ride the old one.
725 fr_hash_table_delete(attributes_byvalue, a);
727 if (!fr_hash_table_replace(attributes_byname, da)) {
728 fr_strerror_printf("dict_addattr: Internal error storing attribute %s", name);
735 * Insert the SAME pointer (not free'd when this entry is
736 * deleted), into another table.
738 * We want this behaviour because we want OLD names for
739 * the attributes to be read from the configuration
740 * files, but when we're printing them, (and looking up
741 * by value) we want to use the NEW name.
743 if (!fr_hash_table_replace(attributes_byvalue, da)) {
744 fr_strerror_printf("dict_addattr: Failed inserting attribute name %s", name);
748 if (!vendor && (attr > 0) && (attr < 256)) {
749 dict_base_attrs[attr] = da;
757 * Add a value for an attribute to the dictionary.
759 int dict_addvalue(const char *namestr, const char *attrstr, int value)
765 static DICT_ATTR *last_attr = NULL;
768 fr_strerror_printf("dict_addvalue: empty names are not permitted");
772 if ((length = strlen(namestr)) >= DICT_VALUE_MAX_NAME_LEN) {
773 fr_strerror_printf("dict_addvalue: value name too long");
777 if ((dval = fr_pool_alloc(sizeof(*dval) + length)) == NULL) {
778 fr_strerror_printf("dict_addvalue: out of memory");
781 memset(dval, 0, sizeof(*dval));
783 strcpy(dval->name, namestr);
787 * Most VALUEs are bunched together by ATTRIBUTE. We can
788 * save a lot of lookups on dictionary initialization by
789 * caching the last attribute.
791 if (last_attr && (strcasecmp(attrstr, last_attr->name) == 0)) {
794 dattr = dict_attrbyname(attrstr);
799 * Remember which attribute is associated with this
800 * value, if possible.
803 if (dattr->flags.has_value_alias) {
804 fr_strerror_printf("dict_addvalue: Cannot add VALUE for ATTRIBUTE \"%s\": It already has a VALUE-ALIAS", attrstr);
808 dval->attr = dattr->attr;
809 dval->vendor = dattr->vendor;
812 * Enforce valid values
814 * Don't worry about fixups...
816 switch (dattr->type) {
820 fr_strerror_printf("dict_addvalue: ATTRIBUTEs of type 'byte' cannot have VALUEs larger than 255");
827 fr_strerror_printf("dict_addvalue: ATTRIBUTEs of type 'short' cannot have VALUEs larger than 65535");
833 * Allow octets for now, because
834 * of dictionary.cablelabs
838 case PW_TYPE_INTEGER:
843 fr_strerror_printf("dict_addvalue: VALUEs cannot be defined for attributes of type '%s'",
844 fr_int2str(type_table, dattr->type, "?Unknown?"));
848 dattr->flags.has_value = 1;
850 value_fixup_t *fixup;
852 fixup = (value_fixup_t *) malloc(sizeof(*fixup));
855 fr_strerror_printf("dict_addvalue: out of memory");
858 memset(fixup, 0, sizeof(*fixup));
860 strlcpy(fixup->attrstr, attrstr, sizeof(fixup->attrstr));
864 * Insert to the head of the list.
866 fixup->next = value_fixup;
873 * Add the value into the dictionary.
875 if (!fr_hash_table_insert(values_byname, dval)) {
880 * Suppress duplicates with the same
881 * name and value. There are lots in
884 old = dict_valbyname(dattr->attr, dattr->vendor, namestr);
885 if (old && (old->value == dval->value)) {
892 fr_strerror_printf("dict_addvalue: Duplicate value name %s for attribute %s", namestr, attrstr);
897 * There are multiple VALUE's, keyed by attribute, so we
898 * take care of that here.
900 if (!fr_hash_table_replace(values_byvalue, dval)) {
901 fr_strerror_printf("dict_addvalue: Failed inserting value %s",
909 static int sscanf_i(const char *str, unsigned int *pvalue)
913 static const char *tab = "0123456789";
915 if ((str[0] == '0') &&
916 ((str[1] == 'x') || (str[1] == 'X'))) {
917 tab = "0123456789abcdef";
926 if (*str == '.') break;
928 c = memchr(tab, tolower((int) *str), base);
941 int dict_str2oid(const char *ptr, unsigned int *pvalue, int vendor, int tlv_depth)
947 if (tlv_depth > fr_attr_max_tlv) {
948 fr_strerror_printf("Attribute has too long OID");
954 da = dict_attrbyvalue(*pvalue, vendor);
956 da = dict_attrbyvalue(*pvalue, VENDORPEC_EXTENDED);
959 fr_strerror_printf("Parent attribute is undefined.");
963 if (!(da->flags.has_tlv || da->flags.extended || da->flags.extended_flags)) {
964 fr_strerror_printf("Parent attribute %s cannot have sub-tlvs",
970 p = strchr(ptr, '.');
972 if (!sscanf_i(ptr, &value)) {
973 fr_strerror_printf("Failed parsing attribute identifier %s",
979 *pvalue |= (value & fr_attr_mask[tlv_depth]) << fr_attr_shift[tlv_depth];
985 return dict_str2oid(p + 1, pvalue, vendor, tlv_depth + 1);
993 * Process the ATTRIBUTE command
995 static int process_attribute(const char* fn, const int line,
996 const unsigned int block_vendor, DICT_ATTR *block_tlv,
997 int tlv_depth, char **argv, int argc)
1000 unsigned int vendor = 0;
1003 unsigned int length = 0;
1007 if ((argc < 3) || (argc > 4)) {
1008 fr_strerror_printf("dict_init: %s[%d]: invalid ATTRIBUTE line",
1013 if (strncmp(argv[1], "Attr-", 5) == 0) {
1014 fr_strerror_printf("dict_init: %s[%d]: Invalid attribute name",
1019 memset(&flags, 0, sizeof(flags));
1022 * Look for extended attributes before doing anything else.
1024 p = strchr(argv[1], '.');
1031 * Validate all entries
1033 if (!sscanf_i(argv[1], &value)) {
1034 fr_strerror_printf("dict_init: %s[%d]: invalid value", fn, line);
1039 if (value > (1 << 24)) {
1040 fr_strerror_printf("dict_init: %s[%d]: Attribute number is too large", fn, line);
1046 * Parse NUM.NUM.NUM.NUM
1052 *p = '.'; /* reset for later printing */
1055 da = dict_attrbyvalue(value, block_vendor);
1056 } else if (value == PW_VENDOR_SPECIFIC) {
1058 const DICT_VENDOR *dv;
1064 fr_strerror_printf("dict_init: %s[%d]: Invalid attribute identifier", fn, line);
1069 if (!sscanf_i(p, &vendor)) {
1075 dv = dict_vendorbyvalue(vendor);
1077 fr_strerror_printf("dict_init: %s[%d]: Unknown vendor \"%u\" in attribute identifier", fn, line, vendor);
1082 return process_attribute(fn, line, vendor, NULL, 0,
1085 da = dict_attrbyvalue(value, VENDORPEC_EXTENDED);
1088 fr_strerror_printf("dict_init: %s[%d]: Entry refers to unknown attribute %d", fn, line, value);
1093 * 241.1 means 241 is of type "extended".
1096 if (!(da->flags.has_tlv || da->flags.extended || da->flags.extended_flags)) {
1097 fr_strerror_printf("dict_init: %s[%d]: Parent attribute %s cannot contain sub-attributes", fn, line, da->name);
1101 my_depth = dict_str2oid(p + 1, &value, block_vendor, tlv_depth + 1);
1105 strlcpy(buffer, fr_strerror(), sizeof(buffer));
1107 fr_strerror_printf("dict_init: %s[%d]: Invalid attribute identifier: %s", fn, line, buffer);
1113 * Look up the REAL parent TLV.
1116 unsigned int parent = value;
1118 parent &= ~(fr_attr_mask[my_depth] << fr_attr_shift[my_depth]);
1120 da = dict_attrbyvalue(parent, block_);
1122 fr_strerror_printf("dict_init: %s[%d]: Parent attribute is undefined.", fn, line);
1129 * Set which type of attribute this is.
1131 flags.extended = da->flags.extended;
1132 flags.extended_flags = da->flags.extended_flags;
1133 flags.evs = da->flags.evs;
1134 if (da->flags.has_tlv) flags.is_tlv = 1;
1137 if (strncmp(argv[2], "octets[", 7) != 0) {
1139 * find the type of the attribute.
1141 type = fr_str2int(type_table, argv[2], -1);
1143 fr_strerror_printf("dict_init: %s[%d]: invalid type \"%s\"",
1149 type = PW_TYPE_OCTETS;
1151 p = strchr(argv[2] + 7, ']');
1153 fr_strerror_printf("dict_init: %s[%d]: Invalid format for octets", fn, line);
1159 if (!sscanf_i(argv[1], &length)) {
1160 fr_strerror_printf("dict_init: %s[%d]: invalid length", fn, line);
1164 if ((length == 0) || (length > 253)) {
1165 fr_strerror_printf("dict_init: %s[%d]: invalid length", fn, line);
1171 * Only look up the vendor if the string
1176 * Force "length" for data types of fixed length;
1188 case PW_TYPE_IPADDR:
1189 case PW_TYPE_INTEGER:
1190 case PW_TYPE_SIGNED:
1194 case PW_TYPE_ETHERNET:
1202 case PW_TYPE_IPV6ADDR:
1206 case PW_TYPE_EXTENDED:
1207 if ((vendor != 0) || (value < 241)) {
1208 fr_strerror_printf("dict_init: %s[%d]: Attributes of type \"extended\" MUST be RFC attributes with value >= 241.", fn, line);
1211 type = PW_TYPE_OCTETS;
1215 case PW_TYPE_EXTENDED_FLAGS:
1216 if ((vendor != 0) || (value < 241)) {
1217 fr_strerror_printf("dict_init: %s[%d]: Attributes of type \"extended-flags\" MUST be RFC attributes with value >= 241.", fn, line);
1220 type = PW_TYPE_OCTETS;
1221 flags.extended_flags = 1;
1225 type = PW_TYPE_OCTETS;
1227 if (((value >> fr_attr_shift[1]) & fr_attr_mask[1]) != PW_VENDOR_SPECIFIC) {
1228 fr_strerror_printf("dict_init: %s[%d]: Attributes of type \"evs\" MUST have attribute code 26.", fn, line);
1237 flags.length = length;
1239 } else { /* argc == 4: we have options */
1240 char *key, *next, *last;
1245 if (flags.extended || flags.extended_flags || flags.evs) {
1246 fr_strerror_printf("dict_init: %s[%d]: Extended attributes cannot use flags", fn, line);
1251 fr_strerror_printf("dict_init: %s[%d]: length cannot be used with options", fn, line);
1257 next = strchr(key, ',');
1258 if (next) *(next++) = '\0';
1260 if (strcmp(key, "has_tag") == 0 ||
1261 strcmp(key, "has_tag=1") == 0) {
1262 /* Boolean flag, means this is a
1266 } else if (strncmp(key, "encrypt=", 8) == 0) {
1267 /* Encryption method, defaults to 0 (none).
1268 Currently valid is just type 2,
1269 Tunnel-Password style, which can only
1270 be applied to strings. */
1271 flags.encrypt = strtol(key + 8, &last, 0);
1273 fr_strerror_printf( "dict_init: %s[%d] invalid option %s",
1278 } else if (strncmp(key, "array", 6) == 0) {
1282 case PW_TYPE_IPADDR:
1285 case PW_TYPE_INTEGER:
1290 fr_strerror_printf( "dict_init: %s[%d] Only IP addresses can have the \"array\" flag set.",
1296 * The only thing is the vendor name,
1297 * and it's a known name: allow it.
1299 } else if ((key == argv[3]) && !next) {
1301 fr_strerror_printf( "dict_init: %s[%d] New-style attributes cannot use a vendor flag.",
1307 fr_strerror_printf( "dict_init: %s[%d] Vendor flag inside of \"BEGIN-VENDOR\" is not allowed.",
1312 vendor = dict_vendorbyname(key);
1313 if (!vendor) goto unknown;
1318 fr_strerror_printf( "dict_init: %s[%d]: unknown option \"%s\"",
1324 if (key && !*key) break;
1328 if (block_vendor) vendor = block_vendor;
1331 * Special checks for tags, they make our life much more
1334 if (flags.has_tag) {
1336 * Only string, octets, and integer can be tagged.
1339 case PW_TYPE_STRING:
1340 case PW_TYPE_INTEGER:
1344 fr_strerror_printf("dict_init: %s[%d]: Attributes of type %s cannot be tagged.",
1346 fr_int2str(type_table, type, "?Unknown?"));
1351 if (type == PW_TYPE_TLV) {
1354 && (vendor != DHCP_MAGIC_VENDOR)
1359 dv = dict_vendorbyvalue(vendor);
1360 if (!dv || (dv->type != 1) || (dv->length != 1)) {
1361 fr_strerror_printf("dict_init: %s[%d]: Type \"tlv\" can only be for \"format=1,1\".",
1372 * TLV's can be only one octet.
1374 if ((value <= 0) || ((value & ~fr_attr_mask[tlv_depth]) != 0)) {
1375 fr_strerror_printf( "dict_init: %s[%d]: sub-tlv has invalid attribute number",
1383 value <<= fr_attr_shift[tlv_depth];
1384 value |= block_tlv->attr;
1388 #ifdef WITH_DICTIONARY_WARNINGS
1390 * Hack to help us discover which vendors have illegal
1393 if (!vendor && (value < 256) &&
1394 !strstr(fn, "rfc") && !strstr(fn, "illegal")) {
1395 fprintf(stderr, "WARNING: Illegal Attribute %s in %s\n",
1403 if (dict_addattr(argv[0], value, vendor, type, flags) < 0) {
1406 strlcpy(buffer, fr_strerror(), sizeof(buffer));
1408 fr_strerror_printf("dict_init: %s[%d]: %s",
1418 * Process the VALUE command
1420 static int process_value(const char* fn, const int line, char **argv,
1426 fr_strerror_printf("dict_init: %s[%d]: invalid VALUE line",
1431 * For Compatibility, skip "Server-Config"
1433 if (strcasecmp(argv[0], "Server-Config") == 0)
1437 * Validate all entries
1439 if (!sscanf_i(argv[2], &value)) {
1440 fr_strerror_printf("dict_init: %s[%d]: invalid value",
1445 if (dict_addvalue(argv[1], argv[0], value) < 0) {
1448 strlcpy(buffer, fr_strerror(), sizeof(buffer));
1450 fr_strerror_printf("dict_init: %s[%d]: %s",
1460 * Process the VALUE-ALIAS command
1462 * This allows VALUE mappings to be shared among multiple
1465 static int process_value_alias(const char* fn, const int line, char **argv,
1468 DICT_ATTR *my_da, *da;
1472 fr_strerror_printf("dict_init: %s[%d]: invalid VALUE-ALIAS line",
1477 my_da = dict_attrbyname(argv[0]);
1479 fr_strerror_printf("dict_init: %s[%d]: ATTRIBUTE \"%s\" does not exist",
1484 if (my_da->flags.has_value) {
1485 fr_strerror_printf("dict_init: %s[%d]: Cannot add VALUE-ALIAS to ATTRIBUTE \"%s\" with pre-existing VALUE",
1490 if (my_da->flags.has_value_alias) {
1491 fr_strerror_printf("dict_init: %s[%d]: Cannot add VALUE-ALIAS to ATTRIBUTE \"%s\" with pre-existing VALUE-ALIAS",
1496 da = dict_attrbyname(argv[1]);
1498 fr_strerror_printf("dict_init: %s[%d]: Cannot find ATTRIBUTE \"%s\" for alias",
1503 if (!da->flags.has_value) {
1504 fr_strerror_printf("dict_init: %s[%d]: VALUE-ALIAS cannot refer to ATTRIBUTE %s: It has no values",
1509 if (da->flags.has_value_alias) {
1510 fr_strerror_printf("dict_init: %s[%d]: Cannot add VALUE-ALIAS to ATTRIBUTE \"%s\" which itself has a VALUE-ALIAS",
1515 if (my_da->type != da->type) {
1516 fr_strerror_printf("dict_init: %s[%d]: Cannot add VALUE-ALIAS between attributes of differing type",
1521 if ((dval = fr_pool_alloc(sizeof(*dval))) == NULL) {
1522 fr_strerror_printf("dict_addvalue: out of memory");
1526 dval->name[0] = '\0'; /* empty name */
1527 dval->attr = my_da->attr;
1528 dval->vendor = my_da->vendor;
1529 dval->value = da->attr;
1531 if (!fr_hash_table_insert(values_byname, dval)) {
1532 fr_strerror_printf("dict_init: %s[%d]: Error create alias",
1543 * Process the VENDOR command
1545 static int process_vendor(const char* fn, const int line, char **argv,
1549 int continuation = 0;
1550 const char *format = NULL;
1552 if ((argc < 2) || (argc > 3)) {
1553 fr_strerror_printf( "dict_init: %s[%d] invalid VENDOR entry",
1559 * Validate all entries
1561 if (!isdigit((int) argv[1][0])) {
1562 fr_strerror_printf("dict_init: %s[%d]: invalid value",
1566 value = atoi(argv[1]);
1568 /* Create a new VENDOR entry for the list */
1569 if (dict_addvendor(argv[0], value) < 0) {
1572 strlcpy(buffer, fr_strerror(), sizeof(buffer));
1574 fr_strerror_printf("dict_init: %s[%d]: %s",
1580 * Look for a format statement
1585 } else if (value == VENDORPEC_USR) { /* catch dictionary screw-ups */
1586 format = "format=4,0";
1588 } else if (value == VENDORPEC_LUCENT) {
1589 format = "format=2,1";
1591 } else if (value == VENDORPEC_STARENT) {
1592 format = "format=2,2";
1594 } /* else no fixups to do */
1601 if (strncasecmp(format, "format=", 7) != 0) {
1602 fr_strerror_printf("dict_init: %s[%d]: Invalid format for VENDOR. Expected \"format=\", got \"%s\"",
1608 if ((strlen(p) < 3) ||
1609 !isdigit((int) p[0]) ||
1611 !isdigit((int) p[2]) ||
1612 (p[3] && (p[3] != ','))) {
1613 fr_strerror_printf("dict_init: %s[%d]: Invalid format for VENDOR. Expected text like \"1,1\", got \"%s\"",
1618 type = (int) (p[0] - '0');
1619 length = (int) (p[2] - '0');
1622 if ((p[4] != 'c') ||
1624 fr_strerror_printf("dict_init: %s[%d]: Invalid format for VENDOR. Expected text like \"1,1\", got \"%s\"",
1630 if ((value != VENDORPEC_WIMAX) ||
1631 (type != 1) || (length != 1)) {
1632 fr_strerror_printf("dict_init: %s[%d]: Only WiMAX VSAs can have continuations",
1638 dv = dict_vendorbyvalue(value);
1640 fr_strerror_printf("dict_init: %s[%d]: Failed adding format for VENDOR",
1645 if ((type != 1) && (type != 2) && (type != 4)) {
1646 fr_strerror_printf("dict_init: %s[%d]: invalid type value %d for VENDOR",
1651 if ((length != 0) && (length != 1) && (length != 2)) {
1652 fr_strerror_printf("dict_init: %s[%d]: invalid length value %d for VENDOR",
1658 dv->length = length;
1659 dv->flags = continuation;
1666 * String split routine. Splits an input string IN PLACE
1667 * into pieces, based on spaces.
1669 static int str2argv(char *str, char **argv, int max_argc)
1674 if (argc >= max_argc) break;
1677 * Chop out comments early.
1684 while ((*str == ' ') ||
1687 (*str == '\n')) *(str++) = '\0';
1698 (*str != '\n')) str++;
1704 #define MAX_ARGV (16)
1707 * Initialize the dictionary.
1709 static int my_dict_init(const char *dir, const char *fn,
1710 const char *src_file, int src_line)
1717 unsigned int vendor;
1718 unsigned int block_vendor;
1719 struct stat statbuf;
1720 char *argv[MAX_ARGV];
1722 DICT_ATTR *da, *block_tlv[MAX_TLV_NEST + 1];
1723 int which_block_tlv = 0;
1725 block_tlv[0] = NULL;
1726 block_tlv[1] = NULL;
1727 block_tlv[2] = NULL;
1729 if (strlen(fn) >= sizeof(dirtmp) / 2 ||
1730 strlen(dir) >= sizeof(dirtmp) / 2) {
1731 fr_strerror_printf("dict_init: filename name too long");
1736 * First see if fn is relative to dir. If so, create
1737 * new filename. If not, remember the absolute dir.
1739 if ((p = strrchr(fn, FR_DIR_SEP)) != NULL) {
1743 } else if (dir && dir[0] && strcmp(dir, ".") != 0) {
1744 snprintf(dirtmp, sizeof(dirtmp), "%s/%s", dir, fn);
1748 if ((fp = fopen(fn, "r")) == NULL) {
1750 fr_strerror_printf("dict_init: Couldn't open dictionary \"%s\": %s",
1751 fn, strerror(errno));
1753 fr_strerror_printf("dict_init: %s[%d]: Couldn't open dictionary \"%s\": %s",
1754 src_file, src_line, fn, strerror(errno));
1759 stat(fn, &statbuf); /* fopen() guarantees this will succeed */
1760 if (!S_ISREG(statbuf.st_mode)) {
1762 fr_strerror_printf("dict_init: Dictionary \"%s\" is not a regular file",
1768 * Globally writable dictionaries means that users can control
1769 * the server configuration with little difficulty.
1772 if ((statbuf.st_mode & S_IWOTH) != 0) {
1774 fr_strerror_printf("dict_init: Dictionary \"%s\" is globally writable. Refusing to start due to insecure configuration.",
1780 dict_stat_add(fn, &statbuf);
1783 * Seed the random pool with data.
1785 fr_rand_seed(&statbuf, sizeof(statbuf));
1789 while (fgets(buf, sizeof(buf), fp) != NULL) {
1791 if (buf[0] == '#' || buf[0] == 0 ||
1792 buf[0] == '\n' || buf[0] == '\r')
1796 * Comment characters should NOT be appearing anywhere but
1797 * as start of a comment;
1799 p = strchr(buf, '#');
1802 argc = str2argv(buf, argv, MAX_ARGV);
1803 if (argc == 0) continue;
1806 fr_strerror_printf( "dict_init: %s[%d] invalid entry",
1813 * Process VALUE lines.
1815 if (strcasecmp(argv[0], "VALUE") == 0) {
1816 if (process_value(fn, line,
1817 argv + 1, argc - 1) == -1) {
1825 * Perhaps this is an attribute.
1827 if (strcasecmp(argv[0], "ATTRIBUTE") == 0) {
1828 if (process_attribute(fn, line, block_vendor,
1829 block_tlv[which_block_tlv],
1831 argv + 1, argc - 1) == -1) {
1839 * See if we need to import another dictionary.
1841 if (strcasecmp(argv[0], "$INCLUDE") == 0) {
1842 if (my_dict_init(dir, argv[1], fn, line) < 0) {
1849 if (strcasecmp(argv[0], "VALUE-ALIAS") == 0) {
1850 if (process_value_alias(fn, line,
1851 argv + 1, argc - 1) == -1) {
1859 * Process VENDOR lines.
1861 if (strcasecmp(argv[0], "VENDOR") == 0) {
1862 if (process_vendor(fn, line,
1863 argv + 1, argc - 1) == -1) {
1870 if (strcasecmp(argv[0], "BEGIN-TLV") == 0) {
1873 "dict_init: %s[%d] invalid BEGIN-TLV entry",
1879 da = dict_attrbyname(argv[1]);
1882 "dict_init: %s[%d]: unknown attribute %s",
1888 if (da->type != PW_TYPE_TLV) {
1890 "dict_init: %s[%d]: attribute %s is not of type tlv",
1896 if (which_block_tlv >= MAX_TLV_NEST) {
1898 "dict_init: %s[%d]: TLVs are nested too deep",
1905 block_tlv[++which_block_tlv] = da;
1909 if (strcasecmp(argv[0], "END-TLV") == 0) {
1912 "dict_init: %s[%d] invalid END-TLV entry",
1918 da = dict_attrbyname(argv[1]);
1921 "dict_init: %s[%d]: unknown attribute %s",
1927 if (da != block_tlv[which_block_tlv]) {
1929 "dict_init: %s[%d]: END-TLV %s does not match any previous BEGIN-TLV",
1934 block_tlv[which_block_tlv--] = NULL;
1938 if (strcasecmp(argv[0], "BEGIN-VENDOR") == 0) {
1941 "dict_init: %s[%d] invalid BEGIN-VENDOR entry",
1947 vendor = dict_vendorbyname(argv[1]);
1950 "dict_init: %s[%d]: unknown vendor %s",
1956 block_vendor = vendor;
1959 * Check for extended attr VSAs
1962 if (strncmp(argv[2], "format=", 7) != 0) {
1964 "dict_init: %s[%d]: Invalid format %s",
1971 da = dict_attrbyname(p);
1973 fr_strerror_printf("dict_init: %s[%d]: Invalid format for BEGIN-VENDOR: unknown attribute \"%s\"",
1979 if (!da->flags.evs) {
1980 fr_strerror_printf("dict_init: %s[%d]: Invalid format for BEGIN-VENDOR. Attribute \"%s\" is not of \"evs\" data type",
1987 * Pack the encapsulating attribute
1988 * into the vendor Id. This attribute
1991 block_vendor |= (da->attr & fr_attr_mask[1]) * FR_MAX_VENDOR;
1995 } /* BEGIN-VENDOR */
1997 if (strcasecmp(argv[0], "END-VENDOR") == 0) {
2000 "dict_init: %s[%d] invalid END-VENDOR entry",
2006 vendor = dict_vendorbyname(argv[1]);
2009 "dict_init: %s[%d]: unknown vendor %s",
2015 if (vendor != (block_vendor & (FR_MAX_VENDOR - 1))) {
2017 "dict_init: %s[%d]: END-VENDOR %s does not match any previous BEGIN-VENDOR",
2027 * Any other string: We don't recognize it.
2029 fr_strerror_printf("dict_init: %s[%d] invalid keyword \"%s\"",
2040 * Empty callback for hash table initialization.
2042 static int null_callback(void *ctx, void *data)
2044 ctx = ctx; /* -Wunused */
2045 data = data; /* -Wunused */
2052 * Initialize the directory, then fix the attr member of
2055 int dict_init(const char *dir, const char *fn)
2058 * Check if we need to change anything. If not, don't do
2061 if (dict_stat_check(dir, fn)) {
2066 * Free the dictionaries, and the stat cache.
2069 stat_root_dir = strdup(dir);
2070 stat_root_file = strdup(fn);
2073 * Create the table of vendor by name. There MAY NOT
2074 * be multiple vendors of the same name.
2076 * Each vendor is malloc'd, so the free function is free.
2078 vendors_byname = fr_hash_table_create(dict_vendor_name_hash,
2079 dict_vendor_name_cmp,
2081 if (!vendors_byname) {
2086 * Create the table of vendors by value. There MAY
2087 * be vendors of the same value. If there are, we
2088 * pick the latest one.
2090 vendors_byvalue = fr_hash_table_create(dict_vendor_value_hash,
2091 dict_vendor_value_cmp,
2093 if (!vendors_byvalue) {
2098 * Create the table of attributes by name. There MAY NOT
2099 * be multiple attributes of the same name.
2101 * Each attribute is malloc'd, so the free function is free.
2103 attributes_byname = fr_hash_table_create(dict_attr_name_hash,
2106 if (!attributes_byname) {
2111 * Create the table of attributes by value. There MAY
2112 * be attributes of the same value. If there are, we
2113 * pick the latest one.
2115 attributes_byvalue = fr_hash_table_create(dict_attr_value_hash,
2116 dict_attr_value_cmp,
2118 if (!attributes_byvalue) {
2122 values_byname = fr_hash_table_create(dict_value_name_hash,
2123 dict_value_name_cmp,
2125 if (!values_byname) {
2129 values_byvalue = fr_hash_table_create(dict_value_value_hash,
2130 dict_value_value_cmp,
2132 if (!values_byvalue) {
2136 value_fixup = NULL; /* just to be safe. */
2138 if (my_dict_init(dir, fn, NULL, 0) < 0)
2143 value_fixup_t *this, *next;
2145 for (this = value_fixup; this != NULL; this = next) {
2148 a = dict_attrbyname(this->attrstr);
2151 "dict_init: No ATTRIBUTE \"%s\" defined for VALUE \"%s\"",
2152 this->attrstr, this->dval->name);
2153 return -1; /* leak, but they should die... */
2156 this->dval->attr = a->attr;
2159 * Add the value into the dictionary.
2161 if (!fr_hash_table_replace(values_byname,
2163 fr_strerror_printf("dict_addvalue: Duplicate value name %s for attribute %s", this->dval->name, a->name);
2168 * Allow them to use the old name, but
2169 * prefer the new name when printing
2172 if (!fr_hash_table_finddata(values_byvalue, this->dval)) {
2173 fr_hash_table_replace(values_byvalue,
2179 * Just so we don't lose track of things.
2186 * Walk over all of the hash tables to ensure they're
2187 * initialized. We do this because the threads may perform
2188 * lookups, and we don't want multi-threaded re-ordering
2189 * of the table entries. That would be bad.
2191 fr_hash_table_walk(vendors_byname, null_callback, NULL);
2192 fr_hash_table_walk(vendors_byvalue, null_callback, NULL);
2194 fr_hash_table_walk(attributes_byname, null_callback, NULL);
2195 fr_hash_table_walk(attributes_byvalue, null_callback, NULL);
2197 fr_hash_table_walk(values_byvalue, null_callback, NULL);
2198 fr_hash_table_walk(values_byname, null_callback, NULL);
2204 * Get an attribute by its numerical value.
2206 DICT_ATTR *dict_attrbyvalue(unsigned int attr, unsigned int vendor)
2210 if ((attr > 0) && (attr < 256) && !vendor) return dict_base_attrs[attr];
2213 dattr.vendor = vendor;
2215 return fr_hash_table_finddata(attributes_byvalue, &dattr);
2219 * Get an attribute by its name.
2221 DICT_ATTR *dict_attrbyname(const char *name)
2224 uint32_t buffer[(sizeof(*da) + DICT_ATTR_MAX_NAME_LEN + 3)/4];
2226 if (!name) return NULL;
2228 da = (DICT_ATTR *) buffer;
2229 strlcpy(da->name, name, DICT_ATTR_MAX_NAME_LEN + 1);
2231 return fr_hash_table_finddata(attributes_byname, da);
2235 * Associate a value with an attribute and return it.
2237 DICT_VALUE *dict_valbyattr(unsigned int attr, unsigned int vendor, int value)
2239 DICT_VALUE dval, *dv;
2242 * First, look up aliases.
2245 dval.vendor = vendor;
2246 dval.name[0] = '\0';
2249 * Look up the attribute alias target, and use
2250 * the correct attribute number if found.
2252 dv = fr_hash_table_finddata(values_byname, &dval);
2253 if (dv) dval.attr = dv->value;
2257 return fr_hash_table_finddata(values_byvalue, &dval);
2261 * Get a value by its name, keyed off of an attribute.
2263 DICT_VALUE *dict_valbyname(unsigned int attr, unsigned int vendor, const char *name)
2265 DICT_VALUE *my_dv, *dv;
2266 uint32_t buffer[(sizeof(*my_dv) + DICT_VALUE_MAX_NAME_LEN + 3)/4];
2268 if (!name) return NULL;
2270 my_dv = (DICT_VALUE *) buffer;
2272 my_dv->vendor = vendor;
2273 my_dv->name[0] = '\0';
2276 * Look up the attribute alias target, and use
2277 * the correct attribute number if found.
2279 dv = fr_hash_table_finddata(values_byname, my_dv);
2280 if (dv) my_dv->attr = dv->value;
2282 strlcpy(my_dv->name, name, DICT_VALUE_MAX_NAME_LEN + 1);
2284 return fr_hash_table_finddata(values_byname, my_dv);
2288 * Get the vendor PEC based on the vendor name
2290 * This is efficient only for small numbers of vendors.
2292 int dict_vendorbyname(const char *name)
2295 uint32_t buffer[(sizeof(*dv) + DICT_VENDOR_MAX_NAME_LEN + 3)/4];
2297 if (!name) return 0;
2299 dv = (DICT_VENDOR *) buffer;
2300 strlcpy(dv->name, name, DICT_VENDOR_MAX_NAME_LEN + 1);
2302 dv = fr_hash_table_finddata(vendors_byname, dv);
2305 return dv->vendorpec;
2309 * Return the vendor struct based on the PEC.
2311 DICT_VENDOR *dict_vendorbyvalue(int vendorpec)
2315 dv.vendorpec = vendorpec;
2317 return fr_hash_table_finddata(vendors_byvalue, &dv);