Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 19 | #include <haproxy/buf.h> |
Amaury Denoyelle | 9904355 | 2021-08-24 15:36:02 +0200 | [diff] [blame] | 20 | #include <haproxy/connection.h> |
Christopher Faulet | 1329f2a | 2021-12-16 17:32:56 +0100 | [diff] [blame] | 21 | #include <haproxy/conn_stream.h> |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 22 | #include <haproxy/dynbuf.h> |
| 23 | #include <haproxy/h3.h> |
Amaury Denoyelle | b49fa1a | 2021-08-24 15:30:12 +0200 | [diff] [blame] | 24 | #include <haproxy/http.h> |
| 25 | #include <haproxy/htx.h> |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 26 | #include <haproxy/istbuf.h> |
Amaury Denoyelle | 846cc04 | 2022-04-04 16:13:44 +0200 | [diff] [blame] | 27 | #include <haproxy/mux_quic.h> |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 28 | #include <haproxy/ncbuf.h> |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 29 | #include <haproxy/pool.h> |
| 30 | #include <haproxy/qpack-dec.h> |
Amaury Denoyelle | 15b0961 | 2021-08-24 16:20:27 +0200 | [diff] [blame] | 31 | #include <haproxy/qpack-enc.h> |
| 32 | #include <haproxy/quic_enc.h> |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 33 | #include <haproxy/tools.h> |
| 34 | #include <haproxy/xprt_quic.h> |
| 35 | |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 36 | #if defined(DEBUG_H3) |
| 37 | #define h3_debug_printf fprintf |
| 38 | #define h3_debug_hexdump debug_hexdump |
| 39 | #else |
| 40 | #define h3_debug_printf(...) do { } while (0) |
| 41 | #define h3_debug_hexdump(...) do { } while (0) |
| 42 | #endif |
| 43 | |
Amaury Denoyelle | 302ecd4 | 2022-05-24 15:24:32 +0200 | [diff] [blame] | 44 | #define H3_CF_SETTINGS_SENT 0x00000001 /* SETTINGS frame already sent on local control stream */ |
| 45 | #define H3_CF_SETTINGS_RECV 0x00000002 /* SETTINGS frame already received on remote control stream */ |
| 46 | #define H3_CF_UNI_CTRL_SET 0x00000004 /* Remote H3 Control stream opened */ |
| 47 | #define H3_CF_UNI_QPACK_DEC_SET 0x00000008 /* Remote QPACK decoder stream opened */ |
| 48 | #define H3_CF_UNI_QPACK_ENC_SET 0x00000010 /* Remote QPACK encoder stream opened */ |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 49 | |
| 50 | /* Default settings */ |
Amaury Denoyelle | 3394939 | 2021-08-24 15:16:58 +0200 | [diff] [blame] | 51 | static uint64_t h3_settings_qpack_max_table_capacity = 0; |
| 52 | static uint64_t h3_settings_qpack_blocked_streams = 4096; |
| 53 | static uint64_t h3_settings_max_field_section_size = QUIC_VARINT_8_BYTE_MAX; /* Unlimited */ |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 54 | |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 55 | struct h3c { |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 56 | struct qcc *qcc; |
| 57 | enum h3_err err; |
| 58 | uint32_t flags; |
Amaury Denoyelle | 9cc4751 | 2022-05-24 16:27:41 +0200 | [diff] [blame^] | 59 | |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 60 | /* Settings */ |
| 61 | uint64_t qpack_max_table_capacity; |
| 62 | uint64_t qpack_blocked_streams; |
| 63 | uint64_t max_field_section_size; |
Amaury Denoyelle | 9cc4751 | 2022-05-24 16:27:41 +0200 | [diff] [blame^] | 64 | |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 65 | struct buffer_wait buf_wait; /* wait list for buffer allocations */ |
| 66 | }; |
| 67 | |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 68 | DECLARE_STATIC_POOL(pool_head_h3c, "h3c", sizeof(struct h3c)); |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 69 | |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 70 | #define H3_SF_UNI_INIT 0x00000001 /* stream type not parsed for unidirectional stream */ |
Amaury Denoyelle | fc99a69 | 2022-05-24 15:25:19 +0200 | [diff] [blame] | 71 | #define H3_SF_UNI_NO_H3 0x00000002 /* unidirectional stream does not carry H3 frames */ |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 72 | |
Amaury Denoyelle | 67e92d3 | 2022-04-27 18:04:01 +0200 | [diff] [blame] | 73 | struct h3s { |
Amaury Denoyelle | 3236a8e | 2022-05-24 15:24:03 +0200 | [diff] [blame] | 74 | enum h3s_t type; |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 75 | int demux_frame_len; |
| 76 | int demux_frame_type; |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 77 | |
| 78 | int flags; |
Amaury Denoyelle | 67e92d3 | 2022-04-27 18:04:01 +0200 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | DECLARE_STATIC_POOL(pool_head_h3s, "h3s", sizeof(struct h3s)); |
| 82 | |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 83 | /* Simple function to duplicate a buffer */ |
Amaury Denoyelle | c7dd9d6 | 2022-05-24 18:14:28 +0200 | [diff] [blame] | 84 | static inline struct buffer h3_b_dup(const struct ncbuf *b) |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 85 | { |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 86 | return b_make(ncb_orig(b), b->size, b->head, ncb_data(b, 0)); |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 87 | } |
| 88 | |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 89 | /* Initialize an uni-stream <qcs> by reading its type from <rxbuf>. |
| 90 | * |
| 91 | * Returns 0 on success else non-zero. |
| 92 | */ |
| 93 | static int h3_init_uni_stream(struct h3c *h3c, struct qcs *qcs, |
| 94 | struct ncbuf *rxbuf) |
| 95 | { |
| 96 | /* decode unidirectional stream type */ |
| 97 | struct h3s *h3s = qcs->ctx; |
| 98 | struct buffer b; |
| 99 | uint64_t type; |
| 100 | size_t len = 0, ret; |
| 101 | |
| 102 | BUG_ON_HOT(!quic_stream_is_uni(qcs->id) || |
| 103 | h3s->flags & H3_SF_UNI_INIT); |
| 104 | |
| 105 | b = h3_b_dup(rxbuf); |
| 106 | ret = b_quic_dec_int(&type, &b, &len); |
| 107 | if (!ret) { |
| 108 | ABORT_NOW(); |
| 109 | } |
| 110 | |
| 111 | switch (type) { |
| 112 | case H3_UNI_S_T_CTRL: |
| 113 | if (h3c->flags & H3_CF_UNI_CTRL_SET) { |
| 114 | qcc_emit_cc_app(qcs->qcc, H3_STREAM_CREATION_ERROR); |
| 115 | return 1; |
| 116 | } |
| 117 | h3c->flags |= H3_CF_UNI_CTRL_SET; |
| 118 | h3s->type = H3S_T_CTRL; |
| 119 | break; |
| 120 | |
| 121 | case H3_UNI_S_T_PUSH: |
| 122 | /* TODO not supported for the moment */ |
| 123 | h3s->type = H3S_T_PUSH; |
| 124 | break; |
| 125 | |
| 126 | case H3_UNI_S_T_QPACK_DEC: |
| 127 | if (h3c->flags & H3_CF_UNI_QPACK_DEC_SET) { |
| 128 | qcc_emit_cc_app(qcs->qcc, H3_STREAM_CREATION_ERROR); |
| 129 | return 1; |
| 130 | } |
| 131 | h3c->flags |= H3_CF_UNI_QPACK_DEC_SET; |
| 132 | h3s->type = H3S_T_QPACK_DEC; |
Amaury Denoyelle | fc99a69 | 2022-05-24 15:25:19 +0200 | [diff] [blame] | 133 | h3s->flags |= H3_SF_UNI_NO_H3; |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 134 | break; |
| 135 | |
| 136 | case H3_UNI_S_T_QPACK_ENC: |
| 137 | if (h3c->flags & H3_CF_UNI_QPACK_ENC_SET) { |
| 138 | qcc_emit_cc_app(qcs->qcc, H3_STREAM_CREATION_ERROR); |
| 139 | return 1; |
| 140 | } |
| 141 | h3c->flags |= H3_CF_UNI_QPACK_ENC_SET; |
| 142 | h3s->type = H3S_T_QPACK_ENC; |
Amaury Denoyelle | fc99a69 | 2022-05-24 15:25:19 +0200 | [diff] [blame] | 143 | h3s->flags |= H3_SF_UNI_NO_H3; |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 144 | break; |
| 145 | |
| 146 | default: |
Amaury Denoyelle | fc99a69 | 2022-05-24 15:25:19 +0200 | [diff] [blame] | 147 | h3s->flags |= H3_SF_UNI_NO_H3; |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 148 | break; |
| 149 | }; |
| 150 | |
| 151 | h3s->flags |= H3_SF_UNI_INIT; |
| 152 | qcs_consume(qcs, len); |
| 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
Amaury Denoyelle | fc99a69 | 2022-05-24 15:25:19 +0200 | [diff] [blame] | 157 | /* Parse an uni-stream <qcs> from <rxbuf> which does not contains H3 frames. |
| 158 | * This may be used for QPACK encoder/decoder streams for example. |
| 159 | * |
| 160 | * Returns 0 on success else non-zero. |
| 161 | */ |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 162 | static int h3_parse_uni_stream_no_h3(struct qcs *qcs, struct ncbuf *rxbuf) |
Amaury Denoyelle | fc99a69 | 2022-05-24 15:25:19 +0200 | [diff] [blame] | 163 | { |
Amaury Denoyelle | fc99a69 | 2022-05-24 15:25:19 +0200 | [diff] [blame] | 164 | struct h3s *h3s = qcs->ctx; |
| 165 | |
| 166 | BUG_ON_HOT(!quic_stream_is_uni(qcs->id) || |
| 167 | !(h3s->flags & H3_SF_UNI_NO_H3)); |
| 168 | |
| 169 | switch (h3s->type) { |
| 170 | case H3S_T_QPACK_DEC: |
| 171 | if (!qpack_decode_dec(qcs, NULL)) |
| 172 | return 1; |
| 173 | break; |
| 174 | case H3S_T_QPACK_ENC: |
| 175 | if (!qpack_decode_enc(qcs, NULL)) |
| 176 | return 1; |
| 177 | break; |
| 178 | default: |
| 179 | /* unknown uni stream : just consume it. */ |
| 180 | qcs_consume(qcs, ncb_data(rxbuf, 0)); |
| 181 | break; |
| 182 | } |
| 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 187 | /* Decode a h3 frame header made of two QUIC varints from <b> buffer. |
| 188 | * Returns the number of bytes consumed if there was enough data in <b>, 0 if not. |
| 189 | * Note that this function update <b> buffer to reflect the number of bytes consumed |
| 190 | * to decode the h3 frame header. |
| 191 | */ |
| 192 | static inline size_t h3_decode_frm_header(uint64_t *ftype, uint64_t *flen, |
| 193 | struct buffer *b) |
| 194 | { |
| 195 | size_t hlen; |
| 196 | |
| 197 | hlen = 0; |
| 198 | if (!b_quic_dec_int(ftype, b, &hlen) || !b_quic_dec_int(flen, b, &hlen)) |
| 199 | return 0; |
| 200 | |
| 201 | return hlen; |
| 202 | } |
| 203 | |
Amaury Denoyelle | 302ecd4 | 2022-05-24 15:24:32 +0200 | [diff] [blame] | 204 | /* Check if H3 frame of type <ftype> is valid when received on stream <qcs>. |
| 205 | * |
| 206 | * Returns a boolean. If false, a connection error H3_FRAME_UNEXPECTED should |
| 207 | * be reported. |
| 208 | */ |
| 209 | static int h3_is_frame_valid(struct h3c *h3c, struct qcs *qcs, uint64_t ftype) |
| 210 | { |
| 211 | struct h3s *h3s = qcs->ctx; |
| 212 | const uint64_t id = qcs->id; |
| 213 | |
| 214 | BUG_ON_HOT(h3s->type == H3S_T_UNKNOWN); |
| 215 | |
| 216 | switch (ftype) { |
| 217 | case H3_FT_DATA: |
| 218 | case H3_FT_HEADERS: |
| 219 | return h3s->type != H3S_T_CTRL; |
| 220 | |
| 221 | case H3_FT_CANCEL_PUSH: |
| 222 | case H3_FT_GOAWAY: |
| 223 | case H3_FT_MAX_PUSH_ID: |
| 224 | /* Only allowed for control stream. First frame of control |
| 225 | * stream MUST be SETTINGS. |
| 226 | */ |
| 227 | return h3s->type == H3S_T_CTRL && |
| 228 | (h3c->flags & H3_CF_SETTINGS_RECV); |
| 229 | |
| 230 | case H3_FT_SETTINGS: |
| 231 | /* draft-ietf-quic-http34 7.2.4. SETTINGS |
| 232 | * |
| 233 | * If an endpoint receives a second SETTINGS frame on the control |
| 234 | * stream, the endpoint MUST respond with a connection error of type |
| 235 | * H3_FRAME_UNEXPECTED. |
| 236 | */ |
| 237 | return h3s->type == H3S_T_CTRL && |
| 238 | !(h3c->flags & H3_CF_SETTINGS_RECV); |
| 239 | |
| 240 | case H3_FT_PUSH_PROMISE: |
| 241 | return h3s->type != H3S_T_CTRL && |
| 242 | (id & QCS_ID_SRV_INTIATOR_BIT); |
| 243 | |
| 244 | default: |
| 245 | /* draft-ietf-quic-http34 9. Extensions to HTTP/3 |
| 246 | * |
| 247 | * Implementations MUST discard frames [...] that have unknown |
| 248 | * or unsupported types. |
| 249 | */ |
| 250 | return h3s->type != H3S_T_CTRL || (h3c->flags & H3_CF_SETTINGS_RECV); |
| 251 | } |
| 252 | } |
| 253 | |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 254 | /* Parse from buffer <buf> a H3 HEADERS frame of length <len>. Data are copied |
| 255 | * in a local HTX buffer and transfer to the conn-stream layer. <fin> must be |
| 256 | * set if this is the last data to transfer from this stream. |
| 257 | * |
Amaury Denoyelle | 314578a | 2022-04-27 14:52:52 +0200 | [diff] [blame] | 258 | * Returns the number of bytes handled or a negative error code. |
Amaury Denoyelle | b9ce14e | 2021-11-08 09:13:42 +0100 | [diff] [blame] | 259 | */ |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 260 | static int h3_headers_to_htx(struct qcs *qcs, struct ncbuf *buf, uint64_t len, |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 261 | char fin) |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 262 | { |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 263 | struct buffer htx_buf = BUF_NULL; |
| 264 | struct buffer *tmp = get_trash_chunk(); |
Amaury Denoyelle | 7059ebc | 2021-12-08 15:51:04 +0100 | [diff] [blame] | 265 | struct htx *htx = NULL; |
Amaury Denoyelle | b49fa1a | 2021-08-24 15:30:12 +0200 | [diff] [blame] | 266 | struct htx_sl *sl; |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 267 | struct http_hdr list[global.tune.max_http_hdr]; |
Amaury Denoyelle | b49fa1a | 2021-08-24 15:30:12 +0200 | [diff] [blame] | 268 | unsigned int flags = HTX_SL_F_NONE; |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 269 | struct ist meth = IST_NULL, path = IST_NULL; |
| 270 | //struct ist scheme = IST_NULL, authority = IST_NULL; |
| 271 | struct ist authority = IST_NULL; |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 272 | int hdr_idx; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 273 | |
Amaury Denoyelle | 30f23f5 | 2022-04-27 14:41:53 +0200 | [diff] [blame] | 274 | /* TODO support buffer wrapping */ |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 275 | BUG_ON(ncb_head(buf) + len >= ncb_wrap(buf)); |
| 276 | if (qpack_decode_fs((const unsigned char *)ncb_head(buf), len, tmp, list) < 0) |
Amaury Denoyelle | 314578a | 2022-04-27 14:52:52 +0200 | [diff] [blame] | 277 | return -1; |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 278 | |
| 279 | qc_get_buf(qcs, &htx_buf); |
| 280 | BUG_ON(!b_size(&htx_buf)); |
| 281 | htx = htx_from_buf(&htx_buf); |
| 282 | |
| 283 | /* first treat pseudo-header to build the start line */ |
| 284 | hdr_idx = 0; |
| 285 | while (1) { |
| 286 | if (isteq(list[hdr_idx].n, ist(""))) |
| 287 | break; |
| 288 | |
| 289 | if (istmatch(list[hdr_idx].n, ist(":"))) { |
| 290 | /* pseudo-header */ |
| 291 | if (isteq(list[hdr_idx].n, ist(":method"))) |
| 292 | meth = list[hdr_idx].v; |
| 293 | else if (isteq(list[hdr_idx].n, ist(":path"))) |
| 294 | path = list[hdr_idx].v; |
| 295 | //else if (isteq(list[hdr_idx].n, ist(":scheme"))) |
| 296 | // scheme = list[hdr_idx].v; |
| 297 | else if (isteq(list[hdr_idx].n, ist(":authority"))) |
| 298 | authority = list[hdr_idx].v; |
| 299 | } |
| 300 | |
| 301 | ++hdr_idx; |
| 302 | } |
| 303 | |
| 304 | flags |= HTX_SL_F_VER_11; |
Amaury Denoyelle | 0fa14a6 | 2022-04-26 16:24:39 +0200 | [diff] [blame] | 305 | flags |= HTX_SL_F_XFER_LEN; |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 306 | |
| 307 | sl = htx_add_stline(htx, HTX_BLK_REQ_SL, flags, meth, path, ist("HTTP/3.0")); |
| 308 | if (!sl) |
Amaury Denoyelle | 314578a | 2022-04-27 14:52:52 +0200 | [diff] [blame] | 309 | return -1; |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 310 | |
| 311 | if (fin) |
| 312 | sl->flags |= HTX_SL_F_BODYLESS; |
| 313 | |
| 314 | sl->info.req.meth = find_http_meth(meth.ptr, meth.len); |
| 315 | BUG_ON(sl->info.req.meth == HTTP_METH_OTHER); |
| 316 | |
| 317 | if (isttest(authority)) |
| 318 | htx_add_header(htx, ist("host"), authority); |
| 319 | |
| 320 | /* now treat standard headers */ |
| 321 | hdr_idx = 0; |
| 322 | while (1) { |
| 323 | if (isteq(list[hdr_idx].n, ist(""))) |
| 324 | break; |
| 325 | |
| 326 | if (!istmatch(list[hdr_idx].n, ist(":"))) |
| 327 | htx_add_header(htx, list[hdr_idx].n, list[hdr_idx].v); |
| 328 | |
| 329 | ++hdr_idx; |
| 330 | } |
| 331 | |
| 332 | htx_add_endof(htx, HTX_BLK_EOH); |
| 333 | htx_to_buf(htx, &htx_buf); |
| 334 | |
| 335 | if (fin) |
| 336 | htx->flags |= HTX_FL_EOM; |
| 337 | |
Willy Tarreau | 01c2a4a | 2022-05-10 15:46:10 +0200 | [diff] [blame] | 338 | if (!qc_attach_cs(qcs, &htx_buf)) |
Amaury Denoyelle | 314578a | 2022-04-27 14:52:52 +0200 | [diff] [blame] | 339 | return -1; |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 340 | |
| 341 | /* buffer is transferred to conn_stream and set to NULL |
| 342 | * except on stream creation error. |
| 343 | */ |
| 344 | b_free(&htx_buf); |
| 345 | offer_buffers(NULL, 1); |
| 346 | |
Amaury Denoyelle | 314578a | 2022-04-27 14:52:52 +0200 | [diff] [blame] | 347 | return len; |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 348 | } |
| 349 | |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 350 | /* Copy from buffer <buf> a H3 DATA frame of length <len> in QUIC stream <qcs> |
| 351 | * HTX buffer. <fin> must be set if this is the last data to transfer from this |
| 352 | * stream. |
| 353 | * |
Amaury Denoyelle | 314578a | 2022-04-27 14:52:52 +0200 | [diff] [blame] | 354 | * Returns the number of bytes handled or a negative error code. |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 355 | */ |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 356 | static int h3_data_to_htx(struct qcs *qcs, struct ncbuf *buf, uint64_t len, |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 357 | char fin) |
| 358 | { |
| 359 | struct buffer *appbuf; |
| 360 | struct htx *htx = NULL; |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 361 | size_t htx_sent = 0; |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 362 | int htx_space; |
Amaury Denoyelle | 30f23f5 | 2022-04-27 14:41:53 +0200 | [diff] [blame] | 363 | char *head; |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 364 | |
| 365 | appbuf = qc_get_buf(qcs, &qcs->rx.app_buf); |
| 366 | BUG_ON(!appbuf); |
| 367 | htx = htx_from_buf(appbuf); |
| 368 | |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 369 | if (len > ncb_data(buf, 0)) { |
| 370 | len = ncb_data(buf, 0); |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 371 | fin = 0; |
| 372 | } |
| 373 | |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 374 | head = ncb_head(buf); |
Amaury Denoyelle | 30f23f5 | 2022-04-27 14:41:53 +0200 | [diff] [blame] | 375 | retry: |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 376 | htx_space = htx_free_data_space(htx); |
Amaury Denoyelle | f1fc0b3 | 2022-05-02 11:07:06 +0200 | [diff] [blame] | 377 | if (!htx_space) { |
| 378 | qcs->flags |= QC_SF_DEM_FULL; |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 379 | goto out; |
Amaury Denoyelle | f1fc0b3 | 2022-05-02 11:07:06 +0200 | [diff] [blame] | 380 | } |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 381 | |
| 382 | if (len > htx_space) { |
| 383 | len = htx_space; |
| 384 | fin = 0; |
Amaury Denoyelle | ff191de | 2022-02-21 18:38:29 +0100 | [diff] [blame] | 385 | } |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 386 | |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 387 | if (head + len > ncb_wrap(buf)) { |
| 388 | size_t contig = ncb_wrap(buf) - head; |
| 389 | htx_sent = htx_add_data(htx, ist2(ncb_head(buf), contig)); |
Amaury Denoyelle | 73d6ffe | 2022-05-16 13:54:31 +0200 | [diff] [blame] | 390 | if (htx_sent < contig) { |
| 391 | qcs->flags |= QC_SF_DEM_FULL; |
| 392 | goto out; |
| 393 | } |
| 394 | |
Amaury Denoyelle | 30f23f5 | 2022-04-27 14:41:53 +0200 | [diff] [blame] | 395 | len -= contig; |
Amaury Denoyelle | 73d6ffe | 2022-05-16 13:54:31 +0200 | [diff] [blame] | 396 | head = ncb_orig(buf); |
Amaury Denoyelle | 30f23f5 | 2022-04-27 14:41:53 +0200 | [diff] [blame] | 397 | goto retry; |
Amaury Denoyelle | ff191de | 2022-02-21 18:38:29 +0100 | [diff] [blame] | 398 | } |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 399 | |
Amaury Denoyelle | 30f23f5 | 2022-04-27 14:41:53 +0200 | [diff] [blame] | 400 | htx_sent += htx_add_data(htx, ist2(head, len)); |
Amaury Denoyelle | 73d6ffe | 2022-05-16 13:54:31 +0200 | [diff] [blame] | 401 | if (htx_sent < len) { |
| 402 | qcs->flags |= QC_SF_DEM_FULL; |
| 403 | goto out; |
| 404 | } |
Amaury Denoyelle | 30f23f5 | 2022-04-27 14:41:53 +0200 | [diff] [blame] | 405 | |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 406 | if (fin && len == htx_sent) |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 407 | htx->flags |= HTX_FL_EOM; |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 408 | |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 409 | out: |
| 410 | htx_to_buf(htx, appbuf); |
Amaury Denoyelle | 314578a | 2022-04-27 14:52:52 +0200 | [diff] [blame] | 411 | return htx_sent; |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 412 | } |
| 413 | |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 414 | /* Parse a SETTINGS frame which must not be truncated with <flen> as length from |
| 415 | * <rxbuf> buffer. This function does not update this buffer. |
| 416 | * |
| 417 | * Returns 0 on success else non-zero. |
| 418 | */ |
| 419 | static int h3_parse_settings_frm(struct h3c *h3c, const struct ncbuf *rxbuf, size_t flen) |
| 420 | { |
| 421 | uint64_t id, value; |
| 422 | const unsigned char *buf, *end; |
| 423 | |
| 424 | buf = (const unsigned char *)ncb_head(rxbuf); |
| 425 | end = buf + flen; |
| 426 | |
| 427 | while (buf < end) { |
| 428 | if (!quic_dec_int(&id, &buf, end) || !quic_dec_int(&value, &buf, end)) |
| 429 | return 1; |
| 430 | |
| 431 | h3_debug_printf(stderr, "%s id: %llu value: %llu\n", |
| 432 | __func__, (unsigned long long)id, (unsigned long long)value); |
| 433 | switch (id) { |
| 434 | case H3_SETTINGS_QPACK_MAX_TABLE_CAPACITY: |
| 435 | h3c->qpack_max_table_capacity = value; |
| 436 | break; |
| 437 | case H3_SETTINGS_MAX_FIELD_SECTION_SIZE: |
| 438 | h3c->max_field_section_size = value; |
| 439 | break; |
| 440 | case H3_SETTINGS_QPACK_BLOCKED_STREAMS: |
| 441 | h3c->qpack_blocked_streams = value; |
| 442 | break; |
| 443 | case H3_SETTINGS_RESERVED_2 ... H3_SETTINGS_RESERVED_5: |
| 444 | h3c->err = H3_SETTINGS_ERROR; |
| 445 | return 1; |
| 446 | default: |
| 447 | /* MUST be ignored */ |
| 448 | break; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 455 | /* Decode <qcs> remotely initiated bidi-stream. <fin> must be set to indicate |
| 456 | * that we received the last data of the stream. |
Amaury Denoyelle | 0ffd6e7 | 2022-05-24 11:07:28 +0200 | [diff] [blame] | 457 | * |
| 458 | * Returns 0 on success else non-zero. |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 459 | */ |
| 460 | static int h3_decode_qcs(struct qcs *qcs, int fin, void *ctx) |
| 461 | { |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 462 | struct ncbuf *rxbuf = &qcs->rx.ncbuf; |
Amaury Denoyelle | 302ecd4 | 2022-05-24 15:24:32 +0200 | [diff] [blame] | 463 | struct h3c *h3c = ctx; |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 464 | struct h3s *h3s = qcs->ctx; |
Amaury Denoyelle | 314578a | 2022-04-27 14:52:52 +0200 | [diff] [blame] | 465 | ssize_t ret; |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 466 | |
Amaury Denoyelle | bb97042 | 2022-04-12 16:40:52 +0200 | [diff] [blame] | 467 | h3_debug_printf(stderr, "%s: STREAM ID: %lu\n", __func__, qcs->id); |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 468 | if (!ncb_data(rxbuf, 0)) |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 469 | return 0; |
| 470 | |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 471 | if (quic_stream_is_uni(qcs->id) && !(h3s->flags & H3_SF_UNI_INIT)) { |
| 472 | if (h3_init_uni_stream(h3c, qcs, rxbuf)) |
| 473 | return 1; |
| 474 | } |
| 475 | |
| 476 | if (quic_stream_is_uni(qcs->id) && (h3s->flags & H3_SF_UNI_NO_H3)) { |
| 477 | /* For non-h3 STREAM, parse it and return immediately. */ |
| 478 | if (h3_parse_uni_stream_no_h3(qcs, rxbuf)) |
| 479 | return 1; |
| 480 | return 0; |
| 481 | } |
| 482 | |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 483 | while (ncb_data(rxbuf, 0) && !(qcs->flags & QC_SF_DEM_FULL)) { |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 484 | uint64_t ftype, flen; |
| 485 | struct buffer b; |
Amaury Denoyelle | 95b93a3 | 2022-02-14 15:49:53 +0100 | [diff] [blame] | 486 | char last_stream_frame = 0; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 487 | |
| 488 | /* Work on a copy of <rxbuf> */ |
| 489 | b = h3_b_dup(rxbuf); |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 490 | if (!h3s->demux_frame_len) { |
| 491 | size_t hlen = h3_decode_frm_header(&ftype, &flen, &b); |
| 492 | if (!hlen) |
| 493 | break; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 494 | |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 495 | h3_debug_printf(stderr, "%s: ftype: %lu, flen: %lu\n", |
| 496 | __func__, ftype, flen); |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 497 | |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 498 | h3s->demux_frame_type = ftype; |
| 499 | h3s->demux_frame_len = flen; |
Amaury Denoyelle | a977355 | 2022-05-16 14:38:25 +0200 | [diff] [blame] | 500 | qcs_consume(qcs, hlen); |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 501 | } |
Amaury Denoyelle | 0484f92 | 2022-02-15 16:59:39 +0100 | [diff] [blame] | 502 | |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 503 | flen = h3s->demux_frame_len; |
| 504 | ftype = h3s->demux_frame_type; |
Amaury Denoyelle | 80097cc | 2022-05-24 11:13:46 +0200 | [diff] [blame] | 505 | |
Amaury Denoyelle | 302ecd4 | 2022-05-24 15:24:32 +0200 | [diff] [blame] | 506 | if (!h3_is_frame_valid(h3c, qcs, ftype)) { |
| 507 | qcc_emit_cc_app(qcs->qcc, H3_FRAME_UNEXPECTED); |
| 508 | return 1; |
| 509 | } |
| 510 | |
Amaury Denoyelle | 80097cc | 2022-05-24 11:13:46 +0200 | [diff] [blame] | 511 | /* Do not demux incomplete frames except H3 DATA which can be |
| 512 | * fragmented in multiple HTX blocks. |
| 513 | */ |
| 514 | if (flen > b_data(&b) && ftype != H3_FT_DATA) { |
| 515 | /* Reject frames bigger than bufsize. |
| 516 | * |
| 517 | * TODO HEADERS should in complement be limited with H3 |
| 518 | * SETTINGS_MAX_FIELD_SECTION_SIZE parameter to prevent |
| 519 | * excessive decompressed size. |
| 520 | */ |
| 521 | if (flen > ncb_size(rxbuf)) { |
| 522 | qcc_emit_cc_app(qcs->qcc, H3_EXCESSIVE_LOAD); |
| 523 | return 1; |
| 524 | } |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 525 | break; |
Amaury Denoyelle | b5454d4 | 2022-05-12 16:56:16 +0200 | [diff] [blame] | 526 | } |
Amaury Denoyelle | 80097cc | 2022-05-24 11:13:46 +0200 | [diff] [blame] | 527 | |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 528 | last_stream_frame = (fin && flen == ncb_total_data(rxbuf)); |
Amaury Denoyelle | 95b93a3 | 2022-02-14 15:49:53 +0100 | [diff] [blame] | 529 | |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 530 | switch (ftype) { |
| 531 | case H3_FT_DATA: |
Amaury Denoyelle | 31e4f6e | 2022-02-15 17:30:27 +0100 | [diff] [blame] | 532 | ret = h3_data_to_htx(qcs, rxbuf, flen, last_stream_frame); |
| 533 | /* TODO handle error reporting. Stream closure required. */ |
Amaury Denoyelle | 314578a | 2022-04-27 14:52:52 +0200 | [diff] [blame] | 534 | if (ret < 0) { ABORT_NOW(); } |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 535 | break; |
| 536 | case H3_FT_HEADERS: |
Amaury Denoyelle | 31e4f6e | 2022-02-15 17:30:27 +0100 | [diff] [blame] | 537 | ret = h3_headers_to_htx(qcs, rxbuf, flen, last_stream_frame); |
| 538 | /* TODO handle error reporting. Stream closure required. */ |
Amaury Denoyelle | 314578a | 2022-04-27 14:52:52 +0200 | [diff] [blame] | 539 | if (ret < 0) { ABORT_NOW(); } |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 540 | break; |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 541 | case H3_FT_CANCEL_PUSH: |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 542 | case H3_FT_PUSH_PROMISE: |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 543 | case H3_FT_MAX_PUSH_ID: |
| 544 | case H3_FT_GOAWAY: |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 545 | /* Not supported */ |
Amaury Denoyelle | 80097cc | 2022-05-24 11:13:46 +0200 | [diff] [blame] | 546 | ret = flen; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 547 | break; |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 548 | case H3_FT_SETTINGS: |
| 549 | if (h3_parse_settings_frm(qcs->qcc->ctx, rxbuf, flen)) |
| 550 | return 1; |
| 551 | ret = flen; |
| 552 | break; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 553 | default: |
Amaury Denoyelle | d1acaf9 | 2021-11-15 15:52:55 +0100 | [diff] [blame] | 554 | /* draft-ietf-quic-http34 9. Extensions to HTTP/3 |
Amaury Denoyelle | 302ecd4 | 2022-05-24 15:24:32 +0200 | [diff] [blame] | 555 | * |
| 556 | * Implementations MUST discard frames [...] that have unknown |
| 557 | * or unsupported types. |
Amaury Denoyelle | d1acaf9 | 2021-11-15 15:52:55 +0100 | [diff] [blame] | 558 | */ |
| 559 | h3_debug_printf(stderr, "ignore unknown frame type 0x%lx\n", ftype); |
Amaury Denoyelle | 80097cc | 2022-05-24 11:13:46 +0200 | [diff] [blame] | 560 | ret = flen; |
| 561 | break; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 562 | } |
Amaury Denoyelle | 314578a | 2022-04-27 14:52:52 +0200 | [diff] [blame] | 563 | |
Amaury Denoyelle | 291ee25 | 2022-05-02 10:35:39 +0200 | [diff] [blame] | 564 | if (ret) { |
Amaury Denoyelle | 291ee25 | 2022-05-02 10:35:39 +0200 | [diff] [blame] | 565 | BUG_ON(h3s->demux_frame_len < ret); |
| 566 | h3s->demux_frame_len -= ret; |
Amaury Denoyelle | a977355 | 2022-05-16 14:38:25 +0200 | [diff] [blame] | 567 | qcs_consume(qcs, ret); |
Amaury Denoyelle | 291ee25 | 2022-05-02 10:35:39 +0200 | [diff] [blame] | 568 | } |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 569 | } |
| 570 | |
Amaury Denoyelle | 03cc62c | 2022-04-27 16:53:16 +0200 | [diff] [blame] | 571 | /* TODO may be useful to wakeup the MUX if blocked due to full buffer. |
| 572 | * However, currently, io-cb of MUX does not handle Rx. |
| 573 | */ |
| 574 | |
Amaury Denoyelle | b9ce14e | 2021-11-08 09:13:42 +0100 | [diff] [blame] | 575 | return 0; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 576 | } |
| 577 | |
Amaury Denoyelle | a587136 | 2021-10-07 16:26:12 +0200 | [diff] [blame] | 578 | /* Returns buffer for data sending. |
| 579 | * May be NULL if the allocation failed. |
| 580 | */ |
| 581 | static struct buffer *mux_get_buf(struct qcs *qcs) |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 582 | { |
Amaury Denoyelle | a587136 | 2021-10-07 16:26:12 +0200 | [diff] [blame] | 583 | if (!b_size(&qcs->tx.buf)) |
| 584 | b_alloc(&qcs->tx.buf); |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 585 | |
Amaury Denoyelle | a587136 | 2021-10-07 16:26:12 +0200 | [diff] [blame] | 586 | return &qcs->tx.buf; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 587 | } |
| 588 | |
Amaury Denoyelle | 6b92394 | 2022-05-23 14:25:53 +0200 | [diff] [blame] | 589 | /* Function used to emit stream data from <qcs> control uni-stream */ |
| 590 | static int h3_control_send(struct qcs *qcs, void *ctx) |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 591 | { |
| 592 | int ret; |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 593 | struct h3c *h3c = ctx; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 594 | unsigned char data[(2 + 3) * 2 * QUIC_VARINT_MAX_SIZE]; /* enough for 3 settings */ |
Amaury Denoyelle | a587136 | 2021-10-07 16:26:12 +0200 | [diff] [blame] | 595 | struct buffer pos, *res; |
Amaury Denoyelle | 65df3ad | 2022-05-24 15:06:10 +0200 | [diff] [blame] | 596 | size_t frm_len; |
Amaury Denoyelle | 65df3ad | 2022-05-24 15:06:10 +0200 | [diff] [blame] | 597 | |
| 598 | BUG_ON_HOT(h3c->flags & H3_CF_SETTINGS_SENT); |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 599 | |
| 600 | ret = 0; |
Amaury Denoyelle | a587136 | 2021-10-07 16:26:12 +0200 | [diff] [blame] | 601 | pos = b_make((char *)data, sizeof(data), 0, 0); |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 602 | |
Amaury Denoyelle | 65df3ad | 2022-05-24 15:06:10 +0200 | [diff] [blame] | 603 | frm_len = quic_int_getsize(H3_SETTINGS_QPACK_MAX_TABLE_CAPACITY) + |
| 604 | quic_int_getsize(h3_settings_qpack_max_table_capacity) + |
| 605 | quic_int_getsize(H3_SETTINGS_QPACK_BLOCKED_STREAMS) + |
| 606 | quic_int_getsize(h3_settings_qpack_blocked_streams); |
| 607 | if (h3_settings_max_field_section_size) { |
| 608 | frm_len += quic_int_getsize(H3_SETTINGS_MAX_FIELD_SECTION_SIZE) + |
| 609 | quic_int_getsize(h3_settings_max_field_section_size); |
| 610 | } |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 611 | |
Amaury Denoyelle | 65df3ad | 2022-05-24 15:06:10 +0200 | [diff] [blame] | 612 | b_quic_enc_int(&pos, H3_UNI_S_T_CTRL); |
| 613 | /* Build a SETTINGS frame */ |
| 614 | b_quic_enc_int(&pos, H3_FT_SETTINGS); |
| 615 | b_quic_enc_int(&pos, frm_len); |
| 616 | b_quic_enc_int(&pos, H3_SETTINGS_QPACK_MAX_TABLE_CAPACITY); |
| 617 | b_quic_enc_int(&pos, h3_settings_qpack_max_table_capacity); |
| 618 | b_quic_enc_int(&pos, H3_SETTINGS_QPACK_BLOCKED_STREAMS); |
| 619 | b_quic_enc_int(&pos, h3_settings_qpack_blocked_streams); |
| 620 | if (h3_settings_max_field_section_size) { |
| 621 | b_quic_enc_int(&pos, H3_SETTINGS_MAX_FIELD_SECTION_SIZE); |
| 622 | b_quic_enc_int(&pos, h3_settings_max_field_section_size); |
| 623 | } |
Amaury Denoyelle | a587136 | 2021-10-07 16:26:12 +0200 | [diff] [blame] | 624 | |
Amaury Denoyelle | 65df3ad | 2022-05-24 15:06:10 +0200 | [diff] [blame] | 625 | res = mux_get_buf(qcs); |
| 626 | if (b_room(res) < b_data(&pos)) { |
| 627 | // TODO the mux should be put in blocked state, with |
| 628 | // the stream in state waiting for settings to be sent |
| 629 | ABORT_NOW(); |
| 630 | } |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 631 | |
Amaury Denoyelle | 65df3ad | 2022-05-24 15:06:10 +0200 | [diff] [blame] | 632 | ret = b_force_xfer(res, &pos, b_data(&pos)); |
| 633 | if (ret > 0) { |
| 634 | h3c->flags |= H3_CF_SETTINGS_SENT; |
| 635 | if (!(qcs->qcc->wait_event.events & SUB_RETRY_SEND)) |
| 636 | tasklet_wakeup(qcs->qcc->wait_event.tasklet); |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | return ret; |
| 640 | } |
| 641 | |
Amaury Denoyelle | 15b0961 | 2021-08-24 16:20:27 +0200 | [diff] [blame] | 642 | static int h3_resp_headers_send(struct qcs *qcs, struct htx *htx) |
| 643 | { |
| 644 | struct buffer outbuf; |
| 645 | struct buffer headers_buf = BUF_NULL; |
| 646 | struct buffer *res; |
| 647 | struct http_hdr list[global.tune.max_http_hdr]; |
| 648 | struct htx_sl *sl; |
| 649 | struct htx_blk *blk; |
| 650 | enum htx_blk_type type; |
| 651 | int frame_length_size; /* size in bytes of frame length varint field */ |
| 652 | int ret = 0; |
| 653 | int hdr; |
| 654 | int status = 0; |
| 655 | |
| 656 | sl = NULL; |
| 657 | hdr = 0; |
| 658 | for (blk = htx_get_head_blk(htx); blk; blk = htx_get_next_blk(htx, blk)) { |
| 659 | type = htx_get_blk_type(blk); |
| 660 | |
| 661 | if (type == HTX_BLK_UNUSED) |
| 662 | continue; |
| 663 | |
| 664 | if (type == HTX_BLK_EOH) |
| 665 | break; |
| 666 | |
| 667 | if (type == HTX_BLK_RES_SL) { |
| 668 | /* start-line -> HEADERS h3 frame */ |
| 669 | BUG_ON(sl); |
| 670 | sl = htx_get_blk_ptr(htx, blk); |
| 671 | /* TODO should be on h3 layer */ |
| 672 | status = sl->info.res.status; |
| 673 | } |
| 674 | else if (type == HTX_BLK_HDR) { |
| 675 | list[hdr].n = htx_get_blk_name(htx, blk); |
| 676 | list[hdr].v = htx_get_blk_value(htx, blk); |
| 677 | hdr++; |
| 678 | } |
| 679 | else { |
| 680 | ABORT_NOW(); |
| 681 | goto err; |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | BUG_ON(!sl); |
| 686 | |
| 687 | list[hdr].n = ist(""); |
| 688 | |
Amaury Denoyelle | d3d97c6 | 2021-10-05 11:45:58 +0200 | [diff] [blame] | 689 | res = mux_get_buf(qcs); |
Amaury Denoyelle | 15b0961 | 2021-08-24 16:20:27 +0200 | [diff] [blame] | 690 | |
| 691 | /* At least 5 bytes to store frame type + length as a varint max size */ |
| 692 | if (b_room(res) < 5) |
| 693 | ABORT_NOW(); |
| 694 | |
| 695 | b_reset(&outbuf); |
| 696 | outbuf = b_make(b_tail(res), b_contig_space(res), 0, 0); |
| 697 | /* Start the headers after frame type + length */ |
| 698 | headers_buf = b_make(b_head(res) + 5, b_size(res) - 5, 0, 0); |
| 699 | |
| 700 | if (qpack_encode_field_section_line(&headers_buf)) |
| 701 | ABORT_NOW(); |
| 702 | if (qpack_encode_int_status(&headers_buf, status)) |
| 703 | ABORT_NOW(); |
| 704 | |
| 705 | for (hdr = 0; hdr < sizeof(list) / sizeof(list[0]); ++hdr) { |
| 706 | if (isteq(list[hdr].n, ist(""))) |
| 707 | break; |
| 708 | |
Amaury Denoyelle | ffafb3d | 2022-02-15 16:10:42 +0100 | [diff] [blame] | 709 | /* draft-ietf-quic-http34 4.1. HTTP Message Exchanges |
| 710 | * Transfer codings (see Section 6.1 of [HTTP11]) are not |
| 711 | * defined for HTTP/3; the Transfer-Encoding header field MUST |
| 712 | * NOT be used. |
| 713 | */ |
| 714 | if (isteq(list[hdr].n, ist("transfer-encoding"))) |
| 715 | continue; |
| 716 | |
Amaury Denoyelle | 15b0961 | 2021-08-24 16:20:27 +0200 | [diff] [blame] | 717 | if (qpack_encode_header(&headers_buf, list[hdr].n, list[hdr].v)) |
| 718 | ABORT_NOW(); |
| 719 | } |
| 720 | |
| 721 | /* Now that all headers are encoded, we are certain that res buffer is |
| 722 | * big enough |
| 723 | */ |
| 724 | frame_length_size = quic_int_getsize(b_data(&headers_buf)); |
| 725 | res->head += 4 - frame_length_size; |
| 726 | b_putchr(res, 0x01); /* h3 HEADERS frame type */ |
| 727 | if (!b_quic_enc_int(res, b_data(&headers_buf))) |
| 728 | ABORT_NOW(); |
| 729 | b_add(res, b_data(&headers_buf)); |
| 730 | |
| 731 | ret = 0; |
| 732 | blk = htx_get_head_blk(htx); |
| 733 | while (blk) { |
| 734 | type = htx_get_blk_type(blk); |
| 735 | ret += htx_get_blksz(blk); |
| 736 | blk = htx_remove_blk(htx, blk); |
| 737 | if (type == HTX_BLK_EOH) |
| 738 | break; |
| 739 | } |
| 740 | |
| 741 | return ret; |
| 742 | |
| 743 | err: |
| 744 | return 0; |
| 745 | } |
| 746 | |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 747 | /* Returns the total of bytes sent. */ |
| 748 | static int h3_resp_data_send(struct qcs *qcs, struct buffer *buf, size_t count) |
| 749 | { |
| 750 | struct buffer outbuf; |
| 751 | struct buffer *res; |
| 752 | size_t total = 0; |
| 753 | struct htx *htx; |
Amaury Denoyelle | a543eb1 | 2021-10-06 14:53:13 +0200 | [diff] [blame] | 754 | int bsize, fsize, hsize; |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 755 | struct htx_blk *blk; |
| 756 | enum htx_blk_type type; |
| 757 | |
| 758 | htx = htx_from_buf(buf); |
| 759 | |
| 760 | new_frame: |
| 761 | if (!count || htx_is_empty(htx)) |
| 762 | goto end; |
| 763 | |
| 764 | blk = htx_get_head_blk(htx); |
| 765 | type = htx_get_blk_type(blk); |
| 766 | fsize = bsize = htx_get_blksz(blk); |
| 767 | |
| 768 | if (type != HTX_BLK_DATA) |
| 769 | goto end; |
| 770 | |
Amaury Denoyelle | d3d97c6 | 2021-10-05 11:45:58 +0200 | [diff] [blame] | 771 | res = mux_get_buf(qcs); |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 772 | |
| 773 | if (fsize > count) |
| 774 | fsize = count; |
| 775 | |
Amaury Denoyelle | a543eb1 | 2021-10-06 14:53:13 +0200 | [diff] [blame] | 776 | /* h3 DATA headers : 1-byte frame type + varint frame length */ |
| 777 | hsize = 1 + QUIC_VARINT_MAX_SIZE; |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 778 | |
Amaury Denoyelle | a543eb1 | 2021-10-06 14:53:13 +0200 | [diff] [blame] | 779 | while (1) { |
| 780 | b_reset(&outbuf); |
| 781 | outbuf = b_make(b_tail(res), b_contig_space(res), 0, 0); |
| 782 | if (b_size(&outbuf) > hsize || !b_space_wraps(res)) |
| 783 | break; |
| 784 | b_slow_realign(res, trash.area, b_data(res)); |
| 785 | } |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 786 | |
Amaury Denoyelle | 84ea8dc | 2021-12-03 14:40:01 +0100 | [diff] [blame] | 787 | /* Not enough room for headers and at least one data byte, block the |
| 788 | * stream. It is expected that the conn-stream layer will subscribe on |
| 789 | * SEND. |
Amaury Denoyelle | a543eb1 | 2021-10-06 14:53:13 +0200 | [diff] [blame] | 790 | */ |
Amaury Denoyelle | 84ea8dc | 2021-12-03 14:40:01 +0100 | [diff] [blame] | 791 | if (b_size(&outbuf) <= hsize) { |
| 792 | qcs->flags |= QC_SF_BLK_MROOM; |
| 793 | goto end; |
| 794 | } |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 795 | |
Amaury Denoyelle | a543eb1 | 2021-10-06 14:53:13 +0200 | [diff] [blame] | 796 | if (b_size(&outbuf) < hsize + fsize) |
| 797 | fsize = b_size(&outbuf) - hsize; |
| 798 | BUG_ON(fsize <= 0); |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 799 | |
Amaury Denoyelle | a543eb1 | 2021-10-06 14:53:13 +0200 | [diff] [blame] | 800 | b_putchr(&outbuf, 0x00); /* h3 frame type = DATA */ |
| 801 | b_quic_enc_int(&outbuf, fsize); /* h3 frame length */ |
| 802 | |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 803 | b_putblk(&outbuf, htx_get_blk_ptr(htx, blk), fsize); |
Amaury Denoyelle | a543eb1 | 2021-10-06 14:53:13 +0200 | [diff] [blame] | 804 | total += fsize; |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 805 | count -= fsize; |
| 806 | |
| 807 | if (fsize == bsize) |
| 808 | htx_remove_blk(htx, blk); |
| 809 | else |
| 810 | htx_cut_data_blk(htx, blk, fsize); |
| 811 | |
Amaury Denoyelle | a543eb1 | 2021-10-06 14:53:13 +0200 | [diff] [blame] | 812 | /* commit the buffer */ |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 813 | b_add(res, b_data(&outbuf)); |
| 814 | goto new_frame; |
| 815 | |
| 816 | end: |
| 817 | return total; |
| 818 | } |
| 819 | |
Amaury Denoyelle | 26dfd90 | 2021-08-24 16:33:53 +0200 | [diff] [blame] | 820 | size_t h3_snd_buf(struct conn_stream *cs, struct buffer *buf, size_t count, int flags) |
| 821 | { |
| 822 | size_t total = 0; |
Christopher Faulet | db90f2a | 2022-03-22 16:06:25 +0100 | [diff] [blame] | 823 | struct qcs *qcs = __cs_mux(cs); |
Amaury Denoyelle | 26dfd90 | 2021-08-24 16:33:53 +0200 | [diff] [blame] | 824 | struct htx *htx; |
| 825 | enum htx_blk_type btype; |
| 826 | struct htx_blk *blk; |
| 827 | uint32_t bsize; |
| 828 | int32_t idx; |
| 829 | int ret; |
| 830 | |
Amaury Denoyelle | d8769d1 | 2022-03-25 15:28:33 +0100 | [diff] [blame] | 831 | h3_debug_printf(stderr, "%s\n", __func__); |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 832 | |
Amaury Denoyelle | 26dfd90 | 2021-08-24 16:33:53 +0200 | [diff] [blame] | 833 | htx = htx_from_buf(buf); |
| 834 | |
Amaury Denoyelle | 84ea8dc | 2021-12-03 14:40:01 +0100 | [diff] [blame] | 835 | while (count && !htx_is_empty(htx) && !(qcs->flags & QC_SF_BLK_MROOM)) { |
Amaury Denoyelle | 26dfd90 | 2021-08-24 16:33:53 +0200 | [diff] [blame] | 836 | idx = htx_get_head(htx); |
| 837 | blk = htx_get_blk(htx, idx); |
| 838 | btype = htx_get_blk_type(blk); |
| 839 | bsize = htx_get_blksz(blk); |
| 840 | |
| 841 | /* Not implemented : QUIC on backend side */ |
| 842 | BUG_ON(btype == HTX_BLK_REQ_SL); |
| 843 | |
| 844 | switch (btype) { |
| 845 | case HTX_BLK_RES_SL: |
Amaury Denoyelle | 15b0961 | 2021-08-24 16:20:27 +0200 | [diff] [blame] | 846 | /* start-line -> HEADERS h3 frame */ |
| 847 | ret = h3_resp_headers_send(qcs, htx); |
| 848 | if (ret > 0) { |
| 849 | total += ret; |
| 850 | count -= ret; |
| 851 | if (ret < bsize) |
| 852 | goto out; |
| 853 | } |
| 854 | break; |
Amaury Denoyelle | 26dfd90 | 2021-08-24 16:33:53 +0200 | [diff] [blame] | 855 | |
| 856 | case HTX_BLK_DATA: |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 857 | ret = h3_resp_data_send(qcs, buf, count); |
| 858 | if (ret > 0) { |
| 859 | htx = htx_from_buf(buf); |
| 860 | total += ret; |
| 861 | count -= ret; |
| 862 | if (ret < bsize) |
| 863 | goto out; |
| 864 | } |
| 865 | break; |
Amaury Denoyelle | 26dfd90 | 2021-08-24 16:33:53 +0200 | [diff] [blame] | 866 | |
| 867 | case HTX_BLK_TLR: |
| 868 | case HTX_BLK_EOT: |
| 869 | /* TODO trailers */ |
| 870 | |
| 871 | default: |
| 872 | htx_remove_blk(htx, blk); |
| 873 | total += bsize; |
| 874 | count -= bsize; |
| 875 | break; |
| 876 | } |
| 877 | } |
| 878 | |
Amaury Denoyelle | c2025c1 | 2021-12-03 15:03:36 +0100 | [diff] [blame] | 879 | if ((htx->flags & HTX_FL_EOM) && htx_is_empty(htx)) |
| 880 | qcs->flags |= QC_SF_FIN_STREAM; |
| 881 | |
Amaury Denoyelle | 26dfd90 | 2021-08-24 16:33:53 +0200 | [diff] [blame] | 882 | out: |
Amaury Denoyelle | a543eb1 | 2021-10-06 14:53:13 +0200 | [diff] [blame] | 883 | if (total) { |
| 884 | if (!(qcs->qcc->wait_event.events & SUB_RETRY_SEND)) |
| 885 | tasklet_wakeup(qcs->qcc->wait_event.tasklet); |
| 886 | } |
| 887 | |
Amaury Denoyelle | 26dfd90 | 2021-08-24 16:33:53 +0200 | [diff] [blame] | 888 | return total; |
Amaury Denoyelle | f52151d | 2021-08-24 16:11:18 +0200 | [diff] [blame] | 889 | } |
| 890 | |
Amaury Denoyelle | 67e92d3 | 2022-04-27 18:04:01 +0200 | [diff] [blame] | 891 | static int h3_attach(struct qcs *qcs) |
| 892 | { |
| 893 | struct h3s *h3s; |
| 894 | |
| 895 | h3s = pool_alloc(pool_head_h3s); |
| 896 | if (!h3s) |
| 897 | return 1; |
| 898 | |
| 899 | qcs->ctx = h3s; |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 900 | h3s->demux_frame_len = 0; |
| 901 | h3s->demux_frame_type = 0; |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 902 | h3s->flags = 0; |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 903 | |
Amaury Denoyelle | 3236a8e | 2022-05-24 15:24:03 +0200 | [diff] [blame] | 904 | if (quic_stream_is_bidi(qcs->id)) { |
| 905 | h3s->type = H3S_T_REQ; |
| 906 | } |
| 907 | else { |
| 908 | /* stream type must be decoded for unidirectional streams */ |
| 909 | h3s->type = H3S_T_UNKNOWN; |
| 910 | } |
| 911 | |
Amaury Denoyelle | 67e92d3 | 2022-04-27 18:04:01 +0200 | [diff] [blame] | 912 | return 0; |
| 913 | } |
| 914 | |
Amaury Denoyelle | 67e92d3 | 2022-04-27 18:04:01 +0200 | [diff] [blame] | 915 | static void h3_detach(struct qcs *qcs) |
| 916 | { |
| 917 | struct h3s *h3s = qcs->ctx; |
| 918 | pool_free(pool_head_h3s, h3s); |
| 919 | qcs->ctx = NULL; |
| 920 | } |
| 921 | |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 922 | static int h3_finalize(void *ctx) |
| 923 | { |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 924 | struct h3c *h3c = ctx; |
Amaury Denoyelle | 9cc4751 | 2022-05-24 16:27:41 +0200 | [diff] [blame^] | 925 | struct qcs *qcs; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 926 | |
Amaury Denoyelle | 9cc4751 | 2022-05-24 16:27:41 +0200 | [diff] [blame^] | 927 | qcs = qcs_new(h3c->qcc, 0x3, QCS_SRV_UNI); |
| 928 | if (!qcs) |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 929 | return 0; |
| 930 | |
Amaury Denoyelle | 9cc4751 | 2022-05-24 16:27:41 +0200 | [diff] [blame^] | 931 | h3_control_send(qcs, h3c); |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 932 | |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 933 | return 1; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 934 | } |
| 935 | |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 936 | /* Initialize the HTTP/3 context for <qcc> mux. |
| 937 | * Return 1 if succeeded, 0 if not. |
| 938 | */ |
| 939 | static int h3_init(struct qcc *qcc) |
| 940 | { |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 941 | struct h3c *h3c; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 942 | |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 943 | h3c = pool_alloc(pool_head_h3c); |
| 944 | if (!h3c) |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 945 | goto fail_no_h3; |
| 946 | |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 947 | h3c->qcc = qcc; |
| 948 | h3c->err = H3_NO_ERROR; |
| 949 | h3c->flags = 0; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 950 | |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 951 | qcc->ctx = h3c; |
| 952 | LIST_INIT(&h3c->buf_wait.list); |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 953 | |
| 954 | return 1; |
| 955 | |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 956 | fail_no_h3: |
| 957 | return 0; |
| 958 | } |
| 959 | |
Amaury Denoyelle | 8347f27 | 2022-03-29 14:46:55 +0200 | [diff] [blame] | 960 | static void h3_release(void *ctx) |
| 961 | { |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 962 | struct h3c *h3c = ctx; |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 963 | pool_free(pool_head_h3c, h3c); |
Amaury Denoyelle | 8347f27 | 2022-03-29 14:46:55 +0200 | [diff] [blame] | 964 | } |
| 965 | |
Amaury Denoyelle | 198d35f | 2022-04-01 17:56:58 +0200 | [diff] [blame] | 966 | /* Check if the H3 connection can still be considered as active. |
| 967 | * |
| 968 | * Return true if active else false. |
| 969 | */ |
| 970 | static int h3_is_active(const struct qcc *qcc, void *ctx) |
| 971 | { |
| 972 | if (qcc->strms[QCS_CLT_BIDI].nb_streams) |
| 973 | return 1; |
| 974 | |
| 975 | return 0; |
| 976 | } |
| 977 | |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 978 | /* HTTP/3 application layer operations */ |
| 979 | const struct qcc_app_ops h3_ops = { |
| 980 | .init = h3_init, |
Amaury Denoyelle | 67e92d3 | 2022-04-27 18:04:01 +0200 | [diff] [blame] | 981 | .attach = h3_attach, |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 982 | .decode_qcs = h3_decode_qcs, |
Amaury Denoyelle | abbe91e | 2021-11-12 16:09:29 +0100 | [diff] [blame] | 983 | .snd_buf = h3_snd_buf, |
Amaury Denoyelle | 67e92d3 | 2022-04-27 18:04:01 +0200 | [diff] [blame] | 984 | .detach = h3_detach, |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 985 | .finalize = h3_finalize, |
Amaury Denoyelle | 198d35f | 2022-04-01 17:56:58 +0200 | [diff] [blame] | 986 | .is_active = h3_is_active, |
Amaury Denoyelle | 8347f27 | 2022-03-29 14:46:55 +0200 | [diff] [blame] | 987 | .release = h3_release, |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 988 | }; |