Skip to content

Commit

Permalink
pbrd: add logging messages when out of table id's
Browse files Browse the repository at this point in the history
* Add log messages to indicate when we have run out of table IDs
* Increase minimum range size to 1000 to reduce risk of hitting this

Signed-off-by: Quentin Young <[email protected]>
qlyoung committed Jun 13, 2018
1 parent 56c6f60 commit a4044dc
Showing 3 changed files with 40 additions and 11 deletions.
38 changes: 31 additions & 7 deletions pbrd/pbr_nht.c
Original file line number Diff line number Diff line change
@@ -192,7 +192,7 @@ static void *pbr_nhgc_alloc(void *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);
@@ -218,6 +218,9 @@ void pbr_nhgroup_add_cb(const char *name)

pnhgc = pbr_nht_add_group(name);

if (!pnhgc)
return;

DEBUGD(&pbr_dbg_nht, "%s: Added nexthop-group %s", __PRETTY_FUNCTION__,
name);

@@ -234,6 +237,13 @@ 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_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);
@@ -268,7 +278,7 @@ void pbr_nhgroup_del_nexthop_cb(const struct nexthop_group_cmd *nhgc,

/* 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;
@@ -487,6 +497,14 @@ void pbr_nht_add_individual_nexthop(struct pbr_map_sequence *pbrms)
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);

@@ -547,11 +565,18 @@ struct pbr_nexthop_group_cache *pbr_nht_add_group(const char *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;
}

@@ -709,8 +734,7 @@ static int pbr_nhg_hash_equal(const void *arg1, const void *arg2)
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;
@@ -723,7 +747,7 @@ uint32_t pbr_nht_get_next_tableid(void)
}

if (found) {
nhg_tableid[i] = true;
nhg_tableid[i] = !peek;
return i;
} else
return 0;
8 changes: 6 additions & 2 deletions pbrd/pbr_nht.h
Original file line number Diff line number Diff line change
@@ -56,9 +56,13 @@ extern void pbr_nht_write_table_range(struct vty *vty);
extern void pbr_nht_set_tableid_range(uint32_t low, uint32_t high);

/*
* Get the next tableid to use for installation
* Get the next tableid to use for installation.
*
* peek
* If set to true, retrieves the next ID without marking it used. The next
* call will return the same ID.
*/
extern uint32_t pbr_nht_get_next_tableid(void);
extern uint32_t pbr_nht_get_next_tableid(bool peek);
/*
* Get the next rule number to use for installation
*/
5 changes: 3 additions & 2 deletions pbrd/pbr_vty.c
Original file line number Diff line number Diff line change
@@ -97,12 +97,13 @@ DEFPY(pbr_set_table_range,
{
/* upper bound is 2^32 - 2^10 */
int ret = CMD_WARNING;
const int minrange = 1000;

/* validate given bounds */
if (lb > ub)
vty_out(vty, "%% Lower bound must be less than upper bound\n");
else if (ub - lb < 10)
vty_out(vty, "%% Range breadth must be at least 10\n");
else if (ub - lb < minrange)
vty_out(vty, "%% Range breadth must be at least %d\n", minrange);
else {
ret = CMD_SUCCESS;
pbr_nht_set_tableid_range((uint32_t) lb, (uint32_t) ub);

0 comments on commit a4044dc

Please sign in to comment.