]> git.puffer.fish Git - matthieu/frr.git/commitdiff
pbrd: add logging messages when out of table id's
authorQuentin Young <qlyoung@cumulusnetworks.com>
Wed, 13 Jun 2018 20:00:58 +0000 (20:00 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Wed, 13 Jun 2018 20:00:58 +0000 (20:00 +0000)
* 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 <qlyoung@cumulusnetworks.com>
pbrd/pbr_nht.c
pbrd/pbr_nht.h
pbrd/pbr_vty.c

index a4a9233f72a138a94267e42edc4225adee79bf03..a8cefce84f1db0ed0ee37e5f8074d4e17aa62faf 100644 (file)
@@ -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;
index e6fdbfd04cb838ffb9a0e541c6294550115194c1..d37803fbe32e52fffeb5c0b605715064413254b4 100644 (file)
@@ -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
  */
index 0744ccf700fe7e48b518d7aeb984b48049c07fd3..44e14c5477dff78061faed8f16f4abdecbb7c6f3 100644 (file)
@@ -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);