From 144a1b34dfc37fdd1174e7a2f150f2315730d8f7 Mon Sep 17 00:00:00 2001 From: Stephen Worley Date: Tue, 14 May 2019 16:26:20 -0700 Subject: [PATCH] zebra: Put NHE ref updating into a function When the referenced NHE changes for a route_entry, use this function to handle it. Signed-off-by: Stephen Worley --- zebra/zebra_nhg.c | 33 ++++++++++++++++++++++----------- zebra/zebra_nhg.h | 3 +++ zebra/zebra_rib.c | 5 +---- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index f43aa2f31e..1fd4ec4a9c 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -1493,17 +1493,7 @@ int nexthop_active_update(struct route_node *rn, struct route_entry *re) new_nhe = zebra_nhg_rib_find(0, &new_grp, re->vrf_id, rt_afi); - if (new_nhe && (re->nhe_id != new_nhe->id)) { - struct nhg_hash_entry *old_nhe = - zebra_nhg_lookup_id(re->nhe_id); - - re->ng = new_nhe->nhg; - re->nhe_id = new_nhe->id; - - zebra_nhg_increment_ref(new_nhe); - if (old_nhe) - zebra_nhg_decrement_ref(old_nhe); - } + zebra_nhg_re_update_ref(re, new_nhe); } if (curr_active) { @@ -1532,6 +1522,27 @@ int nexthop_active_update(struct route_node *rn, struct route_entry *re) return curr_active; } +int zebra_nhg_re_update_ref(struct route_entry *re, struct nhg_hash_entry *new) +{ + struct nhg_hash_entry *old = NULL; + + if (!new) + return -1; + + if (re->nhe_id != new->id) { + old = zebra_nhg_lookup_id(re->nhe_id); + + re->ng = new->nhg; + re->nhe_id = new->id; + + zebra_nhg_increment_ref(new); + if (old) + zebra_nhg_decrement_ref(old); + } + + return 0; +} + /* Convert a nhe into a group array */ uint8_t zebra_nhg_nhe2grp(struct nh_grp *grp, struct nhg_hash_entry *nhe) { diff --git a/zebra/zebra_nhg.h b/zebra/zebra_nhg.h index c6ac7d4706..ef8b2730fb 100644 --- a/zebra/zebra_nhg.h +++ b/zebra/zebra_nhg.h @@ -229,6 +229,9 @@ void zebra_nhg_set_if(struct nhg_hash_entry *nhe, struct interface *ifp); extern int nexthop_active_update(struct route_node *rn, struct route_entry *re); +extern int zebra_nhg_re_update_ref(struct route_entry *re, + struct nhg_hash_entry *nhe); + extern uint8_t zebra_nhg_nhe2grp(struct nh_grp *grp, struct nhg_hash_entry *nhe); diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 438923e232..8fe673cb31 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -2772,13 +2772,10 @@ int rib_add_multipath(afi_t afi, safi_t safi, struct prefix *p, XFREE(MTYPE_RE, re); return -1; } - - re->nhe_id = nhe->id; } /* Attach the re to the nhe's nexthop group */ - zebra_nhg_increment_ref(nhe); - re->ng = nhe->nhg; + zebra_nhg_re_update_ref(re, nhe); /* Make it sure prefixlen is applied to the prefix. */ apply_mask(p);