lsquic_parse_Q050.c revision 06b2a236
1/* Copyright (c) 2017 - 2021 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_parse_Q050.c -- Parsing functions specific to GQUIC Q050 4 */ 5 6#include <assert.h> 7#include <errno.h> 8#include <inttypes.h> 9#include <string.h> 10#include <sys/queue.h> 11#ifndef WIN32 12#include <sys/types.h> 13#else 14#include <vc_compat.h> 15#endif 16 17#include "lsquic_types.h" 18#include "lsquic_int_types.h" 19#include "lsquic_packet_common.h" 20#include "lsquic_packet_in.h" 21#include "lsquic_packet_out.h" 22#include "lsquic_parse.h" 23#include "lsquic_parse_common.h" 24#include "lsquic_version.h" 25#include "lsquic.h" 26#include "lsquic_parse_gquic_be.h" 27#include "lsquic_parse_ietf.h" 28#include "lsquic_byteswap.h" 29#include "lsquic_hash.h" 30#include "lsquic_conn.h" 31#include "lsquic_varint.h" 32#include "lsquic_enc_sess.h" 33 34#define LSQUIC_LOGGER_MODULE LSQLM_PARSE 35#include "lsquic_logger.h" 36 37 38/* [draft-ietf-quic-transport-24] Section-17.2 */ 39static const enum header_type bits2ht[4] = 40{ 41 [0] = HETY_INITIAL, 42 [1] = HETY_0RTT, 43 [2] = HETY_HANDSHAKE, 44 [3] = HETY_RETRY, 45}; 46 47 48int 49lsquic_Q050_parse_packet_in_long_begin (struct lsquic_packet_in *packet_in, 50 size_t length, int is_server, unsigned cid_len, 51 struct packin_parse_state *state) 52{ 53 const unsigned char *p = packet_in->pi_data; 54 const unsigned char *const end = p + length; 55 lsquic_ver_tag_t tag; 56 enum header_type header_type; 57 unsigned dcil, scil, odcil; 58 int verneg, r; 59 unsigned char first_byte; 60 uint64_t payload_len, token_len; 61 62 if (length < 6) 63 return -1; 64 first_byte = *p++; 65 66 memcpy(&tag, p, 4); 67 p += 4; 68 verneg = 0 == tag; 69 if (!verneg) 70 header_type = bits2ht[ (first_byte >> 4) & 3 ]; 71 else 72 header_type = HETY_VERNEG; 73 74 packet_in->pi_header_type = header_type; 75 76 dcil = *p++; 77 if (p + dcil >= end || dcil > MAX_CID_LEN) 78 return -1; 79 if (dcil) 80 { 81 memcpy(packet_in->pi_dcid.idbuf, p, dcil); 82 packet_in->pi_flags |= PI_CONN_ID; 83 p += dcil; 84 packet_in->pi_dcid.len = dcil; 85 } 86 87 scil = *p++; 88 if (p + scil > end || scil > MAX_CID_LEN) 89 return -1; 90 if (scil) 91 { 92 memcpy(packet_in->pi_dcid.idbuf, p, scil); 93 packet_in->pi_flags |= PI_CONN_ID; 94 p += scil; 95 packet_in->pi_dcid.len = scil; 96 } 97 98 if (is_server) 99 { 100 if (scil) 101 return -1; 102 } 103 else 104 if (dcil) 105 return -1; 106 107 switch (header_type) 108 { 109 case HETY_INITIAL: 110 r = vint_read(p, end, &token_len); 111 if (r < 0) 112 return -1; 113 if (token_len && !is_server) 114 { 115 /* From [draft-ietf-quic-transport-14]: 116 * 117 * Token Length: A variable-length integer specifying the 118 * length of the Token field, in bytes. This value is zero 119 * if no token is present. Initial packets sent by the 120 * server MUST set the Token Length field to zero; clients 121 * that receive an Initial packet with a non-zero Token 122 * Length field MUST either discard the packet or generate 123 * a connection error of type PROTOCOL_VIOLATION. 124 */ 125 return -1; 126 } 127 p += r; 128 if (token_len) 129 { 130 if (token_len >= 131 1ull << (sizeof(packet_in->pi_token_size) * 8)) 132 return -1; 133 if (p + token_len > end) 134 return -1; 135 packet_in->pi_token = p - packet_in->pi_data; 136 packet_in->pi_token_size = token_len; 137 p += token_len; 138 } 139 /* fall-through */ 140 case HETY_HANDSHAKE: 141 case HETY_0RTT: 142 if (p >= end) 143 return -1; 144 r = vint_read(p, end, &payload_len); 145 if (r < 0) 146 return -1; 147 p += r; 148 if (p - packet_in->pi_data + payload_len > length) 149 return -1; 150 length = p - packet_in->pi_data + payload_len; 151 if (end - p < 4) 152 return -1; 153 state->pps_p = p - r; 154 state->pps_nbytes = r; 155 packet_in->pi_quic_ver = 1; 156 break; 157 case HETY_RETRY: 158 if (p >= end) 159 return -1; 160 odcil = *p++; 161 if (p + odcil > end || odcil > MAX_CID_LEN) 162 return -1; 163 packet_in->pi_odcid_len = odcil; 164 packet_in->pi_odcid = p - packet_in->pi_data; 165 p += odcil; 166 packet_in->pi_token = p - packet_in->pi_data; 167 packet_in->pi_token_size = end - p; 168 p = end; 169 length = end - packet_in->pi_data; 170 state->pps_p = NULL; 171 state->pps_nbytes = 0; 172 packet_in->pi_quic_ver = 1; 173 break; 174 default: 175 assert(header_type == HETY_VERNEG); 176 if (p >= end || (3 & (uintptr_t) (end - p))) 177 return -1; 178 packet_in->pi_quic_ver = p - packet_in->pi_data; 179 p = end; 180 state->pps_p = NULL; 181 state->pps_nbytes = 0; 182 break; 183 } 184 185 packet_in->pi_header_sz = p - packet_in->pi_data; 186 packet_in->pi_data_sz = length; 187 packet_in->pi_nonce = 0; 188 packet_in->pi_refcnt = 0; 189 packet_in->pi_frame_types = 0; 190 memset(&packet_in->pi_next, 0, sizeof(packet_in->pi_next)); 191 packet_in->pi_refcnt = 0; 192 packet_in->pi_received = 0; 193 194 /* Packet number is set to an invalid value. The packet number must 195 * be decrypted, which happens later. 196 */ 197 packet_in->pi_packno = 1ULL << 62; 198 199 return 0; 200} 201 202 203 204 205static unsigned 206gquic_Q050_packno_bits2len (enum packno_bits bits) 207{ 208 return bits + 1; 209} 210 211#define iquic_packno_bits2len gquic_Q050_packno_bits2len 212 213 214static enum packno_bits 215gquic_Q050_calc_packno_bits (lsquic_packno_t packno, 216 lsquic_packno_t least_unacked, uint64_t n_in_flight) 217{ 218 uint64_t delta; 219 unsigned bits; 220 221 delta = packno - least_unacked; 222 if (n_in_flight > delta) 223 delta = n_in_flight; 224 225 delta *= 4; 226 bits = (delta >= (1ULL << 8)) 227 + (delta >= (1ULL << 16)) 228 + (delta >= (1ULL << 24)) 229 ; 230 231 return bits; 232} 233 234 235static unsigned 236write_packno (unsigned char *p, lsquic_packno_t packno, enum packno_bits bits) 237{ 238 unsigned char *const begin = p; 239 240 switch (bits) 241 { 242 case IQUIC_PACKNO_LEN_4: 243 *p++ = packno >> 24; 244 /* fall-through */ 245 case IQUIC_PACKNO_LEN_3: 246 *p++ = packno >> 16; 247 /* fall-through */ 248 case IQUIC_PACKNO_LEN_2: 249 *p++ = packno >> 8; 250 /* fall-through */ 251 default: 252 *p++ = packno; 253 } 254 255 return p - begin; 256} 257 258 259static int 260gen_short_pkt_header (const struct lsquic_conn *lconn, 261 const struct lsquic_packet_out *packet_out, unsigned char *buf, 262 size_t bufsz, unsigned *packno_off_p, unsigned *packno_len_p) 263{ 264 unsigned packno_len, need; 265 enum packno_bits bits; 266 unsigned char *p = buf; 267 268 bits = lsquic_packet_out_packno_bits(packet_out); 269 packno_len = iquic_packno_bits2len(bits); 270 271 if (lconn->cn_flags & LSCONN_SERVER) 272 need = 1 + packno_len; 273 else 274 need = 1 + 8 /* CID */ + packno_len; 275 276 if (need > bufsz) 277 return -1; 278 279 *p++ = 0x40 | bits; 280 281 if (0 == (lconn->cn_flags & LSCONN_SERVER)) 282 { 283 memcpy(p, lconn->cn_cid.idbuf, 8); 284 p += 8; 285 } 286 287 *packno_off_p = p - buf; 288 *packno_len_p = packno_len; 289 (void) write_packno(p, packet_out->po_packno, bits); 290 291 return need; 292} 293 294 295static size_t 296gquic_Q050_packout_header_size_long_by_flags (const struct lsquic_conn *lconn, 297 enum packet_out_flags flags) 298{ 299 size_t sz; 300 enum packno_bits packno_bits; 301 302 packno_bits = (flags >> POBIT_SHIFT) & 0x3; 303 304 sz = 1 /* Type */ 305 + 4 /* Version */ 306 + 1 /* DCIL */ 307 + 1 /* SCIL */ 308 + lconn->cn_cid.len 309 + 1 /* Token length: only use for Initial packets, while token is never 310 * set in this version. 311 */ 312 + (flags & PO_NONCE ? DNONC_LENGTH : 0) 313 + 2 /* Always use two bytes to encode payload length */ 314 + iquic_packno_bits2len(packno_bits) 315 ; 316 317 return sz; 318} 319 320 321/* [draft-ietf-quic-transport-17] Section-17.2 */ 322static const unsigned char header_type_to_bin[] = { 323 [HETY_INITIAL] = 0x0, 324 [HETY_0RTT] = 0x1, 325 [HETY_HANDSHAKE] = 0x2, 326 [HETY_RETRY] = 0x3, 327}; 328 329 330static size_t 331gquic_Q050_packout_header_size_long_by_packet (const struct lsquic_conn *lconn, 332 const struct lsquic_packet_out *packet_out) 333{ 334 size_t sz; 335 enum packno_bits packno_bits; 336 337 packno_bits = lsquic_packet_out_packno_bits(packet_out); 338 339 sz = 1 /* Type */ 340 + 4 /* Version */ 341 + 1 /* DCIL */ 342 + 1 /* SCIL */ 343 + lconn->cn_cid.len 344 /* Token is never sent, but token length byte is used */ 345 + (packet_out->po_header_type == HETY_INITIAL) 346 + 2 /* Always use two bytes to encode payload length */ 347 + iquic_packno_bits2len(packno_bits) 348 + (packet_out->po_nonce ? DNONC_LENGTH : 0) 349 ; 350 351 return sz; 352} 353 354 355static int 356gquic_Q050_gen_long_pkt_header (const struct lsquic_conn *lconn, 357 const struct lsquic_packet_out *packet_out, unsigned char *buf, 358 size_t bufsz, unsigned *packno_off_p, unsigned *packno_len_p) 359{ 360 enum packno_bits packno_bits; 361 lsquic_ver_tag_t ver_tag; 362 unsigned token_len, payload_len, bits; 363 unsigned char *p; 364 size_t need; 365 366 need = gquic_Q050_packout_header_size_long_by_packet(lconn, packet_out); 367 if (need > bufsz) 368 { 369 errno = EINVAL; 370 return -1; 371 } 372 373 packno_bits = lsquic_packet_out_packno_bits(packet_out); 374 p = buf; 375 *p++ = 0x80 | 0x40 376 | (header_type_to_bin[ packet_out->po_header_type ] << 4) 377 | packno_bits; 378 ver_tag = lsquic_ver2tag(lconn->cn_version); 379 memcpy(p, &ver_tag, sizeof(ver_tag)); 380 p += sizeof(ver_tag); 381 382 if (lconn->cn_flags & LSCONN_SERVER) 383 { 384 *p++ = 0; 385 *p++ = lconn->cn_cid.len; 386 memcpy(p, lconn->cn_cid.idbuf, lconn->cn_cid.len); 387 p += lconn->cn_cid.len; 388 } 389 else 390 { 391 *p++ = lconn->cn_cid.len; 392 memcpy(p, lconn->cn_cid.idbuf, lconn->cn_cid.len); 393 p += lconn->cn_cid.len; 394 *p++ = 0; 395 } 396 397 if (HETY_INITIAL == packet_out->po_header_type) 398 { 399 token_len = packet_out->po_token_len; 400 bits = vint_val2bits(token_len); 401 vint_write(p, token_len, bits, 1 << bits); 402 p += 1 << bits; 403 memcpy(p, packet_out->po_token, token_len); 404 p += token_len; 405 } 406 407 payload_len = packet_out->po_data_sz 408 + lconn->cn_esf_c->esf_tag_len 409 + iquic_packno_bits2len(packno_bits); 410 if (packet_out->po_nonce) 411 payload_len += DNONC_LENGTH; 412 bits = 1; /* Always use two bytes to encode payload length */ 413 vint_write(p, payload_len, bits, 1 << bits); 414 p += 1 << bits; 415 *packno_off_p = p - buf; 416 *packno_len_p = iquic_packno_bits2len(packno_bits); 417 p += write_packno(p, packet_out->po_packno, packno_bits); 418 419 if (packet_out->po_nonce) 420 { 421 memcpy(p, packet_out->po_nonce, DNONC_LENGTH); 422 p += DNONC_LENGTH; 423 } 424 425 assert(need == (size_t) (p - buf)); 426 return p - buf; 427} 428 429 430static int 431gquic_Q050_gen_reg_pkt_header (const struct lsquic_conn *lconn, 432 const struct lsquic_packet_out *packet_out, unsigned char *buf, 433 size_t bufsz, unsigned *packno_off, unsigned *packno_len) 434{ 435 if (0 == (packet_out->po_flags & PO_LONGHEAD)) 436 return gen_short_pkt_header(lconn, packet_out, buf, bufsz, 437 packno_off, packno_len); 438 else 439 return gquic_Q050_gen_long_pkt_header(lconn, packet_out, buf, bufsz, 440 packno_off, packno_len); 441} 442 443 444static size_t 445gquic_Q050_packout_header_size_short (const struct lsquic_conn *lconn, 446 enum packet_out_flags flags) 447{ 448 enum packno_bits bits; 449 size_t sz; 450 451 bits = (flags >> POBIT_SHIFT) & 0x3; 452 sz = 1; /* Type */ 453 sz += (lconn->cn_flags & LSCONN_SERVER) ? 0 : 8; 454 sz += iquic_packno_bits2len(bits); 455 456 return sz; 457} 458 459 460static size_t 461gquic_Q050_packout_max_header_size (const struct lsquic_conn *lconn, 462 enum packet_out_flags flags, size_t dcid_len_unused, 463 enum header_type unused) 464{ 465 if (lconn->cn_flags & LSCONN_SERVER) 466 { 467 if (0 == (flags & PO_LONGHEAD)) 468 return gquic_Q050_packout_header_size_short(lconn, flags); 469 else 470 return gquic_Q050_packout_header_size_long_by_flags(lconn, flags); 471 } 472 else 473 { 474 if (lconn->cn_flags & LSCONN_HANDSHAKE_DONE) 475 return gquic_Q050_packout_header_size_short(lconn, flags); 476 else 477 return gquic_Q050_packout_header_size_long_by_flags(lconn, flags); 478 } 479} 480 481 482static size_t 483gquic_Q050_packout_size (const struct lsquic_conn *lconn, 484 const struct lsquic_packet_out *packet_out) 485{ 486 size_t sz; 487 488 if ((lconn->cn_flags & LSCONN_HANDSHAKE_DONE) 489 && packet_out->po_header_type == HETY_NOT_SET) 490 sz = gquic_Q050_packout_header_size_short(lconn, packet_out->po_flags); 491 else 492 sz = gquic_Q050_packout_header_size_long_by_packet(lconn, packet_out); 493 494 sz += packet_out->po_data_sz; 495 sz += lconn->cn_esf_c->esf_tag_len; 496 497 return sz; 498} 499 500 501static void 502gquic_Q050_parse_packet_in_finish (struct lsquic_packet_in *packet_in, 503 struct packin_parse_state *state) 504{ 505} 506 507 508/* Same as Q046 plus CRYPTO frame at slot 8 */ 509static const enum quic_frame_type byte2frame_type_Q050[0x100] = 510{ 511 [0x00] = QUIC_FRAME_PADDING, 512 [0x01] = QUIC_FRAME_RST_STREAM, 513 [0x02] = QUIC_FRAME_CONNECTION_CLOSE, 514 [0x03] = QUIC_FRAME_GOAWAY, 515 [0x04] = QUIC_FRAME_WINDOW_UPDATE, 516 [0x05] = QUIC_FRAME_BLOCKED, 517 [0x06] = QUIC_FRAME_STOP_WAITING, 518 [0x07] = QUIC_FRAME_PING, 519 [0x08] = QUIC_FRAME_CRYPTO, 520 [0x09] = QUIC_FRAME_INVALID, 521 [0x0A] = QUIC_FRAME_INVALID, 522 [0x0B] = QUIC_FRAME_INVALID, 523 [0x0C] = QUIC_FRAME_INVALID, 524 [0x0D] = QUIC_FRAME_INVALID, 525 [0x0E] = QUIC_FRAME_INVALID, 526 [0x0F] = QUIC_FRAME_INVALID, 527 [0x10] = QUIC_FRAME_INVALID, 528 [0x11] = QUIC_FRAME_INVALID, 529 [0x12] = QUIC_FRAME_INVALID, 530 [0x13] = QUIC_FRAME_INVALID, 531 [0x14] = QUIC_FRAME_INVALID, 532 [0x15] = QUIC_FRAME_INVALID, 533 [0x16] = QUIC_FRAME_INVALID, 534 [0x17] = QUIC_FRAME_INVALID, 535 [0x18] = QUIC_FRAME_INVALID, 536 [0x19] = QUIC_FRAME_INVALID, 537 [0x1A] = QUIC_FRAME_INVALID, 538 [0x1B] = QUIC_FRAME_INVALID, 539 [0x1C] = QUIC_FRAME_INVALID, 540 [0x1D] = QUIC_FRAME_INVALID, 541 [0x1E] = QUIC_FRAME_INVALID, 542 [0x1F] = QUIC_FRAME_INVALID, 543 [0x20] = QUIC_FRAME_INVALID, 544 [0x21] = QUIC_FRAME_INVALID, 545 [0x22] = QUIC_FRAME_INVALID, 546 [0x23] = QUIC_FRAME_INVALID, 547 [0x24] = QUIC_FRAME_INVALID, 548 [0x25] = QUIC_FRAME_INVALID, 549 [0x26] = QUIC_FRAME_INVALID, 550 [0x27] = QUIC_FRAME_INVALID, 551 [0x28] = QUIC_FRAME_INVALID, 552 [0x29] = QUIC_FRAME_INVALID, 553 [0x2A] = QUIC_FRAME_INVALID, 554 [0x2B] = QUIC_FRAME_INVALID, 555 [0x2C] = QUIC_FRAME_INVALID, 556 [0x2D] = QUIC_FRAME_INVALID, 557 [0x2E] = QUIC_FRAME_INVALID, 558 [0x2F] = QUIC_FRAME_INVALID, 559 [0x30] = QUIC_FRAME_INVALID, 560 [0x31] = QUIC_FRAME_INVALID, 561 [0x32] = QUIC_FRAME_INVALID, 562 [0x33] = QUIC_FRAME_INVALID, 563 [0x34] = QUIC_FRAME_INVALID, 564 [0x35] = QUIC_FRAME_INVALID, 565 [0x36] = QUIC_FRAME_INVALID, 566 [0x37] = QUIC_FRAME_INVALID, 567 [0x38] = QUIC_FRAME_INVALID, 568 [0x39] = QUIC_FRAME_INVALID, 569 [0x3A] = QUIC_FRAME_INVALID, 570 [0x3B] = QUIC_FRAME_INVALID, 571 [0x3C] = QUIC_FRAME_INVALID, 572 [0x3D] = QUIC_FRAME_INVALID, 573 [0x3E] = QUIC_FRAME_INVALID, 574 [0x3F] = QUIC_FRAME_INVALID, 575 [0x40] = QUIC_FRAME_ACK, 576 [0x41] = QUIC_FRAME_ACK, 577 [0x42] = QUIC_FRAME_ACK, 578 [0x43] = QUIC_FRAME_ACK, 579 [0x44] = QUIC_FRAME_ACK, 580 [0x45] = QUIC_FRAME_ACK, 581 [0x46] = QUIC_FRAME_ACK, 582 [0x47] = QUIC_FRAME_ACK, 583 [0x48] = QUIC_FRAME_ACK, 584 [0x49] = QUIC_FRAME_ACK, 585 [0x4A] = QUIC_FRAME_ACK, 586 [0x4B] = QUIC_FRAME_ACK, 587 [0x4C] = QUIC_FRAME_ACK, 588 [0x4D] = QUIC_FRAME_ACK, 589 [0x4E] = QUIC_FRAME_ACK, 590 [0x4F] = QUIC_FRAME_ACK, 591 [0x50] = QUIC_FRAME_ACK, 592 [0x51] = QUIC_FRAME_ACK, 593 [0x52] = QUIC_FRAME_ACK, 594 [0x53] = QUIC_FRAME_ACK, 595 [0x54] = QUIC_FRAME_ACK, 596 [0x55] = QUIC_FRAME_ACK, 597 [0x56] = QUIC_FRAME_ACK, 598 [0x57] = QUIC_FRAME_ACK, 599 [0x58] = QUIC_FRAME_ACK, 600 [0x59] = QUIC_FRAME_ACK, 601 [0x5A] = QUIC_FRAME_ACK, 602 [0x5B] = QUIC_FRAME_ACK, 603 [0x5C] = QUIC_FRAME_ACK, 604 [0x5D] = QUIC_FRAME_ACK, 605 [0x5E] = QUIC_FRAME_ACK, 606 [0x5F] = QUIC_FRAME_ACK, 607 [0x60] = QUIC_FRAME_ACK, 608 [0x61] = QUIC_FRAME_ACK, 609 [0x62] = QUIC_FRAME_ACK, 610 [0x63] = QUIC_FRAME_ACK, 611 [0x64] = QUIC_FRAME_ACK, 612 [0x65] = QUIC_FRAME_ACK, 613 [0x66] = QUIC_FRAME_ACK, 614 [0x67] = QUIC_FRAME_ACK, 615 [0x68] = QUIC_FRAME_ACK, 616 [0x69] = QUIC_FRAME_ACK, 617 [0x6A] = QUIC_FRAME_ACK, 618 [0x6B] = QUIC_FRAME_ACK, 619 [0x6C] = QUIC_FRAME_ACK, 620 [0x6D] = QUIC_FRAME_ACK, 621 [0x6E] = QUIC_FRAME_ACK, 622 [0x6F] = QUIC_FRAME_ACK, 623 [0x70] = QUIC_FRAME_ACK, 624 [0x71] = QUIC_FRAME_ACK, 625 [0x72] = QUIC_FRAME_ACK, 626 [0x73] = QUIC_FRAME_ACK, 627 [0x74] = QUIC_FRAME_ACK, 628 [0x75] = QUIC_FRAME_ACK, 629 [0x76] = QUIC_FRAME_ACK, 630 [0x77] = QUIC_FRAME_ACK, 631 [0x78] = QUIC_FRAME_ACK, 632 [0x79] = QUIC_FRAME_ACK, 633 [0x7A] = QUIC_FRAME_ACK, 634 [0x7B] = QUIC_FRAME_ACK, 635 [0x7C] = QUIC_FRAME_ACK, 636 [0x7D] = QUIC_FRAME_ACK, 637 [0x7E] = QUIC_FRAME_ACK, 638 [0x7F] = QUIC_FRAME_ACK, 639 [0x80] = QUIC_FRAME_STREAM, 640 [0x81] = QUIC_FRAME_STREAM, 641 [0x82] = QUIC_FRAME_STREAM, 642 [0x83] = QUIC_FRAME_STREAM, 643 [0x84] = QUIC_FRAME_STREAM, 644 [0x85] = QUIC_FRAME_STREAM, 645 [0x86] = QUIC_FRAME_STREAM, 646 [0x87] = QUIC_FRAME_STREAM, 647 [0x88] = QUIC_FRAME_STREAM, 648 [0x89] = QUIC_FRAME_STREAM, 649 [0x8A] = QUIC_FRAME_STREAM, 650 [0x8B] = QUIC_FRAME_STREAM, 651 [0x8C] = QUIC_FRAME_STREAM, 652 [0x8D] = QUIC_FRAME_STREAM, 653 [0x8E] = QUIC_FRAME_STREAM, 654 [0x8F] = QUIC_FRAME_STREAM, 655 [0x90] = QUIC_FRAME_STREAM, 656 [0x91] = QUIC_FRAME_STREAM, 657 [0x92] = QUIC_FRAME_STREAM, 658 [0x93] = QUIC_FRAME_STREAM, 659 [0x94] = QUIC_FRAME_STREAM, 660 [0x95] = QUIC_FRAME_STREAM, 661 [0x96] = QUIC_FRAME_STREAM, 662 [0x97] = QUIC_FRAME_STREAM, 663 [0x98] = QUIC_FRAME_STREAM, 664 [0x99] = QUIC_FRAME_STREAM, 665 [0x9A] = QUIC_FRAME_STREAM, 666 [0x9B] = QUIC_FRAME_STREAM, 667 [0x9C] = QUIC_FRAME_STREAM, 668 [0x9D] = QUIC_FRAME_STREAM, 669 [0x9E] = QUIC_FRAME_STREAM, 670 [0x9F] = QUIC_FRAME_STREAM, 671 [0xA0] = QUIC_FRAME_STREAM, 672 [0xA1] = QUIC_FRAME_STREAM, 673 [0xA2] = QUIC_FRAME_STREAM, 674 [0xA3] = QUIC_FRAME_STREAM, 675 [0xA4] = QUIC_FRAME_STREAM, 676 [0xA5] = QUIC_FRAME_STREAM, 677 [0xA6] = QUIC_FRAME_STREAM, 678 [0xA7] = QUIC_FRAME_STREAM, 679 [0xA8] = QUIC_FRAME_STREAM, 680 [0xA9] = QUIC_FRAME_STREAM, 681 [0xAA] = QUIC_FRAME_STREAM, 682 [0xAB] = QUIC_FRAME_STREAM, 683 [0xAC] = QUIC_FRAME_STREAM, 684 [0xAD] = QUIC_FRAME_STREAM, 685 [0xAE] = QUIC_FRAME_STREAM, 686 [0xAF] = QUIC_FRAME_STREAM, 687 [0xB0] = QUIC_FRAME_STREAM, 688 [0xB1] = QUIC_FRAME_STREAM, 689 [0xB2] = QUIC_FRAME_STREAM, 690 [0xB3] = QUIC_FRAME_STREAM, 691 [0xB4] = QUIC_FRAME_STREAM, 692 [0xB5] = QUIC_FRAME_STREAM, 693 [0xB6] = QUIC_FRAME_STREAM, 694 [0xB7] = QUIC_FRAME_STREAM, 695 [0xB8] = QUIC_FRAME_STREAM, 696 [0xB9] = QUIC_FRAME_STREAM, 697 [0xBA] = QUIC_FRAME_STREAM, 698 [0xBB] = QUIC_FRAME_STREAM, 699 [0xBC] = QUIC_FRAME_STREAM, 700 [0xBD] = QUIC_FRAME_STREAM, 701 [0xBE] = QUIC_FRAME_STREAM, 702 [0xBF] = QUIC_FRAME_STREAM, 703 [0xC0] = QUIC_FRAME_STREAM, 704 [0xC1] = QUIC_FRAME_STREAM, 705 [0xC2] = QUIC_FRAME_STREAM, 706 [0xC3] = QUIC_FRAME_STREAM, 707 [0xC4] = QUIC_FRAME_STREAM, 708 [0xC5] = QUIC_FRAME_STREAM, 709 [0xC6] = QUIC_FRAME_STREAM, 710 [0xC7] = QUIC_FRAME_STREAM, 711 [0xC8] = QUIC_FRAME_STREAM, 712 [0xC9] = QUIC_FRAME_STREAM, 713 [0xCA] = QUIC_FRAME_STREAM, 714 [0xCB] = QUIC_FRAME_STREAM, 715 [0xCC] = QUIC_FRAME_STREAM, 716 [0xCD] = QUIC_FRAME_STREAM, 717 [0xCE] = QUIC_FRAME_STREAM, 718 [0xCF] = QUIC_FRAME_STREAM, 719 [0xD0] = QUIC_FRAME_STREAM, 720 [0xD1] = QUIC_FRAME_STREAM, 721 [0xD2] = QUIC_FRAME_STREAM, 722 [0xD3] = QUIC_FRAME_STREAM, 723 [0xD4] = QUIC_FRAME_STREAM, 724 [0xD5] = QUIC_FRAME_STREAM, 725 [0xD6] = QUIC_FRAME_STREAM, 726 [0xD7] = QUIC_FRAME_STREAM, 727 [0xD8] = QUIC_FRAME_STREAM, 728 [0xD9] = QUIC_FRAME_STREAM, 729 [0xDA] = QUIC_FRAME_STREAM, 730 [0xDB] = QUIC_FRAME_STREAM, 731 [0xDC] = QUIC_FRAME_STREAM, 732 [0xDD] = QUIC_FRAME_STREAM, 733 [0xDE] = QUIC_FRAME_STREAM, 734 [0xDF] = QUIC_FRAME_STREAM, 735 [0xE0] = QUIC_FRAME_STREAM, 736 [0xE1] = QUIC_FRAME_STREAM, 737 [0xE2] = QUIC_FRAME_STREAM, 738 [0xE3] = QUIC_FRAME_STREAM, 739 [0xE4] = QUIC_FRAME_STREAM, 740 [0xE5] = QUIC_FRAME_STREAM, 741 [0xE6] = QUIC_FRAME_STREAM, 742 [0xE7] = QUIC_FRAME_STREAM, 743 [0xE8] = QUIC_FRAME_STREAM, 744 [0xE9] = QUIC_FRAME_STREAM, 745 [0xEA] = QUIC_FRAME_STREAM, 746 [0xEB] = QUIC_FRAME_STREAM, 747 [0xEC] = QUIC_FRAME_STREAM, 748 [0xED] = QUIC_FRAME_STREAM, 749 [0xEE] = QUIC_FRAME_STREAM, 750 [0xEF] = QUIC_FRAME_STREAM, 751 [0xF0] = QUIC_FRAME_STREAM, 752 [0xF1] = QUIC_FRAME_STREAM, 753 [0xF2] = QUIC_FRAME_STREAM, 754 [0xF3] = QUIC_FRAME_STREAM, 755 [0xF4] = QUIC_FRAME_STREAM, 756 [0xF5] = QUIC_FRAME_STREAM, 757 [0xF6] = QUIC_FRAME_STREAM, 758 [0xF7] = QUIC_FRAME_STREAM, 759 [0xF8] = QUIC_FRAME_STREAM, 760 [0xF9] = QUIC_FRAME_STREAM, 761 [0xFA] = QUIC_FRAME_STREAM, 762 [0xFB] = QUIC_FRAME_STREAM, 763 [0xFC] = QUIC_FRAME_STREAM, 764 [0xFD] = QUIC_FRAME_STREAM, 765 [0xFE] = QUIC_FRAME_STREAM, 766 [0xFF] = QUIC_FRAME_STREAM, 767}; 768 769 770static enum quic_frame_type 771gquic_Q050_parse_frame_type (const unsigned char *buf, size_t len) 772{ 773 if (len > 0) 774 return byte2frame_type_Q050[buf[0]]; 775 else 776 return QUIC_FRAME_INVALID; 777} 778 779 780static int 781gquic_Q050_gen_crypto_frame (unsigned char *buf, size_t buf_len, 782 lsquic_stream_id_t stream_id, uint64_t offset, int fin, 783 size_t size, gsf_read_f gsf_read, void *stream) 784{ 785 return lsquic_ietf_v1_gen_crypto_frame(buf, 0x8, buf_len, stream_id, 786 offset, fin, size, gsf_read, stream); 787} 788 789 790static int 791gquic_Q050_parse_crypto_frame (const unsigned char *buf, size_t rem_packet_sz, 792 struct stream_frame *stream_frame) 793{ 794 if (rem_packet_sz > 0) 795 { 796 assert(0x08 == buf[0]); 797 return lsquic_ietf_v1_parse_crypto_frame(buf, rem_packet_sz, 798 stream_frame); 799 } 800 else 801 return -1; 802} 803 804 805static size_t 806gquic_Q050_calc_crypto_frame_header_sz (uint64_t offset, unsigned data_sz) 807{ 808 return 1 /* Frame type */ 809 + (1 << vint_val2bits(offset)) 810 + (1 << vint_val2bits(data_sz)) 811 ; 812} 813 814 815/* No simple PRST for Q050 */ 816static ssize_t 817gquic_Q050_generate_simple_prst (const lsquic_cid_t *cidp, unsigned char *buf, 818 size_t buf_sz) 819{ 820 return -1; 821} 822 823 824static unsigned 825gquic_Q050_handshake_done_frame_size (void) 826{ 827 return 0; 828} 829 830 831static int 832gquic_Q050_gen_handshake_done_frame (unsigned char *buf, size_t buf_len) 833{ 834 return -1; 835} 836 837 838static int 839gquic_Q050_parse_handshake_done_frame (const unsigned char *buf, size_t buf_len) 840{ 841 return -1; 842} 843 844 845const struct parse_funcs lsquic_parse_funcs_gquic_Q050 = 846{ 847 .pf_gen_reg_pkt_header = gquic_Q050_gen_reg_pkt_header, 848 .pf_parse_packet_in_finish = gquic_Q050_parse_packet_in_finish, 849 .pf_gen_stream_frame = lsquic_gquic_be_gen_stream_frame, 850 .pf_calc_stream_frame_header_sz = lsquic_calc_stream_frame_header_sz_gquic, 851 .pf_parse_stream_frame = lsquic_gquic_be_parse_stream_frame, 852 .pf_dec_stream_frame_size = lsquic_gquic_be_dec_stream_frame_size, 853 .pf_parse_ack_frame = lsquic_gquic_be_parse_ack_frame, 854 .pf_gen_ack_frame = lsquic_gquic_be_gen_ack_frame, 855 .pf_gen_stop_waiting_frame = lsquic_gquic_be_gen_stop_waiting_frame, 856 .pf_parse_stop_waiting_frame = lsquic_gquic_be_parse_stop_waiting_frame, 857 .pf_skip_stop_waiting_frame = lsquic_gquic_be_skip_stop_waiting_frame, 858 .pf_gen_window_update_frame = lsquic_gquic_be_gen_window_update_frame, 859 .pf_parse_window_update_frame = lsquic_gquic_be_parse_window_update_frame, 860 .pf_gen_blocked_frame = lsquic_gquic_be_gen_blocked_frame, 861 .pf_parse_blocked_frame = lsquic_gquic_be_parse_blocked_frame, 862 .pf_gen_rst_frame = lsquic_gquic_be_gen_rst_frame, 863 .pf_parse_rst_frame = lsquic_gquic_be_parse_rst_frame, 864 .pf_connect_close_frame_size = lsquic_gquic_be_connect_close_frame_size, 865 .pf_gen_connect_close_frame = lsquic_gquic_be_gen_connect_close_frame, 866 .pf_parse_connect_close_frame = lsquic_gquic_be_parse_connect_close_frame, 867 .pf_gen_goaway_frame = lsquic_gquic_be_gen_goaway_frame, 868 .pf_parse_goaway_frame = lsquic_gquic_be_parse_goaway_frame, 869 .pf_gen_ping_frame = lsquic_gquic_be_gen_ping_frame, 870#ifndef NDEBUG 871 .pf_write_float_time16 = lsquic_gquic_be_write_float_time16, 872 .pf_read_float_time16 = lsquic_gquic_be_read_float_time16, 873#endif 874 .pf_generate_simple_prst = gquic_Q050_generate_simple_prst, 875 .pf_parse_frame_type = gquic_Q050_parse_frame_type, 876 .pf_turn_on_fin = lsquic_turn_on_fin_Q035_thru_Q046, 877 .pf_packout_size = gquic_Q050_packout_size, 878 .pf_packout_max_header_size = gquic_Q050_packout_max_header_size, 879 .pf_calc_packno_bits = gquic_Q050_calc_packno_bits, 880 .pf_packno_bits2len = gquic_Q050_packno_bits2len, 881 .pf_gen_crypto_frame = gquic_Q050_gen_crypto_frame, 882 .pf_parse_crypto_frame = gquic_Q050_parse_crypto_frame, 883 .pf_calc_crypto_frame_header_sz = gquic_Q050_calc_crypto_frame_header_sz, 884 .pf_gen_handshake_done_frame = gquic_Q050_gen_handshake_done_frame, 885 .pf_parse_handshake_done_frame = gquic_Q050_parse_handshake_done_frame, 886 .pf_handshake_done_frame_size = gquic_Q050_handshake_done_frame_size, 887}; 888