From: Aurelien DARRAGON Date: Fri, 9 May 2025 14:02:09 +0000 (+0200) Subject: MINOR: proxy: add a true list containing all proxies X-Git-Tag: v3.3-dev1~28 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=943958c3ff042d24331f6ca872440cec8d2e13f8;p=thirdparty%2Fhaproxy.git MINOR: proxy: add a true list containing all proxies 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. --- diff --git a/include/haproxy/proxy-t.h b/include/haproxy/proxy-t.h index 0ea2fd95b..993751c5c 100644 --- a/include/haproxy/proxy-t.h +++ b/include/haproxy/proxy-t.h @@ -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, ... */ diff --git a/include/haproxy/proxy.h b/include/haproxy/proxy.h index c6c41260c..43e975860 100644 --- a/include/haproxy/proxy.h +++ b/include/haproxy/proxy.h @@ -33,6 +33,7 @@ #include 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 */ diff --git a/src/proxy.c b/src/proxy.c index 56066bf8e..70f19bcbf 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -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; }