From 113745e6f0c0ef8fe89e89fdfdcc6ed994889d4a Mon Sep 17 00:00:00 2001 From: Valentine Krasnobaeva Date: Tue, 12 Nov 2024 22:43:49 +0100 Subject: [PATCH] BUG/MINOR: cli: don't show sockpairs in HAPROXY_CLI and HAPROXY_MASTER_CLI Before this fix, HAPROXY_CLI and HAPROXY_MASTER_CLI have contained along with CLI sockets addresses internal sockpairs, which are used only for master CLI (reload sockpair and sockpair shared with a worker process). These internal sockpairs are always need to be hidden. At the moment there is no any client, who uses sockpair addresses for the stats listener or in order to connect to master CLI. So, let's simply not copy these internal sockpair addresses of MASTER and GLOBAL proxy listeners. As listeners with sockpairs are skipped and they can be presented in the listeners list in any order, let's add semicolon separator between addresses only in the case, when there are already some string saved in the trash and we are sure, that we are adding a new address to it. Otherwise, we could have such weird output: HAPROXY_MASTER_CLI=unix@/tmp/mcli.sock;; This fix is need to be backported in all stable versions. --- src/cli.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/cli.c b/src/cli.c index de4dca628d..e9952f0293 100644 --- a/src/cli.c +++ b/src/cli.c @@ -651,10 +651,6 @@ int listeners_setenv(struct proxy *frontend, const char *varname) char addr[46]; char port[6]; - /* separate listener by semicolons */ - if (trash->data) - chunk_appendf(trash, ";"); - if (l->rx.addr.ss_family == AF_UNIX || l->rx.addr.ss_family == AF_CUST_ABNS || l->rx.addr.ss_family == AF_CUST_ABNSZ) { @@ -663,21 +659,22 @@ int listeners_setenv(struct proxy *frontend, const char *varname) un = (struct sockaddr_un *)&l->rx.addr; if (l->rx.addr.ss_family == AF_CUST_ABNS || l->rx.addr.ss_family == AF_CUST_ABNSZ) { - chunk_appendf(trash, "abns@%s", un->sun_path+1); + chunk_appendf(trash, "%sabns@%s", (trash->data ? ";" : ""), un->sun_path+1); } else { - chunk_appendf(trash, "unix@%s", un->sun_path); + chunk_appendf(trash, "%sunix@%s", (trash->data ? ";" : ""), un->sun_path); } } else if (l->rx.addr.ss_family == AF_INET) { addr_to_str(&l->rx.addr, addr, sizeof(addr)); port_to_str(&l->rx.addr, port, sizeof(port)); - chunk_appendf(trash, "ipv4@%s:%s", addr, port); + chunk_appendf(trash, "%sipv4@%s:%s", (trash->data ? ";" : ""), addr, port); } else if (l->rx.addr.ss_family == AF_INET6) { addr_to_str(&l->rx.addr, addr, sizeof(addr)); port_to_str(&l->rx.addr, port, sizeof(port)); - chunk_appendf(trash, "ipv6@[%s]:%s", addr, port); - } else if (l->rx.addr.ss_family == AF_CUST_SOCKPAIR) { - chunk_appendf(trash, "sockpair@%d", ((struct sockaddr_in *)&l->rx.addr)->sin_addr.s_addr); + chunk_appendf(trash, "%sipv6@[%s]:%s", (trash->data ? ";" : ""), addr, port); } + /* AF_CUST_SOCKPAIR is explicitly skipped, we don't want to show reload and shared + * master CLI sockpairs in HAPROXY_CLI and HAPROXY_MASTER_CLI + */ } } trash->area[trash->data++] = '\0';