]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy: add a true list containing all proxies
authorAurelien DARRAGON <adarragon@haproxy.com>
Fri, 9 May 2025 14:02:09 +0000 (16:02 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Mon, 2 Jun 2025 15:51:21 +0000 (17:51 +0200)
We have global proxies_list pointer which is announced as the list of
"all existing proxies", but in fact it only represents regular proxies
declared on the config file through "listen, frontend or backend" keywords

It is ambiguous, and we currently don't have a straightforwrd method to
iterate over all proxies (either public or internal ones) within haproxy

Instead we still have to manually iterate over multiple lists (main
proxies, log-forward proxies, peer proxies..) which is error-prone.

In this patch we add a struct list member (8 bytes) inside struct proxy
in order to store every proxy (except default ones) within a global
"proxies" list which is actually representative for all proxies existing
under haproxy process, like we already have for servers.

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

index 0ea2fd95b3aa93827c4f8d959be3445929cea47c..993751c5c53fe6f7ec6831e3758c2aebccbd316c 100644 (file)
@@ -311,6 +311,10 @@ struct proxy {
        char flags;                             /* bit field PR_FL_* */
        enum pr_mode mode;                      /* mode = PR_MODE_TCP, PR_MODE_HTTP, ... */
        char cap;                               /* supported capabilities (PR_CAP_*) */
+       /* 4-bytes hole */
+
+       struct list global_list;                /* list member for global proxy list */
+
        unsigned int maxconn;                   /* max # of active streams on the frontend */
 
        int options;                            /* PR_O_REDISP, PR_O_TRANSP, ... */
index c6c41260ca81ed81a39a47710f4b557c0d78bf2b..43e9758606d1c77cff6423f3568f47706e41551f 100644 (file)
@@ -33,6 +33,7 @@
 #include <haproxy/thread.h>
 
 extern struct proxy *proxies_list;
+extern struct list proxies;
 extern struct eb_root used_proxy_id;   /* list of proxy IDs in use */
 extern unsigned int error_snapshot_id;  /* global ID assigned to each error then incremented */
 extern struct eb_root proxy_by_name;    /* tree of proxies sorted by name */
index 56066bf8e83a056c249f42197d0b4754cf60f924..70f19bcbf93a160b44154c853b16450f27bd6fe7 100644 (file)
@@ -58,7 +58,8 @@
 
 
 int listeners; /* # of proxy listeners, set by cfgparse */
-struct proxy *proxies_list  = NULL;    /* list of all existing proxies */
+struct proxy *proxies_list  = NULL;     /* list of main proxies */
+struct list proxies = LIST_HEAD_INIT(proxies); /* list of all proxies */
 struct eb_root used_proxy_id = EB_ROOT;        /* list of proxy IDs in use */
 struct eb_root proxy_by_name = EB_ROOT; /* tree of proxies sorted by name */
 struct eb_root defproxy_by_name = EB_ROOT; /* tree of default proxies sorted by name (dups possible) */
@@ -218,6 +219,7 @@ static inline void proxy_free_common(struct proxy *px)
        /* note that the node's key points to p->id */
        ebpt_delete(&px->conf.by_name);
        ha_free(&px->id);
+       LIST_DEL_INIT(&px->global_list);
        drop_file_name(&px->conf.file);
        ha_free(&px->check_command);
        ha_free(&px->check_path);
@@ -1468,6 +1470,7 @@ void init_new_proxy(struct proxy *p)
 {
        memset(p, 0, sizeof(struct proxy));
        p->obj_type = OBJ_TYPE_PROXY;
+       LIST_INIT(&p->global_list);
        LIST_INIT(&p->acl);
        LIST_INIT(&p->http_req_rules);
        LIST_INIT(&p->http_res_rules);
@@ -1725,6 +1728,9 @@ int setup_new_proxy(struct proxy *px, const char *name, unsigned int cap, char *
        if (name && !(cap & PR_CAP_INT))
                proxy_store_name(px);
 
+       if (!(cap & PR_CAP_DEF))
+               LIST_APPEND(&proxies, &px->global_list);
+
        return 1;
 }