value_node: Add 'idx' member to handle lookup by ifindex.

That's a bit of an ugly layering violation, but it's the easiest way
how the ip-address related code can find the corresponding netdev
node that was created by the link related rtnl code.
This commit is contained in:
Harald Welte 2018-06-04 20:08:21 +02:00
parent 3a964a4e40
commit b6718f7599
2 changed files with 14 additions and 0 deletions

View File

@ -71,6 +71,17 @@ struct value_node *value_node_find_or_add(struct value_node *parent, const char
return vn;
}
struct value_node *value_node_find_by_idx(struct value_node *parent, int idx)
{
struct value_node *vn;
llist_for_each_entry(vn, &parent->children, list) {
if (idx == vn->idx)
return vn;
}
return NULL;
}
void value_node_del(struct value_node *node)
{
/* remove ourselves from the parent */

View File

@ -8,6 +8,8 @@ struct value_node {
struct llist_head list;
/* the display name */
const char *name;
/* additional numeric index (for ifindex matching) */
int idx;
/* the value (if any) */
const char *value;
/* the children (if value == NULL) */
@ -17,5 +19,6 @@ struct value_node {
struct value_node *value_node_add(void *ctx, struct value_node *parent,
const char *name, const char *value);
struct value_node *value_node_find(struct value_node *parent, const char *name);
struct value_node *value_node_find_by_idx(struct value_node *parent, int idx);
struct value_node *value_node_find_or_add(struct value_node *parent, const char *name);
void value_node_del(struct value_node *node);