lsquic_packet_gquic.h revision b8fa6195
1/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc. See LICENSE. */ 2#ifndef LSQUIC_PACKET_GQUIC_H 3#define LSQUIC_PACKET_GQUIC_H 1 4 5#include <stdint.h> 6 7#include "lsquic_int_types.h" 8 9enum PACKET_PUBLIC_FLAGS 10{ 11 PACKET_PUBLIC_FLAGS_VERSION = 1, 12 PACKET_PUBLIC_FLAGS_RST = 2, 13 PACKET_PUBLIC_FLAGS_NONCE = 4, 14 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID = 8, 15 PACKET_PUBLIC_FLAGS_MULTIPATH = 1 << 6, 16 PACKET_PUBLIC_FLAGS_TWO_OR_MORE_BYTES = 1 << 7, 17}; 18 19/* XXX The name of this macro no longer matches: it applies both to gQUIC and 20 * IETF QUIC. 21 */ 22#define GQUIC_FRAME_REGEN_MASK ((1 << QUIC_FRAME_ACK) \ 23 | (1 << QUIC_FRAME_PATH_CHALLENGE) | (1 << QUIC_FRAME_PATH_RESPONSE) \ 24 | (1 << QUIC_FRAME_STOP_WAITING) | (1 << QUIC_FRAME_TIMESTAMP)) 25 26#define GQUIC_FRAME_REGENERATE(frame_type) ((1 << (frame_type)) & GQUIC_FRAME_REGEN_MASK) 27 28#define GQUIC_FRAME_ACKABLE_MASK ( \ 29 (1 << QUIC_FRAME_STREAM) \ 30 | (1 << QUIC_FRAME_RST_STREAM) \ 31 | (1 << QUIC_FRAME_GOAWAY) \ 32 | (1 << QUIC_FRAME_WINDOW_UPDATE) \ 33 | (1 << QUIC_FRAME_PING) \ 34 | (1 << QUIC_FRAME_BLOCKED) \ 35 | (1 << QUIC_FRAME_CRYPTO) \ 36) 37 38#define GQUIC_FRAME_ACKABLE(frame_type) ((1 << (frame_type)) & GQUIC_FRAME_ACKABLE_MASK) 39 40#define GQUIC_FRAME_RETRANSMITTABLE_MASK ( \ 41 (1 << QUIC_FRAME_STREAM) \ 42 | (1 << QUIC_FRAME_RST_STREAM) \ 43 | (1 << QUIC_FRAME_GOAWAY) \ 44 | (1 << QUIC_FRAME_WINDOW_UPDATE) \ 45 | (1 << QUIC_FRAME_BLOCKED) \ 46 | (1 << QUIC_FRAME_CONNECTION_CLOSE) \ 47 | (1 << QUIC_FRAME_CRYPTO) \ 48 | (1 << QUIC_FRAME_PING) \ 49) 50 51#define GQUIC_FRAME_RETRANSMITTABLE(frame_type) \ 52 ((1 << (frame_type)) & GQUIC_FRAME_RETRANSMITTABLE_MASK) 53 54#define GQUIC_MAX_PUBHDR_SZ (1 /* Type */ + 8 /* CID */ + 4 /* Version */ \ 55 + 32 /* Nonce */ + 6 /* Packet Number */ ) 56 57#define GQUIC_MIN_PUBHDR_SZ (1 /* Type */ + 1 /* Packet number */) 58 59#define GQUIC_IETF_LONG_HEADER_SIZE (1 /* Type */ + 4 /* Version */ \ 60 + 1 /* DCIL/SCIL */ + 8 /* CID */ + 4 /* Packet number */) 61 62/* XXX Nonce? */ 63#define IQUIC_MAX_PUBHDR_SZ GQUIC_IETF_LONG_HEADER_SIZE 64 65#define IQUIC_MIN_PUBHDR_SZ (1 /* Type */ + 8 /* CID */ \ 66 + 1 /* Packet number */) 67 68#define QUIC_MAX_PUBHDR_SZ (GQUIC_MAX_PUBHDR_SZ > IQUIC_MAX_PUBHDR_SZ \ 69 ? GQUIC_MAX_PUBHDR_SZ : IQUIC_MAX_PUBHDR_SZ) 70 71#define QUIC_MIN_PUBHDR_SZ (GQUIC_MIN_PUBHDR_SZ < IQUIC_MIN_PUBHDR_SZ \ 72 ? GQUIC_MIN_PUBHDR_SZ : IQUIC_MIN_PUBHDR_SZ) 73 74/* 12 bytes of FNV hash or encryption IV */ 75#define GQUIC_PACKET_HASH_SZ 12 76 77/* [draft-hamilton-quic-transport-protocol-01], Section 7 */ 78#define GQUIC_MAX_IPv4_PACKET_SZ 1370 79#define GQUIC_MAX_IPv6_PACKET_SZ 1350 80 81#define GQUIC_MAX_PACKET_SZ (GQUIC_MAX_IPv4_PACKET_SZ > \ 82 GQUIC_MAX_IPv6_PACKET_SZ ? GQUIC_MAX_IPv4_PACKET_SZ : GQUIC_MAX_IPv6_PACKET_SZ) 83 84#define GQUIC_MIN_PACKET_OVERHEAD (GQUIC_PACKET_HASH_SZ + GQUIC_MIN_PUBHDR_SZ) 85 86#define GQUIC_MAX_PAYLOAD_SZ (GQUIC_MAX_PACKET_SZ - GQUIC_MIN_PACKET_OVERHEAD) 87 88#define GQUIC_WUF_SZ 13 /* Type (1) + Stream ID (4) + Offset (8) */ 89#define GQUIC_BLOCKED_FRAME_SZ 5 /* Type (1) + Stream ID (4) */ 90#define GQUIC_RST_STREAM_SZ 17 /* Type (1) + Stream ID (4) + Offset (8) + 91 Error code (4) */ 92#define GQUIC_GOAWAY_FRAME_SZ 11 /* Type (1) + Error code (4) + Stream ID (4) + 93 Reason phrase length (2) */ 94 95#define gquic_packno_bits2len(b) (((b) << 1) + !(b)) 96 97lsquic_packno_t 98lsquic_restore_packno (lsquic_packno_t cur_packno, 99 unsigned packet_len, 100 lsquic_packno_t max_packno); 101 102#endif 103