]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: NHG ID bounds macros
authorStephen Worley <sworley@cumulusnetworks.com>
Wed, 13 May 2020 18:32:13 +0000 (14:32 -0400)
committerStephen Worley <sworley@cumulusnetworks.com>
Mon, 28 Sep 2020 16:40:59 +0000 (12:40 -0400)
Determine the NHG ID spacing and lower bound with ZEBRA_ROUTE_MAX
in macros.

Directly set the upperbound to be the lower 28bits of the uint32_t ID
space (the top 4 are reserved for l2-NHGs). Round that number down
a bit to make it more even.

Convert all former lower_bound calls to just use the macro.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
lib/zclient.c
lib/zclient.h
zebra/rt_netlink.c
zebra/zebra_nhg.c

index deb5f519bd55de43d5a2217602e8e7cdfa74a6cc..b73dc688fb0df63d075951d5ef275718284bc0d7 100644 (file)
@@ -4081,13 +4081,5 @@ uint32_t zclient_get_nhg_start(uint32_t proto)
 {
        assert(proto < ZEBRA_ROUTE_MAX);
 
-       return ZEBRA_NHG_SPACING * proto;
-}
-
-/*
- * Where do routing protocols IDs start overall (first ID after zebra)
- */
-uint32_t zclient_get_nhg_lower_bound()
-{
-       return ZEBRA_NHG_SPACING * (ZEBRA_ROUTE_CONNECT + 1);
+       return ZEBRA_NHG_PROTO_SPACING * proto;
 }
index db5e1ce5b91815105d1f4fb9c3db7d7cb4c7d5cd..3ac9ca945641d7704e2435d1ef3bc258010a942e 100644 (file)
@@ -686,13 +686,20 @@ struct zclient_options {
 extern struct zclient_options zclient_options_default;
 
 /*
+ * We reserve the top 4 bits for l2-NHG, everything else
+ * is for zebra/proto l3-NHG.
+ *
  * Each client is going to get it's own nexthop group space
- * and we'll separate them by 50 million, we'll figure out where
- * to start based upon the route_types.h
+ * and we'll separate them, we'll figure out where to start based upon
+ * the route_types.h
  */
-#define ZEBRA_NHG_SPACING 50000000
+#define ZEBRA_NHG_PROTO_UPPER                                                  \
+       ((uint32_t)250000000) /* Bottom 28 bits then rounded down */
+#define ZEBRA_NHG_PROTO_SPACING (ZEBRA_NHG_PROTO_UPPER / ZEBRA_ROUTE_MAX)
+#define ZEBRA_NHG_PROTO_LOWER                                                  \
+       (ZEBRA_NHG_PROTO_SPACING * (ZEBRA_ROUTE_CONNECT + 1))
+
 extern uint32_t zclient_get_nhg_start(uint32_t proto);
-extern uint32_t zclient_get_nhg_lower_bound(void);
 
 extern struct zclient *zclient_new(struct thread_master *m,
                                   struct zclient_options *opt);
index 07135b7fc87ab3c75005516a13d682144bbde292..34841aa4a5b52e1f73eee8fbf8515387bcfe6f98 100644 (file)
@@ -144,7 +144,7 @@ static bool is_proto_nhg(uint32_t id, int type)
                return false;
        }
 
-       if (id >= zclient_get_nhg_lower_bound())
+       if (id >= ZEBRA_NHG_PROTO_LOWER)
                return true;
 
        return false;
index 74551e31c4d5cc034f9ad8c9f5e7f267e7074855..c078b25ab1204b899aa18ac7c57ae08783dc7d33 100644 (file)
@@ -676,7 +676,7 @@ static bool zebra_nhe_find(struct nhg_hash_entry **nhe, /* return value */
        if (lookup->id == 0)
                lookup->id = ++id_counter;
 
-       if (lookup->id < zclient_get_nhg_lower_bound()) {
+       if (lookup->id < ZEBRA_NHG_PROTO_LOWER) {
                /*
                 * This is a zebra hashed/owned NHG.
                 *
@@ -730,7 +730,7 @@ static bool zebra_nhe_find(struct nhg_hash_entry **nhe, /* return value */
        if (CHECK_FLAG(nh->flags, NEXTHOP_FLAG_ACTIVE))
                SET_FLAG(newnhe->flags, NEXTHOP_GROUP_VALID);
 
-       if (nh->next == NULL && newnhe->id < zclient_get_nhg_lower_bound()) {
+       if (nh->next == NULL && newnhe->id < ZEBRA_NHG_PROTO_LOWER) {
                if (CHECK_FLAG(nh->flags, NEXTHOP_FLAG_RECURSIVE)) {
                        /* Single recursive nexthop */
                        handle_recursive_depend(&newnhe->nhg_depends,
@@ -1246,7 +1246,7 @@ int zebra_nhg_kernel_find(uint32_t id, struct nexthop *nh, struct nh_grp *grp,
                zlog_debug("%s: nh %pNHv, id %u, count %d",
                           __func__, nh, id, (int)count);
 
-       if (id > id_counter && id < zclient_get_nhg_lower_bound())
+       if (id > id_counter && id < ZEBRA_NHG_PROTO_LOWER)
                /* Increase our counter so we don't try to create
                 * an ID that already exists
                 */
@@ -2319,7 +2319,7 @@ int nexthop_active_update(struct route_node *rn, struct route_entry *re)
        struct nhg_hash_entry *curr_nhe;
        uint32_t curr_active = 0, backup_active = 0;
 
-       if (re->nhe->id >= zclient_get_nhg_lower_bound())
+       if (re->nhe->id >= ZEBRA_NHG_PROTO_LOWER)
                return proto_nhg_nexthop_active_update(&re->nhe->nhg);
 
        afi_t rt_afi = family2afi(rn->p.family);
@@ -2525,7 +2525,7 @@ void zebra_nhg_install_kernel(struct nhg_hash_entry *nhe)
 
        if (CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_VALID)
            && (!CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED)
-               || nhe->id >= zclient_get_nhg_lower_bound())
+               || nhe->id >= ZEBRA_NHG_PROTO_LOWER)
            && !CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_QUEUED)) {
                /* Change its type to us since we are installing it */
                if (!ZEBRA_NHG_CREATED(nhe))