Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1 | /* |
Willy Tarreau | 3dfb7da | 2022-03-02 22:33:39 +0100 | [diff] [blame] | 2 | * Copyright 2019 HAProxy Technologies, Frederic Lecaille <flecaille@haproxy.com> |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version |
| 7 | * 2 of the License, or (at your option) any later version. |
| 8 | */ |
| 9 | |
Amaury Denoyelle | 5c25dc5 | 2022-09-30 17:44:15 +0200 | [diff] [blame] | 10 | #include <string.h> |
| 11 | |
Frédéric Lécaille | 8090b51 | 2020-11-30 16:19:22 +0100 | [diff] [blame] | 12 | #include <import/eb64tree.h> |
Amaury Denoyelle | 40c24f1 | 2023-01-27 17:47:49 +0100 | [diff] [blame] | 13 | #include <haproxy/buf-t.h> |
| 14 | #include <haproxy/chunk.h> |
| 15 | #include <haproxy/pool.h> |
Amaury Denoyelle | 92fa63f | 2022-09-30 18:11:13 +0200 | [diff] [blame] | 16 | #include <haproxy/quic_conn-t.h> |
Amaury Denoyelle | 5c25dc5 | 2022-09-30 17:44:15 +0200 | [diff] [blame] | 17 | #include <haproxy/quic_enc.h> |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 18 | #include <haproxy/quic_frame.h> |
Amaury Denoyelle | 5c25dc5 | 2022-09-30 17:44:15 +0200 | [diff] [blame] | 19 | #include <haproxy/quic_tp-t.h> |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 20 | #include <haproxy/trace.h> |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 21 | |
| 22 | #define TRACE_SOURCE &trace_quic |
| 23 | |
| 24 | const char *quic_frame_type_string(enum quic_frame_type ft) |
| 25 | { |
| 26 | switch (ft) { |
| 27 | case QUIC_FT_PADDING: |
| 28 | return "PADDING"; |
| 29 | case QUIC_FT_PING: |
| 30 | return "PING"; |
| 31 | case QUIC_FT_ACK: |
| 32 | return "ACK"; |
| 33 | case QUIC_FT_ACK_ECN: |
Frédéric Lécaille | 904caac | 2023-03-06 15:34:19 +0100 | [diff] [blame] | 34 | return "ACK_ECN"; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 35 | case QUIC_FT_RESET_STREAM: |
| 36 | return "RESET_STREAM"; |
| 37 | case QUIC_FT_STOP_SENDING: |
| 38 | return "STOP_SENDING"; |
| 39 | case QUIC_FT_CRYPTO: |
| 40 | return "CRYPTO"; |
| 41 | case QUIC_FT_NEW_TOKEN: |
| 42 | return "NEW_TOKEN"; |
| 43 | |
| 44 | case QUIC_FT_STREAM_8: |
| 45 | return "STREAM_8"; |
| 46 | case QUIC_FT_STREAM_9: |
| 47 | return "STREAM_9"; |
| 48 | case QUIC_FT_STREAM_A: |
| 49 | return "STREAM_A"; |
| 50 | case QUIC_FT_STREAM_B: |
| 51 | return "STREAM_B"; |
| 52 | case QUIC_FT_STREAM_C: |
| 53 | return "STREAM_C"; |
| 54 | case QUIC_FT_STREAM_D: |
| 55 | return "STREAM_D"; |
| 56 | case QUIC_FT_STREAM_E: |
| 57 | return "STREAM_E"; |
| 58 | case QUIC_FT_STREAM_F: |
| 59 | return "STREAM_F"; |
| 60 | |
| 61 | case QUIC_FT_MAX_DATA: |
| 62 | return "MAX_DATA"; |
| 63 | case QUIC_FT_MAX_STREAM_DATA: |
| 64 | return "MAX_STREAM_DATA"; |
| 65 | case QUIC_FT_MAX_STREAMS_BIDI: |
| 66 | return "MAX_STREAMS_BIDI"; |
| 67 | case QUIC_FT_MAX_STREAMS_UNI: |
| 68 | return "MAX_STREAMS_UNI"; |
| 69 | case QUIC_FT_DATA_BLOCKED: |
| 70 | return "DATA_BLOCKED"; |
| 71 | case QUIC_FT_STREAM_DATA_BLOCKED: |
| 72 | return "STREAM_DATA_BLOCKED"; |
| 73 | case QUIC_FT_STREAMS_BLOCKED_BIDI: |
| 74 | return "STREAMS_BLOCKED_BIDI"; |
| 75 | case QUIC_FT_STREAMS_BLOCKED_UNI: |
| 76 | return "STREAMS_BLOCKED_UNI"; |
| 77 | case QUIC_FT_NEW_CONNECTION_ID: |
| 78 | return "NEW_CONNECTION_ID"; |
| 79 | case QUIC_FT_RETIRE_CONNECTION_ID: |
| 80 | return "RETIRE_CONNECTION_ID"; |
| 81 | case QUIC_FT_PATH_CHALLENGE: |
| 82 | return "PATH_CHALLENGE"; |
| 83 | case QUIC_FT_PATH_RESPONSE: |
| 84 | return "PATH_RESPONSE"; |
| 85 | case QUIC_FT_CONNECTION_CLOSE: |
| 86 | return "CONNECTION_CLOSE"; |
| 87 | case QUIC_FT_CONNECTION_CLOSE_APP: |
| 88 | return "CONNECTION_CLOSE_APP"; |
| 89 | case QUIC_FT_HANDSHAKE_DONE: |
| 90 | return "HANDSHAKE_DONE"; |
| 91 | default: |
| 92 | return "UNKNOWN"; |
| 93 | } |
| 94 | } |
| 95 | |
Frédéric Lécaille | 010e532 | 2021-12-23 15:19:15 +0100 | [diff] [blame] | 96 | static void chunk_cc_phrase_appendf(struct buffer *buf, |
| 97 | const unsigned char *phr, size_t phrlen) |
| 98 | { |
| 99 | chunk_appendf(buf, " reason_phrase: '"); |
| 100 | while (phrlen--) |
| 101 | chunk_appendf(buf, "%c", *phr++); |
| 102 | chunk_appendf(buf, "'"); |
| 103 | } |
| 104 | |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 105 | /* Add traces to <buf> depending on <frm> frame type. */ |
| 106 | void chunk_frm_appendf(struct buffer *buf, const struct quic_frame *frm) |
| 107 | { |
| 108 | chunk_appendf(buf, " %s", quic_frame_type_string(frm->type)); |
| 109 | switch (frm->type) { |
| 110 | case QUIC_FT_CRYPTO: |
| 111 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 112 | const struct qf_crypto *crypto_frm = &frm->crypto; |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 113 | chunk_appendf(buf, " cfoff=%llu cflen=%llu", |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 114 | (ull)crypto_frm->offset, (ull)crypto_frm->len); |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 115 | break; |
| 116 | } |
| 117 | case QUIC_FT_RESET_STREAM: |
| 118 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 119 | const struct qf_reset_stream *rs_frm = &frm->reset_stream; |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 120 | chunk_appendf(buf, " id=%llu app_error_code=%llu final_size=%llu", |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 121 | (ull)rs_frm->id, (ull)rs_frm->app_error_code, (ull)rs_frm->final_size); |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 122 | break; |
| 123 | } |
| 124 | case QUIC_FT_STOP_SENDING: |
| 125 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 126 | const struct qf_stop_sending *ss_frm = &frm->stop_sending; |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 127 | chunk_appendf(&trace_buf, " id=%llu app_error_code=%llu", |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 128 | (ull)ss_frm->id, (ull)ss_frm->app_error_code); |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 129 | break; |
| 130 | } |
| 131 | case QUIC_FT_STREAM_8 ... QUIC_FT_STREAM_F: |
| 132 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 133 | const struct qf_stream *strm_frm = &frm->stream; |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 134 | chunk_appendf(&trace_buf, " uni=%d fin=%d id=%llu off=%llu len=%llu", |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 135 | !!(strm_frm->id & QUIC_STREAM_FRAME_ID_DIR_BIT), |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 136 | !!(frm->type & QUIC_STREAM_FRAME_TYPE_FIN_BIT), |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 137 | (ull)strm_frm->id, (ull)strm_frm->offset.key, (ull)strm_frm->len); |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 138 | break; |
| 139 | } |
| 140 | case QUIC_FT_MAX_DATA: |
| 141 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 142 | const struct qf_max_data *md_frm = &frm->max_data; |
| 143 | chunk_appendf(&trace_buf, " max_data=%llu", (ull)md_frm->max_data); |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 144 | break; |
| 145 | } |
| 146 | case QUIC_FT_MAX_STREAM_DATA: |
| 147 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 148 | const struct qf_max_stream_data *msd_frm = &frm->max_stream_data; |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 149 | chunk_appendf(&trace_buf, " id=%llu max_stream_data=%llu", |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 150 | (ull)msd_frm->id, (ull)msd_frm->max_stream_data); |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 151 | break; |
| 152 | } |
| 153 | case QUIC_FT_MAX_STREAMS_BIDI: |
| 154 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 155 | const struct qf_max_streams *ms_frm = &frm->max_streams_bidi; |
| 156 | chunk_appendf(&trace_buf, " max_streams=%llu", (ull)ms_frm->max_streams); |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 157 | break; |
| 158 | } |
| 159 | case QUIC_FT_MAX_STREAMS_UNI: |
| 160 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 161 | const struct qf_max_streams *ms_frm = &frm->max_streams_uni; |
| 162 | chunk_appendf(&trace_buf, " max_streams=%llu", (ull)ms_frm->max_streams); |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 163 | break; |
| 164 | } |
| 165 | case QUIC_FT_DATA_BLOCKED: |
| 166 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 167 | const struct qf_data_blocked *db_frm = &frm->data_blocked; |
| 168 | chunk_appendf(&trace_buf, " limit=%llu", (ull)db_frm->limit); |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 169 | break; |
| 170 | } |
| 171 | case QUIC_FT_STREAM_DATA_BLOCKED: |
| 172 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 173 | const struct qf_stream_data_blocked *sdb_frm = &frm->stream_data_blocked; |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 174 | chunk_appendf(&trace_buf, " id=%llu limit=%llu", |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 175 | (ull)sdb_frm->id, (ull)sdb_frm->limit); |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 176 | break; |
| 177 | } |
| 178 | case QUIC_FT_STREAMS_BLOCKED_BIDI: |
| 179 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 180 | const struct qf_streams_blocked *sb_frm = &frm->streams_blocked_bidi; |
| 181 | chunk_appendf(&trace_buf, " limit=%llu", (ull)sb_frm->limit); |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 182 | break; |
| 183 | } |
| 184 | case QUIC_FT_STREAMS_BLOCKED_UNI: |
| 185 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 186 | const struct qf_streams_blocked *sb_frm = &frm->streams_blocked_uni; |
| 187 | chunk_appendf(&trace_buf, " limit=%llu", (ull)sb_frm->limit); |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 188 | break; |
| 189 | } |
| 190 | case QUIC_FT_RETIRE_CONNECTION_ID: |
| 191 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 192 | const struct qf_retire_connection_id *rcid_frm = &frm->retire_connection_id; |
| 193 | chunk_appendf(&trace_buf, " seq_num=%llu", (ull)rcid_frm->seq_num); |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 194 | break; |
| 195 | } |
| 196 | case QUIC_FT_CONNECTION_CLOSE: |
| 197 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 198 | const struct qf_connection_close *cc_frm = &frm->connection_close; |
| 199 | size_t plen = QUIC_MIN((size_t)cc_frm->reason_phrase_len, sizeof cc_frm->reason_phrase); |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 200 | chunk_appendf(&trace_buf, |
| 201 | " error_code=%llu frame_type=%llu reason_phrase_len=%llu", |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 202 | (ull)cc_frm->error_code, (ull)cc_frm->frame_type, |
| 203 | (ull)cc_frm->reason_phrase_len); |
Frédéric Lécaille | 010e532 | 2021-12-23 15:19:15 +0100 | [diff] [blame] | 204 | if (plen) |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 205 | chunk_cc_phrase_appendf(&trace_buf, cc_frm->reason_phrase, plen); |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 206 | break; |
| 207 | } |
| 208 | case QUIC_FT_CONNECTION_CLOSE_APP: |
| 209 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 210 | const struct qf_connection_close_app *cc_frm = &frm->connection_close_app; |
| 211 | size_t plen = QUIC_MIN((size_t)cc_frm->reason_phrase_len, sizeof cc_frm->reason_phrase); |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 212 | chunk_appendf(&trace_buf, |
| 213 | " error_code=%llu reason_phrase_len=%llu", |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 214 | (ull)cc_frm->error_code, (ull)cc_frm->reason_phrase_len); |
Frédéric Lécaille | 010e532 | 2021-12-23 15:19:15 +0100 | [diff] [blame] | 215 | if (plen) |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 216 | chunk_cc_phrase_appendf(&trace_buf, cc_frm->reason_phrase, plen); |
Frédéric Lécaille | 1ede823 | 2021-12-23 14:11:25 +0100 | [diff] [blame] | 217 | break; |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 222 | /* Encode <frm> PADDING frame at <pos> buffer position, <end> being one byte past the end |
| 223 | * of this buffer. |
| 224 | * Returns 1 if succeeded (enough room in the buffer to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 225 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 226 | static int quic_build_padding_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 227 | struct quic_frame *frm, struct quic_conn *conn) |
| 228 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 229 | struct qf_padding *padding_frm = &frm->padding; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 230 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 231 | if (end - *pos < padding_frm->len - 1) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 232 | return 0; |
| 233 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 234 | memset(*pos, 0, padding_frm->len - 1); |
| 235 | *pos += padding_frm->len - 1; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 236 | |
| 237 | return 1; |
| 238 | } |
| 239 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 240 | /* Parse a PADDING frame at <pos> buffer position with <end> as end into <frm> frame. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 241 | * Return 1 if succeeded (enough room to parse this frame), 0 if not. |
| 242 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 243 | static int quic_parse_padding_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 244 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 245 | { |
| 246 | const unsigned char *beg; |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 247 | struct qf_padding *padding_frm = &frm->padding; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 248 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 249 | beg = *pos; |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 250 | padding_frm->len = 1; |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 251 | while (*pos < end && !**pos) |
| 252 | (*pos)++; |
| 253 | padding_frm->len += *pos - beg; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 254 | |
| 255 | return 1; |
| 256 | } |
| 257 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 258 | /* Encode a ACK frame at <pos> buffer position. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 259 | * Always succeeds. |
| 260 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 261 | static int quic_build_ping_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 262 | struct quic_frame *frm, struct quic_conn *conn) |
| 263 | { |
| 264 | /* No field */ |
| 265 | return 1; |
| 266 | } |
| 267 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 268 | /* Parse a PADDING frame from <pos> buffer position with <end> as end into <frm> frame. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 269 | * Always succeeds. |
| 270 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 271 | static int quic_parse_ping_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 272 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 273 | { |
| 274 | /* No field */ |
| 275 | return 1; |
| 276 | } |
| 277 | |
| 278 | /* Encode a ACK frame. |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 279 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 280 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 281 | static int quic_build_ack_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | fde2a98 | 2021-12-27 15:12:09 +0100 | [diff] [blame] | 282 | struct quic_frame *frm, struct quic_conn *qc) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 283 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 284 | struct qf_tx_ack *ack_frm = &frm->tx_ack; |
Frédéric Lécaille | 8090b51 | 2020-11-30 16:19:22 +0100 | [diff] [blame] | 285 | struct eb64_node *ar, *prev_ar; |
| 286 | struct quic_arng_node *ar_node, *prev_ar_node; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 287 | |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 288 | ar = eb64_last(&ack_frm->arngs->root); |
Frédéric Lécaille | a54e49d | 2022-05-10 15:15:24 +0200 | [diff] [blame] | 289 | ar_node = eb64_entry(ar, struct quic_arng_node, first); |
Frédéric Lécaille | 8f99194 | 2023-03-24 15:14:45 +0100 | [diff] [blame] | 290 | TRACE_PROTO("TX ack range", QUIC_EV_CONN_PRSAFRM, |
Frédéric Lécaille | fde2a98 | 2021-12-27 15:12:09 +0100 | [diff] [blame] | 291 | qc,, &ar_node->last, &ar_node->first.key); |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 292 | if (!quic_enc_int(pos, end, ar_node->last) || |
| 293 | !quic_enc_int(pos, end, ack_frm->ack_delay) || |
| 294 | !quic_enc_int(pos, end, ack_frm->arngs->sz - 1) || |
| 295 | !quic_enc_int(pos, end, ar_node->last - ar_node->first.key)) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 296 | return 0; |
| 297 | |
Frédéric Lécaille | 8090b51 | 2020-11-30 16:19:22 +0100 | [diff] [blame] | 298 | while ((prev_ar = eb64_prev(ar))) { |
Frédéric Lécaille | a54e49d | 2022-05-10 15:15:24 +0200 | [diff] [blame] | 299 | prev_ar_node = eb64_entry(prev_ar, struct quic_arng_node, first); |
Frédéric Lécaille | 8f99194 | 2023-03-24 15:14:45 +0100 | [diff] [blame] | 300 | TRACE_PROTO("TX ack range", QUIC_EV_CONN_PRSAFRM, qc,, |
Frédéric Lécaille | 8090b51 | 2020-11-30 16:19:22 +0100 | [diff] [blame] | 301 | &prev_ar_node->last, &prev_ar_node->first.key); |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 302 | if (!quic_enc_int(pos, end, ar_node->first.key - prev_ar_node->last - 2) || |
| 303 | !quic_enc_int(pos, end, prev_ar_node->last - prev_ar_node->first.key)) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 304 | return 0; |
| 305 | |
Frédéric Lécaille | 8090b51 | 2020-11-30 16:19:22 +0100 | [diff] [blame] | 306 | ar = prev_ar; |
Frédéric Lécaille | a54e49d | 2022-05-10 15:15:24 +0200 | [diff] [blame] | 307 | ar_node = eb64_entry(ar, struct quic_arng_node, first); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | return 1; |
| 311 | } |
| 312 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 313 | /* Parse an ACK frame header at <pos> buffer position with <end> as end into <frm> frame. |
| 314 | * Return 1 if succeeded (enough room at <pos> buffer position to parse this frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 315 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 316 | static int quic_parse_ack_frame_header(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 317 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 318 | { |
| 319 | int ret; |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 320 | struct qf_ack *ack_frm = &frm->ack; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 321 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 322 | ret = quic_dec_int(&ack_frm->largest_ack, pos, end); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 323 | if (!ret) |
| 324 | return 0; |
| 325 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 326 | ret = quic_dec_int(&ack_frm->ack_delay, pos, end); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 327 | if (!ret) |
| 328 | return 0; |
| 329 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 330 | ret = quic_dec_int(&ack_frm->ack_range_num, pos, end); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 331 | if (!ret) |
| 332 | return 0; |
| 333 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 334 | ret = quic_dec_int(&ack_frm->first_ack_range, pos, end); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 335 | if (!ret) |
| 336 | return 0; |
| 337 | |
| 338 | return 1; |
| 339 | } |
| 340 | |
| 341 | /* Encode a ACK_ECN frame. |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 342 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 343 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 344 | static int quic_build_ack_ecn_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 345 | struct quic_frame *frm, struct quic_conn *conn) |
| 346 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 347 | struct qf_ack *ack_frm = &frm->ack; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 348 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 349 | return quic_enc_int(pos, end, ack_frm->largest_ack) && |
| 350 | quic_enc_int(pos, end, ack_frm->ack_delay) && |
| 351 | quic_enc_int(pos, end, ack_frm->first_ack_range) && |
| 352 | quic_enc_int(pos, end, ack_frm->ack_range_num); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 353 | } |
| 354 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 355 | /* Parse an ACK_ECN frame at <pos> buffer position with <end> as end into <frm> frame. |
| 356 | * Return 1 if succeeded (enough at <pos> buffer position to parse this frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 357 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 358 | static int quic_parse_ack_ecn_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 359 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 360 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 361 | struct qf_ack *ack_frm = &frm->ack; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 362 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 363 | return quic_dec_int(&ack_frm->largest_ack, pos, end) && |
| 364 | quic_dec_int(&ack_frm->ack_delay, pos, end) && |
| 365 | quic_dec_int(&ack_frm->first_ack_range, pos, end) && |
| 366 | quic_dec_int(&ack_frm->ack_range_num, pos, end); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 367 | } |
| 368 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 369 | /* Encode a RESET_STREAM frame at <pos> buffer position. |
| 370 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 371 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 372 | static int quic_build_reset_stream_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 373 | struct quic_frame *frm, struct quic_conn *conn) |
| 374 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 375 | struct qf_reset_stream *rs_frm = &frm->reset_stream; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 376 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 377 | return quic_enc_int(pos, end, rs_frm->id) && |
| 378 | quic_enc_int(pos, end, rs_frm->app_error_code) && |
| 379 | quic_enc_int(pos, end, rs_frm->final_size); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 380 | } |
| 381 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 382 | /* Parse a RESET_STREAM frame at <pos> buffer position with <end> as end into <frm> frame. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 383 | * Return 1 if succeeded (enough room to parse this frame), 0 if not. |
| 384 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 385 | static int quic_parse_reset_stream_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 386 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 387 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 388 | struct qf_reset_stream *rs_frm = &frm->reset_stream; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 389 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 390 | return quic_dec_int(&rs_frm->id, pos, end) && |
| 391 | quic_dec_int(&rs_frm->app_error_code, pos, end) && |
| 392 | quic_dec_int(&rs_frm->final_size, pos, end); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | /* Encode a STOP_SENDING frame. |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 396 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 397 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 398 | static int quic_build_stop_sending_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 399 | struct quic_frame *frm, struct quic_conn *conn) |
| 400 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 401 | struct qf_stop_sending *ss_frm = &frm->stop_sending; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 402 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 403 | return quic_enc_int(pos, end, ss_frm->id) && |
| 404 | quic_enc_int(pos, end, ss_frm->app_error_code); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 405 | } |
| 406 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 407 | /* Parse a STOP_SENDING frame at <pos> buffer position with <end> as end into <frm> frame. |
| 408 | * Return 1 if succeeded (enough room at <pos> buffer position to parse this frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 409 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 410 | static int quic_parse_stop_sending_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 411 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 412 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 413 | struct qf_stop_sending *ss_frm = &frm->stop_sending; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 414 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 415 | return quic_dec_int(&ss_frm->id, pos, end) && |
| 416 | quic_dec_int(&ss_frm->app_error_code, pos, end); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 417 | } |
| 418 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 419 | /* Encode a CRYPTO frame at <pos> buffer position. |
| 420 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 421 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 422 | static int quic_build_crypto_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 423 | struct quic_frame *frm, struct quic_conn *conn) |
| 424 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 425 | struct qf_crypto *crypto_frm = &frm->crypto; |
| 426 | const struct quic_enc_level *qel = crypto_frm->qel; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 427 | size_t offset, len; |
| 428 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 429 | if (!quic_enc_int(pos, end, crypto_frm->offset) || |
| 430 | !quic_enc_int(pos, end, crypto_frm->len) || end - *pos < crypto_frm->len) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 431 | return 0; |
| 432 | |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 433 | len = crypto_frm->len; |
| 434 | offset = crypto_frm->offset; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 435 | while (len) { |
| 436 | int idx; |
| 437 | size_t to_copy; |
| 438 | const unsigned char *data; |
| 439 | |
| 440 | idx = offset >> QUIC_CRYPTO_BUF_SHIFT; |
| 441 | to_copy = qel->tx.crypto.bufs[idx]->sz - (offset & QUIC_CRYPTO_BUF_MASK); |
| 442 | if (to_copy > len) |
| 443 | to_copy = len; |
| 444 | data = qel->tx.crypto.bufs[idx]->data + (offset & QUIC_CRYPTO_BUF_MASK); |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 445 | memcpy(*pos, data, to_copy); |
| 446 | *pos += to_copy; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 447 | offset += to_copy; |
| 448 | len -= to_copy; |
| 449 | } |
| 450 | |
| 451 | return 1; |
| 452 | } |
| 453 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 454 | /* Parse a CRYPTO frame from <pos> buffer position with <end> as end into <frm> frame. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 455 | * Return 1 if succeeded (enough room to parse this frame), 0 if not. |
| 456 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 457 | static int quic_parse_crypto_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 458 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 459 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 460 | struct qf_crypto *crypto_frm = &frm->crypto; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 461 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 462 | if (!quic_dec_int(&crypto_frm->offset, pos, end) || |
| 463 | !quic_dec_int(&crypto_frm->len, pos, end) || end - *pos < crypto_frm->len) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 464 | return 0; |
| 465 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 466 | crypto_frm->data = *pos; |
| 467 | *pos += crypto_frm->len; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 468 | |
| 469 | return 1; |
| 470 | } |
| 471 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 472 | /* Encode a NEW_TOKEN frame at <pos> buffer position. |
| 473 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 474 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 475 | static int quic_build_new_token_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 476 | struct quic_frame *frm, struct quic_conn *conn) |
| 477 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 478 | struct qf_new_token *new_token_frm = &frm->new_token; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 479 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 480 | if (!quic_enc_int(pos, end, new_token_frm->len) || end - *pos < new_token_frm->len) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 481 | return 0; |
| 482 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 483 | memcpy(*pos, new_token_frm->data, new_token_frm->len); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 484 | |
| 485 | return 1; |
| 486 | } |
| 487 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 488 | /* Parse a NEW_TOKEN frame at <pos> buffer position with <end> as end into <frm> frame. |
| 489 | * Return 1 if succeeded (enough room at <pos> buffer position to parse this frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 490 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 491 | static int quic_parse_new_token_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 492 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 493 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 494 | struct qf_new_token *new_token_frm = &frm->new_token; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 495 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 496 | if (!quic_dec_int(&new_token_frm->len, pos, end) || end - *pos < new_token_frm->len) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 497 | return 0; |
| 498 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 499 | new_token_frm->data = *pos; |
| 500 | *pos += new_token_frm->len; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 501 | |
| 502 | return 1; |
| 503 | } |
| 504 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 505 | /* Encode a STREAM frame at <pos> buffer position. |
| 506 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 507 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 508 | static int quic_build_stream_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 509 | struct quic_frame *frm, struct quic_conn *conn) |
| 510 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 511 | struct qf_stream *strm_frm = &frm->stream; |
Amaury Denoyelle | 642ab06 | 2022-02-23 10:54:42 +0100 | [diff] [blame] | 512 | const unsigned char *wrap; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 513 | |
Amaury Denoyelle | 1dac018 | 2023-02-02 16:45:07 +0100 | [diff] [blame] | 514 | /* Caller must set OFF bit if and only if a non-null offset is used. */ |
| 515 | BUG_ON(!!(frm->type & QUIC_STREAM_FRAME_TYPE_OFF_BIT) != |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 516 | !!strm_frm->offset.key); |
Amaury Denoyelle | 1dac018 | 2023-02-02 16:45:07 +0100 | [diff] [blame] | 517 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 518 | if (!quic_enc_int(pos, end, strm_frm->id) || |
| 519 | ((frm->type & QUIC_STREAM_FRAME_TYPE_OFF_BIT) && !quic_enc_int(pos, end, strm_frm->offset.key)) || |
Frédéric Lécaille | 242fb1b | 2020-12-31 12:45:38 +0100 | [diff] [blame] | 520 | ((frm->type & QUIC_STREAM_FRAME_TYPE_LEN_BIT) && |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 521 | (!quic_enc_int(pos, end, strm_frm->len) || end - *pos < strm_frm->len))) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 522 | return 0; |
| 523 | |
Amaury Denoyelle | 19eaf88 | 2023-04-25 15:52:24 +0200 | [diff] [blame] | 524 | /* No need for data memcpy if no payload. */ |
| 525 | if (!strm_frm->len) |
| 526 | return 1; |
| 527 | |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 528 | wrap = (const unsigned char *)b_wrap(strm_frm->buf); |
| 529 | if (strm_frm->data + strm_frm->len > wrap) { |
| 530 | size_t to_copy = wrap - strm_frm->data; |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 531 | memcpy(*pos, strm_frm->data, to_copy); |
| 532 | *pos += to_copy; |
Amaury Denoyelle | 642ab06 | 2022-02-23 10:54:42 +0100 | [diff] [blame] | 533 | |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 534 | to_copy = strm_frm->len - to_copy; |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 535 | memcpy(*pos, b_orig(strm_frm->buf), to_copy); |
| 536 | *pos += to_copy; |
Amaury Denoyelle | 642ab06 | 2022-02-23 10:54:42 +0100 | [diff] [blame] | 537 | } |
| 538 | else { |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 539 | memcpy(*pos, strm_frm->data, strm_frm->len); |
| 540 | *pos += strm_frm->len; |
Frédéric Lécaille | 785d3bd | 2021-09-10 09:13:39 +0200 | [diff] [blame] | 541 | } |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 542 | |
| 543 | return 1; |
| 544 | } |
| 545 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 546 | /* Parse a STREAM frame at <pos> buffer position with <end> as end into <frm> frame. |
| 547 | * Return 1 if succeeded (enough room at <pos> buffer position to parse this frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 548 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 549 | static int quic_parse_stream_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 550 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 551 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 552 | struct qf_stream *strm_frm = &frm->stream; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 553 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 554 | if (!quic_dec_int(&strm_frm->id, pos, end)) |
Frédéric Lécaille | 129a351 | 2020-12-31 10:57:04 +0100 | [diff] [blame] | 555 | return 0; |
| 556 | |
| 557 | /* Offset parsing */ |
Frédéric Lécaille | 242fb1b | 2020-12-31 12:45:38 +0100 | [diff] [blame] | 558 | if (!(frm->type & QUIC_STREAM_FRAME_TYPE_OFF_BIT)) { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 559 | strm_frm->offset.key = 0; |
Frédéric Lécaille | 129a351 | 2020-12-31 10:57:04 +0100 | [diff] [blame] | 560 | } |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 561 | else if (!quic_dec_int((uint64_t *)&strm_frm->offset.key, pos, end)) |
Frédéric Lécaille | 129a351 | 2020-12-31 10:57:04 +0100 | [diff] [blame] | 562 | return 0; |
| 563 | |
| 564 | /* Length parsing */ |
Frédéric Lécaille | 242fb1b | 2020-12-31 12:45:38 +0100 | [diff] [blame] | 565 | if (!(frm->type & QUIC_STREAM_FRAME_TYPE_LEN_BIT)) { |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 566 | strm_frm->len = end - *pos; |
Frédéric Lécaille | 129a351 | 2020-12-31 10:57:04 +0100 | [diff] [blame] | 567 | } |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 568 | else if (!quic_dec_int(&strm_frm->len, pos, end) || end - *pos < strm_frm->len) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 569 | return 0; |
| 570 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 571 | strm_frm->data = *pos; |
| 572 | *pos += strm_frm->len; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 573 | |
| 574 | return 1; |
| 575 | } |
| 576 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 577 | /* Encode a MAX_DATA frame at <pos> buffer position. |
| 578 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 579 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 580 | static int quic_build_max_data_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 581 | struct quic_frame *frm, struct quic_conn *conn) |
| 582 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 583 | struct qf_max_data *md_frm = &frm->max_data; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 584 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 585 | return quic_enc_int(pos, end, md_frm->max_data); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 586 | } |
| 587 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 588 | /* Parse a MAX_DATA frame at <pos> buffer position with <end> as end into <frm> frame. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 589 | * Return 1 if succeeded (enough room to parse this frame), 0 if not. |
| 590 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 591 | static int quic_parse_max_data_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 592 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 593 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 594 | struct qf_max_data *md_frm = &frm->max_data; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 595 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 596 | return quic_dec_int(&md_frm->max_data, pos, end); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 597 | } |
| 598 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 599 | /* Encode a MAX_STREAM_DATA frame at <pos> buffer position. |
| 600 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 601 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 602 | static int quic_build_max_stream_data_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 603 | struct quic_frame *frm, struct quic_conn *conn) |
| 604 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 605 | struct qf_max_stream_data *msd_frm = &frm->max_stream_data; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 606 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 607 | return quic_enc_int(pos, end, msd_frm->id) && |
| 608 | quic_enc_int(pos, end, msd_frm->max_stream_data); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 609 | } |
| 610 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 611 | /* Parse a MAX_STREAM_DATA frame at <pos> buffer position with <end> as end into <frm> frame. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 612 | * Return 1 if succeeded (enough room to parse this frame), 0 if not. |
| 613 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 614 | static int quic_parse_max_stream_data_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 615 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 616 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 617 | struct qf_max_stream_data *msd_frm = &frm->max_stream_data; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 618 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 619 | return quic_dec_int(&msd_frm->id, pos, end) && |
| 620 | quic_dec_int(&msd_frm->max_stream_data, pos, end); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 621 | } |
| 622 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 623 | /* Encode a MAX_STREAMS frame for bidirectional streams at <buf> buffer position. |
| 624 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 625 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 626 | static int quic_build_max_streams_bidi_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 627 | struct quic_frame *frm, struct quic_conn *conn) |
| 628 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 629 | struct qf_max_streams *ms_frm = &frm->max_streams_bidi; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 630 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 631 | return quic_enc_int(pos, end, ms_frm->max_streams); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 632 | } |
| 633 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 634 | /* Parse a MAX_STREAMS frame for bidirectional streams at <pos> buffer position with <end> |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 635 | * as end into <frm> frame. |
| 636 | * Return 1 if succeeded (enough room to parse this frame), 0 if not. |
| 637 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 638 | static int quic_parse_max_streams_bidi_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 639 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 640 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 641 | struct qf_max_streams *ms_frm = &frm->max_streams_bidi; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 642 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 643 | return quic_dec_int(&ms_frm->max_streams, pos, end); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 644 | } |
| 645 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 646 | /* Encode a MAX_STREAMS frame for unidirectional streams at <pos> buffer position. |
| 647 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 648 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 649 | static int quic_build_max_streams_uni_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 650 | struct quic_frame *frm, struct quic_conn *conn) |
| 651 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 652 | struct qf_max_streams *ms_frm = &frm->max_streams_uni; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 653 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 654 | return quic_enc_int(pos, end, ms_frm->max_streams); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 655 | } |
| 656 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 657 | /* Parse a MAX_STREAMS frame for undirectional streams at <pos> buffer position with <end> |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 658 | * as end into <frm> frame. |
| 659 | * Return 1 if succeeded (enough room to parse this frame), 0 if not. |
| 660 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 661 | static int quic_parse_max_streams_uni_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 662 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 663 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 664 | struct qf_max_streams *ms_frm = &frm->max_streams_uni; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 665 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 666 | return quic_dec_int(&ms_frm->max_streams, pos, end); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 667 | } |
| 668 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 669 | /* Encode a DATA_BLOCKED frame at <pos> buffer position. |
| 670 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 671 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 672 | static int quic_build_data_blocked_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 673 | struct quic_frame *frm, struct quic_conn *conn) |
| 674 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 675 | struct qf_data_blocked *db_frm = &frm->data_blocked; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 676 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 677 | return quic_enc_int(pos, end, db_frm->limit); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 678 | } |
| 679 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 680 | /* Parse a DATA_BLOCKED frame at <pos> buffer position with <end> as end into <frm> frame. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 681 | * Return 1 if succeeded (enough room to parse this frame), 0 if not. |
| 682 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 683 | static int quic_parse_data_blocked_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 684 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 685 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 686 | struct qf_data_blocked *db_frm = &frm->data_blocked; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 687 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 688 | return quic_dec_int(&db_frm->limit, pos, end); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 689 | } |
| 690 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 691 | /* Encode a STREAM_DATA_BLOCKED at <pos> buffer position. |
| 692 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 693 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 694 | static int quic_build_stream_data_blocked_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 695 | struct quic_frame *frm, struct quic_conn *conn) |
| 696 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 697 | struct qf_stream_data_blocked *sdb_frm = &frm->stream_data_blocked; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 698 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 699 | return quic_enc_int(pos, end, sdb_frm->id) && |
| 700 | quic_enc_int(pos, end, sdb_frm->limit); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 701 | } |
| 702 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 703 | /* Parse a STREAM_DATA_BLOCKED frame at <pos> buffer position with <end> as end into <frm> frame. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 704 | * Return 1 if succeeded (enough room to parse this frame), 0 if not. |
| 705 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 706 | static int quic_parse_stream_data_blocked_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 707 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 708 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 709 | struct qf_stream_data_blocked *sdb_frm = &frm->stream_data_blocked; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 710 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 711 | return quic_dec_int(&sdb_frm->id, pos, end) && |
| 712 | quic_dec_int(&sdb_frm->limit, pos, end); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 713 | } |
| 714 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 715 | /* Encode a STREAMS_BLOCKED frame for bidirectional streams at <pos> buffer position. |
| 716 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 717 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 718 | static int quic_build_streams_blocked_bidi_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 719 | struct quic_frame *frm, struct quic_conn *conn) |
| 720 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 721 | struct qf_streams_blocked *sb_frm = &frm->streams_blocked_bidi; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 722 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 723 | return quic_enc_int(pos, end, sb_frm->limit); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 724 | } |
| 725 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 726 | /* Parse a STREAMS_BLOCKED frame for bidirectional streams at <pos> buffer position with <end> |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 727 | * as end into <frm> frame. |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 728 | * Return 1 if succeeded (enough room at <pos> buffer position to parse this frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 729 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 730 | static int quic_parse_streams_blocked_bidi_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 731 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 732 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 733 | struct qf_streams_blocked *sb_frm = &frm->streams_blocked_bidi; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 734 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 735 | return quic_dec_int(&sb_frm->limit, pos, end); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 736 | } |
| 737 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 738 | /* Encode a STREAMS_BLOCKED frame for unidirectional streams at <pos> buffer position. |
| 739 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 740 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 741 | static int quic_build_streams_blocked_uni_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 742 | struct quic_frame *frm, struct quic_conn *conn) |
| 743 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 744 | struct qf_streams_blocked *sb_frm = &frm->streams_blocked_uni; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 745 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 746 | return quic_enc_int(pos, end, sb_frm->limit); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 747 | } |
| 748 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 749 | /* Parse a STREAMS_BLOCKED frame for unidirectional streams at <pos> buffer position with <end> |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 750 | * as end into <frm> frame. |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 751 | * Return 1 if succeeded (enough room at <pos> buffer position to parse this frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 752 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 753 | static int quic_parse_streams_blocked_uni_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 754 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 755 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 756 | struct qf_streams_blocked *sb_frm = &frm->streams_blocked_uni; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 757 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 758 | return quic_dec_int(&sb_frm->limit, pos, end); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 759 | } |
| 760 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 761 | /* Encode a NEW_CONNECTION_ID frame at <pos> buffer position. |
| 762 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 763 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 764 | static int quic_build_new_connection_id_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 765 | struct quic_frame *frm, struct quic_conn *conn) |
| 766 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 767 | struct qf_new_connection_id *ncid_frm = &frm->new_connection_id; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 768 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 769 | if (!quic_enc_int(pos, end, ncid_frm->seq_num) || |
| 770 | !quic_enc_int(pos, end, ncid_frm->retire_prior_to) || |
| 771 | end - *pos < sizeof ncid_frm->cid.len + ncid_frm->cid.len + QUIC_STATELESS_RESET_TOKEN_LEN) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 772 | return 0; |
| 773 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 774 | *(*pos)++ = ncid_frm->cid.len; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 775 | |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 776 | if (ncid_frm->cid.len) { |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 777 | memcpy(*pos, ncid_frm->cid.data, ncid_frm->cid.len); |
| 778 | *pos += ncid_frm->cid.len; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 779 | } |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 780 | memcpy(*pos, ncid_frm->stateless_reset_token, QUIC_STATELESS_RESET_TOKEN_LEN); |
| 781 | *pos += QUIC_STATELESS_RESET_TOKEN_LEN; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 782 | |
| 783 | return 1; |
| 784 | } |
| 785 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 786 | /* Parse a NEW_CONNECTION_ID frame at <pos> buffer position with <end> as end into <frm> frame. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 787 | * Return 1 if succeeded (enough room to parse this frame), 0 if not. |
| 788 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 789 | static int quic_parse_new_connection_id_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 790 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 791 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 792 | struct qf_new_connection_id *ncid_frm = &frm->new_connection_id; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 793 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 794 | if (!quic_dec_int(&ncid_frm->seq_num, pos, end) || |
| 795 | !quic_dec_int(&ncid_frm->retire_prior_to, pos, end) || end <= *pos) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 796 | return 0; |
| 797 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 798 | ncid_frm->cid.len = *(*pos)++; |
| 799 | if (end - *pos < ncid_frm->cid.len + QUIC_STATELESS_RESET_TOKEN_LEN) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 800 | return 0; |
| 801 | |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 802 | if (ncid_frm->cid.len) { |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 803 | ncid_frm->cid.data = *pos; |
| 804 | *pos += ncid_frm->cid.len; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 805 | } |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 806 | ncid_frm->stateless_reset_token = *pos; |
| 807 | *pos += QUIC_STATELESS_RESET_TOKEN_LEN; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 808 | |
| 809 | return 1; |
| 810 | } |
| 811 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 812 | /* Encode a RETIRE_CONNECTION_ID frame at <pos> buffer position. |
| 813 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 814 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 815 | static int quic_build_retire_connection_id_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 816 | struct quic_frame *frm, struct quic_conn *conn) |
| 817 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 818 | struct qf_retire_connection_id *rcid_frm = &frm->retire_connection_id; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 819 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 820 | return quic_enc_int(pos, end, rcid_frm->seq_num); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 821 | } |
| 822 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 823 | /* Parse a RETIRE_CONNECTION_ID frame at <pos> buffer position with <end> as end into <frm> frame. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 824 | * Return 1 if succeeded (enough room to parse this frame), 0 if not. |
| 825 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 826 | static int quic_parse_retire_connection_id_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 827 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 828 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 829 | struct qf_retire_connection_id *rcid_frm = &frm->retire_connection_id; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 830 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 831 | return quic_dec_int(&rcid_frm->seq_num, pos, end); |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 832 | } |
| 833 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 834 | /* Encode a PATH_CHALLENGE frame at <pos> buffer position. |
| 835 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 836 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 837 | static int quic_build_path_challenge_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 838 | struct quic_frame *frm, struct quic_conn *conn) |
| 839 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 840 | struct qf_path_challenge *pc_frm = &frm->path_challenge; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 841 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 842 | if (end - *pos < sizeof pc_frm->data) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 843 | return 0; |
| 844 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 845 | memcpy(*pos, pc_frm->data, sizeof pc_frm->data); |
| 846 | *pos += sizeof pc_frm->data; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 847 | |
| 848 | return 1; |
| 849 | } |
| 850 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 851 | /* Parse a PATH_CHALLENGE frame at <pos> buffer position with <end> as end into <frm> frame. |
| 852 | * Return 1 if succeeded (enough room at <pos> buffer position to parse this frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 853 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 854 | static int quic_parse_path_challenge_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 855 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 856 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 857 | struct qf_path_challenge *pc_frm = &frm->path_challenge; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 858 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 859 | if (end - *pos < sizeof pc_frm->data) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 860 | return 0; |
| 861 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 862 | memcpy(pc_frm->data, *pos, sizeof pc_frm->data); |
| 863 | *pos += sizeof pc_frm->data; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 864 | |
| 865 | return 1; |
| 866 | } |
| 867 | |
| 868 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 869 | /* Encode a PATH_RESPONSE frame at <pos> buffer position. |
| 870 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 871 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 872 | static int quic_build_path_response_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 873 | struct quic_frame *frm, struct quic_conn *conn) |
| 874 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 875 | struct qf_path_challenge_response *pcr_frm = &frm->path_challenge_response; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 876 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 877 | if (end - *pos < sizeof pcr_frm->data) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 878 | return 0; |
| 879 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 880 | memcpy(*pos, pcr_frm->data, sizeof pcr_frm->data); |
| 881 | *pos += sizeof pcr_frm->data; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 882 | |
| 883 | return 1; |
| 884 | } |
| 885 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 886 | /* Parse a PATH_RESPONSE frame at <pos> buffer position with <end> as end into <frm> frame. |
| 887 | * Return 1 if succeeded (enough room at <pos> buffer position to parse this frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 888 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 889 | static int quic_parse_path_response_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 890 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 891 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 892 | struct qf_path_challenge_response *pcr_frm = &frm->path_challenge_response; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 893 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 894 | if (end - *pos < sizeof pcr_frm->data) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 895 | return 0; |
| 896 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 897 | memcpy(pcr_frm->data, *pos, sizeof pcr_frm->data); |
| 898 | *pos += sizeof pcr_frm->data; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 899 | |
| 900 | return 1; |
| 901 | } |
| 902 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 903 | /* Encode a CONNECTION_CLOSE frame at QUIC layer at <pos> buffer position. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 904 | * Note there exist two types of CONNECTION_CLOSE frame, one for the application layer |
| 905 | * and another at QUIC layer. |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 906 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 907 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 908 | static int quic_build_connection_close_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 909 | struct quic_frame *frm, struct quic_conn *conn) |
| 910 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 911 | struct qf_connection_close *cc_frm = &frm->connection_close; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 912 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 913 | if (!quic_enc_int(pos, end, cc_frm->error_code) || |
| 914 | !quic_enc_int(pos, end, cc_frm->frame_type) || |
| 915 | !quic_enc_int(pos, end, cc_frm->reason_phrase_len) || |
| 916 | end - *pos < cc_frm->reason_phrase_len) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 917 | return 0; |
| 918 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 919 | memcpy(*pos, cc_frm->reason_phrase, cc_frm->reason_phrase_len); |
| 920 | *pos += cc_frm->reason_phrase_len; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 921 | |
| 922 | return 1; |
| 923 | } |
| 924 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 925 | /* Parse a CONNECTION_CLOSE frame at QUIC layer at <pos> buffer position with <end> as end into <frm> frame. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 926 | * Note there exist two types of CONNECTION_CLOSE frame, one for the application layer |
| 927 | * and another at QUIC layer. |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 928 | * Return 1 if succeeded (enough room at <pos> buffer position to parse this frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 929 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 930 | static int quic_parse_connection_close_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 931 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 932 | { |
Frédéric Lécaille | 010e532 | 2021-12-23 15:19:15 +0100 | [diff] [blame] | 933 | size_t plen; |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 934 | struct qf_connection_close *cc_frm = &frm->connection_close; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 935 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 936 | if (!quic_dec_int(&cc_frm->error_code, pos, end) || |
| 937 | !quic_dec_int(&cc_frm->frame_type, pos, end) || |
| 938 | !quic_dec_int(&cc_frm->reason_phrase_len, pos, end) || |
| 939 | end - *pos < cc_frm->reason_phrase_len) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 940 | return 0; |
| 941 | |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 942 | plen = QUIC_MIN((size_t)cc_frm->reason_phrase_len, sizeof cc_frm->reason_phrase); |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 943 | memcpy(cc_frm->reason_phrase, *pos, plen); |
| 944 | *pos += cc_frm->reason_phrase_len; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 945 | |
| 946 | return 1; |
| 947 | } |
| 948 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 949 | /* Encode a CONNECTION_CLOSE frame at application layer at <pos> buffer position. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 950 | * Note there exist two types of CONNECTION_CLOSE frame, one for application layer |
| 951 | * and another at QUIC layer. |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 952 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 953 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 954 | static int quic_build_connection_close_app_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 955 | struct quic_frame *frm, struct quic_conn *conn) |
| 956 | { |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 957 | struct qf_connection_close_app *cc_frm = &frm->connection_close_app; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 958 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 959 | if (!quic_enc_int(pos, end, cc_frm->error_code) || |
| 960 | !quic_enc_int(pos, end, cc_frm->reason_phrase_len) || |
| 961 | end - *pos < cc_frm->reason_phrase_len) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 962 | return 0; |
| 963 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 964 | memcpy(*pos, cc_frm->reason_phrase, cc_frm->reason_phrase_len); |
| 965 | *pos += cc_frm->reason_phrase_len; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 966 | |
| 967 | return 1; |
| 968 | } |
| 969 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 970 | /* Parse a CONNECTION_CLOSE frame at QUIC layer at <pos> buffer position with <end> as end into <frm> frame. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 971 | * Note there exist two types of CONNECTION_CLOSE frame, one for the application layer |
| 972 | * and another at QUIC layer. |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 973 | * Return 1 if succeeded (enough room at <pos> buffer position to parse this frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 974 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 975 | static int quic_parse_connection_close_app_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 976 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 977 | { |
Frédéric Lécaille | 010e532 | 2021-12-23 15:19:15 +0100 | [diff] [blame] | 978 | size_t plen; |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 979 | struct qf_connection_close_app *cc_frm = &frm->connection_close_app; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 980 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 981 | if (!quic_dec_int(&cc_frm->error_code, pos, end) || |
| 982 | !quic_dec_int(&cc_frm->reason_phrase_len, pos, end) || |
| 983 | end - *pos < cc_frm->reason_phrase_len) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 984 | return 0; |
| 985 | |
Amaury Denoyelle | d5f03cd | 2023-04-24 15:32:23 +0200 | [diff] [blame] | 986 | plen = QUIC_MIN((size_t)cc_frm->reason_phrase_len, sizeof cc_frm->reason_phrase); |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 987 | memcpy(cc_frm->reason_phrase, *pos, plen); |
| 988 | *pos += cc_frm->reason_phrase_len; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 989 | |
| 990 | return 1; |
| 991 | } |
| 992 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 993 | /* Encode a HANDSHAKE_DONE frame at <pos> buffer position. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 994 | * Always succeeds. |
| 995 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 996 | static int quic_build_handshake_done_frame(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 997 | struct quic_frame *frm, struct quic_conn *conn) |
| 998 | { |
| 999 | /* No field */ |
| 1000 | return 1; |
| 1001 | } |
| 1002 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 1003 | /* Parse a HANDSHAKE_DONE frame at QUIC layer at <pos> buffer position with <end> as end into <frm> frame. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1004 | * Always succeed. |
| 1005 | */ |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 1006 | static int quic_parse_handshake_done_frame(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 1007 | const unsigned char **pos, const unsigned char *end) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1008 | { |
| 1009 | /* No field */ |
| 1010 | return 1; |
| 1011 | } |
| 1012 | |
| 1013 | struct quic_frame_builder { |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 1014 | int (*func)(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1015 | struct quic_frame *frm, struct quic_conn *conn); |
Frédéric Lécaille | ce2ecc9 | 2022-02-02 14:37:37 +0100 | [diff] [blame] | 1016 | uint32_t mask; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1017 | unsigned char flags; |
| 1018 | }; |
| 1019 | |
Frédéric Lécaille | 2cb130c | 2021-09-17 17:05:44 +0200 | [diff] [blame] | 1020 | const struct quic_frame_builder quic_frame_builders[] = { |
Frédéric Lécaille | 156a59b | 2021-09-17 16:51:51 +0200 | [diff] [blame] | 1021 | [QUIC_FT_PADDING] = { .func = quic_build_padding_frame, .flags = QUIC_FL_TX_PACKET_PADDING, .mask = QUIC_FT_PKT_TYPE_IH01_BITMASK, }, |
| 1022 | [QUIC_FT_PING] = { .func = quic_build_ping_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE_IH01_BITMASK, }, |
Frédéric Lécaille | f5821dc | 2021-07-30 14:42:33 +0200 | [diff] [blame] | 1023 | [QUIC_FT_ACK] = { .func = quic_build_ack_frame, .flags = 0, .mask = QUIC_FT_PKT_TYPE_IH_1_BITMASK, }, |
| 1024 | [QUIC_FT_ACK_ECN] = { .func = quic_build_ack_ecn_frame, .flags = 0, .mask = QUIC_FT_PKT_TYPE_IH_1_BITMASK, }, |
Frédéric Lécaille | 156a59b | 2021-09-17 16:51:51 +0200 | [diff] [blame] | 1025 | [QUIC_FT_RESET_STREAM] = { .func = quic_build_reset_stream_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1026 | [QUIC_FT_STOP_SENDING] = { .func = quic_build_stop_sending_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1027 | [QUIC_FT_CRYPTO] = { .func = quic_build_crypto_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE_IH_1_BITMASK, }, |
| 1028 | [QUIC_FT_NEW_TOKEN] = { .func = quic_build_new_token_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE____1_BITMASK, }, |
| 1029 | [QUIC_FT_STREAM_8] = { .func = quic_build_stream_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1030 | [QUIC_FT_STREAM_9] = { .func = quic_build_stream_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1031 | [QUIC_FT_STREAM_A] = { .func = quic_build_stream_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1032 | [QUIC_FT_STREAM_B] = { .func = quic_build_stream_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1033 | [QUIC_FT_STREAM_C] = { .func = quic_build_stream_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1034 | [QUIC_FT_STREAM_D] = { .func = quic_build_stream_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1035 | [QUIC_FT_STREAM_E] = { .func = quic_build_stream_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1036 | [QUIC_FT_STREAM_F] = { .func = quic_build_stream_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1037 | [QUIC_FT_MAX_DATA] = { .func = quic_build_max_data_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1038 | [QUIC_FT_MAX_STREAM_DATA] = { .func = quic_build_max_stream_data_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1039 | [QUIC_FT_MAX_STREAMS_BIDI] = { .func = quic_build_max_streams_bidi_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1040 | [QUIC_FT_MAX_STREAMS_UNI] = { .func = quic_build_max_streams_uni_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1041 | [QUIC_FT_DATA_BLOCKED] = { .func = quic_build_data_blocked_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1042 | [QUIC_FT_STREAM_DATA_BLOCKED] = { .func = quic_build_stream_data_blocked_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1043 | [QUIC_FT_STREAMS_BLOCKED_BIDI] = { .func = quic_build_streams_blocked_bidi_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1044 | [QUIC_FT_STREAMS_BLOCKED_UNI] = { .func = quic_build_streams_blocked_uni_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1045 | [QUIC_FT_NEW_CONNECTION_ID] = { .func = quic_build_new_connection_id_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1046 | [QUIC_FT_RETIRE_CONNECTION_ID] = { .func = quic_build_retire_connection_id_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1047 | [QUIC_FT_PATH_CHALLENGE] = { .func = quic_build_path_challenge_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1048 | [QUIC_FT_PATH_RESPONSE] = { .func = quic_build_path_response_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
Frédéric Lécaille | f5821dc | 2021-07-30 14:42:33 +0200 | [diff] [blame] | 1049 | [QUIC_FT_CONNECTION_CLOSE] = { .func = quic_build_connection_close_frame, .flags = 0, .mask = QUIC_FT_PKT_TYPE_IH01_BITMASK, }, |
| 1050 | [QUIC_FT_CONNECTION_CLOSE_APP] = { .func = quic_build_connection_close_app_frame, .flags = 0, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
Frédéric Lécaille | 156a59b | 2021-09-17 16:51:51 +0200 | [diff] [blame] | 1051 | [QUIC_FT_HANDSHAKE_DONE] = { .func = quic_build_handshake_done_frame, .flags = QUIC_FL_TX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE____1_BITMASK, }, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1052 | }; |
| 1053 | |
| 1054 | struct quic_frame_parser { |
Frédéric Lécaille | 50044ad | 2020-12-29 11:42:08 +0100 | [diff] [blame] | 1055 | int (*func)(struct quic_frame *frm, struct quic_conn *qc, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 1056 | const unsigned char **pos, const unsigned char *end); |
Frédéric Lécaille | ce2ecc9 | 2022-02-02 14:37:37 +0100 | [diff] [blame] | 1057 | uint32_t mask; |
Frédéric Lécaille | f7fe965 | 2020-12-09 14:56:18 +0100 | [diff] [blame] | 1058 | unsigned char flags; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1059 | }; |
| 1060 | |
Frédéric Lécaille | 2cb130c | 2021-09-17 17:05:44 +0200 | [diff] [blame] | 1061 | const struct quic_frame_parser quic_frame_parsers[] = { |
Frédéric Lécaille | f7fe965 | 2020-12-09 14:56:18 +0100 | [diff] [blame] | 1062 | [QUIC_FT_PADDING] = { .func = quic_parse_padding_frame, .flags = 0, .mask = QUIC_FT_PKT_TYPE_IH01_BITMASK, }, |
| 1063 | [QUIC_FT_PING] = { .func = quic_parse_ping_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE_IH01_BITMASK, }, |
| 1064 | [QUIC_FT_ACK] = { .func = quic_parse_ack_frame_header, .flags = 0, .mask = QUIC_FT_PKT_TYPE_IH_1_BITMASK, }, |
| 1065 | [QUIC_FT_ACK_ECN] = { .func = quic_parse_ack_ecn_frame, .flags = 0, .mask = QUIC_FT_PKT_TYPE_IH_1_BITMASK, }, |
| 1066 | [QUIC_FT_RESET_STREAM] = { .func = quic_parse_reset_stream_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1067 | [QUIC_FT_STOP_SENDING] = { .func = quic_parse_stop_sending_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1068 | [QUIC_FT_CRYPTO] = { .func = quic_parse_crypto_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE_IH_1_BITMASK, }, |
| 1069 | [QUIC_FT_NEW_TOKEN] = { .func = quic_parse_new_token_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE____1_BITMASK, }, |
| 1070 | [QUIC_FT_STREAM_8] = { .func = quic_parse_stream_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1071 | [QUIC_FT_STREAM_9] = { .func = quic_parse_stream_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1072 | [QUIC_FT_STREAM_A] = { .func = quic_parse_stream_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1073 | [QUIC_FT_STREAM_B] = { .func = quic_parse_stream_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1074 | [QUIC_FT_STREAM_C] = { .func = quic_parse_stream_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1075 | [QUIC_FT_STREAM_D] = { .func = quic_parse_stream_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1076 | [QUIC_FT_STREAM_E] = { .func = quic_parse_stream_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1077 | [QUIC_FT_STREAM_F] = { .func = quic_parse_stream_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1078 | [QUIC_FT_MAX_DATA] = { .func = quic_parse_max_data_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1079 | [QUIC_FT_MAX_STREAM_DATA] = { .func = quic_parse_max_stream_data_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1080 | [QUIC_FT_MAX_STREAMS_BIDI] = { .func = quic_parse_max_streams_bidi_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1081 | [QUIC_FT_MAX_STREAMS_UNI] = { .func = quic_parse_max_streams_uni_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1082 | [QUIC_FT_DATA_BLOCKED] = { .func = quic_parse_data_blocked_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1083 | [QUIC_FT_STREAM_DATA_BLOCKED] = { .func = quic_parse_stream_data_blocked_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1084 | [QUIC_FT_STREAMS_BLOCKED_BIDI] = { .func = quic_parse_streams_blocked_bidi_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1085 | [QUIC_FT_STREAMS_BLOCKED_UNI] = { .func = quic_parse_streams_blocked_uni_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1086 | [QUIC_FT_NEW_CONNECTION_ID] = { .func = quic_parse_new_connection_id_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1087 | [QUIC_FT_RETIRE_CONNECTION_ID] = { .func = quic_parse_retire_connection_id_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1088 | [QUIC_FT_PATH_CHALLENGE] = { .func = quic_parse_path_challenge_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1089 | [QUIC_FT_PATH_RESPONSE] = { .func = quic_parse_path_response_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1090 | [QUIC_FT_CONNECTION_CLOSE] = { .func = quic_parse_connection_close_frame, .flags = 0, .mask = QUIC_FT_PKT_TYPE_IH01_BITMASK, }, |
| 1091 | [QUIC_FT_CONNECTION_CLOSE_APP] = { .func = quic_parse_connection_close_app_frame, .flags = 0, .mask = QUIC_FT_PKT_TYPE___01_BITMASK, }, |
| 1092 | [QUIC_FT_HANDSHAKE_DONE] = { .func = quic_parse_handshake_done_frame, .flags = QUIC_FL_RX_PACKET_ACK_ELICITING, .mask = QUIC_FT_PKT_TYPE____1_BITMASK, }, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1093 | }; |
| 1094 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 1095 | /* Decode a QUIC frame at <pos> buffer position into <frm> frame. |
| 1096 | * Returns 1 if succeeded (enough data at <pos> buffer position to parse the frame), 0 if not. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1097 | */ |
| 1098 | int qc_parse_frm(struct quic_frame *frm, struct quic_rx_packet *pkt, |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 1099 | const unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | fde2a98 | 2021-12-27 15:12:09 +0100 | [diff] [blame] | 1100 | struct quic_conn *qc) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1101 | { |
Frédéric Lécaille | a8b2f84 | 2022-08-10 17:56:45 +0200 | [diff] [blame] | 1102 | int ret = 0; |
Frédéric Lécaille | 2cb130c | 2021-09-17 17:05:44 +0200 | [diff] [blame] | 1103 | const struct quic_frame_parser *parser; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1104 | |
Frédéric Lécaille | a8b2f84 | 2022-08-10 17:56:45 +0200 | [diff] [blame] | 1105 | TRACE_ENTER(QUIC_EV_CONN_PRSFRM, qc); |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 1106 | if (end <= *pos) { |
Frédéric Lécaille | fde2a98 | 2021-12-27 15:12:09 +0100 | [diff] [blame] | 1107 | TRACE_DEVEL("wrong frame", QUIC_EV_CONN_PRSFRM, qc); |
Frédéric Lécaille | a8b2f84 | 2022-08-10 17:56:45 +0200 | [diff] [blame] | 1108 | goto leave; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1109 | } |
| 1110 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 1111 | frm->type = *(*pos)++; |
Frédéric Lécaille | 0c80e69 | 2022-02-15 10:27:34 +0100 | [diff] [blame] | 1112 | if (frm->type >= QUIC_FT_MAX) { |
Frédéric Lécaille | fde2a98 | 2021-12-27 15:12:09 +0100 | [diff] [blame] | 1113 | TRACE_DEVEL("wrong frame type", QUIC_EV_CONN_PRSFRM, qc, frm); |
Frédéric Lécaille | a8b2f84 | 2022-08-10 17:56:45 +0200 | [diff] [blame] | 1114 | goto leave; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | parser = &quic_frame_parsers[frm->type]; |
Frédéric Lécaille | ce2ecc9 | 2022-02-02 14:37:37 +0100 | [diff] [blame] | 1118 | if (!(parser->mask & (1U << pkt->type))) { |
Frédéric Lécaille | fde2a98 | 2021-12-27 15:12:09 +0100 | [diff] [blame] | 1119 | TRACE_DEVEL("unauthorized frame", QUIC_EV_CONN_PRSFRM, qc, frm); |
Frédéric Lécaille | a8b2f84 | 2022-08-10 17:56:45 +0200 | [diff] [blame] | 1120 | goto leave; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1121 | } |
| 1122 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 1123 | if (!parser->func(frm, qc, pos, end)) { |
Frédéric Lécaille | fde2a98 | 2021-12-27 15:12:09 +0100 | [diff] [blame] | 1124 | TRACE_DEVEL("parsing error", QUIC_EV_CONN_PRSFRM, qc, frm); |
Frédéric Lécaille | a8b2f84 | 2022-08-10 17:56:45 +0200 | [diff] [blame] | 1125 | goto leave; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1126 | } |
| 1127 | |
Frédéric Lécaille | 8f99194 | 2023-03-24 15:14:45 +0100 | [diff] [blame] | 1128 | TRACE_PROTO("RX frm", QUIC_EV_CONN_PSTRM, qc, frm); |
| 1129 | |
Frédéric Lécaille | f7fe965 | 2020-12-09 14:56:18 +0100 | [diff] [blame] | 1130 | pkt->flags |= parser->flags; |
| 1131 | |
Frédéric Lécaille | a8b2f84 | 2022-08-10 17:56:45 +0200 | [diff] [blame] | 1132 | ret = 1; |
| 1133 | leave: |
| 1134 | TRACE_LEAVE(QUIC_EV_CONN_PRSFRM, qc); |
| 1135 | return ret; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1136 | } |
| 1137 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 1138 | /* Encode <frm> QUIC frame at <pos> buffer position. |
| 1139 | * Returns 1 if succeeded (enough room at <pos> buffer position to encode the frame), 0 if not. |
Frédéric Lécaille | b8047de | 2022-08-23 17:40:09 +0200 | [diff] [blame] | 1140 | * The buffer is updated to point to one byte past the end of the built frame |
| 1141 | * only if succeeded. |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1142 | */ |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 1143 | int qc_build_frm(unsigned char **pos, const unsigned char *end, |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1144 | struct quic_frame *frm, struct quic_tx_packet *pkt, |
Frédéric Lécaille | fde2a98 | 2021-12-27 15:12:09 +0100 | [diff] [blame] | 1145 | struct quic_conn *qc) |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1146 | { |
Frédéric Lécaille | a8b2f84 | 2022-08-10 17:56:45 +0200 | [diff] [blame] | 1147 | int ret = 0; |
Frédéric Lécaille | 2cb130c | 2021-09-17 17:05:44 +0200 | [diff] [blame] | 1148 | const struct quic_frame_builder *builder; |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 1149 | unsigned char *p = *pos; |
Frédéric Lécaille | f7fe965 | 2020-12-09 14:56:18 +0100 | [diff] [blame] | 1150 | |
Frédéric Lécaille | a8b2f84 | 2022-08-10 17:56:45 +0200 | [diff] [blame] | 1151 | TRACE_ENTER(QUIC_EV_CONN_BFRM, qc); |
Frédéric Lécaille | f5821dc | 2021-07-30 14:42:33 +0200 | [diff] [blame] | 1152 | builder = &quic_frame_builders[frm->type]; |
Frédéric Lécaille | ce2ecc9 | 2022-02-02 14:37:37 +0100 | [diff] [blame] | 1153 | if (!(builder->mask & (1U << pkt->type))) { |
Frédéric Lécaille | f5821dc | 2021-07-30 14:42:33 +0200 | [diff] [blame] | 1154 | /* XXX This it a bug to send an unauthorized frame with such a packet type XXX */ |
Frédéric Lécaille | a8b2f84 | 2022-08-10 17:56:45 +0200 | [diff] [blame] | 1155 | TRACE_ERROR("unauthorized frame", QUIC_EV_CONN_BFRM, qc, frm); |
Frédéric Lécaille | ce2ecc9 | 2022-02-02 14:37:37 +0100 | [diff] [blame] | 1156 | BUG_ON(!(builder->mask & (1U << pkt->type))); |
Frédéric Lécaille | f5821dc | 2021-07-30 14:42:33 +0200 | [diff] [blame] | 1157 | } |
| 1158 | |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 1159 | if (end <= p) { |
Frédéric Lécaille | fde2a98 | 2021-12-27 15:12:09 +0100 | [diff] [blame] | 1160 | TRACE_DEVEL("not enough room", QUIC_EV_CONN_BFRM, qc, frm); |
Frédéric Lécaille | a8b2f84 | 2022-08-10 17:56:45 +0200 | [diff] [blame] | 1161 | goto leave; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1162 | } |
| 1163 | |
Frédéric Lécaille | 8f99194 | 2023-03-24 15:14:45 +0100 | [diff] [blame] | 1164 | TRACE_PROTO("TX frm", QUIC_EV_CONN_BFRM, qc, frm); |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 1165 | *p++ = frm->type; |
| 1166 | if (!quic_frame_builders[frm->type].func(&p, end, frm, qc)) { |
Frédéric Lécaille | 8f99194 | 2023-03-24 15:14:45 +0100 | [diff] [blame] | 1167 | TRACE_ERROR("frame building error", QUIC_EV_CONN_BFRM, qc, frm); |
Frédéric Lécaille | a8b2f84 | 2022-08-10 17:56:45 +0200 | [diff] [blame] | 1168 | goto leave; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1169 | } |
| 1170 | |
Frédéric Lécaille | dc2593e | 2021-09-17 16:57:14 +0200 | [diff] [blame] | 1171 | pkt->flags |= builder->flags; |
Frédéric Lécaille | 1bc6e31 | 2023-04-24 17:45:01 +0200 | [diff] [blame^] | 1172 | *pos = p; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1173 | |
Frédéric Lécaille | a8b2f84 | 2022-08-10 17:56:45 +0200 | [diff] [blame] | 1174 | ret = 1; |
| 1175 | leave: |
| 1176 | TRACE_LEAVE(QUIC_EV_CONN_BFRM, qc); |
| 1177 | return ret; |
Frédéric Lécaille | a7e7ce9 | 2020-11-23 14:14:04 +0100 | [diff] [blame] | 1178 | } |
| 1179 | |
Amaury Denoyelle | 57b3eaa | 2023-02-02 16:12:09 +0100 | [diff] [blame] | 1180 | /* Detach all duplicated frames from <frm> reflist. */ |
| 1181 | void qc_frm_unref(struct quic_frame *frm, struct quic_conn *qc) |
| 1182 | { |
| 1183 | struct quic_frame *f, *tmp; |
| 1184 | |
| 1185 | TRACE_ENTER(QUIC_EV_CONN_PRSAFRM, qc); |
| 1186 | |
| 1187 | list_for_each_entry_safe(f, tmp, &frm->reflist, ref) { |
| 1188 | f->origin = NULL; |
| 1189 | LIST_DEL_INIT(&f->ref); |
| 1190 | if (f->pkt) { |
| 1191 | TRACE_DEVEL("remove frame reference", |
| 1192 | QUIC_EV_CONN_PRSAFRM, qc, f, &f->pkt->pn_node.key); |
| 1193 | } |
| 1194 | else { |
| 1195 | TRACE_DEVEL("remove frame reference for unsent frame", |
| 1196 | QUIC_EV_CONN_PRSAFRM, qc, f); |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | TRACE_LEAVE(QUIC_EV_CONN_PRSAFRM, qc); |
| 1201 | } |