]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: protocol: rely on AF_CUST_ABNS family to recognize ABNS sockets
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 24 Oct 2024 12:20:01 +0000 (14:20 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Tue, 29 Oct 2024 11:14:37 +0000 (12:14 +0100)
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
src/connection.c
src/extcheck.c
src/hlua.c
src/hlua_fcn.c
src/session.c
src/tools.c

index c33b1b7264db26ff2ac544e7854863055c925666..556be111b07944757af2a063afb0f1b42cfe5a89 100644 (file)
--- 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);
index ea895963e85f6c03677936ee5aea47ec05d712f5..9c1d4a013394b43af70ad68f28da4d698155955c 100644 (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:
index 2c04dc7a22c7c63f81dd840d2d56096d5fb7dba1..20e9fa8f942453ca09f89cf835f599fbf564a36b 100644 (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>
index c8b42dc8198653f2bef4f1a714b2e9a7a2cdfc26..cd2b908d732031df293173cc7bf55d479a0158a8 100644 (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>
index 21a023828bf8bbc29e6aa6d8dd8f8748bdf341f1..afb5cf07ec1a26b8f2ed9ad4bb9f03079b9d87ef 100644 (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>
index 5dbbba8e5cef38f307f1067a78510196d3c84c1a..ac82aa8eaf587cb161ac0058172ffbe104c68c10 100644 (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>
index 572d12482b4c5e2c8178e522d5773fbe7e5e9026..a51a4ffdc5a67d6dfc8c5bbad668dbb3b82699b5 100644 (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 {