From: Aurelien DARRAGON Date: Thu, 24 Oct 2024 12:20:01 +0000 (+0200) Subject: MEDIUM: protocol: rely on AF_CUST_ABNS family to recognize ABNS sockets X-Git-Tag: v3.1-dev11~34 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5d766260f0c3e3ef1bd1e7ade0681b21775145d9;p=thirdparty%2Fhaproxy.git MEDIUM: protocol: rely on AF_CUST_ABNS family to recognize ABNS sockets Now that we can easily distinguish regular UNIX socket from ABNS sockets by simply looking at the address family, stop looking at the first byte from addr->sun_path to guess if the socket is an ABNS one or not. Looking at the family is straightforward and will allow to differentiate between upcoming ABNSZ and ABNS (where looking at the first byte from path won't help anymore). --- diff --git a/src/cli.c b/src/cli.c index c33b1b7264..556be111b0 100644 --- a/src/cli.c +++ b/src/cli.c @@ -659,7 +659,7 @@ int listeners_setenv(struct proxy *frontend, const char *varname) const struct sockaddr_un *un; un = (struct sockaddr_un *)&l->rx.addr; - if (un->sun_path[0] == '\0') { + if (l->rx.addr.ss_family == AF_CUST_ABNS) { chunk_appendf(trash, "abns@%s", un->sun_path+1); } else { chunk_appendf(trash, "unix@%s", un->sun_path); @@ -1588,7 +1588,7 @@ static int cli_io_handler_show_cli_sock(struct appctx *appctx) const struct sockaddr_un *un; un = (struct sockaddr_un *)&l->rx.addr; - if (un->sun_path[0] == '\0') { + if (l->rx.addr.ss_family == AF_CUST_ABNS) { chunk_appendf(&trash, "abns@%s ", un->sun_path+1); } else { chunk_appendf(&trash, "unix@%s ", un->sun_path); diff --git a/src/connection.c b/src/connection.c index ea895963e8..9c1d4a0133 100644 --- a/src/connection.c +++ b/src/connection.c @@ -2644,7 +2644,6 @@ static void conn_calculate_hash_sockaddr(const struct sockaddr_storage *ss, { struct sockaddr_in *addr; struct sockaddr_in6 *addr6; - struct sockaddr_un *un; switch (ss->ss_family) { case AF_INET: @@ -2678,20 +2677,17 @@ static void conn_calculate_hash_sockaddr(const struct sockaddr_storage *ss, break; case AF_UNIX: - case AF_CUST_ABNS: - un = (struct sockaddr_un *)ss; + conn_hash_update(hash, + &((struct sockaddr_un *)ss)->sun_path, + strlen(((struct sockaddr_un *)ss)->sun_path), + hash_flags, param_type_addr); + break; - if (un->sun_path[0]) { - /* regular UNIX socket */ - conn_hash_update(hash, - &un->sun_path, strlen(un->sun_path), - hash_flags, param_type_addr); - } else { - /* ABNS UNIX socket */ - conn_hash_update(hash, - &un->sun_path, sizeof(un->sun_path), - hash_flags, param_type_addr); - } + case AF_CUST_ABNS: + conn_hash_update(hash, + &((struct sockaddr_un *)ss)->sun_path, + sizeof(((struct sockaddr_un *)ss)->sun_path), + hash_flags, param_type_addr); break; case AF_CUST_SOCKPAIR: diff --git a/src/extcheck.c b/src/extcheck.c index 2c04dc7a22..20e9fa8f94 100644 --- a/src/extcheck.c +++ b/src/extcheck.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include diff --git a/src/hlua.c b/src/hlua.c index c8b42dc819..cd2b908d73 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c index 21a023828b..afb5cf07ec 100644 --- a/src/hlua_fcn.c +++ b/src/hlua_fcn.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/src/session.c b/src/session.c index 5dbbba8e5c..ac82aa8eaf 100644 --- a/src/session.c +++ b/src/session.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/src/tools.c b/src/tools.c index 572d12482b..a51a4ffdc5 100644 --- a/src/tools.c +++ b/src/tools.c @@ -1476,7 +1476,7 @@ char * sa2str(const struct sockaddr_storage *addr, int port, int map_ports) case AF_UNIX: case AF_CUST_ABNS: path = ((struct sockaddr_un *)addr)->sun_path; - if (path[0] == '\0') { + if (addr->ss_family == AF_CUST_ABNS) { const int max_length = sizeof(struct sockaddr_un) - offsetof(struct sockaddr_un, sun_path) - 1; return memprintf(&out, "abns@%.*s", max_length, path+1); } else {