return nhrc;
}
-static int pbr_nhrc_hash_equal(const void *arg1, const void *arg2)
+static bool pbr_nhrc_hash_equal(const void *arg1, const void *arg2)
{
const struct nexthop *nh1, *nh2;
return key;
}
-static int pbr_nh_hash_equal(const void *arg1, const void *arg2)
+static bool pbr_nh_hash_equal(const void *arg1, const void *arg2)
{
const struct pbr_nexthop_cache *pbrnc1 =
(const struct pbr_nexthop_cache *)arg1;
(const struct pbr_nexthop_cache *)arg2;
if (pbrnc1->nexthop->vrf_id != pbrnc2->nexthop->vrf_id)
- return 0;
+ return false;
if (pbrnc1->nexthop->ifindex != pbrnc2->nexthop->ifindex)
- return 0;
+ return false;
if (pbrnc1->nexthop->type != pbrnc2->nexthop->type)
- return 0;
+ return false;
switch (pbrnc1->nexthop->type) {
case NEXTHOP_TYPE_IFINDEX:
- return 1;
+ return true;
case NEXTHOP_TYPE_IPV4_IFINDEX:
case NEXTHOP_TYPE_IPV4:
return pbrnc1->nexthop->gate.ipv4.s_addr
== pbrnc2->nexthop->gate.ipv4.s_addr;
case NEXTHOP_TYPE_IPV6_IFINDEX:
case NEXTHOP_TYPE_IPV6:
- return !memcmp(&pbrnc1->nexthop->gate.ipv6,
- &pbrnc2->nexthop->gate.ipv6, 16);
+ return !!memcmp(&pbrnc1->nexthop->gate.ipv6,
+ &pbrnc2->nexthop->gate.ipv6, 16);
case NEXTHOP_TYPE_BLACKHOLE:
return pbrnc1->nexthop->bh_type == pbrnc2->nexthop->bh_type;
}
/*
* We should not get here
*/
- return 0;
+ return false;
}
static void pbr_nhgc_delete(struct pbr_nexthop_group_cache *p)
new = XCALLOC(MTYPE_PBR_NHG, sizeof(*new));
strcpy(new->name, pnhgc->name);
- new->table_id = pbr_nht_get_next_tableid();
+ new->table_id = pbr_nht_get_next_tableid(false);
DEBUGD(&pbr_dbg_nht, "%s: NHT: %s assigned Table ID: %u",
__PRETTY_FUNCTION__, new->name, new->table_id);
pnhgc = pbr_nht_add_group(name);
+ if (!pnhgc)
+ return;
+
DEBUGD(&pbr_dbg_nht, "%s: Added nexthop-group %s", __PRETTY_FUNCTION__,
name);
struct pbr_nexthop_cache pnhc_find = {};
struct pbr_nexthop_cache *pnhc;
+ if (!pbr_nht_get_next_tableid(true)) {
+ zlog_warn(
+ "%s: Exhausted all table identifiers; cannot create nexthop-group cache for nexthop-group '%s'",
+ __PRETTY_FUNCTION__, 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);
/* 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);
/* delete pnhc from pnhgc->nhh */
pnhc_find.nexthop = (struct nexthop *)nhop;
memset(&find, 0, sizeof(find));
pbr_nht_nexthop_make_name(pbrms->parent->name, PBR_NHC_NAMELEN,
pbrms->seqno, find.name);
+
+ if (!pbr_nht_get_next_tableid(true)) {
+ zlog_warn(
+ "%s: Exhausted all table identifiers; cannot create nexthop-group cache for nexthop-group '%s'",
+ __PRETTY_FUNCTION__, find.name);
+ return;
+ }
+
if (!pbrms->internal_nhg_name)
pbrms->internal_nhg_name = XSTRDUP(MTYPE_TMP, find.name);
struct pbr_nexthop_group_cache *pnhgc;
struct pbr_nexthop_group_cache lookup;
+ if (!pbr_nht_get_next_tableid(true)) {
+ zlog_warn(
+ "%s: Exhausted all table identifiers; cannot create nexthop-group cache for nexthop-group '%s'",
+ __PRETTY_FUNCTION__, name);
+ return NULL;
+ }
+
nhgc = nhgc_find(name);
if (!nhgc) {
- zlog_warn("%s: Could not find group %s to add",
- __PRETTY_FUNCTION__, name);
+ DEBUGD(&pbr_dbg_nht, "%s: Could not find nhgc with name: %s\n",
+ __PRETTY_FUNCTION__, name);
return NULL;
}
pnhgc);
for (ALL_NEXTHOPS(nhgc->nhg, nhop)) {
- struct pbr_nexthop_cache lookup;
+ struct pbr_nexthop_cache lookupc;
struct pbr_nexthop_cache *pnhc;
- lookup.nexthop = nhop;
- pnhc = hash_lookup(pnhgc->nhh, &lookup);
+ lookupc.nexthop = nhop;
+ pnhc = hash_lookup(pnhgc->nhh, &lookupc);
if (!pnhc) {
- pnhc = hash_get(pnhgc->nhh, &lookup, pbr_nh_alloc);
+ pnhc = hash_get(pnhgc->nhh, &lookupc, pbr_nh_alloc);
pnhc->parent = pnhgc;
}
}
return jhash(&nhgc->name, strlen(nhgc->name), 0x52c34a96);
}
-static int pbr_nhg_hash_equal(const void *arg1, const void *arg2)
+static bool pbr_nhg_hash_equal(const void *arg1, const void *arg2)
{
const struct pbr_nexthop_group_cache *nhgc1 =
(const struct pbr_nexthop_group_cache *)arg1;
return !strcmp(nhgc1->name, nhgc2->name);
}
-
-uint32_t pbr_nht_get_next_tableid(void)
+uint32_t pbr_nht_get_next_tableid(bool peek)
{
uint32_t i;
bool found = false;
}
if (found) {
- nhg_tableid[i] = true;
+ nhg_tableid[i] = !peek;
return i;
} else
return 0;