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> |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 21 | #include <haproxy/dynbuf.h> |
| 22 | #include <haproxy/h3.h> |
Frédéric Lécaille | 6f7607e | 2022-05-25 22:25:37 +0200 | [diff] [blame] | 23 | #include <haproxy/h3_stats.h> |
Amaury Denoyelle | b49fa1a | 2021-08-24 15:30:12 +0200 | [diff] [blame] | 24 | #include <haproxy/http.h> |
| 25 | #include <haproxy/htx.h> |
Amaury Denoyelle | 8c6176b | 2022-05-24 18:16:49 +0200 | [diff] [blame] | 26 | #include <haproxy/intops.h> |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 27 | #include <haproxy/istbuf.h> |
Amaury Denoyelle | 846cc04 | 2022-04-04 16:13:44 +0200 | [diff] [blame] | 28 | #include <haproxy/mux_quic.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> |
Willy Tarreau | cb086c6 | 2022-05-27 09:47:12 +0200 | [diff] [blame] | 33 | #include <haproxy/stconn.h> |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 34 | #include <haproxy/tools.h> |
Amaury Denoyelle | 016aa93 | 2022-05-30 15:49:36 +0200 | [diff] [blame] | 35 | #include <haproxy/trace.h> |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 36 | #include <haproxy/xprt_quic.h> |
| 37 | |
Amaury Denoyelle | 016aa93 | 2022-05-30 15:49:36 +0200 | [diff] [blame] | 38 | /* trace source and events */ |
| 39 | static void h3_trace(enum trace_level level, uint64_t mask, |
| 40 | const struct trace_source *src, |
| 41 | const struct ist where, const struct ist func, |
| 42 | const void *a1, const void *a2, const void *a3, const void *a4); |
| 43 | |
| 44 | static const struct trace_event h3_trace_events[] = { |
Amaury Denoyelle | 494512d | 2022-05-30 15:50:34 +0200 | [diff] [blame] | 45 | #define H3_EV_RX_FRAME (1ULL << 0) |
| 46 | { .mask = H3_EV_RX_FRAME, .name = "rx_frame", .desc = "receipt of any H3 frame" }, |
| 47 | #define H3_EV_RX_DATA (1ULL << 1) |
| 48 | { .mask = H3_EV_RX_DATA, .name = "rx_data", .desc = "receipt of H3 DATA frame" }, |
| 49 | #define H3_EV_RX_HDR (1ULL << 2) |
| 50 | { .mask = H3_EV_RX_HDR, .name = "rx_hdr", .desc = "receipt of H3 HEADERS frame" }, |
| 51 | #define H3_EV_RX_SETTINGS (1ULL << 3) |
| 52 | { .mask = H3_EV_RX_SETTINGS, .name = "rx_settings", .desc = "receipt of H3 SETTINGS frame" }, |
Amaury Denoyelle | a717eb7 | 2022-05-30 15:51:01 +0200 | [diff] [blame] | 53 | #define H3_EV_TX_DATA (1ULL << 4) |
| 54 | { .mask = H3_EV_TX_DATA, .name = "tx_data", .desc = "transmission of H3 DATA frame" }, |
| 55 | #define H3_EV_TX_HDR (1ULL << 5) |
| 56 | { .mask = H3_EV_TX_HDR, .name = "tx_hdr", .desc = "transmission of H3 HEADERS frame" }, |
| 57 | #define H3_EV_TX_SETTINGS (1ULL << 6) |
| 58 | { .mask = H3_EV_TX_SETTINGS, .name = "tx_settings", .desc = "transmission of H3 SETTINGS frame" }, |
Amaury Denoyelle | d5581d5 | 2022-05-30 15:51:31 +0200 | [diff] [blame] | 59 | #define H3_EV_H3S_NEW (1ULL << 7) |
| 60 | { .mask = H3_EV_H3S_NEW, .name = "h3s_new", .desc = "new H3 stream" }, |
| 61 | #define H3_EV_H3S_END (1ULL << 8) |
| 62 | { .mask = H3_EV_H3S_END, .name = "h3s_end", .desc = "H3 stream terminated" }, |
Amaury Denoyelle | 016aa93 | 2022-05-30 15:49:36 +0200 | [diff] [blame] | 63 | { } |
| 64 | }; |
| 65 | |
| 66 | static const struct name_desc h3_trace_lockon_args[4] = { |
| 67 | /* arg1 */ { /* already used by the connection */ }, |
| 68 | /* arg2 */ { .name="qcs", .desc="QUIC stream" }, |
| 69 | /* arg3 */ { }, |
| 70 | /* arg4 */ { } |
| 71 | }; |
| 72 | |
| 73 | static const struct name_desc h3_trace_decoding[] = { |
| 74 | #define H3_VERB_CLEAN 1 |
| 75 | { .name="clean", .desc="only user-friendly stuff, generally suitable for level \"user\"" }, |
| 76 | #define H3_VERB_MINIMAL 2 |
| 77 | { .name="minimal", .desc="report only qcc/qcs state and flags, no real decoding" }, |
| 78 | { /* end */ } |
| 79 | }; |
| 80 | |
| 81 | struct trace_source trace_h3 = { |
| 82 | .name = IST("h3"), |
| 83 | .desc = "HTTP/3 transcoder", |
| 84 | .arg_def = TRC_ARG1_CONN, /* TRACE()'s first argument is always a connection */ |
| 85 | .default_cb = h3_trace, |
| 86 | .known_events = h3_trace_events, |
| 87 | .lockon_args = h3_trace_lockon_args, |
| 88 | .decoding = h3_trace_decoding, |
| 89 | .report_events = ~0, /* report everything by default */ |
| 90 | }; |
| 91 | |
| 92 | #define TRACE_SOURCE &trace_h3 |
| 93 | INITCALL1(STG_REGISTER, trace_register_source, TRACE_SOURCE); |
| 94 | |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 95 | #if defined(DEBUG_H3) |
| 96 | #define h3_debug_printf fprintf |
| 97 | #define h3_debug_hexdump debug_hexdump |
| 98 | #else |
| 99 | #define h3_debug_printf(...) do { } while (0) |
| 100 | #define h3_debug_hexdump(...) do { } while (0) |
| 101 | #endif |
| 102 | |
Amaury Denoyelle | 302ecd4 | 2022-05-24 15:24:32 +0200 | [diff] [blame] | 103 | #define H3_CF_SETTINGS_SENT 0x00000001 /* SETTINGS frame already sent on local control stream */ |
| 104 | #define H3_CF_SETTINGS_RECV 0x00000002 /* SETTINGS frame already received on remote control stream */ |
| 105 | #define H3_CF_UNI_CTRL_SET 0x00000004 /* Remote H3 Control stream opened */ |
| 106 | #define H3_CF_UNI_QPACK_DEC_SET 0x00000008 /* Remote QPACK decoder stream opened */ |
| 107 | #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] | 108 | |
| 109 | /* Default settings */ |
Amaury Denoyelle | 3394939 | 2021-08-24 15:16:58 +0200 | [diff] [blame] | 110 | static uint64_t h3_settings_qpack_max_table_capacity = 0; |
| 111 | static uint64_t h3_settings_qpack_blocked_streams = 4096; |
| 112 | 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] | 113 | |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 114 | struct h3c { |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 115 | struct qcc *qcc; |
| 116 | enum h3_err err; |
| 117 | uint32_t flags; |
Amaury Denoyelle | 9cc4751 | 2022-05-24 16:27:41 +0200 | [diff] [blame] | 118 | |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 119 | /* Settings */ |
| 120 | uint64_t qpack_max_table_capacity; |
| 121 | uint64_t qpack_blocked_streams; |
| 122 | uint64_t max_field_section_size; |
Amaury Denoyelle | 9cc4751 | 2022-05-24 16:27:41 +0200 | [diff] [blame] | 123 | |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 124 | struct buffer_wait buf_wait; /* wait list for buffer allocations */ |
Frédéric Lécaille | 6f7607e | 2022-05-25 22:25:37 +0200 | [diff] [blame] | 125 | /* Stats counters */ |
| 126 | struct h3_counters *prx_counters; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 127 | }; |
| 128 | |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 129 | 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] | 130 | |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 131 | #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] | 132 | #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] | 133 | |
Amaury Denoyelle | 67e92d3 | 2022-04-27 18:04:01 +0200 | [diff] [blame] | 134 | struct h3s { |
Amaury Denoyelle | c015679 | 2022-06-03 15:29:07 +0200 | [diff] [blame] | 135 | struct h3c *h3c; |
| 136 | |
Amaury Denoyelle | 3236a8e | 2022-05-24 15:24:03 +0200 | [diff] [blame] | 137 | enum h3s_t type; |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 138 | int demux_frame_len; |
| 139 | int demux_frame_type; |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 140 | |
| 141 | int flags; |
Amaury Denoyelle | 67e92d3 | 2022-04-27 18:04:01 +0200 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | DECLARE_STATIC_POOL(pool_head_h3s, "h3s", sizeof(struct h3s)); |
| 145 | |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 146 | /* Initialize an uni-stream <qcs> by reading its type from <b>. |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 147 | * |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 148 | * Returns the count of consumed bytes or a negative error code. |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 149 | */ |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 150 | static ssize_t h3_init_uni_stream(struct h3c *h3c, struct qcs *qcs, |
| 151 | struct buffer *b) |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 152 | { |
| 153 | /* decode unidirectional stream type */ |
| 154 | struct h3s *h3s = qcs->ctx; |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 155 | uint64_t type; |
| 156 | size_t len = 0, ret; |
| 157 | |
Amaury Denoyelle | d5581d5 | 2022-05-30 15:51:31 +0200 | [diff] [blame] | 158 | TRACE_ENTER(H3_EV_H3S_NEW, qcs->qcc->conn, qcs); |
| 159 | |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 160 | BUG_ON_HOT(!quic_stream_is_uni(qcs->id) || |
| 161 | h3s->flags & H3_SF_UNI_INIT); |
| 162 | |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 163 | ret = b_quic_dec_int(&type, b, &len); |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 164 | if (!ret) { |
| 165 | ABORT_NOW(); |
| 166 | } |
| 167 | |
| 168 | switch (type) { |
| 169 | case H3_UNI_S_T_CTRL: |
| 170 | if (h3c->flags & H3_CF_UNI_CTRL_SET) { |
| 171 | qcc_emit_cc_app(qcs->qcc, H3_STREAM_CREATION_ERROR); |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 172 | return -1; |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 173 | } |
| 174 | h3c->flags |= H3_CF_UNI_CTRL_SET; |
| 175 | h3s->type = H3S_T_CTRL; |
| 176 | break; |
| 177 | |
| 178 | case H3_UNI_S_T_PUSH: |
| 179 | /* TODO not supported for the moment */ |
| 180 | h3s->type = H3S_T_PUSH; |
| 181 | break; |
| 182 | |
| 183 | case H3_UNI_S_T_QPACK_DEC: |
| 184 | if (h3c->flags & H3_CF_UNI_QPACK_DEC_SET) { |
| 185 | qcc_emit_cc_app(qcs->qcc, H3_STREAM_CREATION_ERROR); |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 186 | return -1; |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 187 | } |
| 188 | h3c->flags |= H3_CF_UNI_QPACK_DEC_SET; |
| 189 | h3s->type = H3S_T_QPACK_DEC; |
Amaury Denoyelle | fc99a69 | 2022-05-24 15:25:19 +0200 | [diff] [blame] | 190 | h3s->flags |= H3_SF_UNI_NO_H3; |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 191 | break; |
| 192 | |
| 193 | case H3_UNI_S_T_QPACK_ENC: |
| 194 | if (h3c->flags & H3_CF_UNI_QPACK_ENC_SET) { |
| 195 | qcc_emit_cc_app(qcs->qcc, H3_STREAM_CREATION_ERROR); |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 196 | return -1; |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 197 | } |
| 198 | h3c->flags |= H3_CF_UNI_QPACK_ENC_SET; |
| 199 | h3s->type = H3S_T_QPACK_ENC; |
Amaury Denoyelle | fc99a69 | 2022-05-24 15:25:19 +0200 | [diff] [blame] | 200 | h3s->flags |= H3_SF_UNI_NO_H3; |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 201 | break; |
| 202 | |
| 203 | default: |
Amaury Denoyelle | 849b24f | 2022-05-24 17:22:07 +0200 | [diff] [blame] | 204 | /* draft-ietf-quic-http34 9. Extensions to HTTP/3 |
| 205 | * |
| 206 | * Implementations MUST [...] abort reading on unidirectional |
| 207 | * streams that have unknown or unsupported types. |
| 208 | */ |
| 209 | qcs->flags |= QC_SF_READ_ABORTED; |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 210 | return -1; |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 211 | }; |
| 212 | |
| 213 | h3s->flags |= H3_SF_UNI_INIT; |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 214 | |
Amaury Denoyelle | d5581d5 | 2022-05-30 15:51:31 +0200 | [diff] [blame] | 215 | TRACE_LEAVE(H3_EV_H3S_NEW, qcs->qcc->conn, qcs); |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 216 | return len; |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 217 | } |
| 218 | |
Amaury Denoyelle | fc99a69 | 2022-05-24 15:25:19 +0200 | [diff] [blame] | 219 | /* Parse an uni-stream <qcs> from <rxbuf> which does not contains H3 frames. |
| 220 | * This may be used for QPACK encoder/decoder streams for example. |
| 221 | * |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 222 | * Returns the number of consumed bytes or a negative error code. |
Amaury Denoyelle | fc99a69 | 2022-05-24 15:25:19 +0200 | [diff] [blame] | 223 | */ |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 224 | static ssize_t h3_parse_uni_stream_no_h3(struct qcs *qcs, struct buffer *b) |
Amaury Denoyelle | fc99a69 | 2022-05-24 15:25:19 +0200 | [diff] [blame] | 225 | { |
Amaury Denoyelle | fc99a69 | 2022-05-24 15:25:19 +0200 | [diff] [blame] | 226 | struct h3s *h3s = qcs->ctx; |
| 227 | |
| 228 | BUG_ON_HOT(!quic_stream_is_uni(qcs->id) || |
| 229 | !(h3s->flags & H3_SF_UNI_NO_H3)); |
| 230 | |
| 231 | switch (h3s->type) { |
| 232 | case H3S_T_QPACK_DEC: |
Amaury Denoyelle | 53eef46 | 2022-06-14 16:34:32 +0200 | [diff] [blame] | 233 | if (qpack_decode_dec(b, NULL)) |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 234 | return -1; |
Amaury Denoyelle | fc99a69 | 2022-05-24 15:25:19 +0200 | [diff] [blame] | 235 | break; |
| 236 | case H3S_T_QPACK_ENC: |
Amaury Denoyelle | 53eef46 | 2022-06-14 16:34:32 +0200 | [diff] [blame] | 237 | if (qpack_decode_enc(b, NULL)) |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 238 | return -1; |
Amaury Denoyelle | fc99a69 | 2022-05-24 15:25:19 +0200 | [diff] [blame] | 239 | break; |
Amaury Denoyelle | 849b24f | 2022-05-24 17:22:07 +0200 | [diff] [blame] | 240 | case H3S_T_UNKNOWN: |
Amaury Denoyelle | fc99a69 | 2022-05-24 15:25:19 +0200 | [diff] [blame] | 241 | default: |
Amaury Denoyelle | 849b24f | 2022-05-24 17:22:07 +0200 | [diff] [blame] | 242 | /* Unknown stream should be flagged with QC_SF_READ_ABORTED. */ |
| 243 | ABORT_NOW(); |
Amaury Denoyelle | fc99a69 | 2022-05-24 15:25:19 +0200 | [diff] [blame] | 244 | } |
| 245 | |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 246 | /* TODO adjust return code */ |
Amaury Denoyelle | fc99a69 | 2022-05-24 15:25:19 +0200 | [diff] [blame] | 247 | return 0; |
| 248 | } |
| 249 | |
Amaury Denoyelle | 88d5dd1 | 2022-05-31 11:44:52 +0200 | [diff] [blame] | 250 | /* Decode a H3 frame header from <rxbuf> buffer. The frame type is stored in |
| 251 | * <ftype> and length in <flen>. |
| 252 | * |
| 253 | * Returns the size of the H3 frame header. Note that the input buffer is not |
| 254 | * consumed. |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 255 | */ |
| 256 | static inline size_t h3_decode_frm_header(uint64_t *ftype, uint64_t *flen, |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 257 | struct buffer *b) |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 258 | { |
| 259 | size_t hlen; |
| 260 | |
| 261 | hlen = 0; |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 262 | if (!b_quic_dec_int(ftype, b, &hlen) || |
| 263 | !b_quic_dec_int(flen, b, &hlen)) { |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 264 | return 0; |
Amaury Denoyelle | 88d5dd1 | 2022-05-31 11:44:52 +0200 | [diff] [blame] | 265 | } |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 266 | |
| 267 | return hlen; |
| 268 | } |
| 269 | |
Amaury Denoyelle | 302ecd4 | 2022-05-24 15:24:32 +0200 | [diff] [blame] | 270 | /* Check if H3 frame of type <ftype> is valid when received on stream <qcs>. |
| 271 | * |
| 272 | * Returns a boolean. If false, a connection error H3_FRAME_UNEXPECTED should |
| 273 | * be reported. |
| 274 | */ |
| 275 | static int h3_is_frame_valid(struct h3c *h3c, struct qcs *qcs, uint64_t ftype) |
| 276 | { |
| 277 | struct h3s *h3s = qcs->ctx; |
| 278 | const uint64_t id = qcs->id; |
| 279 | |
| 280 | BUG_ON_HOT(h3s->type == H3S_T_UNKNOWN); |
| 281 | |
| 282 | switch (ftype) { |
| 283 | case H3_FT_DATA: |
| 284 | case H3_FT_HEADERS: |
| 285 | return h3s->type != H3S_T_CTRL; |
| 286 | |
| 287 | case H3_FT_CANCEL_PUSH: |
| 288 | case H3_FT_GOAWAY: |
| 289 | case H3_FT_MAX_PUSH_ID: |
| 290 | /* Only allowed for control stream. First frame of control |
| 291 | * stream MUST be SETTINGS. |
| 292 | */ |
| 293 | return h3s->type == H3S_T_CTRL && |
| 294 | (h3c->flags & H3_CF_SETTINGS_RECV); |
| 295 | |
| 296 | case H3_FT_SETTINGS: |
| 297 | /* draft-ietf-quic-http34 7.2.4. SETTINGS |
| 298 | * |
| 299 | * If an endpoint receives a second SETTINGS frame on the control |
| 300 | * stream, the endpoint MUST respond with a connection error of type |
| 301 | * H3_FRAME_UNEXPECTED. |
| 302 | */ |
| 303 | return h3s->type == H3S_T_CTRL && |
| 304 | !(h3c->flags & H3_CF_SETTINGS_RECV); |
| 305 | |
| 306 | case H3_FT_PUSH_PROMISE: |
| 307 | return h3s->type != H3S_T_CTRL && |
| 308 | (id & QCS_ID_SRV_INTIATOR_BIT); |
| 309 | |
| 310 | default: |
| 311 | /* draft-ietf-quic-http34 9. Extensions to HTTP/3 |
| 312 | * |
| 313 | * Implementations MUST discard frames [...] that have unknown |
| 314 | * or unsupported types. |
| 315 | */ |
| 316 | return h3s->type != H3S_T_CTRL || (h3c->flags & H3_CF_SETTINGS_RECV); |
| 317 | } |
| 318 | } |
| 319 | |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 320 | /* Parse from buffer <buf> a H3 HEADERS frame of length <len>. Data are copied |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 321 | * in a local HTX buffer and transfer to the stream connector layer. <fin> must be |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 322 | * set if this is the last data to transfer from this stream. |
| 323 | * |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 324 | * Returns the number of consumed bytes or a negative error code. |
Amaury Denoyelle | b9ce14e | 2021-11-08 09:13:42 +0100 | [diff] [blame] | 325 | */ |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 326 | static ssize_t h3_headers_to_htx(struct qcs *qcs, const struct buffer *buf, |
| 327 | uint64_t len, char fin) |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 328 | { |
Amaury Denoyelle | 2bc4786 | 2022-06-30 10:04:42 +0200 | [diff] [blame] | 329 | struct h3s *h3s = qcs->ctx; |
| 330 | struct h3c *h3c = h3s->h3c; |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 331 | struct buffer htx_buf = BUF_NULL; |
| 332 | struct buffer *tmp = get_trash_chunk(); |
Amaury Denoyelle | 7059ebc | 2021-12-08 15:51:04 +0100 | [diff] [blame] | 333 | struct htx *htx = NULL; |
Amaury Denoyelle | b49fa1a | 2021-08-24 15:30:12 +0200 | [diff] [blame] | 334 | struct htx_sl *sl; |
Amaury Denoyelle | fd7cdc3 | 2021-08-24 15:13:20 +0200 | [diff] [blame] | 335 | struct http_hdr list[global.tune.max_http_hdr]; |
Amaury Denoyelle | b49fa1a | 2021-08-24 15:30:12 +0200 | [diff] [blame] | 336 | unsigned int flags = HTX_SL_F_NONE; |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 337 | struct ist meth = IST_NULL, path = IST_NULL; |
| 338 | //struct ist scheme = IST_NULL, authority = IST_NULL; |
| 339 | struct ist authority = IST_NULL; |
Amaury Denoyelle | 2bc4786 | 2022-06-30 10:04:42 +0200 | [diff] [blame] | 340 | int hdr_idx, ret; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 341 | |
Amaury Denoyelle | 494512d | 2022-05-30 15:50:34 +0200 | [diff] [blame] | 342 | TRACE_ENTER(H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs); |
| 343 | |
Amaury Denoyelle | 30f23f5 | 2022-04-27 14:41:53 +0200 | [diff] [blame] | 344 | /* TODO support buffer wrapping */ |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 345 | BUG_ON(b_head(buf) + len >= b_wrap(buf)); |
Amaury Denoyelle | 2bc4786 | 2022-06-30 10:04:42 +0200 | [diff] [blame] | 346 | ret = qpack_decode_fs((const unsigned char *)b_head(buf), len, tmp, |
| 347 | list, sizeof(list) / sizeof(list[0])); |
| 348 | if (ret < 0) { |
| 349 | TRACE_ERROR("QPACK decoding error", H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs); |
| 350 | h3c->err = -ret; |
Amaury Denoyelle | 314578a | 2022-04-27 14:52:52 +0200 | [diff] [blame] | 351 | return -1; |
Amaury Denoyelle | 60ef19f | 2022-06-14 17:38:36 +0200 | [diff] [blame] | 352 | } |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 353 | |
| 354 | qc_get_buf(qcs, &htx_buf); |
| 355 | BUG_ON(!b_size(&htx_buf)); |
| 356 | htx = htx_from_buf(&htx_buf); |
| 357 | |
| 358 | /* first treat pseudo-header to build the start line */ |
| 359 | hdr_idx = 0; |
| 360 | while (1) { |
| 361 | if (isteq(list[hdr_idx].n, ist(""))) |
| 362 | break; |
| 363 | |
| 364 | if (istmatch(list[hdr_idx].n, ist(":"))) { |
| 365 | /* pseudo-header */ |
| 366 | if (isteq(list[hdr_idx].n, ist(":method"))) |
| 367 | meth = list[hdr_idx].v; |
| 368 | else if (isteq(list[hdr_idx].n, ist(":path"))) |
| 369 | path = list[hdr_idx].v; |
| 370 | //else if (isteq(list[hdr_idx].n, ist(":scheme"))) |
| 371 | // scheme = list[hdr_idx].v; |
| 372 | else if (isteq(list[hdr_idx].n, ist(":authority"))) |
| 373 | authority = list[hdr_idx].v; |
| 374 | } |
| 375 | |
| 376 | ++hdr_idx; |
| 377 | } |
| 378 | |
| 379 | flags |= HTX_SL_F_VER_11; |
Amaury Denoyelle | 0fa14a6 | 2022-04-26 16:24:39 +0200 | [diff] [blame] | 380 | flags |= HTX_SL_F_XFER_LEN; |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 381 | |
| 382 | sl = htx_add_stline(htx, HTX_BLK_REQ_SL, flags, meth, path, ist("HTTP/3.0")); |
Amaury Denoyelle | 2bc4786 | 2022-06-30 10:04:42 +0200 | [diff] [blame] | 383 | if (!sl) { |
| 384 | h3c->err = H3_INTERNAL_ERROR; |
Amaury Denoyelle | 314578a | 2022-04-27 14:52:52 +0200 | [diff] [blame] | 385 | return -1; |
Amaury Denoyelle | 2bc4786 | 2022-06-30 10:04:42 +0200 | [diff] [blame] | 386 | } |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 387 | |
| 388 | if (fin) |
| 389 | sl->flags |= HTX_SL_F_BODYLESS; |
| 390 | |
| 391 | sl->info.req.meth = find_http_meth(meth.ptr, meth.len); |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 392 | |
| 393 | if (isttest(authority)) |
| 394 | htx_add_header(htx, ist("host"), authority); |
| 395 | |
| 396 | /* now treat standard headers */ |
| 397 | hdr_idx = 0; |
| 398 | while (1) { |
| 399 | if (isteq(list[hdr_idx].n, ist(""))) |
| 400 | break; |
| 401 | |
| 402 | if (!istmatch(list[hdr_idx].n, ist(":"))) |
| 403 | htx_add_header(htx, list[hdr_idx].n, list[hdr_idx].v); |
| 404 | |
| 405 | ++hdr_idx; |
| 406 | } |
| 407 | |
| 408 | htx_add_endof(htx, HTX_BLK_EOH); |
| 409 | htx_to_buf(htx, &htx_buf); |
| 410 | |
| 411 | if (fin) |
| 412 | htx->flags |= HTX_FL_EOM; |
| 413 | |
Amaury Denoyelle | 2bc4786 | 2022-06-30 10:04:42 +0200 | [diff] [blame] | 414 | if (!qc_attach_sc(qcs, &htx_buf)) { |
| 415 | h3c->err = H3_INTERNAL_ERROR; |
Amaury Denoyelle | 314578a | 2022-04-27 14:52:52 +0200 | [diff] [blame] | 416 | return -1; |
Amaury Denoyelle | 2bc4786 | 2022-06-30 10:04:42 +0200 | [diff] [blame] | 417 | } |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 418 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 419 | /* buffer is transferred to the stream connector and set to NULL |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 420 | * except on stream creation error. |
| 421 | */ |
| 422 | b_free(&htx_buf); |
| 423 | offer_buffers(NULL, 1); |
| 424 | |
Amaury Denoyelle | 494512d | 2022-05-30 15:50:34 +0200 | [diff] [blame] | 425 | TRACE_LEAVE(H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs); |
Amaury Denoyelle | 314578a | 2022-04-27 14:52:52 +0200 | [diff] [blame] | 426 | return len; |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 427 | } |
| 428 | |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 429 | /* Copy from buffer <buf> a H3 DATA frame of length <len> in QUIC stream <qcs> |
| 430 | * HTX buffer. <fin> must be set if this is the last data to transfer from this |
| 431 | * stream. |
| 432 | * |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 433 | * Returns the number of consumed bytes or a negative error code. |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 434 | */ |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 435 | static ssize_t h3_data_to_htx(struct qcs *qcs, const struct buffer *buf, |
| 436 | uint64_t len, char fin) |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 437 | { |
| 438 | struct buffer *appbuf; |
| 439 | struct htx *htx = NULL; |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 440 | size_t htx_sent = 0; |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 441 | int htx_space; |
Amaury Denoyelle | 30f23f5 | 2022-04-27 14:41:53 +0200 | [diff] [blame] | 442 | char *head; |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 443 | |
Amaury Denoyelle | 494512d | 2022-05-30 15:50:34 +0200 | [diff] [blame] | 444 | TRACE_ENTER(H3_EV_RX_FRAME|H3_EV_RX_DATA, qcs->qcc->conn, qcs); |
| 445 | |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 446 | appbuf = qc_get_buf(qcs, &qcs->rx.app_buf); |
| 447 | BUG_ON(!appbuf); |
| 448 | htx = htx_from_buf(appbuf); |
| 449 | |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 450 | if (len > b_data(buf)) { |
| 451 | len = b_data(buf); |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 452 | fin = 0; |
| 453 | } |
| 454 | |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 455 | head = b_head(buf); |
Amaury Denoyelle | 30f23f5 | 2022-04-27 14:41:53 +0200 | [diff] [blame] | 456 | retry: |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 457 | htx_space = htx_free_data_space(htx); |
Amaury Denoyelle | f1fc0b3 | 2022-05-02 11:07:06 +0200 | [diff] [blame] | 458 | if (!htx_space) { |
| 459 | qcs->flags |= QC_SF_DEM_FULL; |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 460 | goto out; |
Amaury Denoyelle | f1fc0b3 | 2022-05-02 11:07:06 +0200 | [diff] [blame] | 461 | } |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 462 | |
| 463 | if (len > htx_space) { |
| 464 | len = htx_space; |
| 465 | fin = 0; |
Amaury Denoyelle | ff191de | 2022-02-21 18:38:29 +0100 | [diff] [blame] | 466 | } |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 467 | |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 468 | if (head + len > b_wrap(buf)) { |
| 469 | size_t contig = b_wrap(buf) - head; |
| 470 | htx_sent = htx_add_data(htx, ist2(b_head(buf), contig)); |
Amaury Denoyelle | 73d6ffe | 2022-05-16 13:54:31 +0200 | [diff] [blame] | 471 | if (htx_sent < contig) { |
| 472 | qcs->flags |= QC_SF_DEM_FULL; |
| 473 | goto out; |
| 474 | } |
| 475 | |
Amaury Denoyelle | 30f23f5 | 2022-04-27 14:41:53 +0200 | [diff] [blame] | 476 | len -= contig; |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 477 | head = b_orig(buf); |
Amaury Denoyelle | 30f23f5 | 2022-04-27 14:41:53 +0200 | [diff] [blame] | 478 | goto retry; |
Amaury Denoyelle | ff191de | 2022-02-21 18:38:29 +0100 | [diff] [blame] | 479 | } |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 480 | |
Amaury Denoyelle | 30f23f5 | 2022-04-27 14:41:53 +0200 | [diff] [blame] | 481 | htx_sent += htx_add_data(htx, ist2(head, len)); |
Amaury Denoyelle | 73d6ffe | 2022-05-16 13:54:31 +0200 | [diff] [blame] | 482 | if (htx_sent < len) { |
| 483 | qcs->flags |= QC_SF_DEM_FULL; |
| 484 | goto out; |
| 485 | } |
Amaury Denoyelle | 30f23f5 | 2022-04-27 14:41:53 +0200 | [diff] [blame] | 486 | |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 487 | if (fin && len == htx_sent) |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 488 | htx->flags |= HTX_FL_EOM; |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 489 | |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 490 | out: |
| 491 | htx_to_buf(htx, appbuf); |
Amaury Denoyelle | 494512d | 2022-05-30 15:50:34 +0200 | [diff] [blame] | 492 | |
| 493 | TRACE_LEAVE(H3_EV_RX_FRAME|H3_EV_RX_DATA, qcs->qcc->conn, qcs); |
Amaury Denoyelle | 314578a | 2022-04-27 14:52:52 +0200 | [diff] [blame] | 494 | return htx_sent; |
Amaury Denoyelle | 91379f7 | 2022-02-14 17:14:59 +0100 | [diff] [blame] | 495 | } |
| 496 | |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 497 | /* Parse a SETTINGS frame of length <len> of payload <buf>. |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 498 | * |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 499 | * Returns the number of consumed bytes or a negative error code. |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 500 | */ |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 501 | static ssize_t h3_parse_settings_frm(struct h3c *h3c, const struct buffer *buf, |
| 502 | size_t len) |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 503 | { |
Amaury Denoyelle | 8c6176b | 2022-05-24 18:16:49 +0200 | [diff] [blame] | 504 | struct buffer b; |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 505 | uint64_t id, value; |
Amaury Denoyelle | 8c6176b | 2022-05-24 18:16:49 +0200 | [diff] [blame] | 506 | size_t ret = 0; |
| 507 | long mask = 0; /* used to detect duplicated settings identifier */ |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 508 | |
Amaury Denoyelle | 494512d | 2022-05-30 15:50:34 +0200 | [diff] [blame] | 509 | TRACE_ENTER(H3_EV_RX_FRAME|H3_EV_RX_SETTINGS, h3c->qcc->conn); |
| 510 | |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 511 | /* Work on a copy of <buf>. */ |
Amaury Denoyelle | 3a2fcfd | 2022-06-09 11:54:38 +0200 | [diff] [blame] | 512 | b = b_make(b_orig(buf), b_size(buf), b_head_ofs(buf), len); |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 513 | |
Amaury Denoyelle | 8c6176b | 2022-05-24 18:16:49 +0200 | [diff] [blame] | 514 | while (b_data(&b)) { |
| 515 | if (!b_quic_dec_int(&id, &b, &ret) || !b_quic_dec_int(&value, &b, &ret)) { |
| 516 | h3c->err = H3_FRAME_ERROR; |
| 517 | return -1; |
| 518 | } |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 519 | |
| 520 | h3_debug_printf(stderr, "%s id: %llu value: %llu\n", |
| 521 | __func__, (unsigned long long)id, (unsigned long long)value); |
Amaury Denoyelle | 8c6176b | 2022-05-24 18:16:49 +0200 | [diff] [blame] | 522 | |
| 523 | /* draft-ietf-quic-http34 7.2.4. SETTINGS |
| 524 | * |
| 525 | * The same setting identifier MUST NOT occur more than once in the |
| 526 | * SETTINGS frame. A receiver MAY treat the presence of duplicate |
| 527 | * setting identifiers as a connection error of type H3_SETTINGS_ERROR. |
| 528 | */ |
| 529 | |
| 530 | /* Ignore duplicate check for ID too big used for GREASE. */ |
| 531 | if (id < sizeof(mask)) { |
| 532 | if (ha_bit_test(id, &mask)) { |
| 533 | h3c->err = H3_SETTINGS_ERROR; |
| 534 | return -1; |
| 535 | } |
| 536 | ha_bit_set(id, &mask); |
| 537 | } |
| 538 | |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 539 | switch (id) { |
| 540 | case H3_SETTINGS_QPACK_MAX_TABLE_CAPACITY: |
| 541 | h3c->qpack_max_table_capacity = value; |
| 542 | break; |
| 543 | case H3_SETTINGS_MAX_FIELD_SECTION_SIZE: |
| 544 | h3c->max_field_section_size = value; |
| 545 | break; |
| 546 | case H3_SETTINGS_QPACK_BLOCKED_STREAMS: |
| 547 | h3c->qpack_blocked_streams = value; |
| 548 | break; |
Amaury Denoyelle | 8c6176b | 2022-05-24 18:16:49 +0200 | [diff] [blame] | 549 | |
| 550 | case H3_SETTINGS_RESERVED_0: |
| 551 | case H3_SETTINGS_RESERVED_2: |
| 552 | case H3_SETTINGS_RESERVED_3: |
| 553 | case H3_SETTINGS_RESERVED_4: |
| 554 | case H3_SETTINGS_RESERVED_5: |
| 555 | /* draft-ietf-quic-http34 7.2.4.1. Defined SETTINGS Parameters |
| 556 | * |
| 557 | * Setting identifiers which were defined in [HTTP2] where there is no |
| 558 | * corresponding HTTP/3 setting have also been reserved |
| 559 | * (Section 11.2.2). These reserved settings MUST NOT be sent, and |
| 560 | * their receipt MUST be treated as a connection error of type |
| 561 | * H3_SETTINGS_ERROR. |
| 562 | */ |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 563 | h3c->err = H3_SETTINGS_ERROR; |
Amaury Denoyelle | 8c6176b | 2022-05-24 18:16:49 +0200 | [diff] [blame] | 564 | return -1; |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 565 | default: |
| 566 | /* MUST be ignored */ |
| 567 | break; |
| 568 | } |
| 569 | } |
| 570 | |
Amaury Denoyelle | 494512d | 2022-05-30 15:50:34 +0200 | [diff] [blame] | 571 | TRACE_LEAVE(H3_EV_RX_FRAME|H3_EV_RX_SETTINGS); |
Amaury Denoyelle | 8c6176b | 2022-05-24 18:16:49 +0200 | [diff] [blame] | 572 | return ret; |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 573 | } |
| 574 | |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 575 | /* Decode <qcs> remotely initiated bidi-stream. <fin> must be set to indicate |
| 576 | * that we received the last data of the stream. |
Amaury Denoyelle | 0ffd6e7 | 2022-05-24 11:07:28 +0200 | [diff] [blame] | 577 | * |
| 578 | * Returns 0 on success else non-zero. |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 579 | */ |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 580 | static ssize_t h3_decode_qcs(struct qcs *qcs, struct buffer *b, int fin) |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 581 | { |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 582 | struct h3s *h3s = qcs->ctx; |
Amaury Denoyelle | c015679 | 2022-06-03 15:29:07 +0200 | [diff] [blame] | 583 | struct h3c *h3c = h3s->h3c; |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 584 | ssize_t total = 0, ret; |
Amaury Denoyelle | 7b0f122 | 2022-02-14 17:13:55 +0100 | [diff] [blame] | 585 | |
Amaury Denoyelle | bb97042 | 2022-04-12 16:40:52 +0200 | [diff] [blame] | 586 | h3_debug_printf(stderr, "%s: STREAM ID: %lu\n", __func__, qcs->id); |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 587 | if (!b_data(b)) |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 588 | return 0; |
| 589 | |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 590 | if (quic_stream_is_uni(qcs->id) && !(h3s->flags & H3_SF_UNI_INIT)) { |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 591 | if ((ret = h3_init_uni_stream(h3c, qcs, b)) < 0) |
| 592 | return -1; |
| 593 | |
| 594 | total += ret; |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | if (quic_stream_is_uni(qcs->id) && (h3s->flags & H3_SF_UNI_NO_H3)) { |
| 598 | /* For non-h3 STREAM, parse it and return immediately. */ |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 599 | if ((ret = h3_parse_uni_stream_no_h3(qcs, b)) < 0) |
| 600 | return -1; |
| 601 | |
| 602 | total += ret; |
| 603 | return total; |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 604 | } |
| 605 | |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 606 | while (b_data(b) && !(qcs->flags & QC_SF_DEM_FULL)) { |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 607 | uint64_t ftype, flen; |
Amaury Denoyelle | 95b93a3 | 2022-02-14 15:49:53 +0100 | [diff] [blame] | 608 | char last_stream_frame = 0; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 609 | |
| 610 | /* Work on a copy of <rxbuf> */ |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 611 | if (!h3s->demux_frame_len) { |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 612 | size_t hlen = h3_decode_frm_header(&ftype, &flen, b); |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 613 | if (!hlen) |
| 614 | break; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 615 | |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 616 | h3_debug_printf(stderr, "%s: ftype: %lu, flen: %lu\n", |
| 617 | __func__, ftype, flen); |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 618 | |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 619 | h3s->demux_frame_type = ftype; |
| 620 | h3s->demux_frame_len = flen; |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 621 | total += hlen; |
Amaury Denoyelle | 417c7c0 | 2022-05-31 14:18:33 +0200 | [diff] [blame] | 622 | |
| 623 | if (!h3_is_frame_valid(h3c, qcs, ftype)) { |
| 624 | qcc_emit_cc_app(qcs->qcc, H3_FRAME_UNEXPECTED); |
Amaury Denoyelle | dca4c53 | 2022-06-07 18:24:34 +0200 | [diff] [blame] | 625 | return -1; |
Amaury Denoyelle | 417c7c0 | 2022-05-31 14:18:33 +0200 | [diff] [blame] | 626 | } |
| 627 | |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 628 | if (!b_data(b)) |
Amaury Denoyelle | 417c7c0 | 2022-05-31 14:18:33 +0200 | [diff] [blame] | 629 | break; |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 630 | } |
Amaury Denoyelle | 0484f92 | 2022-02-15 16:59:39 +0100 | [diff] [blame] | 631 | |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 632 | flen = h3s->demux_frame_len; |
| 633 | ftype = h3s->demux_frame_type; |
Amaury Denoyelle | 80097cc | 2022-05-24 11:13:46 +0200 | [diff] [blame] | 634 | |
| 635 | /* Do not demux incomplete frames except H3 DATA which can be |
| 636 | * fragmented in multiple HTX blocks. |
| 637 | */ |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 638 | if (flen > b_data(b) && ftype != H3_FT_DATA) { |
Amaury Denoyelle | 80097cc | 2022-05-24 11:13:46 +0200 | [diff] [blame] | 639 | /* Reject frames bigger than bufsize. |
| 640 | * |
| 641 | * TODO HEADERS should in complement be limited with H3 |
| 642 | * SETTINGS_MAX_FIELD_SECTION_SIZE parameter to prevent |
| 643 | * excessive decompressed size. |
| 644 | */ |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 645 | if (flen > QC_S_RX_BUF_SZ) { |
Amaury Denoyelle | 80097cc | 2022-05-24 11:13:46 +0200 | [diff] [blame] | 646 | qcc_emit_cc_app(qcs->qcc, H3_EXCESSIVE_LOAD); |
Amaury Denoyelle | dca4c53 | 2022-06-07 18:24:34 +0200 | [diff] [blame] | 647 | return -1; |
Amaury Denoyelle | 80097cc | 2022-05-24 11:13:46 +0200 | [diff] [blame] | 648 | } |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 649 | break; |
Amaury Denoyelle | b5454d4 | 2022-05-12 16:56:16 +0200 | [diff] [blame] | 650 | } |
Amaury Denoyelle | 80097cc | 2022-05-24 11:13:46 +0200 | [diff] [blame] | 651 | |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 652 | last_stream_frame = (fin && flen == b_data(b)); |
Amaury Denoyelle | 95b93a3 | 2022-02-14 15:49:53 +0100 | [diff] [blame] | 653 | |
Frédéric Lécaille | 6f7607e | 2022-05-25 22:25:37 +0200 | [diff] [blame] | 654 | h3_inc_frame_type_cnt(h3c->prx_counters, ftype); |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 655 | switch (ftype) { |
| 656 | case H3_FT_DATA: |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 657 | ret = h3_data_to_htx(qcs, b, flen, last_stream_frame); |
Amaury Denoyelle | 31e4f6e | 2022-02-15 17:30:27 +0100 | [diff] [blame] | 658 | /* TODO handle error reporting. Stream closure required. */ |
Amaury Denoyelle | 314578a | 2022-04-27 14:52:52 +0200 | [diff] [blame] | 659 | if (ret < 0) { ABORT_NOW(); } |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 660 | break; |
| 661 | case H3_FT_HEADERS: |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 662 | ret = h3_headers_to_htx(qcs, b, flen, last_stream_frame); |
Amaury Denoyelle | 2bc4786 | 2022-06-30 10:04:42 +0200 | [diff] [blame] | 663 | if (ret < 0) { |
| 664 | /* TODO for some error, it may be preferable to |
| 665 | * only close the stream once RESET_STREAM is |
| 666 | * supported. |
| 667 | */ |
| 668 | qcc_emit_cc_app(qcs->qcc, h3c->err); |
| 669 | return -1; |
| 670 | } |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 671 | break; |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 672 | case H3_FT_CANCEL_PUSH: |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 673 | case H3_FT_PUSH_PROMISE: |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 674 | case H3_FT_MAX_PUSH_ID: |
| 675 | case H3_FT_GOAWAY: |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 676 | /* Not supported */ |
Amaury Denoyelle | 80097cc | 2022-05-24 11:13:46 +0200 | [diff] [blame] | 677 | ret = flen; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 678 | break; |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 679 | case H3_FT_SETTINGS: |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 680 | ret = h3_parse_settings_frm(qcs->qcc->ctx, b, flen); |
Amaury Denoyelle | 8c6176b | 2022-05-24 18:16:49 +0200 | [diff] [blame] | 681 | if (ret < 0) { |
| 682 | qcc_emit_cc_app(qcs->qcc, h3c->err); |
Amaury Denoyelle | dca4c53 | 2022-06-07 18:24:34 +0200 | [diff] [blame] | 683 | return -1; |
Amaury Denoyelle | 8c6176b | 2022-05-24 18:16:49 +0200 | [diff] [blame] | 684 | } |
| 685 | h3c->flags |= H3_CF_SETTINGS_RECV; |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 686 | break; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 687 | default: |
Amaury Denoyelle | d1acaf9 | 2021-11-15 15:52:55 +0100 | [diff] [blame] | 688 | /* draft-ietf-quic-http34 9. Extensions to HTTP/3 |
Amaury Denoyelle | 302ecd4 | 2022-05-24 15:24:32 +0200 | [diff] [blame] | 689 | * |
| 690 | * Implementations MUST discard frames [...] that have unknown |
| 691 | * or unsupported types. |
Amaury Denoyelle | d1acaf9 | 2021-11-15 15:52:55 +0100 | [diff] [blame] | 692 | */ |
| 693 | h3_debug_printf(stderr, "ignore unknown frame type 0x%lx\n", ftype); |
Amaury Denoyelle | 80097cc | 2022-05-24 11:13:46 +0200 | [diff] [blame] | 694 | ret = flen; |
| 695 | break; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 696 | } |
Amaury Denoyelle | 314578a | 2022-04-27 14:52:52 +0200 | [diff] [blame] | 697 | |
Amaury Denoyelle | 291ee25 | 2022-05-02 10:35:39 +0200 | [diff] [blame] | 698 | if (ret) { |
Amaury Denoyelle | 291ee25 | 2022-05-02 10:35:39 +0200 | [diff] [blame] | 699 | BUG_ON(h3s->demux_frame_len < ret); |
| 700 | h3s->demux_frame_len -= ret; |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 701 | b_del(b, ret); |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 702 | total += ret; |
Amaury Denoyelle | 291ee25 | 2022-05-02 10:35:39 +0200 | [diff] [blame] | 703 | } |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 704 | } |
| 705 | |
Amaury Denoyelle | 03cc62c | 2022-04-27 16:53:16 +0200 | [diff] [blame] | 706 | /* TODO may be useful to wakeup the MUX if blocked due to full buffer. |
| 707 | * However, currently, io-cb of MUX does not handle Rx. |
| 708 | */ |
| 709 | |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 710 | return total; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 711 | } |
| 712 | |
Amaury Denoyelle | a587136 | 2021-10-07 16:26:12 +0200 | [diff] [blame] | 713 | /* Returns buffer for data sending. |
| 714 | * May be NULL if the allocation failed. |
| 715 | */ |
| 716 | static struct buffer *mux_get_buf(struct qcs *qcs) |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 717 | { |
Amaury Denoyelle | a587136 | 2021-10-07 16:26:12 +0200 | [diff] [blame] | 718 | if (!b_size(&qcs->tx.buf)) |
| 719 | b_alloc(&qcs->tx.buf); |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 720 | |
Amaury Denoyelle | a587136 | 2021-10-07 16:26:12 +0200 | [diff] [blame] | 721 | return &qcs->tx.buf; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 722 | } |
| 723 | |
Amaury Denoyelle | 6b92394 | 2022-05-23 14:25:53 +0200 | [diff] [blame] | 724 | /* Function used to emit stream data from <qcs> control uni-stream */ |
| 725 | 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] | 726 | { |
| 727 | int ret; |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 728 | struct h3c *h3c = ctx; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 729 | 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] | 730 | struct buffer pos, *res; |
Amaury Denoyelle | 65df3ad | 2022-05-24 15:06:10 +0200 | [diff] [blame] | 731 | size_t frm_len; |
Amaury Denoyelle | 65df3ad | 2022-05-24 15:06:10 +0200 | [diff] [blame] | 732 | |
Amaury Denoyelle | a717eb7 | 2022-05-30 15:51:01 +0200 | [diff] [blame] | 733 | TRACE_ENTER(H3_EV_TX_SETTINGS, qcs->qcc->conn, qcs); |
| 734 | |
Amaury Denoyelle | 65df3ad | 2022-05-24 15:06:10 +0200 | [diff] [blame] | 735 | BUG_ON_HOT(h3c->flags & H3_CF_SETTINGS_SENT); |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 736 | |
| 737 | ret = 0; |
Amaury Denoyelle | a587136 | 2021-10-07 16:26:12 +0200 | [diff] [blame] | 738 | pos = b_make((char *)data, sizeof(data), 0, 0); |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 739 | |
Amaury Denoyelle | 65df3ad | 2022-05-24 15:06:10 +0200 | [diff] [blame] | 740 | frm_len = quic_int_getsize(H3_SETTINGS_QPACK_MAX_TABLE_CAPACITY) + |
| 741 | quic_int_getsize(h3_settings_qpack_max_table_capacity) + |
| 742 | quic_int_getsize(H3_SETTINGS_QPACK_BLOCKED_STREAMS) + |
| 743 | quic_int_getsize(h3_settings_qpack_blocked_streams); |
| 744 | if (h3_settings_max_field_section_size) { |
| 745 | frm_len += quic_int_getsize(H3_SETTINGS_MAX_FIELD_SECTION_SIZE) + |
| 746 | quic_int_getsize(h3_settings_max_field_section_size); |
| 747 | } |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 748 | |
Amaury Denoyelle | 65df3ad | 2022-05-24 15:06:10 +0200 | [diff] [blame] | 749 | b_quic_enc_int(&pos, H3_UNI_S_T_CTRL); |
| 750 | /* Build a SETTINGS frame */ |
| 751 | b_quic_enc_int(&pos, H3_FT_SETTINGS); |
| 752 | b_quic_enc_int(&pos, frm_len); |
| 753 | b_quic_enc_int(&pos, H3_SETTINGS_QPACK_MAX_TABLE_CAPACITY); |
| 754 | b_quic_enc_int(&pos, h3_settings_qpack_max_table_capacity); |
| 755 | b_quic_enc_int(&pos, H3_SETTINGS_QPACK_BLOCKED_STREAMS); |
| 756 | b_quic_enc_int(&pos, h3_settings_qpack_blocked_streams); |
| 757 | if (h3_settings_max_field_section_size) { |
| 758 | b_quic_enc_int(&pos, H3_SETTINGS_MAX_FIELD_SECTION_SIZE); |
| 759 | b_quic_enc_int(&pos, h3_settings_max_field_section_size); |
| 760 | } |
Amaury Denoyelle | a587136 | 2021-10-07 16:26:12 +0200 | [diff] [blame] | 761 | |
Amaury Denoyelle | 65df3ad | 2022-05-24 15:06:10 +0200 | [diff] [blame] | 762 | res = mux_get_buf(qcs); |
| 763 | if (b_room(res) < b_data(&pos)) { |
| 764 | // TODO the mux should be put in blocked state, with |
| 765 | // the stream in state waiting for settings to be sent |
| 766 | ABORT_NOW(); |
| 767 | } |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 768 | |
Amaury Denoyelle | 65df3ad | 2022-05-24 15:06:10 +0200 | [diff] [blame] | 769 | ret = b_force_xfer(res, &pos, b_data(&pos)); |
| 770 | if (ret > 0) { |
| 771 | h3c->flags |= H3_CF_SETTINGS_SENT; |
| 772 | if (!(qcs->qcc->wait_event.events & SUB_RETRY_SEND)) |
| 773 | tasklet_wakeup(qcs->qcc->wait_event.tasklet); |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 774 | } |
| 775 | |
Amaury Denoyelle | a717eb7 | 2022-05-30 15:51:01 +0200 | [diff] [blame] | 776 | TRACE_LEAVE(H3_EV_TX_SETTINGS, qcs->qcc->conn, qcs); |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 777 | return ret; |
| 778 | } |
| 779 | |
Amaury Denoyelle | 15b0961 | 2021-08-24 16:20:27 +0200 | [diff] [blame] | 780 | static int h3_resp_headers_send(struct qcs *qcs, struct htx *htx) |
| 781 | { |
| 782 | struct buffer outbuf; |
| 783 | struct buffer headers_buf = BUF_NULL; |
| 784 | struct buffer *res; |
| 785 | struct http_hdr list[global.tune.max_http_hdr]; |
| 786 | struct htx_sl *sl; |
| 787 | struct htx_blk *blk; |
| 788 | enum htx_blk_type type; |
| 789 | int frame_length_size; /* size in bytes of frame length varint field */ |
| 790 | int ret = 0; |
| 791 | int hdr; |
| 792 | int status = 0; |
| 793 | |
Amaury Denoyelle | a717eb7 | 2022-05-30 15:51:01 +0200 | [diff] [blame] | 794 | TRACE_ENTER(H3_EV_TX_HDR, qcs->qcc->conn, qcs); |
| 795 | |
Amaury Denoyelle | 15b0961 | 2021-08-24 16:20:27 +0200 | [diff] [blame] | 796 | sl = NULL; |
| 797 | hdr = 0; |
| 798 | for (blk = htx_get_head_blk(htx); blk; blk = htx_get_next_blk(htx, blk)) { |
| 799 | type = htx_get_blk_type(blk); |
| 800 | |
| 801 | if (type == HTX_BLK_UNUSED) |
| 802 | continue; |
| 803 | |
| 804 | if (type == HTX_BLK_EOH) |
| 805 | break; |
| 806 | |
| 807 | if (type == HTX_BLK_RES_SL) { |
| 808 | /* start-line -> HEADERS h3 frame */ |
| 809 | BUG_ON(sl); |
| 810 | sl = htx_get_blk_ptr(htx, blk); |
| 811 | /* TODO should be on h3 layer */ |
| 812 | status = sl->info.res.status; |
| 813 | } |
| 814 | else if (type == HTX_BLK_HDR) { |
Amaury Denoyelle | 60ef19f | 2022-06-14 17:38:36 +0200 | [diff] [blame] | 815 | if (unlikely(hdr >= sizeof(list) / sizeof(list[0]) - 1)) |
Amaury Denoyelle | fa7fadc | 2022-06-15 15:52:27 +0200 | [diff] [blame] | 816 | goto err; |
Amaury Denoyelle | 15b0961 | 2021-08-24 16:20:27 +0200 | [diff] [blame] | 817 | list[hdr].n = htx_get_blk_name(htx, blk); |
| 818 | list[hdr].v = htx_get_blk_value(htx, blk); |
| 819 | hdr++; |
| 820 | } |
| 821 | else { |
| 822 | ABORT_NOW(); |
| 823 | goto err; |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | BUG_ON(!sl); |
| 828 | |
| 829 | list[hdr].n = ist(""); |
| 830 | |
Amaury Denoyelle | d3d97c6 | 2021-10-05 11:45:58 +0200 | [diff] [blame] | 831 | res = mux_get_buf(qcs); |
Amaury Denoyelle | 15b0961 | 2021-08-24 16:20:27 +0200 | [diff] [blame] | 832 | |
| 833 | /* At least 5 bytes to store frame type + length as a varint max size */ |
| 834 | if (b_room(res) < 5) |
| 835 | ABORT_NOW(); |
| 836 | |
| 837 | b_reset(&outbuf); |
| 838 | outbuf = b_make(b_tail(res), b_contig_space(res), 0, 0); |
| 839 | /* Start the headers after frame type + length */ |
| 840 | headers_buf = b_make(b_head(res) + 5, b_size(res) - 5, 0, 0); |
| 841 | |
| 842 | if (qpack_encode_field_section_line(&headers_buf)) |
| 843 | ABORT_NOW(); |
| 844 | if (qpack_encode_int_status(&headers_buf, status)) |
| 845 | ABORT_NOW(); |
| 846 | |
| 847 | for (hdr = 0; hdr < sizeof(list) / sizeof(list[0]); ++hdr) { |
| 848 | if (isteq(list[hdr].n, ist(""))) |
| 849 | break; |
| 850 | |
Amaury Denoyelle | ffafb3d | 2022-02-15 16:10:42 +0100 | [diff] [blame] | 851 | /* draft-ietf-quic-http34 4.1. HTTP Message Exchanges |
| 852 | * Transfer codings (see Section 6.1 of [HTTP11]) are not |
| 853 | * defined for HTTP/3; the Transfer-Encoding header field MUST |
| 854 | * NOT be used. |
| 855 | */ |
| 856 | if (isteq(list[hdr].n, ist("transfer-encoding"))) |
| 857 | continue; |
| 858 | |
Amaury Denoyelle | 15b0961 | 2021-08-24 16:20:27 +0200 | [diff] [blame] | 859 | if (qpack_encode_header(&headers_buf, list[hdr].n, list[hdr].v)) |
| 860 | ABORT_NOW(); |
| 861 | } |
| 862 | |
| 863 | /* Now that all headers are encoded, we are certain that res buffer is |
| 864 | * big enough |
| 865 | */ |
| 866 | frame_length_size = quic_int_getsize(b_data(&headers_buf)); |
| 867 | res->head += 4 - frame_length_size; |
| 868 | b_putchr(res, 0x01); /* h3 HEADERS frame type */ |
| 869 | if (!b_quic_enc_int(res, b_data(&headers_buf))) |
| 870 | ABORT_NOW(); |
| 871 | b_add(res, b_data(&headers_buf)); |
| 872 | |
| 873 | ret = 0; |
| 874 | blk = htx_get_head_blk(htx); |
| 875 | while (blk) { |
| 876 | type = htx_get_blk_type(blk); |
| 877 | ret += htx_get_blksz(blk); |
| 878 | blk = htx_remove_blk(htx, blk); |
| 879 | if (type == HTX_BLK_EOH) |
| 880 | break; |
| 881 | } |
| 882 | |
Amaury Denoyelle | a717eb7 | 2022-05-30 15:51:01 +0200 | [diff] [blame] | 883 | TRACE_LEAVE(H3_EV_TX_HDR, qcs->qcc->conn, qcs); |
Amaury Denoyelle | 15b0961 | 2021-08-24 16:20:27 +0200 | [diff] [blame] | 884 | return ret; |
| 885 | |
| 886 | err: |
Amaury Denoyelle | a717eb7 | 2022-05-30 15:51:01 +0200 | [diff] [blame] | 887 | TRACE_DEVEL("leaving on error", H3_EV_TX_HDR, qcs->qcc->conn, qcs); |
Amaury Denoyelle | 15b0961 | 2021-08-24 16:20:27 +0200 | [diff] [blame] | 888 | return 0; |
| 889 | } |
| 890 | |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 891 | /* Returns the total of bytes sent. */ |
| 892 | static int h3_resp_data_send(struct qcs *qcs, struct buffer *buf, size_t count) |
| 893 | { |
| 894 | struct buffer outbuf; |
| 895 | struct buffer *res; |
| 896 | size_t total = 0; |
| 897 | struct htx *htx; |
Amaury Denoyelle | a543eb1 | 2021-10-06 14:53:13 +0200 | [diff] [blame] | 898 | int bsize, fsize, hsize; |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 899 | struct htx_blk *blk; |
| 900 | enum htx_blk_type type; |
| 901 | |
Amaury Denoyelle | a717eb7 | 2022-05-30 15:51:01 +0200 | [diff] [blame] | 902 | TRACE_ENTER(H3_EV_TX_DATA, qcs->qcc->conn, qcs); |
| 903 | |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 904 | htx = htx_from_buf(buf); |
| 905 | |
| 906 | new_frame: |
| 907 | if (!count || htx_is_empty(htx)) |
| 908 | goto end; |
| 909 | |
| 910 | blk = htx_get_head_blk(htx); |
| 911 | type = htx_get_blk_type(blk); |
| 912 | fsize = bsize = htx_get_blksz(blk); |
| 913 | |
| 914 | if (type != HTX_BLK_DATA) |
| 915 | goto end; |
| 916 | |
Amaury Denoyelle | d3d97c6 | 2021-10-05 11:45:58 +0200 | [diff] [blame] | 917 | res = mux_get_buf(qcs); |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 918 | |
| 919 | if (fsize > count) |
| 920 | fsize = count; |
| 921 | |
Amaury Denoyelle | a543eb1 | 2021-10-06 14:53:13 +0200 | [diff] [blame] | 922 | /* h3 DATA headers : 1-byte frame type + varint frame length */ |
| 923 | hsize = 1 + QUIC_VARINT_MAX_SIZE; |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 924 | |
Amaury Denoyelle | a543eb1 | 2021-10-06 14:53:13 +0200 | [diff] [blame] | 925 | while (1) { |
| 926 | b_reset(&outbuf); |
| 927 | outbuf = b_make(b_tail(res), b_contig_space(res), 0, 0); |
| 928 | if (b_size(&outbuf) > hsize || !b_space_wraps(res)) |
| 929 | break; |
| 930 | b_slow_realign(res, trash.area, b_data(res)); |
| 931 | } |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 932 | |
Amaury Denoyelle | 84ea8dc | 2021-12-03 14:40:01 +0100 | [diff] [blame] | 933 | /* Not enough room for headers and at least one data byte, block the |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 934 | * stream. It is expected that the stream connector layer will subscribe |
| 935 | * on SEND. |
Amaury Denoyelle | a543eb1 | 2021-10-06 14:53:13 +0200 | [diff] [blame] | 936 | */ |
Amaury Denoyelle | 84ea8dc | 2021-12-03 14:40:01 +0100 | [diff] [blame] | 937 | if (b_size(&outbuf) <= hsize) { |
| 938 | qcs->flags |= QC_SF_BLK_MROOM; |
| 939 | goto end; |
| 940 | } |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 941 | |
Amaury Denoyelle | a543eb1 | 2021-10-06 14:53:13 +0200 | [diff] [blame] | 942 | if (b_size(&outbuf) < hsize + fsize) |
| 943 | fsize = b_size(&outbuf) - hsize; |
| 944 | BUG_ON(fsize <= 0); |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 945 | |
Amaury Denoyelle | a543eb1 | 2021-10-06 14:53:13 +0200 | [diff] [blame] | 946 | b_putchr(&outbuf, 0x00); /* h3 frame type = DATA */ |
| 947 | b_quic_enc_int(&outbuf, fsize); /* h3 frame length */ |
| 948 | |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 949 | b_putblk(&outbuf, htx_get_blk_ptr(htx, blk), fsize); |
Amaury Denoyelle | a543eb1 | 2021-10-06 14:53:13 +0200 | [diff] [blame] | 950 | total += fsize; |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 951 | count -= fsize; |
| 952 | |
| 953 | if (fsize == bsize) |
| 954 | htx_remove_blk(htx, blk); |
| 955 | else |
| 956 | htx_cut_data_blk(htx, blk, fsize); |
| 957 | |
Amaury Denoyelle | a543eb1 | 2021-10-06 14:53:13 +0200 | [diff] [blame] | 958 | /* commit the buffer */ |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 959 | b_add(res, b_data(&outbuf)); |
| 960 | goto new_frame; |
| 961 | |
| 962 | end: |
Amaury Denoyelle | a717eb7 | 2022-05-30 15:51:01 +0200 | [diff] [blame] | 963 | TRACE_LEAVE(H3_EV_TX_DATA, qcs->qcc->conn, qcs); |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 964 | return total; |
| 965 | } |
| 966 | |
Willy Tarreau | 3215e73 | 2022-05-27 10:09:11 +0200 | [diff] [blame] | 967 | size_t h3_snd_buf(struct stconn *sc, struct buffer *buf, size_t count, int flags) |
Amaury Denoyelle | 26dfd90 | 2021-08-24 16:33:53 +0200 | [diff] [blame] | 968 | { |
| 969 | size_t total = 0; |
Willy Tarreau | 3215e73 | 2022-05-27 10:09:11 +0200 | [diff] [blame] | 970 | struct qcs *qcs = __sc_mux_strm(sc); |
Amaury Denoyelle | 26dfd90 | 2021-08-24 16:33:53 +0200 | [diff] [blame] | 971 | struct htx *htx; |
| 972 | enum htx_blk_type btype; |
| 973 | struct htx_blk *blk; |
| 974 | uint32_t bsize; |
| 975 | int32_t idx; |
| 976 | int ret; |
| 977 | |
Amaury Denoyelle | d8769d1 | 2022-03-25 15:28:33 +0100 | [diff] [blame] | 978 | h3_debug_printf(stderr, "%s\n", __func__); |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 979 | |
Amaury Denoyelle | 26dfd90 | 2021-08-24 16:33:53 +0200 | [diff] [blame] | 980 | htx = htx_from_buf(buf); |
| 981 | |
Amaury Denoyelle | 84ea8dc | 2021-12-03 14:40:01 +0100 | [diff] [blame] | 982 | while (count && !htx_is_empty(htx) && !(qcs->flags & QC_SF_BLK_MROOM)) { |
Amaury Denoyelle | 26dfd90 | 2021-08-24 16:33:53 +0200 | [diff] [blame] | 983 | idx = htx_get_head(htx); |
| 984 | blk = htx_get_blk(htx, idx); |
| 985 | btype = htx_get_blk_type(blk); |
| 986 | bsize = htx_get_blksz(blk); |
| 987 | |
| 988 | /* Not implemented : QUIC on backend side */ |
| 989 | BUG_ON(btype == HTX_BLK_REQ_SL); |
| 990 | |
| 991 | switch (btype) { |
| 992 | case HTX_BLK_RES_SL: |
Amaury Denoyelle | 15b0961 | 2021-08-24 16:20:27 +0200 | [diff] [blame] | 993 | /* start-line -> HEADERS h3 frame */ |
| 994 | ret = h3_resp_headers_send(qcs, htx); |
| 995 | if (ret > 0) { |
| 996 | total += ret; |
| 997 | count -= ret; |
| 998 | if (ret < bsize) |
| 999 | goto out; |
| 1000 | } |
| 1001 | break; |
Amaury Denoyelle | 26dfd90 | 2021-08-24 16:33:53 +0200 | [diff] [blame] | 1002 | |
| 1003 | case HTX_BLK_DATA: |
Amaury Denoyelle | 8e2a998 | 2021-08-24 16:24:37 +0200 | [diff] [blame] | 1004 | ret = h3_resp_data_send(qcs, buf, count); |
| 1005 | if (ret > 0) { |
| 1006 | htx = htx_from_buf(buf); |
| 1007 | total += ret; |
| 1008 | count -= ret; |
| 1009 | if (ret < bsize) |
| 1010 | goto out; |
| 1011 | } |
| 1012 | break; |
Amaury Denoyelle | 26dfd90 | 2021-08-24 16:33:53 +0200 | [diff] [blame] | 1013 | |
| 1014 | case HTX_BLK_TLR: |
| 1015 | case HTX_BLK_EOT: |
| 1016 | /* TODO trailers */ |
| 1017 | |
| 1018 | default: |
| 1019 | htx_remove_blk(htx, blk); |
| 1020 | total += bsize; |
| 1021 | count -= bsize; |
| 1022 | break; |
| 1023 | } |
| 1024 | } |
| 1025 | |
Amaury Denoyelle | c2025c1 | 2021-12-03 15:03:36 +0100 | [diff] [blame] | 1026 | if ((htx->flags & HTX_FL_EOM) && htx_is_empty(htx)) |
| 1027 | qcs->flags |= QC_SF_FIN_STREAM; |
| 1028 | |
Amaury Denoyelle | 26dfd90 | 2021-08-24 16:33:53 +0200 | [diff] [blame] | 1029 | out: |
Amaury Denoyelle | a543eb1 | 2021-10-06 14:53:13 +0200 | [diff] [blame] | 1030 | if (total) { |
| 1031 | if (!(qcs->qcc->wait_event.events & SUB_RETRY_SEND)) |
| 1032 | tasklet_wakeup(qcs->qcc->wait_event.tasklet); |
| 1033 | } |
| 1034 | |
Amaury Denoyelle | 26dfd90 | 2021-08-24 16:33:53 +0200 | [diff] [blame] | 1035 | return total; |
Amaury Denoyelle | f52151d | 2021-08-24 16:11:18 +0200 | [diff] [blame] | 1036 | } |
| 1037 | |
Amaury Denoyelle | c015679 | 2022-06-03 15:29:07 +0200 | [diff] [blame] | 1038 | static int h3_attach(struct qcs *qcs, void *conn_ctx) |
Amaury Denoyelle | 67e92d3 | 2022-04-27 18:04:01 +0200 | [diff] [blame] | 1039 | { |
| 1040 | struct h3s *h3s; |
| 1041 | |
Amaury Denoyelle | d5581d5 | 2022-05-30 15:51:31 +0200 | [diff] [blame] | 1042 | TRACE_ENTER(H3_EV_H3S_NEW, qcs->qcc->conn, qcs); |
| 1043 | |
Amaury Denoyelle | 67e92d3 | 2022-04-27 18:04:01 +0200 | [diff] [blame] | 1044 | h3s = pool_alloc(pool_head_h3s); |
| 1045 | if (!h3s) |
| 1046 | return 1; |
| 1047 | |
| 1048 | qcs->ctx = h3s; |
Amaury Denoyelle | c015679 | 2022-06-03 15:29:07 +0200 | [diff] [blame] | 1049 | h3s->h3c = conn_ctx; |
| 1050 | |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 1051 | h3s->demux_frame_len = 0; |
| 1052 | h3s->demux_frame_type = 0; |
Amaury Denoyelle | 3555064 | 2022-05-24 15:14:53 +0200 | [diff] [blame] | 1053 | h3s->flags = 0; |
Amaury Denoyelle | 48f01bd | 2022-04-27 15:37:20 +0200 | [diff] [blame] | 1054 | |
Amaury Denoyelle | 3236a8e | 2022-05-24 15:24:03 +0200 | [diff] [blame] | 1055 | if (quic_stream_is_bidi(qcs->id)) { |
| 1056 | h3s->type = H3S_T_REQ; |
| 1057 | } |
| 1058 | else { |
| 1059 | /* stream type must be decoded for unidirectional streams */ |
| 1060 | h3s->type = H3S_T_UNKNOWN; |
| 1061 | } |
| 1062 | |
Amaury Denoyelle | d5581d5 | 2022-05-30 15:51:31 +0200 | [diff] [blame] | 1063 | TRACE_LEAVE(H3_EV_H3S_NEW, qcs->qcc->conn, qcs); |
Amaury Denoyelle | 67e92d3 | 2022-04-27 18:04:01 +0200 | [diff] [blame] | 1064 | return 0; |
| 1065 | } |
| 1066 | |
Amaury Denoyelle | 67e92d3 | 2022-04-27 18:04:01 +0200 | [diff] [blame] | 1067 | static void h3_detach(struct qcs *qcs) |
| 1068 | { |
| 1069 | struct h3s *h3s = qcs->ctx; |
Amaury Denoyelle | d5581d5 | 2022-05-30 15:51:31 +0200 | [diff] [blame] | 1070 | |
| 1071 | TRACE_ENTER(H3_EV_H3S_END, qcs->qcc->conn, qcs); |
| 1072 | |
Amaury Denoyelle | 67e92d3 | 2022-04-27 18:04:01 +0200 | [diff] [blame] | 1073 | pool_free(pool_head_h3s, h3s); |
| 1074 | qcs->ctx = NULL; |
Amaury Denoyelle | d5581d5 | 2022-05-30 15:51:31 +0200 | [diff] [blame] | 1075 | |
| 1076 | TRACE_LEAVE(H3_EV_H3S_END, qcs->qcc->conn, qcs); |
Amaury Denoyelle | 67e92d3 | 2022-04-27 18:04:01 +0200 | [diff] [blame] | 1077 | } |
| 1078 | |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 1079 | static int h3_finalize(void *ctx) |
| 1080 | { |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 1081 | struct h3c *h3c = ctx; |
Amaury Denoyelle | 9cc4751 | 2022-05-24 16:27:41 +0200 | [diff] [blame] | 1082 | struct qcs *qcs; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 1083 | |
Amaury Denoyelle | b143723 | 2022-07-08 11:53:22 +0200 | [diff] [blame^] | 1084 | qcs = qcc_init_stream_local(h3c->qcc, 0); |
Amaury Denoyelle | 9cc4751 | 2022-05-24 16:27:41 +0200 | [diff] [blame] | 1085 | if (!qcs) |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 1086 | return 0; |
| 1087 | |
Amaury Denoyelle | 9cc4751 | 2022-05-24 16:27:41 +0200 | [diff] [blame] | 1088 | h3_control_send(qcs, h3c); |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 1089 | |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 1090 | return 1; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 1091 | } |
| 1092 | |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 1093 | /* Initialize the HTTP/3 context for <qcc> mux. |
| 1094 | * Return 1 if succeeded, 0 if not. |
| 1095 | */ |
| 1096 | static int h3_init(struct qcc *qcc) |
| 1097 | { |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 1098 | struct h3c *h3c; |
Frédéric Lécaille | 6f7607e | 2022-05-25 22:25:37 +0200 | [diff] [blame] | 1099 | struct quic_conn *qc = qcc->conn->handle.qc; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 1100 | |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 1101 | h3c = pool_alloc(pool_head_h3c); |
| 1102 | if (!h3c) |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 1103 | goto fail_no_h3; |
| 1104 | |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 1105 | h3c->qcc = qcc; |
| 1106 | h3c->err = H3_NO_ERROR; |
| 1107 | h3c->flags = 0; |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 1108 | |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 1109 | qcc->ctx = h3c; |
Frédéric Lécaille | 6f7607e | 2022-05-25 22:25:37 +0200 | [diff] [blame] | 1110 | h3c->prx_counters = |
| 1111 | EXTRA_COUNTERS_GET(qc->li->bind_conf->frontend->extra_counters_fe, |
| 1112 | &h3_stats_module); |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 1113 | LIST_INIT(&h3c->buf_wait.list); |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 1114 | |
| 1115 | return 1; |
| 1116 | |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 1117 | fail_no_h3: |
| 1118 | return 0; |
| 1119 | } |
| 1120 | |
Amaury Denoyelle | 8347f27 | 2022-03-29 14:46:55 +0200 | [diff] [blame] | 1121 | static void h3_release(void *ctx) |
| 1122 | { |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 1123 | struct h3c *h3c = ctx; |
Amaury Denoyelle | 8d1ecac | 2022-05-24 14:55:43 +0200 | [diff] [blame] | 1124 | pool_free(pool_head_h3c, h3c); |
Amaury Denoyelle | 8347f27 | 2022-03-29 14:46:55 +0200 | [diff] [blame] | 1125 | } |
| 1126 | |
Amaury Denoyelle | 198d35f | 2022-04-01 17:56:58 +0200 | [diff] [blame] | 1127 | /* Check if the H3 connection can still be considered as active. |
| 1128 | * |
| 1129 | * Return true if active else false. |
| 1130 | */ |
| 1131 | static int h3_is_active(const struct qcc *qcc, void *ctx) |
| 1132 | { |
| 1133 | if (qcc->strms[QCS_CLT_BIDI].nb_streams) |
| 1134 | return 1; |
| 1135 | |
| 1136 | return 0; |
| 1137 | } |
| 1138 | |
Frédéric Lécaille | 6f7607e | 2022-05-25 22:25:37 +0200 | [diff] [blame] | 1139 | /* Increment the h3 error code counters for <error_code> value */ |
| 1140 | static void h3_stats_inc_err_cnt(void *ctx, int err_code) |
| 1141 | { |
| 1142 | struct h3c *h3c = ctx; |
| 1143 | |
| 1144 | h3_inc_err_cnt(h3c->prx_counters, err_code); |
| 1145 | } |
| 1146 | |
Amaury Denoyelle | 016aa93 | 2022-05-30 15:49:36 +0200 | [diff] [blame] | 1147 | /* h3 trace handler */ |
| 1148 | static void h3_trace(enum trace_level level, uint64_t mask, |
| 1149 | const struct trace_source *src, |
| 1150 | const struct ist where, const struct ist func, |
| 1151 | const void *a1, const void *a2, const void *a3, const void *a4) |
| 1152 | { |
| 1153 | const struct connection *conn = a1; |
| 1154 | const struct qcc *qcc = conn ? conn->ctx : NULL; |
| 1155 | const struct qcs *qcs = a2; |
| 1156 | |
| 1157 | if (src->verbosity > H3_VERB_CLEAN) { |
| 1158 | chunk_appendf(&trace_buf, " : qcc=%p(F)", qcc); |
| 1159 | |
| 1160 | if (qcs) |
Frédéric Lécaille | 628e89c | 2022-06-24 12:13:53 +0200 | [diff] [blame] | 1161 | chunk_appendf(&trace_buf, " qcs=%p(%llu)", qcs, (ull)qcs->id); |
Amaury Denoyelle | 016aa93 | 2022-05-30 15:49:36 +0200 | [diff] [blame] | 1162 | } |
| 1163 | } |
| 1164 | |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 1165 | /* HTTP/3 application layer operations */ |
| 1166 | const struct qcc_app_ops h3_ops = { |
| 1167 | .init = h3_init, |
Amaury Denoyelle | 67e92d3 | 2022-04-27 18:04:01 +0200 | [diff] [blame] | 1168 | .attach = h3_attach, |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 1169 | .decode_qcs = h3_decode_qcs, |
Amaury Denoyelle | abbe91e | 2021-11-12 16:09:29 +0100 | [diff] [blame] | 1170 | .snd_buf = h3_snd_buf, |
Amaury Denoyelle | 67e92d3 | 2022-04-27 18:04:01 +0200 | [diff] [blame] | 1171 | .detach = h3_detach, |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 1172 | .finalize = h3_finalize, |
Amaury Denoyelle | 198d35f | 2022-04-01 17:56:58 +0200 | [diff] [blame] | 1173 | .is_active = h3_is_active, |
Amaury Denoyelle | 8347f27 | 2022-03-29 14:46:55 +0200 | [diff] [blame] | 1174 | .release = h3_release, |
Frédéric Lécaille | 6f7607e | 2022-05-25 22:25:37 +0200 | [diff] [blame] | 1175 | .inc_err_cnt = h3_stats_inc_err_cnt, |
Frédéric Lécaille | ccac11f | 2021-03-03 16:09:02 +0100 | [diff] [blame] | 1176 | }; |