]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: config: define wrapper for proxies loop during check config
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 16 Jul 2026 09:27:41 +0000 (11:27 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 23 Jul 2026 14:03:19 +0000 (16:03 +0200)
On check_config_validity(), proxy post init code is reexcuted over
several proxies list : the main proxies list, log sections and sinks.

This patch defines an internal wrapper to help performing this
iteration. It will become necessary once each list is converted from a
singly linked format to a doubly linked struct list. Once all lists are
converted, the wrapper should be removed as it will be once again
unnecessary.

src/cfgparse.c

index 6d528dd4882dad8d55c2e85a9551fd536c2bd988..71944ea21b8748bf525fe9563f4f40287b920c7d 100644 (file)
@@ -2258,6 +2258,32 @@ err:
        return err_code;
 }
 
+/* Returns the next entry following <cur> proxy attached it <head> list. This
+ * is a wrapper able to work with either a simple singly linked list or a
+ * doubly linked struct list type.
+ *
+ * TODO remove it once all proxies list are unified under the same type
+ */
+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 */
+               next = cur ?
+                 LIST_ELEM(cur->el.n, struct proxy *, el) :
+                 LIST_ELEM(list->n,   struct proxy *, el);
+
+               if (&next->el == head)
+                       next = NULL;
+       }
+       else {
+               next = cur ? cur->next : head;
+       }
+
+       return next;
+}
+
 /*
  * Returns the error code, 0 if OK, or any combination of :
  *  - ERR_ABORT: must abort ASAP
@@ -2270,7 +2296,8 @@ err:
 int check_config_validity()
 {
        int cfgerr = 0, ret;
-       struct proxy *init_proxies_list = NULL, *defpx;
+       struct proxy *defpx;
+       void *init_proxies_list = NULL;
        struct stktable *t;
        struct server *newsrv = NULL;
        struct mt_list back;
@@ -2409,11 +2436,12 @@ int check_config_validity()
                err_code |= proxy_check_http_errors(defpx);
        }
 
+       curproxy = NULL;
        /* starting to initialize the main proxies list */
        init_proxies_list = proxies_list;
 
 init_proxies_list_stage1:
-       for (curproxy = init_proxies_list; curproxy; curproxy = curproxy->next) {
+       while ((curproxy = _get_next_proxy(init_proxies_list, curproxy))) {
                proxy_init_per_thr(curproxy);
 
                /* Assign automatic UUID if unset except for internal proxies.
@@ -2464,6 +2492,7 @@ init_proxies_list_stage1:
        /* Dynamic proxies IDs will never be lowered than this value. */
        dynpx_next_id = next_pxid;
 
+       curproxy = NULL;
        /*
         * We have just initialized the main proxies list
         * we must also configure the log-forward proxies list
@@ -2513,11 +2542,12 @@ init_proxies_list_stage1:
 
        /* perform the final checks before creating tasks */
 
+       curproxy = NULL;
        /* starting to initialize the main proxies list */
        init_proxies_list = proxies_list;
 
 init_proxies_list_stage2:
-       for (curproxy = init_proxies_list; curproxy; curproxy = curproxy->next) {
+       while ((curproxy = _get_next_proxy(init_proxies_list, curproxy))) {
                struct listener *listener;
                unsigned int next_id;
 
@@ -2619,6 +2649,7 @@ init_proxies_list_stage2:
                }
        }
 
+       curproxy = NULL;
        /*
         * We have just initialized the main proxies list
         * we must also configure the log-forward proxies list