]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: quic: store source address for backend conns
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 20 Nov 2025 15:26:41 +0000 (16:26 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 20 Nov 2025 15:44:03 +0000 (16:44 +0100)
quic_conn has a local_addr member which is used to store the connection
source address. On backend side, this member is initialized to NULL as
the address is not yet known prior to connect. With this patch,
quic_connect_server() is extended so that local_addr is updated after
connect() success.

Also, quic_sock_get_src() is completed for the backend side which now
returns local_addr member. This step is necessary to properly support
fetches bc_src/bc_src_port.

src/proto_quic.c
src/quic_sock.c

index bbf5626f85ee37b6d9a9e44f01baab9cdc738a5a..50b231b2ac94b2dd5e2d57b6ed72c51b2412df69 100644 (file)
@@ -285,8 +285,9 @@ int quic_connect_server(struct connection *conn, int flags)
        struct server *srv;
        struct proxy *be;
        struct conn_src *src;
-       struct sockaddr_storage *addr;
+       struct sockaddr_storage *addr, saddr;
        struct quic_conn *qc = conn->handle.qc;
+       socklen_t saddr_len;
 
        BUG_ON(qc->fd != -1);
        BUG_ON(!conn->dst);
@@ -427,6 +428,12 @@ int quic_connect_server(struct connection *conn, int flags)
                return SF_ERR_SRVCL;
        }
 
+       /* Update quic-conn source address after connect. */
+       if (getsockname(fd, (struct sockaddr *)&saddr, &saddr_len) == 0) {
+               if (saddr_len <= sizeof(qc->local_addr))
+                       qc->local_addr = saddr;
+       }
+
        qc->fd = fd;
        fd_insert(fd, qc, quic_conn_sock_fd_iocb, tgid, ti->ltid_bit);
        fd_want_recv(fd);
index e10dd6923a5f00de8182395f31178fbde21ff4c9..f0322e5070dd5c2ab0fe84aa567e26d0b25a971a 100644 (file)
@@ -60,8 +60,14 @@ int quic_sock_get_src(struct connection *conn, struct sockaddr *addr, socklen_t
 
        qc = conn->handle.qc;
        if (conn_is_back(conn)) {
-               /* no source address defined for outgoing connections for now */
-               return -1;
+               /* source address should be known since connect() */
+               if (!is_addr(&qc->local_addr))
+                       return -1;
+
+               if (len > sizeof(qc->local_addr))
+                       len = sizeof(qc->local_addr);
+               memcpy(addr, &qc->local_addr, len);
+               return 0;
        } else {
                /* front connection, return the peer's address */
                if (len > sizeof(qc->peer_addr))