]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: log: convert list to standard doubly linked one
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 16 Jul 2026 10:00:46 +0000 (12:00 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 23 Jul 2026 14:03:19 +0000 (16:03 +0200)
Log-forward proxies are not stored in <proxies_list> alongside other
visible user proxies. Instead, they are stored in a dedicated list
<cfg_log_forward>.

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 <el>
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().

include/haproxy/log.h
include/haproxy/proxy-t.h
src/cfgparse.c
src/haproxy.c
src/log.c

index 061d61801691692fa9b8dc34ea7fce5c18bdb7a4..79330e0f0ca655c1cdcc7ee4b85f83e0ea07c0de 100644 (file)
@@ -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;
 }
index 365e891a2335ee84aec993bc28d650c151c7b89c..d6984625bcc8ea46be4bb415fe9ce7107bee8a28 100644 (file)
@@ -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
+                                                * - <cfg_log_forward> for log forwarder
+                                                * - <defaults_list> for defaults section
+                                                */
 
        unsigned int maxconn;                   /* max # of active streams on the frontend */
 
index 71944ea21b8748bf525fe9563f4f40287b920c7d..4c562680d647c9a8b9bcd1044c22b8c33a29b816 100644 (file)
@@ -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)
index 405386cb192b896d41d428b3e82059a63c7ee95b..774c6bca539aa56d9861f02e3cfb24e18db7d53b 100644 (file)
@@ -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) {
index d84295b59584a7c7b1e8676e4177990b8e6bf588..eb02b8bee333f8550d613ca2578b02ddc68a571c 100644 (file)
--- 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;