]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy: assign dynamic proxy ID
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 23 Dec 2025 15:15:47 +0000 (16:15 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 6 Feb 2026 16:28:27 +0000 (17:28 +0100)
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 <dynpx_next_id>. 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.

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

index 57dbbd9ff727ec9530e6a90df96ccf0b24e3f37b..69860510f8ac205c7fb2c54956244bc1147688f7 100644 (file)
@@ -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[];
index 39cabdf6bcd1ece4317874baa448b6026dc11c94..5dd10faf4639d1e2b90f4e002300e81f9403cc87 100644 (file)
@@ -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
index 695470c069b0a09d8fb98e7fb79cb4d60fe462f5..4a5ce7e17deda438424f259a9420f722ec3276b2 100644 (file)
@@ -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;
        }