lsquic_packet_gquic.h revision 06b2a236
1/* Copyright (c) 2017 - 2021 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#define GQUIC_FRAME_ACKABLE_MASK ( \ 20 (1 << QUIC_FRAME_STREAM) \ 21 | (1 << QUIC_FRAME_RST_STREAM) \ 22 | (1 << QUIC_FRAME_GOAWAY) \ 23 | (1 << QUIC_FRAME_WINDOW_UPDATE) \ 24 | (1 << QUIC_FRAME_PING) \ 25 | (1 << QUIC_FRAME_BLOCKED) \ 26 | (1 << QUIC_FRAME_CRYPTO) \ 27) 28 29#define GQUIC_FRAME_ACKABLE(frame_type) ((1 << (frame_type)) & GQUIC_FRAME_ACKABLE_MASK) 30 31#define GQUIC_FRAME_RETRANSMITTABLE_MASK ( \ 32 (1 << QUIC_FRAME_STREAM) \ 33 | (1 << QUIC_FRAME_RST_STREAM) \ 34 | (1 << QUIC_FRAME_GOAWAY) \ 35 | (1 << QUIC_FRAME_WINDOW_UPDATE) \ 36 | (1 << QUIC_FRAME_BLOCKED) \ 37 | (1 << QUIC_FRAME_CONNECTION_CLOSE) \ 38 | (1 << QUIC_FRAME_CRYPTO) \ 39 | (1 << QUIC_FRAME_PING) \ 40) 41 42#define GQUIC_FRAME_RETRANSMITTABLE(frame_type) \ 43 ((1 << (frame_type)) & GQUIC_FRAME_RETRANSMITTABLE_MASK) 44 45#define GQUIC_MAX_PUBHDR_SZ (1 /* Type */ + 8 /* CID */ + 4 /* Version */ \ 46 + 32 /* Nonce */ + 6 /* Packet Number */ ) 47 48#define GQUIC_MIN_PUBHDR_SZ (1 /* Type */ + 1 /* Packet number */) 49 50#define GQUIC_IETF_LONG_HEADER_SIZE (1 /* Type */ + 4 /* Version */ \ 51 + 1 /* DCIL/SCIL */ + 8 /* CID */ + 4 /* Packet number */) 52 53/* XXX Nonce? */ 54#define IQUIC_MAX_PUBHDR_SZ GQUIC_IETF_LONG_HEADER_SIZE 55 56#define IQUIC_MIN_PUBHDR_SZ (1 /* Type */ + 8 /* CID */ \ 57 + 1 /* Packet number */) 58 59#define QUIC_MAX_PUBHDR_SZ (GQUIC_MAX_PUBHDR_SZ > IQUIC_MAX_PUBHDR_SZ \ 60 ? GQUIC_MAX_PUBHDR_SZ : IQUIC_MAX_PUBHDR_SZ) 61 62#define QUIC_MIN_PUBHDR_SZ (GQUIC_MIN_PUBHDR_SZ < IQUIC_MIN_PUBHDR_SZ \ 63 ? GQUIC_MIN_PUBHDR_SZ : IQUIC_MIN_PUBHDR_SZ) 64 65/* 12 bytes of FNV hash or encryption IV */ 66#define GQUIC_PACKET_HASH_SZ 12 67 68/* [draft-hamilton-quic-transport-protocol-01], Section 7 */ 69#define GQUIC_MAX_IPv4_PACKET_SZ 1370 70#define GQUIC_MAX_IPv6_PACKET_SZ 1350 71 72#define GQUIC_MAX_PACKET_SZ (GQUIC_MAX_IPv4_PACKET_SZ > \ 73 GQUIC_MAX_IPv6_PACKET_SZ ? GQUIC_MAX_IPv4_PACKET_SZ : GQUIC_MAX_IPv6_PACKET_SZ) 74 75#define GQUIC_MIN_PACKET_OVERHEAD (GQUIC_PACKET_HASH_SZ + GQUIC_MIN_PUBHDR_SZ) 76 77#define GQUIC_MAX_PAYLOAD_SZ (GQUIC_MAX_PACKET_SZ - GQUIC_MIN_PACKET_OVERHEAD) 78 79#define GQUIC_WUF_SZ 13 /* Type (1) + Stream ID (4) + Offset (8) */ 80#define GQUIC_BLOCKED_FRAME_SZ 5 /* Type (1) + Stream ID (4) */ 81#define GQUIC_RST_STREAM_SZ 17 /* Type (1) + Stream ID (4) + Offset (8) + 82 Error code (4) */ 83#define GQUIC_GOAWAY_FRAME_SZ 11 /* Type (1) + Error code (4) + Stream ID (4) + 84 Reason phrase length (2) */ 85 86#define gquic_packno_bits2len(b) (((b) << 1) + !(b)) 87 88lsquic_packno_t 89lsquic_restore_packno (lsquic_packno_t cur_packno, 90 unsigned packet_len, 91 lsquic_packno_t max_packno); 92 93#endif 94