From: Frédéric Lécaille Date: Wed, 26 Jan 2022 16:45:39 +0000 (+0100) Subject: MINOR: proto_quic: Allocate datagram handlers X-Git-Tag: v2.6-dev1~56 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=69dd5e6a0b05190381415908e8db732432316e18;p=thirdparty%2Fhaproxy.git MINOR: proto_quic: Allocate datagram handlers 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. --- diff --git a/include/haproxy/receiver-t.h b/include/haproxy/receiver-t.h index ddf3c3564d..91a6ea2ea9 100644 --- a/include/haproxy/receiver-t.h +++ b/include/haproxy/receiver-t.h @@ -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 diff --git a/include/haproxy/xprt_quic-t.h b/include/haproxy/xprt_quic-t.h index 5cfd3daa37..0c486af357 100644 --- a/include/haproxy/xprt_quic-t.h +++ b/include/haproxy/xprt_quic-t.h @@ -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 */ diff --git a/src/proto_quic.c b/src/proto_quic.c index c12c8e134c..aa44ce4c15 100644 --- a/src/proto_quic.c +++ b/src/proto_quic.c @@ -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 if the message is at most bytes long * (including '\0'). Note that may be NULL if 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; }