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 <sworley@cumulusnetworks.com>
This commit is contained in:
Stephen Worley 2019-03-26 19:40:23 -04:00
parent 8f8a806fba
commit 2d6cd1f007
3 changed files with 7 additions and 7 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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++;