From: Amaury Denoyelle Date: Tue, 1 Dec 2026 09:36:49 +0000 (+0100) Subject: CLEANUP: quic: refactor qc_new_conn() to use an obj_type X-Git-Url: https://git.kaiwu.me/http/%22../$%7BISSUES%7D/static/%7B@url%7D?a=commitdiff_plain;h=e409895493221b19eadc2ab54f041b8930d75251;p=haproxy.git CLEANUP: quic: refactor qc_new_conn() to use an obj_type Function qc_new_conn() is used both on frontend and backend sides. First parameter was a void pointer, either referring to a listener or a server instance, depending on the proxy side. This was used to set either the local listener or the local server variable, the other one remaining NULL. This code works as expected, but it triggers a false report from coverity, which has no way to know that either the listener or the server is set. Adjust the code to use an obj_type enum pointer instead of an opaque one, plus a switch statement that makes this state explicit. This should fix coverity report from github issue #3247. --- diff --git a/include/haproxy/quic_conn.h b/include/haproxy/quic_conn.h index c01b82e6a..88736716a 100644 --- a/include/haproxy/quic_conn.h +++ b/include/haproxy/quic_conn.h @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -65,7 +66,7 @@ struct task *quic_conn_app_io_cb(struct task *t, void *context, unsigned int sta void quic_conn_closed_err_count_inc(struct quic_conn *qc, struct quic_frame *frm); int qc_h3_request_reject(struct quic_conn *qc, uint64_t id); -struct quic_conn *qc_new_conn(void *target, +struct quic_conn *qc_new_conn(enum obj_type *target, const struct quic_rx_packet *initial_pkt, const struct quic_cid *token_odcid, struct connection *connection, diff --git a/src/quic_conn.c b/src/quic_conn.c index 1b3027415..53331e7ee 100644 --- a/src/quic_conn.c +++ b/src/quic_conn.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -1097,7 +1098,7 @@ struct task *qc_process_timer(struct task *task, void *ctx, unsigned int state) * * Returns the newly allocated quic_conn instance on success or NULL on error. */ -struct quic_conn *qc_new_conn(void *target, +struct quic_conn *qc_new_conn(enum obj_type *target, const struct quic_rx_packet *initial_pkt, const struct quic_cid *token_odcid, struct connection *conn, @@ -1106,15 +1107,29 @@ struct quic_conn *qc_new_conn(void *target, struct sockaddr_storage *peer_addr) { struct quic_conn *qc = NULL; - struct listener *l = objt_listener(target); - struct server *srv = objt_server(target); - struct proxy *prx = l ? l->bind_conf->frontend : __objt_server(target)->proxy; + struct listener *l = NULL; + struct server *srv = NULL; + struct proxy *prx; const struct quic_cc_algo *cc_algo = NULL; size_t max_cwnd; unsigned int next_actconn = 0, next_sslconn = 0, next_handshake = 0; TRACE_ENTER(QUIC_EV_CONN_INIT); + switch (obj_type(target)) { + case OBJ_TYPE_LISTENER: + l = __objt_listener(target); + prx = l->bind_conf->frontend; + break; + case OBJ_TYPE_SERVER: + srv = __objt_server(target); + prx = srv->proxy; + break; + default: + ABORT_NOW(); + return NULL; + } + next_sslconn = increment_sslconn(); if (!next_sslconn) { TRACE_STATE("sslconn reached", QUIC_EV_CONN_INIT); diff --git a/src/quic_rx.c b/src/quic_rx.c index 1bdb98fb7..42ab47b74 100644 --- a/src/quic_rx.c +++ b/src/quic_rx.c @@ -2002,7 +2002,7 @@ static struct quic_conn *quic_rx_pkt_retrieve_conn(struct quic_rx_packet *pkt, in46un_to_addr(&pkt->saddr, &saddr); in46un_to_addr(&dgram->daddr, &daddr); - qc = qc_new_conn(l, pkt, &token_odcid, NULL, conn_id, + qc = qc_new_conn(&l->obj_type, pkt, &token_odcid, NULL, conn_id, &daddr, &saddr); if (qc == NULL) { quic_cid_delete(conn_id); /* Removes CID from global tree as it points to a NULL qc. */ diff --git a/src/xprt_quic.c b/src/xprt_quic.c index 632eb5286..135bbc54f 100644 --- a/src/xprt_quic.c +++ b/src/xprt_quic.c @@ -165,7 +165,7 @@ static int qc_conn_init(struct connection *conn, void **xprt_ctx) goto out; } - qc = qc_new_conn(srv, NULL, NULL, conn, conn_id, NULL, &srv->addr); + qc = qc_new_conn(&srv->obj_type, NULL, NULL, conn, conn_id, NULL, &srv->addr); if (!qc) { quic_cid_delete(conn_id); pool_free(pool_head_quic_connection_id, conn_id);