interface: add lif_interface_collection_inherit() (ref #2)

This commit is contained in:
Ariadne Conill 2020-08-04 11:46:10 -06:00
parent 0eb25f1d62
commit 3d5ca9050e
2 changed files with 31 additions and 0 deletions

View file

@ -214,3 +214,33 @@ lif_interface_collection_delete(struct lif_dict *collection, struct lif_interfac
lif_dict_delete_entry(collection, entry);
}
bool
lif_interface_collection_inherit(struct lif_interface *interface, struct lif_dict *collection, const char *ifname)
{
struct lif_interface *parent = lif_interface_collection_find(collection, ifname);
if (parent == NULL)
return false;
/* copy the variables */
struct lif_node *iter;
LIF_DICT_FOREACH(iter, &parent->vars)
{
struct lif_dict_entry *entry = iter->data;
if (!strcmp(entry->key, "address"))
{
struct lif_address *addr = calloc(1, sizeof *addr);
struct lif_address *other_addr = entry->data;
memcpy(addr, other_addr, sizeof *addr);
lif_dict_add(&interface->vars, entry->key, addr);
}
else
lif_dict_add(&interface->vars, entry->key, strdup(entry->data));
}
return true;
}

View file

@ -73,6 +73,7 @@ extern void lif_interface_collection_init(struct lif_dict *collection);
extern void lif_interface_collection_fini(struct lif_dict *collection);
extern struct lif_interface *lif_interface_collection_find(struct lif_dict *collection, const char *ifname);
extern struct lif_interface *lif_interface_collection_upsert(struct lif_dict *collection, struct lif_interface *interface);
extern bool lif_interface_collection_inherit(struct lif_interface *interface, struct lif_dict *collection, const char *ifname);
extern void lif_interface_collection_delete(struct lif_dict *collection, struct lif_interface *interface);
#endif