From 4db01e79142d33c674ba315bb64bcb8430e5fc13 Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Fri, 22 May 2020 16:36:30 -0400 Subject: [PATCH] zebra: add fib nhg for backups, revise api Add an nhg for the fib-installed backup nexthops; rename an api to access the fib-installed nexthop nhg. Signed-off-by: Mark Stapp --- zebra/rib.h | 18 ++++++++++++++++-- zebra/zebra_dplane.c | 2 +- zebra/zebra_pw.c | 4 ++-- zebra/zebra_rib.c | 4 ++-- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/zebra/rib.h b/zebra/rib.h index a024b6dfaa..ec992974fa 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -94,9 +94,11 @@ struct route_entry { struct nhg_hash_entry *nhe; /* Nexthop group from FIB (optional), reflecting what is actually - * installed in the FIB if that differs. + * installed in the FIB if that differs. The 'backup' group is used + * when backup nexthops are present in the route's nhg. */ struct nexthop_group fib_ng; + struct nexthop_group fib_backup_ng; /* Nexthop group hash entry ID */ uint32_t nhe_id; @@ -526,7 +528,7 @@ DECLARE_HOOK(rib_update, (struct route_node * rn, const char *reason), /* * Access active nexthop-group, either RIB or FIB version */ -static inline struct nexthop_group *rib_active_nhg(struct route_entry *re) +static inline struct nexthop_group *rib_get_fib_nhg(struct route_entry *re) { if (re->fib_ng.nexthop) return &(re->fib_ng); @@ -534,6 +536,18 @@ static inline struct nexthop_group *rib_active_nhg(struct route_entry *re) return &(re->nhe->nhg); } +/* + * Access active nexthop-group, either RIB or FIB version + */ +static inline struct nexthop_group *rib_get_fib_backup_nhg( + struct route_entry *re) +{ + if (re->fib_backup_ng.nexthop) + return &(re->fib_backup_ng); + else + return zebra_nhg_get_backup_nhg(re->nhe); +} + extern void zebra_vty_init(void); extern pid_t pid; diff --git a/zebra/zebra_dplane.c b/zebra/zebra_dplane.c index 7e7bf1410c..290abf7b34 100644 --- a/zebra/zebra_dplane.c +++ b/zebra/zebra_dplane.c @@ -2473,7 +2473,7 @@ dplane_route_notif_update(struct route_node *rn, new_ctx->u.rinfo.zd_ng.nexthop = NULL; copy_nexthops(&(new_ctx->u.rinfo.zd_ng.nexthop), - (rib_active_nhg(re))->nexthop, NULL); + (rib_get_fib_nhg(re))->nexthop, NULL); for (ALL_NEXTHOPS(new_ctx->u.rinfo.zd_ng, nexthop)) UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); diff --git a/zebra/zebra_pw.c b/zebra/zebra_pw.c index 8f0c964c18..2328ab650a 100644 --- a/zebra/zebra_pw.c +++ b/zebra/zebra_pw.c @@ -550,7 +550,7 @@ static void vty_show_mpls_pseudowire_detail(struct vty *vty) re = rib_match(family2afi(pw->af), SAFI_UNICAST, pw->vrf_id, &pw->nexthop, NULL); if (re) { - for (ALL_NEXTHOPS_PTR(rib_active_nhg(re), nexthop)) { + for (ALL_NEXTHOPS_PTR(rib_get_fib_nhg(re), nexthop)) { snprintfrr(buf_nh, sizeof(buf_nh), "%pNHv", nexthop); vty_out(vty, " Next Hop: %s\n", buf_nh); @@ -604,7 +604,7 @@ static void vty_show_mpls_pseudowire(struct zebra_pw *pw, json_object *json_pws) re = rib_match(family2afi(pw->af), SAFI_UNICAST, pw->vrf_id, &pw->nexthop, NULL); if (re) { - for (ALL_NEXTHOPS_PTR(rib_active_nhg(re), nexthop)) { + for (ALL_NEXTHOPS_PTR(rib_get_fib_nhg(re), nexthop)) { json_nexthop = json_object_new_object(); snprintfrr(buf_nh, sizeof(buf_nh), "%pNHv", nexthop); json_object_string_add(json_nexthop, "nexthop", buf_nh); diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 31582dcb3d..d07542ba66 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -1931,7 +1931,7 @@ static void rib_process_dplane_notify(struct zebra_dplane_ctx *ctx) start_count = 0; if (CHECK_FLAG(re->status, ROUTE_ENTRY_INSTALLED)) { - for (ALL_NEXTHOPS_PTR(rib_active_nhg(re), nexthop)) { + for (ALL_NEXTHOPS_PTR(rib_get_fib_nhg(re), nexthop)) { if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB)) start_count++; } @@ -1956,7 +1956,7 @@ static void rib_process_dplane_notify(struct zebra_dplane_ctx *ctx) */ end_count = 0; - for (ALL_NEXTHOPS_PTR(rib_active_nhg(re), nexthop)) { + for (ALL_NEXTHOPS_PTR(rib_get_fib_nhg(re), nexthop)) { if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB)) end_count++; } -- 2.39.5