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).
This commit is contained in:
Aurelien DARRAGON 2024-10-24 14:20:01 +02:00
parent 78ac312bbd
commit 5d766260f0
7 changed files with 17 additions and 17 deletions

View File

@ -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);

View File

@ -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:

View File

@ -33,6 +33,7 @@
#include <haproxy/global.h>
#include <haproxy/list.h>
#include <haproxy/limits.h>
#include <haproxy/protocol.h>
#include <haproxy/proxy.h>
#include <haproxy/server.h>
#include <haproxy/signal.h>

View File

@ -48,6 +48,7 @@
#include <haproxy/obj_type.h>
#include <haproxy/pattern.h>
#include <haproxy/payload.h>
#include <haproxy/protocol.h>
#include <haproxy/proxy.h>
#include <haproxy/regex.h>
#include <haproxy/sample.h>

View File

@ -30,6 +30,7 @@
#include <haproxy/http.h>
#include <haproxy/net_helper.h>
#include <haproxy/pattern-t.h>
#include <haproxy/protocol.h>
#include <haproxy/proxy.h>
#include <haproxy/regex.h>
#include <haproxy/server.h>

View File

@ -19,6 +19,7 @@
#include <haproxy/listener.h>
#include <haproxy/log.h>
#include <haproxy/pool.h>
#include <haproxy/protocol.h>
#include <haproxy/proxy.h>
#include <haproxy/session.h>
#include <haproxy/tcp_rules.h>

View File

@ -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 {