blob: f7c38c7460da328b6ede12af436b44bc1aef3907 [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>
Amaury Denoyelledeed7772021-12-03 11:36:46 +01007#include <haproxy/dynbuf.h>
8#include <haproxy/pool.h>
Amaury Denoyelleeb01f592021-10-07 16:44:05 +02009#include <haproxy/ssl_sock-t.h>
Frédéric Lécailledfbae762021-02-18 09:59:01 +010010
Amaury Denoyelledeed7772021-12-03 11:36:46 +010011DECLARE_POOL(pool_head_qcc, "qcc", sizeof(struct qcc));
Frédéric Lécailledfbae762021-02-18 09:59:01 +010012DECLARE_POOL(pool_head_qcs, "qcs", sizeof(struct qcs));
13
Frédéric Lécailledfbae762021-02-18 09:59:01 +010014void quic_mux_transport_params_update(struct qcc *qcc)
15{
Amaury Denoyelledeed7772021-12-03 11:36:46 +010016 struct quic_transport_params *clt_params;
Frédéric Lécailledfbae762021-02-18 09:59:01 +010017
Amaury Denoyelledeed7772021-12-03 11:36:46 +010018 /* Client parameters, params used to TX. */
19 clt_params = &qcc->conn->qc->tx.params;
Frédéric Lécailledfbae762021-02-18 09:59:01 +010020
Amaury Denoyelledeed7772021-12-03 11:36:46 +010021 qcc->tx.max_data = clt_params->initial_max_data;
22 /* Client initiated streams must respect the server flow control. */
23 qcc->strms[QCS_CLT_BIDI].rx.max_data = clt_params->initial_max_stream_data_bidi_local;
24 qcc->strms[QCS_CLT_UNI].rx.max_data = clt_params->initial_max_stream_data_uni;
25
26 /* Server initiated streams must respect the server flow control. */
27 qcc->strms[QCS_SRV_BIDI].max_streams = clt_params->initial_max_streams_bidi;
28 qcc->strms[QCS_SRV_BIDI].tx.max_data = clt_params->initial_max_stream_data_bidi_remote;
29
30 qcc->strms[QCS_SRV_UNI].max_streams = clt_params->initial_max_streams_uni;
31 qcc->strms[QCS_SRV_UNI].tx.max_data = clt_params->initial_max_stream_data_uni;
Frédéric Lécailledfbae762021-02-18 09:59:01 +010032}
33
Amaury Denoyelledeed7772021-12-03 11:36:46 +010034/* Allocate a new QUIC streams with id <id> and type <type>. */
35struct qcs *qcs_new(struct qcc *qcc, uint64_t id, enum qcs_type type)
Frédéric Lécailledfbae762021-02-18 09:59:01 +010036{
Amaury Denoyelledeed7772021-12-03 11:36:46 +010037 struct qcs *qcs;
Frédéric Lécailledfbae762021-02-18 09:59:01 +010038
Amaury Denoyelledeed7772021-12-03 11:36:46 +010039 qcs = pool_alloc(pool_head_qcs);
40 if (!qcs)
41 goto out;
Frédéric Lécailledfbae762021-02-18 09:59:01 +010042
Amaury Denoyellefdbf63e2021-12-16 15:22:30 +010043 fprintf(stderr, "%s: stream ID %lu\n", __func__, id);
Frédéric Lécailledfbae762021-02-18 09:59:01 +010044
Amaury Denoyelledeed7772021-12-03 11:36:46 +010045 qcs->qcc = qcc;
46 qcs->cs = NULL;
47 qcs->flags = QC_SF_NONE;
Frédéric Lécailledfbae762021-02-18 09:59:01 +010048
Amaury Denoyelledeed7772021-12-03 11:36:46 +010049 qcs->by_id.key = id;
50 eb64_insert(&qcc->streams_by_id, &qcs->by_id);
51 qcc->strms[type].nb_streams++;
Frédéric Lécailledfbae762021-02-18 09:59:01 +010052
Amaury Denoyelledeed7772021-12-03 11:36:46 +010053 qcs->rx.buf = BUF_NULL;
54 qcs->rx.offset = 0;
55 qcs->rx.frms = EB_ROOT_UNIQUE;
Frédéric Lécailledfbae762021-02-18 09:59:01 +010056
Amaury Denoyelledeed7772021-12-03 11:36:46 +010057 qcs->tx.buf = BUF_NULL;
58 qcs->tx.xprt_buf = BUF_NULL;
59 qcs->tx.offset = 0;
60 qcs->tx.ack_offset = 0;
61 qcs->tx.acked_frms = EB_ROOT_UNIQUE;
Frédéric Lécailledfbae762021-02-18 09:59:01 +010062
Amaury Denoyelledeed7772021-12-03 11:36:46 +010063 qcs->wait_event.tasklet = NULL;
64 qcs->wait_event.events = 0;
65 qcs->subs = NULL;
66
67 out:
68 return qcs;
Frédéric Lécailledfbae762021-02-18 09:59:01 +010069}
70
Amaury Denoyelledeed7772021-12-03 11:36:46 +010071/* Free a qcs. This function must only be used for unidirectional streams.
72 * Bidirectional streams are released by the upper layer through qc_detach().
Frédéric Lécailledfbae762021-02-18 09:59:01 +010073 */
Amaury Denoyelledeed7772021-12-03 11:36:46 +010074void uni_qcs_free(struct qcs *qcs)
Frédéric Lécailledfbae762021-02-18 09:59:01 +010075{
Amaury Denoyelledeed7772021-12-03 11:36:46 +010076 eb64_delete(&qcs->by_id);
77 pool_free(pool_head_qcs, qcs);
Frédéric Lécailledfbae762021-02-18 09:59:01 +010078}
79
Amaury Denoyelledeed7772021-12-03 11:36:46 +010080struct buffer *qc_get_buf(struct qcs *qcs, struct buffer *bptr)
Frédéric Lécailledfbae762021-02-18 09:59:01 +010081{
Amaury Denoyelledeed7772021-12-03 11:36:46 +010082 struct buffer *buf = b_alloc(bptr);
83 BUG_ON(!buf);
84 return buf;
Frédéric Lécailledfbae762021-02-18 09:59:01 +010085}
86
Amaury Denoyellea3f222d2021-12-06 11:24:00 +010087int qcs_subscribe(struct qcs *qcs, int event_type, struct wait_event *es)
88{
89 fprintf(stderr, "%s\n", __func__);
90
91 BUG_ON(event_type & ~(SUB_RETRY_SEND|SUB_RETRY_RECV));
92 BUG_ON(qcs->subs && qcs->subs != es);
93
94 es->events |= event_type;
95 qcs->subs = es;
96
97 return 0;
98}
99
100void qcs_notify_recv(struct qcs *qcs)
101{
102 if (qcs->subs && qcs->subs->events & SUB_RETRY_RECV) {
103 tasklet_wakeup(qcs->subs->tasklet);
104 qcs->subs->events &= ~SUB_RETRY_RECV;
105 if (!qcs->subs->events)
106 qcs->subs = NULL;
107 }
108}
109
110void qcs_notify_send(struct qcs *qcs)
111{
112 if (qcs->subs && qcs->subs->events & SUB_RETRY_SEND) {
113 tasklet_wakeup(qcs->subs->tasklet);
114 qcs->subs->events &= ~SUB_RETRY_SEND;
115 if (!qcs->subs->events)
116 qcs->subs = NULL;
117 }
118}
119
Amaury Denoyelle2873a312021-12-08 14:42:55 +0100120/* detachs the QUIC stream from its QCC and releases it to the QCS pool. */
121static void qcs_destroy(struct qcs *qcs)
122{
123 fprintf(stderr, "%s: release stream %llu\n", __func__, qcs->by_id.key);
124
125 eb64_delete(&qcs->by_id);
126
127 b_free(&qcs->rx.buf);
128 b_free(&qcs->tx.buf);
129 b_free(&qcs->tx.xprt_buf);
130
131 --qcs->qcc->strms[qcs_id_type(qcs->by_id.key)].nb_streams;
132
133 pool_free(pool_head_qcs, qcs);
134}
135
136static inline int qcc_is_dead(const struct qcc *qcc)
137{
138 fprintf(stderr, "%s: %lu\n", __func__, qcc->strms[QCS_CLT_BIDI].nb_streams);
139
140 if (!qcc->strms[QCS_CLT_BIDI].nb_streams)
141 return 1;
142
143 return 0;
144}
145
146/* release function. This one should be called to free all resources allocated
147 * to the mux.
148 */
149static void qc_release(struct qcc *qcc)
150{
151 struct connection *conn = NULL;
152
153 if (qcc) {
154 /* The connection must be aattached to this mux to be released */
155 if (qcc->conn && qcc->conn->ctx == qcc)
156 conn = qcc->conn;
157
158 if (qcc->wait_event.tasklet)
159 tasklet_free(qcc->wait_event.tasklet);
160
161 pool_free(pool_head_qcc, qcc);
162 }
163
164 if (conn) {
165 conn->mux = NULL;
166 conn->ctx = NULL;
167
168 conn_stop_tracking(conn);
169 conn_full_close(conn);
170 if (conn->destroy_cb)
171 conn->destroy_cb(conn);
172 conn_free(conn);
173 }
174}
175
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200176static int qcs_push_frame(struct qcs *qcs, struct buffer *payload, int fin, uint64_t offset)
177{
178 struct quic_frame *frm;
Amaury Denoyelled3d97c62021-10-05 11:45:58 +0200179 struct buffer *buf = &qcs->tx.xprt_buf;
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200180 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 +0200181 int total = 0, to_xfer;
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200182
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100183 fprintf(stderr, "%s\n", __func__);
184
Amaury Denoyelle1e308ff2021-10-12 18:14:12 +0200185 qc_get_buf(qcs, buf);
Frédéric Lécailled2ba0962021-09-20 17:50:03 +0200186 to_xfer = QUIC_MIN(b_data(payload), b_room(buf));
187 if (!to_xfer)
188 goto out;
189
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200190 frm = pool_zalloc(pool_head_quic_frame);
191 if (!frm)
192 goto err;
193
Frédéric Lécailled2ba0962021-09-20 17:50:03 +0200194 total = b_force_xfer(buf, payload, to_xfer);
Amaury Denoyellefecfa0d2021-12-07 16:50:14 +0100195 /* FIN is positioned only when the buffer has been totally emptied. */
Frédéric Lécailled2ba0962021-09-20 17:50:03 +0200196 fin = fin && !b_data(payload);
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200197 frm->type = QUIC_FT_STREAM_8;
198 if (fin)
199 frm->type |= QUIC_STREAM_FRAME_TYPE_FIN_BIT;
200 if (offset) {
201 frm->type |= QUIC_STREAM_FRAME_TYPE_OFF_BIT;
202 frm->stream.offset.key = offset;
203 }
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100204 frm->stream.qcs = (struct qcs *)qcs;
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200205 frm->stream.buf = buf;
206 frm->stream.id = qcs->by_id.key;
207 if (total) {
208 frm->type |= QUIC_STREAM_FRAME_TYPE_LEN_BIT;
209 frm->stream.len = total;
210 }
211
212 MT_LIST_APPEND(&qel->pktns->tx.frms, &frm->mt_list);
Frédéric Lécailled2ba0962021-09-20 17:50:03 +0200213 out:
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200214 fprintf(stderr, "%s: total=%d fin=%d offset=%lu\n", __func__, total, fin, offset);
215 return total;
216
217 err:
218 return -1;
219}
220
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100221static int qc_send(struct qcc *qcc)
222{
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200223 struct eb64_node *node;
Amaury Denoyellee257d9e2021-12-03 14:39:29 +0100224 int xprt_wake = 0;
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100225 int ret;
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200226
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100227 fprintf(stderr, "%s\n", __func__);
Frédéric Lécaille8526f142021-09-20 17:58:22 +0200228
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200229 /* TODO simple loop through all streams and check if there is frames to
230 * send
231 */
232 node = eb64_first(&qcc->streams_by_id);
233 while (node) {
Amaury Denoyelled3d97c62021-10-05 11:45:58 +0200234 struct qcs *qcs = container_of(node, struct qcs, by_id);
235 struct buffer *buf = &qcs->tx.buf;
236 if (b_data(buf)) {
Amaury Denoyellefecfa0d2021-12-07 16:50:14 +0100237 char fin = qcs->flags & QC_SF_FIN_STREAM;
Amaury Denoyellec2025c12021-12-03 15:03:36 +0100238 ret = qcs_push_frame(qcs, buf, fin, qcs->tx.offset);
Amaury Denoyelled3d97c62021-10-05 11:45:58 +0200239 if (ret < 0)
240 ABORT_NOW();
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200241
Amaury Denoyellee257d9e2021-12-03 14:39:29 +0100242 if (ret > 0) {
Amaury Denoyellea3f222d2021-12-06 11:24:00 +0100243 qcs_notify_send(qcs);
Amaury Denoyelle84ea8dc2021-12-03 14:40:01 +0100244 if (qcs->flags & QC_SF_BLK_MROOM)
245 qcs->flags &= ~QC_SF_BLK_MROOM;
246
Amaury Denoyellee257d9e2021-12-03 14:39:29 +0100247 xprt_wake = 1;
248 }
Amaury Denoyellea543eb12021-10-06 14:53:13 +0200249
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100250 fprintf(stderr, "%s ret=%d\n", __func__, ret);
Amaury Denoyelled3d97c62021-10-05 11:45:58 +0200251 qcs->tx.offset += ret;
Amaury Denoyellea2c58a72021-12-03 14:38:31 +0100252
253 if (b_data(buf)) {
254 qcc->conn->xprt->subscribe(qcc->conn, qcc->conn->xprt_ctx,
255 SUB_RETRY_SEND, &qcc->wait_event);
256 }
Frédéric Lécaille578a7892021-09-13 16:13:00 +0200257 }
258 node = eb64_next(node);
259 }
Frédéric Lécaille8526f142021-09-20 17:58:22 +0200260
Amaury Denoyellee257d9e2021-12-03 14:39:29 +0100261 if (xprt_wake)
262 tasklet_wakeup(((struct ssl_sock_ctx *)(qcc->conn->xprt_ctx))->wait_event.tasklet);
263
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100264 return ret;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100265}
266
Amaury Denoyelle2873a312021-12-08 14:42:55 +0100267static int qc_release_detached_streams(struct qcc *qcc)
268{
269 struct eb64_node *node;
270 int release = 0;
271
272 node = eb64_first(&qcc->streams_by_id);
273 while (node) {
274 struct qcs *qcs = container_of(node, struct qcs, by_id);
275 node = eb64_next(node);
276
277 if (qcs->flags & QC_SF_DETACH) {
Amaury Denoyelle5154e7a2021-12-08 14:51:04 +0100278 if ((!b_data(&qcs->tx.buf) && !b_data(&qcs->tx.xprt_buf)) ||
279 qcc->flags & QC_CF_CC_RECV) {
Amaury Denoyelle2873a312021-12-08 14:42:55 +0100280 qcs_destroy(qcs);
281 release = 1;
282 }
283 else {
284 qcc->conn->xprt->subscribe(qcc->conn, qcc->conn->xprt_ctx,
285 SUB_RETRY_SEND, &qcc->wait_event);
286 }
287 }
288 }
289
290 return release;
291}
292
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100293static struct task *qc_io_cb(struct task *t, void *ctx, unsigned int status)
294{
Amaury Denoyelle769e9ff2021-10-05 11:43:50 +0200295 struct qcc *qcc = ctx;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100296
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100297 fprintf(stderr, "%s\n", __func__);
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100298
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100299 qc_send(qcc);
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100300
Amaury Denoyelle2873a312021-12-08 14:42:55 +0100301 if (qc_release_detached_streams(qcc)) {
302 if (qcc_is_dead(qcc)) {
303 qc_release(qcc);
304 return NULL;
305 }
306 }
307
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100308 return NULL;
309}
310
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100311static int qc_init(struct connection *conn, struct proxy *prx,
312 struct session *sess, struct buffer *input)
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100313{
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100314 struct qcc *qcc;
Amaury Denoyellef3b0ba72021-12-08 15:12:01 +0100315 struct quic_transport_params *srv_params;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100316
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100317 qcc = pool_alloc(pool_head_qcc);
318 if (!qcc)
319 goto fail_no_qcc;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100320
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100321 qcc->conn = conn;
322 conn->ctx = qcc;
323 conn->qc->qcc = qcc;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100324
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100325 qcc->app_ops = NULL;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100326
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100327 qcc->streams_by_id = EB_ROOT_UNIQUE;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100328
Amaury Denoyellef3b0ba72021-12-08 15:12:01 +0100329 /* Server parameters, params used for RX flow control. */
330 srv_params = &conn->qc->rx.params;
331
332 qcc->rx.max_data = srv_params->initial_max_data;
333 qcc->tx.max_data = 0;
334
335 /* Client initiated streams must respect the server flow control. */
336 qcc->strms[QCS_CLT_BIDI].max_streams = srv_params->initial_max_streams_bidi;
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100337 qcc->strms[QCS_CLT_BIDI].nb_streams = 0;
338 qcc->strms[QCS_CLT_BIDI].largest_id = -1;
Amaury Denoyellef3b0ba72021-12-08 15:12:01 +0100339 qcc->strms[QCS_CLT_BIDI].rx.max_data = 0;
340 qcc->strms[QCS_CLT_BIDI].tx.max_data = srv_params->initial_max_stream_data_bidi_remote;
341
342 qcc->strms[QCS_CLT_UNI].max_streams = srv_params->initial_max_streams_uni;
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100343 qcc->strms[QCS_CLT_UNI].nb_streams = 0;
344 qcc->strms[QCS_CLT_UNI].largest_id = -1;
Amaury Denoyellef3b0ba72021-12-08 15:12:01 +0100345 qcc->strms[QCS_CLT_UNI].rx.max_data = 0;
346 qcc->strms[QCS_CLT_UNI].tx.max_data = srv_params->initial_max_stream_data_uni;
347
348 /* Server initiated streams must respect the server flow control. */
349 qcc->strms[QCS_SRV_BIDI].max_streams = 0;
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100350 qcc->strms[QCS_SRV_BIDI].nb_streams = 0;
351 qcc->strms[QCS_SRV_BIDI].largest_id = -1;
Amaury Denoyellef3b0ba72021-12-08 15:12:01 +0100352 qcc->strms[QCS_SRV_BIDI].rx.max_data = srv_params->initial_max_stream_data_bidi_local;
353 qcc->strms[QCS_SRV_BIDI].tx.max_data = 0;
354
355 qcc->strms[QCS_SRV_UNI].max_streams = 0;
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100356 qcc->strms[QCS_SRV_UNI].nb_streams = 0;
357 qcc->strms[QCS_SRV_UNI].largest_id = -1;
Amaury Denoyellef3b0ba72021-12-08 15:12:01 +0100358 qcc->strms[QCS_SRV_UNI].rx.max_data = srv_params->initial_max_stream_data_uni;
359 qcc->strms[QCS_SRV_UNI].tx.max_data = 0;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100360
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100361 qcc->wait_event.tasklet = tasklet_new();
362 if (!qcc->wait_event.tasklet)
363 goto fail_no_tasklet;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100364
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100365 qcc->subs = NULL;
366 qcc->wait_event.tasklet->process = qc_io_cb;
367 qcc->wait_event.tasklet->context = qcc;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100368
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100369 /* init read cycle */
370 tasklet_wakeup(qcc->wait_event.tasklet);
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100371
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100372 return 0;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100373
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100374 fail_no_tasklet:
375 pool_free(pool_head_qcc, qcc);
376 fail_no_qcc:
377 return -1;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100378}
379
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100380static void qc_detach(struct conn_stream *cs)
381{
Amaury Denoyelle916f0ac2021-12-06 16:03:47 +0100382 struct qcs *qcs = cs->ctx;
383 struct qcc *qcc = qcs->qcc;
384
385 fprintf(stderr, "%s: leaving with tx.buf.data=%lu, tx.xprt_buf.data=%lu\n",
386 __func__, b_data(&qcs->tx.buf), b_data(&qcs->tx.xprt_buf));
387
Amaury Denoyelle5154e7a2021-12-08 14:51:04 +0100388 if ((b_data(&qcs->tx.buf) || b_data(&qcs->tx.xprt_buf)) &&
389 !(qcc->flags & QC_CF_CC_RECV)) {
Amaury Denoyelle2873a312021-12-08 14:42:55 +0100390 qcs->flags |= QC_SF_DETACH;
391 return;
392 }
393
Amaury Denoyelle916f0ac2021-12-06 16:03:47 +0100394 qcs_destroy(qcs);
395 if (qcc_is_dead(qcc)) {
396 qc_release(qcc);
397 return;
398 }
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100399}
400
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100401/* Called from the upper layer, to receive data */
402static size_t qc_rcv_buf(struct conn_stream *cs, struct buffer *buf,
403 size_t count, int flags)
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100404{
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100405 /* XXX TODO XXX */
406 fprintf(stderr, "%s\n", __func__);
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100407
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100408 return 0;
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100409}
410
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100411static size_t qc_snd_buf(struct conn_stream *cs, struct buffer *buf,
412 size_t count, int flags)
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100413{
414 struct qcs *qcs = cs->ctx;
415
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100416 fprintf(stderr, "%s\n", __func__);
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100417
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100418 return qcs->qcc->app_ops->snd_buf(cs, buf, count, flags);
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100419}
420
421/* Called from the upper layer, to subscribe <es> to events <event_type>. The
422 * event subscriber <es> is not allowed to change from a previous call as long
423 * as at least one event is still subscribed. The <event_type> must only be a
424 * combination of SUB_RETRY_RECV and SUB_RETRY_SEND. It always returns 0.
425 */
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100426static int qc_subscribe(struct conn_stream *cs, int event_type,
427 struct wait_event *es)
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100428{
Amaury Denoyellea3f222d2021-12-06 11:24:00 +0100429 return qcs_subscribe(cs->ctx, event_type, es);
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100430}
431
432/* Called from the upper layer, to unsubscribe <es> from events <event_type>.
433 * The <es> pointer is not allowed to differ from the one passed to the
434 * subscribe() call. It always returns zero.
435 */
436static int qc_unsubscribe(struct conn_stream *cs, int event_type, struct wait_event *es)
437{
438 struct qcs *qcs = cs->ctx;
439
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100440 BUG_ON(event_type & ~(SUB_RETRY_SEND|SUB_RETRY_RECV));
441 BUG_ON(qcs->subs && qcs->subs != es);
442
443 es->events &= ~event_type;
444 if (!es->events)
445 qcs->subs = NULL;
446
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100447 return 0;
448}
449
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100450static const struct mux_ops qc_ops = {
451 .init = qc_init,
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100452 .detach = qc_detach,
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100453 .rcv_buf = qc_rcv_buf,
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100454 .snd_buf = qc_snd_buf,
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100455 .subscribe = qc_subscribe,
456 .unsubscribe = qc_unsubscribe,
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100457};
458
459static struct mux_proto_list mux_proto_quic =
Amaury Denoyelledeed7772021-12-03 11:36:46 +0100460 { .token = IST("quic"), .mode = PROTO_MODE_HTTP, .side = PROTO_SIDE_FE, .mux = &qc_ops };
Frédéric Lécailledfbae762021-02-18 09:59:01 +0100461
462INITCALL1(STG_REGISTER, register_mux_proto, &mux_proto_quic);