]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy: add proxy_get_next_id() to find next free proxy ID
authorWilly Tarreau <w@1wt.eu>
Sat, 23 Aug 2025 17:24:21 +0000 (19:24 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 16 Sep 2025 07:23:46 +0000 (09:23 +0200)
This was previously achieved via the generic get_next_id() but we'll soon
get rid of generic ID trees so let's have a dedicated proxy_get_next_id().

include/haproxy/proxy.h
src/cfgparse.c
src/proxy.c

index 2329db8b79f51f1d31333113bbb616cbd6458180..26e00d14156e8f63b4d49c478afbc6296b2bb1aa 100644 (file)
@@ -57,6 +57,7 @@ void free_proxy(struct proxy *p);
 const char *proxy_cap_str(int cap);
 const char *proxy_mode_str(int mode);
 const char *proxy_find_best_option(const char *word, const char **extra);
+uint proxy_get_next_id(uint from);
 void proxy_store_name(struct proxy *px);
 struct proxy *proxy_find_by_id(int id, int cap, int table);
 struct proxy *proxy_find_by_name(const char *name, int cap, int table);
index 8e25c9ef4a8d37e099838122961c233b41b2114c..059e557a42f69ce0a9cbc83eaa4471cc56447023 100644 (file)
@@ -2850,7 +2850,7 @@ init_proxies_list_stage1:
                         * build or config options and we don't want them to
                         * possibly reuse existing IDs.
                         */
-                       next_pxid = get_next_id(&used_proxy_id, next_pxid);
+                       next_pxid = proxy_get_next_id(next_pxid);
                        curproxy->conf.id.key = curproxy->uuid = next_pxid;
                        eb32_insert(&used_proxy_id, &curproxy->conf.id);
                }
index c886e74732903fe920559605b59328616c3708a4..a9ca53482595589284ce39f361f36121168c4cda 100644 (file)
@@ -538,6 +538,23 @@ const char *proxy_find_best_option(const char *word, const char **extra)
        return best_ptr;
 }
 
+/* This function returns the first unused proxy ID greater than or equal to
+ * <from> in used_proxy_id. Zero is returned if no spare one is found (should
+ * never happen).
+ */
+uint proxy_get_next_id(uint from)
+{
+       struct eb32_node *used;
+
+       do {
+               used = eb32_lookup_ge(&used_proxy_id, from);
+               if (!used || used->key > from)
+                       return from; /* available */
+               from++;
+       } while (from);
+       return from;
+}
+
 /* This function parses a "timeout" statement in a proxy section. It returns
  * -1 if there is any error, 1 for a warning, otherwise zero. If it does not
  * return zero, it will write an error or warning message into a preallocated