From: Stephen Worley Date: Fri, 22 Mar 2019 17:07:22 +0000 (-0400) Subject: zebra: Add helper functions for freeing the members of nexthop group hash entries X-Git-Tag: base_7.3~219^2~130 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=b599cd2acceb4ac96e4d3569bb1caaea4f51f266;p=matthieu%2Ffrr.git 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 --- diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index 82bbef3911..789e371da5 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -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 * diff --git a/zebra/zebra_nhg.h b/zebra/zebra_nhg.h index e741cc0cfc..287aaf275f 100644 --- a/zebra/zebra_nhg.h +++ b/zebra/zebra_nhg.h @@ -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);