From: Amaury Denoyelle Date: Wed, 22 Jul 2026 14:06:55 +0000 (+0200) Subject: MINOR: proxy: centralize proxies_list insert during config parsing X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8fa7d45b63a0bcfecb8dfb41648cd6f2c2a6cf71;p=thirdparty%2Fhaproxy.git MINOR: proxy: centralize proxies_list insert during config parsing Define a new function wrapper mainpx_register() which is used to insert a proxy instance in 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. --- diff --git a/include/haproxy/proxy.h b/include/haproxy/proxy.h index f5f29f96f..3d543024c 100644 --- a/include/haproxy/proxy.h +++ b/include/haproxy/proxy.h @@ -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 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 */ /* diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index 92b77661c..fe5337fe8 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -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; } diff --git a/src/cli.c b/src/cli.c index 4c79ecbc8..be5d02960 100644 --- 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; } diff --git a/src/haload_init.c b/src/haload_init.c index c5fc8b744..8da0b8f95 100644 --- a/src/haload_init.c +++ b/src/haload_init.c @@ -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; diff --git a/src/http_client.c b/src/http_client.c index a4c96e857..a34ad2bd2 100644 --- a/src/http_client.c +++ b/src/http_client.c @@ -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."); diff --git a/src/tcpcheck.c b/src/tcpcheck.c index 00b88f54a..5dcd8707a 100644 --- a/src/tcpcheck.c +++ b/src/tcpcheck.c @@ -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;