From a7434007170d32b408e8bccb6f3978acb1070c38 Mon Sep 17 00:00:00 2001 From: Frederic Lecaille Date: Tue, 19 Dec 2023 07:58:48 +0100 Subject: [PATCH] MINOR: quic-be: xprt ->init() adapatations Allocate a connection to connect to QUIC servers from qc_conn_init() which is the ->init() QUIC xprt callback. Also initialize ->prepare_srv and ->destroy_srv callback as this done for TCP servers. --- include/haproxy/quic_conn.h | 3 ++- src/quic_conn.c | 5 +++-- src/quic_rx.c | 2 +- src/xprt_quic.c | 21 +++++++++++++++++++-- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/include/haproxy/quic_conn.h b/include/haproxy/quic_conn.h index b6a416644..77d9f69be 100644 --- a/include/haproxy/quic_conn.h +++ b/include/haproxy/quic_conn.h @@ -69,7 +69,8 @@ struct quic_conn *qc_new_conn(const struct quic_version *qv, int ipv4, struct quic_connection_id *conn_id, struct sockaddr_storage *local_addr, struct sockaddr_storage *peer_addr, - int server, int token, void *owner); + int server, int token, void *owner, + struct connection *conn); int quic_build_post_handshake_frames(struct quic_conn *qc); const struct quic_version *qc_supported_version(uint32_t version); int quic_peer_validated_addr(struct quic_conn *qc); diff --git a/src/quic_conn.c b/src/quic_conn.c index 82c630add..7ca436062 100644 --- a/src/quic_conn.c +++ b/src/quic_conn.c @@ -1032,7 +1032,8 @@ struct quic_conn *qc_new_conn(const struct quic_version *qv, int ipv4, struct quic_connection_id *conn_id, struct sockaddr_storage *local_addr, struct sockaddr_storage *peer_addr, - int server, int token, void *owner) + int server, int token, void *owner, + struct connection *conn) { struct quic_conn *qc = NULL; struct listener *l = server ? owner : NULL; @@ -1100,7 +1101,7 @@ struct quic_conn *qc_new_conn(const struct quic_version *qv, int ipv4, qc->idle_timer_task = NULL; qc->xprt_ctx = NULL; - qc->conn = NULL; + qc->conn = conn; qc->qcc = NULL; qc->app_ops = NULL; qc->path = NULL; diff --git a/src/quic_rx.c b/src/quic_rx.c index 6f650c4c1..2398cd8cb 100644 --- a/src/quic_rx.c +++ b/src/quic_rx.c @@ -1820,7 +1820,7 @@ static struct quic_conn *quic_rx_pkt_retrieve_conn(struct quic_rx_packet *pkt, qc = qc_new_conn(pkt->version, ipv4, &pkt->dcid, &pkt->scid, &token_odcid, conn_id, &dgram->daddr, &pkt->saddr, 1, - !!pkt->token_len, l); + !!pkt->token_len, l, NULL); if (qc == NULL) { pool_free(pool_head_quic_connection_id, conn_id); goto err; diff --git a/src/xprt_quic.c b/src/xprt_quic.c index dcca43509..1575f3645 100644 --- a/src/xprt_quic.c +++ b/src/xprt_quic.c @@ -111,10 +111,25 @@ static int quic_conn_unsubscribe(struct connection *conn, void *xprt_ctx, int ev */ static int qc_conn_init(struct connection *conn, void **xprt_ctx) { - struct quic_conn *qc = conn->handle.qc; + int ret = -1; + struct quic_conn *qc = NULL; TRACE_ENTER(QUIC_EV_CONN_NEW, qc); + if (objt_listener(conn->target)) { + qc = conn->handle.qc; + } + else { + int ipv4 = conn->dst->ss_family == AF_INET; + struct server *srv = objt_server(conn->target); + qc = qc_new_conn(quic_version_1, ipv4, NULL, NULL, NULL, + NULL, NULL, &srv->addr, 0, 0, srv, conn); + } + + if (!qc) + goto out; + + ret = 0; /* Ensure thread connection migration is finalized ASAP. */ if (qc->flags & QUIC_FL_CONN_TID_REBIND) qc_finalize_tid_rebind(qc); @@ -128,7 +143,7 @@ static int qc_conn_init(struct connection *conn, void **xprt_ctx) out: TRACE_LEAVE(QUIC_EV_CONN_NEW, qc); - return 0; + return ret; } /* Start the QUIC transport layer */ @@ -178,6 +193,8 @@ static struct xprt_ops ssl_quic = { .start = qc_xprt_start, .prepare_bind_conf = ssl_sock_prepare_bind_conf, .destroy_bind_conf = ssl_sock_destroy_bind_conf, + .prepare_srv = ssl_sock_prepare_srv_ctx, + .destroy_srv = ssl_sock_free_srv_ctx, .get_alpn = ssl_sock_get_alpn, .get_ssl_sock_ctx = qc_get_ssl_sock_ctx, .dump_info = qc_xprt_dump_info,