zebra: Add helper functions for freeing the members of nexthop group hash entries

Add some functions that can be called to free everything that should
have been allocated in a nexthop group hash entry.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
This commit is contained in:
Stephen Worley 2019-03-22 13:07:22 -04:00
parent cced3a2d29
commit b599cd2acc
2 changed files with 41 additions and 22 deletions

View File

@ -328,38 +328,54 @@ struct nhg_hash_entry *zebra_nhg_find(struct nexthop_group *nhg,
lookup.id = id;
lookup.vrf_id = vrf_id;
lookup.afi = afi;
lookup.nhg = *nhg;
lookup.nhg_depends = NULL;
lookup.nhg = nhg;
lookup.nhg_depends = nhg_depends;
if (dep_count)
lookup.nhg_depends = nhg_depends;
nhe = hash_lookup(zrouter.nhgs, &lookup);
if (id)
nhe = zebra_nhg_lookup_id(id);
else
nhe = hash_lookup(zrouter.nhgs, &lookup);
if (!nhe) {
nhe = hash_get(zrouter.nhgs, &lookup, zebra_nhg_alloc);
} else {
if (id) {
/* Duplicate but with different ID from the kernel */
/* The kernel allows duplicate nexthops as long as they
* have different IDs. We are ignoring those to prevent
* syncing problems with the kernel changes.
*/
flog_warn(
EC_ZEBRA_DUPLICATE_NHG_MESSAGE,
"Nexthop Group from with ID (%d) is a duplicate, ignoring",
id);
if (lookup.nhg_depends)
list_delete(&lookup.nhg_depends);
return NULL;
}
zebra_nhg_free_group_depends(nhg, nhg_depends);
}
return nhe;
}
/**
* zebra_nhg_free_group_depends() - Helper function for freeing nexthop_group
* struct and depends
*
* @nhg: Nexthop group
* @nhg_depends: Nexthop group hash entry dependency list
*/
void zebra_nhg_free_group_depends(struct nexthop_group *nhg,
struct list *nhg_depends)
{
if (nhg_depends)
list_delete(&nhg_depends);
if (nhg) {
if (nhg->nexthop)
nexthops_free(nhg->nexthop);
nexthop_group_delete(&nhg);
}
}
/**
* zebra_nhg_free_members() - Free all members in the hash entry struct
*
* @nhe: Nexthop group hash entry
*
* Just use this to free everything but the entry itself.
*/
void zebra_nhg_free_members(struct nhg_hash_entry *nhe)
{
zebra_nhg_free_group_depends(nhe->nhg, nhe->nhg_depends);
}
/**
* zebra_nhg_free() - Free the nexthop group hash entry
*

View File

@ -104,6 +104,9 @@ extern struct nhg_hash_entry *
zebra_nhg_find(struct nexthop_group *nhg, vrf_id_t vrf_id, afi_t afi,
uint32_t id, struct list *nhg_depends, int dep_count);
void zebra_nhg_free_group_depends(struct nexthop_group *nhg,
struct list *nhg_depends);
void zebra_nhg_free_members(struct nhg_hash_entry *nhe);
void zebra_nhg_free(void *arg);
void zebra_nhg_release(struct nhg_hash_entry *nhe);
void zebra_nhg_decrement_ref(struct nhg_hash_entry *nhe);