From: Amaury Denoyelle Date: Tue, 23 Dec 2025 15:15:47 +0000 (+0100) Subject: MINOR: proxy: assign dynamic proxy ID X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5753c14e8412540524de4394c830e125509d2a33;p=thirdparty%2Fhaproxy.git MINOR: proxy: assign dynamic proxy ID Implement proxy ID generation for dynamic backends. This is performed through the already function existing proxy_get_next_id(). As an optimization, lookup will performed starting from a global variable . It is initialized to the greatest ID assigned after parsing, and updated each time a backend instance is created. When backend deletion will be implemented, it could be lowered to the newly available slot. --- diff --git a/include/haproxy/proxy.h b/include/haproxy/proxy.h index 57dbbd9ff..69860510f 100644 --- a/include/haproxy/proxy.h +++ b/include/haproxy/proxy.h @@ -41,6 +41,8 @@ extern unsigned int error_snapshot_id; /* global ID assigned to each error then extern struct ceb_root *proxy_by_name; /* tree of proxies sorted by name */ extern struct list defaults_list; /* all defaults proxies list */ +extern unsigned int dynpx_next_id; + extern const struct cfg_opt cfg_opts[]; extern const struct cfg_opt cfg_opts2[]; extern const struct cfg_opt cfg_opts3[]; diff --git a/src/cfgparse.c b/src/cfgparse.c index 39cabdf6b..5dd10faf4 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -2428,6 +2428,9 @@ init_proxies_list_stage1: } } + /* Dynamic proxies IDs will never be lowered than this value. */ + dynpx_next_id = next_pxid; + /* * We have just initialized the main proxies list * we must also configure the log-forward proxies list diff --git a/src/proxy.c b/src/proxy.c index 695470c06..4a5ce7e17 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -77,6 +77,8 @@ struct ceb_root *defproxy_by_name = NULL; /* tree of default proxies sorted by n struct list defaults_list = LIST_HEAD_INIT(defaults_list); /* list of all defaults proxies */ unsigned int error_snapshot_id = 0; /* global ID assigned to each error then incremented */ +unsigned int dynpx_next_id = 0; /* lowest ID assigned to dynamic proxies */ + /* CLI context used during "show servers {state|conn}" */ struct show_srv_ctx { struct proxy *px; /* current proxy to dump or NULL */ @@ -4916,6 +4918,14 @@ static int cli_parse_add_backend(char **args, char *payload, struct appctx *appc goto err; } + /* Assign automatically proxy ID. */ + px->uuid = proxy_get_next_id(dynpx_next_id); + if (!px->uuid) { + memprintf(&msg, "no spare proxy ID available"); + goto err; + } + dynpx_next_id = px->uuid; + if (!proxies_list) { proxies_list->next = px; }