blob: e38464081a2490c52be5092ffc5f5c3fb495fc07 [file] [log] [blame]
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001/*
2 * HTTP/3 protocol processing
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation, version 2.1
7 * exclusively.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
Amaury Denoyelle5c25dc52022-09-30 17:44:15 +020019#include <import/ist.h>
20
21#include <haproxy/api.h>
Frédéric Lécailleccac11f2021-03-03 16:09:02 +010022#include <haproxy/buf.h>
Amaury Denoyelle5c25dc52022-09-30 17:44:15 +020023#include <haproxy/chunk.h>
Amaury Denoyelle99043552021-08-24 15:36:02 +020024#include <haproxy/connection.h>
Frédéric Lécailleccac11f2021-03-03 16:09:02 +010025#include <haproxy/dynbuf.h>
26#include <haproxy/h3.h>
Frédéric Lécaille6f7607e2022-05-25 22:25:37 +020027#include <haproxy/h3_stats.h>
Amaury Denoyelleb49fa1a2021-08-24 15:30:12 +020028#include <haproxy/http.h>
Amaury Denoyelle5c25dc52022-09-30 17:44:15 +020029#include <haproxy/http-hdr-t.h>
Amaury Denoyelle115ccce2022-08-17 18:02:47 +020030#include <haproxy/http_htx.h>
Amaury Denoyelleb49fa1a2021-08-24 15:30:12 +020031#include <haproxy/htx.h>
Amaury Denoyelle8c6176b2022-05-24 18:16:49 +020032#include <haproxy/intops.h>
Frédéric Lécailleccac11f2021-03-03 16:09:02 +010033#include <haproxy/istbuf.h>
Amaury Denoyelle846cc042022-04-04 16:13:44 +020034#include <haproxy/mux_quic.h>
Frédéric Lécailleccac11f2021-03-03 16:09:02 +010035#include <haproxy/pool.h>
36#include <haproxy/qpack-dec.h>
Amaury Denoyelle15b09612021-08-24 16:20:27 +020037#include <haproxy/qpack-enc.h>
Amaury Denoyelle92fa63f2022-09-30 18:11:13 +020038#include <haproxy/quic_conn-t.h>
Amaury Denoyelle15b09612021-08-24 16:20:27 +020039#include <haproxy/quic_enc.h>
Amaury Denoyelle5c25dc52022-09-30 17:44:15 +020040#include <haproxy/stats-t.h>
Frédéric Lécailleccac11f2021-03-03 16:09:02 +010041#include <haproxy/tools.h>
Amaury Denoyelle016aa932022-05-30 15:49:36 +020042#include <haproxy/trace.h>
Frédéric Lécailleccac11f2021-03-03 16:09:02 +010043
Amaury Denoyelle016aa932022-05-30 15:49:36 +020044/* trace source and events */
45static void h3_trace(enum trace_level level, uint64_t mask,
46 const struct trace_source *src,
47 const struct ist where, const struct ist func,
48 const void *a1, const void *a2, const void *a3, const void *a4);
49
50static const struct trace_event h3_trace_events[] = {
Amaury Denoyelle494512d2022-05-30 15:50:34 +020051#define H3_EV_RX_FRAME (1ULL << 0)
52 { .mask = H3_EV_RX_FRAME, .name = "rx_frame", .desc = "receipt of any H3 frame" },
53#define H3_EV_RX_DATA (1ULL << 1)
54 { .mask = H3_EV_RX_DATA, .name = "rx_data", .desc = "receipt of H3 DATA frame" },
55#define H3_EV_RX_HDR (1ULL << 2)
56 { .mask = H3_EV_RX_HDR, .name = "rx_hdr", .desc = "receipt of H3 HEADERS frame" },
57#define H3_EV_RX_SETTINGS (1ULL << 3)
58 { .mask = H3_EV_RX_SETTINGS, .name = "rx_settings", .desc = "receipt of H3 SETTINGS frame" },
Amaury Denoyellea717eb72022-05-30 15:51:01 +020059#define H3_EV_TX_DATA (1ULL << 4)
60 { .mask = H3_EV_TX_DATA, .name = "tx_data", .desc = "transmission of H3 DATA frame" },
61#define H3_EV_TX_HDR (1ULL << 5)
62 { .mask = H3_EV_TX_HDR, .name = "tx_hdr", .desc = "transmission of H3 HEADERS frame" },
63#define H3_EV_TX_SETTINGS (1ULL << 6)
64 { .mask = H3_EV_TX_SETTINGS, .name = "tx_settings", .desc = "transmission of H3 SETTINGS frame" },
Amaury Denoyelled5581d52022-05-30 15:51:31 +020065#define H3_EV_H3S_NEW (1ULL << 7)
66 { .mask = H3_EV_H3S_NEW, .name = "h3s_new", .desc = "new H3 stream" },
67#define H3_EV_H3S_END (1ULL << 8)
68 { .mask = H3_EV_H3S_END, .name = "h3s_end", .desc = "H3 stream terminated" },
Amaury Denoyelle016aa932022-05-30 15:49:36 +020069 { }
70};
71
72static const struct name_desc h3_trace_lockon_args[4] = {
73 /* arg1 */ { /* already used by the connection */ },
74 /* arg2 */ { .name="qcs", .desc="QUIC stream" },
75 /* arg3 */ { },
76 /* arg4 */ { }
77};
78
79static const struct name_desc h3_trace_decoding[] = {
80#define H3_VERB_CLEAN 1
81 { .name="clean", .desc="only user-friendly stuff, generally suitable for level \"user\"" },
82#define H3_VERB_MINIMAL 2
83 { .name="minimal", .desc="report only qcc/qcs state and flags, no real decoding" },
84 { /* end */ }
85};
86
87struct trace_source trace_h3 = {
88 .name = IST("h3"),
89 .desc = "HTTP/3 transcoder",
90 .arg_def = TRC_ARG1_CONN, /* TRACE()'s first argument is always a connection */
91 .default_cb = h3_trace,
92 .known_events = h3_trace_events,
93 .lockon_args = h3_trace_lockon_args,
94 .decoding = h3_trace_decoding,
95 .report_events = ~0, /* report everything by default */
96};
97
98#define TRACE_SOURCE &trace_h3
99INITCALL1(STG_REGISTER, trace_register_source, TRACE_SOURCE);
100
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100101#if defined(DEBUG_H3)
102#define h3_debug_printf fprintf
103#define h3_debug_hexdump debug_hexdump
104#else
105#define h3_debug_printf(...) do { } while (0)
106#define h3_debug_hexdump(...) do { } while (0)
107#endif
108
Amaury Denoyelle302ecd42022-05-24 15:24:32 +0200109#define H3_CF_SETTINGS_SENT 0x00000001 /* SETTINGS frame already sent on local control stream */
110#define H3_CF_SETTINGS_RECV 0x00000002 /* SETTINGS frame already received on remote control stream */
111#define H3_CF_UNI_CTRL_SET 0x00000004 /* Remote H3 Control stream opened */
112#define H3_CF_UNI_QPACK_DEC_SET 0x00000008 /* Remote QPACK decoder stream opened */
113#define H3_CF_UNI_QPACK_ENC_SET 0x00000010 /* Remote QPACK encoder stream opened */
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100114
115/* Default settings */
Amaury Denoyelle33949392021-08-24 15:16:58 +0200116static uint64_t h3_settings_qpack_max_table_capacity = 0;
117static uint64_t h3_settings_qpack_blocked_streams = 4096;
118static uint64_t h3_settings_max_field_section_size = QUIC_VARINT_8_BYTE_MAX; /* Unlimited */
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100119
Amaury Denoyelle8d1ecac2022-05-24 14:55:43 +0200120struct h3c {
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100121 struct qcc *qcc;
Amaury Denoyelled7010392022-07-13 15:17:29 +0200122 struct qcs *ctrl_strm; /* Control stream */
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100123 enum h3_err err;
124 uint32_t flags;
Amaury Denoyelle9cc47512022-05-24 16:27:41 +0200125
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100126 /* Settings */
127 uint64_t qpack_max_table_capacity;
128 uint64_t qpack_blocked_streams;
129 uint64_t max_field_section_size;
Amaury Denoyelle9cc47512022-05-24 16:27:41 +0200130
Amaury Denoyelle114c9c82022-03-28 14:53:45 +0200131 uint64_t id_goaway; /* stream ID used for a GOAWAY frame */
132
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100133 struct buffer_wait buf_wait; /* wait list for buffer allocations */
Frédéric Lécaille6f7607e2022-05-25 22:25:37 +0200134 /* Stats counters */
135 struct h3_counters *prx_counters;
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100136};
137
Amaury Denoyelle8d1ecac2022-05-24 14:55:43 +0200138DECLARE_STATIC_POOL(pool_head_h3c, "h3c", sizeof(struct h3c));
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100139
Amaury Denoyelle35550642022-05-24 15:14:53 +0200140#define H3_SF_UNI_INIT 0x00000001 /* stream type not parsed for unidirectional stream */
Amaury Denoyellefc99a692022-05-24 15:25:19 +0200141#define H3_SF_UNI_NO_H3 0x00000002 /* unidirectional stream does not carry H3 frames */
Amaury Denoyelled2c5ee62022-12-08 16:54:42 +0100142#define H3_SF_HAVE_CLEN 0x00000004 /* content-length header is present */
Amaury Denoyelle35550642022-05-24 15:14:53 +0200143
Amaury Denoyelle67e92d32022-04-27 18:04:01 +0200144struct h3s {
Amaury Denoyellec0156792022-06-03 15:29:07 +0200145 struct h3c *h3c;
146
Amaury Denoyelle3236a8e2022-05-24 15:24:03 +0200147 enum h3s_t type;
Amaury Denoyelle8d818c62022-08-02 11:32:45 +0200148 enum h3s_st_req st_req; /* only used for request streams */
Amaury Denoyelle48f01bd2022-04-27 15:37:20 +0200149 int demux_frame_len;
150 int demux_frame_type;
Amaury Denoyelle35550642022-05-24 15:14:53 +0200151
Amaury Denoyelled2c5ee62022-12-08 16:54:42 +0100152 unsigned long long body_len; /* known request body length from content-length header if present */
153 unsigned long long data_len; /* total length of all parsed DATA */
154
Amaury Denoyelle35550642022-05-24 15:14:53 +0200155 int flags;
Amaury Denoyelle2fe93ab2022-12-09 15:01:31 +0100156 int err; /* used for stream reset */
Amaury Denoyelle67e92d32022-04-27 18:04:01 +0200157};
158
159DECLARE_STATIC_POOL(pool_head_h3s, "h3s", sizeof(struct h3s));
160
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200161/* Initialize an uni-stream <qcs> by reading its type from <b>.
Amaury Denoyelle35550642022-05-24 15:14:53 +0200162 *
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200163 * Returns the count of consumed bytes or a negative error code.
Amaury Denoyelle35550642022-05-24 15:14:53 +0200164 */
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200165static ssize_t h3_init_uni_stream(struct h3c *h3c, struct qcs *qcs,
166 struct buffer *b)
Amaury Denoyelle35550642022-05-24 15:14:53 +0200167{
168 /* decode unidirectional stream type */
169 struct h3s *h3s = qcs->ctx;
Amaury Denoyelle35550642022-05-24 15:14:53 +0200170 uint64_t type;
171 size_t len = 0, ret;
172
Amaury Denoyelled5581d52022-05-30 15:51:31 +0200173 TRACE_ENTER(H3_EV_H3S_NEW, qcs->qcc->conn, qcs);
174
Amaury Denoyelle35550642022-05-24 15:14:53 +0200175 BUG_ON_HOT(!quic_stream_is_uni(qcs->id) ||
176 h3s->flags & H3_SF_UNI_INIT);
177
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200178 ret = b_quic_dec_int(&type, b, &len);
Amaury Denoyelle35550642022-05-24 15:14:53 +0200179 if (!ret) {
180 ABORT_NOW();
181 }
182
183 switch (type) {
184 case H3_UNI_S_T_CTRL:
185 if (h3c->flags & H3_CF_UNI_CTRL_SET) {
Amaury Denoyelled666d742022-07-13 15:15:58 +0200186 qcc_emit_cc_app(qcs->qcc, H3_STREAM_CREATION_ERROR, 1);
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200187 return -1;
Amaury Denoyelle35550642022-05-24 15:14:53 +0200188 }
189 h3c->flags |= H3_CF_UNI_CTRL_SET;
190 h3s->type = H3S_T_CTRL;
191 break;
192
193 case H3_UNI_S_T_PUSH:
194 /* TODO not supported for the moment */
195 h3s->type = H3S_T_PUSH;
196 break;
197
198 case H3_UNI_S_T_QPACK_DEC:
199 if (h3c->flags & H3_CF_UNI_QPACK_DEC_SET) {
Amaury Denoyelled666d742022-07-13 15:15:58 +0200200 qcc_emit_cc_app(qcs->qcc, H3_STREAM_CREATION_ERROR, 1);
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200201 return -1;
Amaury Denoyelle35550642022-05-24 15:14:53 +0200202 }
203 h3c->flags |= H3_CF_UNI_QPACK_DEC_SET;
204 h3s->type = H3S_T_QPACK_DEC;
Amaury Denoyellefc99a692022-05-24 15:25:19 +0200205 h3s->flags |= H3_SF_UNI_NO_H3;
Amaury Denoyelle35550642022-05-24 15:14:53 +0200206 break;
207
208 case H3_UNI_S_T_QPACK_ENC:
209 if (h3c->flags & H3_CF_UNI_QPACK_ENC_SET) {
Amaury Denoyelled666d742022-07-13 15:15:58 +0200210 qcc_emit_cc_app(qcs->qcc, H3_STREAM_CREATION_ERROR, 1);
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200211 return -1;
Amaury Denoyelle35550642022-05-24 15:14:53 +0200212 }
213 h3c->flags |= H3_CF_UNI_QPACK_ENC_SET;
214 h3s->type = H3S_T_QPACK_ENC;
Amaury Denoyellefc99a692022-05-24 15:25:19 +0200215 h3s->flags |= H3_SF_UNI_NO_H3;
Amaury Denoyelle35550642022-05-24 15:14:53 +0200216 break;
217
218 default:
Amaury Denoyelle849b24f2022-05-24 17:22:07 +0200219 /* draft-ietf-quic-http34 9. Extensions to HTTP/3
220 *
221 * Implementations MUST [...] abort reading on unidirectional
222 * streams that have unknown or unsupported types.
223 */
Amaury Denoyelle663e8722022-12-09 14:58:28 +0100224 qcc_abort_stream_read(qcs);
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200225 return -1;
Amaury Denoyelle35550642022-05-24 15:14:53 +0200226 };
227
228 h3s->flags |= H3_SF_UNI_INIT;
Amaury Denoyelle35550642022-05-24 15:14:53 +0200229
Amaury Denoyelled5581d52022-05-30 15:51:31 +0200230 TRACE_LEAVE(H3_EV_H3S_NEW, qcs->qcc->conn, qcs);
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200231 return len;
Amaury Denoyelle35550642022-05-24 15:14:53 +0200232}
233
Amaury Denoyelle26aa3992022-08-16 17:42:47 +0200234/* Parse a buffer <b> for a <qcs> uni-stream which does not contains H3 frames.
235 * This may be used for QPACK encoder/decoder streams for example. <fin> is set
236 * if this is the last frame of the stream.
Amaury Denoyellefc99a692022-05-24 15:25:19 +0200237 *
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200238 * Returns the number of consumed bytes or a negative error code.
Amaury Denoyellefc99a692022-05-24 15:25:19 +0200239 */
Amaury Denoyelle26aa3992022-08-16 17:42:47 +0200240static ssize_t h3_parse_uni_stream_no_h3(struct qcs *qcs, struct buffer *b, int fin)
Amaury Denoyellefc99a692022-05-24 15:25:19 +0200241{
Amaury Denoyellefc99a692022-05-24 15:25:19 +0200242 struct h3s *h3s = qcs->ctx;
243
244 BUG_ON_HOT(!quic_stream_is_uni(qcs->id) ||
245 !(h3s->flags & H3_SF_UNI_NO_H3));
246
247 switch (h3s->type) {
248 case H3S_T_QPACK_DEC:
Amaury Denoyelle26aa3992022-08-16 17:42:47 +0200249 if (qpack_decode_dec(b, fin, qcs))
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200250 return -1;
Amaury Denoyellefc99a692022-05-24 15:25:19 +0200251 break;
252 case H3S_T_QPACK_ENC:
Amaury Denoyelle26aa3992022-08-16 17:42:47 +0200253 if (qpack_decode_enc(b, fin, qcs))
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200254 return -1;
Amaury Denoyellefc99a692022-05-24 15:25:19 +0200255 break;
Amaury Denoyelle849b24f2022-05-24 17:22:07 +0200256 case H3S_T_UNKNOWN:
Amaury Denoyellefc99a692022-05-24 15:25:19 +0200257 default:
Amaury Denoyelle849b24f2022-05-24 17:22:07 +0200258 /* Unknown stream should be flagged with QC_SF_READ_ABORTED. */
259 ABORT_NOW();
Amaury Denoyellefc99a692022-05-24 15:25:19 +0200260 }
261
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200262 /* TODO adjust return code */
Amaury Denoyellefc99a692022-05-24 15:25:19 +0200263 return 0;
264}
265
Amaury Denoyelle88d5dd12022-05-31 11:44:52 +0200266/* Decode a H3 frame header from <rxbuf> buffer. The frame type is stored in
267 * <ftype> and length in <flen>.
268 *
269 * Returns the size of the H3 frame header. Note that the input buffer is not
270 * consumed.
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100271 */
272static inline size_t h3_decode_frm_header(uint64_t *ftype, uint64_t *flen,
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200273 struct buffer *b)
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100274{
275 size_t hlen;
276
277 hlen = 0;
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200278 if (!b_quic_dec_int(ftype, b, &hlen) ||
279 !b_quic_dec_int(flen, b, &hlen)) {
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100280 return 0;
Amaury Denoyelle88d5dd12022-05-31 11:44:52 +0200281 }
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100282
283 return hlen;
284}
285
Amaury Denoyelle302ecd42022-05-24 15:24:32 +0200286/* Check if H3 frame of type <ftype> is valid when received on stream <qcs>.
287 *
288 * Returns a boolean. If false, a connection error H3_FRAME_UNEXPECTED should
289 * be reported.
290 */
291static int h3_is_frame_valid(struct h3c *h3c, struct qcs *qcs, uint64_t ftype)
292{
293 struct h3s *h3s = qcs->ctx;
294 const uint64_t id = qcs->id;
295
296 BUG_ON_HOT(h3s->type == H3S_T_UNKNOWN);
297
298 switch (ftype) {
299 case H3_FT_DATA:
Amaury Denoyelle8d818c62022-08-02 11:32:45 +0200300 return h3s->type != H3S_T_CTRL && (h3s->st_req == H3S_ST_REQ_HEADERS ||
301 h3s->st_req == H3S_ST_REQ_DATA);
302
Amaury Denoyelle302ecd42022-05-24 15:24:32 +0200303 case H3_FT_HEADERS:
Amaury Denoyelle8d818c62022-08-02 11:32:45 +0200304 return h3s->type != H3S_T_CTRL && h3s->st_req != H3S_ST_REQ_TRAILERS;
Amaury Denoyelle302ecd42022-05-24 15:24:32 +0200305
306 case H3_FT_CANCEL_PUSH:
307 case H3_FT_GOAWAY:
308 case H3_FT_MAX_PUSH_ID:
309 /* Only allowed for control stream. First frame of control
310 * stream MUST be SETTINGS.
311 */
312 return h3s->type == H3S_T_CTRL &&
313 (h3c->flags & H3_CF_SETTINGS_RECV);
314
315 case H3_FT_SETTINGS:
316 /* draft-ietf-quic-http34 7.2.4. SETTINGS
317 *
318 * If an endpoint receives a second SETTINGS frame on the control
319 * stream, the endpoint MUST respond with a connection error of type
320 * H3_FRAME_UNEXPECTED.
321 */
322 return h3s->type == H3S_T_CTRL &&
323 !(h3c->flags & H3_CF_SETTINGS_RECV);
324
325 case H3_FT_PUSH_PROMISE:
326 return h3s->type != H3S_T_CTRL &&
327 (id & QCS_ID_SRV_INTIATOR_BIT);
328
329 default:
330 /* draft-ietf-quic-http34 9. Extensions to HTTP/3
331 *
332 * Implementations MUST discard frames [...] that have unknown
333 * or unsupported types.
334 */
335 return h3s->type != H3S_T_CTRL || (h3c->flags & H3_CF_SETTINGS_RECV);
336 }
337}
338
Amaury Denoyelled2c5ee62022-12-08 16:54:42 +0100339/* Check from stream <qcs> that length of all DATA frames does not exceed with
340 * a previously parsed content-length header. <fin> must be set for the last
341 * data of the stream so that length of DATA frames must be equal to the
342 * content-length.
343 *
344 * This must only be called for a stream with H3_SF_HAVE_CLEN flag.
345 *
346 * Return 0 on valid else non-zero.
347 */
348static int h3_check_body_size(struct qcs *qcs, int fin)
349{
350 struct h3s *h3s = qcs->ctx;
351 int ret = 0;
352 TRACE_ENTER(H3_EV_RX_FRAME, qcs->qcc->conn, qcs);
353
354 /* Reserved for streams with a previously parsed content-length header. */
355 BUG_ON(!(h3s->flags & H3_SF_HAVE_CLEN));
356
357 /* RFC 9114 4.1.2. Malformed Requests and Responses
358 *
359 * A request or response that is defined as having content when it
360 * contains a Content-Length header field (Section 8.6 of [HTTP]) is
361 * malformed if the value of the Content-Length header field does not
362 * equal the sum of the DATA frame lengths received.
363 *
364 * TODO for backend support
365 * A response that is
366 * defined as never having content, even when a Content-Length is
367 * present, can have a non-zero Content-Length header field even though
368 * no content is included in DATA frames.
369 */
370 if (h3s->data_len > h3s->body_len ||
371 (fin && h3s->data_len < h3s->body_len)) {
372 TRACE_ERROR("Content-length does not match DATA frame size", H3_EV_RX_FRAME|H3_EV_RX_DATA, qcs->qcc->conn, qcs);
Amaury Denoyelle2fe93ab2022-12-09 15:01:31 +0100373 h3s->err = H3_MESSAGE_ERROR;
Amaury Denoyelled2c5ee62022-12-08 16:54:42 +0100374 ret = -1;
375 }
376
377 TRACE_LEAVE(H3_EV_RX_FRAME, qcs->qcc->conn, qcs);
378 return ret;
379}
380
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100381/* Parse from buffer <buf> a H3 HEADERS frame of length <len>. Data are copied
Willy Tarreau4596fe22022-05-17 19:07:51 +0200382 * in a local HTX buffer and transfer to the stream connector layer. <fin> must be
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100383 * set if this is the last data to transfer from this stream.
384 *
Amaury Denoyelle2fe93ab2022-12-09 15:01:31 +0100385 * Returns the number of consumed bytes or a negative error code. On error
386 * either the connection should be closed or the stream reset using codes
387 * provided in h3c.err / h3s.err.
Amaury Denoyelleb9ce14e2021-11-08 09:13:42 +0100388 */
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200389static ssize_t h3_headers_to_htx(struct qcs *qcs, const struct buffer *buf,
390 uint64_t len, char fin)
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100391{
Amaury Denoyelle2bc47862022-06-30 10:04:42 +0200392 struct h3s *h3s = qcs->ctx;
393 struct h3c *h3c = h3s->h3c;
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100394 struct buffer htx_buf = BUF_NULL;
395 struct buffer *tmp = get_trash_chunk();
Amaury Denoyelle7059ebc2021-12-08 15:51:04 +0100396 struct htx *htx = NULL;
Amaury Denoyelleb49fa1a2021-08-24 15:30:12 +0200397 struct htx_sl *sl;
Amaury Denoyellefd7cdc32021-08-24 15:13:20 +0200398 struct http_hdr list[global.tune.max_http_hdr];
Amaury Denoyelleb49fa1a2021-08-24 15:30:12 +0200399 unsigned int flags = HTX_SL_F_NONE;
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100400 struct ist meth = IST_NULL, path = IST_NULL;
Amaury Denoyelle7b5a6712022-12-07 14:33:26 +0100401 struct ist scheme = IST_NULL, authority = IST_NULL;
Amaury Denoyelle2bc47862022-06-30 10:04:42 +0200402 int hdr_idx, ret;
Amaury Denoyelled6fb7a02022-12-07 14:31:42 +0100403 int cookie = -1, last_cookie = -1, i;
404
405 /* RFC 9114 4.1.2. Malformed Requests and Responses
406 *
407 * A malformed request or response is one that is an otherwise valid
408 * sequence of frames but is invalid due to:
409 * - the presence of prohibited fields or pseudo-header fields,
410 * - the absence of mandatory pseudo-header fields,
411 * - invalid values for pseudo-header fields,
412 * - pseudo-header fields after fields,
413 * - an invalid sequence of HTTP messages,
414 * - the inclusion of uppercase field names, or
415 * - the inclusion of invalid characters in field names or values.
416 *
417 * [...]
418 *
419 * Intermediaries that process HTTP requests or responses (i.e., any
420 * intermediary not acting as a tunnel) MUST NOT forward a malformed
421 * request or response. Malformed requests or responses that are
422 * detected MUST be treated as a stream error of type H3_MESSAGE_ERROR.
423 */
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100424
Amaury Denoyelle494512d2022-05-30 15:50:34 +0200425 TRACE_ENTER(H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs);
426
Amaury Denoyelle8d818c62022-08-02 11:32:45 +0200427 /* TODO support trailer parsing in this function */
428
Amaury Denoyelle30f23f52022-04-27 14:41:53 +0200429 /* TODO support buffer wrapping */
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200430 BUG_ON(b_head(buf) + len >= b_wrap(buf));
Amaury Denoyelle2bc47862022-06-30 10:04:42 +0200431 ret = qpack_decode_fs((const unsigned char *)b_head(buf), len, tmp,
432 list, sizeof(list) / sizeof(list[0]));
433 if (ret < 0) {
434 TRACE_ERROR("QPACK decoding error", H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs);
435 h3c->err = -ret;
Amaury Denoyelle788fc052022-12-15 10:53:55 +0100436 len = -1;
437 goto out;
Amaury Denoyelle60ef19f2022-06-14 17:38:36 +0200438 }
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100439
440 qc_get_buf(qcs, &htx_buf);
Amaury Denoyelle788fc052022-12-15 10:53:55 +0100441 BUG_ON(!b_size(&htx_buf)); /* TODO */
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100442 htx = htx_from_buf(&htx_buf);
443
444 /* first treat pseudo-header to build the start line */
445 hdr_idx = 0;
446 while (1) {
Amaury Denoyelle7b5a6712022-12-07 14:33:26 +0100447 /* RFC 9114 4.3. HTTP Control Data
448 *
449 * Endpoints MUST treat a request or response that contains
450 * undefined or invalid pseudo-header fields as malformed.
451 *
452 * All pseudo-header fields MUST appear in the header section before
453 * regular header fields. Any request or response that contains a
454 * pseudo-header field that appears in a header section after a regular
455 * header field MUST be treated as malformed.
456 */
457
458 /* Stop at first non pseudo-header. */
459 if (!istmatch(list[hdr_idx].n, ist(":")))
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100460 break;
461
Amaury Denoyelle7b5a6712022-12-07 14:33:26 +0100462 /* pseudo-header. Malformed name with uppercase character or
463 * invalid token will be rejected in the else clause.
464 */
465 if (isteq(list[hdr_idx].n, ist(":method"))) {
466 if (isttest(meth)) {
467 TRACE_ERROR("duplicated method pseudo-header", H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs);
Amaury Denoyelle2fe93ab2022-12-09 15:01:31 +0100468 h3s->err = H3_MESSAGE_ERROR;
Amaury Denoyelle788fc052022-12-15 10:53:55 +0100469 len = -1;
470 goto out;
Amaury Denoyelle7b5a6712022-12-07 14:33:26 +0100471 }
472 meth = list[hdr_idx].v;
473 }
474 else if (isteq(list[hdr_idx].n, ist(":path"))) {
475 if (isttest(path)) {
476 TRACE_ERROR("duplicated path pseudo-header", H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs);
Amaury Denoyelle2fe93ab2022-12-09 15:01:31 +0100477 h3s->err = H3_MESSAGE_ERROR;
Amaury Denoyelle788fc052022-12-15 10:53:55 +0100478 len = -1;
479 goto out;
Amaury Denoyelle7b5a6712022-12-07 14:33:26 +0100480 }
481 path = list[hdr_idx].v;
482 }
483 else if (isteq(list[hdr_idx].n, ist(":scheme"))) {
484 if (isttest(scheme)) {
485 /* duplicated pseudo-header */
486 TRACE_ERROR("duplicated scheme pseudo-header", H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs);
Amaury Denoyelle2fe93ab2022-12-09 15:01:31 +0100487 h3s->err = H3_MESSAGE_ERROR;
Amaury Denoyelle788fc052022-12-15 10:53:55 +0100488 len = -1;
489 goto out;
Amaury Denoyelle7b5a6712022-12-07 14:33:26 +0100490 }
491 scheme = list[hdr_idx].v;
492 }
493 else if (isteq(list[hdr_idx].n, ist(":authority"))) {
494 if (isttest(authority)) {
495 TRACE_ERROR("duplicated authority pseudo-header", H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs);
Amaury Denoyelle2fe93ab2022-12-09 15:01:31 +0100496 h3s->err = H3_MESSAGE_ERROR;
Amaury Denoyelle788fc052022-12-15 10:53:55 +0100497 len = -1;
498 goto out;
Amaury Denoyelle7b5a6712022-12-07 14:33:26 +0100499 }
500 authority = list[hdr_idx].v;
501 }
502 else {
503 TRACE_ERROR("unknown pseudo-header", H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs);
Amaury Denoyelle2fe93ab2022-12-09 15:01:31 +0100504 h3s->err = H3_MESSAGE_ERROR;
Amaury Denoyelle788fc052022-12-15 10:53:55 +0100505 len = -1;
506 goto out;
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100507 }
508
509 ++hdr_idx;
510 }
511
Amaury Denoyelle7b5a6712022-12-07 14:33:26 +0100512 if (!istmatch(meth, ist("CONNECT"))) {
513 /* RFC 9114 4.3.1. Request Pseudo-Header Fields
514 *
515 * All HTTP/3 requests MUST include exactly one value for the :method,
516 * :scheme, and :path pseudo-header fields, unless the request is a
517 * CONNECT request; see Section 4.4.
518 */
519 if (!isttest(meth) || !isttest(scheme) || !isttest(path)) {
520 TRACE_ERROR("missing mandatory pseudo-header", H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs);
Amaury Denoyelle2fe93ab2022-12-09 15:01:31 +0100521 h3s->err = H3_MESSAGE_ERROR;
Amaury Denoyelle788fc052022-12-15 10:53:55 +0100522 len = -1;
523 goto out;
Amaury Denoyelle7b5a6712022-12-07 14:33:26 +0100524 }
525 }
526
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100527 flags |= HTX_SL_F_VER_11;
Amaury Denoyelle0fa14a62022-04-26 16:24:39 +0200528 flags |= HTX_SL_F_XFER_LEN;
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100529
530 sl = htx_add_stline(htx, HTX_BLK_REQ_SL, flags, meth, path, ist("HTTP/3.0"));
Amaury Denoyelle2bc47862022-06-30 10:04:42 +0200531 if (!sl) {
532 h3c->err = H3_INTERNAL_ERROR;
Amaury Denoyelle788fc052022-12-15 10:53:55 +0100533 len = -1;
534 goto out;
Amaury Denoyelle2bc47862022-06-30 10:04:42 +0200535 }
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100536
537 if (fin)
538 sl->flags |= HTX_SL_F_BODYLESS;
539
540 sl->info.req.meth = find_http_meth(meth.ptr, meth.len);
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100541
Amaury Denoyellec4913f62022-12-15 10:58:05 +0100542 if (isttest(authority)) {
543 if (!htx_add_header(htx, ist("host"), authority)) {
544 h3c->err = H3_INTERNAL_ERROR;
545 len = -1;
546 goto out;
547 }
548 }
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100549
550 /* now treat standard headers */
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100551 while (1) {
552 if (isteq(list[hdr_idx].n, ist("")))
553 break;
554
Amaury Denoyelle7b5a6712022-12-07 14:33:26 +0100555 if (istmatch(list[hdr_idx].n, ist(":"))) {
556 TRACE_ERROR("pseudo-header field after fields", H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs);
Amaury Denoyelle2fe93ab2022-12-09 15:01:31 +0100557 h3s->err = H3_MESSAGE_ERROR;
Amaury Denoyelle788fc052022-12-15 10:53:55 +0100558 len = -1;
559 goto out;
Amaury Denoyelle7b5a6712022-12-07 14:33:26 +0100560 }
561
Amaury Denoyelled6fb7a02022-12-07 14:31:42 +0100562 for (i = 0; i < list[hdr_idx].n.len; ++i) {
563 const char c = list[hdr_idx].n.ptr[i];
564 if ((uint8_t)(c - 'A') < 'Z' - 'A' || !HTTP_IS_TOKEN(c)) {
565 TRACE_ERROR("invalid characters in field name", H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs);
Amaury Denoyelle2fe93ab2022-12-09 15:01:31 +0100566 h3s->err = H3_MESSAGE_ERROR;
Amaury Denoyelle788fc052022-12-15 10:53:55 +0100567 len = -1;
568 goto out;
Amaury Denoyelled6fb7a02022-12-07 14:31:42 +0100569 }
570 }
571
Amaury Denoyelle115ccce2022-08-17 18:02:47 +0200572 if (isteq(list[hdr_idx].n, ist("cookie"))) {
573 http_cookie_register(list, hdr_idx, &cookie, &last_cookie);
Amaury Denoyelle19942e32022-12-15 09:18:25 +0100574 ++hdr_idx;
Amaury Denoyelle115ccce2022-08-17 18:02:47 +0200575 continue;
576 }
Amaury Denoyelled2c5ee62022-12-08 16:54:42 +0100577 else if (isteq(list[hdr_idx].n, ist("content-length"))) {
578 ret = http_parse_cont_len_header(&list[hdr_idx].v,
579 &h3s->body_len,
580 h3s->flags & H3_SF_HAVE_CLEN);
581 if (ret < 0) {
582 TRACE_ERROR("invalid content-length", H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs);
Amaury Denoyelle2fe93ab2022-12-09 15:01:31 +0100583 h3s->err = H3_MESSAGE_ERROR;
Amaury Denoyelle788fc052022-12-15 10:53:55 +0100584 len = -1;
585 goto out;
Amaury Denoyelled2c5ee62022-12-08 16:54:42 +0100586 }
587 else if (!ret) {
588 /* Skip duplicated value. */
589 ++hdr_idx;
590 continue;
591 }
592
593 h3s->flags |= H3_SF_HAVE_CLEN;
594 /* This will fail if current frame is the last one and
595 * content-length is not null.
596 */
Amaury Denoyelle788fc052022-12-15 10:53:55 +0100597 if (h3_check_body_size(qcs, fin)) {
598 len = -1;
599 goto out;
600 }
Amaury Denoyelled2c5ee62022-12-08 16:54:42 +0100601 }
Amaury Denoyelle8ad26692023-01-17 17:47:06 +0100602 else if (isteq(list[hdr_idx].n, ist("connection")) ||
603 isteq(list[hdr_idx].n, ist("proxy-connection")) ||
604 isteq(list[hdr_idx].n, ist("keep-alive")) ||
605 isteq(list[hdr_idx].n, ist("transfer-encoding"))) {
606 /* RFC 9114 4.2. HTTP Fields
607 *
608 * HTTP/3 does not use the Connection header field to indicate
609 * connection-specific fields; in this protocol, connection-
610 * specific metadata is conveyed by other means. An endpoint
611 * MUST NOT generate an HTTP/3 field section containing
612 * connection-specific fields; any message containing
613 * connection-specific fields MUST be treated as malformed.
614 */
615 TRACE_ERROR("invalid connection header", H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs);
616 h3s->err = H3_MESSAGE_ERROR;
617 len = -1;
618 goto out;
619 }
620 else if (isteq(list[hdr_idx].n, ist("te")) &&
621 !isteq(list[hdr_idx].v, ist("trailers"))) {
622 /* RFC 9114 4.2. HTTP Fields
623 *
624 * The only exception to this is the TE header field, which MAY
625 * be present in an HTTP/3 request header; when it is, it MUST
626 * NOT contain any value other than "trailers".
627 */
628 TRACE_ERROR("invalid te header", H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs);
629 h3s->err = H3_MESSAGE_ERROR;
630 len = -1;
631 goto out;
632 }
Amaury Denoyelle115ccce2022-08-17 18:02:47 +0200633
Amaury Denoyellec4913f62022-12-15 10:58:05 +0100634 if (!htx_add_header(htx, list[hdr_idx].n, list[hdr_idx].v)) {
635 h3c->err = H3_INTERNAL_ERROR;
636 len = -1;
637 goto out;
638 }
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100639 ++hdr_idx;
640 }
641
Amaury Denoyelle115ccce2022-08-17 18:02:47 +0200642 if (cookie >= 0) {
643 if (http_cookie_merge(htx, list, cookie)) {
644 h3c->err = H3_INTERNAL_ERROR;
Amaury Denoyelle788fc052022-12-15 10:53:55 +0100645 len = -1;
646 goto out;
Amaury Denoyelle115ccce2022-08-17 18:02:47 +0200647 }
648 }
649
Amaury Denoyellec4913f62022-12-15 10:58:05 +0100650 if (!htx_add_endof(htx, HTX_BLK_EOH)) {
651 h3c->err = H3_INTERNAL_ERROR;
652 len = -1;
653 goto out;
654 }
655
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100656 if (fin)
657 htx->flags |= HTX_FL_EOM;
658
Amaury Denoyelle788fc052022-12-15 10:53:55 +0100659 htx_to_buf(htx, &htx_buf);
660 htx = NULL;
661
Amaury Denoyelle2bc47862022-06-30 10:04:42 +0200662 if (!qc_attach_sc(qcs, &htx_buf)) {
663 h3c->err = H3_INTERNAL_ERROR;
Amaury Denoyelle788fc052022-12-15 10:53:55 +0100664 len = -1;
665 goto out;
Amaury Denoyelle2bc47862022-06-30 10:04:42 +0200666 }
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100667
Amaury Denoyelle114c9c82022-03-28 14:53:45 +0200668 /* RFC 9114 5.2. Connection Shutdown
669 *
670 * The GOAWAY frame contains an identifier that
671 * indicates to the receiver the range of requests or pushes that were
672 * or might be processed in this connection. The server sends a client-
673 * initiated bidirectional stream ID; the client sends a push ID.
674 * Requests or pushes with the indicated identifier or greater are
675 * rejected (Section 4.1.1) by the sender of the GOAWAY. This
676 * identifier MAY be zero if no requests or pushes were processed.
677 */
678 if (qcs->id >= h3c->id_goaway)
679 h3c->id_goaway = qcs->id + 4;
680
Amaury Denoyelle788fc052022-12-15 10:53:55 +0100681 out:
682 /* HTX may be non NULL if error before previous htx_to_buf(). */
683 if (htx)
684 htx_to_buf(htx, &htx_buf);
685
Willy Tarreau4596fe22022-05-17 19:07:51 +0200686 /* buffer is transferred to the stream connector and set to NULL
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100687 * except on stream creation error.
688 */
Amaury Denoyelle788fc052022-12-15 10:53:55 +0100689 if (b_size(&htx_buf)) {
690 b_free(&htx_buf);
691 offer_buffers(NULL, 1);
692 }
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100693
Amaury Denoyelle494512d2022-05-30 15:50:34 +0200694 TRACE_LEAVE(H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs);
Amaury Denoyelle314578a2022-04-27 14:52:52 +0200695 return len;
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100696}
697
Amaury Denoyelle91379f72022-02-14 17:14:59 +0100698/* Copy from buffer <buf> a H3 DATA frame of length <len> in QUIC stream <qcs>
699 * HTX buffer. <fin> must be set if this is the last data to transfer from this
700 * stream.
701 *
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200702 * Returns the number of consumed bytes or a negative error code.
Amaury Denoyelle91379f72022-02-14 17:14:59 +0100703 */
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200704static ssize_t h3_data_to_htx(struct qcs *qcs, const struct buffer *buf,
705 uint64_t len, char fin)
Amaury Denoyelle91379f72022-02-14 17:14:59 +0100706{
707 struct buffer *appbuf;
708 struct htx *htx = NULL;
Amaury Denoyelle1290f1e2022-05-13 14:49:05 +0200709 size_t htx_sent = 0;
Amaury Denoyelle91379f72022-02-14 17:14:59 +0100710 int htx_space;
Amaury Denoyelle30f23f52022-04-27 14:41:53 +0200711 char *head;
Amaury Denoyelle91379f72022-02-14 17:14:59 +0100712
Amaury Denoyelle494512d2022-05-30 15:50:34 +0200713 TRACE_ENTER(H3_EV_RX_FRAME|H3_EV_RX_DATA, qcs->qcc->conn, qcs);
714
Amaury Denoyelle91379f72022-02-14 17:14:59 +0100715 appbuf = qc_get_buf(qcs, &qcs->rx.app_buf);
716 BUG_ON(!appbuf);
717 htx = htx_from_buf(appbuf);
718
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200719 if (len > b_data(buf)) {
720 len = b_data(buf);
Amaury Denoyelle48f01bd2022-04-27 15:37:20 +0200721 fin = 0;
722 }
723
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200724 head = b_head(buf);
Amaury Denoyelle30f23f52022-04-27 14:41:53 +0200725 retry:
Amaury Denoyelle91379f72022-02-14 17:14:59 +0100726 htx_space = htx_free_data_space(htx);
Amaury Denoyellef1fc0b32022-05-02 11:07:06 +0200727 if (!htx_space) {
728 qcs->flags |= QC_SF_DEM_FULL;
Amaury Denoyelle48f01bd2022-04-27 15:37:20 +0200729 goto out;
Amaury Denoyellef1fc0b32022-05-02 11:07:06 +0200730 }
Amaury Denoyelle48f01bd2022-04-27 15:37:20 +0200731
732 if (len > htx_space) {
733 len = htx_space;
734 fin = 0;
Amaury Denoyelleff191de2022-02-21 18:38:29 +0100735 }
Amaury Denoyelle91379f72022-02-14 17:14:59 +0100736
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200737 if (head + len > b_wrap(buf)) {
738 size_t contig = b_wrap(buf) - head;
739 htx_sent = htx_add_data(htx, ist2(b_head(buf), contig));
Amaury Denoyelle73d6ffe2022-05-16 13:54:31 +0200740 if (htx_sent < contig) {
741 qcs->flags |= QC_SF_DEM_FULL;
742 goto out;
743 }
744
Amaury Denoyelle30f23f52022-04-27 14:41:53 +0200745 len -= contig;
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200746 head = b_orig(buf);
Amaury Denoyelle30f23f52022-04-27 14:41:53 +0200747 goto retry;
Amaury Denoyelleff191de2022-02-21 18:38:29 +0100748 }
Amaury Denoyelle91379f72022-02-14 17:14:59 +0100749
Amaury Denoyelle30f23f52022-04-27 14:41:53 +0200750 htx_sent += htx_add_data(htx, ist2(head, len));
Amaury Denoyelle73d6ffe2022-05-16 13:54:31 +0200751 if (htx_sent < len) {
752 qcs->flags |= QC_SF_DEM_FULL;
753 goto out;
754 }
Amaury Denoyelle30f23f52022-04-27 14:41:53 +0200755
Amaury Denoyelle48f01bd2022-04-27 15:37:20 +0200756 if (fin && len == htx_sent)
Amaury Denoyelle91379f72022-02-14 17:14:59 +0100757 htx->flags |= HTX_FL_EOM;
Amaury Denoyelle91379f72022-02-14 17:14:59 +0100758
Amaury Denoyelle48f01bd2022-04-27 15:37:20 +0200759 out:
760 htx_to_buf(htx, appbuf);
Amaury Denoyelle494512d2022-05-30 15:50:34 +0200761
762 TRACE_LEAVE(H3_EV_RX_FRAME|H3_EV_RX_DATA, qcs->qcc->conn, qcs);
Amaury Denoyelle314578a2022-04-27 14:52:52 +0200763 return htx_sent;
Amaury Denoyelle91379f72022-02-14 17:14:59 +0100764}
765
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200766/* Parse a SETTINGS frame of length <len> of payload <buf>.
Amaury Denoyellef8db5aa2022-05-24 15:26:07 +0200767 *
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200768 * Returns the number of consumed bytes or a negative error code.
Amaury Denoyellef8db5aa2022-05-24 15:26:07 +0200769 */
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200770static ssize_t h3_parse_settings_frm(struct h3c *h3c, const struct buffer *buf,
771 size_t len)
Amaury Denoyellef8db5aa2022-05-24 15:26:07 +0200772{
Amaury Denoyelle8c6176b2022-05-24 18:16:49 +0200773 struct buffer b;
Amaury Denoyellef8db5aa2022-05-24 15:26:07 +0200774 uint64_t id, value;
Amaury Denoyelle8c6176b2022-05-24 18:16:49 +0200775 size_t ret = 0;
776 long mask = 0; /* used to detect duplicated settings identifier */
Amaury Denoyellef8db5aa2022-05-24 15:26:07 +0200777
Amaury Denoyelle494512d2022-05-30 15:50:34 +0200778 TRACE_ENTER(H3_EV_RX_FRAME|H3_EV_RX_SETTINGS, h3c->qcc->conn);
779
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200780 /* Work on a copy of <buf>. */
Amaury Denoyelle3a2fcfd2022-06-09 11:54:38 +0200781 b = b_make(b_orig(buf), b_size(buf), b_head_ofs(buf), len);
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200782
Amaury Denoyelle8c6176b2022-05-24 18:16:49 +0200783 while (b_data(&b)) {
784 if (!b_quic_dec_int(&id, &b, &ret) || !b_quic_dec_int(&value, &b, &ret)) {
785 h3c->err = H3_FRAME_ERROR;
786 return -1;
787 }
Amaury Denoyellef8db5aa2022-05-24 15:26:07 +0200788
789 h3_debug_printf(stderr, "%s id: %llu value: %llu\n",
790 __func__, (unsigned long long)id, (unsigned long long)value);
Amaury Denoyelle8c6176b2022-05-24 18:16:49 +0200791
792 /* draft-ietf-quic-http34 7.2.4. SETTINGS
793 *
794 * The same setting identifier MUST NOT occur more than once in the
795 * SETTINGS frame. A receiver MAY treat the presence of duplicate
796 * setting identifiers as a connection error of type H3_SETTINGS_ERROR.
797 */
798
799 /* Ignore duplicate check for ID too big used for GREASE. */
800 if (id < sizeof(mask)) {
801 if (ha_bit_test(id, &mask)) {
802 h3c->err = H3_SETTINGS_ERROR;
803 return -1;
804 }
805 ha_bit_set(id, &mask);
806 }
807
Amaury Denoyellef8db5aa2022-05-24 15:26:07 +0200808 switch (id) {
809 case H3_SETTINGS_QPACK_MAX_TABLE_CAPACITY:
810 h3c->qpack_max_table_capacity = value;
811 break;
812 case H3_SETTINGS_MAX_FIELD_SECTION_SIZE:
813 h3c->max_field_section_size = value;
814 break;
815 case H3_SETTINGS_QPACK_BLOCKED_STREAMS:
816 h3c->qpack_blocked_streams = value;
817 break;
Amaury Denoyelle8c6176b2022-05-24 18:16:49 +0200818
819 case H3_SETTINGS_RESERVED_0:
820 case H3_SETTINGS_RESERVED_2:
821 case H3_SETTINGS_RESERVED_3:
822 case H3_SETTINGS_RESERVED_4:
823 case H3_SETTINGS_RESERVED_5:
824 /* draft-ietf-quic-http34 7.2.4.1. Defined SETTINGS Parameters
825 *
826 * Setting identifiers which were defined in [HTTP2] where there is no
827 * corresponding HTTP/3 setting have also been reserved
828 * (Section 11.2.2). These reserved settings MUST NOT be sent, and
829 * their receipt MUST be treated as a connection error of type
830 * H3_SETTINGS_ERROR.
831 */
Amaury Denoyellef8db5aa2022-05-24 15:26:07 +0200832 h3c->err = H3_SETTINGS_ERROR;
Amaury Denoyelle8c6176b2022-05-24 18:16:49 +0200833 return -1;
Amaury Denoyellef8db5aa2022-05-24 15:26:07 +0200834 default:
835 /* MUST be ignored */
836 break;
837 }
838 }
839
Frédéric Lécaillebefcf702022-09-08 16:04:55 +0200840 TRACE_LEAVE(H3_EV_RX_FRAME|H3_EV_RX_SETTINGS, h3c->qcc->conn);
Amaury Denoyelle8c6176b2022-05-24 18:16:49 +0200841 return ret;
Amaury Denoyellef8db5aa2022-05-24 15:26:07 +0200842}
843
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100844/* Decode <qcs> remotely initiated bidi-stream. <fin> must be set to indicate
845 * that we received the last data of the stream.
Amaury Denoyelle0ffd6e72022-05-24 11:07:28 +0200846 *
847 * Returns 0 on success else non-zero.
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100848 */
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200849static ssize_t h3_decode_qcs(struct qcs *qcs, struct buffer *b, int fin)
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100850{
Amaury Denoyelle48f01bd2022-04-27 15:37:20 +0200851 struct h3s *h3s = qcs->ctx;
Amaury Denoyellec0156792022-06-03 15:29:07 +0200852 struct h3c *h3c = h3s->h3c;
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200853 ssize_t total = 0, ret;
Amaury Denoyelle7b0f1222022-02-14 17:13:55 +0100854
Amaury Denoyellebb970422022-04-12 16:40:52 +0200855 h3_debug_printf(stderr, "%s: STREAM ID: %lu\n", __func__, qcs->id);
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200856 if (!b_data(b))
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100857 return 0;
858
Amaury Denoyellef8db5aa2022-05-24 15:26:07 +0200859 if (quic_stream_is_uni(qcs->id) && !(h3s->flags & H3_SF_UNI_INIT)) {
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200860 if ((ret = h3_init_uni_stream(h3c, qcs, b)) < 0)
861 return -1;
862
863 total += ret;
Amaury Denoyellef8db5aa2022-05-24 15:26:07 +0200864 }
865
866 if (quic_stream_is_uni(qcs->id) && (h3s->flags & H3_SF_UNI_NO_H3)) {
867 /* For non-h3 STREAM, parse it and return immediately. */
Amaury Denoyelle26aa3992022-08-16 17:42:47 +0200868 if ((ret = h3_parse_uni_stream_no_h3(qcs, b, fin)) < 0)
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200869 return -1;
870
871 total += ret;
872 return total;
Amaury Denoyellef8db5aa2022-05-24 15:26:07 +0200873 }
874
Amaury Denoyelle6b02c6b2022-08-16 17:16:47 +0200875 /* RFC 9114 6.2.1. Control Streams
876 *
877 * The sender MUST NOT close the control stream, and the receiver MUST NOT
878 * request that the sender close the control stream. If either control
879 * stream is closed at any point, this MUST be treated as a connection
880 * error of type H3_CLOSED_CRITICAL_STREAM.
881 */
882 if (h3s->type == H3S_T_CTRL && fin) {
883 qcc_emit_cc_app(qcs->qcc, H3_CLOSED_CRITICAL_STREAM, 1);
884 return -1;
885 }
886
Amaury Denoyelle2fe93ab2022-12-09 15:01:31 +0100887 while (b_data(b) && !(qcs->flags & QC_SF_DEM_FULL) && !h3c->err && !h3s->err) {
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100888 uint64_t ftype, flen;
Amaury Denoyelle95b93a32022-02-14 15:49:53 +0100889 char last_stream_frame = 0;
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100890
Amaury Denoyelle48f01bd2022-04-27 15:37:20 +0200891 if (!h3s->demux_frame_len) {
Amaury Denoyelled2c5ee62022-12-08 16:54:42 +0100892 /* Switch to a new frame. */
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200893 size_t hlen = h3_decode_frm_header(&ftype, &flen, b);
Amaury Denoyelle48f01bd2022-04-27 15:37:20 +0200894 if (!hlen)
895 break;
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100896
Amaury Denoyelle48f01bd2022-04-27 15:37:20 +0200897 h3_debug_printf(stderr, "%s: ftype: %lu, flen: %lu\n",
898 __func__, ftype, flen);
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100899
Amaury Denoyelle48f01bd2022-04-27 15:37:20 +0200900 h3s->demux_frame_type = ftype;
901 h3s->demux_frame_len = flen;
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200902 total += hlen;
Amaury Denoyelle417c7c02022-05-31 14:18:33 +0200903
Amaury Denoyelled2c5ee62022-12-08 16:54:42 +0100904 /* Check that content-length is not exceeded on a new DATA frame. */
905 if (ftype == H3_FT_DATA) {
906 h3s->data_len += flen;
Amaury Denoyelle2fe93ab2022-12-09 15:01:31 +0100907 if (h3s->flags & H3_SF_HAVE_CLEN && h3_check_body_size(qcs, fin))
908 break;
Amaury Denoyelled2c5ee62022-12-08 16:54:42 +0100909 }
910
Amaury Denoyelle417c7c02022-05-31 14:18:33 +0200911 if (!h3_is_frame_valid(h3c, qcs, ftype)) {
Amaury Denoyelled666d742022-07-13 15:15:58 +0200912 qcc_emit_cc_app(qcs->qcc, H3_FRAME_UNEXPECTED, 1);
Amaury Denoyelledca4c532022-06-07 18:24:34 +0200913 return -1;
Amaury Denoyelle417c7c02022-05-31 14:18:33 +0200914 }
915
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200916 if (!b_data(b))
Amaury Denoyelle417c7c02022-05-31 14:18:33 +0200917 break;
Amaury Denoyelle48f01bd2022-04-27 15:37:20 +0200918 }
Amaury Denoyelle0484f922022-02-15 16:59:39 +0100919
Amaury Denoyelle48f01bd2022-04-27 15:37:20 +0200920 flen = h3s->demux_frame_len;
921 ftype = h3s->demux_frame_type;
Amaury Denoyelle80097cc2022-05-24 11:13:46 +0200922
923 /* Do not demux incomplete frames except H3 DATA which can be
924 * fragmented in multiple HTX blocks.
925 */
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200926 if (flen > b_data(b) && ftype != H3_FT_DATA) {
Amaury Denoyelle80097cc2022-05-24 11:13:46 +0200927 /* Reject frames bigger than bufsize.
928 *
929 * TODO HEADERS should in complement be limited with H3
930 * SETTINGS_MAX_FIELD_SECTION_SIZE parameter to prevent
931 * excessive decompressed size.
932 */
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200933 if (flen > QC_S_RX_BUF_SZ) {
Amaury Denoyelled666d742022-07-13 15:15:58 +0200934 qcc_emit_cc_app(qcs->qcc, H3_EXCESSIVE_LOAD, 1);
Amaury Denoyelledca4c532022-06-07 18:24:34 +0200935 return -1;
Amaury Denoyelle80097cc2022-05-24 11:13:46 +0200936 }
Amaury Denoyelle48f01bd2022-04-27 15:37:20 +0200937 break;
Amaury Denoyelleb5454d42022-05-12 16:56:16 +0200938 }
Amaury Denoyelle80097cc2022-05-24 11:13:46 +0200939
Amaury Denoyelled2c5ee62022-12-08 16:54:42 +0100940 /* Check content-length equality with DATA frames length on the last frame. */
Amaury Denoyelle2fe93ab2022-12-09 15:01:31 +0100941 if (fin && h3s->flags & H3_SF_HAVE_CLEN && h3_check_body_size(qcs, fin))
942 break;
Amaury Denoyelled2c5ee62022-12-08 16:54:42 +0100943
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200944 last_stream_frame = (fin && flen == b_data(b));
Amaury Denoyelle95b93a32022-02-14 15:49:53 +0100945
Frédéric Lécaille6f7607e2022-05-25 22:25:37 +0200946 h3_inc_frame_type_cnt(h3c->prx_counters, ftype);
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100947 switch (ftype) {
948 case H3_FT_DATA:
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200949 ret = h3_data_to_htx(qcs, b, flen, last_stream_frame);
Amaury Denoyelle8d818c62022-08-02 11:32:45 +0200950 h3s->st_req = H3S_ST_REQ_DATA;
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100951 break;
952 case H3_FT_HEADERS:
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200953 ret = h3_headers_to_htx(qcs, b, flen, last_stream_frame);
Amaury Denoyelle8d818c62022-08-02 11:32:45 +0200954 h3s->st_req = (h3s->st_req == H3S_ST_REQ_BEFORE) ?
955 H3S_ST_REQ_HEADERS : H3S_ST_REQ_TRAILERS;
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100956 break;
Amaury Denoyellef8db5aa2022-05-24 15:26:07 +0200957 case H3_FT_CANCEL_PUSH:
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100958 case H3_FT_PUSH_PROMISE:
Amaury Denoyellef8db5aa2022-05-24 15:26:07 +0200959 case H3_FT_MAX_PUSH_ID:
960 case H3_FT_GOAWAY:
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100961 /* Not supported */
Amaury Denoyelle80097cc2022-05-24 11:13:46 +0200962 ret = flen;
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100963 break;
Amaury Denoyellef8db5aa2022-05-24 15:26:07 +0200964 case H3_FT_SETTINGS:
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200965 ret = h3_parse_settings_frm(qcs->qcc->ctx, b, flen);
Amaury Denoyelle8c6176b2022-05-24 18:16:49 +0200966 if (ret < 0) {
Amaury Denoyelled666d742022-07-13 15:15:58 +0200967 qcc_emit_cc_app(qcs->qcc, h3c->err, 1);
Amaury Denoyelledca4c532022-06-07 18:24:34 +0200968 return -1;
Amaury Denoyelle8c6176b2022-05-24 18:16:49 +0200969 }
970 h3c->flags |= H3_CF_SETTINGS_RECV;
Amaury Denoyellef8db5aa2022-05-24 15:26:07 +0200971 break;
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100972 default:
Amaury Denoyelled1acaf92021-11-15 15:52:55 +0100973 /* draft-ietf-quic-http34 9. Extensions to HTTP/3
Amaury Denoyelle302ecd42022-05-24 15:24:32 +0200974 *
975 * Implementations MUST discard frames [...] that have unknown
976 * or unsupported types.
Amaury Denoyelled1acaf92021-11-15 15:52:55 +0100977 */
978 h3_debug_printf(stderr, "ignore unknown frame type 0x%lx\n", ftype);
Amaury Denoyelle80097cc2022-05-24 11:13:46 +0200979 ret = flen;
980 break;
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100981 }
Amaury Denoyelle314578a2022-04-27 14:52:52 +0200982
Amaury Denoyelle2fe93ab2022-12-09 15:01:31 +0100983 if (ret > 0) {
Amaury Denoyelle291ee252022-05-02 10:35:39 +0200984 BUG_ON(h3s->demux_frame_len < ret);
985 h3s->demux_frame_len -= ret;
Amaury Denoyelle62eef852022-06-03 16:40:34 +0200986 b_del(b, ret);
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +0200987 total += ret;
Amaury Denoyelle291ee252022-05-02 10:35:39 +0200988 }
Frédéric Lécailleccac11f2021-03-03 16:09:02 +0100989 }
990
Amaury Denoyelle2fe93ab2022-12-09 15:01:31 +0100991 /* Interrupt decoding on stream/connection error detected. */
992 if (h3s->err) {
993 qcc_abort_stream_read(qcs);
994 qcc_reset_stream(qcs, h3s->err);
995 return b_data(b);
996 }
997 else if (h3c->err) {
998 qcc_emit_cc_app(qcs->qcc, h3c->err, 1);
999 return b_data(b);
1000 }
1001
Amaury Denoyelle03cc62c2022-04-27 16:53:16 +02001002 /* TODO may be useful to wakeup the MUX if blocked due to full buffer.
1003 * However, currently, io-cb of MUX does not handle Rx.
1004 */
1005
Amaury Denoyelle1f21ebd2022-06-07 17:30:55 +02001006 return total;
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001007}
1008
Amaury Denoyellea5871362021-10-07 16:26:12 +02001009/* Returns buffer for data sending.
1010 * May be NULL if the allocation failed.
1011 */
1012static struct buffer *mux_get_buf(struct qcs *qcs)
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001013{
Amaury Denoyellea5871362021-10-07 16:26:12 +02001014 if (!b_size(&qcs->tx.buf))
1015 b_alloc(&qcs->tx.buf);
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001016
Amaury Denoyellea5871362021-10-07 16:26:12 +02001017 return &qcs->tx.buf;
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001018}
1019
Amaury Denoyelle6b923942022-05-23 14:25:53 +02001020/* Function used to emit stream data from <qcs> control uni-stream */
1021static int h3_control_send(struct qcs *qcs, void *ctx)
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001022{
1023 int ret;
Amaury Denoyelle8d1ecac2022-05-24 14:55:43 +02001024 struct h3c *h3c = ctx;
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001025 unsigned char data[(2 + 3) * 2 * QUIC_VARINT_MAX_SIZE]; /* enough for 3 settings */
Amaury Denoyellea5871362021-10-07 16:26:12 +02001026 struct buffer pos, *res;
Amaury Denoyelle65df3ad2022-05-24 15:06:10 +02001027 size_t frm_len;
Amaury Denoyelle65df3ad2022-05-24 15:06:10 +02001028
Amaury Denoyellea717eb72022-05-30 15:51:01 +02001029 TRACE_ENTER(H3_EV_TX_SETTINGS, qcs->qcc->conn, qcs);
1030
Amaury Denoyelle65df3ad2022-05-24 15:06:10 +02001031 BUG_ON_HOT(h3c->flags & H3_CF_SETTINGS_SENT);
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001032
1033 ret = 0;
Amaury Denoyellea5871362021-10-07 16:26:12 +02001034 pos = b_make((char *)data, sizeof(data), 0, 0);
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001035
Amaury Denoyelle65df3ad2022-05-24 15:06:10 +02001036 frm_len = quic_int_getsize(H3_SETTINGS_QPACK_MAX_TABLE_CAPACITY) +
1037 quic_int_getsize(h3_settings_qpack_max_table_capacity) +
1038 quic_int_getsize(H3_SETTINGS_QPACK_BLOCKED_STREAMS) +
1039 quic_int_getsize(h3_settings_qpack_blocked_streams);
1040 if (h3_settings_max_field_section_size) {
1041 frm_len += quic_int_getsize(H3_SETTINGS_MAX_FIELD_SECTION_SIZE) +
1042 quic_int_getsize(h3_settings_max_field_section_size);
1043 }
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001044
Amaury Denoyelle65df3ad2022-05-24 15:06:10 +02001045 b_quic_enc_int(&pos, H3_UNI_S_T_CTRL);
1046 /* Build a SETTINGS frame */
1047 b_quic_enc_int(&pos, H3_FT_SETTINGS);
1048 b_quic_enc_int(&pos, frm_len);
1049 b_quic_enc_int(&pos, H3_SETTINGS_QPACK_MAX_TABLE_CAPACITY);
1050 b_quic_enc_int(&pos, h3_settings_qpack_max_table_capacity);
1051 b_quic_enc_int(&pos, H3_SETTINGS_QPACK_BLOCKED_STREAMS);
1052 b_quic_enc_int(&pos, h3_settings_qpack_blocked_streams);
1053 if (h3_settings_max_field_section_size) {
1054 b_quic_enc_int(&pos, H3_SETTINGS_MAX_FIELD_SECTION_SIZE);
1055 b_quic_enc_int(&pos, h3_settings_max_field_section_size);
1056 }
Amaury Denoyellea5871362021-10-07 16:26:12 +02001057
Amaury Denoyelle65df3ad2022-05-24 15:06:10 +02001058 res = mux_get_buf(qcs);
1059 if (b_room(res) < b_data(&pos)) {
1060 // TODO the mux should be put in blocked state, with
1061 // the stream in state waiting for settings to be sent
1062 ABORT_NOW();
1063 }
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001064
Amaury Denoyelle65df3ad2022-05-24 15:06:10 +02001065 ret = b_force_xfer(res, &pos, b_data(&pos));
Amaury Denoyelle20f2a422023-01-03 14:39:24 +01001066 if (ret > 0) {
1067 /* Register qcs for sending before other streams. */
Amaury Denoyellef9b03262023-01-09 10:34:25 +01001068 qcc_send_stream(qcs, 1);
Amaury Denoyelle65df3ad2022-05-24 15:06:10 +02001069 h3c->flags |= H3_CF_SETTINGS_SENT;
Amaury Denoyelle20f2a422023-01-03 14:39:24 +01001070 }
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001071
Amaury Denoyellea717eb72022-05-30 15:51:01 +02001072 TRACE_LEAVE(H3_EV_TX_SETTINGS, qcs->qcc->conn, qcs);
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001073 return ret;
1074}
1075
Amaury Denoyelle15b09612021-08-24 16:20:27 +02001076static int h3_resp_headers_send(struct qcs *qcs, struct htx *htx)
1077{
1078 struct buffer outbuf;
1079 struct buffer headers_buf = BUF_NULL;
1080 struct buffer *res;
1081 struct http_hdr list[global.tune.max_http_hdr];
1082 struct htx_sl *sl;
1083 struct htx_blk *blk;
1084 enum htx_blk_type type;
1085 int frame_length_size; /* size in bytes of frame length varint field */
1086 int ret = 0;
1087 int hdr;
1088 int status = 0;
1089
Amaury Denoyellea717eb72022-05-30 15:51:01 +02001090 TRACE_ENTER(H3_EV_TX_HDR, qcs->qcc->conn, qcs);
1091
Amaury Denoyelle15b09612021-08-24 16:20:27 +02001092 sl = NULL;
1093 hdr = 0;
1094 for (blk = htx_get_head_blk(htx); blk; blk = htx_get_next_blk(htx, blk)) {
1095 type = htx_get_blk_type(blk);
1096
1097 if (type == HTX_BLK_UNUSED)
1098 continue;
1099
1100 if (type == HTX_BLK_EOH)
1101 break;
1102
1103 if (type == HTX_BLK_RES_SL) {
1104 /* start-line -> HEADERS h3 frame */
1105 BUG_ON(sl);
1106 sl = htx_get_blk_ptr(htx, blk);
1107 /* TODO should be on h3 layer */
1108 status = sl->info.res.status;
1109 }
1110 else if (type == HTX_BLK_HDR) {
Amaury Denoyelle60ef19f2022-06-14 17:38:36 +02001111 if (unlikely(hdr >= sizeof(list) / sizeof(list[0]) - 1))
Amaury Denoyellefa7fadc2022-06-15 15:52:27 +02001112 goto err;
Amaury Denoyelle15b09612021-08-24 16:20:27 +02001113 list[hdr].n = htx_get_blk_name(htx, blk);
1114 list[hdr].v = htx_get_blk_value(htx, blk);
1115 hdr++;
1116 }
1117 else {
1118 ABORT_NOW();
1119 goto err;
1120 }
1121 }
1122
1123 BUG_ON(!sl);
1124
1125 list[hdr].n = ist("");
1126
Amaury Denoyelled3d97c62021-10-05 11:45:58 +02001127 res = mux_get_buf(qcs);
Amaury Denoyelle15b09612021-08-24 16:20:27 +02001128
1129 /* At least 5 bytes to store frame type + length as a varint max size */
1130 if (b_room(res) < 5)
1131 ABORT_NOW();
1132
1133 b_reset(&outbuf);
1134 outbuf = b_make(b_tail(res), b_contig_space(res), 0, 0);
1135 /* Start the headers after frame type + length */
1136 headers_buf = b_make(b_head(res) + 5, b_size(res) - 5, 0, 0);
1137
1138 if (qpack_encode_field_section_line(&headers_buf))
1139 ABORT_NOW();
1140 if (qpack_encode_int_status(&headers_buf, status))
1141 ABORT_NOW();
1142
1143 for (hdr = 0; hdr < sizeof(list) / sizeof(list[0]); ++hdr) {
1144 if (isteq(list[hdr].n, ist("")))
1145 break;
1146
Amaury Denoyelle8ad26692023-01-17 17:47:06 +01001147 /* RFC 9114 4.2. HTTP Fields
1148 *
1149 * An intermediary transforming an HTTP/1.x message to HTTP/3
1150 * MUST remove connection-specific header fields as discussed in
1151 * Section 7.6.1 of [HTTP], or their messages will be treated by
1152 * other HTTP/3 endpoints as malformed.
Amaury Denoyelleffafb3d2022-02-15 16:10:42 +01001153 */
Amaury Denoyelle8ad26692023-01-17 17:47:06 +01001154 if (isteq(list[hdr].n, ist("connection")) ||
1155 isteq(list[hdr].n, ist("proxy-connection")) ||
1156 isteq(list[hdr].n, ist("keep-alive")) ||
1157 isteq(list[hdr].n, ist("transfer-encoding"))) {
Amaury Denoyelleffafb3d2022-02-15 16:10:42 +01001158 continue;
Amaury Denoyelle8ad26692023-01-17 17:47:06 +01001159 }
1160 else if (isteq(list[hdr].n, ist("te"))) {
1161 /* "te" may only be sent with "trailers" if this value
1162 * is present, otherwise it must be deleted.
1163 */
1164 const struct ist v = istist(list[hdr].v, ist("trailers"));
1165 if (!isttest(v) || (v.len > 8 && v.ptr[8] != ','))
1166 continue;
1167 list[hdr].v = ist("trailers");
1168 }
Amaury Denoyelleffafb3d2022-02-15 16:10:42 +01001169
Amaury Denoyelle15b09612021-08-24 16:20:27 +02001170 if (qpack_encode_header(&headers_buf, list[hdr].n, list[hdr].v))
1171 ABORT_NOW();
1172 }
1173
1174 /* Now that all headers are encoded, we are certain that res buffer is
1175 * big enough
1176 */
1177 frame_length_size = quic_int_getsize(b_data(&headers_buf));
1178 res->head += 4 - frame_length_size;
1179 b_putchr(res, 0x01); /* h3 HEADERS frame type */
1180 if (!b_quic_enc_int(res, b_data(&headers_buf)))
1181 ABORT_NOW();
1182 b_add(res, b_data(&headers_buf));
1183
1184 ret = 0;
1185 blk = htx_get_head_blk(htx);
1186 while (blk) {
1187 type = htx_get_blk_type(blk);
1188 ret += htx_get_blksz(blk);
1189 blk = htx_remove_blk(htx, blk);
1190 if (type == HTX_BLK_EOH)
1191 break;
1192 }
1193
Amaury Denoyellea717eb72022-05-30 15:51:01 +02001194 TRACE_LEAVE(H3_EV_TX_HDR, qcs->qcc->conn, qcs);
Amaury Denoyelle15b09612021-08-24 16:20:27 +02001195 return ret;
1196
1197 err:
Amaury Denoyellea717eb72022-05-30 15:51:01 +02001198 TRACE_DEVEL("leaving on error", H3_EV_TX_HDR, qcs->qcc->conn, qcs);
Amaury Denoyelle15b09612021-08-24 16:20:27 +02001199 return 0;
1200}
1201
Amaury Denoyelle8e2a9982021-08-24 16:24:37 +02001202/* Returns the total of bytes sent. */
Amaury Denoyelle9534e592022-09-19 17:14:27 +02001203static int h3_resp_data_send(struct qcs *qcs, struct htx *htx, size_t count)
Amaury Denoyelle8e2a9982021-08-24 16:24:37 +02001204{
1205 struct buffer outbuf;
1206 struct buffer *res;
1207 size_t total = 0;
Amaury Denoyellea543eb12021-10-06 14:53:13 +02001208 int bsize, fsize, hsize;
Amaury Denoyelle8e2a9982021-08-24 16:24:37 +02001209 struct htx_blk *blk;
1210 enum htx_blk_type type;
1211
Amaury Denoyellea717eb72022-05-30 15:51:01 +02001212 TRACE_ENTER(H3_EV_TX_DATA, qcs->qcc->conn, qcs);
1213
Amaury Denoyelle8e2a9982021-08-24 16:24:37 +02001214 new_frame:
1215 if (!count || htx_is_empty(htx))
1216 goto end;
1217
1218 blk = htx_get_head_blk(htx);
1219 type = htx_get_blk_type(blk);
1220 fsize = bsize = htx_get_blksz(blk);
1221
1222 if (type != HTX_BLK_DATA)
1223 goto end;
1224
Amaury Denoyelled3d97c62021-10-05 11:45:58 +02001225 res = mux_get_buf(qcs);
Amaury Denoyelle8e2a9982021-08-24 16:24:37 +02001226
1227 if (fsize > count)
1228 fsize = count;
1229
Amaury Denoyellea543eb12021-10-06 14:53:13 +02001230 /* h3 DATA headers : 1-byte frame type + varint frame length */
1231 hsize = 1 + QUIC_VARINT_MAX_SIZE;
Amaury Denoyelle8e2a9982021-08-24 16:24:37 +02001232
Amaury Denoyellea543eb12021-10-06 14:53:13 +02001233 while (1) {
1234 b_reset(&outbuf);
1235 outbuf = b_make(b_tail(res), b_contig_space(res), 0, 0);
1236 if (b_size(&outbuf) > hsize || !b_space_wraps(res))
1237 break;
1238 b_slow_realign(res, trash.area, b_data(res));
1239 }
Amaury Denoyelle8e2a9982021-08-24 16:24:37 +02001240
Amaury Denoyelle84ea8dc2021-12-03 14:40:01 +01001241 /* Not enough room for headers and at least one data byte, block the
Willy Tarreau4596fe22022-05-17 19:07:51 +02001242 * stream. It is expected that the stream connector layer will subscribe
1243 * on SEND.
Amaury Denoyellea543eb12021-10-06 14:53:13 +02001244 */
Amaury Denoyelle84ea8dc2021-12-03 14:40:01 +01001245 if (b_size(&outbuf) <= hsize) {
1246 qcs->flags |= QC_SF_BLK_MROOM;
1247 goto end;
1248 }
Amaury Denoyelle8e2a9982021-08-24 16:24:37 +02001249
Amaury Denoyellea543eb12021-10-06 14:53:13 +02001250 if (b_size(&outbuf) < hsize + fsize)
1251 fsize = b_size(&outbuf) - hsize;
1252 BUG_ON(fsize <= 0);
Amaury Denoyelle8e2a9982021-08-24 16:24:37 +02001253
Amaury Denoyellea543eb12021-10-06 14:53:13 +02001254 b_putchr(&outbuf, 0x00); /* h3 frame type = DATA */
1255 b_quic_enc_int(&outbuf, fsize); /* h3 frame length */
1256
Amaury Denoyelle8e2a9982021-08-24 16:24:37 +02001257 b_putblk(&outbuf, htx_get_blk_ptr(htx, blk), fsize);
Amaury Denoyellea543eb12021-10-06 14:53:13 +02001258 total += fsize;
Amaury Denoyelle8e2a9982021-08-24 16:24:37 +02001259 count -= fsize;
1260
1261 if (fsize == bsize)
1262 htx_remove_blk(htx, blk);
1263 else
1264 htx_cut_data_blk(htx, blk, fsize);
1265
Amaury Denoyellea543eb12021-10-06 14:53:13 +02001266 /* commit the buffer */
Amaury Denoyelle8e2a9982021-08-24 16:24:37 +02001267 b_add(res, b_data(&outbuf));
1268 goto new_frame;
1269
1270 end:
Amaury Denoyellea717eb72022-05-30 15:51:01 +02001271 TRACE_LEAVE(H3_EV_TX_DATA, qcs->qcc->conn, qcs);
Amaury Denoyelle8e2a9982021-08-24 16:24:37 +02001272 return total;
1273}
1274
Amaury Denoyelle9534e592022-09-19 17:14:27 +02001275static size_t h3_snd_buf(struct qcs *qcs, struct htx *htx, size_t count)
Amaury Denoyelle26dfd902021-08-24 16:33:53 +02001276{
1277 size_t total = 0;
Amaury Denoyelle26dfd902021-08-24 16:33:53 +02001278 enum htx_blk_type btype;
1279 struct htx_blk *blk;
1280 uint32_t bsize;
1281 int32_t idx;
1282 int ret;
1283
Amaury Denoyelled8769d12022-03-25 15:28:33 +01001284 h3_debug_printf(stderr, "%s\n", __func__);
Amaury Denoyelledeed7772021-12-03 11:36:46 +01001285
Amaury Denoyelle84ea8dc2021-12-03 14:40:01 +01001286 while (count && !htx_is_empty(htx) && !(qcs->flags & QC_SF_BLK_MROOM)) {
Amaury Denoyelle26dfd902021-08-24 16:33:53 +02001287 idx = htx_get_head(htx);
1288 blk = htx_get_blk(htx, idx);
1289 btype = htx_get_blk_type(blk);
1290 bsize = htx_get_blksz(blk);
1291
1292 /* Not implemented : QUIC on backend side */
1293 BUG_ON(btype == HTX_BLK_REQ_SL);
1294
1295 switch (btype) {
1296 case HTX_BLK_RES_SL:
Amaury Denoyelle15b09612021-08-24 16:20:27 +02001297 /* start-line -> HEADERS h3 frame */
1298 ret = h3_resp_headers_send(qcs, htx);
1299 if (ret > 0) {
1300 total += ret;
1301 count -= ret;
1302 if (ret < bsize)
1303 goto out;
1304 }
1305 break;
Amaury Denoyelle26dfd902021-08-24 16:33:53 +02001306
1307 case HTX_BLK_DATA:
Amaury Denoyelle9534e592022-09-19 17:14:27 +02001308 ret = h3_resp_data_send(qcs, htx, count);
Amaury Denoyelle8e2a9982021-08-24 16:24:37 +02001309 if (ret > 0) {
Amaury Denoyelle8e2a9982021-08-24 16:24:37 +02001310 total += ret;
1311 count -= ret;
1312 if (ret < bsize)
1313 goto out;
1314 }
1315 break;
Amaury Denoyelle26dfd902021-08-24 16:33:53 +02001316
1317 case HTX_BLK_TLR:
1318 case HTX_BLK_EOT:
1319 /* TODO trailers */
1320
1321 default:
1322 htx_remove_blk(htx, blk);
1323 total += bsize;
1324 count -= bsize;
1325 break;
1326 }
1327 }
1328
Amaury Denoyelle26dfd902021-08-24 16:33:53 +02001329 out:
1330 return total;
Amaury Denoyellef52151d2021-08-24 16:11:18 +02001331}
1332
Amaury Denoyellec0156792022-06-03 15:29:07 +02001333static int h3_attach(struct qcs *qcs, void *conn_ctx)
Amaury Denoyelle67e92d32022-04-27 18:04:01 +02001334{
1335 struct h3s *h3s;
1336
Amaury Denoyelled5581d52022-05-30 15:51:31 +02001337 TRACE_ENTER(H3_EV_H3S_NEW, qcs->qcc->conn, qcs);
1338
Amaury Denoyelle67e92d32022-04-27 18:04:01 +02001339 h3s = pool_alloc(pool_head_h3s);
1340 if (!h3s)
1341 return 1;
1342
1343 qcs->ctx = h3s;
Amaury Denoyellec0156792022-06-03 15:29:07 +02001344 h3s->h3c = conn_ctx;
1345
Amaury Denoyelle48f01bd2022-04-27 15:37:20 +02001346 h3s->demux_frame_len = 0;
1347 h3s->demux_frame_type = 0;
Amaury Denoyelled2c5ee62022-12-08 16:54:42 +01001348 h3s->body_len = 0;
1349 h3s->data_len = 0;
Amaury Denoyelle35550642022-05-24 15:14:53 +02001350 h3s->flags = 0;
Amaury Denoyelle2fe93ab2022-12-09 15:01:31 +01001351 h3s->err = 0;
Amaury Denoyelle48f01bd2022-04-27 15:37:20 +02001352
Amaury Denoyelle3236a8e2022-05-24 15:24:03 +02001353 if (quic_stream_is_bidi(qcs->id)) {
1354 h3s->type = H3S_T_REQ;
Amaury Denoyelle8d818c62022-08-02 11:32:45 +02001355 h3s->st_req = H3S_ST_REQ_BEFORE;
Amaury Denoyelle30e260e2022-08-03 11:17:57 +02001356 qcs_wait_http_req(qcs);
Amaury Denoyelle3236a8e2022-05-24 15:24:03 +02001357 }
1358 else {
1359 /* stream type must be decoded for unidirectional streams */
1360 h3s->type = H3S_T_UNKNOWN;
1361 }
1362
Amaury Denoyelled5581d52022-05-30 15:51:31 +02001363 TRACE_LEAVE(H3_EV_H3S_NEW, qcs->qcc->conn, qcs);
Amaury Denoyelle67e92d32022-04-27 18:04:01 +02001364 return 0;
1365}
1366
Amaury Denoyelle67e92d32022-04-27 18:04:01 +02001367static void h3_detach(struct qcs *qcs)
1368{
1369 struct h3s *h3s = qcs->ctx;
Amaury Denoyelled5581d52022-05-30 15:51:31 +02001370
1371 TRACE_ENTER(H3_EV_H3S_END, qcs->qcc->conn, qcs);
1372
Amaury Denoyelle67e92d32022-04-27 18:04:01 +02001373 pool_free(pool_head_h3s, h3s);
1374 qcs->ctx = NULL;
Amaury Denoyelled5581d52022-05-30 15:51:31 +02001375
1376 TRACE_LEAVE(H3_EV_H3S_END, qcs->qcc->conn, qcs);
Amaury Denoyelle67e92d32022-04-27 18:04:01 +02001377}
1378
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001379static int h3_finalize(void *ctx)
1380{
Amaury Denoyelle8d1ecac2022-05-24 14:55:43 +02001381 struct h3c *h3c = ctx;
Amaury Denoyelle9cc47512022-05-24 16:27:41 +02001382 struct qcs *qcs;
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001383
Amaury Denoyelleb1437232022-07-08 11:53:22 +02001384 qcs = qcc_init_stream_local(h3c->qcc, 0);
Amaury Denoyelle9cc47512022-05-24 16:27:41 +02001385 if (!qcs)
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001386 return 0;
1387
Amaury Denoyelle9cc47512022-05-24 16:27:41 +02001388 h3_control_send(qcs, h3c);
Amaury Denoyelled7010392022-07-13 15:17:29 +02001389 h3c->ctrl_strm = qcs;
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001390
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001391 return 1;
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001392}
1393
Amaury Denoyelle114c9c82022-03-28 14:53:45 +02001394/* Generate a GOAWAY frame for <h3c> connection on the control stream.
1395 *
1396 * Returns 0 on success else non-zero.
1397 */
1398static int h3_send_goaway(struct h3c *h3c)
1399{
1400 struct qcs *qcs = h3c->ctrl_strm;
1401 struct buffer pos, *res;
1402 unsigned char data[3 * QUIC_VARINT_MAX_SIZE];
1403 size_t frm_len = quic_int_getsize(h3c->id_goaway);
1404
1405 if (!qcs)
1406 return 1;
1407
1408 pos = b_make((char *)data, sizeof(data), 0, 0);
1409
1410 b_quic_enc_int(&pos, H3_FT_GOAWAY);
1411 b_quic_enc_int(&pos, frm_len);
1412 b_quic_enc_int(&pos, h3c->id_goaway);
1413
1414 res = mux_get_buf(qcs);
1415 if (!res || b_room(res) < b_data(&pos)) {
1416 /* Do not try forcefully to emit GOAWAY if no space left. */
1417 return 1;
1418 }
1419
1420 b_force_xfer(res, &pos, b_data(&pos));
1421
1422 return 0;
1423}
1424
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001425/* Initialize the HTTP/3 context for <qcc> mux.
1426 * Return 1 if succeeded, 0 if not.
1427 */
1428static int h3_init(struct qcc *qcc)
1429{
Amaury Denoyelle8d1ecac2022-05-24 14:55:43 +02001430 struct h3c *h3c;
Frédéric Lécaille6f7607e2022-05-25 22:25:37 +02001431 struct quic_conn *qc = qcc->conn->handle.qc;
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001432
Amaury Denoyelle8d1ecac2022-05-24 14:55:43 +02001433 h3c = pool_alloc(pool_head_h3c);
1434 if (!h3c)
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001435 goto fail_no_h3;
1436
Amaury Denoyelle8d1ecac2022-05-24 14:55:43 +02001437 h3c->qcc = qcc;
Amaury Denoyelled7010392022-07-13 15:17:29 +02001438 h3c->ctrl_strm = NULL;
Amaury Denoyelle2fe93ab2022-12-09 15:01:31 +01001439 h3c->err = 0;
Amaury Denoyelle8d1ecac2022-05-24 14:55:43 +02001440 h3c->flags = 0;
Amaury Denoyelle114c9c82022-03-28 14:53:45 +02001441 h3c->id_goaway = 0;
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001442
Amaury Denoyelle8d1ecac2022-05-24 14:55:43 +02001443 qcc->ctx = h3c;
Amaury Denoyelle5c25dc52022-09-30 17:44:15 +02001444 /* TODO cleanup only ref to quic_conn */
Frédéric Lécaille6f7607e2022-05-25 22:25:37 +02001445 h3c->prx_counters =
1446 EXTRA_COUNTERS_GET(qc->li->bind_conf->frontend->extra_counters_fe,
1447 &h3_stats_module);
Amaury Denoyelle8d1ecac2022-05-24 14:55:43 +02001448 LIST_INIT(&h3c->buf_wait.list);
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001449
1450 return 1;
1451
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001452 fail_no_h3:
1453 return 0;
1454}
1455
Amaury Denoyellef8aaf8b2022-09-14 16:23:47 +02001456/* Send a HTTP/3 GOAWAY followed by a CONNECTION_CLOSE_APP. */
1457static void h3_shutdown(void *ctx)
Amaury Denoyelle8347f272022-03-29 14:46:55 +02001458{
Amaury Denoyelle8d1ecac2022-05-24 14:55:43 +02001459 struct h3c *h3c = ctx;
Amaury Denoyelle069288b2022-07-15 10:58:25 +02001460
1461 /* RFC 9114 5.2. Connection Shutdown
1462 *
Amaury Denoyelle114c9c82022-03-28 14:53:45 +02001463 * Even when a connection is not idle, either endpoint can decide to
1464 * stop using the connection and initiate a graceful connection close.
1465 * Endpoints initiate the graceful shutdown of an HTTP/3 connection by
1466 * sending a GOAWAY frame.
1467 */
1468 h3_send_goaway(h3c);
1469
1470 /* RFC 9114 5.2. Connection Shutdown
1471 *
Amaury Denoyelle069288b2022-07-15 10:58:25 +02001472 * An endpoint that completes a
1473 * graceful shutdown SHOULD use the H3_NO_ERROR error code when closing
1474 * the connection.
1475 */
1476 qcc_emit_cc_app(h3c->qcc, H3_NO_ERROR, 0);
Amaury Denoyellef8aaf8b2022-09-14 16:23:47 +02001477}
Amaury Denoyelle069288b2022-07-15 10:58:25 +02001478
Amaury Denoyellef8aaf8b2022-09-14 16:23:47 +02001479static void h3_release(void *ctx)
1480{
1481 struct h3c *h3c = ctx;
Amaury Denoyelle8d1ecac2022-05-24 14:55:43 +02001482 pool_free(pool_head_h3c, h3c);
Amaury Denoyelle8347f272022-03-29 14:46:55 +02001483}
1484
Frédéric Lécaille6f7607e2022-05-25 22:25:37 +02001485/* Increment the h3 error code counters for <error_code> value */
1486static void h3_stats_inc_err_cnt(void *ctx, int err_code)
1487{
1488 struct h3c *h3c = ctx;
1489
1490 h3_inc_err_cnt(h3c->prx_counters, err_code);
1491}
1492
Amaury Denoyelle016aa932022-05-30 15:49:36 +02001493/* h3 trace handler */
1494static void h3_trace(enum trace_level level, uint64_t mask,
1495 const struct trace_source *src,
1496 const struct ist where, const struct ist func,
1497 const void *a1, const void *a2, const void *a3, const void *a4)
1498{
1499 const struct connection *conn = a1;
1500 const struct qcc *qcc = conn ? conn->ctx : NULL;
1501 const struct qcs *qcs = a2;
1502
Frédéric Lécaille1c725aa2022-09-08 15:49:37 +02001503 if (!qcc)
1504 return;
1505
Amaury Denoyelle016aa932022-05-30 15:49:36 +02001506 if (src->verbosity > H3_VERB_CLEAN) {
1507 chunk_appendf(&trace_buf, " : qcc=%p(F)", qcc);
Frédéric Lécaille2eb5faa2022-09-08 16:03:13 +02001508 if (qcc->conn->handle.qc)
1509 chunk_appendf(&trace_buf, " qc=%p", qcc->conn->handle.qc);
Amaury Denoyelle016aa932022-05-30 15:49:36 +02001510
1511 if (qcs)
Frédéric Lécaille628e89c2022-06-24 12:13:53 +02001512 chunk_appendf(&trace_buf, " qcs=%p(%llu)", qcs, (ull)qcs->id);
Amaury Denoyelle016aa932022-05-30 15:49:36 +02001513 }
1514}
1515
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001516/* HTTP/3 application layer operations */
1517const struct qcc_app_ops h3_ops = {
1518 .init = h3_init,
Amaury Denoyelle67e92d32022-04-27 18:04:01 +02001519 .attach = h3_attach,
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001520 .decode_qcs = h3_decode_qcs,
Amaury Denoyelleabbe91e2021-11-12 16:09:29 +01001521 .snd_buf = h3_snd_buf,
Amaury Denoyelle67e92d32022-04-27 18:04:01 +02001522 .detach = h3_detach,
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001523 .finalize = h3_finalize,
Amaury Denoyellef8aaf8b2022-09-14 16:23:47 +02001524 .shutdown = h3_shutdown,
Frédéric Lécaille6f7607e2022-05-25 22:25:37 +02001525 .inc_err_cnt = h3_stats_inc_err_cnt,
Amaury Denoyellef8aaf8b2022-09-14 16:23:47 +02001526 .release = h3_release,
Frédéric Lécailleccac11f2021-03-03 16:09:02 +01001527};