blob: 2e5ebdc9fc1d2e0fa751ac6a73a225108307b054 [file] [log] [blame]
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001#include <haproxy/mux_quic.h>
Frédéric Lécailledfbae762021-02-18 09:59:01 +01002
Amaury Denoyelleeb01f592021-10-07 16:44:05 +02003#include <import/eb64tree.h>
4
Frédéric Lécailledfbae762021-02-18 09:59:01 +01005#include <haproxy/api.h>
Frédéric Lécailledfbae762021-02-18 09:59:01 +01006#include <haproxy/connection.h>
Christopher Faulet1329f2a2021-12-16 17:32:56 +01007#include <haproxy/conn_stream.h>
Amaury Denoyelledeed7772021-12-03 11:36:46 +01008#include <haproxy/dynbuf.h>
Amaury Denoyelle9a327a72022-02-14 17:11:09 +01009#include <haproxy/htx.h>
Amaury Denoyelle1b2dba52022-04-15 17:32:04 +020010#include <haproxy/list.h>
Amaury Denoyelledeed7772021-12-03 11:36:46 +010011#include <haproxy/pool.h>
Amaury Denoyelle0cc02a32022-04-19 17:21:11 +020012#include <haproxy/quic_stream.h>
Amaury Denoyelle251eadf2022-03-24 17:14:52 +010013#include <haproxy/sink.h>
Amaury Denoyelleeb01f592021-10-07 16:44:05 +020014#include <haproxy/ssl_sock-t.h>
Amaury Denoyelledd4fbfb2022-03-24 16:09:16 +010015#include <haproxy/trace.h>
Amaury Denoyelle2c71fe52022-02-09 18:16:49 +010016#include <haproxy/xprt_quic.h>
Frédéric Lécailledfbae762021-02-18 09:59:01 +010017
Amaury Denoyelledeed7772021-12-03 11:36:46 +010018DECLARE_POOL(pool_head_qcc, "qcc", sizeof(struct qcc));
Frédéric Lécailledfbae762021-02-18 09:59:01 +010019DECLARE_POOL(pool_head_qcs, "qcs", sizeof(struct qcs));
20
Amaury Denoyelledd4fbfb2022-03-24 16:09:16 +010021/* trace source and events */
22static void qmux_trace(enum trace_level level, uint64_t mask,
23 const struct trace_source *src,
24 const struct ist where, const struct ist func,
25 const void *a1, const void *a2, const void *a3, const void *a4);
26
27static const struct trace_event qmux_trace_events[] = {
Amaury Denoyelle4f137572022-03-24 17:10:00 +010028#define QMUX_EV_QCC_RECV (1ULL << 1)
29 { .mask = QMUX_EV_QCC_RECV, .name = "qcc_recv", .desc = "Rx on QUIC connection" },
30#define QMUX_EV_QCC_SEND (1ULL << 2)
31 { .mask = QMUX_EV_QCC_SEND, .name = "qcc_send", .desc = "Tx on QUIC connection" },
32#define QMUX_EV_QCC_WAKE (1ULL << 3)
33 { .mask = QMUX_EV_QCC_WAKE, .name = "qcc_wake", .desc = "QUIC connection woken up" },
34#define QMUX_EV_QCC_END (1ULL << 4)
35 { .mask = QMUX_EV_QCC_END, .name = "qcc_end", .desc = "QUIC connection terminated" },
36#define QMUX_EV_QCC_NQCS (1ULL << 5)
37 { .mask = QMUX_EV_QCC_NQCS, .name = "qcc_no_qcs", .desc = "QUIC stream not found" },
38#define QMUX_EV_QCS_NEW (1ULL << 6)
39 { .mask = QMUX_EV_QCS_NEW, .name = "qcs_new", .desc = "new QUIC stream" },
40#define QMUX_EV_QCS_RECV (1ULL << 7)
41 { .mask = QMUX_EV_QCS_RECV, .name = "qcs_recv", .desc = "Rx on QUIC stream" },
42#define QMUX_EV_QCS_SEND (1ULL << 8)
43 { .mask = QMUX_EV_QCS_SEND, .name = "qcs_send", .desc = "Tx on QUIC stream" },
44#define QMUX_EV_QCS_END (1ULL << 9)
45 { .mask = QMUX_EV_QCS_END, .name = "qcs_end", .desc = "QUIC stream terminated" },
46#define QMUX_EV_STRM_RECV (1ULL << 10)
47 { .mask = QMUX_EV_STRM_RECV, .name = "strm_recv", .desc = "receiving data for stream" },
48#define QMUX_EV_STRM_SEND (1ULL << 11)
49 { .mask = QMUX_EV_STRM_SEND, .name = "strm_send", .desc = "sending data for stream" },
50#define QMUX_EV_STRM_END (1ULL << 12)
51 { .mask = QMUX_EV_STRM_END, .name = "strm_end", .desc = "detaching app-layer stream" },
Amaury Denoyellefa29f332022-03-25 09:09:40 +010052#define QMUX_EV_SEND_FRM (1ULL << 13)
53 { .mask = QMUX_EV_SEND_FRM, .name = "send_frm", .desc = "sending QUIC frame" },
Amaury Denoyelleda6ad202022-04-12 11:41:04 +020054/* special event dedicated to qcs_xfer_data */
55#define QMUX_EV_QCS_XFER_DATA (1ULL << 14)
56 { .mask = QMUX_EV_QCS_XFER_DATA, .name = "qcs_xfer_data", .desc = "qcs_xfer_data" },
57/* special event dedicated to qcs_build_stream_frm */
58#define QMUX_EV_QCS_BUILD_STRM (1ULL << 15)
59 { .mask = QMUX_EV_QCS_BUILD_STRM, .name = "qcs_build_stream_frm", .desc = "qcs_build_stream_frm" },
Amaury Denoyelledd4fbfb2022-03-24 16:09:16 +010060 { }
61};
62
Amaury Denoyelleda6ad202022-04-12 11:41:04 +020063/* custom arg for QMUX_EV_QCS_XFER_DATA */
64struct qcs_xfer_data_trace_arg {
65 size_t prep;
Amaury Denoyellefdcec362022-03-25 09:28:10 +010066 int xfer;
Amaury Denoyelleda6ad202022-04-12 11:41:04 +020067};
68/* custom arg for QMUX_EV_QCS_BUILD_STRM */
69struct qcs_build_stream_trace_arg {
70 size_t len;
Amaury Denoyellefdcec362022-03-25 09:28:10 +010071 char fin;
72 uint64_t offset;
73};
74
Amaury Denoyelledd4fbfb2022-03-24 16:09:16 +010075static const struct name_desc qmux_trace_lockon_args[4] = {
76 /* arg1 */ { /* already used by the connection */ },
77 /* arg2 */ { .name="qcs", .desc="QUIC stream" },
78 /* arg3 */ { },
79 /* arg4 */ { }
80};
81
82static const struct name_desc qmux_trace_decoding[] = {
83#define QMUX_VERB_CLEAN 1
84 { .name="clean", .desc="only user-friendly stuff, generally suitable for level \"user\"" },
85#define QMUX_VERB_MINIMAL 2
86 { .name="minimal", .desc="report only qcc/qcs state and flags, no real decoding" },
87 { /* end */ }
88};
89
90struct trace_source trace_qmux = {
91 .name = IST("qmux"),
92 .desc = "QUIC multiplexer",
93 .arg_def = TRC_ARG1_CONN, /* TRACE()'s first argument is always a connection */
94 .default_cb = qmux_trace,
95 .known_events = qmux_trace_events,
96 .lockon_args = qmux_trace_lockon_args,
97 .decoding = qmux_trace_decoding,
98 .report_events = ~0, /* report everything by default */
99};
100
101#define TRACE_SOURCE &trace_qmux
102INITCALL1(STG_REGISTER, trace_register_source, TRACE_SOURCE);
103
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100104/* Allocate a new QUIC streams with id <id> and type <type>. */
105struct qcs *qcs_new(struct qcc *qcc, uint64_t id, enum qcs_type type)
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100106{
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100107 struct qcs *qcs;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100108
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100109 TRACE_ENTER(QMUX_EV_QCS_NEW, qcc->conn);
110
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100111 qcs = pool_alloc(pool_head_qcs);
112 if (!qcs)
Amaury Denoyelle17014a62022-04-27 15:09:27 +0200113 return NULL;
114
115 qcs->stream = NULL;
116 qcs->qcc = qcc;
117 qcs->cs = NULL;
118 qcs->flags = QC_SF_NONE;
Amaury Denoyelle47447af2022-04-27 15:17:11 +0200119 qcs->ctx = NULL;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100120
Amaury Denoyellee4301da2022-04-19 17:59:50 +0200121 /* allocate transport layer stream descriptor
122 *
123 * TODO qc_stream_desc is only useful for Tx buffering. It should not
124 * be required for unidirectional remote streams.
125 */
Amaury Denoyelle17014a62022-04-27 15:09:27 +0200126 qcs->stream = qc_stream_desc_new(id, qcs, qcc->conn->handle.qc);
127 if (!qcs->stream)
128 goto err;
Amaury Denoyelle7272cd72022-03-29 15:15:54 +0200129
Amaury Denoyelle47447af2022-04-27 15:17:11 +0200130 if (qcc->app_ops->attach) {
131 if (qcc->app_ops->attach(qcs))
132 goto err;
133 }
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100134
Christopher Faulet9ec2f4d2022-03-23 15:15:29 +0100135 qcs->endp = cs_endpoint_new();
136 if (!qcs->endp) {
137 pool_free(pool_head_qcs, qcs);
Amaury Denoyelle17014a62022-04-27 15:09:27 +0200138 goto err;
Christopher Faulet9ec2f4d2022-03-23 15:15:29 +0100139 }
140 qcs->endp->target = qcs;
141 qcs->endp->ctx = qcc->conn;
142 qcs->endp->flags |= (CS_EP_T_MUX|CS_EP_ORPHAN|CS_EP_NOT_FIRST);
143
Amaury Denoyellee4301da2022-04-19 17:59:50 +0200144 qcs->id = qcs->by_id.key = id;
Amaury Denoyelled8e680c2022-03-29 15:18:44 +0200145 /* store transport layer stream descriptor in qcc tree */
Amaury Denoyellee4301da2022-04-19 17:59:50 +0200146 eb64_insert(&qcc->streams_by_id, &qcs->by_id);
Christopher Faulet9ec2f4d2022-03-23 15:15:29 +0100147
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100148 qcc->strms[type].nb_streams++;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100149
Amaury Denoyelle6ea78192022-03-07 15:47:02 +0100150 /* If stream is local, use peer remote-limit, or else the opposite. */
151 /* TODO use uni limit for unidirectional streams */
152 qcs->tx.msd = quic_stream_is_local(qcc, id) ? qcc->rfctl.msd_bidi_r :
153 qcc->rfctl.msd_bidi_l;
154
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100155 qcs->rx.buf = BUF_NULL;
Amaury Denoyelle9a327a72022-02-14 17:11:09 +0100156 qcs->rx.app_buf = BUF_NULL;
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100157 qcs->rx.offset = 0;
158 qcs->rx.frms = EB_ROOT_UNIQUE;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100159
Amaury Denoyelle44d09122022-04-26 11:21:10 +0200160 /* TODO use uni limit for unidirectional streams */
161 qcs->rx.msd = quic_stream_is_local(qcc, id) ? qcc->lfctl.msd_bidi_l :
162 qcc->lfctl.msd_bidi_r;
163
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100164 qcs->tx.buf = BUF_NULL;
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100165 qcs->tx.offset = 0;
Amaury Denoyelle6ccfa3c2022-03-10 16:45:53 +0100166 qcs->tx.sent_offset = 0;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100167
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100168 qcs->wait_event.tasklet = NULL;
169 qcs->wait_event.events = 0;
170 qcs->subs = NULL;
171
172 out:
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100173 TRACE_LEAVE(QMUX_EV_QCS_NEW, qcc->conn, qcs);
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100174 return qcs;
Amaury Denoyelle17014a62022-04-27 15:09:27 +0200175
176 err:
Amaury Denoyelle47447af2022-04-27 15:17:11 +0200177 if (qcs->ctx && qcc->app_ops->detach)
178 qcc->app_ops->detach(qcs);
179
Amaury Denoyelle17014a62022-04-27 15:09:27 +0200180 if (qcs->stream)
181 qc_stream_desc_release(qcs->stream);
182
183 pool_free(pool_head_qcs, qcs);
184 return NULL;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100185}
186
Amaury Denoyelledccbd732022-03-29 18:36:59 +0200187/* Free a qcs. This function must only be done to remove a stream on allocation
188 * error or connection shutdown. Else use qcs_destroy which handle all the
189 * QUIC connection mechanism.
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100190 */
Amaury Denoyelledccbd732022-03-29 18:36:59 +0200191void qcs_free(struct qcs *qcs)
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100192{
Amaury Denoyelledccbd732022-03-29 18:36:59 +0200193 b_free(&qcs->rx.buf);
194 b_free(&qcs->tx.buf);
Amaury Denoyelledccbd732022-03-29 18:36:59 +0200195
Amaury Denoyelled8e680c2022-03-29 15:18:44 +0200196 BUG_ON(!qcs->qcc->strms[qcs_id_type(qcs->id)].nb_streams);
197 --qcs->qcc->strms[qcs_id_type(qcs->id)].nb_streams;
Amaury Denoyelledccbd732022-03-29 18:36:59 +0200198
Amaury Denoyelle47447af2022-04-27 15:17:11 +0200199 if (qcs->ctx && qcs->qcc->app_ops->detach)
200 qcs->qcc->app_ops->detach(qcs);
201
Amaury Denoyellee4301da2022-04-19 17:59:50 +0200202 qc_stream_desc_release(qcs->stream);
203
Christopher Faulet9ec2f4d2022-03-23 15:15:29 +0100204 BUG_ON(qcs->endp && !(qcs->endp->flags & CS_EP_ORPHAN));
205 cs_endpoint_free(qcs->endp);
Amaury Denoyellee4301da2022-04-19 17:59:50 +0200206
207 eb64_delete(&qcs->by_id);
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100208 pool_free(pool_head_qcs, qcs);
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100209}
210
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100211struct buffer *qc_get_buf(struct qcs *qcs, struct buffer *bptr)
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100212{
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100213 struct buffer *buf = b_alloc(bptr);
214 BUG_ON(!buf);
215 return buf;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100216}
217
Amaury Denoyellea3f222d2021-12-06 11:24:00 +0100218int qcs_subscribe(struct qcs *qcs, int event_type, struct wait_event *es)
219{
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100220 struct qcc *qcc = qcs->qcc;
221
222 TRACE_ENTER(QMUX_EV_STRM_SEND|QMUX_EV_STRM_RECV, qcc->conn, qcs);
Amaury Denoyellea3f222d2021-12-06 11:24:00 +0100223
224 BUG_ON(event_type & ~(SUB_RETRY_SEND|SUB_RETRY_RECV));
225 BUG_ON(qcs->subs && qcs->subs != es);
226
227 es->events |= event_type;
228 qcs->subs = es;
229
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100230 if (event_type & SUB_RETRY_RECV)
231 TRACE_DEVEL("subscribe(recv)", QMUX_EV_STRM_RECV, qcc->conn, qcs);
232
233 if (event_type & SUB_RETRY_SEND)
234 TRACE_DEVEL("subscribe(send)", QMUX_EV_STRM_SEND, qcc->conn, qcs);
235
236 TRACE_LEAVE(QMUX_EV_STRM_SEND|QMUX_EV_STRM_RECV, qcc->conn, qcs);
237
Amaury Denoyellea3f222d2021-12-06 11:24:00 +0100238 return 0;
239}
240
241void qcs_notify_recv(struct qcs *qcs)
242{
243 if (qcs->subs && qcs->subs->events & SUB_RETRY_RECV) {
244 tasklet_wakeup(qcs->subs->tasklet);
245 qcs->subs->events &= ~SUB_RETRY_RECV;
246 if (!qcs->subs->events)
247 qcs->subs = NULL;
248 }
249}
250
251void qcs_notify_send(struct qcs *qcs)
252{
253 if (qcs->subs && qcs->subs->events & SUB_RETRY_SEND) {
254 tasklet_wakeup(qcs->subs->tasklet);
255 qcs->subs->events &= ~SUB_RETRY_SEND;
256 if (!qcs->subs->events)
257 qcs->subs = NULL;
258 }
259}
260
Amaury Denoyelle8a5b27a2021-12-21 11:53:10 +0100261/* Retrieve as an ebtree node the stream with <id> as ID, possibly allocates
262 * several streams, depending on the already open ones.
263 * Return this node if succeeded, NULL if not.
264 */
Amaury Denoyelle50742292022-03-29 14:57:19 +0200265struct qcs *qcc_get_qcs(struct qcc *qcc, uint64_t id)
Amaury Denoyelle8a5b27a2021-12-21 11:53:10 +0100266{
267 unsigned int strm_type;
268 int64_t sub_id;
Amaury Denoyellee4301da2022-04-19 17:59:50 +0200269 struct eb64_node *node;
Amaury Denoyelle50742292022-03-29 14:57:19 +0200270 struct qcs *qcs = NULL;
Amaury Denoyelle8a5b27a2021-12-21 11:53:10 +0100271
272 strm_type = id & QCS_ID_TYPE_MASK;
273 sub_id = id >> QCS_ID_TYPE_SHIFT;
Amaury Denoyellee4301da2022-04-19 17:59:50 +0200274 node = NULL;
Amaury Denoyelle0dc40f02022-02-07 11:44:17 +0100275 if (quic_stream_is_local(qcc, id)) {
Amaury Denoyelle8a5b27a2021-12-21 11:53:10 +0100276 /* Local streams: this stream must be already opened. */
Amaury Denoyellee4301da2022-04-19 17:59:50 +0200277 node = eb64_lookup(&qcc->streams_by_id, id);
278 if (!node) {
Amaury Denoyelle8a5b27a2021-12-21 11:53:10 +0100279 /* unknown stream id */
280 goto out;
281 }
Amaury Denoyellee4301da2022-04-19 17:59:50 +0200282 qcs = eb64_entry(node, struct qcs, by_id);
Amaury Denoyelle8a5b27a2021-12-21 11:53:10 +0100283 }
284 else {
285 /* Remote streams. */
286 struct eb_root *strms;
287 uint64_t largest_id;
288 enum qcs_type qcs_type;
289
290 strms = &qcc->streams_by_id;
291 qcs_type = qcs_id_type(id);
Amaury Denoyellec055e302022-02-07 16:09:06 +0100292
293 /* TODO also checks max-streams for uni streams */
294 if (quic_stream_is_bidi(id)) {
Amaury Denoyelle78396e52022-03-21 17:13:32 +0100295 if (sub_id + 1 > qcc->lfctl.ms_bidi) {
Amaury Denoyellec055e302022-02-07 16:09:06 +0100296 /* streams limit reached */
297 goto out;
298 }
Amaury Denoyelle8a5b27a2021-12-21 11:53:10 +0100299 }
300
301 /* Note: ->largest_id was initialized with (uint64_t)-1 as value, 0 being a
302 * correct value.
303 */
304 largest_id = qcc->strms[qcs_type].largest_id;
305 if (sub_id > (int64_t)largest_id) {
306 /* RFC: "A stream ID that is used out of order results in all streams
307 * of that type with lower-numbered stream IDs also being opened".
308 * So, let's "open" these streams.
309 */
310 int64_t i;
Amaury Denoyelle50742292022-03-29 14:57:19 +0200311 struct qcs *tmp_qcs;
Amaury Denoyelle8a5b27a2021-12-21 11:53:10 +0100312
Amaury Denoyelle50742292022-03-29 14:57:19 +0200313 tmp_qcs = NULL;
Amaury Denoyelle8a5b27a2021-12-21 11:53:10 +0100314 for (i = largest_id + 1; i <= sub_id; i++) {
315 uint64_t id = (i << QCS_ID_TYPE_SHIFT) | strm_type;
316 enum qcs_type type = id & QCS_ID_DIR_BIT ? QCS_CLT_UNI : QCS_CLT_BIDI;
Amaury Denoyelle7272cd72022-03-29 15:15:54 +0200317
Amaury Denoyelle50742292022-03-29 14:57:19 +0200318 tmp_qcs = qcs_new(qcc, id, type);
319 if (!tmp_qcs) {
Amaury Denoyelle8a5b27a2021-12-21 11:53:10 +0100320 /* allocation failure */
321 goto out;
322 }
323
324 qcc->strms[qcs_type].largest_id = i;
325 }
Amaury Denoyelle50742292022-03-29 14:57:19 +0200326 if (tmp_qcs)
327 qcs = tmp_qcs;
Amaury Denoyelle8a5b27a2021-12-21 11:53:10 +0100328 }
329 else {
Amaury Denoyellee4301da2022-04-19 17:59:50 +0200330 node = eb64_lookup(strms, id);
331 if (node)
332 qcs = eb64_entry(node, struct qcs, by_id);
Amaury Denoyelle8a5b27a2021-12-21 11:53:10 +0100333 }
334 }
335
Amaury Denoyelle50742292022-03-29 14:57:19 +0200336 return qcs;
Amaury Denoyelle8a5b27a2021-12-21 11:53:10 +0100337
338 out:
339 return NULL;
340}
341
Amaury Denoyelle0e3010b2022-02-28 11:37:48 +0100342/* Handle a new STREAM frame <strm_frm>. The frame content will be copied in
343 * the buffer of the stream instance. The stream instance will be stored in
344 * <out_qcs>. In case of success, the caller can immediatly call qcc_decode_qcs
345 * to process the frame content.
346 *
Amaury Denoyelle3df8ca02022-04-26 11:36:40 +0200347 * Returns a code indicating how the frame was handled.
348 * - 0: frame received completly and can be dropped.
349 * - 1: frame not received but can be dropped.
350 * - 2: frame cannot be handled, either partially or not at all. <done>
351 * indicated the number of bytes handled. The rest should be buffered.
Amaury Denoyelle0e3010b2022-02-28 11:37:48 +0100352 */
353int qcc_recv(struct qcc *qcc, uint64_t id, uint64_t len, uint64_t offset,
Amaury Denoyelle3df8ca02022-04-26 11:36:40 +0200354 char fin, char *data, struct qcs **out_qcs, size_t *done)
Amaury Denoyelle0e3010b2022-02-28 11:37:48 +0100355{
356 struct qcs *qcs;
Amaury Denoyelle0e3010b2022-02-28 11:37:48 +0100357 size_t total, diff;
358
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100359 TRACE_ENTER(QMUX_EV_QCC_RECV, qcc->conn);
360
Amaury Denoyelle3df8ca02022-04-26 11:36:40 +0200361 *out_qcs = NULL;
362 *done = 0;
363
Amaury Denoyelle50742292022-03-29 14:57:19 +0200364 qcs = qcc_get_qcs(qcc, id);
365 if (!qcs) {
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100366 TRACE_DEVEL("leaving on stream not found", QMUX_EV_QCC_RECV|QMUX_EV_QCC_NQCS, qcc->conn, NULL, &id);
Amaury Denoyelle0e3010b2022-02-28 11:37:48 +0100367 return 1;
368 }
369
Amaury Denoyelle0e3010b2022-02-28 11:37:48 +0100370 *out_qcs = qcs;
371
372 if (offset > qcs->rx.offset)
373 return 2;
374
375 if (offset + len <= qcs->rx.offset) {
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100376 TRACE_DEVEL("leaving on already received offset", QMUX_EV_QCC_RECV|QMUX_EV_QCS_RECV, qcc->conn, qcs);
Amaury Denoyelle0e3010b2022-02-28 11:37:48 +0100377 return 1;
378 }
379
380 /* Last frame already handled for this stream. */
381 BUG_ON(qcs->flags & QC_SF_FIN_RECV);
Amaury Denoyelle44d09122022-04-26 11:21:10 +0200382 /* TODO initial max-stream-data overflow. Implement FLOW_CONTROL_ERROR emission. */
383 BUG_ON(offset + len > qcs->rx.msd);
Amaury Denoyelle0e3010b2022-02-28 11:37:48 +0100384
Amaury Denoyelle3df8ca02022-04-26 11:36:40 +0200385 if (!qc_get_buf(qcs, &qcs->rx.buf) || b_full(&qcs->rx.buf)) {
Amaury Denoyelle0e3010b2022-02-28 11:37:48 +0100386 /* TODO should mark qcs as full */
387 return 2;
388 }
389
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100390 TRACE_DEVEL("newly received offset", QMUX_EV_QCC_RECV|QMUX_EV_QCS_RECV, qcc->conn, qcs);
Amaury Denoyelle0e3010b2022-02-28 11:37:48 +0100391 diff = qcs->rx.offset - offset;
392
Amaury Denoyelle0e3010b2022-02-28 11:37:48 +0100393 len -= diff;
394 data += diff;
395
Amaury Denoyelle3df8ca02022-04-26 11:36:40 +0200396 /* TODO handle STREAM frames larger than RX buffer. */
397 BUG_ON(len > b_size(&qcs->rx.buf));
Amaury Denoyelle0e3010b2022-02-28 11:37:48 +0100398
Amaury Denoyelle3df8ca02022-04-26 11:36:40 +0200399 total = b_putblk(&qcs->rx.buf, data, len);
Amaury Denoyelle0e3010b2022-02-28 11:37:48 +0100400 qcs->rx.offset += total;
Amaury Denoyelle3df8ca02022-04-26 11:36:40 +0200401 *done = total;
Amaury Denoyelle0e3010b2022-02-28 11:37:48 +0100402
Amaury Denoyelle44d09122022-04-26 11:21:10 +0200403 /* TODO initial max-stream-data reached. Implement MAX_STREAM_DATA emission. */
404 BUG_ON(qcs->rx.offset == qcs->rx.msd);
405
Amaury Denoyelle3df8ca02022-04-26 11:36:40 +0200406 if (total < len) {
407 TRACE_DEVEL("leaving on partially received offset", QMUX_EV_QCC_RECV|QMUX_EV_QCS_RECV, qcc->conn, qcs);
408 return 2;
409 }
410
Amaury Denoyelle0e3010b2022-02-28 11:37:48 +0100411 if (fin)
412 qcs->flags |= QC_SF_FIN_RECV;
413
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100414 TRACE_LEAVE(QMUX_EV_QCC_RECV, qcc->conn);
Amaury Denoyelle0e3010b2022-02-28 11:37:48 +0100415 return 0;
416}
417
Amaury Denoyelle1e5e5132022-03-08 16:23:03 +0100418/* Handle a new MAX_DATA frame. <max> must contains the maximum data field of
419 * the frame.
420 *
421 * Returns 0 on success else non-zero.
422 */
423int qcc_recv_max_data(struct qcc *qcc, uint64_t max)
424{
425 if (qcc->rfctl.md < max) {
426 qcc->rfctl.md = max;
427
428 if (qcc->flags & QC_CF_BLK_MFCTL) {
429 qcc->flags &= ~QC_CF_BLK_MFCTL;
430 tasklet_wakeup(qcc->wait_event.tasklet);
431 }
432 }
433 return 0;
434}
435
Amaury Denoyelle8727ff42022-03-08 10:39:55 +0100436/* Handle a new MAX_STREAM_DATA frame. <max> must contains the maximum data
437 * field of the frame and <id> is the identifier of the QUIC stream.
438 *
439 * Returns 0 on success else non-zero.
440 */
441int qcc_recv_max_stream_data(struct qcc *qcc, uint64_t id, uint64_t max)
442{
443 struct qcs *qcs;
444 struct eb64_node *node;
445
446 node = eb64_lookup(&qcc->streams_by_id, id);
447 if (node) {
Amaury Denoyellee4301da2022-04-19 17:59:50 +0200448 qcs = eb64_entry(node, struct qcs, by_id);
Amaury Denoyelle8727ff42022-03-08 10:39:55 +0100449 if (max > qcs->tx.msd) {
450 qcs->tx.msd = max;
451
452 if (qcs->flags & QC_SF_BLK_SFCTL) {
453 qcs->flags &= ~QC_SF_BLK_SFCTL;
454 tasklet_wakeup(qcc->wait_event.tasklet);
455 }
456 }
457 }
458
459 return 0;
460}
461
Amaury Denoyelle0e3010b2022-02-28 11:37:48 +0100462/* Decode the content of STREAM frames already received on the stream instance
463 * <qcs>.
464 *
465 * Returns 0 on success else non-zero.
466 */
467int qcc_decode_qcs(struct qcc *qcc, struct qcs *qcs)
468{
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100469 TRACE_ENTER(QMUX_EV_QCS_RECV, qcc->conn, qcs);
470
Amaury Denoyelle0e3010b2022-02-28 11:37:48 +0100471 if (qcc->app_ops->decode_qcs(qcs, qcs->flags & QC_SF_FIN_RECV, qcc->ctx) < 0) {
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100472 TRACE_DEVEL("leaving on decoding error", QMUX_EV_QCS_RECV, qcc->conn, qcs);
Amaury Denoyelle0e3010b2022-02-28 11:37:48 +0100473 return 1;
474 }
475
Amaury Denoyelleb7104152022-04-22 17:38:43 +0200476 qcs_notify_recv(qcs);
477
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100478 TRACE_LEAVE(QMUX_EV_QCS_RECV, qcc->conn, qcs);
479
Amaury Denoyelle0e3010b2022-02-28 11:37:48 +0100480 return 0;
481}
482
Amaury Denoyellec055e302022-02-07 16:09:06 +0100483static int qc_is_max_streams_needed(struct qcc *qcc)
484{
Amaury Denoyelle78396e52022-03-21 17:13:32 +0100485 return qcc->lfctl.cl_bidi_r > qcc->lfctl.ms_bidi_init / 2;
Amaury Denoyellec055e302022-02-07 16:09:06 +0100486}
487
Ilya Shipitsin5e87bcf2021-12-25 11:45:52 +0500488/* detaches the QUIC stream from its QCC and releases it to the QCS pool. */
Amaury Denoyelle2873a312021-12-08 14:42:55 +0100489static void qcs_destroy(struct qcs *qcs)
490{
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100491 struct connection *conn = qcs->qcc->conn;
Amaury Denoyelled8e680c2022-03-29 15:18:44 +0200492 const uint64_t id = qcs->id;
Amaury Denoyellec055e302022-02-07 16:09:06 +0100493
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100494 TRACE_ENTER(QMUX_EV_QCS_END, conn, qcs);
Amaury Denoyelle2873a312021-12-08 14:42:55 +0100495
Amaury Denoyellec055e302022-02-07 16:09:06 +0100496 if (quic_stream_is_remote(qcs->qcc, id)) {
497 if (quic_stream_is_bidi(id)) {
Amaury Denoyelle78396e52022-03-21 17:13:32 +0100498 ++qcs->qcc->lfctl.cl_bidi_r;
Amaury Denoyellec055e302022-02-07 16:09:06 +0100499 if (qc_is_max_streams_needed(qcs->qcc))
500 tasklet_wakeup(qcs->qcc->wait_event.tasklet);
501 }
502 }
503
Amaury Denoyelledccbd732022-03-29 18:36:59 +0200504 qcs_free(qcs);
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100505
506 TRACE_LEAVE(QMUX_EV_QCS_END, conn);
Amaury Denoyelle2873a312021-12-08 14:42:55 +0100507}
508
509static inline int qcc_is_dead(const struct qcc *qcc)
510{
Amaury Denoyelle198d35f2022-04-01 17:56:58 +0200511 if (qcc->app_ops && qcc->app_ops->is_active &&
512 qcc->app_ops->is_active(qcc, qcc->ctx))
513 return 0;
514
Amaury Denoyelled97fc802022-04-06 16:13:09 +0200515 if ((qcc->conn->flags & CO_FL_ERROR) || !qcc->task)
Amaury Denoyelleaebe26f2022-01-13 16:28:06 +0100516 return 1;
517
518 return 0;
519}
520
521/* Return true if the mux timeout should be armed. */
522static inline int qcc_may_expire(struct qcc *qcc)
523{
Amaury Denoyelle06890aa2022-04-04 16:15:06 +0200524 return !qcc->nb_cs;
Amaury Denoyelle2873a312021-12-08 14:42:55 +0100525}
526
527/* release function. This one should be called to free all resources allocated
528 * to the mux.
529 */
530static void qc_release(struct qcc *qcc)
531{
Christopher Faulet4de1bff2022-04-14 11:36:41 +0200532 struct connection *conn = qcc->conn;
533 struct eb64_node *node;
Amaury Denoyelle2873a312021-12-08 14:42:55 +0100534
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100535 TRACE_ENTER(QMUX_EV_QCC_END);
536
Christopher Faulet4de1bff2022-04-14 11:36:41 +0200537 if (qcc->app_ops && qcc->app_ops->release)
538 qcc->app_ops->release(qcc->ctx);
Amaury Denoyellef8909452022-03-30 11:51:56 +0200539
Christopher Faulet4de1bff2022-04-14 11:36:41 +0200540 if (qcc->task) {
541 task_destroy(qcc->task);
542 qcc->task = NULL;
543 }
Amaury Denoyelle2873a312021-12-08 14:42:55 +0100544
Christopher Faulet4de1bff2022-04-14 11:36:41 +0200545 if (qcc->wait_event.tasklet)
546 tasklet_free(qcc->wait_event.tasklet);
Amaury Denoyellef3e03a42022-04-21 15:41:34 +0200547 if (conn && qcc->wait_event.events) {
548 conn->xprt->unsubscribe(conn, conn->xprt_ctx,
549 qcc->wait_event.events,
550 &qcc->wait_event);
551 }
Amaury Denoyellef8909452022-03-30 11:51:56 +0200552
Christopher Faulet4de1bff2022-04-14 11:36:41 +0200553 /* liberate remaining qcs instances */
554 node = eb64_first(&qcc->streams_by_id);
555 while (node) {
Amaury Denoyellee4301da2022-04-19 17:59:50 +0200556 struct qcs *qcs = eb64_entry(node, struct qcs, by_id);
Christopher Faulet4de1bff2022-04-14 11:36:41 +0200557 node = eb64_next(node);
Amaury Denoyellee4301da2022-04-19 17:59:50 +0200558 qcs_free(qcs);
Amaury Denoyelle2873a312021-12-08 14:42:55 +0100559 }
560
Christopher Faulet4de1bff2022-04-14 11:36:41 +0200561 pool_free(pool_head_qcc, qcc);
562
Amaury Denoyelle2873a312021-12-08 14:42:55 +0100563 if (conn) {
Amaury Denoyelle0e0969d2022-01-31 15:41:14 +0100564 LIST_DEL_INIT(&conn->stopping_list);
565
Willy Tarreau784b8682022-04-11 14:18:10 +0200566 conn->handle.qc->conn = NULL;
Amaury Denoyelle2873a312021-12-08 14:42:55 +0100567 conn->mux = NULL;
568 conn->ctx = NULL;
569
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100570 TRACE_DEVEL("freeing conn", QMUX_EV_QCC_END, conn);
571
Amaury Denoyelle2873a312021-12-08 14:42:55 +0100572 conn_stop_tracking(conn);
573 conn_full_close(conn);
574 if (conn->destroy_cb)
575 conn->destroy_cb(conn);
576 conn_free(conn);
577 }
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100578
579 TRACE_LEAVE(QMUX_EV_QCC_END);
Amaury Denoyelle2873a312021-12-08 14:42:55 +0100580}
581
Amaury Denoyellefe8f5552022-04-27 16:44:49 +0200582/* Transfer as much as possible data on <qcs> from <in> to <out>. <max_data> is
583 * the current flow-control limit on the connection which must not be exceeded.
Amaury Denoyelle75d14ad2022-03-22 15:10:29 +0100584 *
Amaury Denoyellefe8f5552022-04-27 16:44:49 +0200585 * Returns the total bytes of transferred data.
Amaury Denoyelle75d14ad2022-03-22 15:10:29 +0100586 */
Amaury Denoyelleda6ad202022-04-12 11:41:04 +0200587static int qcs_xfer_data(struct qcs *qcs, struct buffer *out,
Amaury Denoyellefe8f5552022-04-27 16:44:49 +0200588 struct buffer *in, uint64_t max_data)
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200589{
Amaury Denoyelle05ce55e2022-03-08 10:35:42 +0100590 struct qcc *qcc = qcs->qcc;
Amaury Denoyelleda6ad202022-04-12 11:41:04 +0200591 int left, to_xfer;
Amaury Denoyelle6ccfa3c2022-03-10 16:45:53 +0100592 int total = 0;
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200593
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100594 TRACE_ENTER(QMUX_EV_QCS_SEND, qcc->conn, qcs);
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100595
Amaury Denoyelle6ccfa3c2022-03-10 16:45:53 +0100596 qc_get_buf(qcs, out);
597
598 /*
599 * QCS out buffer diagram
600 * head left to_xfer
601 * -------------> ----------> ----->
Amaury Denoyellee0320b82022-03-11 19:12:23 +0100602 * --------------------------------------------------
Amaury Denoyelle6ccfa3c2022-03-10 16:45:53 +0100603 * |...............|xxxxxxxxxxx|<<<<<
Amaury Denoyellee0320b82022-03-11 19:12:23 +0100604 * --------------------------------------------------
Amaury Denoyelle6ccfa3c2022-03-10 16:45:53 +0100605 * ^ ack-off ^ sent-off ^ off
606 *
607 * STREAM frame
608 * ^ ^
609 * |xxxxxxxxxxxxxxxxx|
610 */
611
Amaury Denoyelle7272cd72022-03-29 15:15:54 +0200612 BUG_ON_HOT(qcs->tx.sent_offset < qcs->stream->ack_offset);
Amaury Denoyelle6ccfa3c2022-03-10 16:45:53 +0100613 BUG_ON_HOT(qcs->tx.offset < qcs->tx.sent_offset);
614
Amaury Denoyelle6ccfa3c2022-03-10 16:45:53 +0100615 left = qcs->tx.offset - qcs->tx.sent_offset;
Amaury Denoyellefe8f5552022-04-27 16:44:49 +0200616 to_xfer = QUIC_MIN(b_data(in), b_room(out));
Amaury Denoyelle6ea78192022-03-07 15:47:02 +0100617
618 BUG_ON_HOT(qcs->tx.offset > qcs->tx.msd);
619 /* do not exceed flow control limit */
620 if (qcs->tx.offset + to_xfer > qcs->tx.msd)
621 to_xfer = qcs->tx.msd - qcs->tx.offset;
622
Amaury Denoyelle05ce55e2022-03-08 10:35:42 +0100623 BUG_ON_HOT(max_data > qcc->rfctl.md);
624 /* do not overcome flow control limit on connection */
625 if (max_data + to_xfer > qcc->rfctl.md)
626 to_xfer = qcc->rfctl.md - max_data;
627
Amaury Denoyelle6ccfa3c2022-03-10 16:45:53 +0100628 if (!left && !to_xfer)
Frédéric Lécailled2ba0962021-09-20 17:50:03 +0200629 goto out;
630
Amaury Denoyellefe8f5552022-04-27 16:44:49 +0200631 total = b_force_xfer(out, in, to_xfer);
Amaury Denoyelleda6ad202022-04-12 11:41:04 +0200632
633 out:
634 {
635 struct qcs_xfer_data_trace_arg arg = {
636 .prep = b_data(out), .xfer = total,
637 };
638 TRACE_LEAVE(QMUX_EV_QCS_SEND|QMUX_EV_QCS_XFER_DATA,
639 qcc->conn, qcs, &arg);
640 }
641
642 return total;
Amaury Denoyelleda6ad202022-04-12 11:41:04 +0200643}
644
Amaury Denoyellefe8f5552022-04-27 16:44:49 +0200645/* Prepare a STREAM frame for <qcs> instance using <out> as payload. The frame
646 * is appended in <frm_list>. Set <fin> if this is supposed to be the last
647 * stream frame.
648 *
649 * Returns the length of the STREAM frame or a negative error code.
650 */
Amaury Denoyelleda6ad202022-04-12 11:41:04 +0200651static int qcs_build_stream_frm(struct qcs *qcs, struct buffer *out, char fin,
652 struct list *frm_list)
653{
654 struct qcc *qcc = qcs->qcc;
655 struct quic_frame *frm;
656 int head, total;
Amaury Denoyellea4569202022-04-15 17:29:25 +0200657 uint64_t base_off;
Amaury Denoyelleda6ad202022-04-12 11:41:04 +0200658
659 TRACE_ENTER(QMUX_EV_QCS_SEND, qcc->conn, qcs);
660
Amaury Denoyellea4569202022-04-15 17:29:25 +0200661 /* if ack_offset < buf_offset, it points to an older buffer. */
662 base_off = MAX(qcs->stream->buf_offset, qcs->stream->ack_offset);
663 BUG_ON(qcs->tx.sent_offset < base_off);
664
665 head = qcs->tx.sent_offset - base_off;
Amaury Denoyelleda6ad202022-04-12 11:41:04 +0200666 total = b_data(out) - head;
Amaury Denoyellea4569202022-04-15 17:29:25 +0200667 BUG_ON(total < 0);
668
Amaury Denoyelleda6ad202022-04-12 11:41:04 +0200669 if (!total) {
670 TRACE_LEAVE(QMUX_EV_QCS_SEND, qcc->conn, qcs);
671 return 0;
672 }
Amaury Denoyellea4569202022-04-15 17:29:25 +0200673 BUG_ON(qcs->tx.sent_offset >= qcs->tx.offset);
674 BUG_ON(qcs->tx.sent_offset + total > qcs->tx.offset);
Amaury Denoyelleda6ad202022-04-12 11:41:04 +0200675
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200676 frm = pool_zalloc(pool_head_quic_frame);
677 if (!frm)
678 goto err;
679
Frédéric Lécailleb9171912022-04-21 17:32:10 +0200680 LIST_INIT(&frm->reflist);
Amaury Denoyelle6ccfa3c2022-03-10 16:45:53 +0100681 frm->type = QUIC_FT_STREAM_8;
Amaury Denoyelle7272cd72022-03-29 15:15:54 +0200682 frm->stream.stream = qcs->stream;
Amaury Denoyelled8e680c2022-03-29 15:18:44 +0200683 frm->stream.id = qcs->id;
Amaury Denoyelle6ccfa3c2022-03-10 16:45:53 +0100684 frm->stream.buf = out;
685 frm->stream.data = (unsigned char *)b_peek(out, head);
686
Amaury Denoyellefecfa0d2021-12-07 16:50:14 +0100687 /* FIN is positioned only when the buffer has been totally emptied. */
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200688 if (fin)
689 frm->type |= QUIC_STREAM_FRAME_TYPE_FIN_BIT;
Amaury Denoyelle6ccfa3c2022-03-10 16:45:53 +0100690
691 if (qcs->tx.sent_offset) {
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200692 frm->type |= QUIC_STREAM_FRAME_TYPE_OFF_BIT;
Amaury Denoyelle6ccfa3c2022-03-10 16:45:53 +0100693 frm->stream.offset.key = qcs->tx.sent_offset;
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200694 }
Amaury Denoyelle6ccfa3c2022-03-10 16:45:53 +0100695
Amaury Denoyelleda6ad202022-04-12 11:41:04 +0200696 frm->type |= QUIC_STREAM_FRAME_TYPE_LEN_BIT;
697 frm->stream.len = total;
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200698
Amaury Denoyelle2c71fe52022-02-09 18:16:49 +0100699 LIST_APPEND(frm_list, &frm->list);
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100700
Frédéric Lécailled2ba0962021-09-20 17:50:03 +0200701 out:
Amaury Denoyellefdcec362022-03-25 09:28:10 +0100702 {
Amaury Denoyelleda6ad202022-04-12 11:41:04 +0200703 struct qcs_build_stream_trace_arg arg = {
704 .len = frm->stream.len, .fin = fin,
705 .offset = frm->stream.offset.key,
Amaury Denoyellefdcec362022-03-25 09:28:10 +0100706 };
Amaury Denoyelleda6ad202022-04-12 11:41:04 +0200707 TRACE_LEAVE(QMUX_EV_QCS_SEND|QMUX_EV_QCS_BUILD_STRM,
Amaury Denoyellefdcec362022-03-25 09:28:10 +0100708 qcc->conn, qcs, &arg);
709 }
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100710
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200711 return total;
712
713 err:
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100714 TRACE_DEVEL("leaving in error", QMUX_EV_QCS_SEND, qcc->conn, qcs);
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200715 return -1;
716}
717
Amaury Denoyelle54445d02022-03-10 16:44:14 +0100718/* This function must be called by the upper layer to inform about the sending
719 * of a STREAM frame for <qcs> instance. The frame is of <data> length and on
720 * <offset>.
721 */
722void qcc_streams_sent_done(struct qcs *qcs, uint64_t data, uint64_t offset)
723{
Amaury Denoyelle05ce55e2022-03-08 10:35:42 +0100724 struct qcc *qcc = qcs->qcc;
725 uint64_t diff;
Amaury Denoyelle6ccfa3c2022-03-10 16:45:53 +0100726
727 BUG_ON(offset > qcs->tx.sent_offset);
Amaury Denoyellea4569202022-04-15 17:29:25 +0200728 BUG_ON(offset >= qcs->tx.offset);
Amaury Denoyelle6ccfa3c2022-03-10 16:45:53 +0100729
Amaury Denoyelle54445d02022-03-10 16:44:14 +0100730 /* check if the STREAM frame has already been notified. It can happen
731 * for retransmission.
732 */
733 if (offset + data <= qcs->tx.sent_offset)
734 return;
Amaury Denoyelle6ccfa3c2022-03-10 16:45:53 +0100735
736 diff = offset + data - qcs->tx.sent_offset;
737
Amaury Denoyelle05ce55e2022-03-08 10:35:42 +0100738 /* increase offset sum on connection */
739 qcc->tx.sent_offsets += diff;
740 BUG_ON_HOT(qcc->tx.sent_offsets > qcc->rfctl.md);
741 if (qcc->tx.sent_offsets == qcc->rfctl.md)
742 qcc->flags |= QC_CF_BLK_MFCTL;
743
Amaury Denoyelle6ccfa3c2022-03-10 16:45:53 +0100744 /* increase offset on stream */
745 qcs->tx.sent_offset += diff;
Amaury Denoyelle6ea78192022-03-07 15:47:02 +0100746 BUG_ON_HOT(qcs->tx.sent_offset > qcs->tx.msd);
Amaury Denoyellea4569202022-04-15 17:29:25 +0200747 BUG_ON_HOT(qcs->tx.sent_offset > qcs->tx.offset);
Amaury Denoyelle6ea78192022-03-07 15:47:02 +0100748 if (qcs->tx.sent_offset == qcs->tx.msd)
749 qcs->flags |= QC_SF_BLK_SFCTL;
Amaury Denoyellea4569202022-04-15 17:29:25 +0200750
751 if (qcs->tx.offset == qcs->tx.sent_offset && b_full(&qcs->stream->buf->buf)) {
752 qc_stream_buf_release(qcs->stream);
Amaury Denoyelle1b2dba52022-04-15 17:32:04 +0200753 /* prepare qcs for immediate send retry if data to send */
754 if (b_data(&qcs->tx.buf))
755 LIST_APPEND(&qcc->send_retry_list, &qcs->el);
Amaury Denoyellea4569202022-04-15 17:29:25 +0200756 }
Amaury Denoyelle54445d02022-03-10 16:44:14 +0100757}
758
Amaury Denoyelle2c71fe52022-02-09 18:16:49 +0100759/* Wrapper for send on transport layer. Send a list of frames <frms> for the
760 * connection <qcc>.
761 *
762 * Returns 0 if all data sent with success else non-zero.
763 */
764static int qc_send_frames(struct qcc *qcc, struct list *frms)
765{
Amaury Denoyelledb5d1a12022-03-10 16:42:23 +0100766 /* TODO implement an opportunistic retry mechanism. This is needed
767 * because qc_send_app_pkts is not completed. It will only prepare data
768 * up to its Tx buffer. The frames left are not send even if the Tx
769 * buffer is emptied by the sendto call.
770 *
771 * To overcome this, we call repeatedly qc_send_app_pkts until we
772 * detect that the transport layer has send nothing. This could happen
773 * on congestion or sendto syscall error.
774 *
775 * When qc_send_app_pkts is improved to handle retry by itself, we can
776 * remove the looping from the MUX.
777 */
778 struct quic_frame *first_frm;
779 uint64_t first_offset = 0;
780 char first_stream_frame_type;
Amaury Denoyellee9c4cc12022-03-04 15:29:53 +0100781
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100782 TRACE_ENTER(QMUX_EV_QCC_SEND, qcc->conn);
783
784 if (LIST_ISEMPTY(frms)) {
785 TRACE_DEVEL("leaving with no frames to send", QMUX_EV_QCC_SEND, qcc->conn);
Amaury Denoyelle1b2dba52022-04-15 17:32:04 +0200786 return 1;
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100787 }
Frédéric Lécaille4e22f282022-03-18 18:38:19 +0100788
Amaury Denoyelle1b2dba52022-04-15 17:32:04 +0200789 LIST_INIT(&qcc->send_retry_list);
790
Amaury Denoyellee9c4cc12022-03-04 15:29:53 +0100791 retry_send:
Amaury Denoyelledb5d1a12022-03-10 16:42:23 +0100792 first_frm = LIST_ELEM(frms->n, struct quic_frame *, list);
793 if ((first_frm->type & QUIC_FT_STREAM_8) == QUIC_FT_STREAM_8) {
794 first_offset = first_frm->stream.offset.key;
795 first_stream_frame_type = 1;
796 }
797 else {
798 first_stream_frame_type = 0;
799 }
800
Amaury Denoyelle2c71fe52022-02-09 18:16:49 +0100801 if (!LIST_ISEMPTY(frms))
Frédéric Lécaille3e3a6212022-04-25 10:17:00 +0200802 qc_send_app_pkts(qcc->conn->handle.qc, 0, frms);
Amaury Denoyelle2c71fe52022-02-09 18:16:49 +0100803
Amaury Denoyelledb5d1a12022-03-10 16:42:23 +0100804 /* If there is frames left, check if the transport layer has send some
805 * data or is blocked.
Amaury Denoyelle2c71fe52022-02-09 18:16:49 +0100806 */
Amaury Denoyelledb5d1a12022-03-10 16:42:23 +0100807 if (!LIST_ISEMPTY(frms)) {
808 if (first_frm != LIST_ELEM(frms->n, struct quic_frame *, list))
809 goto retry_send;
810
811 /* If the first frame is STREAM, check if its offset has
812 * changed.
813 */
814 if (first_stream_frame_type &&
815 first_offset != LIST_ELEM(frms->n, struct quic_frame *, list)->stream.offset.key) {
816 goto retry_send;
817 }
Amaury Denoyellee9c4cc12022-03-04 15:29:53 +0100818 }
819
Amaury Denoyelledb5d1a12022-03-10 16:42:23 +0100820 /* If there is frames left at this stage, transport layer is blocked.
821 * Subscribe on it to retry later.
822 */
Amaury Denoyelle2c71fe52022-02-09 18:16:49 +0100823 if (!LIST_ISEMPTY(frms)) {
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100824 TRACE_DEVEL("leaving with remaining frames to send, subscribing", QMUX_EV_QCC_SEND, qcc->conn);
Amaury Denoyelle2c71fe52022-02-09 18:16:49 +0100825 qcc->conn->xprt->subscribe(qcc->conn, qcc->conn->xprt_ctx,
826 SUB_RETRY_SEND, &qcc->wait_event);
827 return 1;
828 }
829
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100830 TRACE_LEAVE(QMUX_EV_QCC_SEND);
831
Amaury Denoyelle2c71fe52022-02-09 18:16:49 +0100832 return 0;
833}
834
Amaury Denoyellec9337802022-04-04 16:36:34 +0200835/* Send a MAX_STREAM_BIDI frame to update the limit of bidirectional streams
836 * allowed to be opened by the peer. The caller should have first checked if
837 * this is required with qc_is_max_streams_needed.
838 *
839 * Returns 0 on success else non-zero.
840 */
841static int qc_send_max_streams(struct qcc *qcc)
842{
843 struct list frms = LIST_HEAD_INIT(frms);
844 struct quic_frame *frm;
845
846 frm = pool_zalloc(pool_head_quic_frame);
847 BUG_ON(!frm); /* TODO handle this properly */
848
Frédéric Lécailleb9171912022-04-21 17:32:10 +0200849 LIST_INIT(&frm->reflist);
Amaury Denoyellec9337802022-04-04 16:36:34 +0200850 frm->type = QUIC_FT_MAX_STREAMS_BIDI;
851 frm->max_streams_bidi.max_streams = qcc->lfctl.ms_bidi +
852 qcc->lfctl.cl_bidi_r;
853 TRACE_DEVEL("sending MAX_STREAMS frame", QMUX_EV_SEND_FRM, qcc->conn, NULL, frm);
854 LIST_APPEND(&frms, &frm->list);
855
856 if (qc_send_frames(qcc, &frms))
857 return 1;
858
859 /* save the new limit if the frame has been send. */
860 qcc->lfctl.ms_bidi += qcc->lfctl.cl_bidi_r;
861 qcc->lfctl.cl_bidi_r = 0;
862
863 return 0;
864}
865
Amaury Denoyelle1b2dba52022-04-15 17:32:04 +0200866/* Used internally by qc_send function. Proceed to send for <qcs>. This will
867 * transfer data from qcs buffer to its quic_stream counterpart. A STREAM frame
868 * is then generated and inserted in <frms> list. <qcc_max_data> is the current
869 * flow-control max-data at the connection level which must not be surpassed.
870 *
871 * Returns the total bytes transferred between qcs and quic_stream buffers. Can
872 * be null if out buffer cannot be allocated.
873 */
874static int _qc_send_qcs(struct qcs *qcs, struct list *frms,
875 uint64_t qcc_max_data)
876{
877 struct qcc *qcc = qcs->qcc;
878 struct buffer *buf = &qcs->tx.buf;
879 struct buffer *out = qc_stream_buf_get(qcs->stream);
880 int xfer = 0;
881
882 /* Allocate <out> buffer if necessary. */
883 if (!out) {
884 if (qcc->flags & QC_CF_CONN_FULL)
885 return 0;
886
887 out = qc_stream_buf_alloc(qcs->stream, qcs->tx.offset);
888 if (!out) {
889 qcc->flags |= QC_CF_CONN_FULL;
890 return 0;
891 }
892 }
893
894 /* Transfer data from <buf> to <out>. */
895 if (b_data(buf)) {
896 xfer = qcs_xfer_data(qcs, out, buf, qcc_max_data);
Amaury Denoyelle1b2dba52022-04-15 17:32:04 +0200897 if (xfer > 0) {
898 qcs_notify_send(qcs);
899 qcs->flags &= ~QC_SF_BLK_MROOM;
900 }
901
902 qcs->tx.offset += xfer;
903 }
904
905 /* out buffer cannot be emptied if qcs offsets differ. */
906 BUG_ON(!b_data(out) && qcs->tx.sent_offset != qcs->tx.offset);
907
908 /* Build a new STREAM frame with <out> buffer. */
909 if (qcs->tx.sent_offset != qcs->tx.offset) {
910 int ret;
911 char fin = !!(qcs->flags & QC_SF_FIN_STREAM);
912
913 /* FIN is set if all incoming data were transfered. */
914 fin = !!(fin && !b_data(buf));
915
916 ret = qcs_build_stream_frm(qcs, out, fin, frms);
Amaury Denoyelleb50f3112022-04-28 14:41:50 +0200917 if (ret < 0) { ABORT_NOW(); /* TODO handle this properly */ }
Amaury Denoyelle1b2dba52022-04-15 17:32:04 +0200918 }
919
920 return xfer;
921}
922
Amaury Denoyelle75d14ad2022-03-22 15:10:29 +0100923/* Proceed to sending. Loop through all available streams for the <qcc>
924 * instance and try to send as much as possible.
925 *
926 * Returns the total of bytes sent to the transport layer.
927 */
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100928static int qc_send(struct qcc *qcc)
929{
Amaury Denoyelle6ccfa3c2022-03-10 16:45:53 +0100930 struct list frms = LIST_HEAD_INIT(frms);
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200931 struct eb64_node *node;
Amaury Denoyelle1b2dba52022-04-15 17:32:04 +0200932 struct qcs *qcs, *qcs_tmp;
933 int total = 0, tmp_total = 0;
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200934
Amaury Denoyelle4f137572022-03-24 17:10:00 +0100935 TRACE_ENTER(QMUX_EV_QCC_SEND);
Frédéric Lécaille8526f142021-09-20 17:58:22 +0200936
Amaury Denoyelled97fc802022-04-06 16:13:09 +0200937 if (qcc->conn->flags & CO_FL_SOCK_WR_SH) {
938 qcc->conn->flags |= CO_FL_ERROR;
939 TRACE_DEVEL("leaving on error", QMUX_EV_QCC_SEND, qcc->conn);
940 return 0;
941 }
942
Amaury Denoyellec9337802022-04-04 16:36:34 +0200943 if (qc_is_max_streams_needed(qcc))
944 qc_send_max_streams(qcc);
945
Amaury Denoyelle05ce55e2022-03-08 10:35:42 +0100946 if (qcc->flags & QC_CF_BLK_MFCTL)
947 return 0;
948
Amaury Denoyelle2c71fe52022-02-09 18:16:49 +0100949 /* loop through all streams, construct STREAM frames if data available.
950 * TODO optimize the loop to favor streams which are not too heavy.
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200951 */
952 node = eb64_first(&qcc->streams_by_id);
953 while (node) {
Amaury Denoyelle1b2dba52022-04-15 17:32:04 +0200954 int ret;
955 qcs = eb64_entry(node, struct qcs, by_id);
Amaury Denoyelle2c71fe52022-02-09 18:16:49 +0100956
Amaury Denoyellee2ec9422022-03-10 16:46:18 +0100957 /* TODO
958 * for the moment, unidirectional streams have their own
959 * mechanism for sending. This should be unified in the future,
960 * in this case the next check will be removed.
961 */
Amaury Denoyelled8e680c2022-03-29 15:18:44 +0200962 if (quic_stream_is_uni(qcs->id)) {
Amaury Denoyellee2ec9422022-03-10 16:46:18 +0100963 node = eb64_next(node);
964 continue;
965 }
966
Amaury Denoyelle6ea78192022-03-07 15:47:02 +0100967 if (qcs->flags & QC_SF_BLK_SFCTL) {
968 node = eb64_next(node);
969 continue;
970 }
971
Amaury Denoyelle1b2dba52022-04-15 17:32:04 +0200972 if (!b_data(&qcs->tx.buf) && !qc_stream_buf_get(qcs->stream)) {
Amaury Denoyelled2f80a22022-04-15 17:30:49 +0200973 node = eb64_next(node);
974 continue;
975 }
Amaury Denoyellea4569202022-04-15 17:29:25 +0200976
Amaury Denoyelle1b2dba52022-04-15 17:32:04 +0200977 ret = _qc_send_qcs(qcs, &frms, qcc->tx.sent_offsets + total);
978 total += ret;
979 node = eb64_next(node);
980 }
Amaury Denoyelleda6ad202022-04-12 11:41:04 +0200981
Amaury Denoyelle1b2dba52022-04-15 17:32:04 +0200982 if (qc_send_frames(qcc, &frms)) {
983 /* data rejected by transport layer, do not retry. */
984 goto out;
985 }
Amaury Denoyelleda6ad202022-04-12 11:41:04 +0200986
Amaury Denoyelle1b2dba52022-04-15 17:32:04 +0200987 retry:
988 tmp_total = 0;
989 list_for_each_entry_safe(qcs, qcs_tmp, &qcc->send_retry_list, el) {
990 int ret;
991 BUG_ON(!b_data(&qcs->tx.buf));
992 BUG_ON(qc_stream_buf_get(qcs->stream));
Amaury Denoyelleda6ad202022-04-12 11:41:04 +0200993
Amaury Denoyelle1b2dba52022-04-15 17:32:04 +0200994 ret = _qc_send_qcs(qcs, &frms, qcc->tx.sent_offsets + tmp_total);
995 tmp_total += ret;
996 LIST_DELETE(&qcs->el);
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200997 }
Frédéric Lécaille8526f142021-09-20 17:58:22 +0200998
Amaury Denoyelle1b2dba52022-04-15 17:32:04 +0200999 total += tmp_total;
1000 if (!qc_send_frames(qcc, &frms) && !LIST_ISEMPTY(&qcc->send_retry_list))
1001 goto retry;
Amaury Denoyellee257d9e2021-12-03 14:39:29 +01001002
Amaury Denoyelle1b2dba52022-04-15 17:32:04 +02001003 out:
Amaury Denoyelle4f137572022-03-24 17:10:00 +01001004 TRACE_LEAVE(QMUX_EV_QCC_SEND);
1005
Amaury Denoyelle75d14ad2022-03-22 15:10:29 +01001006 return total;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001007}
1008
Amaury Denoyelle6a4aebf2022-02-01 10:16:05 +01001009/* Release all streams that are already marked as detached. This is only done
1010 * if their TX buffers are empty or if a CONNECTION_CLOSE has been received.
1011 *
1012 * Return the number of released stream.
1013 */
Amaury Denoyelle2873a312021-12-08 14:42:55 +01001014static int qc_release_detached_streams(struct qcc *qcc)
1015{
1016 struct eb64_node *node;
1017 int release = 0;
1018
1019 node = eb64_first(&qcc->streams_by_id);
1020 while (node) {
Amaury Denoyellee4301da2022-04-19 17:59:50 +02001021 struct qcs *qcs = eb64_entry(node, struct qcs, by_id);
Amaury Denoyelle2873a312021-12-08 14:42:55 +01001022 node = eb64_next(node);
1023
1024 if (qcs->flags & QC_SF_DETACH) {
Amaury Denoyelle7272cd72022-03-29 15:15:54 +02001025 if (!b_data(&qcs->tx.buf) &&
1026 qcs->tx.offset == qcs->tx.sent_offset) {
Amaury Denoyelle2873a312021-12-08 14:42:55 +01001027 qcs_destroy(qcs);
1028 release = 1;
1029 }
1030 else {
1031 qcc->conn->xprt->subscribe(qcc->conn, qcc->conn->xprt_ctx,
1032 SUB_RETRY_SEND, &qcc->wait_event);
1033 }
1034 }
1035 }
1036
1037 return release;
1038}
1039
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001040static struct task *qc_io_cb(struct task *t, void *ctx, unsigned int status)
1041{
Amaury Denoyelle769e9ff2021-10-05 11:43:50 +02001042 struct qcc *qcc = ctx;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001043
Amaury Denoyelle4f137572022-03-24 17:10:00 +01001044 TRACE_ENTER(QMUX_EV_QCC_WAKE);
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001045
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001046 qc_send(qcc);
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001047
Amaury Denoyelle2873a312021-12-08 14:42:55 +01001048 if (qc_release_detached_streams(qcc)) {
Amaury Denoyelle06890aa2022-04-04 16:15:06 +02001049 if (qcc_is_dead(qcc)) {
1050 qc_release(qcc);
1051 }
Amaury Denoyellea3daaec2022-04-21 16:29:27 +02001052 else if (qcc->task) {
Amaury Denoyelle06890aa2022-04-04 16:15:06 +02001053 if (qcc_may_expire(qcc))
1054 qcc->task->expire = tick_add(now_ms, qcc->timeout);
1055 else
1056 qcc->task->expire = TICK_ETERNITY;
Amaury Denoyelle1136e922022-02-01 10:33:09 +01001057 task_queue(qcc->task);
Amaury Denoyelle2873a312021-12-08 14:42:55 +01001058 }
1059 }
1060
Amaury Denoyelle4f137572022-03-24 17:10:00 +01001061 TRACE_LEAVE(QMUX_EV_QCC_WAKE);
1062
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001063 return NULL;
1064}
1065
Amaury Denoyelleaebe26f2022-01-13 16:28:06 +01001066static struct task *qc_timeout_task(struct task *t, void *ctx, unsigned int state)
1067{
1068 struct qcc *qcc = ctx;
1069 int expired = tick_is_expired(t->expire, now_ms);
1070
Amaury Denoyelle4f137572022-03-24 17:10:00 +01001071 TRACE_ENTER(QMUX_EV_QCC_WAKE, qcc ? qcc->conn : NULL);
Amaury Denoyelleaebe26f2022-01-13 16:28:06 +01001072
1073 if (qcc) {
1074 if (!expired) {
Amaury Denoyelle4f137572022-03-24 17:10:00 +01001075 TRACE_DEVEL("leaving (not expired)", QMUX_EV_QCC_WAKE, qcc->conn);
Amaury Denoyelleaebe26f2022-01-13 16:28:06 +01001076 return t;
1077 }
1078
1079 if (!qcc_may_expire(qcc)) {
Amaury Denoyelle4f137572022-03-24 17:10:00 +01001080 TRACE_DEVEL("leaving (cannot expired)", QMUX_EV_QCC_WAKE, qcc->conn);
Amaury Denoyelleaebe26f2022-01-13 16:28:06 +01001081 t->expire = TICK_ETERNITY;
1082 return t;
1083 }
1084 }
1085
Amaury Denoyelleaebe26f2022-01-13 16:28:06 +01001086 task_destroy(t);
Amaury Denoyelleea3e0352022-02-21 10:05:16 +01001087
Amaury Denoyelle4f137572022-03-24 17:10:00 +01001088 if (!qcc) {
1089 TRACE_DEVEL("leaving (not more qcc)", QMUX_EV_QCC_WAKE);
Amaury Denoyelleea3e0352022-02-21 10:05:16 +01001090 return NULL;
Amaury Denoyelle4f137572022-03-24 17:10:00 +01001091 }
Amaury Denoyelleea3e0352022-02-21 10:05:16 +01001092
Amaury Denoyelleaebe26f2022-01-13 16:28:06 +01001093 qcc->task = NULL;
1094
1095 if (qcc_is_dead(qcc))
1096 qc_release(qcc);
1097
Amaury Denoyelle4f137572022-03-24 17:10:00 +01001098 TRACE_LEAVE(QMUX_EV_QCC_WAKE);
1099
Amaury Denoyelleaebe26f2022-01-13 16:28:06 +01001100 return NULL;
1101}
1102
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001103static int qc_init(struct connection *conn, struct proxy *prx,
1104 struct session *sess, struct buffer *input)
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001105{
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001106 struct qcc *qcc;
Amaury Denoyelle6ea78192022-03-07 15:47:02 +01001107 struct quic_transport_params *lparams, *rparams;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001108
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001109 qcc = pool_alloc(pool_head_qcc);
1110 if (!qcc)
1111 goto fail_no_qcc;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001112
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001113 qcc->conn = conn;
1114 conn->ctx = qcc;
Amaury Denoyelle06890aa2022-04-04 16:15:06 +02001115 qcc->nb_cs = 0;
Amaury Denoyellece1f30d2022-02-01 15:14:24 +01001116 qcc->flags = 0;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001117
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001118 qcc->app_ops = NULL;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001119
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001120 qcc->streams_by_id = EB_ROOT_UNIQUE;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001121
Amaury Denoyellef3b0ba72021-12-08 15:12:01 +01001122 /* Server parameters, params used for RX flow control. */
Willy Tarreau784b8682022-04-11 14:18:10 +02001123 lparams = &conn->handle.qc->rx.params;
Amaury Denoyellef3b0ba72021-12-08 15:12:01 +01001124
Amaury Denoyelle749cb642022-02-09 10:25:29 +01001125 qcc->rx.max_data = lparams->initial_max_data;
Amaury Denoyelle05ce55e2022-03-08 10:35:42 +01001126 qcc->tx.sent_offsets = 0;
Amaury Denoyellef3b0ba72021-12-08 15:12:01 +01001127
1128 /* Client initiated streams must respect the server flow control. */
Amaury Denoyelle749cb642022-02-09 10:25:29 +01001129 qcc->strms[QCS_CLT_BIDI].max_streams = lparams->initial_max_streams_bidi;
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001130 qcc->strms[QCS_CLT_BIDI].nb_streams = 0;
1131 qcc->strms[QCS_CLT_BIDI].largest_id = -1;
Amaury Denoyellef3b0ba72021-12-08 15:12:01 +01001132 qcc->strms[QCS_CLT_BIDI].rx.max_data = 0;
Amaury Denoyelle749cb642022-02-09 10:25:29 +01001133 qcc->strms[QCS_CLT_BIDI].tx.max_data = lparams->initial_max_stream_data_bidi_remote;
Amaury Denoyellef3b0ba72021-12-08 15:12:01 +01001134
Amaury Denoyelle749cb642022-02-09 10:25:29 +01001135 qcc->strms[QCS_CLT_UNI].max_streams = lparams->initial_max_streams_uni;
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001136 qcc->strms[QCS_CLT_UNI].nb_streams = 0;
1137 qcc->strms[QCS_CLT_UNI].largest_id = -1;
Amaury Denoyellef3b0ba72021-12-08 15:12:01 +01001138 qcc->strms[QCS_CLT_UNI].rx.max_data = 0;
Amaury Denoyelle749cb642022-02-09 10:25:29 +01001139 qcc->strms[QCS_CLT_UNI].tx.max_data = lparams->initial_max_stream_data_uni;
Amaury Denoyellef3b0ba72021-12-08 15:12:01 +01001140
1141 /* Server initiated streams must respect the server flow control. */
1142 qcc->strms[QCS_SRV_BIDI].max_streams = 0;
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001143 qcc->strms[QCS_SRV_BIDI].nb_streams = 0;
1144 qcc->strms[QCS_SRV_BIDI].largest_id = -1;
Amaury Denoyelle749cb642022-02-09 10:25:29 +01001145 qcc->strms[QCS_SRV_BIDI].rx.max_data = lparams->initial_max_stream_data_bidi_local;
Amaury Denoyellef3b0ba72021-12-08 15:12:01 +01001146 qcc->strms[QCS_SRV_BIDI].tx.max_data = 0;
1147
1148 qcc->strms[QCS_SRV_UNI].max_streams = 0;
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001149 qcc->strms[QCS_SRV_UNI].nb_streams = 0;
1150 qcc->strms[QCS_SRV_UNI].largest_id = -1;
Amaury Denoyelle749cb642022-02-09 10:25:29 +01001151 qcc->strms[QCS_SRV_UNI].rx.max_data = lparams->initial_max_stream_data_uni;
Amaury Denoyellef3b0ba72021-12-08 15:12:01 +01001152 qcc->strms[QCS_SRV_UNI].tx.max_data = 0;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001153
Amaury Denoyelle78396e52022-03-21 17:13:32 +01001154 qcc->lfctl.ms_bidi = qcc->lfctl.ms_bidi_init = lparams->initial_max_streams_bidi;
Amaury Denoyelle44d09122022-04-26 11:21:10 +02001155 qcc->lfctl.msd_bidi_l = lparams->initial_max_stream_data_bidi_local;
1156 qcc->lfctl.msd_bidi_r = lparams->initial_max_stream_data_bidi_remote;
Amaury Denoyelle78396e52022-03-21 17:13:32 +01001157 qcc->lfctl.cl_bidi_r = 0;
Amaury Denoyellec055e302022-02-07 16:09:06 +01001158
Willy Tarreau784b8682022-04-11 14:18:10 +02001159 rparams = &conn->handle.qc->tx.params;
Amaury Denoyelle05ce55e2022-03-08 10:35:42 +01001160 qcc->rfctl.md = rparams->initial_max_data;
Amaury Denoyelle6ea78192022-03-07 15:47:02 +01001161 qcc->rfctl.msd_bidi_l = rparams->initial_max_stream_data_bidi_local;
1162 qcc->rfctl.msd_bidi_r = rparams->initial_max_stream_data_bidi_remote;
1163
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001164 qcc->wait_event.tasklet = tasklet_new();
1165 if (!qcc->wait_event.tasklet)
1166 goto fail_no_tasklet;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001167
Amaury Denoyelle1b2dba52022-04-15 17:32:04 +02001168 LIST_INIT(&qcc->send_retry_list);
1169
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001170 qcc->subs = NULL;
1171 qcc->wait_event.tasklet->process = qc_io_cb;
1172 qcc->wait_event.tasklet->context = qcc;
Frédéric Lécaillef27b66f2022-03-18 22:49:22 +01001173 qcc->wait_event.events = 0;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001174
Amaury Denoyelleaebe26f2022-01-13 16:28:06 +01001175 /* haproxy timeouts */
Amaury Denoyellea3daaec2022-04-21 16:29:27 +02001176 qcc->task = NULL;
Amaury Denoyelleaebe26f2022-01-13 16:28:06 +01001177 qcc->timeout = prx->timeout.client;
Amaury Denoyellea3daaec2022-04-21 16:29:27 +02001178 if (tick_isset(qcc->timeout)) {
1179 qcc->task = task_new_here();
1180 if (!qcc->task)
1181 goto fail_no_timeout_task;
1182 qcc->task->process = qc_timeout_task;
1183 qcc->task->context = qcc;
1184 qcc->task->expire = tick_add(now_ms, qcc->timeout);
1185 }
Amaury Denoyelleaebe26f2022-01-13 16:28:06 +01001186
Amaury Denoyelle0e0969d2022-01-31 15:41:14 +01001187 if (!conn_is_back(conn)) {
1188 if (!LIST_INLIST(&conn->stopping_list)) {
1189 LIST_APPEND(&mux_stopping_data[tid].list,
1190 &conn->stopping_list);
1191 }
1192 }
1193
Willy Tarreau784b8682022-04-11 14:18:10 +02001194 HA_ATOMIC_STORE(&conn->handle.qc->qcc, qcc);
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001195 /* init read cycle */
1196 tasklet_wakeup(qcc->wait_event.tasklet);
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001197
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001198 return 0;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001199
Amaury Denoyelleaebe26f2022-01-13 16:28:06 +01001200 fail_no_timeout_task:
1201 tasklet_free(qcc->wait_event.tasklet);
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001202 fail_no_tasklet:
1203 pool_free(pool_head_qcc, qcc);
1204 fail_no_qcc:
1205 return -1;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001206}
1207
Amaury Denoyelle2461bd52022-04-13 16:54:52 +02001208static void qc_destroy(void *ctx)
1209{
1210 struct qcc *qcc = ctx;
1211
1212 TRACE_ENTER(QMUX_EV_QCC_END, qcc->conn);
1213 qc_release(qcc);
1214 TRACE_LEAVE(QMUX_EV_QCC_END);
1215}
1216
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001217static void qc_detach(struct conn_stream *cs)
1218{
Christopher Fauletdb90f2a2022-03-22 16:06:25 +01001219 struct qcs *qcs = __cs_mux(cs);
Amaury Denoyelle916f0ac2021-12-06 16:03:47 +01001220 struct qcc *qcc = qcs->qcc;
1221
Amaury Denoyelle4f137572022-03-24 17:10:00 +01001222 TRACE_ENTER(QMUX_EV_STRM_END, qcc->conn, qcs);
Amaury Denoyelle916f0ac2021-12-06 16:03:47 +01001223
Amaury Denoyelle80388212022-04-08 12:00:12 +02001224 qcs->cs = NULL;
Amaury Denoyelle06890aa2022-04-04 16:15:06 +02001225 --qcc->nb_cs;
1226
Amaury Denoyellefe035ec2022-04-06 15:46:30 +02001227 if ((b_data(&qcs->tx.buf) || qcs->tx.offset > qcs->tx.sent_offset) &&
1228 !(qcc->conn->flags & CO_FL_ERROR)) {
Amaury Denoyelle4f137572022-03-24 17:10:00 +01001229 TRACE_DEVEL("leaving with remaining data, detaching qcs", QMUX_EV_STRM_END, qcc->conn, qcs);
Amaury Denoyelle2873a312021-12-08 14:42:55 +01001230 qcs->flags |= QC_SF_DETACH;
1231 return;
1232 }
1233
Amaury Denoyelle916f0ac2021-12-06 16:03:47 +01001234 qcs_destroy(qcs);
Amaury Denoyelle1136e922022-02-01 10:33:09 +01001235
Amaury Denoyelle06890aa2022-04-04 16:15:06 +02001236 if (qcc_is_dead(qcc)) {
1237 qc_release(qcc);
1238 }
Amaury Denoyellea3daaec2022-04-21 16:29:27 +02001239 else if (qcc->task) {
Amaury Denoyelle06890aa2022-04-04 16:15:06 +02001240 if (qcc_may_expire(qcc))
1241 qcc->task->expire = tick_add(now_ms, qcc->timeout);
1242 else
1243 qcc->task->expire = TICK_ETERNITY;
Amaury Denoyelle1136e922022-02-01 10:33:09 +01001244 task_queue(qcc->task);
Amaury Denoyelle916f0ac2021-12-06 16:03:47 +01001245 }
Amaury Denoyelle4f137572022-03-24 17:10:00 +01001246
1247 TRACE_LEAVE(QMUX_EV_STRM_END);
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001248}
1249
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001250/* Called from the upper layer, to receive data */
1251static size_t qc_rcv_buf(struct conn_stream *cs, struct buffer *buf,
1252 size_t count, int flags)
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001253{
Christopher Fauletdb90f2a2022-03-22 16:06:25 +01001254 struct qcs *qcs = __cs_mux(cs);
Amaury Denoyelle9a327a72022-02-14 17:11:09 +01001255 struct htx *qcs_htx = NULL;
1256 struct htx *cs_htx = NULL;
1257 size_t ret = 0;
Amaury Denoyelleeb53e5b2022-02-14 17:11:32 +01001258 char fin = 0;
Amaury Denoyelle9a327a72022-02-14 17:11:09 +01001259
Amaury Denoyelle4f137572022-03-24 17:10:00 +01001260 TRACE_ENTER(QMUX_EV_STRM_RECV, qcs->qcc->conn, qcs);
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001261
Amaury Denoyelle9a327a72022-02-14 17:11:09 +01001262 qcs_htx = htx_from_buf(&qcs->rx.app_buf);
1263 if (htx_is_empty(qcs_htx)) {
1264 /* Set buffer data to 0 as HTX is empty. */
1265 htx_to_buf(qcs_htx, &qcs->rx.app_buf);
1266 goto end;
1267 }
1268
1269 ret = qcs_htx->data;
1270
1271 cs_htx = htx_from_buf(buf);
1272 if (htx_is_empty(cs_htx) && htx_used_space(qcs_htx) <= count) {
1273 htx_to_buf(cs_htx, buf);
1274 htx_to_buf(qcs_htx, &qcs->rx.app_buf);
1275 b_xfer(buf, &qcs->rx.app_buf, b_data(&qcs->rx.app_buf));
1276 goto end;
1277 }
1278
1279 htx_xfer_blks(cs_htx, qcs_htx, count, HTX_BLK_UNUSED);
1280 BUG_ON(qcs_htx->flags & HTX_FL_PARSING_ERROR);
1281
1282 /* Copy EOM from src to dst buffer if all data copied. */
Amaury Denoyelleeb53e5b2022-02-14 17:11:32 +01001283 if (htx_is_empty(qcs_htx) && (qcs_htx->flags & HTX_FL_EOM)) {
1284 cs_htx->flags |= HTX_FL_EOM;
1285 fin = 1;
1286 }
Amaury Denoyelle9a327a72022-02-14 17:11:09 +01001287
1288 cs_htx->extra = qcs_htx->extra ? (qcs_htx->data + qcs_htx->extra) : 0;
1289 htx_to_buf(cs_htx, buf);
1290 htx_to_buf(qcs_htx, &qcs->rx.app_buf);
1291 ret -= qcs_htx->data;
1292
1293 end:
1294 if (b_data(&qcs->rx.app_buf)) {
Christopher Fauletb041b232022-03-24 10:27:02 +01001295 cs->endp->flags |= (CS_EP_RCV_MORE | CS_EP_WANT_ROOM);
Amaury Denoyelle9a327a72022-02-14 17:11:09 +01001296 }
1297 else {
Christopher Fauletb041b232022-03-24 10:27:02 +01001298 cs->endp->flags &= ~(CS_EP_RCV_MORE | CS_EP_WANT_ROOM);
1299 if (cs->endp->flags & CS_EP_ERR_PENDING)
1300 cs->endp->flags |= CS_EP_ERROR;
Amaury Denoyelle9a327a72022-02-14 17:11:09 +01001301
Amaury Denoyelleeb53e5b2022-02-14 17:11:32 +01001302 if (fin)
Amaury Denoyellef6df6b42022-04-22 16:52:14 +02001303 cs->endp->flags |= CS_EP_EOI;
Amaury Denoyelle9a327a72022-02-14 17:11:09 +01001304
1305 if (b_size(&qcs->rx.app_buf)) {
1306 b_free(&qcs->rx.app_buf);
1307 offer_buffers(NULL, 1);
1308 }
1309 }
1310
1311 if (ret)
1312 tasklet_wakeup(qcs->qcc->wait_event.tasklet);
1313
Amaury Denoyelle4f137572022-03-24 17:10:00 +01001314 TRACE_LEAVE(QMUX_EV_STRM_RECV, qcs->qcc->conn, qcs);
1315
Amaury Denoyelle9a327a72022-02-14 17:11:09 +01001316 return ret;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001317}
1318
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001319static size_t qc_snd_buf(struct conn_stream *cs, struct buffer *buf,
1320 size_t count, int flags)
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001321{
Christopher Fauletdb90f2a2022-03-22 16:06:25 +01001322 struct qcs *qcs = __cs_mux(cs);
Amaury Denoyelle4f137572022-03-24 17:10:00 +01001323 size_t ret;
1324
1325 TRACE_ENTER(QMUX_EV_STRM_SEND, qcs->qcc->conn, qcs);
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001326
Amaury Denoyelle4f137572022-03-24 17:10:00 +01001327 ret = qcs->qcc->app_ops->snd_buf(cs, buf, count, flags);
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001328
Amaury Denoyelle4f137572022-03-24 17:10:00 +01001329 TRACE_LEAVE(QMUX_EV_STRM_SEND, qcs->qcc->conn, qcs);
1330
1331 return ret;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001332}
1333
1334/* Called from the upper layer, to subscribe <es> to events <event_type>. The
1335 * event subscriber <es> is not allowed to change from a previous call as long
1336 * as at least one event is still subscribed. The <event_type> must only be a
1337 * combination of SUB_RETRY_RECV and SUB_RETRY_SEND. It always returns 0.
1338 */
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001339static int qc_subscribe(struct conn_stream *cs, int event_type,
1340 struct wait_event *es)
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001341{
Christopher Fauletdb90f2a2022-03-22 16:06:25 +01001342 return qcs_subscribe(__cs_mux(cs), event_type, es);
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001343}
1344
1345/* Called from the upper layer, to unsubscribe <es> from events <event_type>.
1346 * The <es> pointer is not allowed to differ from the one passed to the
1347 * subscribe() call. It always returns zero.
1348 */
1349static int qc_unsubscribe(struct conn_stream *cs, int event_type, struct wait_event *es)
1350{
Christopher Fauletdb90f2a2022-03-22 16:06:25 +01001351 struct qcs *qcs = __cs_mux(cs);
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001352
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001353 BUG_ON(event_type & ~(SUB_RETRY_SEND|SUB_RETRY_RECV));
1354 BUG_ON(qcs->subs && qcs->subs != es);
1355
1356 es->events &= ~event_type;
1357 if (!es->events)
1358 qcs->subs = NULL;
1359
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001360 return 0;
1361}
1362
Amaury Denoyellefe035ec2022-04-06 15:46:30 +02001363/* Loop through all qcs from <qcc>. If CO_FL_ERROR is set on the connection,
Christopher Fauletb041b232022-03-24 10:27:02 +01001364 * report CS_EP_ERR_PENDING|CS_EP_ERROR on the attached conn-streams and wake
Amaury Denoyellefe035ec2022-04-06 15:46:30 +02001365 * them.
1366 */
1367static int qc_wake_some_streams(struct qcc *qcc)
1368{
Amaury Denoyellefe035ec2022-04-06 15:46:30 +02001369 struct qcs *qcs;
1370 struct eb64_node *node;
1371
1372 for (node = eb64_first(&qcc->streams_by_id); node;
1373 node = eb64_next(node)) {
Amaury Denoyellee4301da2022-04-19 17:59:50 +02001374 qcs = eb64_entry(node, struct qcs, by_id);
Amaury Denoyellefe035ec2022-04-06 15:46:30 +02001375
1376 if (!qcs->cs)
1377 continue;
1378
1379 if (qcc->conn->flags & CO_FL_ERROR) {
Christopher Fauletb041b232022-03-24 10:27:02 +01001380 qcs->endp->flags |= CS_EP_ERR_PENDING;
1381 if (qcs->endp->flags & CS_EP_EOS)
1382 qcs->endp->flags |= CS_EP_ERROR;
Amaury Denoyellefe035ec2022-04-06 15:46:30 +02001383
1384 if (qcs->subs) {
1385 qcs_notify_recv(qcs);
1386 qcs_notify_send(qcs);
1387 }
1388 else if (qcs->cs->data_cb->wake) {
1389 qcs->cs->data_cb->wake(qcs->cs);
1390 }
1391 }
1392 }
1393
1394 return 0;
1395}
1396
Amaury Denoyelle0e0969d2022-01-31 15:41:14 +01001397static int qc_wake(struct connection *conn)
1398{
1399 struct qcc *qcc = conn->ctx;
Willy Tarreau784b8682022-04-11 14:18:10 +02001400 struct proxy *prx = conn->handle.qc->li->bind_conf->frontend;
Amaury Denoyelled97fc802022-04-06 16:13:09 +02001401
1402 TRACE_ENTER(QMUX_EV_QCC_WAKE, conn);
Amaury Denoyelle0e0969d2022-01-31 15:41:14 +01001403
1404 /* Check if a soft-stop is in progress.
1405 * Release idling front connection if this is the case.
Amaury Denoyelled97fc802022-04-06 16:13:09 +02001406 *
1407 * TODO this is revelant for frontend connections only.
Amaury Denoyelle0e0969d2022-01-31 15:41:14 +01001408 */
Amaury Denoyelled97fc802022-04-06 16:13:09 +02001409 if (unlikely(prx->flags & (PR_FL_DISABLED|PR_FL_STOPPED)))
1410 goto release;
1411
Willy Tarreau784b8682022-04-11 14:18:10 +02001412 if (conn->handle.qc->flags & QUIC_FL_CONN_NOTIFY_CLOSE)
Amaury Denoyelleb515b0a2022-04-06 10:28:43 +02001413 qcc->conn->flags |= (CO_FL_SOCK_RD_SH|CO_FL_SOCK_WR_SH);
1414
Amaury Denoyelled97fc802022-04-06 16:13:09 +02001415 qc_send(qcc);
1416
Amaury Denoyellefe035ec2022-04-06 15:46:30 +02001417 qc_wake_some_streams(qcc);
1418
Amaury Denoyelled97fc802022-04-06 16:13:09 +02001419 if (qcc_is_dead(qcc))
1420 goto release;
1421
1422 TRACE_LEAVE(QMUX_EV_QCC_WAKE, conn);
1423
1424 return 0;
Amaury Denoyelle0e0969d2022-01-31 15:41:14 +01001425
Amaury Denoyelled97fc802022-04-06 16:13:09 +02001426 release:
1427 qc_release(qcc);
1428 TRACE_DEVEL("leaving after releasing the connection", QMUX_EV_QCC_WAKE);
Amaury Denoyelle0e0969d2022-01-31 15:41:14 +01001429 return 1;
1430}
1431
Amaury Denoyelledd4fbfb2022-03-24 16:09:16 +01001432
Amaury Denoyellefa29f332022-03-25 09:09:40 +01001433static void qmux_trace_frm(const struct quic_frame *frm)
1434{
1435 switch (frm->type) {
1436 case QUIC_FT_MAX_STREAMS_BIDI:
1437 chunk_appendf(&trace_buf, " max_streams=%lu",
1438 frm->max_streams_bidi.max_streams);
1439 break;
1440
1441 case QUIC_FT_MAX_STREAMS_UNI:
1442 chunk_appendf(&trace_buf, " max_streams=%lu",
1443 frm->max_streams_uni.max_streams);
1444 break;
1445
1446 default:
1447 break;
1448 }
1449}
1450
Amaury Denoyelledd4fbfb2022-03-24 16:09:16 +01001451/* quic-mux trace handler */
1452static void qmux_trace(enum trace_level level, uint64_t mask,
1453 const struct trace_source *src,
1454 const struct ist where, const struct ist func,
1455 const void *a1, const void *a2, const void *a3, const void *a4)
1456{
1457 const struct connection *conn = a1;
1458 const struct qcc *qcc = conn ? conn->ctx : NULL;
1459 const struct qcs *qcs = a2;
1460
1461 if (!qcc)
1462 return;
1463
1464 if (src->verbosity > QMUX_VERB_CLEAN) {
1465 chunk_appendf(&trace_buf, " : qcc=%p(F)", qcc);
1466
1467 if (qcs)
Amaury Denoyelled8e680c2022-03-29 15:18:44 +02001468 chunk_appendf(&trace_buf, " qcs=%p(%lu)", qcs, qcs->id);
Amaury Denoyelle4f137572022-03-24 17:10:00 +01001469
1470 if (mask & QMUX_EV_QCC_NQCS) {
1471 const uint64_t *id = a3;
1472 chunk_appendf(&trace_buf, " id=%lu", *id);
1473 }
Amaury Denoyellefa29f332022-03-25 09:09:40 +01001474
1475 if (mask & QMUX_EV_SEND_FRM)
1476 qmux_trace_frm(a3);
Amaury Denoyellefdcec362022-03-25 09:28:10 +01001477
Amaury Denoyelleda6ad202022-04-12 11:41:04 +02001478 if (mask & QMUX_EV_QCS_XFER_DATA) {
1479 const struct qcs_xfer_data_trace_arg *arg = a3;
1480 chunk_appendf(&trace_buf, " prep=%lu xfer=%d",
1481 arg->prep, arg->xfer);
1482 }
1483
1484 if (mask & QMUX_EV_QCS_BUILD_STRM) {
1485 const struct qcs_build_stream_trace_arg *arg = a3;
1486 chunk_appendf(&trace_buf, " len=%lu fin=%d offset=%lu",
1487 arg->len, arg->fin, arg->offset);
Amaury Denoyellefdcec362022-03-25 09:28:10 +01001488 }
Amaury Denoyelledd4fbfb2022-03-24 16:09:16 +01001489 }
1490}
1491
Amaury Denoyelle251eadf2022-03-24 17:14:52 +01001492/* Function to automatically activate QUIC MUX traces on stdout.
1493 * Activated via the compilation flag -DENABLE_QUIC_STDOUT_TRACES.
1494 * Main use for now is in the docker image for QUIC interop testing.
1495 */
1496static void qmux_init_stdout_traces(void)
1497{
1498#ifdef ENABLE_QUIC_STDOUT_TRACES
1499 trace_qmux.sink = sink_find("stdout");
1500 trace_qmux.level = TRACE_LEVEL_DEVELOPER;
1501 trace_qmux.state = TRACE_STATE_RUNNING;
1502 trace_qmux.verbosity = QMUX_VERB_MINIMAL;
1503#endif
1504}
1505INITCALL0(STG_INIT, qmux_init_stdout_traces);
1506
Amaury Denoyelledd4fbfb2022-03-24 16:09:16 +01001507
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001508static const struct mux_ops qc_ops = {
1509 .init = qc_init,
Amaury Denoyelle2461bd52022-04-13 16:54:52 +02001510 .destroy = qc_destroy,
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001511 .detach = qc_detach,
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001512 .rcv_buf = qc_rcv_buf,
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001513 .snd_buf = qc_snd_buf,
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001514 .subscribe = qc_subscribe,
1515 .unsubscribe = qc_unsubscribe,
Amaury Denoyelle0e0969d2022-01-31 15:41:14 +01001516 .wake = qc_wake,
Christopher Fauleta97cced2022-04-12 18:04:10 +02001517 .flags = MX_FL_HTX|MX_FL_NO_UPG,
Willy Tarreau671bd5a2022-04-11 09:29:21 +02001518 .name = "QUIC",
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001519};
1520
1521static struct mux_proto_list mux_proto_quic =
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001522 { .token = IST("quic"), .mode = PROTO_MODE_HTTP, .side = PROTO_SIDE_FE, .mux = &qc_ops };
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001523
1524INITCALL1(STG_REGISTER, register_mux_proto, &mux_proto_quic);