]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: make NHG ID allocation smarter
authorStephen Worley <sworley@cumulusnetworks.com>
Wed, 13 May 2020 21:42:55 +0000 (17:42 -0400)
committerStephen Worley <sworley@cumulusnetworks.com>
Mon, 28 Sep 2020 16:40:59 +0000 (12:40 -0400)
Make NHG ID allocation smarter so it wraps once it hits
the lower bound for protos and performs a lookup to make
sure we don't already have that ID in use.

Its pretty unlikely we would wrap since the ID space is somewhere
around 24million for Zebra at this point in time.

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

index c078b25ab1204b899aa18ac7c57ae08783dc7d33..6d4a915673aebf4389ee462456d017bccaa11f94 100644 (file)
@@ -69,6 +69,35 @@ static void depends_decrement_free(struct nhg_connected_tree_head *head);
 static struct nhg_backup_info *
 nhg_backup_copy(const struct nhg_backup_info *orig);
 
+/* Helper function for getting the next allocatable ID */
+static uint32_t nhg_get_next_id()
+{
+       while (1) {
+               id_counter++;
+
+               if (IS_ZEBRA_DEBUG_NHG_DETAIL)
+                       zlog_debug("%s: ID %u checking", __func__, id_counter);
+
+               if (id_counter == ZEBRA_NHG_PROTO_LOWER) {
+                       if (IS_ZEBRA_DEBUG_NHG_DETAIL)
+                               zlog_debug("%s: ID counter wrapped", __func__);
+
+                       id_counter = 0;
+                       continue;
+               }
+
+               if (zebra_nhg_lookup_id(id_counter)) {
+                       if (IS_ZEBRA_DEBUG_NHG_DETAIL)
+                               zlog_debug("%s: ID already exists", __func__);
+
+                       continue;
+               }
+
+               break;
+       }
+
+       return id_counter;
+}
 
 static void nhg_connected_free(struct nhg_connected *dep)
 {
@@ -674,7 +703,7 @@ static bool zebra_nhe_find(struct nhg_hash_entry **nhe, /* return value */
         * assign the next global id value if necessary.
         */
        if (lookup->id == 0)
-               lookup->id = ++id_counter;
+               lookup->id = nhg_get_next_id();
 
        if (lookup->id < ZEBRA_NHG_PROTO_LOWER) {
                /*