From 65f137fe3c3b5d3defe21735ddd6990bcb20ab4f Mon Sep 17 00:00:00 2001 From: Stephen Worley Date: Thu, 22 Apr 2021 17:16:57 -0400 Subject: [PATCH] zebra: add PROTO_OWNED macro for NHE id bounds checking Add a PROTO_OWNED macro for code readability when checking ID bounds for whether a NHG is proto owned. Signed-off-by: Stephen Worley --- zebra/zebra_nhg.c | 8 ++++---- zebra/zebra_nhg.h | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index 7edf022892..0f3c0a147e 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -2559,7 +2559,7 @@ int nexthop_active_update(struct route_node *rn, struct route_entry *re) struct nhg_hash_entry *curr_nhe; uint32_t curr_active = 0, backup_active = 0; - if (re->nhe->id >= ZEBRA_NHG_PROTO_LOWER) + if (PROTO_OWNED(re->nhe)) return proto_nhg_nexthop_active_update(&re->nhe->nhg); afi_t rt_afi = family2afi(rn->p.family); @@ -2861,13 +2861,13 @@ void zebra_nhg_dplane_result(struct zebra_dplane_ctx *ctx) zebra_nhg_handle_install(nhe); /* If daemon nhg, send it an update */ - if (nhe->id >= ZEBRA_NHG_PROTO_LOWER) + if (PROTO_OWNED(nhe)) zsend_nhg_notify(nhe->type, nhe->zapi_instance, nhe->zapi_session, nhe->id, ZAPI_NHG_INSTALLED); } else { /* If daemon nhg, send it an update */ - if (nhe->id >= ZEBRA_NHG_PROTO_LOWER) + if (PROTO_OWNED(nhe)) zsend_nhg_notify(nhe->type, nhe->zapi_instance, nhe->zapi_session, nhe->id, ZAPI_NHG_FAIL_INSTALL); @@ -3201,7 +3201,7 @@ static void zebra_nhg_score_proto_entry(struct hash_bucket *bucket, void *arg) iter = arg; /* Needs to match type and outside zebra ID space */ - if (nhe->type == iter->type && nhe->id >= ZEBRA_NHG_PROTO_LOWER) { + if (nhe->type == iter->type && PROTO_OWNED(nhe)) { if (IS_ZEBRA_DEBUG_NHG_DETAIL) zlog_debug( "%s: found nhe %p (%u), vrf %d, type %s after client disconnect", diff --git a/zebra/zebra_nhg.h b/zebra/zebra_nhg.h index 38015bf557..0489f059be 100644 --- a/zebra/zebra_nhg.h +++ b/zebra/zebra_nhg.h @@ -147,6 +147,8 @@ enum nhg_type { /* Is this an NHE owned by zebra and not an upper level protocol? */ #define ZEBRA_OWNED(NHE) (NHE->type == ZEBRA_ROUTE_NHG) +#define PROTO_OWNED(NHE) (NHE->id >= ZEBRA_NHG_PROTO_LOWER) + /* * Backup nexthops: this is a group object itself, so * that the backup nexthops can use the same code as a normal object. -- 2.39.5