From b2402d67b73b547689158bf58be0056a7387acb9 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sat, 23 Aug 2025 19:24:21 +0200 Subject: [PATCH] MINOR: proxy: add proxy_get_next_id() to find next free proxy ID 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 | 1 + src/cfgparse.c | 2 +- src/proxy.c | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/haproxy/proxy.h b/include/haproxy/proxy.h index 2329db8b7..26e00d141 100644 --- a/include/haproxy/proxy.h +++ b/include/haproxy/proxy.h @@ -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); diff --git a/src/cfgparse.c b/src/cfgparse.c index 8e25c9ef4..059e557a4 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -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); } diff --git a/src/proxy.c b/src/proxy.c index c886e7473..a9ca53482 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -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 + * 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