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) {
562 if (vendor && (vendor < FR_MAX_VENDOR)) {
563 fr_strerror_printf("dict_addattr: VSAs cannot use the \"extended\" or \"evs\" attribute formats.");
566 if (!vendor) 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);
1112 * Look up the REAL parent TLV.
1115 unsigned int parent = value;
1117 parent &= ~(fr_attr_mask[my_depth] << fr_attr_shift[my_depth]);
1119 da = dict_attrbyvalue(parent, da->vendor);
1121 fr_strerror_printf("dict_init: %s[%d]: Parent attribute is undefined.", fn, line);
1127 * Set which type of attribute this is.
1129 flags.extended = da->flags.extended;
1130 flags.extended_flags = da->flags.extended_flags;
1131 flags.evs = da->flags.evs;
1132 if (da->flags.has_tlv) flags.is_tlv = 1;
1135 if (strncmp(argv[2], "octets[", 7) != 0) {
1137 * find the type of the attribute.
1139 type = fr_str2int(type_table, argv[2], -1);
1141 fr_strerror_printf("dict_init: %s[%d]: invalid type \"%s\"",
1147 type = PW_TYPE_OCTETS;
1149 p = strchr(argv[2] + 7, ']');
1151 fr_strerror_printf("dict_init: %s[%d]: Invalid format for octets", fn, line);
1157 if (!sscanf_i(argv[1], &length)) {
1158 fr_strerror_printf("dict_init: %s[%d]: invalid length", fn, line);
1162 if ((length == 0) || (length > 253)) {
1163 fr_strerror_printf("dict_init: %s[%d]: invalid length", fn, line);
1169 * Only look up the vendor if the string
1174 * Force "length" for data types of fixed length;
1186 case PW_TYPE_IPADDR:
1187 case PW_TYPE_INTEGER:
1188 case PW_TYPE_SIGNED:
1192 case PW_TYPE_ETHERNET:
1200 case PW_TYPE_IPV6ADDR:
1204 case PW_TYPE_EXTENDED:
1205 if ((vendor != 0) || (value < 241)) {
1206 fr_strerror_printf("dict_init: %s[%d]: Attributes of type \"extended\" MUST be RFC attributes with value >= 241.", fn, line);
1209 type = PW_TYPE_OCTETS;
1213 case PW_TYPE_EXTENDED_FLAGS:
1214 if ((vendor != 0) || (value < 241)) {
1215 fr_strerror_printf("dict_init: %s[%d]: Attributes of type \"extended-flags\" MUST be RFC attributes with value >= 241.", fn, line);
1218 type = PW_TYPE_OCTETS;
1219 flags.extended_flags = 1;
1223 type = PW_TYPE_OCTETS;
1225 if (((value >> fr_attr_shift[1]) & fr_attr_mask[1]) != PW_VENDOR_SPECIFIC) {
1226 fr_strerror_printf("dict_init: %s[%d]: Attributes of type \"evs\" MUST have attribute code 26.", fn, line);
1235 flags.length = length;
1237 } else { /* argc == 4: we have options */
1238 char *key, *next, *last;
1243 if (flags.extended || flags.extended_flags || flags.evs) {
1244 fr_strerror_printf("dict_init: %s[%d]: Extended attributes cannot use flags", fn, line);
1249 fr_strerror_printf("dict_init: %s[%d]: length cannot be used with options", fn, line);
1255 next = strchr(key, ',');
1256 if (next) *(next++) = '\0';
1258 if (strcmp(key, "has_tag") == 0 ||
1259 strcmp(key, "has_tag=1") == 0) {
1260 /* Boolean flag, means this is a
1264 } else if (strncmp(key, "encrypt=", 8) == 0) {
1265 /* Encryption method, defaults to 0 (none).
1266 Currently valid is just type 2,
1267 Tunnel-Password style, which can only
1268 be applied to strings. */
1269 flags.encrypt = strtol(key + 8, &last, 0);
1271 fr_strerror_printf( "dict_init: %s[%d] invalid option %s",
1276 } else if (strncmp(key, "array", 6) == 0) {
1280 case PW_TYPE_IPADDR:
1283 case PW_TYPE_INTEGER:
1288 fr_strerror_printf( "dict_init: %s[%d] Only IP addresses can have the \"array\" flag set.",
1294 * The only thing is the vendor name,
1295 * and it's a known name: allow it.
1297 } else if ((key == argv[3]) && !next) {
1299 fr_strerror_printf( "dict_init: %s[%d] New-style attributes cannot use a vendor flag.",
1305 fr_strerror_printf( "dict_init: %s[%d] Vendor flag inside of \"BEGIN-VENDOR\" is not allowed.",
1310 vendor = dict_vendorbyname(key);
1311 if (!vendor) goto unknown;
1316 fr_strerror_printf( "dict_init: %s[%d]: unknown option \"%s\"",
1322 if (key && !*key) break;
1326 if (block_vendor) vendor = block_vendor;
1329 * Special checks for tags, they make our life much more
1332 if (flags.has_tag) {
1334 * Only string, octets, and integer can be tagged.
1337 case PW_TYPE_STRING:
1338 case PW_TYPE_INTEGER:
1342 fr_strerror_printf("dict_init: %s[%d]: Attributes of type %s cannot be tagged.",
1344 fr_int2str(type_table, type, "?Unknown?"));
1349 if (type == PW_TYPE_TLV) {
1350 if (vendor && (vendor < FR_MAX_VENDOR)
1352 && (vendor != DHCP_MAGIC_VENDOR)
1357 dv = dict_vendorbyvalue(vendor);
1358 if (!dv || (dv->type != 1) || (dv->length != 1)) {
1359 fr_strerror_printf("dict_init: %s[%d]: Type \"tlv\" can only be for \"format=1,1\".",
1370 * TLV's can be only one octet.
1372 if ((value <= 0) || ((value & ~fr_attr_mask[tlv_depth]) != 0)) {
1373 fr_strerror_printf( "dict_init: %s[%d]: sub-tlv has invalid attribute number",
1381 value <<= fr_attr_shift[tlv_depth];
1382 value |= block_tlv->attr;
1386 #ifdef WITH_DICTIONARY_WARNINGS
1388 * Hack to help us discover which vendors have illegal
1391 if (!vendor && (value < 256) &&
1392 !strstr(fn, "rfc") && !strstr(fn, "illegal")) {
1393 fprintf(stderr, "WARNING: Illegal Attribute %s in %s\n",
1401 if (dict_addattr(argv[0], value, vendor, type, flags) < 0) {
1404 strlcpy(buffer, fr_strerror(), sizeof(buffer));
1406 fr_strerror_printf("dict_init: %s[%d]: %s",
1416 * Process the VALUE command
1418 static int process_value(const char* fn, const int line, char **argv,
1424 fr_strerror_printf("dict_init: %s[%d]: invalid VALUE line",
1429 * For Compatibility, skip "Server-Config"
1431 if (strcasecmp(argv[0], "Server-Config") == 0)
1435 * Validate all entries
1437 if (!sscanf_i(argv[2], &value)) {
1438 fr_strerror_printf("dict_init: %s[%d]: invalid value",
1443 if (dict_addvalue(argv[1], argv[0], value) < 0) {
1446 strlcpy(buffer, fr_strerror(), sizeof(buffer));
1448 fr_strerror_printf("dict_init: %s[%d]: %s",
1458 * Process the VALUE-ALIAS command
1460 * This allows VALUE mappings to be shared among multiple
1463 static int process_value_alias(const char* fn, const int line, char **argv,
1466 DICT_ATTR *my_da, *da;
1470 fr_strerror_printf("dict_init: %s[%d]: invalid VALUE-ALIAS line",
1475 my_da = dict_attrbyname(argv[0]);
1477 fr_strerror_printf("dict_init: %s[%d]: ATTRIBUTE \"%s\" does not exist",
1482 if (my_da->flags.has_value) {
1483 fr_strerror_printf("dict_init: %s[%d]: Cannot add VALUE-ALIAS to ATTRIBUTE \"%s\" with pre-existing VALUE",
1488 if (my_da->flags.has_value_alias) {
1489 fr_strerror_printf("dict_init: %s[%d]: Cannot add VALUE-ALIAS to ATTRIBUTE \"%s\" with pre-existing VALUE-ALIAS",
1494 da = dict_attrbyname(argv[1]);
1496 fr_strerror_printf("dict_init: %s[%d]: Cannot find ATTRIBUTE \"%s\" for alias",
1501 if (!da->flags.has_value) {
1502 fr_strerror_printf("dict_init: %s[%d]: VALUE-ALIAS cannot refer to ATTRIBUTE %s: It has no values",
1507 if (da->flags.has_value_alias) {
1508 fr_strerror_printf("dict_init: %s[%d]: Cannot add VALUE-ALIAS to ATTRIBUTE \"%s\" which itself has a VALUE-ALIAS",
1513 if (my_da->type != da->type) {
1514 fr_strerror_printf("dict_init: %s[%d]: Cannot add VALUE-ALIAS between attributes of differing type",
1519 if ((dval = fr_pool_alloc(sizeof(*dval))) == NULL) {
1520 fr_strerror_printf("dict_addvalue: out of memory");
1524 dval->name[0] = '\0'; /* empty name */
1525 dval->attr = my_da->attr;
1526 dval->vendor = my_da->vendor;
1527 dval->value = da->attr;
1529 if (!fr_hash_table_insert(values_byname, dval)) {
1530 fr_strerror_printf("dict_init: %s[%d]: Error create alias",
1541 * Process the VENDOR command
1543 static int process_vendor(const char* fn, const int line, char **argv,
1547 int continuation = 0;
1548 const char *format = NULL;
1550 if ((argc < 2) || (argc > 3)) {
1551 fr_strerror_printf( "dict_init: %s[%d] invalid VENDOR entry",
1557 * Validate all entries
1559 if (!isdigit((int) argv[1][0])) {
1560 fr_strerror_printf("dict_init: %s[%d]: invalid value",
1564 value = atoi(argv[1]);
1566 /* Create a new VENDOR entry for the list */
1567 if (dict_addvendor(argv[0], value) < 0) {
1570 strlcpy(buffer, fr_strerror(), sizeof(buffer));
1572 fr_strerror_printf("dict_init: %s[%d]: %s",
1578 * Look for a format statement
1583 } else if (value == VENDORPEC_USR) { /* catch dictionary screw-ups */
1584 format = "format=4,0";
1586 } else if (value == VENDORPEC_LUCENT) {
1587 format = "format=2,1";
1589 } else if (value == VENDORPEC_STARENT) {
1590 format = "format=2,2";
1592 } /* else no fixups to do */
1599 if (strncasecmp(format, "format=", 7) != 0) {
1600 fr_strerror_printf("dict_init: %s[%d]: Invalid format for VENDOR. Expected \"format=\", got \"%s\"",
1606 if ((strlen(p) < 3) ||
1607 !isdigit((int) p[0]) ||
1609 !isdigit((int) p[2]) ||
1610 (p[3] && (p[3] != ','))) {
1611 fr_strerror_printf("dict_init: %s[%d]: Invalid format for VENDOR. Expected text like \"1,1\", got \"%s\"",
1616 type = (int) (p[0] - '0');
1617 length = (int) (p[2] - '0');
1620 if ((p[4] != 'c') ||
1622 fr_strerror_printf("dict_init: %s[%d]: Invalid format for VENDOR. Expected text like \"1,1\", got \"%s\"",
1628 if ((value != VENDORPEC_WIMAX) ||
1629 (type != 1) || (length != 1)) {
1630 fr_strerror_printf("dict_init: %s[%d]: Only WiMAX VSAs can have continuations",
1636 dv = dict_vendorbyvalue(value);
1638 fr_strerror_printf("dict_init: %s[%d]: Failed adding format for VENDOR",
1643 if ((type != 1) && (type != 2) && (type != 4)) {
1644 fr_strerror_printf("dict_init: %s[%d]: invalid type value %d for VENDOR",
1649 if ((length != 0) && (length != 1) && (length != 2)) {
1650 fr_strerror_printf("dict_init: %s[%d]: invalid length value %d for VENDOR",
1656 dv->length = length;
1657 dv->flags = continuation;
1664 * String split routine. Splits an input string IN PLACE
1665 * into pieces, based on spaces.
1667 static int str2argv(char *str, char **argv, int max_argc)
1672 if (argc >= max_argc) break;
1675 * Chop out comments early.
1682 while ((*str == ' ') ||
1685 (*str == '\n')) *(str++) = '\0';
1696 (*str != '\n')) str++;
1702 #define MAX_ARGV (16)
1705 * Initialize the dictionary.
1707 static int my_dict_init(const char *dir, const char *fn,
1708 const char *src_file, int src_line)
1715 unsigned int vendor;
1716 unsigned int block_vendor;
1717 struct stat statbuf;
1718 char *argv[MAX_ARGV];
1720 DICT_ATTR *da, *block_tlv[MAX_TLV_NEST + 1];
1721 int which_block_tlv = 0;
1723 block_tlv[0] = NULL;
1724 block_tlv[1] = NULL;
1725 block_tlv[2] = NULL;
1727 if (strlen(fn) >= sizeof(dirtmp) / 2 ||
1728 strlen(dir) >= sizeof(dirtmp) / 2) {
1729 fr_strerror_printf("dict_init: filename name too long");
1734 * First see if fn is relative to dir. If so, create
1735 * new filename. If not, remember the absolute dir.
1737 if ((p = strrchr(fn, FR_DIR_SEP)) != NULL) {
1741 } else if (dir && dir[0] && strcmp(dir, ".") != 0) {
1742 snprintf(dirtmp, sizeof(dirtmp), "%s/%s", dir, fn);
1746 if ((fp = fopen(fn, "r")) == NULL) {
1748 fr_strerror_printf("dict_init: Couldn't open dictionary \"%s\": %s",
1749 fn, strerror(errno));
1751 fr_strerror_printf("dict_init: %s[%d]: Couldn't open dictionary \"%s\": %s",
1752 src_file, src_line, fn, strerror(errno));
1757 stat(fn, &statbuf); /* fopen() guarantees this will succeed */
1758 if (!S_ISREG(statbuf.st_mode)) {
1760 fr_strerror_printf("dict_init: Dictionary \"%s\" is not a regular file",
1766 * Globally writable dictionaries means that users can control
1767 * the server configuration with little difficulty.
1770 if ((statbuf.st_mode & S_IWOTH) != 0) {
1772 fr_strerror_printf("dict_init: Dictionary \"%s\" is globally writable. Refusing to start due to insecure configuration.",
1778 dict_stat_add(fn, &statbuf);
1781 * Seed the random pool with data.
1783 fr_rand_seed(&statbuf, sizeof(statbuf));
1787 while (fgets(buf, sizeof(buf), fp) != NULL) {
1789 if (buf[0] == '#' || buf[0] == 0 ||
1790 buf[0] == '\n' || buf[0] == '\r')
1794 * Comment characters should NOT be appearing anywhere but
1795 * as start of a comment;
1797 p = strchr(buf, '#');
1800 argc = str2argv(buf, argv, MAX_ARGV);
1801 if (argc == 0) continue;
1804 fr_strerror_printf( "dict_init: %s[%d] invalid entry",
1811 * Process VALUE lines.
1813 if (strcasecmp(argv[0], "VALUE") == 0) {
1814 if (process_value(fn, line,
1815 argv + 1, argc - 1) == -1) {
1823 * Perhaps this is an attribute.
1825 if (strcasecmp(argv[0], "ATTRIBUTE") == 0) {
1826 if (process_attribute(fn, line, block_vendor,
1827 block_tlv[which_block_tlv],
1829 argv + 1, argc - 1) == -1) {
1837 * See if we need to import another dictionary.
1839 if (strcasecmp(argv[0], "$INCLUDE") == 0) {
1840 if (my_dict_init(dir, argv[1], fn, line) < 0) {
1847 if (strcasecmp(argv[0], "VALUE-ALIAS") == 0) {
1848 if (process_value_alias(fn, line,
1849 argv + 1, argc - 1) == -1) {
1857 * Process VENDOR lines.
1859 if (strcasecmp(argv[0], "VENDOR") == 0) {
1860 if (process_vendor(fn, line,
1861 argv + 1, argc - 1) == -1) {
1868 if (strcasecmp(argv[0], "BEGIN-TLV") == 0) {
1871 "dict_init: %s[%d] invalid BEGIN-TLV entry",
1877 da = dict_attrbyname(argv[1]);
1880 "dict_init: %s[%d]: unknown attribute %s",
1886 if (da->type != PW_TYPE_TLV) {
1888 "dict_init: %s[%d]: attribute %s is not of type tlv",
1894 if (which_block_tlv >= MAX_TLV_NEST) {
1896 "dict_init: %s[%d]: TLVs are nested too deep",
1903 block_tlv[++which_block_tlv] = da;
1907 if (strcasecmp(argv[0], "END-TLV") == 0) {
1910 "dict_init: %s[%d] invalid END-TLV entry",
1916 da = dict_attrbyname(argv[1]);
1919 "dict_init: %s[%d]: unknown attribute %s",
1925 if (da != block_tlv[which_block_tlv]) {
1927 "dict_init: %s[%d]: END-TLV %s does not match any previous BEGIN-TLV",
1932 block_tlv[which_block_tlv--] = NULL;
1936 if (strcasecmp(argv[0], "BEGIN-VENDOR") == 0) {
1939 "dict_init: %s[%d] invalid BEGIN-VENDOR entry",
1945 vendor = dict_vendorbyname(argv[1]);
1948 "dict_init: %s[%d]: unknown vendor %s",
1954 block_vendor = vendor;
1957 * Check for extended attr VSAs
1960 if (strncmp(argv[2], "format=", 7) != 0) {
1962 "dict_init: %s[%d]: Invalid format %s",
1969 da = dict_attrbyname(p);
1971 fr_strerror_printf("dict_init: %s[%d]: Invalid format for BEGIN-VENDOR: unknown attribute \"%s\"",
1977 if (!da->flags.evs) {
1978 fr_strerror_printf("dict_init: %s[%d]: Invalid format for BEGIN-VENDOR. Attribute \"%s\" is not of \"evs\" data type",
1985 * Pack the encapsulating attribute
1986 * into the vendor Id. This attribute
1989 block_vendor |= (da->attr & fr_attr_mask[1]) * FR_MAX_VENDOR;
1993 } /* BEGIN-VENDOR */
1995 if (strcasecmp(argv[0], "END-VENDOR") == 0) {
1998 "dict_init: %s[%d] invalid END-VENDOR entry",
2004 vendor = dict_vendorbyname(argv[1]);
2007 "dict_init: %s[%d]: unknown vendor %s",
2013 if (vendor != (block_vendor & (FR_MAX_VENDOR - 1))) {
2015 "dict_init: %s[%d]: END-VENDOR %s does not match any previous BEGIN-VENDOR",
2025 * Any other string: We don't recognize it.
2027 fr_strerror_printf("dict_init: %s[%d] invalid keyword \"%s\"",
2038 * Empty callback for hash table initialization.
2040 static int null_callback(void *ctx, void *data)
2042 ctx = ctx; /* -Wunused */
2043 data = data; /* -Wunused */
2050 * Initialize the directory, then fix the attr member of
2053 int dict_init(const char *dir, const char *fn)
2056 * Check if we need to change anything. If not, don't do
2059 if (dict_stat_check(dir, fn)) {
2064 * Free the dictionaries, and the stat cache.
2067 stat_root_dir = strdup(dir);
2068 stat_root_file = strdup(fn);
2071 * Create the table of vendor by name. There MAY NOT
2072 * be multiple vendors of the same name.
2074 * Each vendor is malloc'd, so the free function is free.
2076 vendors_byname = fr_hash_table_create(dict_vendor_name_hash,
2077 dict_vendor_name_cmp,
2079 if (!vendors_byname) {
2084 * Create the table of vendors by value. There MAY
2085 * be vendors of the same value. If there are, we
2086 * pick the latest one.
2088 vendors_byvalue = fr_hash_table_create(dict_vendor_value_hash,
2089 dict_vendor_value_cmp,
2091 if (!vendors_byvalue) {
2096 * Create the table of attributes by name. There MAY NOT
2097 * be multiple attributes of the same name.
2099 * Each attribute is malloc'd, so the free function is free.
2101 attributes_byname = fr_hash_table_create(dict_attr_name_hash,
2104 if (!attributes_byname) {
2109 * Create the table of attributes by value. There MAY
2110 * be attributes of the same value. If there are, we
2111 * pick the latest one.
2113 attributes_byvalue = fr_hash_table_create(dict_attr_value_hash,
2114 dict_attr_value_cmp,
2116 if (!attributes_byvalue) {
2120 values_byname = fr_hash_table_create(dict_value_name_hash,
2121 dict_value_name_cmp,
2123 if (!values_byname) {
2127 values_byvalue = fr_hash_table_create(dict_value_value_hash,
2128 dict_value_value_cmp,
2130 if (!values_byvalue) {
2134 value_fixup = NULL; /* just to be safe. */
2136 if (my_dict_init(dir, fn, NULL, 0) < 0)
2141 value_fixup_t *this, *next;
2143 for (this = value_fixup; this != NULL; this = next) {
2146 a = dict_attrbyname(this->attrstr);
2149 "dict_init: No ATTRIBUTE \"%s\" defined for VALUE \"%s\"",
2150 this->attrstr, this->dval->name);
2151 return -1; /* leak, but they should die... */
2154 this->dval->attr = a->attr;
2157 * Add the value into the dictionary.
2159 if (!fr_hash_table_replace(values_byname,
2161 fr_strerror_printf("dict_addvalue: Duplicate value name %s for attribute %s", this->dval->name, a->name);
2166 * Allow them to use the old name, but
2167 * prefer the new name when printing
2170 if (!fr_hash_table_finddata(values_byvalue, this->dval)) {
2171 fr_hash_table_replace(values_byvalue,
2177 * Just so we don't lose track of things.
2184 * Walk over all of the hash tables to ensure they're
2185 * initialized. We do this because the threads may perform
2186 * lookups, and we don't want multi-threaded re-ordering
2187 * of the table entries. That would be bad.
2189 fr_hash_table_walk(vendors_byname, null_callback, NULL);
2190 fr_hash_table_walk(vendors_byvalue, null_callback, NULL);
2192 fr_hash_table_walk(attributes_byname, null_callback, NULL);
2193 fr_hash_table_walk(attributes_byvalue, null_callback, NULL);
2195 fr_hash_table_walk(values_byvalue, null_callback, NULL);
2196 fr_hash_table_walk(values_byname, null_callback, NULL);
2202 * Get an attribute by its numerical value.
2204 DICT_ATTR *dict_attrbyvalue(unsigned int attr, unsigned int vendor)
2208 if ((attr > 0) && (attr < 256) && !vendor) return dict_base_attrs[attr];
2211 dattr.vendor = vendor;
2213 return fr_hash_table_finddata(attributes_byvalue, &dattr);
2217 * Get an attribute by its name.
2219 DICT_ATTR *dict_attrbyname(const char *name)
2222 uint32_t buffer[(sizeof(*da) + DICT_ATTR_MAX_NAME_LEN + 3)/4];
2224 if (!name) return NULL;
2226 da = (DICT_ATTR *) buffer;
2227 strlcpy(da->name, name, DICT_ATTR_MAX_NAME_LEN + 1);
2229 return fr_hash_table_finddata(attributes_byname, da);
2233 * Associate a value with an attribute and return it.
2235 DICT_VALUE *dict_valbyattr(unsigned int attr, unsigned int vendor, int value)
2237 DICT_VALUE dval, *dv;
2240 * First, look up aliases.
2243 dval.vendor = vendor;
2244 dval.name[0] = '\0';
2247 * Look up the attribute alias target, and use
2248 * the correct attribute number if found.
2250 dv = fr_hash_table_finddata(values_byname, &dval);
2251 if (dv) dval.attr = dv->value;
2255 return fr_hash_table_finddata(values_byvalue, &dval);
2259 * Get a value by its name, keyed off of an attribute.
2261 DICT_VALUE *dict_valbyname(unsigned int attr, unsigned int vendor, const char *name)
2263 DICT_VALUE *my_dv, *dv;
2264 uint32_t buffer[(sizeof(*my_dv) + DICT_VALUE_MAX_NAME_LEN + 3)/4];
2266 if (!name) return NULL;
2268 my_dv = (DICT_VALUE *) buffer;
2270 my_dv->vendor = vendor;
2271 my_dv->name[0] = '\0';
2274 * Look up the attribute alias target, and use
2275 * the correct attribute number if found.
2277 dv = fr_hash_table_finddata(values_byname, my_dv);
2278 if (dv) my_dv->attr = dv->value;
2280 strlcpy(my_dv->name, name, DICT_VALUE_MAX_NAME_LEN + 1);
2282 return fr_hash_table_finddata(values_byname, my_dv);
2286 * Get the vendor PEC based on the vendor name
2288 * This is efficient only for small numbers of vendors.
2290 int dict_vendorbyname(const char *name)
2293 uint32_t buffer[(sizeof(*dv) + DICT_VENDOR_MAX_NAME_LEN + 3)/4];
2295 if (!name) return 0;
2297 dv = (DICT_VENDOR *) buffer;
2298 strlcpy(dv->name, name, DICT_VENDOR_MAX_NAME_LEN + 1);
2300 dv = fr_hash_table_finddata(vendors_byname, dv);
2303 return dv->vendorpec;
2307 * Return the vendor struct based on the PEC.
2309 DICT_VENDOR *dict_vendorbyvalue(int vendorpec)
2313 dv.vendorpec = vendorpec;
2315 return fr_hash_table_finddata(vendors_byvalue, &dv);