]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy: refactor defaults proxies API
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 22 Jan 2026 10:16:14 +0000 (11:16 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 22 Jan 2026 16:55:47 +0000 (17:55 +0100)
This patch renames functions which deal with defaults section. A common
"defaults_px_" prefix is defined. This serves as a marker to identify
functions which can only be used with proxies defaults capability. New
BUG_ON() are enforced to ensure this is valid.

Also, older proxy_unref_or_destroy_defaults() is renamed
defaults_px_detach().

include/haproxy/proxy.h
src/cfgparse-listen.c
src/haproxy.c
src/proxy.c

index 973f1a8ad04d4ede8c1f2bbe799fd92c69e9c270..b0f10c99c760e17847b8777c75d2e9f8429817a6 100644 (file)
@@ -67,12 +67,13 @@ struct proxy *proxy_find_best_match(int cap, const char *name, int id, int *diff
 int proxy_cfg_ensure_no_http(struct proxy *curproxy);
 int proxy_cfg_ensure_no_log(struct proxy *curproxy);
 void init_new_proxy(struct proxy *p);
-void proxy_free_defaults(struct proxy *defproxy);
-void proxy_destroy_defaults(struct proxy *px);
-void proxy_destroy_all_unref_defaults(void);
+
+void defaults_px_destroy(struct proxy *px);
+void defaults_px_destroy_all_unref(void);
+void defaults_px_detach(struct proxy *px);
+
 void proxy_ref_defaults(struct proxy *px, struct proxy *defpx);
 void proxy_unref_defaults(struct proxy *px);
-void proxy_unref_or_destroy_defaults(struct proxy *px);
 int setup_new_proxy(struct proxy *px, const char *name, unsigned int cap, char **errmsg);
 struct proxy *alloc_new_proxy(const char *name, unsigned int cap,
                               char **errmsg);
index 68bf937312a943c2ed3fb0fd8485b3a67bef0f79..0c811a6086ece95092bba83d745bf19f72d6802f 100644 (file)
@@ -415,7 +415,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                        if (curproxy) {
                                file_prev = curproxy->conf.file;
                                line_prev = curproxy->conf.line;
-                               proxy_unref_or_destroy_defaults(curproxy);
+                               defaults_px_detach(curproxy);
                                curproxy = NULL;
                        }
                }
index 4498367b334bae63b4db13fd42ad377566d3c2c4..c012c9d5c4ac85e0f34b7d2cc2f89ad4eb49db74 100644 (file)
@@ -2099,7 +2099,7 @@ static void step_init_2(int argc, char** argv)
        const char *cc, *cflags, *opts;
 
        /* destroy unreferenced defaults proxies  */
-       proxy_destroy_all_unref_defaults();
+       defaults_px_destroy_all_unref();
 
        list_for_each_entry(prcf, &pre_check_list, list) {
                err_code |= prcf->fct();
@@ -2743,7 +2743,7 @@ void deinit(void)
         */
 
        /* destroy all referenced defaults proxies  */
-       proxy_destroy_all_unref_defaults();
+       defaults_px_destroy_all_unref();
 
        userlist_free(userlist);
 
index 1d4bbf413d697fe0a3bece698f2e36d413a02ad8..a5bd572ad017ef55b41ba12351dd9db21ba341af 100644 (file)
@@ -1589,7 +1589,7 @@ int proxy_init_per_thr(struct proxy *px)
  * destroyed. Note that most of the fields are not even reset, so extreme care
  * is required here.
  */
-void proxy_free_defaults(struct proxy *defproxy)
+static void defaults_px_free(struct proxy *defproxy)
 {
        struct cap_hdr *h,*h_next;
 
@@ -1623,22 +1623,17 @@ void proxy_free_defaults(struct proxy *defproxy)
        deinit_proxy_tcpcheck(defproxy);
 }
 
-/* delete a defproxy from the tree if still in it, frees its content and its
- * storage. Nothing is done if <px> is NULL or if it doesn't have PR_CAP_DEF
- * set, allowing to pass it the direct result of a lookup function.
+/* Removes <px> defaults instance from the name tree, free its content and
+ * storage. This must only be used if <px> is unreferenced.
  */
-void proxy_destroy_defaults(struct proxy *px)
+void defaults_px_destroy(struct proxy *px)
 {
        struct proxy *prev;
 
-       if (!px)
-               return;
-       if (!(px->cap & PR_CAP_DEF))
-               return;
+       BUG_ON(!(px->cap & PR_CAP_DEF));
        BUG_ON(px->conf.refcount != 0);
 
-       cebis_item_delete((px->cap & PR_CAP_DEF) ? &defproxy_by_name : &proxy_by_name,
-                         conf.name_node, id, px);
+       cebis_item_delete(&defproxy_by_name, conf.name_node, id, px);
 
        /* If orphaned defaults list is not empty, it may contain <px> instance.
         * In this case it is necessary to manually remove it from the list.
@@ -1657,14 +1652,14 @@ void proxy_destroy_defaults(struct proxy *px)
                px->next = NULL;
        }
 
-       proxy_free_defaults(px);
+       defaults_px_free(px);
        free(px);
 }
 
 /* delete all unreferenced default proxies. A default proxy is unreferenced if
  * its refcount is equal to zero.
  */
-void proxy_destroy_all_unref_defaults()
+void defaults_px_destroy_all_unref(void)
 {
        struct proxy *px, *nx;
 
@@ -1672,7 +1667,7 @@ void proxy_destroy_all_unref_defaults()
                BUG_ON(!(px->cap & PR_CAP_DEF));
                nx = cebis_item_next(&defproxy_by_name, conf.name_node, id, px);
                if (!px->conf.refcount)
-                       proxy_destroy_defaults(px);
+                       defaults_px_destroy(px);
        }
 
        px = orphaned_default_proxies;
@@ -1680,27 +1675,29 @@ void proxy_destroy_all_unref_defaults()
                BUG_ON(!(px->cap & PR_CAP_DEF));
                nx = px->next;
                if (!px->conf.refcount)
-                       proxy_destroy_defaults(px);
+                       defaults_px_destroy(px);
                px = nx;
        }
 }
 
-/* Try to destroy a defaults section, or just unreference it if still
- * refcounted. In this case it's added to the orphaned_default_proxies list
- * so that it can later be found.
+/* Removes <px> defaults from the name tree. This operation is useful when a
+ * section is made invisible by a newer instance with the same name. If <px> is
+ * not referenced it is freed immediately, else it is moved in defaults
+ * orphaned list.
  */
-void proxy_unref_or_destroy_defaults(struct proxy *px)
+void defaults_px_detach(struct proxy *px)
 {
-       if (!px || !(px->cap & PR_CAP_DEF))
-               return;
+       BUG_ON(!(px->cap & PR_CAP_DEF));
 
-       cebis_item_delete((px->cap & PR_CAP_DEF) ? &defproxy_by_name : &proxy_by_name, conf.name_node, id, px);
+       cebis_item_delete(&defproxy_by_name, conf.name_node, id, px);
        if (px->conf.refcount) {
                /* still referenced just append it to the orphaned list */
                px->next = orphaned_default_proxies;
                orphaned_default_proxies = px;
-       } else
-               proxy_destroy_defaults(px);
+       }
+       else {
+               defaults_px_destroy(px);
+       }
 }
 
 /* Add a reference on the default proxy <defpx> for the proxy <px> Nothing is
@@ -1727,7 +1724,7 @@ void proxy_unref_defaults(struct proxy *px)
        if (px->defpx == NULL)
                return;
        if (!--px->defpx->conf.refcount)
-               proxy_destroy_defaults(px->defpx);
+               defaults_px_destroy(px->defpx);
        px->defpx = NULL;
 }