]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proto_quic: Allocate datagram handlers
authorFrédéric Lécaille <flecaille@haproxy.com>
Wed, 26 Jan 2022 16:45:39 +0000 (17:45 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 27 Jan 2022 15:37:55 +0000 (16:37 +0100)
Add quic_dghdlr new struct do define datagram handler tasks, one by thread.
Allocate them and attach them to the listener receiver part calling
quic_alloc_dghdlrs_listener() newly implemented function.

include/haproxy/receiver-t.h
include/haproxy/xprt_quic-t.h
src/proto_quic.c

index ddf3c3564d4b48df9d1d5b6690d663ed386bba86..91a6ea2ea95c6c2ea6f35392526e4d910d0c679e 100644 (file)
@@ -70,6 +70,8 @@ struct receiver {
        __decl_thread(HA_RWLOCK_T cids_lock); /* RW lock for connection IDs tree accesses */
        struct qring *tx_qrings;         /* Array of rings (one by thread) */
        struct mt_list tx_qring_list;    /* The same as ->qrings but arranged in a list */
+
+       struct quic_dghdlr **dghdlrs;    /* Datagram handlers (one by thread) */
        struct rxbuf *rxbufs;            /* Array of buffers for RX (one by thread) */
        struct mt_list rxbuf_list;       /* The same as ->rxbufs but arranged in a list */
 #endif
index 5cfd3daa37e2a2db1ca2304f8d9e40343ee7cba6..0c486af3575511c3be74e6679e6e6933cffdcf25 100644 (file)
@@ -468,6 +468,14 @@ struct quic_rx_packet {
        unsigned int flags;
 };
 
+/* QUIC datagram handler */
+struct quic_dghdlr {
+       struct mt_list dgrams;
+       struct tasklet *task;
+       struct eb_root odcids;
+       struct eb_root cids;
+};
+
 /* UDP datagram context used by the I/O handler receiver callbacks.
  * Useful to store the connection
  */
index c12c8e134cd073b86f814d5b8fc0d3972760894a..aa44ce4c15b1e79f990447d3a1d852a5da927037 100644 (file)
@@ -604,6 +604,55 @@ static int quic_alloc_rxbufs_listener(struct listener *l)
        return 0;
 }
 
+/* Allocate QUIC listener datagram handlers, one by thread.
+ * Returns 1 if succeeded, 0 if not.
+ */
+static int quic_alloc_dghdlrs_listener(struct listener *l)
+{
+       int i;
+
+       l->rx.dghdlrs = calloc(global.nbthread, sizeof *l->rx.dghdlrs);
+       if (!l->rx.dghdlrs)
+               return 0;
+
+       for (i = 0; i < global.nbthread; i++) {
+               struct quic_dghdlr *dghdlr;
+
+               dghdlr = calloc(1, sizeof *dghdlr);
+               if (!dghdlr)
+                       goto err;
+
+               dghdlr->task = tasklet_new();
+               if (!dghdlr->task) {
+                       free(dghdlr);
+                       goto err;
+               }
+
+               dghdlr->task->tid = i;
+               dghdlr->task->context = dghdlr;
+               dghdlr->odcids = EB_ROOT_UNIQUE;
+               dghdlr->cids = EB_ROOT_UNIQUE;
+               MT_LIST_INIT(&dghdlr->dgrams);
+               l->rx.dghdlrs[i] = dghdlr;
+       }
+
+       return 1;
+
+ err:
+       for (i = 0; i < global.nbthread; i++) {
+               struct quic_dghdlr *dghdlr = l->rx.dghdlrs[i];
+
+               if (!dghdlr)
+                       break;
+
+               tasklet_free(dghdlr->task);
+               free(dghdlr);
+       }
+       free(l->rx.dghdlrs);
+
+       return 0;
+}
+
 /* This function tries to bind a QUIC4/6 listener. It may return a warning or
  * an error message in <errmsg> if the message is at most <errlen> bytes long
  * (including '\0'). Note that <errmsg> may be NULL if <errlen> is also zero.
@@ -635,8 +684,9 @@ static int quic_bind_listener(struct listener *listener, char *errmsg, int errle
        }
 
        if (!quic_alloc_tx_rings_listener(listener) ||
-           !quic_alloc_rxbufs_listener(listener)) {
-               msg = "could not initialize tx/rx rings";
+           !quic_alloc_rxbufs_listener(listener) ||
+           !quic_alloc_dghdlrs_listener(listener)) {
+               msg = "could not initialize tx/rx rings or dgram handlers";
                err |= ERR_WARN;
                goto udp_return;
        }