From 5d766260f0c3e3ef1bd1e7ade0681b21775145d9 Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Thu, 24 Oct 2024 14:20:01 +0200 Subject: [PATCH] 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). --- src/cli.c | 4 ++-- src/connection.c | 24 ++++++++++-------------- src/extcheck.c | 1 + src/hlua.c | 1 + src/hlua_fcn.c | 1 + src/session.c | 1 + src/tools.c | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/cli.c b/src/cli.c index c33b1b726..556be111b 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 ea895963e..9c1d4a013 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 2c04dc7a2..20e9fa8f9 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 c8b42dc81..cd2b908d7 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 21a023828..afb5cf07e 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 5dbbba8e5..ac82aa8ea 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 572d12482..a51a4ffdc 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 {