From 5463ce26c35c875b56d507ac1b0e25b1f106cff5 Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Thu, 21 Nov 2019 15:05:52 -0500 Subject: [PATCH] zebra: clean up rib and nhg headers Clean up the relationships between zebra's rib and nexthop-group headers as prep for adding a nexthop-group pointer to the route_entry. Signed-off-by: Mark Stapp --- zebra/rib.h | 2 ++ zebra/zebra_mpls.c | 2 +- zebra/zebra_nhg.c | 36 +----------------------------------- zebra/zebra_nhg.h | 7 ++----- zebra/zebra_rib.c | 36 +++++++++++++++++++++++++++++++++++- 5 files changed, 41 insertions(+), 42 deletions(-) diff --git a/zebra/rib.h b/zebra/rib.h index 35aa011c0d..6a7b65c55f 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -35,6 +35,7 @@ #include "if.h" #include "mpls.h" #include "srcdest_table.h" +#include "zebra/zebra_nhg.h" #ifdef __cplusplus extern "C" { @@ -334,6 +335,7 @@ extern void route_entry_nexthop_add(struct route_entry *re, struct nexthop *nexthop); extern void route_entry_copy_nexthops(struct route_entry *re, struct nexthop *nh); +int route_entry_update_nhe(struct route_entry *re, struct nhg_hash_entry *new); #define route_entry_dump(prefix, src, re) _route_entry_dump(__func__, prefix, src, re) extern void _route_entry_dump(const char *func, union prefixconstptr pp, diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c index 6942a37989..3a44db9dc0 100644 --- a/zebra/zebra_mpls.c +++ b/zebra/zebra_mpls.c @@ -2572,7 +2572,7 @@ static void mpls_zebra_nhg_update(struct route_entry *re, afi_t afi, nhe = zebra_nhg_rib_find(0, new_grp, afi); - zebra_nhg_re_update_ref(re, nhe); + route_entry_update_nhe(re, nhe); } static bool mpls_ftn_update_nexthop(int add, struct nexthop *nexthop, diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index 2d7521d8be..1108cc4501 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -1704,7 +1704,7 @@ int nexthop_active_update(struct route_node *rn, struct route_entry *re) new_nhe = zebra_nhg_rib_find(0, &new_grp, rt_afi); - zebra_nhg_re_update_ref(re, new_nhe); + route_entry_update_nhe(re, new_nhe); } if (curr_active) { @@ -1730,40 +1730,6 @@ int nexthop_active_update(struct route_node *rn, struct route_entry *re) return curr_active; } -static void zebra_nhg_re_attach_ref(struct route_entry *re, - struct nhg_hash_entry *new) -{ - re->ng = new->nhg; - re->nhe_id = new->id; - - zebra_nhg_increment_ref(new); -} - -int zebra_nhg_re_update_ref(struct route_entry *re, struct nhg_hash_entry *new) -{ - struct nhg_hash_entry *old = NULL; - int ret = 0; - - if (new == NULL) { - re->ng = NULL; - goto done; - } - - if (re->nhe_id != new->id) { - old = zebra_nhg_lookup_id(re->nhe_id); - - zebra_nhg_re_attach_ref(re, new); - - if (old) - zebra_nhg_decrement_ref(old); - } else if (!re->ng) - /* This is the first time it's being attached */ - zebra_nhg_re_attach_ref(re, new); - -done: - return ret; -} - /* Convert a nhe into a group array */ uint8_t zebra_nhg_nhe2grp(struct nh_grp *grp, struct nhg_hash_entry *nhe, int max_num) diff --git a/zebra/zebra_nhg.h b/zebra/zebra_nhg.h index 1f695433c9..4aa433a9a7 100644 --- a/zebra/zebra_nhg.h +++ b/zebra/zebra_nhg.h @@ -23,11 +23,9 @@ #ifndef __ZEBRA_NHG_H__ #define __ZEBRA_NHG_H__ -#include "zebra/rib.h" +#include "lib/nexthop.h" #include "lib/nexthop_group.h" -#include "zebra/zebra_dplane.h" - /* This struct is used exclusively for dataplane * interaction via a dataplane context. * @@ -201,8 +199,6 @@ zebra_nhg_rib_find(uint32_t id, struct nexthop_group *nhg, afi_t rt_afi); /* Reference counter functions */ extern void zebra_nhg_decrement_ref(struct nhg_hash_entry *nhe); extern void zebra_nhg_increment_ref(struct nhg_hash_entry *nhe); -extern int zebra_nhg_re_update_ref(struct route_entry *re, - struct nhg_hash_entry *nhe); /* Check validity of nhe, if invalid will update dependents as well */ extern void zebra_nhg_check_valid(struct nhg_hash_entry *nhe); @@ -224,5 +220,6 @@ extern void zebra_nhg_dplane_result(struct zebra_dplane_ctx *ctx); extern void zebra_nhg_sweep_table(struct hash *hash); /* Nexthop resolution processing */ +struct route_entry; /* Forward ref to avoid circular includes */ extern int nexthop_active_update(struct route_node *rn, struct route_entry *re); #endif diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 781963793e..31d46e5a26 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -333,6 +333,40 @@ struct nexthop *route_entry_nexthop_blackhole_add(struct route_entry *re, return nexthop; } +static void route_entry_attach_ref(struct route_entry *re, + struct nhg_hash_entry *new) +{ + re->ng = new->nhg; + re->nhe_id = new->id; + + zebra_nhg_increment_ref(new); +} + +int route_entry_update_nhe(struct route_entry *re, struct nhg_hash_entry *new) +{ + struct nhg_hash_entry *old = NULL; + int ret = 0; + + if (new == NULL) { + re->ng = NULL; + goto done; + } + + if (re->nhe_id != new->id) { + old = zebra_nhg_lookup_id(re->nhe_id); + + route_entry_attach_ref(re, new); + + if (old) + zebra_nhg_decrement_ref(old); + } else if (!re->ng) + /* This is the first time it's being attached */ + route_entry_attach_ref(re, new); + +done: + return ret; +} + struct route_entry *rib_match(afi_t afi, safi_t safi, vrf_id_t vrf_id, union g_addr *addr, struct route_node **rn_out) { @@ -2708,7 +2742,7 @@ int rib_add_multipath(afi_t afi, safi_t safi, struct prefix *p, * level protocols, as the refcnt might be wrong, since it checks * if old_id != new_id. */ - zebra_nhg_re_update_ref(re, nhe); + route_entry_update_nhe(re, nhe); /* Make it sure prefixlen is applied to the prefix. */ apply_mask(p); -- 2.39.5