From: Wesley Coakley Date: Sat, 15 May 2021 06:41:28 +0000 (-0400) Subject: pbrd: nhg "add" edge case for last in table range X-Git-Tag: base_8.1~495^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=64f37745da704e1ae1b9ac51ef39d2fa6f00baae;p=mirror%2Ffrr.git 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 --- 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;