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