]> git.kaiwu.me - haproxy.git/commitdiff
CLEANUP: quic: refactor qc_new_conn() to use an obj_type
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 1 Dec 2026 09:36:49 +0000 (10:36 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 1 Dec 2026 10:05:00 +0000 (11:05 +0100)
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.

include/haproxy/quic_conn.h
src/quic_conn.c
src/quic_rx.c
src/xprt_quic.c

index c01b82e6a5a340b22508c2570dc1c21f25125eb1..88736716aa372c5ad0655ad027e7be7465e5c9b5 100644 (file)
@@ -35,6 +35,7 @@
 #include <haproxy/dynbuf.h>
 #include <haproxy/ncbmbuf.h>
 #include <haproxy/net_helper.h>
+#include <haproxy/obj_type-t.h>
 #include <haproxy/openssl-compat.h>
 #include <haproxy/ticks.h>
 
@@ -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,
index 1b3027415bca61237f4b46012d563d9be2e6f4fe..53331e7eece3b874b4cef0ba31412fa9eafd91e5 100644 (file)
@@ -40,6 +40,7 @@
 #include <haproxy/log.h>
 #include <haproxy/mux_quic.h>
 #include <haproxy/ncbuf.h>
+#include <haproxy/obj_type.h>
 #include <haproxy/pipe.h>
 #include <haproxy/proxy.h>
 #include <haproxy/quic_ack.h>
@@ -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);
index 1bdb98fb78c715a2b428897415ce22290957c6a8..42ab47b74990e9319a228b8cc6277f6f0090c589 100644 (file)
@@ -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. */
index 632eb5286dec114b17e766f011516cca36a74912..135bbc54f8613286814088dddc8dd61517825175 100644 (file)
@@ -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);