]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy: centralize proxies_list insert during config parsing
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 22 Jul 2026 14:06:55 +0000 (16:06 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 23 Jul 2026 14:03:19 +0000 (16:03 +0200)
Define a new function wrapper mainpx_register() which is used to insert
a proxy instance in <proxies_list> which contain all user visible
entries. Insertion is performed at the front of the list. Thus it must
only be used during configuration parsing, before proxies list reversal.

The main objective of this patch is to simplify the list conversion to a
doubly linked one by centralizing the required changes in a single
function. A nice benefit is that it is now easier to determine the exact
proxies list composition.

include/haproxy/proxy.h
src/cfgparse-listen.c
src/cli.c
src/haload_init.c
src/http_client.c
src/tcpcheck.c

index f5f29f96f1d28c48bd3c89681f34d28072d2a9f4..3d543024c5abd2deef57a91822d118e5e3f14721 100644 (file)
@@ -314,6 +314,16 @@ static inline void increment_send_rate(uint64_t bytes, int splice)
        update_freq_ctr(&th_ctx->out_32bps, (bytes + 16) / 32);
 }
 
+/* Insert <px> at the front of the global list of visible proxies. This should
+ * only be used during configuration parsing. At runtime, a newly added proxy
+ * should be appended at the end of the list instead.
+ */
+static inline void main_proxies_register(struct proxy *px)
+{
+       px->next = proxies_list;
+       proxies_list = px;
+}
+
 #endif /* _HAPROXY_PROXY_H */
 
 /*
index 92b77661c3d9cdcc71216ab19e5cadabf3eb5fd3..fe5337fe85755c610249d6768e69efe3e7eead66 100644 (file)
@@ -520,8 +520,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                        curr_defproxy = last_defproxy = curproxy;
                } else {
                        /* regular proxies are in a list */
-                       curproxy->next = proxies_list;
-                       proxies_list = curproxy;
+                       main_proxies_register(curproxy);
                }
                goto out;
        }
index 4c79ecbc850443cc9d2a7340ecb6d51a01cee665..be5d02960d3984214a6e765c1c0050555c476672 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -470,8 +470,7 @@ static struct proxy *cli_alloc_fe(const char *name, const char *file, int line)
                return NULL;
        }
 
-       fe->next = proxies_list;
-       proxies_list = fe;
+       main_proxies_register(fe);
        fe->maxconn = 10;                 /* default to 10 concurrent connections */
        fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */
        fe->conf.file = copy_file_name(file);
@@ -3904,8 +3903,7 @@ int mworker_cli_create_master_proxy(char **errmsg)
        /* Does not init the default target the CLI applet, but must be done in
         * the request parsing code */
        mworker_proxy->default_target = NULL;
-       mworker_proxy->next = proxies_list;
-       proxies_list = mworker_proxy;
+       main_proxies_register(mworker_proxy);
 
        return 0;
 }
index c5fc8b7449c60fc2d08f6af81f891e6990a7d16e..8da0b8f95c2456af2c4eb72df65554c2623b1208 100644 (file)
@@ -732,8 +732,7 @@ static int hld_pre_check(void)
        hld_proxy.mode = PR_MODE_HTTP;
        if (arg_fast)
                hld_proxy.options2 = PR_O2_SMARTCON;
-       hld_proxy.next = proxies_list;
-    proxies_list = &hld_proxy;
+       main_proxies_register(&hld_proxy);
 
     hld_proxy.timeout.server = 60000;
     hld_proxy.timeout.connect = 60000;
index a4c96e8577ba9b0ae67b7049964bebada60f32ab..a34ad2bd211378a74d4cd064639ca2b58c1721ae 100644 (file)
@@ -1207,8 +1207,7 @@ struct proxy *httpclient_create_proxy(const char *id)
 #endif
 
        /* add the proxy in the proxy list only if everything is successful */
-       px->next = proxies_list;
-       proxies_list = px;
+       main_proxies_register(px);
 
        if (httpclient_resolve_init(px) != 0) {
                memprintf(&errmsg, "cannot initialize resolvers.");
index 00b88f54a565c27fe54c58f87ff9fd57e739b669..5dcd8707aaa9711abfce31112ee811169c237a01 100644 (file)
@@ -5742,8 +5742,7 @@ int cfg_parse_healthchecks(const char *file, int linenum, char **args, int kwm)
                                err_code |= ERR_ALERT | ERR_FATAL;
                                goto out;
                        }
-                       tcpchecks_proxy->next = proxies_list;
-                       proxies_list = tcpchecks_proxy;
+                       main_proxies_register(tcpchecks_proxy);
                }
                tcpchecks_proxy->options2 &= ~PR_O2_CHK_ANY;
                tcpchecks_proxy->tcpcheck.flags = 0;