blob: c4673ee86fe99a78abd949115131806f82546082 [file] [log] [blame]
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001/*
2 * QUIC mux-demux for connections
3 *
4 * Copyright 2021 HAProxy Technologies, Frédéric Lécaille <flecaille@haproxy.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
13#include <import/eb32tree.h>
14#include <haproxy/api.h>
15#include <haproxy/cfgparse.h>
16#include <haproxy/connection.h>
17#include <haproxy/h3.h>
18#include <haproxy/istbuf.h>
19#include <haproxy/log.h>
20#include <haproxy/mux_quic.h>
21#include <haproxy/net_helper.h>
22#include <haproxy/quic_frame.h>
23#include <haproxy/session-t.h>
24#include <haproxy/stats.h>
25#include <haproxy/stream.h>
26#include <haproxy/stream_interface.h>
27#include <haproxy/trace.h>
28
29/* dummy streams returned for closed, error, refused, idle and states */
30static const struct qcs *qc_closed_stream;
31
Frédéric Lécailledfbae762021-02-18 09:59:01 +010032#define QC_SS_MASK(state) (1UL << (state))
33#define QC_SS_IDLE_BIT (1UL << QC_SS_IDLE)
34#define QC_SS_RLOC_BIT (1UL << QC_SS_RLOC)
35#define QC_SS_RREM_BIT (1UL << QC_SS_RREM)
36#define QC_SS_OPEN_BIT (1UL << QC_SS_OPEN)
37#define QC_SS_HREM_BIT (1UL << QC_SS_HREM)
38#define QC_SS_HLOC_BIT (1UL << QC_SS_HLOC)
39#define QC_SS_ERROR_BIT (1UL << QC_SS_ERROR)
40#define QC_SS_CLOSED_BIT (1UL << QC_SS_CLOSED)
41
42
43/* trace source and events */
44static void qc_trace(enum trace_level level, uint64_t mask, \
45 const struct trace_source *src,
46 const struct ist where, const struct ist func,
47 const void *a1, const void *a2, const void *a3, const void *a4);
48
49/* The event representation is split like this :
50 * strm - application layer
51 * qcs - internal QUIC stream
52 * qcc - internal QUIC connection
53 * conn - external connection
54 *
55 */
56static const struct trace_event qc_trace_events[] = {
57#define QC_EV_QCC_NEW (1ULL << 0)
58 { .mask = QC_EV_QCC_NEW, .name = "qcc_new", .desc = "new QUIC connection" },
59#define QC_EV_QCC_RECV (1ULL << 1)
60 { .mask = QC_EV_QCC_RECV, .name = "qcc_recv", .desc = "Rx on QUIC connection" },
61#define QC_EV_QCC_SEND (1ULL << 2)
62 { .mask = QC_EV_QCC_SEND, .name = "qcc_send", .desc = "Tx on QUIC connection" },
63#define QC_EV_QCC_FCTL (1ULL << 3)
64 { .mask = QC_EV_QCC_FCTL, .name = "qcc_fctl", .desc = "QUIC connection flow-controlled" },
65#define QC_EV_QCC_BLK (1ULL << 4)
66 { .mask = QC_EV_QCC_BLK, .name = "qcc_blk", .desc = "QUIC connection blocked" },
67#define QC_EV_QCC_WAKE (1ULL << 5)
68 { .mask = QC_EV_QCC_WAKE, .name = "qcc_wake", .desc = "QUIC connection woken up" },
69#define QC_EV_QCC_END (1ULL << 6)
70 { .mask = QC_EV_QCC_END, .name = "qcc_end", .desc = "QUIC connection terminated" },
71#define QC_EV_QCC_ERR (1ULL << 7)
72 { .mask = QC_EV_QCC_ERR, .name = "qcc_err", .desc = "error on QUIC connection" },
73#define QC_EV_TX_FRAME (1ULL << 8)
74 { .mask = QC_EV_TX_FRAME, .name = "tx_frame", .desc = "transmission of any QUIC frame" },
75#define QC_EV_QCS_NEW (1ULL << 9)
76 { .mask = QC_EV_QCS_NEW, .name = "qcs_new", .desc = "new QUIC stream" },
77#define QC_EV_QCS_GET (1ULL << 10)
78 { .mask = QC_EV_QCS_GET, .name = "qcs_get", .desc = "get QUIC stream by ID" },
79#define QC_EV_QCS_SEND (1ULL << 11)
80 { .mask = QC_EV_QCS_SEND, .name = "qcs_send", .desc = "Tx for QUIC stream" },
81#define QC_EV_QCS_FCTL (1ULL << 12)
82 { .mask = QC_EV_QCS_FCTL, .name = "qcs_fctl", .desc = "QUIC stream flow-controlled" },
83#define QC_EV_QCS_BLK (1ULL << 13)
84 { .mask = QC_EV_QCS_BLK, .name = "qcs_blk", .desc = "QUIC stream blocked" },
85#define QC_EV_QCS_WAKE (1ULL << 14)
86 { .mask = QC_EV_QCS_WAKE, .name = "qcs_wake", .desc = "QUIC stream woken up" },
87#define QC_EV_QCS_END (1ULL << 15)
88 { .mask = QC_EV_QCS_END, .name = "qcs_end", .desc = "QUIC stream terminated" },
89#define QC_EV_QCS_ERR (1ULL << 16)
90 { .mask = QC_EV_QCS_ERR, .name = "qcs_err", .desc = "error on QUIC stream" },
91#define QC_EV_STRM_NEW (1ULL << 17)
92 { .mask = QC_EV_STRM_NEW, .name = "strm_new", .desc = "app-layer stream creation" },
93#define QC_EV_STRM_RECV (1ULL << 18)
94 { .mask = QC_EV_STRM_RECV, .name = "strm_recv", .desc = "receiving data for stream" },
95#define QC_EV_STRM_SEND (1ULL << 19)
96 { .mask = QC_EV_STRM_SEND, .name = "strm_send", .desc = "sending data for stream" },
97#define QC_EV_STRM_FULL (1ULL << 20)
98 { .mask = QC_EV_STRM_FULL, .name = "strm_full", .desc = "stream buffer full" },
99#define QC_EV_STRM_WAKE (1ULL << 21)
100 { .mask = QC_EV_STRM_WAKE, .name = "strm_wake", .desc = "stream woken up" },
101#define QC_EV_STRM_SHUT (1ULL << 22)
102 { .mask = QC_EV_STRM_SHUT, .name = "strm_shut", .desc = "stream shutdown" },
103#define QC_EV_STRM_END (1ULL << 23)
104 { .mask = QC_EV_STRM_END, .name = "strm_end", .desc = "detaching app-layer stream" },
105#define QC_EV_STRM_ERR (1ULL << 24)
106 { .mask = QC_EV_STRM_ERR, .name = "strm_err", .desc = "stream error" },
107 { }
108};
109
110static const struct name_desc qc_trace_lockon_args[4] = {
111 /* arg1 */ { /* already used by the connection */ },
112 /* arg2 */ { .name = "qcs", .desc = "QUIC stream" },
113 /* arg3 */ { },
114 /* arg4 */ { }
115};
116
117static const struct name_desc qc_trace_decoding[] = {
118#define QC_VERB_CLEAN 1
119 { .name="clean", .desc="only user-friendly stuff, generally suitable for level \"user\"" },
120#define QC_VERB_MINIMAL 2
121 { .name="minimal", .desc="report only qcc/qcs state and flags, no real decoding" },
122#define QC_VERB_SIMPLE 3
123 { .name="simple", .desc="add request/response status line or frame info when available" },
124#define QC_VERB_ADVANCED 4
125 { .name="advanced", .desc="add header fields or frame decoding when available" },
126#define QC_VERB_COMPLETE 5
127 { .name="complete", .desc="add full data dump when available" },
128 { /* end */ }
129};
130
131static struct trace_source trace_mux_quic = {
132 .name = IST("mux_quic"),
133 .desc = "QUIC multiplexer",
134 .arg_def = TRC_ARG1_CONN, // TRACE()'s first argument is always a connection
135 .default_cb = qc_trace,
136 .known_events = qc_trace_events,
137 .lockon_args = qc_trace_lockon_args,
138 .decoding = qc_trace_decoding,
139 .report_events = ~0, // report everything by default
140};
141
142#define TRACE_SOURCE &trace_mux_quic
143INITCALL1(STG_REGISTER, trace_register_source, TRACE_SOURCE);
144
145/* quic stats module */
146enum {
147 QC_ST_RESET_STREAM_RCVD,
148
149 QC_ST_CONN_PROTO_ERR,
150 QC_ST_STRM_PROTO_ERR,
151 QC_ST_RESET_STREAM_SENT,
152
153 QC_ST_OPEN_CONN,
154 QC_ST_OPEN_STREAM,
155 QC_ST_TOTAL_CONN,
156 QC_ST_TOTAL_STREAM,
157
158 QC_STATS_COUNT /* must be the last member of the enum */
159};
160
161static struct name_desc qc_stats[] = {
162 [QC_ST_RESET_STREAM_RCVD] = { .name = "qc_rst_stream_rcvd",
163 .desc = "Total number of received RESET_STREAM frames" },
164
165 [QC_ST_CONN_PROTO_ERR] = { .name = "qc_detected_conn_protocol_errors",
166 .desc = "Total number of connection protocol errors" },
167 [QC_ST_STRM_PROTO_ERR] = { .name = "qc_detected_strm_protocol_errors",
168 .desc = "Total number of stream protocol errors" },
169 [QC_ST_RESET_STREAM_SENT] = { .name = "qc_rst_stream_resp",
170 .desc = "Total number of RESET_STREAM sent on detected error" },
171
172 [QC_ST_OPEN_CONN] = { .name = "qc_open_connections",
173 .desc = "Count of currently open connections" },
174 [QC_ST_OPEN_STREAM] = { .name = "qc_backend_open_streams",
175 .desc = "Count of currently open streams" },
176 [QC_ST_TOTAL_CONN] = { .name = "qc_open_connections",
177 .desc = "Total number of connections" },
178 [QC_ST_TOTAL_STREAM] = { .name = "qc_backend_open_streams",
179 .desc = "Total number of streams" },
180};
181
182static struct qc_counters {
183 long long rst_stream_rcvd; /* total number of RESET_STREAM frame received */
184
185 long long conn_proto_err; /* total number of protocol errors detected */
186 long long strm_proto_err; /* total number of protocol errors detected */
187 long long rst_stream_resp; /* total number of RESET_STREAM frame sent on error */
188
189 long long open_conns; /* count of currently open connections */
190 long long open_streams; /* count of currently open streams */
191 long long total_conns; /* total number of connections */
192 long long total_streams; /* total number of streams */
193} qc_counters;
194
195static void qc_fill_stats(void *data, struct field *stats)
196{
197 struct qc_counters *counters = data;
198
199 stats[QC_ST_RESET_STREAM_RCVD] = mkf_u64(FN_COUNTER, counters->rst_stream_rcvd);
200
201 stats[QC_ST_CONN_PROTO_ERR] = mkf_u64(FN_COUNTER, counters->conn_proto_err);
202 stats[QC_ST_STRM_PROTO_ERR] = mkf_u64(FN_COUNTER, counters->strm_proto_err);
203 stats[QC_ST_RESET_STREAM_SENT] = mkf_u64(FN_COUNTER, counters->rst_stream_resp);
204
205 stats[QC_ST_OPEN_CONN] = mkf_u64(FN_GAUGE, counters->open_conns);
206 stats[QC_ST_OPEN_STREAM] = mkf_u64(FN_GAUGE, counters->open_streams);
207 stats[QC_ST_TOTAL_CONN] = mkf_u64(FN_COUNTER, counters->total_conns);
208 stats[QC_ST_TOTAL_STREAM] = mkf_u64(FN_COUNTER, counters->total_streams);
209}
210
211static struct stats_module qc_stats_module = {
212 .name = "quic",
213 .fill_stats = qc_fill_stats,
214 .stats = qc_stats,
215 .stats_count = QC_STATS_COUNT,
216 .counters = &qc_counters,
217 .counters_size = sizeof(qc_counters),
218 .domain_flags = MK_STATS_PROXY_DOMAIN(STATS_PX_CAP_FE|STATS_PX_CAP_BE),
219 .clearable = 1,
220};
221
222INITCALL1(STG_REGISTER, stats_register_module, &qc_stats_module);
223
224/* the qcc connection pool */
225DECLARE_STATIC_POOL(pool_head_qcc, "qcc", sizeof(struct qcc));
226/* the qcs stream pool */
227DECLARE_POOL(pool_head_qcs, "qcs", sizeof(struct qcs));
228
229static struct task *qc_timeout_task(struct task *t, void *context, unsigned int state);
230static int qc_send(struct qcc *qcc);
231static int qc_recv(struct qcc *qcc);
232static int qc_process(struct qcc *qcc);
233static struct task *qc_io_cb(struct task *t, void *ctx, unsigned int state);
234static inline struct qcs *qcc_st_by_id(struct qcc *qcc, int id);
235static struct task *qc_deferred_shut(struct task *t, void *ctx, unsigned int state);
236static struct qcs *qcc_bck_stream_new(struct qcc *qcc, int dir,
237 struct conn_stream *cs, struct session *sess);
238static void qcs_alert(struct qcs *qcs);
239
240/* returns a qcc state as an abbreviated 3-letter string, or "???" if unknown */
241static inline const char *qcc_st_to_str(enum qc_cs st)
242{
243 switch (st) {
244 case QC_CS_NOERR: return "NER";
245 default: return "???";
246 }
247}
248
249/* marks an error on the connection */
250void qc_error(struct qcc *qcc, int err)
251{
252 TRACE_POINT(QC_EV_QCC_ERR, qcc->conn, 0, 0, (void *)(long)(err));
253 qcc->errcode = err;
254 qcc->st0 = QC_CS_ERROR;
255}
256
257static inline const char *qcs_rx_st_to_str(enum qcs_rx_st st)
258{
259 switch (st) {
260 case QC_RX_SS_IDLE: return "IDL";
261 case QC_RX_SS_RECV: return "RCV";
262 case QC_RX_SS_SIZE_KNOWN: return "SKNWN";
263 case QC_RX_SS_DATA_RECVD: return "DATARCVD";
264 case QC_RX_SS_DATA_READ : return "DATAREAD";
265 case QC_RX_SS_RST_RECVD: return "RSTRCVD";
266 case QC_RX_SS_RST_READ: return "RSTREAD";
267 default: return "???";
268 }
269}
270
271static inline const char *qcs_tx_st_to_str(enum qcs_tx_st st)
272{
273 switch (st) {
274 case QC_TX_SS_IDLE: return "IDL";
275 case QC_TX_SS_READY: return "READY";
276 case QC_TX_SS_SEND: return "SEND";
277 case QC_TX_SS_DATA_SENT: return "DATASENT";
278 case QC_TX_SS_DATA_RECVD: return "DATARCVD";
279 case QC_TX_SS_RST_SENT: return "RSTSENT";
280 case QC_TX_SS_RST_RECVD: return "RSTRCVD";
281 default: return "???";
282 }
283}
284
285/* the QUIC traces always expect that arg1, if non-null, is of type connection
286 * (from which we can derive qcc), that arg2, if non-null, is of type qcs.
287 */
288static void qc_trace(enum trace_level level, uint64_t mask, const struct trace_source *src,
289 const struct ist where, const struct ist func,
290 const void *a1, const void *a2, const void *a3, const void *a4)
291{
292 const struct connection *conn = a1;
293 const struct qcc *qcc = conn ? conn->ctx : NULL;
294 const struct qcs *qcs = a2;
295
296 if (!qcc)
297 return;
298
299 if (src->verbosity > QC_VERB_CLEAN) {
300 chunk_appendf(&trace_buf, " : qcc=%p(%c,%s)",
301 qcc, conn_is_back(conn) ? 'B' : 'F', qcc_st_to_str(qcc->st0));
302 if (qcs) {
303 chunk_appendf(&trace_buf, " qcs=%p(rx.%s,tx.%s)",
304 qcs, qcs_rx_st_to_str(qcs->rx.st), qcs_tx_st_to_str(qcs->tx.st));
305 }
306 }
307}
308
309
310/* Detect a pending read0 for a QUIC connection. It happens if a read0 is pending
311 * on the connection AND if there is no more data in the demux buffer. The
312 * function returns 1 to report a read0 or 0 otherwise.
313 */
314__maybe_unused
315static int qcc_read0_pending(struct qcc *qcc)
316{
317 if (conn_xprt_read0_pending(qcc->conn) && !qcc->rx.inmux)
318 return 1;
319 return 0;
320}
321
322/* returns true if the connection is allowed to expire, false otherwise. A
323 * connection may expire when:
324 * - it has no stream
325 * - it has data in the mux buffer
326 * - it has streams in the blocked list
327 * - it has streams in the fctl list
328 * - it has streams in the send list
329 * Otherwise it means some streams are waiting in the data layer and it should
330 * not expire.
331 */
332__maybe_unused
333static inline int qcc_may_expire(const struct qcc *qcc)
334{
335 return eb_is_empty(&qcc->streams_by_id) ||
336 br_data(qcc->mbuf) ||
337 !LIST_ISEMPTY(&qcc->blocked_list) ||
338 !LIST_ISEMPTY(&qcc->fctl_list) ||
339 !LIST_ISEMPTY(&qcc->send_list);
340}
341
342static __inline int
343qcc_is_dead(const struct qcc *qcc)
344{
345 if (eb_is_empty(&qcc->streams_by_id) && /* don't close if streams exist */
346 ((qcc->conn->flags & CO_FL_ERROR) || /* errors close immediately */
347 (qcc->st0 >= QC_CS_ERROR && !qcc->task) || /* a timeout stroke earlier */
348 (!(qcc->conn->owner)) || /* Nobody's left to take care of the connection, drop it now */
349 (!br_data(qcc->mbuf) && /* mux buffer empty, also process clean events below */
350 conn_xprt_read0_pending(qcc->conn))))
351 return 1;
352
353 return 0;
354}
355
356/*****************************************************/
357/* functions below are for dynamic buffer management */
358/*****************************************************/
359
360/* indicates whether or not the we may call the qc_recv() function to attempt
361 * to receive data into the buffer and/or demux pending data. The condition is
362 * a bit complex due to some API limits for now. The rules are the following :
363 * - if an error or a shutdown was detected on the connection and the buffer
364 * is empty, we must not attempt to receive
365 * - if the demux buf failed to be allocated, we must not try to receive and
366 * we know there is nothing pending
367 * - if no flag indicates a blocking condition, we may attempt to receive,
368 * regardless of whether the demux buffer is full or not, so that only
369 * de demux part decides whether or not to block. This is needed because
370 * the connection API indeed prevents us from re-enabling receipt that is
371 * already enabled in a polled state, so we must always immediately stop
372 * as soon as the demux can't proceed so as never to hit an end of read
373 * with data pending in the buffers.
374 * - otherwise must may not attempt
375 */
376static inline int qc_recv_allowed(const struct qcc *qcc)
377{
378 if (qcc->rx.inmux == 0 &&
379 (qcc->st0 >= QC_CS_ERROR ||
380 qcc->conn->flags & CO_FL_ERROR ||
381 conn_xprt_read0_pending(qcc->conn)))
382 return 0;
383
384 if (!(qcc->flags & QC_CF_DEM_BLOCK_ANY))
385 return 1;
386
387 return 0;
388}
389
390/* restarts reading on the connection if it was not enabled */
391static inline void qcc_restart_reading(const struct qcc *qcc, int consider_buffer)
392{
393 if (!qc_recv_allowed(qcc))
394 return;
395
396 if ((!consider_buffer || !qcc->rx.inmux)
397 && (qcc->wait_event.events & SUB_RETRY_RECV))
398 return;
399
400 tasklet_wakeup(qcc->wait_event.tasklet);
401}
402
403/* Tries to grab a buffer and to re-enable processing on mux <target>. The qcc
404 * flags are used to figure what buffer was requested. It returns 1 if the
405 * allocation succeeds, in which case the connection is woken up, or 0 if it's
406 * impossible to wake up and we prefer to be woken up later.
407 */
408static int qc_buf_available(void *target)
409{
410 struct qcc *qcc = target;
411
412 if ((qcc->flags & QC_CF_MUX_MALLOC) && b_alloc(br_tail(qcc->mbuf))) {
413 qcc->flags &= ~QC_CF_MUX_MALLOC;
414
415 if (qcc->flags & QC_CF_DEM_MROOM) {
416 qcc->flags &= ~QC_CF_DEM_MROOM;
417 qcc_restart_reading(qcc, 1);
418 }
419 return 1;
420 }
421
422#if 0
423 if ((qcc->flags & QC_CF_DEM_SALLOC) &&
424 (qcs = qcc_st_by_id(qcc, qcc->dsi)) && qcs->cs &&
425 b_alloc_margin(&qcs->rxbuf, 0)) {
426 qcc->flags &= ~QC_CF_DEM_SALLOC;
427 qcc_restart_reading(qcc, 1);
428 return 1;
429 }
430#endif
431
432 return 0;
433}
434
435struct buffer *qc_get_buf(struct qcc *qcc, struct buffer *bptr)
436{
437 struct buffer *buf = NULL;
438
439 if (likely(!LIST_INLIST(&qcc->buf_wait.list)) &&
440 unlikely((buf = b_alloc(bptr)) == NULL)) {
441 qcc->buf_wait.target = qcc;
442 qcc->buf_wait.wakeup_cb = qc_buf_available;
443 LIST_APPEND(&ti->buffer_wq, &qcc->buf_wait.list);
444 }
445
446 return buf;
447}
448
449__maybe_unused
450static inline void qc_release_buf(struct qcc *qcc, struct buffer *bptr)
451{
452 if (bptr->size) {
453 b_free(bptr);
454 offer_buffers(NULL, 1);
455 }
456}
457
458static inline void qc_release_mbuf(struct qcc *qcc)
459{
460 struct buffer *buf;
461 unsigned int count = 0;
462
463 while (b_size(buf = br_head_pick(qcc->mbuf))) {
464 b_free(buf);
465 count++;
466 }
467 if (count)
468 offer_buffers(NULL, count);
469}
470
471/* returns the number of streams in use on a connection to figure if it's
472 * idle or not. We check nb_cs and not nb_streams as the caller will want
473 * to know if it was the last one after a detach().
474 */
475static int qc_used_streams(struct connection *conn)
476{
477 struct qcc *qcc = conn->ctx;
478
479 return qcc->nb_cs;
480}
481
482/* returns the number of concurrent streams available on the connection with <dir>
483 * as direction
484 */
485static int qc_avail_streams(struct connection *conn, enum qcs_dir dir)
486{
487 struct qcc *qcc = conn->ctx;
488 enum qcs_type qcs_type;
489
490 if (qcc->st0 >= QC_CS_ERROR)
491 return 0;
492
493 qcs_type = qcs_type_from_dir(qcc, dir);
494
495 return qcc->strms[qcs_type].max_streams - qcc->strms[qcs_type].nb_streams;
496}
497
498
499/* returns the number of concurrent bidirectional streams available on the
500 * connection.
501 */
502static int qc_avail_streams_bidi(struct connection *conn)
503{
504 return qc_avail_streams(conn, QCS_BIDI);
505}
506
507/* returns the number of concurrent unidirectional streams available on the
508 * connection.
509 */
510static int qc_avail_streams_uni(struct connection *conn)
511{
512 return qc_avail_streams(conn, QCS_UNI);
513}
514
515/*****************************************************************/
516/* functions below are dedicated to the mux setup and management */
517/*****************************************************************/
518
519/* Update the mux transport parameter after having received remote transpot parameters */
520void quic_mux_transport_params_update(struct qcc *qcc)
521{
522 if (objt_listener(qcc->conn->target)) {
523 struct quic_transport_params *clt_params;
524
525 /* Client parameters, params used to TX. */
526 clt_params = &qcc->conn->qc->tx.params;
527
528 qcc->tx.max_data = clt_params->initial_max_data;
529 /* Client initiated streams must respect the server flow control. */
530 qcc->strms[QCS_CLT_BIDI].rx.max_data = clt_params->initial_max_stream_data_bidi_local;
531 qcc->strms[QCS_CLT_UNI].rx.max_data = clt_params->initial_max_stream_data_uni;
532
533 /* Server initiated streams must respect the server flow control. */
534 qcc->strms[QCS_SRV_BIDI].max_streams = clt_params->initial_max_streams_bidi;
535 qcc->strms[QCS_SRV_BIDI].tx.max_data = clt_params->initial_max_stream_data_bidi_remote;
536
537 qcc->strms[QCS_SRV_UNI].max_streams = clt_params->initial_max_streams_uni;
538 qcc->strms[QCS_SRV_UNI].tx.max_data = clt_params->initial_max_stream_data_uni;
539 }
540 else {
541 struct quic_transport_params *srv_params;
542
543 /* server parameters, TX params. */
544 srv_params = &qcc->conn->qc->tx.params;
545
546 qcc->tx.max_data = srv_params->initial_max_data;
547 /* Client initiated streams must respect the server flow control. */
548 qcc->strms[QCS_CLT_BIDI].max_streams = srv_params->initial_max_streams_bidi;
549 qcc->strms[QCS_CLT_BIDI].tx.max_data = srv_params->initial_max_stream_data_bidi_remote;
550
551 qcc->strms[QCS_CLT_UNI].max_streams = srv_params->initial_max_streams_uni;
552 qcc->strms[QCS_CLT_UNI].tx.max_data = srv_params->initial_max_stream_data_uni;
553
554 /* Server initiated streams must respect the server flow control. */
555 qcc->strms[QCS_SRV_BIDI].rx.max_data = srv_params->initial_max_stream_data_bidi_local;
556 qcc->strms[QCS_SRV_UNI].rx.max_data = srv_params->initial_max_stream_data_uni;
557 }
558
559 /* Now that we have all the flow control information, we can finalize the application
560 * context.
561 */
562 qcc->app_ops->finalize(qcc->ctx);
563}
564
565/* Initialize the mux once it's attached. For outgoing connections, the context
566 * is already initialized before installing the mux, so we detect incoming
567 * connections from the fact that the context is still NULL (even during mux
568 * upgrades). <input> is always used as Input buffer and may contain data. It is
569 * the caller responsibility to not reuse it anymore. Returns < 0 on error.
570 */
571static int qc_init(struct connection *conn, struct proxy *prx,
572 struct session *sess, struct buffer *input)
573{
574 struct qcc *qcc;
575 struct task *t = NULL;
576 void *conn_ctx = conn->ctx;
577
578 TRACE_ENTER(QC_EV_QCC_NEW);
579
580 qcc = pool_alloc(pool_head_qcc);
581 if (!qcc)
582 goto fail_no_qcc;
583
584 if (conn_is_back(conn)) {
585 qcc->flags = QC_CF_IS_BACK;
586 qcc->shut_timeout = qcc->timeout = prx->timeout.server;
587 if (tick_isset(prx->timeout.serverfin))
588 qcc->shut_timeout = prx->timeout.serverfin;
589
590 qcc->px_counters = EXTRA_COUNTERS_GET(prx->extra_counters_be,
591 &qc_stats_module);
592 } else {
593 qcc->flags = QC_CF_NONE;
594 qcc->shut_timeout = qcc->timeout = prx->timeout.client;
595 if (tick_isset(prx->timeout.clientfin))
596 qcc->shut_timeout = prx->timeout.clientfin;
597
598 qcc->px_counters = EXTRA_COUNTERS_GET(prx->extra_counters_fe,
599 &qc_stats_module);
600 }
601
602 qcc->proxy = prx;
603 qcc->task = NULL;
604 if (tick_isset(qcc->timeout)) {
Willy Tarreaubeeabf52021-10-01 18:23:30 +0200605 t = task_new_here();
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100606 if (!t)
607 goto fail;
608
609 qcc->task = t;
610 t->process = qc_timeout_task;
611 t->context = qcc;
612 t->expire = tick_add(now_ms, qcc->timeout);
613 }
614
Amaury Denoyellecde91122021-09-22 15:28:27 +0200615 qcc->subs = NULL;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100616 qcc->wait_event.tasklet = tasklet_new();
617 if (!qcc->wait_event.tasklet)
618 goto fail;
619
620 qcc->wait_event.tasklet->process = qc_io_cb;
621 qcc->wait_event.tasklet->context = qcc;
622 qcc->wait_event.events = 0;
623
624 /* Initialize the context. */
625 qcc->st0 = QC_CS_NOERR;
626 qcc->conn = conn;
627 qcc->conn->qc->qcc = qcc;
628
629 /* Application layer initialization. */
630 qcc->app_ops = &h3_ops;
631 if (!qcc->app_ops->init(qcc))
632 goto fail;
633
634 /* The transports parameters which control the data sent have been stored
635 * in ->tx.params. The ones which control the received data are stored in
636 * in ->rx.params.
637 */
638 if (objt_listener(qcc->conn->target)) {
639 struct quic_transport_params *srv_params;
640
641 /* Server parameters, params used for RX flow control. */
642 srv_params = &conn->qc->rx.params;
643
644 qcc->rx.max_data = srv_params->initial_max_data;
645 qcc->tx.max_data = 0;
646 /* Client initiated streams must respect the server flow control. */
647 qcc->strms[QCS_CLT_BIDI].max_streams = srv_params->initial_max_streams_bidi;
648 qcc->strms[QCS_CLT_BIDI].nb_streams = 0;
649 qcc->strms[QCS_CLT_BIDI].largest_id = -1;
650 qcc->strms[QCS_CLT_BIDI].rx.max_data = 0;
651 qcc->strms[QCS_CLT_BIDI].tx.max_data = srv_params->initial_max_stream_data_bidi_remote;
652
653 qcc->strms[QCS_CLT_UNI].max_streams = srv_params->initial_max_streams_uni;
654 qcc->strms[QCS_CLT_UNI].nb_streams = 0;
655 qcc->strms[QCS_CLT_UNI].largest_id = -1;
656 qcc->strms[QCS_CLT_UNI].rx.max_data = 0;
657 qcc->strms[QCS_CLT_UNI].tx.max_data = srv_params->initial_max_stream_data_uni;
658
659 /* Server initiated streams must respect the server flow control. */
660 qcc->strms[QCS_SRV_BIDI].max_streams = 0;
661 qcc->strms[QCS_SRV_BIDI].nb_streams = 0;
662 qcc->strms[QCS_SRV_BIDI].largest_id = -1;
663 qcc->strms[QCS_SRV_BIDI].rx.max_data = srv_params->initial_max_stream_data_bidi_local;
664 qcc->strms[QCS_SRV_BIDI].tx.max_data = 0;
665
666 qcc->strms[QCS_SRV_UNI].max_streams = 0;
667 qcc->strms[QCS_SRV_UNI].nb_streams = 0;
668 qcc->strms[QCS_SRV_UNI].largest_id = -1;
669 qcc->strms[QCS_SRV_UNI].rx.max_data = srv_params->initial_max_stream_data_uni;
670 qcc->strms[QCS_SRV_UNI].tx.max_data = 0;
671 }
672 else {
673 struct quic_transport_params *clt_params;
674
675 /* client parameters, RX params. */
676 clt_params = &conn->qc->rx.params;
677
678 qcc->rx.max_data = clt_params->initial_max_data;
679 qcc->tx.max_data = 0;
680 /* Client initiated streams must respect the server flow control. */
681 qcc->strms[QCS_CLT_BIDI].max_streams = 0;
682 qcc->strms[QCS_CLT_BIDI].nb_streams = 0;
683 qcc->strms[QCS_CLT_BIDI].largest_id = -1;
684 qcc->strms[QCS_CLT_BIDI].rx.max_data = clt_params->initial_max_stream_data_bidi_local;
685 qcc->strms[QCS_CLT_BIDI].tx.max_data = 0;
686
687 qcc->strms[QCS_CLT_UNI].max_streams = 0;
688 qcc->strms[QCS_CLT_UNI].nb_streams = 0;
689 qcc->strms[QCS_CLT_UNI].largest_id = -1;
690 qcc->strms[QCS_CLT_UNI].rx.max_data = clt_params->initial_max_stream_data_uni;
691 qcc->strms[QCS_CLT_UNI].tx.max_data = 0;
692
693 /* Server initiated streams must respect the server flow control. */
694 qcc->strms[QCS_SRV_BIDI].max_streams = clt_params->initial_max_streams_bidi;
695 qcc->strms[QCS_SRV_BIDI].nb_streams = 0;
696 qcc->strms[QCS_SRV_BIDI].largest_id = -1;
697 qcc->strms[QCS_SRV_BIDI].rx.max_data = 0;
698 qcc->strms[QCS_SRV_BIDI].tx.max_data = clt_params->initial_max_stream_data_bidi_remote;
699
700 qcc->strms[QCS_SRV_UNI].max_streams = clt_params->initial_max_streams_uni;
701 qcc->strms[QCS_SRV_UNI].nb_streams = 0;
702 qcc->strms[QCS_SRV_UNI].largest_id = -1;
703 qcc->strms[QCS_SRV_UNI].rx.max_data = 0;
704 qcc->strms[QCS_SRV_UNI].tx.max_data = clt_params->initial_max_stream_data_uni;
705
706 }
707
708 /* Initialize the streams counters. */
709 qcc->nb_cs = 0;
710 qcc->stream_cnt = 0;
711
712 br_init(qcc->mbuf, sizeof(qcc->mbuf) / sizeof(qcc->mbuf[0]));
713 qcc->streams_by_id = EB_ROOT_UNIQUE;
714 LIST_INIT(&qcc->send_list);
715 LIST_INIT(&qcc->fctl_list);
716 LIST_INIT(&qcc->blocked_list);
717 LIST_INIT(&qcc->buf_wait.list);
718 MT_LIST_INIT(&qcc->qcs_rxbuf_wlist);
719
Frédéric Lécaille01abc462021-07-21 09:34:27 +0200720 HA_ATOMIC_STORE(&conn->ctx, qcc);
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100721
722 if (t)
723 task_queue(t);
724
725 if (qcc->flags & QC_CF_IS_BACK) {
726 /* FIXME: For outgoing connections we need to immediately allocate streams.
727 * This highly depends on the QUIC application needs.
728 */
729 }
730
731 HA_ATOMIC_ADD(&qcc->px_counters->open_conns, 1);
732 HA_ATOMIC_ADD(&qcc->px_counters->total_conns, 1);
733
734 /* prepare to read something */
735 qcc_restart_reading(qcc, 1);
736 TRACE_LEAVE(QC_EV_QCC_NEW, conn);
737 return 0;
738
739 fail:
740 task_destroy(t);
741 if (qcc->wait_event.tasklet)
742 tasklet_free(qcc->wait_event.tasklet);
743 pool_free(pool_head_qcc, qcc);
744 fail_no_qcc:
745 conn->ctx = conn_ctx; /* restore saved ctx */
746 TRACE_DEVEL("leaving in error", QC_EV_QCC_NEW|QC_EV_QCC_END|QC_EV_QCC_ERR);
747 return -1;
748}
749
750/* returns the stream associated with id <id> or NULL if not found */
751__maybe_unused
752static inline struct qcs *qcc_st_by_id(struct qcc *qcc, int id)
753{
754 struct eb64_node *node;
755
756 node = eb64_lookup(&qcc->streams_by_id, id);
757 if (!node)
758 return (struct qcs *)qc_closed_stream;
759
760 return container_of(node, struct qcs, by_id);
761}
762
763/* release function. This one should be called to free all resources allocated
764 * to the mux.
765 */
766static void qc_release(struct qcc *qcc)
767{
768 struct connection *conn = NULL;
769
770 TRACE_ENTER(QC_EV_QCC_END);
771
772 if (qcc) {
773 /* The connection must be aattached to this mux to be released */
774 if (qcc->conn && qcc->conn->ctx == qcc)
775 conn = qcc->conn;
776
777 TRACE_DEVEL("freeing qcc", QC_EV_QCC_END, conn);
778
779 if (LIST_INLIST(&qcc->buf_wait.list))
780 LIST_DELETE(&qcc->buf_wait.list);
781
782 qc_release_mbuf(qcc);
783
784 if (qcc->task) {
785 qcc->task->context = NULL;
786 task_wakeup(qcc->task, TASK_WOKEN_OTHER);
787 qcc->task = NULL;
788 }
789 if (qcc->wait_event.tasklet)
790 tasklet_free(qcc->wait_event.tasklet);
791 if (conn && qcc->wait_event.events != 0)
792 conn->xprt->unsubscribe(conn, conn->xprt_ctx, qcc->wait_event.events,
793 &qcc->wait_event);
794
795 HA_ATOMIC_SUB(&qcc->px_counters->open_conns, 1);
796
797 pool_free(pool_head_qcc, qcc);
798 }
799
800 if (conn) {
801 conn->mux = NULL;
802 conn->ctx = NULL;
803 TRACE_DEVEL("freeing conn", QC_EV_QCC_END, conn);
804
805 conn_stop_tracking(conn);
806 conn_full_close(conn);
807 if (conn->destroy_cb)
808 conn->destroy_cb(conn);
809 conn_free(conn);
810 }
811
812 TRACE_LEAVE(QC_EV_QCC_END);
813}
814
815
816/******************************************************/
817/* functions below are for the QUIC protocol processing */
818/******************************************************/
819
820/* attempt to notify the data layer of recv availability */
821__maybe_unused
822static void qcs_notify_recv(struct qcs *qcs)
823{
824 if (qcs->subs && qcs->subs->events & SUB_RETRY_RECV) {
825 TRACE_POINT(QC_EV_STRM_WAKE, qcs->qcc->conn, qcs);
826 tasklet_wakeup(qcs->subs->tasklet);
827 qcs->subs->events &= ~SUB_RETRY_RECV;
828 if (!qcs->subs->events)
829 qcs->subs = NULL;
830 }
831}
832
833/* attempt to notify the data layer of send availability */
834__maybe_unused
835static void qcs_notify_send(struct qcs *qcs)
836{
837 if (qcs->subs && qcs->subs->events & SUB_RETRY_SEND) {
838 TRACE_POINT(QC_EV_STRM_WAKE, qcs->qcc->conn, qcs);
839 qcs->flags |= QC_SF_NOTIFIED;
840 tasklet_wakeup(qcs->subs->tasklet);
841 qcs->subs->events &= ~SUB_RETRY_SEND;
842 if (!qcs->subs->events)
843 qcs->subs = NULL;
844 }
845 else if (qcs->flags & (QC_SF_WANT_SHUTR | QC_SF_WANT_SHUTW)) {
846 TRACE_POINT(QC_EV_STRM_WAKE, qcs->qcc->conn, qcs);
847 tasklet_wakeup(qcs->shut_tl);
848 }
849}
850
851/* alerts the data layer, trying to wake it up by all means, following
852 * this sequence :
853 * - if the qcs' data layer is subscribed to recv, then it's woken up for recv
854 * - if its subscribed to send, then it's woken up for send
855 * - if it was subscribed to neither, its ->wake() callback is called
856 * It is safe to call this function with a closed stream which doesn't have a
857 * conn_stream anymore.
858 */
859__maybe_unused
860static void qcs_alert(struct qcs *qcs)
861{
862 TRACE_ENTER(QC_EV_QCS_WAKE, qcs->qcc->conn, qcs);
863
864 if (qcs->subs ||
865 (qcs->flags & (QC_SF_WANT_SHUTR | QC_SF_WANT_SHUTW))) {
866 qcs_notify_recv(qcs);
867 qcs_notify_send(qcs);
868 }
869 else if (qcs->cs && qcs->cs->data_cb->wake != NULL) {
870 TRACE_POINT(QC_EV_STRM_WAKE, qcs->qcc->conn, qcs);
871 qcs->cs->data_cb->wake(qcs->cs);
872 }
873
874 TRACE_LEAVE(QC_EV_QCS_WAKE, qcs->qcc->conn, qcs);
875}
876
877/* marks stream <qcs> as CLOSED and decrement the number of active streams for
878 * its connection if the stream was not yet closed. Please use this exclusively
879 * before closing a stream to ensure stream count is well maintained.
880 */
881static inline void qcs_close(struct qcs *qcs)
882{
883 TRACE_ENTER(QC_EV_QCS_END, qcs->qcc->conn, qcs);
884 /* XXX TO DO XXX */
885 TRACE_LEAVE(QC_EV_QCS_END, qcs->qcc->conn, qcs);
886}
887
888/* detaches an QUIC stream from its QCC and releases it to the QCS pool. */
889/* qcs_destroy should only ever be called by the thread that owns the stream,
890 * that means that a tasklet should be used if we want to destroy the qcs
891 * from another thread
892 */
893static void qcs_destroy(struct qcs *qcs)
894{
895 struct connection *conn = qcs->qcc->conn;
896
897 TRACE_ENTER(QC_EV_QCS_END, conn, qcs);
898
899 qcs_close(qcs);
900 eb64_delete(&qcs->by_id);
901 if (b_size(&qcs->rx.buf)) {
902 b_free(&qcs->rx.buf);
903 offer_buffers(NULL, 1);
904 }
905
906 if (qcs->subs)
907 qcs->subs->events = 0;
908
909 /* There's no need to explicitly call unsubscribe here, the only
910 * reference left would be in the qcc send_list/fctl_list, and if
911 * we're in it, we're getting out anyway
912 */
913 LIST_DEL_INIT(&qcs->list);
914
915 /* ditto, calling tasklet_free() here should be ok */
916 tasklet_free(qcs->shut_tl);
917 pool_free(pool_head_qcs, qcs);
918
919 TRACE_LEAVE(QC_EV_QCS_END, conn);
920}
921
922/* allocates a new bidirection stream <id> for connection <qcc> and adds it into qcc's
923 * stream tree. In case of error, nothing is added and NULL is returned. The
924 * causes of errors can be any failed memory allocation. The caller is
925 * responsible for checking if the connection may support an extra stream
926 * prior to calling this function.
927 */
928struct qcs *bidi_qcs_new(struct qcc *qcc, uint64_t id)
929{
930 struct qcs *qcs;
931 enum qcs_type qcs_type;
932
933 TRACE_ENTER(QC_EV_QCS_NEW, qcc->conn);
934
935 qcs = pool_alloc(pool_head_qcs);
936 if (!qcs)
937 goto out;
938
939 qcs->shut_tl = tasklet_new();
940 if (!qcs->shut_tl) {
941 pool_free(pool_head_qcs, qcs);
942 goto out;
943 }
944
945 qcs_type = qcs_id_type(id);
946 qcs->qcc = qcc;
947 qcs->cs = NULL;
948 qcs->id = qcs->by_id.key = id;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100949 qcs->flags = QC_SF_NONE;
950
951 qcs->rx.buf = BUF_NULL;
952 qcs->rx.st = QC_RX_SS_IDLE;
953 qcs->rx.bytes = qcs->rx.offset = 0;
954 qcs->rx.max_data = qcc->strms[qcs_type].rx.max_data;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100955 qcs->rx.buf = BUF_NULL;
Frédéric Lécaille785d3bd2021-09-10 09:13:39 +0200956 qcs->rx.frms = EB_ROOT_UNIQUE;
957
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100958 qcs->tx.st = QC_TX_SS_IDLE;
Frédéric Lécaille785d3bd2021-09-10 09:13:39 +0200959 qcs->tx.bytes = qcs->tx.offset = qcs->tx.ack_offset = 0;
960 qcs->tx.acked_frms = EB_ROOT_UNIQUE;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100961 qcs->tx.max_data = qcc->strms[qcs_type].tx.max_data;
Frédéric Lécaille785d3bd2021-09-10 09:13:39 +0200962 qcs->tx.buf = BUF_NULL;
Amaury Denoyellef52151d2021-08-24 16:11:18 +0200963 br_init(qcs->tx.mbuf, sizeof(qcs->tx.mbuf) / sizeof(qcs->tx.mbuf[0]));
Amaury Denoyelle42bb8aa2021-08-24 16:28:47 +0200964 qcs->tx.left = 0;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100965
966 eb64_insert(&qcc->streams_by_id, &qcs->by_id);
967 qcc->strms[qcs_type].nb_streams++;
968 qcc->stream_cnt++;
969 qcs->subs = NULL;
970 LIST_INIT(&qcs->list);
971 qcs->shut_tl->process = qc_deferred_shut;
972 qcs->shut_tl->context = qcs;
973
974 HA_ATOMIC_ADD(&qcc->px_counters->open_streams, 1);
975 HA_ATOMIC_ADD(&qcc->px_counters->total_streams, 1);
976
977 TRACE_LEAVE(QC_EV_QCS_NEW, qcc->conn, qcs);
978 return qcs;
979
980 out:
981 TRACE_DEVEL("leaving in error", QC_EV_QCS_ERR|QC_EV_QCS_END, qcc->conn);
982 return NULL;
983}
984
985/* Release <qcs> outgoing uni-stream */
986void qcs_release(struct qcs *qcs)
987{
988 eb64_delete(&qcs->by_id);
989 pool_free(pool_head_qcs, qcs);
990}
991
992/* Allocates a locally initiated unidirectional stream. */
993struct qcs *luqs_new(struct qcc *qcc)
994{
995 struct qcs *qcs;
996 uint64_t next_id;
997 enum qcs_type qcs_type;
998
999 TRACE_ENTER(QC_EV_QCS_NEW, qcc->conn);
1000
1001 qcs = NULL;
1002 /* QCS_ID_DIR_BIT bit is set for unidirectional stream. */
1003 if (objt_listener(qcc->conn->target))
1004 qcs_type = QCS_ID_SRV_INTIATOR_BIT | QCS_ID_DIR_BIT;
1005 else
1006 qcs_type = QCS_ID_DIR_BIT;
1007
1008 next_id = qcs_next_id(qcc, qcs_type);
1009 if (next_id == (uint64_t)-1) {
1010 TRACE_PROTO("No more stream available", QC_EV_QCS_NEW, qcc->conn);
1011 goto out;
1012 }
1013
1014 qcs = pool_alloc(pool_head_qcs);
1015 if (!qcs)
1016 goto out;
1017
1018 qcs->qcc = qcc;
1019 qcs->cs = NULL;
1020 qcs->id = qcs->by_id.key = next_id;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001021 qcs->flags = QC_SF_NONE;
1022
Frédéric Lécaille785d3bd2021-09-10 09:13:39 +02001023 qcs->tx.st = QC_TX_SS_IDLE;
1024 qcs->tx.max_data = qcc->strms[qcs_type].tx.max_data;
1025 qcs->tx.offset = qcs->tx.bytes = qcs->tx.ack_offset = 0;
1026 qcs->tx.acked_frms = EB_ROOT_UNIQUE;
1027 qcs->tx.buf = BUF_NULL;
Amaury Denoyellef52151d2021-08-24 16:11:18 +02001028 br_init(qcs->tx.mbuf, sizeof(qcs->tx.mbuf) / sizeof(qcs->tx.mbuf[0]));
Amaury Denoyelle42bb8aa2021-08-24 16:28:47 +02001029 qcs->tx.left = 0;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001030
1031 qcs->subs = NULL;
1032 LIST_INIT(&qcs->list);
Amaury Denoyellecd28b272021-09-22 14:48:32 +02001033 // TODO do not insert luqs into streams_by_id as it prevent to detect
1034 // that the connection is dead
1035 //eb64_insert(&qcc->streams_by_id, &qcs->by_id);
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001036
1037 TRACE_LEAVE(QC_EV_QCS_NEW, qcc->conn);
1038 return qcs;
1039
1040 out:
1041 if (qcs)
1042 pool_free(pool_head_qcs, qcs);
1043 TRACE_DEVEL("leaving in error", QC_EV_QCS_ERR|QC_EV_QCS_END, qcc->conn);
1044 return NULL;
1045}
1046
1047/* Allocates a remotely initiated unidirectional stream. */
1048struct qcs *ruqs_new(struct qcc *qcc, uint64_t id)
1049{
1050 struct qcs *qcs;
1051 enum qcs_type qcs_type;
1052
1053 TRACE_ENTER(QC_EV_QCS_NEW, qcc->conn);
1054 qcs = pool_alloc(pool_head_qcs);
1055 if (!qcs)
1056 goto out;
1057
1058 qcs_type = qcs_id_type(id);
1059
1060 qcs->qcc = qcc;
1061 qcs->cs = NULL;
1062
1063 qcs->qcc = qcc;
1064 qcs->id = qcs->by_id.key = id;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001065 qcs->flags = QC_SF_NONE;
1066
1067 qcs->rx.st = QC_RX_SS_IDLE;
1068 qcs->rx.max_data = qcc->strms[qcs_type].rx.max_data;
1069 qcs->rx.offset = qcs->rx.bytes = 0;
1070 qcs->rx.buf = BUF_NULL;
Frédéric Lécaille785d3bd2021-09-10 09:13:39 +02001071 qcs->rx.frms = EB_ROOT_UNIQUE;
Amaury Denoyellef52151d2021-08-24 16:11:18 +02001072 br_init(qcs->tx.mbuf, sizeof(qcs->tx.mbuf) / sizeof(qcs->tx.mbuf[0]));
Amaury Denoyelle42bb8aa2021-08-24 16:28:47 +02001073 qcs->tx.left = 0;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001074
1075 qcs->subs = NULL;
1076 LIST_INIT(&qcs->list);
Amaury Denoyellecd28b272021-09-22 14:48:32 +02001077 // TODO do not insert ruqs into streams_by_id as it prevent to detect
1078 // that the connection is dead
1079 //eb64_insert(&qcc->streams_by_id, &qcs->by_id);
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001080
1081 TRACE_LEAVE(QC_EV_QCS_NEW, qcc->conn);
1082 return qcs;
1083
1084 out:
1085 TRACE_DEVEL("leaving in error", QC_EV_QCS_ERR|QC_EV_QCS_END, qcc->conn);
1086 return NULL;
1087}
1088
1089/* attempt to notify the data layer of recv availability */
1090void ruqs_notify_recv(struct qcs *qcs)
1091{
1092 if (qcs->subs && qcs->subs->events & SUB_RETRY_RECV) {
1093 TRACE_POINT(QC_EV_STRM_WAKE, qcs->qcc->conn);
1094 tasklet_wakeup(qcs->subs->tasklet);
1095 qcs->subs->events &= ~SUB_RETRY_RECV;
1096 if (!qcs->subs->events)
1097 qcs->subs = NULL;
1098 }
1099}
1100
1101/* Allocates a new stream associated to conn_stream <cs> on the qcc connection
1102 * with dir as direction and returns it, or NULL in case of memory allocation
1103 * error or if the highest possible stream ID was reached.
1104 */
1105static struct qcs *qcc_bck_stream_new(struct qcc *qcc, int dir,
1106 struct conn_stream *cs, struct session *sess)
1107{
1108 struct qcs *qcs = NULL;
1109 enum qcs_type qcs_type;
1110
1111 TRACE_ENTER(QC_EV_QCS_NEW, qcc->conn);
1112
1113 qcs_type = qcs_type_from_dir(qcc, dir);
1114 if (qcc->strms[qcs_type].largest_id + 1 >= qcc->strms[qcs_type].max_streams)
1115 goto out;
1116
1117 /* Defer choosing the ID until we send the first message to create the stream */
1118 qcs = bidi_qcs_new(qcc, qcc->strms[qcs_type].largest_id + 1);
1119 if (!qcs)
1120 goto out;
1121
1122 qcs->cs = cs;
1123 qcs->sess = sess;
1124 cs->ctx = qcs;
1125 qcc->nb_cs++;
1126
1127 out:
1128 if (likely(qcs))
1129 TRACE_LEAVE(QC_EV_QCS_NEW, qcc->conn, qcs);
1130 else
1131 TRACE_LEAVE(QC_EV_QCS_NEW|QC_EV_QCS_ERR|QC_EV_QCS_END, qcc->conn, qcs);
1132 return qcs;
1133}
1134
1135/* Allocates a new bidirectional stream associated to conn_stream <cs> on the <qcc> connection
1136 * and returns it, or NULL in case of memory allocation error or if the highest
1137 * possible stream ID was reached.
1138 */
1139__maybe_unused
1140static struct qcs *qcc_bck_stream_new_bidi(struct qcc *qcc,
1141 struct conn_stream *cs, struct session *sess)
1142{
1143 return qcc_bck_stream_new(qcc, QCS_BIDI, cs, sess);
1144}
1145
1146/* Allocates a new unidirectional stream associated to conn_stream <cs> on the <qcc> connection
1147 * and returns it, or NULL in case of memory allocation error or if the highest
1148 * possible stream ID was reached.
1149 */
1150__maybe_unused
1151static struct qcs *qcc_bck_stream_new_uni(struct qcc *qcc,
1152 struct conn_stream *cs, struct session *sess)
1153{
1154 return qcc_bck_stream_new(qcc, QCS_UNI, cs, sess);
1155}
1156
1157
1158/* wake a specific stream and assign its conn_stream some CS_FL_* flags among
1159 * CS_FL_ERR_PENDING and CS_FL_ERROR if needed. The stream's state
1160 * is automatically updated accordingly. If the stream is orphaned, it is
1161 * destroyed.
1162 */
1163static void qcs_wake_one_stream(struct qcs *qcs)
1164{
1165 struct qcc *qcc = qcs->qcc;
1166
1167 TRACE_ENTER(QC_EV_QCS_WAKE, qcc->conn, qcs);
1168 if (!qcs->cs) {
1169 /* this stream was already orphaned */
1170 qcs_destroy(qcs);
1171 TRACE_DEVEL("leaving with no qcs", QC_EV_QCS_WAKE, qcc->conn);
1172 return;
1173 }
1174 /* XXX TO DO XXX */
1175 TRACE_LEAVE(QC_EV_QCS_WAKE, qcc->conn);
1176}
1177
1178/* wake the streams attached to the connection, whose id is greater than <last>
1179 * or unassigned.
1180 */
1181static void qc_wake_some_streams(struct qcc *qcc, int last)
1182{
1183 struct eb64_node *node;
1184 struct qcs *qcs;
1185
1186 TRACE_ENTER(QC_EV_QCS_WAKE, qcc->conn);
1187
1188 /* Wake all streams with ID > last */
1189 node = eb64_lookup_ge(&qcc->streams_by_id, last + 1);
1190 while (node) {
1191 qcs = container_of(node, struct qcs, by_id);
1192 node = eb64_next(node);
1193 qcs_wake_one_stream(qcs);
1194 }
1195
1196 /* Wake all streams with unassigned ID (ID == 0) */
1197 node = eb64_lookup(&qcc->streams_by_id, 0);
1198 while (node) {
1199 qcs = container_of(node, struct qcs, by_id);
1200 if (qcs->id > 0)
1201 break;
1202 node = eb64_next(node);
1203 qcs_wake_one_stream(qcs);
1204 }
1205
1206 TRACE_LEAVE(QC_EV_QCS_WAKE, qcc->conn);
1207}
1208
1209/* Wake up all blocked streams whose window size has become positive after the
1210 * mux's initial window was adjusted. This should be done after having processed
1211 * SETTINGS frames which have updated the mux's initial window size.
1212 */
1213__maybe_unused
1214static void qcc_unblock_sfctl(struct qcc *qcc)
1215{
1216 TRACE_ENTER(QC_EV_QCC_WAKE, qcc->conn);
1217 /* XXX TO DO XXX */
1218 TRACE_LEAVE(QC_EV_QCC_WAKE, qcc->conn);
1219}
1220
1221/* process Rx frames to be demultiplexed */
1222__maybe_unused
1223static void qc_process_demux(struct qcc *qcc)
1224{
1225 TRACE_ENTER(QC_EV_QCC_WAKE, qcc->conn);
1226 /* XXX TO DO XXX */
1227 TRACE_LEAVE(QC_EV_QCC_WAKE, qcc->conn);
1228}
1229
1230/* resume each qcs eligible for sending in list head <head> */
1231__maybe_unused
1232static void qc_resume_each_sending_qcs(struct qcc *qcc, struct list *head)
1233{
1234 struct qcs *qcs, *qcs_back;
1235
1236 TRACE_ENTER(QC_EV_QCC_SEND|QC_EV_QCS_WAKE, qcc->conn);
1237
1238 list_for_each_entry_safe(qcs, qcs_back, head, list) {
1239 if (qcc_wnd(qcc) <= 0 ||
1240 qcc->flags & QC_CF_MUX_BLOCK_ANY ||
1241 qcc->st0 >= QC_CS_ERROR)
1242 break;
1243
1244 qcs->flags &= ~QC_SF_BLK_ANY;
1245
1246 if (qcs->flags & QC_SF_NOTIFIED)
1247 continue;
1248
1249 /* If the sender changed his mind and unsubscribed, let's just
1250 * remove the stream from the send_list.
1251 */
1252 if (!(qcs->flags & (QC_SF_WANT_SHUTR|QC_SF_WANT_SHUTW)) &&
1253 (!qcs->subs || !(qcs->subs->events & SUB_RETRY_SEND))) {
1254 LIST_DEL_INIT(&qcs->list);
1255 continue;
1256 }
1257
1258 if (qcs->subs && qcs->subs->events & SUB_RETRY_SEND) {
1259 qcs->flags |= QC_SF_NOTIFIED;
1260 tasklet_wakeup(qcs->subs->tasklet);
1261 qcs->subs->events &= ~SUB_RETRY_SEND;
1262 if (!qcs->subs->events)
1263 qcs->subs = NULL;
1264 }
1265 else if (qcs->flags & (QC_SF_WANT_SHUTR|QC_SF_WANT_SHUTW)) {
1266 tasklet_wakeup(qcs->shut_tl);
1267 }
1268 }
1269
1270 TRACE_LEAVE(QC_EV_QCC_SEND|QC_EV_QCS_WAKE, qcc->conn);
1271}
1272
1273/* process Tx frames from streams to be multiplexed. Returns > 0 if it reached
1274 * the end.
1275 */
1276__maybe_unused
1277static int qc_process_mux(struct qcc *qcc)
1278{
1279 TRACE_ENTER(QC_EV_QCC_WAKE, qcc->conn);
Frédéric Lécaille1d402402021-09-20 17:53:17 +02001280
1281 /* First we always process the flow control list because the streams
1282 * waiting there were already elected for immediate emission but were
1283 * blocked just on this.
1284 */
1285 qc_resume_each_sending_qcs(qcc, &qcc->fctl_list);
1286 qc_resume_each_sending_qcs(qcc, &qcc->send_list);
1287
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001288 TRACE_LEAVE(QC_EV_QCC_WAKE, qcc->conn);
Frédéric Lécaille1d402402021-09-20 17:53:17 +02001289 return 1;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001290}
1291
1292
1293/* Attempt to read data, and subscribe if none available.
1294 * The function returns 1 if data has been received, otherwise zero.
1295 */
1296__maybe_unused
1297static int qc_recv(struct qcc *qcc)
1298{
1299 TRACE_ENTER(QC_EV_QCC_RECV, qcc->conn);
1300 /* XXX TO DO XXX */
1301 TRACE_LEAVE(QC_EV_QCC_RECV, qcc->conn);
1302 return 0;
1303}
1304
Frédéric Lécaille578a7892021-09-13 16:13:00 +02001305static int qcs_push_frame(struct qcs *qcs, struct buffer *payload, int fin, uint64_t offset)
1306{
1307 struct quic_frame *frm;
1308 struct buffer *buf = &qcs->tx.buf;
1309 struct quic_enc_level *qel = &qcs->qcc->conn->qc->els[QUIC_TLS_ENC_LEVEL_APP];
Frédéric Lécailled2ba0962021-09-20 17:50:03 +02001310 int total = 0, to_xfer;
Frédéric Lécaille578a7892021-09-13 16:13:00 +02001311
1312 qc_get_buf(qcs->qcc, buf);
Frédéric Lécailled2ba0962021-09-20 17:50:03 +02001313 to_xfer = QUIC_MIN(b_data(payload), b_room(buf));
1314 if (!to_xfer)
1315 goto out;
1316
Frédéric Lécaille578a7892021-09-13 16:13:00 +02001317 frm = pool_zalloc(pool_head_quic_frame);
1318 if (!frm)
1319 goto err;
1320
Frédéric Lécailled2ba0962021-09-20 17:50:03 +02001321 total = b_force_xfer(buf, payload, to_xfer);
1322 fin = fin && !b_data(payload);
Frédéric Lécaille578a7892021-09-13 16:13:00 +02001323 frm->type = QUIC_FT_STREAM_8;
1324 if (fin)
1325 frm->type |= QUIC_STREAM_FRAME_TYPE_FIN_BIT;
1326 if (offset) {
1327 frm->type |= QUIC_STREAM_FRAME_TYPE_OFF_BIT;
1328 frm->stream.offset.key = offset;
1329 }
1330 frm->stream.qcs = qcs;
1331 frm->stream.buf = buf;
1332 frm->stream.id = qcs->by_id.key;
1333 if (total) {
1334 frm->type |= QUIC_STREAM_FRAME_TYPE_LEN_BIT;
1335 frm->stream.len = total;
1336 }
1337
1338 MT_LIST_APPEND(&qel->pktns->tx.frms, &frm->mt_list);
Frédéric Lécailled2ba0962021-09-20 17:50:03 +02001339 out:
Frédéric Lécaille578a7892021-09-13 16:13:00 +02001340 fprintf(stderr, "%s: total=%d fin=%d offset=%lu\n", __func__, total, fin, offset);
1341 return total;
1342
1343 err:
1344 return -1;
1345}
1346
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001347/* Try to send data if possible.
1348 * The function returns 1 if data have been sent, otherwise zero.
1349 */
1350static int qc_send(struct qcc *qcc)
1351{
Frédéric Lécaille578a7892021-09-13 16:13:00 +02001352 struct qcs *qcs;
1353 struct eb64_node *node;
Frédéric Lécaille8526f142021-09-20 17:58:22 +02001354 int ret, done;
Frédéric Lécaille578a7892021-09-13 16:13:00 +02001355
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001356 TRACE_ENTER(QC_EV_QCC_SEND, qcc->conn);
Frédéric Lécaille8526f142021-09-20 17:58:22 +02001357 ret = done = 0;
1358 /* fill as much as we can into the current buffer */
1359 while (((qcc->flags & (QC_CF_MUX_MFULL|QC_CF_MUX_MALLOC)) == 0) && !done)
1360 done = qc_process_mux(qcc);
1361
Frédéric Lécaille578a7892021-09-13 16:13:00 +02001362 /* TODO simple loop through all streams and check if there is frames to
1363 * send
1364 */
1365 node = eb64_first(&qcc->streams_by_id);
1366 while (node) {
1367 struct buffer *buf;
1368 qcs = container_of(node, struct qcs, by_id);
Frédéric Lécaille8526f142021-09-20 17:58:22 +02001369 for (buf = br_head(qcs->tx.mbuf); b_size(buf); buf = br_del_head(qcs->tx.mbuf)) {
Frédéric Lécaille578a7892021-09-13 16:13:00 +02001370 if (b_data(buf)) {
Frédéric Lécaille578a7892021-09-13 16:13:00 +02001371 char fin = 0;
1372
1373 /* if FIN is activated, ensure the buffer to
1374 * send is the last
1375 */
1376 if (qcs->flags & QC_SF_FIN_STREAM) {
1377 BUG_ON(qcs->tx.left < b_data(buf));
1378 fin = !(qcs->tx.left - b_data(buf));
1379 }
1380
1381 ret = qcs_push_frame(qcs, buf, fin, qcs->tx.offset);
Frédéric Lécaille8526f142021-09-20 17:58:22 +02001382 if (ret < 0)
Frédéric Lécaille578a7892021-09-13 16:13:00 +02001383 ABORT_NOW();
1384
1385 qcs->tx.left -= ret;
1386 qcs->tx.offset += ret;
Frédéric Lécaille8526f142021-09-20 17:58:22 +02001387 if (b_data(buf)) {
1388 qcc->conn->xprt->subscribe(qcc->conn, qcc->conn->xprt_ctx,
1389 SUB_RETRY_SEND, &qcc->wait_event);
1390 break;
1391 }
Frédéric Lécaille578a7892021-09-13 16:13:00 +02001392 }
1393 b_free(buf);
1394 }
1395 node = eb64_next(node);
1396 }
Frédéric Lécaille8526f142021-09-20 17:58:22 +02001397 if (ret > 0)
1398 tasklet_wakeup(((struct ssl_sock_ctx *)(qcc->conn->xprt_ctx))->wait_event.tasklet);
1399
Frédéric Lécaille578a7892021-09-13 16:13:00 +02001400
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001401 TRACE_LEAVE(QC_EV_QCC_SEND, qcc->conn);
1402 return 0;
1403}
1404
1405/* this is the tasklet referenced in qcc->wait_event.tasklet */
1406static struct task *qc_io_cb(struct task *t, void *ctx, unsigned int status)
1407{
1408 struct connection *conn;
1409 struct tasklet *tl = (struct tasklet *)t;
1410 int conn_in_list;
1411 struct qcc *qcc;
1412 int ret = 0;
1413
1414
1415 HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
1416 if (t->context == NULL) {
1417 /* The connection has been taken over by another thread,
1418 * we're no longer responsible for it, so just free the
1419 * tasklet, and do nothing.
1420 */
1421 HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
1422 tasklet_free(tl);
1423 goto leave;
1424 }
1425 qcc = ctx;
1426 conn = qcc->conn;
1427
1428 TRACE_ENTER(QC_EV_QCC_WAKE, conn);
1429
1430 conn_in_list = conn->flags & CO_FL_LIST_MASK;
1431
1432 /* Remove the connection from the list, to be sure nobody attempts
1433 * to use it while we handle the I/O events
1434 */
1435 if (conn_in_list)
1436 conn_delete_from_tree(&conn->hash_node->node);
1437
1438 HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
1439
1440 if (!(qcc->wait_event.events & SUB_RETRY_SEND))
1441 ret = qc_send(qcc);
1442#if 0
1443 if (!(qcc->wait_event.events & SUB_RETRY_RECV))
1444 ret |= qc_recv(qcc);
1445#endif
1446 // TODO redefine the proper condition here
1447 //if (ret || qcc->rx.inmux)
1448 ret = qc_process(qcc);
1449
1450 /* If we were in an idle list, we want to add it back into it,
1451 * unless qc_process() returned -1, which mean it has destroyed
1452 * the connection (testing !ret is enough, if qc_process() wasn't
1453 * called then ret will be 0 anyway.
1454 */
1455 if (!ret && conn_in_list) {
1456 struct server *srv = objt_server(conn->target);
1457
1458 HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
1459 if (conn_in_list == CO_FL_SAFE_LIST)
1460 ebmb_insert(&srv->per_thr[tid].safe_conns,
1461 &conn->hash_node->node, sizeof(conn->hash_node->hash));
1462 else
1463 ebmb_insert(&srv->per_thr[tid].idle_conns,
1464 &conn->hash_node->node, sizeof(conn->hash_node->hash));
1465 HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
1466 }
1467
1468leave:
1469 TRACE_LEAVE(QC_EV_QCC_WAKE);
1470 return NULL;
1471}
1472
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001473/* callback called on any event by the connection handler.
1474 * It applies changes and returns zero, or < 0 if it wants immediate
1475 * destruction of the connection (which normally doesn not happen in quic).
1476 */
1477static int qc_process(struct qcc *qcc)
1478{
1479 struct connection *conn = qcc->conn;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001480
1481 TRACE_ENTER(QC_EV_QCC_WAKE, conn);
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001482 TRACE_LEAVE(QC_EV_QCC_WAKE, conn);
1483 return 0;
1484}
1485
1486/* wake-up function called by the connection layer (mux_ops.wake) */
1487static int qc_wake(struct connection *conn)
1488{
1489 struct qcc *qcc = conn->ctx;
1490 int ret;
1491
1492 TRACE_ENTER(QC_EV_QCC_WAKE, conn);
1493 ret = qc_process(qcc);
1494 if (ret >= 0)
1495 qc_wake_some_streams(qcc, 0);
1496 TRACE_LEAVE(QC_EV_QCC_WAKE);
1497 return ret;
1498}
1499
1500/* Connection timeout management. The principle is that if there's no receipt
1501 * nor sending for a certain amount of time, the connection is closed. If the
1502 * MUX buffer still has lying data or is not allocatable, the connection is
1503 * immediately killed. If it's allocatable and empty, we attempt to send a
1504 * GOAWAY frame.
1505 */
1506static struct task *qc_timeout_task(struct task *t, void *context, unsigned int state)
1507{
1508 TRACE_ENTER(QC_EV_QCC_WAKE);
1509 /* XXX TO DO XXX */
1510 TRACE_LEAVE(QC_EV_QCC_WAKE);
1511 return NULL;
1512}
1513
1514
1515/*******************************************/
1516/* functions below are used by the streams */
1517/*******************************************/
1518
1519/*
1520 * Attach a new stream to a connection
1521 * (Used for outgoing connections)
1522 */
1523static struct conn_stream *qc_attach(struct connection *conn, struct session *sess)
1524{
1525 struct conn_stream *cs;
1526 struct qcs *qcs;
1527 struct qcc *qcc = conn->ctx;
1528
1529 TRACE_ENTER(QC_EV_QCS_NEW, conn);
1530 cs = cs_new(conn, conn->target);
1531 if (!cs) {
1532 TRACE_DEVEL("leaving on CS allocation failure", QC_EV_QCS_NEW|QC_EV_QCS_ERR, conn);
1533 return NULL;
1534 }
1535 qcs = qcc_bck_stream_new(qcc, QCS_BIDI, cs, sess);
1536 if (!qcs) {
1537 TRACE_DEVEL("leaving on stream creation failure", QC_EV_QCS_NEW|QC_EV_QCS_ERR, conn);
1538 cs_free(cs);
1539 return NULL;
1540 }
1541 TRACE_LEAVE(QC_EV_QCS_NEW, conn, qcs);
1542 return cs;
1543}
1544
1545/* Retrieves the first valid conn_stream from this connection, or returns NULL.
1546 * We have to scan because we may have some orphan streams. It might be
1547 * beneficial to scan backwards from the end to reduce the likeliness to find
1548 * orphans.
1549 */
1550static const struct conn_stream *qc_get_first_cs(const struct connection *conn)
1551{
1552 struct qcc *qcc = conn->ctx;
1553 struct qcs *qcs;
1554 struct eb64_node *node;
1555
1556 node = eb64_first(&qcc->streams_by_id);
1557 while (node) {
1558 qcs = container_of(node, struct qcs, by_id);
1559 if (qcs->cs)
1560 return qcs->cs;
1561 node = eb64_next(node);
1562 }
1563 return NULL;
1564}
1565
1566static int qc_ctl(struct connection *conn, enum mux_ctl_type mux_ctl, void *output)
1567{
1568 int ret = 0;
1569 struct qcc *qcc = conn->ctx;
1570
1571 switch (mux_ctl) {
1572 case MUX_STATUS:
1573 /* Only consider the mux to be ready if we had no error. */
1574 if (qcc->st0 < QC_CS_ERROR)
1575 ret |= MUX_STATUS_READY;
1576 return ret;
1577 case MUX_EXIT_STATUS:
1578 return MUX_ES_UNKNOWN;
1579 default:
1580 return -1;
1581 }
1582}
1583
1584/*
1585 * Destroy the mux and the associated connection, if it is no longer used
1586 */
1587static void qc_destroy(void *ctx)
1588{
1589 struct qcc *qcc = ctx;
1590
1591 TRACE_ENTER(QC_EV_QCC_END, qcc->conn);
1592 if (eb_is_empty(&qcc->streams_by_id) || !qcc->conn || qcc->conn->ctx != qcc)
1593 qc_release(qcc);
1594 TRACE_LEAVE(QC_EV_QCC_END);
1595}
1596
1597/*
1598 * Detach the stream from the connection and possibly release the connection.
1599 */
1600static void qc_detach(struct conn_stream *cs)
1601{
1602 struct qcs *qcs = cs->ctx;
Amaury Denoyellecd28b272021-09-22 14:48:32 +02001603 struct qcc *qcc = qcs->qcc;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001604
1605 TRACE_ENTER(QC_EV_STRM_END, qcs ? qcs->qcc->conn : NULL, qcs);
Amaury Denoyellecd28b272021-09-22 14:48:32 +02001606 qcs_destroy(qcs);
1607 if (eb_is_empty(&qcc->streams_by_id))
1608 qc_release(qcc);
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001609 TRACE_LEAVE(QC_EV_STRM_END, qcs ? qcs->qcc->conn : NULL);
1610}
1611
1612/* Performs a synchronous or asynchronous shutr(). */
1613static void qc_do_shutr(struct qcs *qcs)
1614{
1615 struct qcc *qcc = qcs->qcc;
1616
1617 TRACE_ENTER(QC_EV_STRM_SHUT, qcc->conn, qcs);
1618 /* XXX TO DO XXX */
1619 TRACE_LEAVE(QC_EV_STRM_SHUT, qcc->conn, qcs);
1620 return;
1621}
1622
1623/* Performs a synchronous or asynchronous shutw(). */
1624static void qc_do_shutw(struct qcs *qcs)
1625{
1626 struct qcc *qcc = qcs->qcc;
1627
1628 TRACE_ENTER(QC_EV_STRM_SHUT, qcc->conn, qcs);
1629 /* XXX TO DO XXX */
1630 TRACE_LEAVE(QC_EV_STRM_SHUT, qcc->conn, qcs);
1631 return;
1632}
1633
1634/* This is the tasklet referenced in qcs->shut_tl, it is used for
1635 * deferred shutdowns when the qc_detach() was done but the mux buffer was full
1636 * and prevented the last frame from being emitted.
1637 */
1638static struct task *qc_deferred_shut(struct task *t, void *ctx, unsigned int state)
1639{
1640 struct qcs *qcs = ctx;
1641 struct qcc *qcc = qcs->qcc;
1642
1643 TRACE_ENTER(QC_EV_STRM_SHUT, qcc->conn, qcs);
1644
1645 if (qcs->flags & QC_SF_NOTIFIED) {
1646 /* some data processing remains to be done first */
1647 goto end;
1648 }
1649
1650 if (qcs->flags & QC_SF_WANT_SHUTW)
1651 qc_do_shutw(qcs);
1652
1653 if (qcs->flags & QC_SF_WANT_SHUTR)
1654 qc_do_shutr(qcs);
1655
1656 if (!(qcs->flags & (QC_SF_WANT_SHUTR|QC_SF_WANT_SHUTW))) {
1657 /* We're done trying to send, remove ourself from the send_list */
1658 LIST_DEL_INIT(&qcs->list);
1659
1660 if (!qcs->cs) {
1661 qcs_destroy(qcs);
1662 if (qcc_is_dead(qcc))
1663 qc_release(qcc);
1664 }
1665 }
1666
1667 end:
1668 TRACE_LEAVE(QC_EV_STRM_SHUT);
1669 return NULL;
1670}
1671
1672/* shutr() called by the conn_stream (mux_ops.shutr) */
1673static void qc_shutr(struct conn_stream *cs, enum cs_shr_mode mode)
1674{
1675
1676 struct qcs *qcs = cs->ctx;
1677
1678 TRACE_ENTER(QC_EV_STRM_SHUT, qcs->qcc->conn, qcs);
1679 if (cs->flags & CS_FL_KILL_CONN)
1680 qcs->flags |= QC_SF_KILL_CONN;
1681
1682 if (mode)
1683 qc_do_shutr(qcs);
1684
1685 TRACE_LEAVE(QC_EV_STRM_SHUT, qcs->qcc->conn, qcs);
1686}
1687
1688/* shutw() called by the conn_stream (mux_ops.shutw) */
1689static void qc_shutw(struct conn_stream *cs, enum cs_shw_mode mode)
1690{
1691 struct qcs *qcs = cs->ctx;
1692
1693 TRACE_ENTER(QC_EV_STRM_SHUT, qcs->qcc->conn, qcs);
1694 if (cs->flags & CS_FL_KILL_CONN)
1695 qcs->flags |= QC_SF_KILL_CONN;
1696
1697 qc_do_shutw(qcs);
1698 TRACE_LEAVE(QC_EV_STRM_SHUT, qcs->qcc->conn, qcs);
1699}
1700
1701/* Called from the upper layer, to subscribe <es> to events <event_type>. The
1702 * event subscriber <es> is not allowed to change from a previous call as long
1703 * as at least one event is still subscribed. The <event_type> must only be a
1704 * combination of SUB_RETRY_RECV and SUB_RETRY_SEND. It always returns 0.
1705 */
1706static int qc_subscribe(struct conn_stream *cs, int event_type, struct wait_event *es)
1707{
1708 struct qcs *qcs = cs->ctx;
1709 struct qcc *qcc = qcs->qcc;
1710
1711 TRACE_ENTER(QC_EV_STRM_SEND|QC_EV_STRM_RECV, qcc->conn, qcs);
1712
1713 BUG_ON(event_type & ~(SUB_RETRY_SEND|SUB_RETRY_RECV));
1714 BUG_ON(qcs->subs && qcs->subs != es);
1715
1716 es->events |= event_type;
1717 qcs->subs = es;
1718
1719 if (event_type & SUB_RETRY_RECV)
1720 TRACE_DEVEL("subscribe(recv)", QC_EV_STRM_RECV, qcc->conn, qcs);
1721
1722 if (event_type & SUB_RETRY_SEND) {
1723 TRACE_DEVEL("subscribe(send)", QC_EV_STRM_SEND, qcc->conn, qcs);
1724 if (!(qcs->flags & QC_SF_BLK_SFCTL) &&
1725 !LIST_INLIST(&qcs->list)) {
1726 if (qcs->flags & QC_SF_BLK_MFCTL)
1727 LIST_APPEND(&qcc->fctl_list, &qcs->list);
1728 else
1729 LIST_APPEND(&qcc->send_list, &qcs->list);
1730 }
1731 }
1732 TRACE_LEAVE(QC_EV_STRM_SEND|QC_EV_STRM_RECV, qcc->conn, qcs);
1733 return 0;
1734}
1735
1736/* Called from the upper layer, to unsubscribe <es> from events <event_type>.
1737 * The <es> pointer is not allowed to differ from the one passed to the
1738 * subscribe() call. It always returns zero.
1739 */
1740static int qc_unsubscribe(struct conn_stream *cs, int event_type, struct wait_event *es)
1741{
1742 struct qcs *qcs = cs->ctx;
1743
1744 TRACE_ENTER(QC_EV_STRM_SEND|QC_EV_STRM_RECV, qcs->qcc->conn, qcs);
1745
1746 BUG_ON(event_type & ~(SUB_RETRY_SEND|SUB_RETRY_RECV));
1747 BUG_ON(qcs->subs && qcs->subs != es);
1748
1749 es->events &= ~event_type;
1750 if (!es->events)
1751 qcs->subs = NULL;
1752
1753 if (event_type & SUB_RETRY_RECV)
1754 TRACE_DEVEL("unsubscribe(recv)", QC_EV_STRM_RECV, qcs->qcc->conn, qcs);
1755
1756 if (event_type & SUB_RETRY_SEND) {
1757 TRACE_DEVEL("subscribe(send)", QC_EV_STRM_SEND, qcs->qcc->conn, qcs);
1758 qcs->flags &= ~QC_SF_NOTIFIED;
1759 if (!(qcs->flags & (QC_SF_WANT_SHUTR | QC_SF_WANT_SHUTW)))
1760 LIST_DEL_INIT(&qcs->list);
1761 }
1762
1763 TRACE_LEAVE(QC_EV_STRM_SEND|QC_EV_STRM_RECV, qcs->qcc->conn, qcs);
1764 return 0;
1765}
1766
1767
1768/* Called from the upper layer, to subscribe <es> to events <event_type>. The
1769 * event subscriber <es> is not allowed to change from a previous call as long
1770 * as at least one event is still subscribed. The <event_type> must only be a
1771 * SUB_RETRY_RECV. It always returns 0.
1772 */
1773static int ruqs_subscribe(struct qcs *qcs, int event_type, struct wait_event *es)
1774{
1775 struct qcc *qcc = qcs->qcc;
1776
1777 TRACE_ENTER(QC_EV_STRM_RECV, qcc->conn, qcs);
1778
1779 BUG_ON(event_type & ~SUB_RETRY_RECV);
1780 BUG_ON(qcs->subs && qcs->subs != es);
1781
1782 es->events |= event_type;
1783 qcs->subs = es;
1784
1785 if (event_type & SUB_RETRY_RECV)
1786 TRACE_DEVEL("subscribe(recv)", QC_EV_STRM_RECV, qcc->conn, qcs);
1787
1788 TRACE_LEAVE(QC_EV_STRM_RECV, qcc->conn, qcs);
1789 return 0;
1790}
1791
1792/* Called from the upper layer, to unsubscribe <es> from events <event_type>.
1793 * The <es> pointer is not allowed to differ from the one passed to the
1794 * subscribe() call. It always returns zero.
1795 */
1796static int ruqs_unsubscribe(struct qcs *qcs, int event_type, struct wait_event *es)
1797{
1798 TRACE_ENTER(QC_EV_STRM_RECV, qcs->qcc->conn, qcs);
1799
1800 BUG_ON(event_type & ~SUB_RETRY_RECV);
1801 BUG_ON(qcs->subs && qcs->subs != es);
1802
1803 es->events &= ~event_type;
1804 if (!es->events)
1805 qcs->subs = NULL;
1806
1807 if (event_type & SUB_RETRY_RECV)
1808 TRACE_DEVEL("unsubscribe(recv)", QC_EV_STRM_RECV, qcs->qcc->conn, qcs);
1809
1810 TRACE_LEAVE(QC_EV_STRM_RECV, qcs->qcc->conn, qcs);
1811 return 0;
1812}
1813
1814/* Called from the upper layer, to subscribe <es> to events <event_type>. The
1815 * event subscriber <es> is not allowed to change from a previous call as long
1816 * as at least one event is still subscribed. The <event_type> must only be
1817 * SUB_RETRY_SEND. It always returns 0.
1818 */
1819static int luqs_subscribe(struct qcs *qcs, int event_type, struct wait_event *es)
1820{
1821 struct qcc *qcc = qcs->qcc;
1822
1823 TRACE_ENTER(QC_EV_STRM_SEND, qcc->conn, qcs);
1824
1825 BUG_ON(event_type & ~SUB_RETRY_SEND);
1826 BUG_ON(qcs->subs && qcs->subs != es);
1827
1828 es->events |= event_type;
1829 qcs->subs = es;
1830
1831 if (event_type & SUB_RETRY_SEND) {
1832 TRACE_DEVEL("subscribe(send)", QC_EV_STRM_SEND, qcc->conn, qcs);
1833 if (!(qcs->flags & QC_SF_BLK_SFCTL) &&
1834 !LIST_INLIST(&qcs->list)) {
1835 if (qcs->flags & QC_SF_BLK_MFCTL)
1836 LIST_APPEND(&qcc->fctl_list, &qcs->list);
1837 else
1838 LIST_APPEND(&qcc->send_list, &qcs->list);
1839 }
1840 }
1841
1842 TRACE_LEAVE(QC_EV_STRM_SEND, qcc->conn, qcs);
1843 return 0;
1844}
1845
1846/* Called from the upper layer, to unsubscribe <es> from events <event_type>.
1847 * The <es> pointer is not allowed to differ from the one passed to the
1848 * subscribe() call. It always returns zero.
1849 */
1850static int luqs_unsubscribe(struct qcs *qcs, int event_type, struct wait_event *es)
1851{
1852 struct qcc *qcc = qcs->qcc;
1853
1854 TRACE_ENTER(QC_EV_STRM_SEND, qcc->conn, qcs);
1855
1856 BUG_ON(event_type & ~SUB_RETRY_SEND);
1857 BUG_ON(qcs->subs && qcs->subs != es);
1858
1859 es->events &= ~event_type;
1860 if (!es->events)
1861 qcs->subs = NULL;
1862
1863 if (event_type & SUB_RETRY_SEND) {
1864 TRACE_DEVEL("subscribe(send)", QC_EV_STRM_SEND, qcc->conn, qcs);
1865 qcs->flags &= ~QC_SF_NOTIFIED;
1866 if (!(qcs->flags & (QC_SF_WANT_SHUTR | QC_SF_WANT_SHUTW)))
1867 LIST_DEL_INIT(&qcs->list);
1868 }
1869
1870 TRACE_LEAVE(QC_EV_STRM_SEND, qcc->conn, qcs);
1871 return 0;
1872}
1873
1874/* Called from the upper layer, to receive data */
1875static size_t qc_rcv_buf(struct conn_stream *cs, struct buffer *buf, size_t count, int flags)
1876{
1877 struct qcs *qcs = cs->ctx;
1878 struct qcc *qcc = qcs->qcc;
1879 int ret;
1880
1881 ret = 0;
1882 TRACE_ENTER(QC_EV_STRM_RECV, qcc->conn, qcs);
1883 /* XXX TO DO XXX */
1884 TRACE_LEAVE(QC_EV_STRM_RECV, qcc->conn, qcs);
1885 return ret;
1886}
1887
1888/* Called from the upper layer, to send data from buffer <buf> for no more than
1889 * <count> bytes. Returns the number of bytes effectively sent. Some status
1890 * flags may be updated on the conn_stream.
1891 */
Amaury Denoyelle26dfd902021-08-24 16:33:53 +02001892size_t qc_snd_buf(struct conn_stream *cs, struct buffer *buf, size_t count, int flags)
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001893{
1894 struct qcs *qcs = cs->ctx;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001895
1896 TRACE_ENTER(QC_EV_QCS_SEND|QC_EV_STRM_SEND, qcs->qcc->conn, qcs);
1897
1898 if (count) {
1899 if (!(qcs->qcc->wait_event.events & SUB_RETRY_SEND))
1900 tasklet_wakeup(qcs->qcc->wait_event.tasklet);
1901 }
1902
1903 TRACE_LEAVE(QC_EV_QCS_SEND|QC_EV_STRM_SEND, qcs->qcc->conn, qcs);
Amaury Denoyelle26dfd902021-08-24 16:33:53 +02001904 return count;
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001905}
1906
1907/* Called from the upper layer, to send data from buffer <buf> for no more than
1908 * <count> bytes. Returns the number of bytes effectively sent. Some status
1909 * flags may be updated on the outgoing uni-stream.
1910 */
1911__maybe_unused
1912static size_t _qcs_snd_buf(struct qcs *qcs, struct buffer *buf, size_t count, int flags)
1913{
1914 size_t total = 0;
1915 struct qcc *qcc = qcs->qcc;
1916 struct buffer *res;
1917 struct quic_tx_frm *frm;
1918
1919 TRACE_ENTER(QC_EV_QCS_SEND|QC_EV_STRM_SEND, qcs->qcc->conn);
1920
1921 if (!count)
1922 goto out;
1923
1924 res = br_tail(qcc->mbuf);
1925 if (!qc_get_buf(qcc, res)) {
1926 qcc->flags |= QC_CF_MUX_MALLOC;
1927 goto out;
1928 }
1929
1930 while (count) {
1931 size_t try, room;
1932
1933 room = b_room(res);
1934 if (!room) {
1935 if ((res = br_tail_add(qcc->mbuf)) != NULL)
1936 continue;
1937
1938 qcc->flags |= QC_CF_MUX_MALLOC;
1939 break;
1940 }
1941
1942 try = count;
1943 if (try > room)
1944 try = room;
1945
1946 total += b_xfer(res, buf, try);
1947 count -= try;
1948 }
1949
1950 if (total) {
1951
Frédéric Lécaille0ad04582021-07-27 14:51:54 +02001952 frm = pool_alloc(pool_head_quic_frame);
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001953 if (!frm) { /* XXX XXX */ }
1954 }
1955
1956 out:
1957 TRACE_LEAVE(QC_EV_QCS_SEND|QC_EV_STRM_SEND, qcs->qcc->conn);
1958 return total;
1959
1960 err:
1961 TRACE_DEVEL("leaving on stream error", QC_EV_QCS_SEND|QC_EV_STRM_SEND, qcs->qcc->conn);
1962 return total;
1963}
1964
1965/* Called from the upper layer, to send data from buffer <buf> for no more than
1966 * <count> bytes. Returns the number of bytes effectively sent. Some status
1967 * flags may be updated on the mux.
1968 */
1969size_t luqs_snd_buf(struct qcs *qcs, struct buffer *buf, size_t count, int flags)
1970{
1971 size_t room, total = 0;
1972 struct qcc *qcc = qcs->qcc;
1973 struct buffer *res;
1974
1975 TRACE_ENTER(QC_EV_QCS_SEND|QC_EV_STRM_SEND, qcs->qcc->conn);
1976 if (!count)
1977 goto out;
1978
1979 res = &qcs->tx.buf;
1980 if (!qc_get_buf(qcc, res)) {
1981 qcc->flags |= QC_CF_MUX_MALLOC;
1982 goto out;
1983 }
1984
1985 room = b_room(res);
1986 if (!room)
1987 goto out;
1988
1989 if (count > room)
1990 count = room;
1991
1992 total += b_xfer(res, buf, count);
Amaury Denoyelle7b1d3d62021-08-27 15:05:29 +02001993 qcs_push_frame(qcs, res, 0, 0);
Frédéric Lécailledfbae762021-02-18 09:59:01 +01001994
1995 out:
1996 TRACE_LEAVE(QC_EV_QCS_SEND|QC_EV_STRM_SEND, qcs->qcc->conn);
1997 return total;
1998
1999 err:
2000 TRACE_DEVEL("leaving on stream error", QC_EV_QCS_SEND|QC_EV_STRM_SEND, qcs->qcc->conn);
2001 return total;
2002}
2003
2004/* for debugging with CLI's "show fd" command */
2005static int qc_show_fd(struct buffer *msg, struct connection *conn)
2006{
2007 struct qcc *qcc = conn->ctx;
2008 struct qcs *qcs = NULL;
2009 struct eb64_node *node;
2010 int fctl_cnt = 0;
2011 int send_cnt = 0;
2012 int tree_cnt = 0;
2013 int orph_cnt = 0;
2014 struct buffer *hmbuf, *tmbuf;
2015
2016 if (!qcc)
2017 return 0;
2018
2019 list_for_each_entry(qcs, &qcc->fctl_list, list)
2020 fctl_cnt++;
2021
2022 list_for_each_entry(qcs, &qcc->send_list, list)
2023 send_cnt++;
2024
2025 qcs = NULL;
2026 node = eb64_first(&qcc->streams_by_id);
2027 while (node) {
2028 qcs = container_of(node, struct qcs, by_id);
2029 tree_cnt++;
2030 if (!qcs->cs)
2031 orph_cnt++;
2032 node = eb64_next(node);
2033 }
2034
2035 hmbuf = br_head(qcc->mbuf);
2036 tmbuf = br_tail(qcc->mbuf);
2037 chunk_appendf(msg, " qcc.st0=%s .flg=0x%04x"
2038 " clt.nb_streams_bidi=%llu srv.nb_streams_bidi=%llu"
2039 " clt.nb_streams_uni=%llu srv.nb_streams_uni=%llu"
2040 " .nbcs=%u .fctl_cnt=%d .send_cnt=%d .tree_cnt=%d"
2041 " .orph_cnt=%d .sub=%d"
2042 " .mbuf=[%u..%u|%u],h=[%u@%p+%u/%u],t=[%u@%p+%u/%u]",
2043 qcc_st_to_str(qcc->st0), qcc->flags,
2044 (unsigned long long)qcc->strms[QCS_CLT_BIDI].nb_streams,
2045 (unsigned long long)qcc->strms[QCS_SRV_BIDI].nb_streams,
2046 (unsigned long long)qcc->strms[QCS_CLT_UNI].nb_streams,
2047 (unsigned long long)qcc->strms[QCS_SRV_UNI].nb_streams,
2048 qcc->nb_cs, fctl_cnt, send_cnt, tree_cnt, orph_cnt,
2049 qcc->wait_event.events,
2050 br_head_idx(qcc->mbuf), br_tail_idx(qcc->mbuf), br_size(qcc->mbuf),
2051 (unsigned int)b_data(hmbuf), b_orig(hmbuf),
2052 (unsigned int)b_head_ofs(hmbuf), (unsigned int)b_size(hmbuf),
2053 (unsigned int)b_data(tmbuf), b_orig(tmbuf),
2054 (unsigned int)b_head_ofs(tmbuf), (unsigned int)b_size(tmbuf));
2055
2056 if (qcs) {
2057 chunk_appendf(msg, " last_qcs=%p .id=%llu rx.st=%s tx.st=%s .flg=0x%04x .rxbuf=%u@%p+%u/%u .cs=%p",
2058 qcs, (unsigned long long)qcs->id,
2059 qcs_rx_st_to_str(qcs->rx.st), qcs_tx_st_to_str(qcs->tx.st), qcs->flags,
2060 (unsigned int)b_data(&qcs->rx.buf), b_orig(&qcs->rx.buf),
2061 (unsigned int)b_head_ofs(&qcs->rx.buf), (unsigned int)b_size(&qcs->rx.buf),
2062 qcs->cs);
2063 if (qcs->cs)
2064 chunk_appendf(msg, " .cs.flg=0x%08x .cs.data=%p",
2065 qcs->cs->flags, qcs->cs->data);
2066 }
2067
2068 return 0;
2069}
2070
2071/* Migrate the the connection to the current thread.
2072 * Return 0 if successful, non-zero otherwise.
2073 * Expected to be called with the old thread lock held.
2074 */
2075static int qc_takeover(struct connection *conn, int orig_tid)
2076{
2077 struct qcc *qcc = conn->ctx;
2078 struct task *task;
2079
2080 if (fd_takeover(conn->handle.fd, conn) != 0)
2081 return -1;
2082
2083 if (conn->xprt->takeover && conn->xprt->takeover(conn, conn->xprt_ctx, orig_tid) != 0) {
2084 /* We failed to takeover the xprt, even if the connection may
2085 * still be valid, flag it as error'd, as we have already
2086 * taken over the fd, and wake the tasklet, so that it will
2087 * destroy it.
2088 */
2089 conn->flags |= CO_FL_ERROR;
2090 tasklet_wakeup_on(qcc->wait_event.tasklet, orig_tid);
2091 return -1;
2092 }
2093
2094 if (qcc->wait_event.events)
2095 qcc->conn->xprt->unsubscribe(qcc->conn, qcc->conn->xprt_ctx,
2096 qcc->wait_event.events, &qcc->wait_event);
2097 /* To let the tasklet know it should free itself, and do nothing else,
2098 * set its context to NULL.
2099 */
2100 qcc->wait_event.tasklet->context = NULL;
2101 tasklet_wakeup_on(qcc->wait_event.tasklet, orig_tid);
2102
2103 task = qcc->task;
2104 if (task) {
2105 task->context = NULL;
2106 qcc->task = NULL;
2107 __ha_barrier_store();
2108 task_kill(task);
2109
Willy Tarreaubeeabf52021-10-01 18:23:30 +02002110 qcc->task = task_new_here();
Frédéric Lécailledfbae762021-02-18 09:59:01 +01002111 if (!qcc->task) {
2112 qc_release(qcc);
2113 return -1;
2114 }
2115
2116 qcc->task->process = qc_timeout_task;
2117 qcc->task->context = qcc;
2118 }
2119
2120 qcc->wait_event.tasklet = tasklet_new();
2121 if (!qcc->wait_event.tasklet) {
2122 qc_release(qcc);
2123 return -1;
2124 }
2125
2126 qcc->wait_event.tasklet->process = qc_io_cb;
2127 qcc->wait_event.tasklet->context = qcc;
2128 qcc->conn->xprt->subscribe(qcc->conn, qcc->conn->xprt_ctx,
2129 SUB_RETRY_RECV, &qcc->wait_event);
2130
2131 return 0;
2132}
2133
2134/****************************************/
2135/* MUX initialization and instantiation */
2136/***************************************/
2137
2138/* The mux operations */
2139static const struct mux_ops qc_ops = {
2140 .init = qc_init,
2141 .wake = qc_wake,
Amaury Denoyelle26dfd902021-08-24 16:33:53 +02002142 //.snd_buf = qc_snd_buf,
2143 .snd_buf = h3_snd_buf,
Frédéric Lécailledfbae762021-02-18 09:59:01 +01002144 .rcv_buf = qc_rcv_buf,
2145 .subscribe = qc_subscribe,
2146 .unsubscribe = qc_unsubscribe,
2147 .ruqs_subscribe = ruqs_subscribe,
2148 .ruqs_unsubscribe = ruqs_unsubscribe,
2149 .luqs_subscribe = luqs_subscribe,
2150 .luqs_unsubscribe = luqs_unsubscribe,
2151 .attach = qc_attach,
2152 .get_first_cs = qc_get_first_cs,
2153 .detach = qc_detach,
2154 .destroy = qc_destroy,
2155 .avail_streams_bidi = qc_avail_streams_bidi,
2156 .avail_streams_uni = qc_avail_streams_uni,
2157 .used_streams = qc_used_streams,
2158 .shutr = qc_shutr,
2159 .shutw = qc_shutw,
2160 .ctl = qc_ctl,
2161 .show_fd = qc_show_fd,
2162 .takeover = qc_takeover,
2163 .flags = MX_FL_CLEAN_ABRT|MX_FL_HTX|MX_FL_HOL_RISK,
2164 .name = "QUIC",
2165};
2166
2167static struct mux_proto_list mux_proto_quic =
2168 { .token = IST("quic"), .mode = PROTO_MODE_HTTP, .side = PROTO_SIDE_BOTH, .mux = &qc_ops };
2169
2170INITCALL1(STG_REGISTER, register_mux_proto, &mux_proto_quic);
2171