From 9834bb52aebb46fc4ba85e959cc98adda996a4b3 Mon Sep 17 00:00:00 2001 From: Stephen Worley Date: Tue, 2 Jul 2019 01:04:29 -0400 Subject: [PATCH] zebra: Resolved nh change, inc refcnt by rt refcnt When the resolved nexthop changes, we should increment the new resolved NHE by the refcnt for the unresolved NHE being used by the routes and decrement the old one by the same amount. Before, we were simple incrementing by one, causing incorrect refcnts to occur. Signed-off-by: Stephen Worley --- zebra/zebra_nhg.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index ebe507a73c..436783065d 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -1364,13 +1364,12 @@ int nexthop_active_update(struct route_node *rn, struct route_entry *re) /* Add new resolved */ zebra_nhg_depends_add(nhe, new_resolved); zebra_nhg_dependents_add(new_resolved, nhe); - /* - * In case the new == old, we increment - * first and then decrement - */ - zebra_nhg_increment_ref(new_resolved); - if (old_resolved) - zebra_nhg_decrement_ref(old_resolved); + + if (old_resolved && new_resolved->id != old_resolved->id) { + new_resolved->refcnt+=nhe->refcnt; + old_resolved->refcnt-=nhe->refcnt; + } else if (!old_resolved) + zebra_nhg_increment_ref(new_resolved); SET_FLAG(nhe->flags, NEXTHOP_GROUP_RECURSIVE); } else