From 2d6cd1f007c860ad4c76e7efbbb0bf5b4226af0c Mon Sep 17 00:00:00 2001 From: Stephen Worley Date: Tue, 26 Mar 2019 19:40:23 -0400 Subject: [PATCH] zebra: Always copy nhg and depends on nhe alloc Changed our alloc function to just copy the nhg and nhg_depends. This makes the zebra_nhg_find code a little bit cleaner, hopefully preventing bugs. The only issue with this is that it makes us have to loop over the nexthops in a group an extra time for the copies. Signed-off-by: Stephen Worley --- zebra/rt_netlink.c | 3 ++- zebra/zebra_nhg.c | 10 ++++------ zebra/zebra_rib.c | 1 + 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 42daefeea9..ea81d180db 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -2399,12 +2399,13 @@ int netlink_nexthop_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) /* This is a new nexthop group */ nhe = zebra_nhg_find(nhg, vrf_id, afi, id, nhg_depends, dep_count); + zebra_nhg_free_group_depends(nhg, nhg_depends); + if (!nhe) { flog_err( EC_ZEBRA_TABLE_LOOKUP_FAILED, "Zebra failed to find or create a nexthop hash entry for ID (%u) from the kernel", id); - zebra_nhg_free_group_depends(nhg, nhg_depends); return -1; } diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index 140e6a9abf..3c78ce5253 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -185,9 +185,10 @@ static void *zebra_nhg_alloc(void *arg) nhe->nhg_depends = NULL; if (copy->nhg_depends) - nhe->nhg_depends = copy->nhg_depends; + nhe->nhg_depends = nhg_depend_dup_list(copy->nhg_depends); - nhe->nhg = copy->nhg; + nhe->nhg = nexthop_group_new(); + nexthop_group_copy(nhe->nhg, copy->nhg); nhe->vrf_id = copy->vrf_id; nhe->afi = copy->afi; @@ -352,11 +353,8 @@ struct nhg_hash_entry *zebra_nhg_find(struct nexthop_group *nhg, else nhe = hash_lookup(zrouter.nhgs, &lookup); - if (!nhe) { + if (!nhe) nhe = hash_get(zrouter.nhgs, &lookup, zebra_nhg_alloc); - } else { - zebra_nhg_free_group_depends(nhg, nhg_depends); - } return nhe; } diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index e882c9d694..a5b939baa9 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -2662,6 +2662,7 @@ int rib_add_multipath(afi_t afi, safi_t safi, struct prefix *p, if (nhe) { // TODO: Add interface pointer + zebra_nhg_free_group_depends(re->ng, NULL); re->ng = nhe->nhg; re->nhe_id = nhe->id; nhe->refcnt++; -- 2.39.5