From 64f37745da704e1ae1b9ac51ef39d2fa6f00baae Mon Sep 17 00:00:00 2001 From: Wesley Coakley Date: Sat, 15 May 2021 02:41:28 -0400 Subject: [PATCH] pbrd: nhg "add" edge case for last in table range When handling the addition of a nhg which would saturate the range of tables PBR is configured to install into, handle this *before* a possible call to pbr_nhgc_alloc during hash query Signed-off-by: Wesley Coakley --- pbrd/pbr_nht.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/pbrd/pbr_nht.c b/pbrd/pbr_nht.c index 824623034d..e40ba22aff 100644 --- a/pbrd/pbr_nht.c +++ b/pbrd/pbr_nht.c @@ -238,16 +238,22 @@ void pbr_nhgroup_add_nexthop_cb(const struct nexthop_group_cmd *nhgc, struct pbr_nexthop_cache pnhc_find = {}; struct pbr_nexthop_cache *pnhc; - if (!pbr_nht_has_unallocated_table()) { - zlog_warn( - "%s: Exhausted all table identifiers; cannot create nexthop-group cache for nexthop-group '%s'", - __func__, nhgc->name); - return; - } - /* find pnhgc by name */ strlcpy(pnhgc_find.name, nhgc->name, sizeof(pnhgc_find.name)); - pnhgc = hash_get(pbr_nhg_hash, &pnhgc_find, pbr_nhgc_alloc); + pnhgc = hash_lookup(pbr_nhg_hash, &pnhgc_find); + + if (!pnhgc) { + /* Check if configured table range is exhausted */ + if (!pbr_nht_has_unallocated_table()) { + zlog_warn( + "%s: Exhausted all table identifiers; cannot create nexthop-group cache for nexthop-group '%s'", + __func__, nhgc->name); + return; + } + + /* No nhgc but range not exhausted? Then alloc it */ + pnhgc = hash_get(pbr_nhg_hash, &pnhgc_find, pbr_nhgc_alloc); + } /* create & insert new pnhc into pnhgc->nhh */ pnhc_find.nexthop = *nhop;