]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: proto_uxst: take in account server namespace
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Tue, 23 Apr 2024 21:11:15 +0000 (23:11 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 30 Apr 2024 19:38:18 +0000 (21:38 +0200)
As UNIX Domain sockets could be attached to Linux namespaces (see more details
about it from the Linux kernel patch set below:

https://lore.kernel.org/netdev/m1hbl7hxo3.fsf@fess.ebiederm.org),

it is better to use sock_create_server_socket() in UNIX stream protocol
implementation, as this function calls my_socket_at() and the latter takes
in account server network namespace, which could be configured as in example
below:

       backend be_bar
                ...
                server rpicam0 /run/ustreamer.sock namespace foonet

So, for UNIX Domain socket, used as an address of some backend server, this
patch makes possible to perform connect() to this backend server from the same
network namespace, where the server is running, or where its listening socket
was created.

Using sock_create_server_socket() in UNIX stream protocol implementation also
makes the code of uxst_connect_server() more uniform with tcp_connect_server()
and quic_connect_server().

src/proto_uxst.c

index 7988e00d15db323fc1c6bb3ec4806cb4cc79a49a..cd584aa9abb27414bb5d68100e31abc78c397c59 100644 (file)
@@ -239,7 +239,8 @@ static int uxst_connect_server(struct connection *conn, int flags)
                return SF_ERR_INTERNAL;
        }
 
-       if ((fd = conn->handle.fd = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) {
+       fd = conn->handle.fd = sock_create_server_socket(conn);
+       if (fd == -1) {
                qfprintf(stderr, "Cannot get a server socket.\n");
 
                if (errno == ENFILE) {