]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: listener: add listener_get_next_id() to find next free listener ID
authorWilly Tarreau <w@1wt.eu>
Sat, 23 Aug 2025 17:25:03 +0000 (19:25 +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 listener_get_next_id().
As a bonus it reduces the exposure of the tree's root outside of the functions.

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

index fb32f2e89b162336cb70f6ec87570ad02dce2229..296fbd13973bdd1dabb76799fcc803d7cc03c026 100644 (file)
@@ -82,6 +82,12 @@ int relax_listener(struct listener *l, int lpx, int lli);
  */
 void stop_listener(struct listener *l, int lpx, int lpr, int lli);
 
+/* This function returns the first unused listener ID greater than or equal to
+ * <from> in the proxy <px>. Zero is returned if no spare one is found (should
+ * never happen).
+ */
+uint listener_get_next_id(const struct proxy *px, uint from);
+
 /* This function adds the specified listener's file descriptor to the polling
  * lists if it is in the LI_LISTEN state. The listener enters LI_READY or
  * LI_FULL state depending on its number of connections. In daemon mode, we
index 059e557a42f69ce0a9cbc83eaa4471cc56447023..4e41daa54aff51db126443f8095c99291846cf2b 100644 (file)
@@ -4290,7 +4290,7 @@ init_proxies_list_stage2:
                                        if (prev_li->luid)
                                                next_id = prev_li->luid + 1;
                                }
-                               next_id = get_next_id(&curproxy->conf.used_listener_id, next_id);
+                               next_id = listener_get_next_id(curproxy, next_id);
                                listener->conf.id.key = listener->luid = next_id;
                                eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id);
                        }
index 9520a38935b344ec139df7ad2248672db832347c..5f74abe5a1489f7f71db52bea8185b35cdd48fe3 100644 (file)
@@ -399,6 +399,23 @@ void stop_listener(struct listener *l, int lpx, int lpr, int lli)
                HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &px->lock);
 }
 
+/* This function returns the first unused listener ID greater than or equal to
+ * <from> in the proxy <px>. Zero is returned if no spare one is found (should
+ * never happen).
+ */
+uint listener_get_next_id(const struct proxy *px, uint from)
+{
+       const struct eb32_node *used;
+
+       do {
+               used = eb32_lookup_ge((struct eb_root*)&px->conf.used_listener_id, from);
+               if (!used || used->key > from)
+                       return from; /* available */
+               from++;
+       } while (from);
+       return from;
+}
+
 /* This function adds the specified <listener> to the protocol <proto>. It
  * does nothing if the protocol was already added. The listener's state is
  * automatically updated from LI_INIT to LI_ASSIGNED. The number of listeners