From: Amaury Denoyelle Date: Thu, 16 Jul 2026 10:00:46 +0000 (+0200) Subject: MINOR: log: convert list to standard doubly linked one X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=262012e0ee71a665764c343259ac03e181035487;p=thirdparty%2Fhaproxy.git MINOR: log: convert list to standard doubly linked one Log-forward proxies are not stored in alongside other visible user proxies. Instead, they are stored in a dedicated list . As with the visible proxies list, log forwarders list was defined as a simple singly linked one. This patch converts it to the doubly linked standard list type, frequently used in haproxy source code. Proxy member is reused as list attach point. It was only used by defaults instances prior to this patch. This patch does not bring noticeable change. However it will simplify visible proxies list similar conversion as both lists are looped over together during check_config_validity(). --- diff --git a/include/haproxy/log.h b/include/haproxy/log.h index 061d61801..79330e0f0 100644 --- a/include/haproxy/log.h +++ b/include/haproxy/log.h @@ -53,7 +53,7 @@ extern const char sess_fin_state[]; extern unsigned int dropped_logs; /* lof forward proxy list */ -extern struct proxy *cfg_log_forward; +extern struct list cfg_log_forward; extern THREAD_LOCAL char *logline; extern THREAD_LOCAL char *logline_rfc5424; @@ -237,12 +237,11 @@ struct ist *build_log_header(struct log_header hdr, size_t *nbelem); */ static inline struct proxy *log_forward_by_name(const char *name) { - struct proxy *px = cfg_log_forward; + struct proxy *px; - while (px) { + list_for_each_entry(px, &cfg_log_forward, el) { if (strcmp(px->id, name) == 0) return px; - px = px->next; } return NULL; } diff --git a/include/haproxy/proxy-t.h b/include/haproxy/proxy-t.h index 365e891a2..d6984625b 100644 --- a/include/haproxy/proxy-t.h +++ b/include/haproxy/proxy-t.h @@ -323,7 +323,10 @@ struct proxy { unsigned long last_change; /* internal use only: last time the proxy state was changed */ struct list global_list; /* list member for global proxy list */ - struct list el; /* attach point in various list - currently used only on defaults_list for defaults section */ + struct list el; /* attach point in various list + * - for log forwarder + * - for defaults section + */ unsigned int maxconn; /* max # of active streams on the frontend */ diff --git a/src/cfgparse.c b/src/cfgparse.c index 71944ea21..4c562680d 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -2269,7 +2269,7 @@ static struct proxy *_get_next_proxy(void *head, struct proxy *cur) struct proxy *next; struct list *list = (struct list *)head; - if (0) { /* TODO complete with newly converted list */ + if (head == &cfg_log_forward) { next = cur ? LIST_ELEM(cur->el.n, struct proxy *, el) : LIST_ELEM(list->n, struct proxy *, el); @@ -2498,13 +2498,11 @@ init_proxies_list_stage1: * we must also configure the log-forward proxies list */ if (init_proxies_list == proxies_list) { - init_proxies_list = cfg_log_forward; - /* check if list is not null to avoid infinite loop */ - if (init_proxies_list) - goto init_proxies_list_stage1; + init_proxies_list = &cfg_log_forward; + goto init_proxies_list_stage1; } - if (init_proxies_list == cfg_log_forward) { + if (init_proxies_list == &cfg_log_forward) { init_proxies_list = sink_proxies_list; /* check if list is not null to avoid infinite loop */ if (init_proxies_list) @@ -2655,13 +2653,11 @@ init_proxies_list_stage2: * we must also configure the log-forward proxies list */ if (init_proxies_list == proxies_list) { - init_proxies_list = cfg_log_forward; - /* check if list is not null to avoid infinite loop */ - if (init_proxies_list) - goto init_proxies_list_stage2; + init_proxies_list = &cfg_log_forward; + goto init_proxies_list_stage2; } - if (init_proxies_list == cfg_log_forward) { + if (init_proxies_list == &cfg_log_forward) { init_proxies_list = sink_proxies_list; /* check if list is not null to avoid infinite loop */ if (init_proxies_list) diff --git a/src/haproxy.c b/src/haproxy.c index 405386cb1..774c6bca5 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -2373,9 +2373,10 @@ static void step_init_2(int argc, char** argv) if (!px) { /* We may only have log-forward section */ - for (px = cfg_log_forward; px; px = px->next) + list_for_each_entry(px, &cfg_log_forward, el) { if (!(px->flags & (PR_FL_DISABLED|PR_FL_STOPPED)) && px->li_all) break; + } } if (pr || px) { diff --git a/src/log.c b/src/log.c index d84295b59..eb02b8bee 100644 --- a/src/log.c +++ b/src/log.c @@ -56,7 +56,7 @@ int cum_log_messages; /* log forward proxy list */ -struct proxy *cfg_log_forward; +struct list cfg_log_forward = LIST_HEAD_INIT(cfg_log_forward); struct log_fmt_st { char *name; @@ -3785,12 +3785,10 @@ void deinit_log_forward() { struct proxy *p, *p0; - p = cfg_log_forward; /* we need to manually clean cfg_log_forward proxy list */ - while (p) { - p0 = p; - p = p->next; - proxy_drop(p0); + list_for_each_entry_safe(p, p0, &cfg_log_forward, el) { + LIST_DEL_INIT(&p->el); + proxy_drop(p); } } @@ -6180,8 +6178,7 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm) goto out; } - curproxy->next = cfg_log_forward; - cfg_log_forward = curproxy; + LIST_INSERT(&cfg_log_forward, &curproxy->el); curproxy->conf.file = copy_file_name(file); curproxy->conf.line = linenum; curproxy->mode = PR_MODE_SYSLOG; @@ -6380,7 +6377,7 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm) * also, cfg_parse_listen_match_option() assumes global curproxy variable points to * currently evaluated proxy */ - curproxy = cfg_log_forward; + curproxy = LIST_NEXT(&cfg_log_forward, struct proxy *, el); if (cfg_parse_listen_match_option(file, linenum, kwm, cfg_opts3, &err_code, args, PR_MODE_SYSLOG, PR_CAP_FE, &curproxy->options3, &curproxy->no_options3)) @@ -6911,7 +6908,7 @@ static int postresolve_loggers() for (px = proxies_list; px; px = px->next) err_code |= postresolve_logger_list(px, &px->loggers, "proxy", px->id); /* log-forward log directives */ - for (px = cfg_log_forward; px; px = px->next) + list_for_each_entry(px, &cfg_log_forward, el) err_code |= postresolve_logger_list(NULL, &px->loggers, "log-forward", px->id); return err_code;