From cd2962ee649f77e2669945584e2ee313467049bb Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Thu, 20 Nov 2025 16:26:41 +0100 Subject: [PATCH] MINOR: quic: store source address for backend conns 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 | 9 ++++++++- src/quic_sock.c | 10 ++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/proto_quic.c b/src/proto_quic.c index bbf5626f8..50b231b2a 100644 --- a/src/proto_quic.c +++ b/src/proto_quic.c @@ -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); diff --git a/src/quic_sock.c b/src/quic_sock.c index e10dd6923..f0322e507 100644 --- a/src/quic_sock.c +++ b/src/quic_sock.c @@ -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))