From 7483dcbe298bbc04f25432a46fa3aab83c963520 Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Fri, 17 Jul 2020 13:07:31 -0400 Subject: [PATCH] zebra: add a route_entry flag for FIB-specific nexthops Add a route_entry flag to indicate the presence of a fib (installed) list of nexthops - more explicit and clearer. Signed-off-by: Mark Stapp --- zebra/rib.h | 20 +++++++++++++------- zebra/zebra_rib.c | 25 ++++++++++++------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/zebra/rib.h b/zebra/rib.h index ec992974fa..6ec9241b73 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -144,6 +144,10 @@ struct route_entry { #define ROUTE_ENTRY_INSTALLED 0x10 /* Route has Failed installation into the Data Plane in some manner */ #define ROUTE_ENTRY_FAILED 0x20 +/* Route has a 'fib' set of nexthops, probably because the installed set + * differs from the rib/normal set of nexthops. + */ +#define ROUTE_ENTRY_USE_FIB_NHG 0x40 /* Sequence value incremented for each dataplane operation */ uint32_t dplane_sequence; @@ -526,26 +530,28 @@ DECLARE_HOOK(rib_update, (struct route_node * rn, const char *reason), (rn, reason)) /* - * Access active nexthop-group, either RIB or FIB version + * Access installed/fib nexthops, which may be a subset of the + * rib nexthops. */ static inline struct nexthop_group *rib_get_fib_nhg(struct route_entry *re) { - if (re->fib_ng.nexthop) + /* If the fib set is a subset of the active rib set, + * use the dedicated fib list. + */ + if (CHECK_FLAG(re->status, ROUTE_ENTRY_USE_FIB_NHG)) return &(re->fib_ng); else return &(re->nhe->nhg); } /* - * Access active nexthop-group, either RIB or FIB version + * Access backup nexthop-group that represents the installed backup nexthops; + * any installed backup will be on the fib list. */ 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); + return &(re->fib_backup_ng); } extern void zebra_vty_init(void); diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index c36bb622f4..1e422f52d7 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -472,6 +472,7 @@ void rib_install_kernel(struct route_node *rn, struct route_entry *re, SET_FLAG(old->status, ROUTE_ENTRY_QUEUED); /* Free old FIB nexthop group */ + UNSET_FLAG(old->status, ROUTE_ENTRY_USE_FIB_NHG); if (old->fib_ng.nexthop) { nexthops_free(old->fib_ng.nexthop); old->fib_ng.nexthop = NULL; @@ -574,6 +575,7 @@ static void rib_uninstall(struct route_node *rn, struct route_entry *re) nexthops_free(re->fib_ng.nexthop); re->fib_ng.nexthop = NULL; } + UNSET_FLAG(re->status, ROUTE_ENTRY_USE_FIB_NHG); for (ALL_NEXTHOPS(re->nhe->nhg, nexthop)) UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); @@ -1376,7 +1378,7 @@ static bool rib_update_nhg_from_ctx(struct nexthop_group *re_nhg, continue; /* Check for a FIB nexthop corresponding to the RIB nexthop */ - if (nexthop_same(ctx_nexthop, nexthop) == false) { + if (!nexthop_same(ctx_nexthop, nexthop)) { /* If the FIB doesn't know about the nexthop, * it's not installed */ @@ -1491,7 +1493,7 @@ static bool rib_update_re_from_ctx(struct route_entry *re, VRF_LOGNAME(vrf), re->vrf_id, dest_str); goto check_backups; - } else if (re->fib_ng.nexthop) { + } else if (CHECK_FLAG(re->status, ROUTE_ENTRY_USE_FIB_NHG)) { /* * Free stale fib list and move on to check the rib nhg. */ @@ -1502,6 +1504,8 @@ static bool rib_update_re_from_ctx(struct route_entry *re, nexthops_free(re->fib_ng.nexthop); re->fib_ng.nexthop = NULL; + UNSET_FLAG(re->status, ROUTE_ENTRY_USE_FIB_NHG); + /* Note that the installed nexthops have changed */ changed_p = true; } else { @@ -1547,20 +1551,15 @@ no_nexthops: */ if (IS_ZEBRA_DEBUG_RIB) zlog_debug( - "%s(%u):%s update_from_ctx(): changed %s, adding new fib nhg", + "%s(%u):%s update_from_ctx(): changed %s, adding new fib nhg%s", VRF_LOGNAME(vrf), re->vrf_id, dest_str, - (changed_p ? "true" : "false")); + (changed_p ? "true" : "false"), + ctxnhg->nexthop != NULL ? "" : " (empty)"); + /* Set the flag about the dedicated fib list */ + SET_FLAG(re->status, ROUTE_ENTRY_USE_FIB_NHG); if (ctxnhg->nexthop) copy_nexthops(&(re->fib_ng.nexthop), ctxnhg->nexthop, NULL); - else { - /* Bit of a special case when the fib has _no_ installed - * nexthops. - */ - nexthop = nexthop_new(); - nexthop->type = NEXTHOP_TYPE_IPV4; - _nexthop_add(&(re->fib_ng.nexthop), nexthop); - } check_backups: @@ -1612,7 +1611,7 @@ check_backups: } /* - * If a FIB backup nexthop set exists: attach a copy + * If a FIB backup nexthop set exists, attach a copy * to the route if any backup is installed */ if (ctxnhg && ctxnhg->nexthop) { -- 2.39.5