Skip to content

Commit

Permalink
Updated dictionary functions in preparation for new decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Feb 16, 2013
1 parent 7af70eb commit 5a2a40b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/include/libradius.h
Expand Up @@ -292,7 +292,10 @@ const DICT_ATTR *dict_attrbyvalue(unsigned int attr, unsigned int vendor);
const DICT_ATTR *dict_attrbyname(const char *attr);
const DICT_ATTR *dict_attrbytype(unsigned int attr, unsigned int vendor,
PW_TYPE type);
const DICT_ATTR *dict_attrbyparent(const DICT_ATTR *parent, unsigned int attr);
const DICT_ATTR *dict_attrbyparent(const DICT_ATTR *parent, unsigned int attr,
unsigned int vendor);
int dict_attr_child(const DICT_ATTR *parent,
unsigned int *pattr, unsigned int *pvendor);
DICT_VALUE *dict_valbyattr(unsigned int attr, unsigned int vendor, int val);
DICT_VALUE *dict_valbyname(unsigned int attr, unsigned int vendor, const char *val);
const char *dict_valnamebyattr(unsigned int attr, unsigned int vendor, int value);
Expand Down
60 changes: 52 additions & 8 deletions src/lib/dict.c
Expand Up @@ -2805,19 +2805,34 @@ const DICT_ATTR *dict_attrbytype(unsigned int attr, unsigned int vendor,
}


/*
* Get an attribute by it's numerical value, and the parent
/**
* @brief Using a parent and attr/vendor, find a child attr/vendor
*/
const DICT_ATTR *dict_attrbyparent(const DICT_ATTR *parent, unsigned int attr)
int dict_attr_child(const DICT_ATTR *parent,
unsigned int *pattr, unsigned int *pvendor)
{
unsigned int attr, vendor;
DICT_ATTR dattr;

if (!parent) return NULL;
if (!parent || !pattr || !pvendor) return FALSE;

attr = *pattr;
vendor = *pvendor;

/*
* Only TLVs can have children
* Only some types can have children
*/
if (!parent->flags.has_tlv) return NULL;
switch (parent->type) {
default: return FALSE;

case PW_TYPE_TLV:
case PW_TYPE_EVS:
case PW_TYPE_EXTENDED:
case PW_TYPE_LONG_EXTENDED:
break;
}

if ((vendor == 0) && (parent->vendor != 0)) return FALSE;

/*
* Bootstrap by starting off with the parents values.
Expand All @@ -2837,6 +2852,7 @@ const DICT_ATTR *dict_attrbyparent(const DICT_ATTR *parent, unsigned int attr)
*/
if (!dattr.vendor) {
dattr.vendor = parent->attr * FR_MAX_VENDOR;
dattr.vendor |= vendor;
dattr.attr = attr;

} else {
Expand All @@ -2846,7 +2862,7 @@ const DICT_ATTR *dict_attrbyparent(const DICT_ATTR *parent, unsigned int attr)
* Trying to nest too deep. It's an error
*/
if (parent->attr & (fr_attr_mask[MAX_TLV_NEST] << fr_attr_shift[MAX_TLV_NEST])) {
return NULL;
return FALSE;
}

for (i = MAX_TLV_NEST - 1; i >= 0; i--) {
Expand All @@ -2856,10 +2872,38 @@ const DICT_ATTR *dict_attrbyparent(const DICT_ATTR *parent, unsigned int attr)
}
}

return NULL;
return FALSE;
}

find:
#if 0
fprintf(stderr, "LOOKING FOR %08x %08x + %08x %08x --> %08x %08x\n",
parent->vendor, parent->attr, attr, vendor,
dattr.vendor, dattr.attr);
#endif

*pattr = dattr.attr;
*pvendor = dattr.vendor;
return TRUE;
}

/*
* Get an attribute by it's numerical value, and the parent
*/
const DICT_ATTR *dict_attrbyparent(const DICT_ATTR *parent,
unsigned int attr, unsigned int vendor)
{
unsigned int my_attr, my_vendor;
DICT_ATTR dattr;

my_attr = attr;
my_vendor = vendor;

if (!dict_attr_child(parent, &my_attr, &my_vendor)) return NULL;

dattr.attr = my_attr;
dattr.vendor = my_vendor;

return fr_hash_table_finddata(attributes_byvalue, &dattr);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/radius.c
Expand Up @@ -3341,7 +3341,7 @@ static ssize_t data2vp_tlvs(const RADIUS_PACKET *packet,

switch (dv_type) {
case 1:
da = dict_attrbyparent(parent, data[0]);
da = dict_attrbyparent(parent, data[0], 0);
if (!da) {
VP_TRACE("No parent for %u\n", data[0]);
goto raw;
Expand Down

0 comments on commit 5a2a40b

Please sign in to comment.