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().
This commit is contained in:
Willy Tarreau 2025-08-23 19:24:21 +02:00
parent f4059ea42f
commit b2402d67b7
3 changed files with 19 additions and 1 deletions

View File

@ -57,6 +57,7 @@ void free_proxy(struct proxy *p);
const char *proxy_cap_str(int cap); const char *proxy_cap_str(int cap);
const char *proxy_mode_str(int mode); const char *proxy_mode_str(int mode);
const char *proxy_find_best_option(const char *word, const char **extra); 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); void proxy_store_name(struct proxy *px);
struct proxy *proxy_find_by_id(int id, int cap, int table); 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); struct proxy *proxy_find_by_name(const char *name, int cap, int table);

View File

@ -2850,7 +2850,7 @@ init_proxies_list_stage1:
* build or config options and we don't want them to * build or config options and we don't want them to
* possibly reuse existing IDs. * 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; curproxy->conf.id.key = curproxy->uuid = next_pxid;
eb32_insert(&used_proxy_id, &curproxy->conf.id); eb32_insert(&used_proxy_id, &curproxy->conf.id);
} }

View File

@ -538,6 +538,23 @@ const char *proxy_find_best_option(const char *word, const char **extra)
return best_ptr; 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 /* 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 * -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 * return zero, it will write an error or warning message into a preallocated