lsquic_parse_gquic_common.c revision 10c492f0
1/* Copyright (c) 2017 - 2018 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_parse_gquic_common.c -- Parsing functions common to GQUIC 4 */ 5 6#include <assert.h> 7#include <errno.h> 8#include <inttypes.h> 9#include <string.h> 10#include <stdlib.h> 11#include <sys/queue.h> 12#ifndef WIN32 13#include <sys/types.h> 14#else 15#include <vc_compat.h> 16#endif 17 18#include "lsquic_types.h" 19#include "lsquic_packet_common.h" 20#include "lsquic_packet_in.h" 21#include "lsquic_parse.h" 22#include "lsquic.h" 23 24#define LSQUIC_LOGGER_MODULE LSQLM_PARSE 25#include "lsquic_logger.h" 26 27#define CHECK_SPACE(need, pstart, pend) \ 28 do { if ((intptr_t) (need) > ((pend) - (pstart))) { return -1; } } while (0) 29 30/* This partially parses `packet_in' and returns 0 if in case it succeeded and 31 * -1 on failure. 32 * 33 * After this function returns 0, connection ID, nonce, and version fields can 34 * be examined. To finsh parsing the packet, call version-specific 35 * pf_parse_packet_in_finish() routine. 36 */ 37int 38parse_packet_in_begin (lsquic_packet_in_t *packet_in, size_t length, 39 int is_server, struct packin_parse_state *state) 40{ 41 int nbytes; 42 enum PACKET_PUBLIC_FLAGS public_flags; 43 const unsigned char *p = packet_in->pi_data; 44 const unsigned char *const pend = packet_in->pi_data + length; 45 46 CHECK_SPACE(1, p, pend); 47 48 public_flags = *p++; 49 50 if (public_flags & PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID) 51 { 52 CHECK_SPACE(8, p, pend); 53 memcpy(&packet_in->pi_conn_id, p, 8); 54 packet_in->pi_flags |= PI_CONN_ID; 55 p += 8; 56 } 57 58 if (public_flags & PACKET_PUBLIC_FLAGS_VERSION) 59 { 60 /* It seems that version negotiation packets sent by Google may have 61 * NONCE bit set. Ignore it: 62 */ 63 public_flags &= ~PACKET_PUBLIC_FLAGS_NONCE; 64 65 if (is_server) 66 { 67 CHECK_SPACE(4, p, pend); 68 packet_in->pi_quic_ver = p - packet_in->pi_data; 69 p += 4; 70 } 71 else 72 { /* OK, we have a version negotiation packet. We need to verify 73 * that it has correct structure. See Section 4.3 of 74 * [draft-ietf-quic-transport-00]. 75 */ 76 if ((public_flags & ~(PACKET_PUBLIC_FLAGS_VERSION| 77 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID)) 78 || ((pend - p) & 3)) 79 return -1; 80 CHECK_SPACE(4, p, pend); 81 packet_in->pi_quic_ver = p - packet_in->pi_data; 82 p = pend; 83 } 84 } 85 else 86 { 87 /* From [draft-hamilton-quic-transport-protocol-01]: 88 * 0x40 = MULTIPATH. This bit is reserved for multipath use. 89 * 0x80 is currently unused, and must be set to 0. 90 * 91 * The reference implementation checks that two high bits are not set 92 * if version flag is not set or if the version is the same. For our 93 * purposes, all GQUIC version we support so far have these bits set 94 * to zero. 95 */ 96 if (public_flags & (0x80|0x40)) 97 return -1; 98 packet_in->pi_quic_ver = 0; 99 } 100 101 if (!is_server && (public_flags & PACKET_PUBLIC_FLAGS_NONCE) == 102 PACKET_PUBLIC_FLAGS_NONCE) 103 { 104 CHECK_SPACE(32, p, pend); 105 packet_in->pi_nonce = p - packet_in->pi_data; 106 p += 32; 107 } 108 else 109 packet_in->pi_nonce = 0; 110 111 state->pps_p = p; 112 113 packet_in->pi_packno = 0; 114 if (0 == (public_flags & (PACKET_PUBLIC_FLAGS_VERSION|PACKET_PUBLIC_FLAGS_RST)) 115 || ((public_flags & PACKET_PUBLIC_FLAGS_VERSION) && is_server)) 116 { 117 nbytes = twobit_to_1246((public_flags >> 4) & 3); 118 CHECK_SPACE(nbytes, p, pend); 119 p += nbytes; 120 state->pps_nbytes = nbytes; 121 } 122 else 123 state->pps_nbytes = 0; 124 125 packet_in->pi_header_sz = p - packet_in->pi_data; 126 packet_in->pi_frame_types = 0; 127 memset(&packet_in->pi_next, 0, sizeof(packet_in->pi_next)); 128 packet_in->pi_data_sz = length; 129 packet_in->pi_refcnt = 0; 130 packet_in->pi_received = 0; 131 132 return 0; 133} 134 135 136static const enum QUIC_FRAME_TYPE byte2frame_type_Q035_thru_Q039[0x100] = 137{ 138 [0x00] = QUIC_FRAME_PADDING, 139 [0x01] = QUIC_FRAME_RST_STREAM, 140 [0x02] = QUIC_FRAME_CONNECTION_CLOSE, 141 [0x03] = QUIC_FRAME_GOAWAY, 142 [0x04] = QUIC_FRAME_WINDOW_UPDATE, 143 [0x05] = QUIC_FRAME_BLOCKED, 144 [0x06] = QUIC_FRAME_STOP_WAITING, 145 [0x07] = QUIC_FRAME_PING, 146 [0x08] = QUIC_FRAME_INVALID, 147 [0x09] = QUIC_FRAME_INVALID, 148 [0x0A] = QUIC_FRAME_INVALID, 149 [0x0B] = QUIC_FRAME_INVALID, 150 [0x0C] = QUIC_FRAME_INVALID, 151 [0x0D] = QUIC_FRAME_INVALID, 152 [0x0E] = QUIC_FRAME_INVALID, 153 [0x0F] = QUIC_FRAME_INVALID, 154 [0x10] = QUIC_FRAME_INVALID, 155 [0x11] = QUIC_FRAME_INVALID, 156 [0x12] = QUIC_FRAME_INVALID, 157 [0x13] = QUIC_FRAME_INVALID, 158 [0x14] = QUIC_FRAME_INVALID, 159 [0x15] = QUIC_FRAME_INVALID, 160 [0x16] = QUIC_FRAME_INVALID, 161 [0x17] = QUIC_FRAME_INVALID, 162 [0x18] = QUIC_FRAME_INVALID, 163 [0x19] = QUIC_FRAME_INVALID, 164 [0x1A] = QUIC_FRAME_INVALID, 165 [0x1B] = QUIC_FRAME_INVALID, 166 [0x1C] = QUIC_FRAME_INVALID, 167 [0x1D] = QUIC_FRAME_INVALID, 168 [0x1E] = QUIC_FRAME_INVALID, 169 [0x1F] = QUIC_FRAME_INVALID, 170 [0x20] = QUIC_FRAME_INVALID, 171 [0x21] = QUIC_FRAME_INVALID, 172 [0x22] = QUIC_FRAME_INVALID, 173 [0x23] = QUIC_FRAME_INVALID, 174 [0x24] = QUIC_FRAME_INVALID, 175 [0x25] = QUIC_FRAME_INVALID, 176 [0x26] = QUIC_FRAME_INVALID, 177 [0x27] = QUIC_FRAME_INVALID, 178 [0x28] = QUIC_FRAME_INVALID, 179 [0x29] = QUIC_FRAME_INVALID, 180 [0x2A] = QUIC_FRAME_INVALID, 181 [0x2B] = QUIC_FRAME_INVALID, 182 [0x2C] = QUIC_FRAME_INVALID, 183 [0x2D] = QUIC_FRAME_INVALID, 184 [0x2E] = QUIC_FRAME_INVALID, 185 [0x2F] = QUIC_FRAME_INVALID, 186 [0x30] = QUIC_FRAME_INVALID, 187 [0x31] = QUIC_FRAME_INVALID, 188 [0x32] = QUIC_FRAME_INVALID, 189 [0x33] = QUIC_FRAME_INVALID, 190 [0x34] = QUIC_FRAME_INVALID, 191 [0x35] = QUIC_FRAME_INVALID, 192 [0x36] = QUIC_FRAME_INVALID, 193 [0x37] = QUIC_FRAME_INVALID, 194 [0x38] = QUIC_FRAME_INVALID, 195 [0x39] = QUIC_FRAME_INVALID, 196 [0x3A] = QUIC_FRAME_INVALID, 197 [0x3B] = QUIC_FRAME_INVALID, 198 [0x3C] = QUIC_FRAME_INVALID, 199 [0x3D] = QUIC_FRAME_INVALID, 200 [0x3E] = QUIC_FRAME_INVALID, 201 [0x3F] = QUIC_FRAME_INVALID, 202 [0x40] = QUIC_FRAME_ACK, 203 [0x41] = QUIC_FRAME_ACK, 204 [0x42] = QUIC_FRAME_ACK, 205 [0x43] = QUIC_FRAME_ACK, 206 [0x44] = QUIC_FRAME_ACK, 207 [0x45] = QUIC_FRAME_ACK, 208 [0x46] = QUIC_FRAME_ACK, 209 [0x47] = QUIC_FRAME_ACK, 210 [0x48] = QUIC_FRAME_ACK, 211 [0x49] = QUIC_FRAME_ACK, 212 [0x4A] = QUIC_FRAME_ACK, 213 [0x4B] = QUIC_FRAME_ACK, 214 [0x4C] = QUIC_FRAME_ACK, 215 [0x4D] = QUIC_FRAME_ACK, 216 [0x4E] = QUIC_FRAME_ACK, 217 [0x4F] = QUIC_FRAME_ACK, 218 [0x50] = QUIC_FRAME_ACK, 219 [0x51] = QUIC_FRAME_ACK, 220 [0x52] = QUIC_FRAME_ACK, 221 [0x53] = QUIC_FRAME_ACK, 222 [0x54] = QUIC_FRAME_ACK, 223 [0x55] = QUIC_FRAME_ACK, 224 [0x56] = QUIC_FRAME_ACK, 225 [0x57] = QUIC_FRAME_ACK, 226 [0x58] = QUIC_FRAME_ACK, 227 [0x59] = QUIC_FRAME_ACK, 228 [0x5A] = QUIC_FRAME_ACK, 229 [0x5B] = QUIC_FRAME_ACK, 230 [0x5C] = QUIC_FRAME_ACK, 231 [0x5D] = QUIC_FRAME_ACK, 232 [0x5E] = QUIC_FRAME_ACK, 233 [0x5F] = QUIC_FRAME_ACK, 234 [0x60] = QUIC_FRAME_ACK, 235 [0x61] = QUIC_FRAME_ACK, 236 [0x62] = QUIC_FRAME_ACK, 237 [0x63] = QUIC_FRAME_ACK, 238 [0x64] = QUIC_FRAME_ACK, 239 [0x65] = QUIC_FRAME_ACK, 240 [0x66] = QUIC_FRAME_ACK, 241 [0x67] = QUIC_FRAME_ACK, 242 [0x68] = QUIC_FRAME_ACK, 243 [0x69] = QUIC_FRAME_ACK, 244 [0x6A] = QUIC_FRAME_ACK, 245 [0x6B] = QUIC_FRAME_ACK, 246 [0x6C] = QUIC_FRAME_ACK, 247 [0x6D] = QUIC_FRAME_ACK, 248 [0x6E] = QUIC_FRAME_ACK, 249 [0x6F] = QUIC_FRAME_ACK, 250 [0x70] = QUIC_FRAME_ACK, 251 [0x71] = QUIC_FRAME_ACK, 252 [0x72] = QUIC_FRAME_ACK, 253 [0x73] = QUIC_FRAME_ACK, 254 [0x74] = QUIC_FRAME_ACK, 255 [0x75] = QUIC_FRAME_ACK, 256 [0x76] = QUIC_FRAME_ACK, 257 [0x77] = QUIC_FRAME_ACK, 258 [0x78] = QUIC_FRAME_ACK, 259 [0x79] = QUIC_FRAME_ACK, 260 [0x7A] = QUIC_FRAME_ACK, 261 [0x7B] = QUIC_FRAME_ACK, 262 [0x7C] = QUIC_FRAME_ACK, 263 [0x7D] = QUIC_FRAME_ACK, 264 [0x7E] = QUIC_FRAME_ACK, 265 [0x7F] = QUIC_FRAME_ACK, 266 [0x80] = QUIC_FRAME_STREAM, 267 [0x81] = QUIC_FRAME_STREAM, 268 [0x82] = QUIC_FRAME_STREAM, 269 [0x83] = QUIC_FRAME_STREAM, 270 [0x84] = QUIC_FRAME_STREAM, 271 [0x85] = QUIC_FRAME_STREAM, 272 [0x86] = QUIC_FRAME_STREAM, 273 [0x87] = QUIC_FRAME_STREAM, 274 [0x88] = QUIC_FRAME_STREAM, 275 [0x89] = QUIC_FRAME_STREAM, 276 [0x8A] = QUIC_FRAME_STREAM, 277 [0x8B] = QUIC_FRAME_STREAM, 278 [0x8C] = QUIC_FRAME_STREAM, 279 [0x8D] = QUIC_FRAME_STREAM, 280 [0x8E] = QUIC_FRAME_STREAM, 281 [0x8F] = QUIC_FRAME_STREAM, 282 [0x90] = QUIC_FRAME_STREAM, 283 [0x91] = QUIC_FRAME_STREAM, 284 [0x92] = QUIC_FRAME_STREAM, 285 [0x93] = QUIC_FRAME_STREAM, 286 [0x94] = QUIC_FRAME_STREAM, 287 [0x95] = QUIC_FRAME_STREAM, 288 [0x96] = QUIC_FRAME_STREAM, 289 [0x97] = QUIC_FRAME_STREAM, 290 [0x98] = QUIC_FRAME_STREAM, 291 [0x99] = QUIC_FRAME_STREAM, 292 [0x9A] = QUIC_FRAME_STREAM, 293 [0x9B] = QUIC_FRAME_STREAM, 294 [0x9C] = QUIC_FRAME_STREAM, 295 [0x9D] = QUIC_FRAME_STREAM, 296 [0x9E] = QUIC_FRAME_STREAM, 297 [0x9F] = QUIC_FRAME_STREAM, 298 [0xA0] = QUIC_FRAME_STREAM, 299 [0xA1] = QUIC_FRAME_STREAM, 300 [0xA2] = QUIC_FRAME_STREAM, 301 [0xA3] = QUIC_FRAME_STREAM, 302 [0xA4] = QUIC_FRAME_STREAM, 303 [0xA5] = QUIC_FRAME_STREAM, 304 [0xA6] = QUIC_FRAME_STREAM, 305 [0xA7] = QUIC_FRAME_STREAM, 306 [0xA8] = QUIC_FRAME_STREAM, 307 [0xA9] = QUIC_FRAME_STREAM, 308 [0xAA] = QUIC_FRAME_STREAM, 309 [0xAB] = QUIC_FRAME_STREAM, 310 [0xAC] = QUIC_FRAME_STREAM, 311 [0xAD] = QUIC_FRAME_STREAM, 312 [0xAE] = QUIC_FRAME_STREAM, 313 [0xAF] = QUIC_FRAME_STREAM, 314 [0xB0] = QUIC_FRAME_STREAM, 315 [0xB1] = QUIC_FRAME_STREAM, 316 [0xB2] = QUIC_FRAME_STREAM, 317 [0xB3] = QUIC_FRAME_STREAM, 318 [0xB4] = QUIC_FRAME_STREAM, 319 [0xB5] = QUIC_FRAME_STREAM, 320 [0xB6] = QUIC_FRAME_STREAM, 321 [0xB7] = QUIC_FRAME_STREAM, 322 [0xB8] = QUIC_FRAME_STREAM, 323 [0xB9] = QUIC_FRAME_STREAM, 324 [0xBA] = QUIC_FRAME_STREAM, 325 [0xBB] = QUIC_FRAME_STREAM, 326 [0xBC] = QUIC_FRAME_STREAM, 327 [0xBD] = QUIC_FRAME_STREAM, 328 [0xBE] = QUIC_FRAME_STREAM, 329 [0xBF] = QUIC_FRAME_STREAM, 330 [0xC0] = QUIC_FRAME_STREAM, 331 [0xC1] = QUIC_FRAME_STREAM, 332 [0xC2] = QUIC_FRAME_STREAM, 333 [0xC3] = QUIC_FRAME_STREAM, 334 [0xC4] = QUIC_FRAME_STREAM, 335 [0xC5] = QUIC_FRAME_STREAM, 336 [0xC6] = QUIC_FRAME_STREAM, 337 [0xC7] = QUIC_FRAME_STREAM, 338 [0xC8] = QUIC_FRAME_STREAM, 339 [0xC9] = QUIC_FRAME_STREAM, 340 [0xCA] = QUIC_FRAME_STREAM, 341 [0xCB] = QUIC_FRAME_STREAM, 342 [0xCC] = QUIC_FRAME_STREAM, 343 [0xCD] = QUIC_FRAME_STREAM, 344 [0xCE] = QUIC_FRAME_STREAM, 345 [0xCF] = QUIC_FRAME_STREAM, 346 [0xD0] = QUIC_FRAME_STREAM, 347 [0xD1] = QUIC_FRAME_STREAM, 348 [0xD2] = QUIC_FRAME_STREAM, 349 [0xD3] = QUIC_FRAME_STREAM, 350 [0xD4] = QUIC_FRAME_STREAM, 351 [0xD5] = QUIC_FRAME_STREAM, 352 [0xD6] = QUIC_FRAME_STREAM, 353 [0xD7] = QUIC_FRAME_STREAM, 354 [0xD8] = QUIC_FRAME_STREAM, 355 [0xD9] = QUIC_FRAME_STREAM, 356 [0xDA] = QUIC_FRAME_STREAM, 357 [0xDB] = QUIC_FRAME_STREAM, 358 [0xDC] = QUIC_FRAME_STREAM, 359 [0xDD] = QUIC_FRAME_STREAM, 360 [0xDE] = QUIC_FRAME_STREAM, 361 [0xDF] = QUIC_FRAME_STREAM, 362 [0xE0] = QUIC_FRAME_STREAM, 363 [0xE1] = QUIC_FRAME_STREAM, 364 [0xE2] = QUIC_FRAME_STREAM, 365 [0xE3] = QUIC_FRAME_STREAM, 366 [0xE4] = QUIC_FRAME_STREAM, 367 [0xE5] = QUIC_FRAME_STREAM, 368 [0xE6] = QUIC_FRAME_STREAM, 369 [0xE7] = QUIC_FRAME_STREAM, 370 [0xE8] = QUIC_FRAME_STREAM, 371 [0xE9] = QUIC_FRAME_STREAM, 372 [0xEA] = QUIC_FRAME_STREAM, 373 [0xEB] = QUIC_FRAME_STREAM, 374 [0xEC] = QUIC_FRAME_STREAM, 375 [0xED] = QUIC_FRAME_STREAM, 376 [0xEE] = QUIC_FRAME_STREAM, 377 [0xEF] = QUIC_FRAME_STREAM, 378 [0xF0] = QUIC_FRAME_STREAM, 379 [0xF1] = QUIC_FRAME_STREAM, 380 [0xF2] = QUIC_FRAME_STREAM, 381 [0xF3] = QUIC_FRAME_STREAM, 382 [0xF4] = QUIC_FRAME_STREAM, 383 [0xF5] = QUIC_FRAME_STREAM, 384 [0xF6] = QUIC_FRAME_STREAM, 385 [0xF7] = QUIC_FRAME_STREAM, 386 [0xF8] = QUIC_FRAME_STREAM, 387 [0xF9] = QUIC_FRAME_STREAM, 388 [0xFA] = QUIC_FRAME_STREAM, 389 [0xFB] = QUIC_FRAME_STREAM, 390 [0xFC] = QUIC_FRAME_STREAM, 391 [0xFD] = QUIC_FRAME_STREAM, 392 [0xFE] = QUIC_FRAME_STREAM, 393 [0xFF] = QUIC_FRAME_STREAM, 394}; 395 396 397static const enum QUIC_FRAME_TYPE byte2frame_type_Q041[0x100] = 398{ 399 [0x00] = QUIC_FRAME_PADDING, 400 [0x01] = QUIC_FRAME_RST_STREAM, 401 [0x02] = QUIC_FRAME_CONNECTION_CLOSE, 402 [0x03] = QUIC_FRAME_GOAWAY, 403 [0x04] = QUIC_FRAME_WINDOW_UPDATE, 404 [0x05] = QUIC_FRAME_BLOCKED, 405 [0x06] = QUIC_FRAME_STOP_WAITING, 406 [0x07] = QUIC_FRAME_PING, 407 [0x08] = QUIC_FRAME_INVALID, 408 [0x09] = QUIC_FRAME_INVALID, 409 [0x0A] = QUIC_FRAME_INVALID, 410 [0x0B] = QUIC_FRAME_INVALID, 411 [0x0C] = QUIC_FRAME_INVALID, 412 [0x0D] = QUIC_FRAME_INVALID, 413 [0x0E] = QUIC_FRAME_INVALID, 414 [0x0F] = QUIC_FRAME_INVALID, 415 [0x10] = QUIC_FRAME_INVALID, 416 [0x11] = QUIC_FRAME_INVALID, 417 [0x12] = QUIC_FRAME_INVALID, 418 [0x13] = QUIC_FRAME_INVALID, 419 [0x14] = QUIC_FRAME_INVALID, 420 [0x15] = QUIC_FRAME_INVALID, 421 [0x16] = QUIC_FRAME_INVALID, 422 [0x17] = QUIC_FRAME_INVALID, 423 [0x18] = QUIC_FRAME_INVALID, 424 [0x19] = QUIC_FRAME_INVALID, 425 [0x1A] = QUIC_FRAME_INVALID, 426 [0x1B] = QUIC_FRAME_INVALID, 427 [0x1C] = QUIC_FRAME_INVALID, 428 [0x1D] = QUIC_FRAME_INVALID, 429 [0x1E] = QUIC_FRAME_INVALID, 430 [0x1F] = QUIC_FRAME_INVALID, 431 [0x20] = QUIC_FRAME_INVALID, 432 [0x21] = QUIC_FRAME_INVALID, 433 [0x22] = QUIC_FRAME_INVALID, 434 [0x23] = QUIC_FRAME_INVALID, 435 [0x24] = QUIC_FRAME_INVALID, 436 [0x25] = QUIC_FRAME_INVALID, 437 [0x26] = QUIC_FRAME_INVALID, 438 [0x27] = QUIC_FRAME_INVALID, 439 [0x28] = QUIC_FRAME_INVALID, 440 [0x29] = QUIC_FRAME_INVALID, 441 [0x2A] = QUIC_FRAME_INVALID, 442 [0x2B] = QUIC_FRAME_INVALID, 443 [0x2C] = QUIC_FRAME_INVALID, 444 [0x2D] = QUIC_FRAME_INVALID, 445 [0x2E] = QUIC_FRAME_INVALID, 446 [0x2F] = QUIC_FRAME_INVALID, 447 [0x30] = QUIC_FRAME_INVALID, 448 [0x31] = QUIC_FRAME_INVALID, 449 [0x32] = QUIC_FRAME_INVALID, 450 [0x33] = QUIC_FRAME_INVALID, 451 [0x34] = QUIC_FRAME_INVALID, 452 [0x35] = QUIC_FRAME_INVALID, 453 [0x36] = QUIC_FRAME_INVALID, 454 [0x37] = QUIC_FRAME_INVALID, 455 [0x38] = QUIC_FRAME_INVALID, 456 [0x39] = QUIC_FRAME_INVALID, 457 [0x3A] = QUIC_FRAME_INVALID, 458 [0x3B] = QUIC_FRAME_INVALID, 459 [0x3C] = QUIC_FRAME_INVALID, 460 [0x3D] = QUIC_FRAME_INVALID, 461 [0x3E] = QUIC_FRAME_INVALID, 462 [0x3F] = QUIC_FRAME_INVALID, 463 [0x40] = QUIC_FRAME_INVALID, 464 [0x41] = QUIC_FRAME_INVALID, 465 [0x42] = QUIC_FRAME_INVALID, 466 [0x43] = QUIC_FRAME_INVALID, 467 [0x44] = QUIC_FRAME_INVALID, 468 [0x45] = QUIC_FRAME_INVALID, 469 [0x46] = QUIC_FRAME_INVALID, 470 [0x47] = QUIC_FRAME_INVALID, 471 [0x48] = QUIC_FRAME_INVALID, 472 [0x49] = QUIC_FRAME_INVALID, 473 [0x4A] = QUIC_FRAME_INVALID, 474 [0x4B] = QUIC_FRAME_INVALID, 475 [0x4C] = QUIC_FRAME_INVALID, 476 [0x4D] = QUIC_FRAME_INVALID, 477 [0x4E] = QUIC_FRAME_INVALID, 478 [0x4F] = QUIC_FRAME_INVALID, 479 [0x50] = QUIC_FRAME_INVALID, 480 [0x51] = QUIC_FRAME_INVALID, 481 [0x52] = QUIC_FRAME_INVALID, 482 [0x53] = QUIC_FRAME_INVALID, 483 [0x54] = QUIC_FRAME_INVALID, 484 [0x55] = QUIC_FRAME_INVALID, 485 [0x56] = QUIC_FRAME_INVALID, 486 [0x57] = QUIC_FRAME_INVALID, 487 [0x58] = QUIC_FRAME_INVALID, 488 [0x59] = QUIC_FRAME_INVALID, 489 [0x5A] = QUIC_FRAME_INVALID, 490 [0x5B] = QUIC_FRAME_INVALID, 491 [0x5C] = QUIC_FRAME_INVALID, 492 [0x5D] = QUIC_FRAME_INVALID, 493 [0x5E] = QUIC_FRAME_INVALID, 494 [0x5F] = QUIC_FRAME_INVALID, 495 [0x60] = QUIC_FRAME_INVALID, 496 [0x61] = QUIC_FRAME_INVALID, 497 [0x62] = QUIC_FRAME_INVALID, 498 [0x63] = QUIC_FRAME_INVALID, 499 [0x64] = QUIC_FRAME_INVALID, 500 [0x65] = QUIC_FRAME_INVALID, 501 [0x66] = QUIC_FRAME_INVALID, 502 [0x67] = QUIC_FRAME_INVALID, 503 [0x68] = QUIC_FRAME_INVALID, 504 [0x69] = QUIC_FRAME_INVALID, 505 [0x6A] = QUIC_FRAME_INVALID, 506 [0x6B] = QUIC_FRAME_INVALID, 507 [0x6C] = QUIC_FRAME_INVALID, 508 [0x6D] = QUIC_FRAME_INVALID, 509 [0x6E] = QUIC_FRAME_INVALID, 510 [0x6F] = QUIC_FRAME_INVALID, 511 [0x70] = QUIC_FRAME_INVALID, 512 [0x71] = QUIC_FRAME_INVALID, 513 [0x72] = QUIC_FRAME_INVALID, 514 [0x73] = QUIC_FRAME_INVALID, 515 [0x74] = QUIC_FRAME_INVALID, 516 [0x75] = QUIC_FRAME_INVALID, 517 [0x76] = QUIC_FRAME_INVALID, 518 [0x77] = QUIC_FRAME_INVALID, 519 [0x78] = QUIC_FRAME_INVALID, 520 [0x79] = QUIC_FRAME_INVALID, 521 [0x7A] = QUIC_FRAME_INVALID, 522 [0x7B] = QUIC_FRAME_INVALID, 523 [0x7C] = QUIC_FRAME_INVALID, 524 [0x7D] = QUIC_FRAME_INVALID, 525 [0x7E] = QUIC_FRAME_INVALID, 526 [0x7F] = QUIC_FRAME_INVALID, 527 [0x80] = QUIC_FRAME_INVALID, 528 [0x81] = QUIC_FRAME_INVALID, 529 [0x82] = QUIC_FRAME_INVALID, 530 [0x83] = QUIC_FRAME_INVALID, 531 [0x84] = QUIC_FRAME_INVALID, 532 [0x85] = QUIC_FRAME_INVALID, 533 [0x86] = QUIC_FRAME_INVALID, 534 [0x87] = QUIC_FRAME_INVALID, 535 [0x88] = QUIC_FRAME_INVALID, 536 [0x89] = QUIC_FRAME_INVALID, 537 [0x8A] = QUIC_FRAME_INVALID, 538 [0x8B] = QUIC_FRAME_INVALID, 539 [0x8C] = QUIC_FRAME_INVALID, 540 [0x8D] = QUIC_FRAME_INVALID, 541 [0x8E] = QUIC_FRAME_INVALID, 542 [0x8F] = QUIC_FRAME_INVALID, 543 [0x90] = QUIC_FRAME_INVALID, 544 [0x91] = QUIC_FRAME_INVALID, 545 [0x92] = QUIC_FRAME_INVALID, 546 [0x93] = QUIC_FRAME_INVALID, 547 [0x94] = QUIC_FRAME_INVALID, 548 [0x95] = QUIC_FRAME_INVALID, 549 [0x96] = QUIC_FRAME_INVALID, 550 [0x97] = QUIC_FRAME_INVALID, 551 [0x98] = QUIC_FRAME_INVALID, 552 [0x99] = QUIC_FRAME_INVALID, 553 [0x9A] = QUIC_FRAME_INVALID, 554 [0x9B] = QUIC_FRAME_INVALID, 555 [0x9C] = QUIC_FRAME_INVALID, 556 [0x9D] = QUIC_FRAME_INVALID, 557 [0x9E] = QUIC_FRAME_INVALID, 558 [0x9F] = QUIC_FRAME_INVALID, 559 [0xA0] = QUIC_FRAME_ACK, 560 [0xA1] = QUIC_FRAME_ACK, 561 [0xA2] = QUIC_FRAME_ACK, 562 [0xA3] = QUIC_FRAME_ACK, 563 [0xA4] = QUIC_FRAME_ACK, 564 [0xA5] = QUIC_FRAME_ACK, 565 [0xA6] = QUIC_FRAME_ACK, 566 [0xA7] = QUIC_FRAME_ACK, 567 [0xA8] = QUIC_FRAME_ACK, 568 [0xA9] = QUIC_FRAME_ACK, 569 [0xAA] = QUIC_FRAME_ACK, 570 [0xAB] = QUIC_FRAME_ACK, 571 [0xAC] = QUIC_FRAME_ACK, 572 [0xAD] = QUIC_FRAME_ACK, 573 [0xAE] = QUIC_FRAME_ACK, 574 [0xAF] = QUIC_FRAME_ACK, 575 [0xB0] = QUIC_FRAME_ACK, 576 [0xB1] = QUIC_FRAME_ACK, 577 [0xB2] = QUIC_FRAME_ACK, 578 [0xB3] = QUIC_FRAME_ACK, 579 [0xB4] = QUIC_FRAME_ACK, 580 [0xB5] = QUIC_FRAME_ACK, 581 [0xB6] = QUIC_FRAME_ACK, 582 [0xB7] = QUIC_FRAME_ACK, 583 [0xB8] = QUIC_FRAME_ACK, 584 [0xB9] = QUIC_FRAME_ACK, 585 [0xBA] = QUIC_FRAME_ACK, 586 [0xBB] = QUIC_FRAME_ACK, 587 [0xBC] = QUIC_FRAME_ACK, 588 [0xBD] = QUIC_FRAME_ACK, 589 [0xBE] = QUIC_FRAME_ACK, 590 [0xBF] = QUIC_FRAME_ACK, 591 [0xC0] = QUIC_FRAME_STREAM, 592 [0xC1] = QUIC_FRAME_STREAM, 593 [0xC2] = QUIC_FRAME_STREAM, 594 [0xC3] = QUIC_FRAME_STREAM, 595 [0xC4] = QUIC_FRAME_STREAM, 596 [0xC5] = QUIC_FRAME_STREAM, 597 [0xC6] = QUIC_FRAME_STREAM, 598 [0xC7] = QUIC_FRAME_STREAM, 599 [0xC8] = QUIC_FRAME_STREAM, 600 [0xC9] = QUIC_FRAME_STREAM, 601 [0xCA] = QUIC_FRAME_STREAM, 602 [0xCB] = QUIC_FRAME_STREAM, 603 [0xCC] = QUIC_FRAME_STREAM, 604 [0xCD] = QUIC_FRAME_STREAM, 605 [0xCE] = QUIC_FRAME_STREAM, 606 [0xCF] = QUIC_FRAME_STREAM, 607 [0xD0] = QUIC_FRAME_STREAM, 608 [0xD1] = QUIC_FRAME_STREAM, 609 [0xD2] = QUIC_FRAME_STREAM, 610 [0xD3] = QUIC_FRAME_STREAM, 611 [0xD4] = QUIC_FRAME_STREAM, 612 [0xD5] = QUIC_FRAME_STREAM, 613 [0xD6] = QUIC_FRAME_STREAM, 614 [0xD7] = QUIC_FRAME_STREAM, 615 [0xD8] = QUIC_FRAME_STREAM, 616 [0xD9] = QUIC_FRAME_STREAM, 617 [0xDA] = QUIC_FRAME_STREAM, 618 [0xDB] = QUIC_FRAME_STREAM, 619 [0xDC] = QUIC_FRAME_STREAM, 620 [0xDD] = QUIC_FRAME_STREAM, 621 [0xDE] = QUIC_FRAME_STREAM, 622 [0xDF] = QUIC_FRAME_STREAM, 623 [0xE0] = QUIC_FRAME_STREAM, 624 [0xE1] = QUIC_FRAME_STREAM, 625 [0xE2] = QUIC_FRAME_STREAM, 626 [0xE3] = QUIC_FRAME_STREAM, 627 [0xE4] = QUIC_FRAME_STREAM, 628 [0xE5] = QUIC_FRAME_STREAM, 629 [0xE6] = QUIC_FRAME_STREAM, 630 [0xE7] = QUIC_FRAME_STREAM, 631 [0xE8] = QUIC_FRAME_STREAM, 632 [0xE9] = QUIC_FRAME_STREAM, 633 [0xEA] = QUIC_FRAME_STREAM, 634 [0xEB] = QUIC_FRAME_STREAM, 635 [0xEC] = QUIC_FRAME_STREAM, 636 [0xED] = QUIC_FRAME_STREAM, 637 [0xEE] = QUIC_FRAME_STREAM, 638 [0xEF] = QUIC_FRAME_STREAM, 639 [0xF0] = QUIC_FRAME_STREAM, 640 [0xF1] = QUIC_FRAME_STREAM, 641 [0xF2] = QUIC_FRAME_STREAM, 642 [0xF3] = QUIC_FRAME_STREAM, 643 [0xF4] = QUIC_FRAME_STREAM, 644 [0xF5] = QUIC_FRAME_STREAM, 645 [0xF6] = QUIC_FRAME_STREAM, 646 [0xF7] = QUIC_FRAME_STREAM, 647 [0xF8] = QUIC_FRAME_STREAM, 648 [0xF9] = QUIC_FRAME_STREAM, 649 [0xFA] = QUIC_FRAME_STREAM, 650 [0xFB] = QUIC_FRAME_STREAM, 651 [0xFC] = QUIC_FRAME_STREAM, 652 [0xFD] = QUIC_FRAME_STREAM, 653 [0xFE] = QUIC_FRAME_STREAM, 654 [0xFF] = QUIC_FRAME_STREAM, 655}; 656 657 658enum QUIC_FRAME_TYPE 659parse_frame_type_gquic_Q035_thru_Q039 (unsigned char b) 660{ 661 return byte2frame_type_Q035_thru_Q039[b]; 662} 663 664 665enum QUIC_FRAME_TYPE 666parse_frame_type_gquic_Q041 (unsigned char b) 667{ 668 return byte2frame_type_Q041[b]; 669} 670 671 672unsigned 673parse_stream_frame_header_sz_gquic (unsigned char type) 674{ 675 const unsigned data_len = (type >> 4) & 2; 676 const unsigned offset_len = ((type >> 2) & 7) + 1 - !((type >> 2) & 7); 677 const unsigned stream_id_len = 1 + (type & 3); 678 return 1 + data_len + offset_len + stream_id_len; 679} 680 681 682void 683lsquic_turn_on_fin_Q035_thru_Q039 (unsigned char *stream_header) 684{ 685 /* 1fdoooss */ 686 *stream_header |= 0x40; 687} 688 689 690size_t 691calc_stream_frame_header_sz_gquic (uint32_t stream_id, uint64_t offset) 692{ 693 return 694 /* Type */ 695 1 696 /* Stream ID length */ 697 + ((stream_id) > 0x0000FF) 698 + ((stream_id) > 0x00FFFF) 699 + ((stream_id) > 0xFFFFFF) 700 + 1 701 /* Offset length */ 702 + ((offset) >= (1ULL << 56)) 703 + ((offset) >= (1ULL << 48)) 704 + ((offset) >= (1ULL << 40)) 705 + ((offset) >= (1ULL << 32)) 706 + ((offset) >= (1ULL << 24)) 707 + ((offset) >= (1ULL << 16)) 708 + (((offset) > 0) << 1) 709 /* Add data length (2) yourself, if necessary */ 710 ; 711} 712 713 714char * 715acki2str (const struct ack_info *acki, size_t *sz) 716{ 717 size_t off, bufsz, nw; 718 unsigned n; 719 char *buf; 720 721 bufsz = acki->n_ranges * (3 /* [-] */ + 20 /* ~0ULL */ * 2); 722 buf = malloc(bufsz); 723 if (!buf) 724 { 725 LSQ_WARN("%s: malloc(%zd) failure: %s", __func__, bufsz, 726 strerror(errno)); 727 return NULL; 728 } 729 730 off = 0; 731 for (n = 0; n < acki->n_ranges; ++n) 732 { 733 nw = snprintf(buf + off, bufsz - off, "[%"PRIu64"-%"PRIu64"]", 734 acki->ranges[n].high, acki->ranges[n].low); 735 if (nw > bufsz - off) 736 break; 737 off += nw; 738 } 739 740 *sz = off; 741 return buf; 742} 743 744 745