lsquic_packet_common.h revision 50aadb33
1/* Copyright (c) 2017 LiteSpeed Technologies Inc. See LICENSE. */ 2#ifndef LSQUIC_PACKET_COMMON_H 3#define LSQUIC_PACKET_COMMON_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 19enum QUIC_FRAME_TYPE 20{ 21 QUIC_FRAME_INVALID, 22 23 /*Special*/ 24 QUIC_FRAME_STREAM, 25 QUIC_FRAME_ACK, 26 27 /*Regular*/ 28 QUIC_FRAME_PADDING, 29 QUIC_FRAME_RST_STREAM, 30 QUIC_FRAME_CONNECTION_CLOSE, 31 QUIC_FRAME_GOAWAY, 32 QUIC_FRAME_WINDOW_UPDATE, 33 QUIC_FRAME_BLOCKED, 34 QUIC_FRAME_STOP_WAITING, 35 QUIC_FRAME_PING, 36 N_QUIC_FRAMES 37}; 38 39extern const size_t lsquic_frame_types_str_sz; 40 41const char * 42lsquic_frame_types_to_str (char *buf, size_t bufsz, short frame_types); 43 44#define QFRAME_REGEN_MASK ((1 << QUIC_FRAME_ACK) \ 45 | (1 << QUIC_FRAME_STOP_WAITING)) 46 47#define QFRAME_REGENERATE(frame_type) ((1 << (frame_type)) & QFRAME_REGEN_MASK) 48 49#define QFRAME_ACKABLE_MASK ( \ 50 (1 << QUIC_FRAME_STREAM) \ 51 | (1 << QUIC_FRAME_RST_STREAM) \ 52 | (1 << QUIC_FRAME_GOAWAY) \ 53 | (1 << QUIC_FRAME_WINDOW_UPDATE) \ 54 | (1 << QUIC_FRAME_PING) \ 55 | (1 << QUIC_FRAME_BLOCKED) \ 56) 57 58#define QFRAME_ACKABLE(frame_type) ((1 << (frame_type)) & QFRAME_ACKABLE_MASK) 59 60#define QFRAME_RETRANSMITTABLE_MASK ( \ 61 (1 << QUIC_FRAME_STREAM) \ 62 | (1 << QUIC_FRAME_RST_STREAM) \ 63 | (1 << QUIC_FRAME_GOAWAY) \ 64 | (1 << QUIC_FRAME_WINDOW_UPDATE) \ 65 | (1 << QUIC_FRAME_BLOCKED) \ 66 | (1 << QUIC_FRAME_CONNECTION_CLOSE) \ 67) 68 69#define QFRAME_RETRANSMITTABLE(frame_type) \ 70 ((1 << (frame_type)) & QFRAME_RETRANSMITTABLE_MASK) 71 72#define QUIC_MAX_PUBHDR_SZ (1 /* Type */ + 8 /* CID */ + 4 /* Version */ \ 73 + 32 /* Nonce */ + 6 /* Packet Number */ ) 74 75#define QUIC_MIN_PUBHDR_SZ (1 /* Type */ + 1 /* Packet number */) 76 77/* 12 bytes of FNV hash or encryption IV */ 78#define QUIC_PACKET_HASH_SZ 12 79 80/* [draft-hamilton-quic-transport-protocol-01], Section 7 */ 81#define QUIC_MAX_IPv4_PACKET_SZ 1370 82#define QUIC_MAX_IPv6_PACKET_SZ 1350 83 84#define QUIC_MAX_PACKET_SZ (QUIC_MAX_IPv4_PACKET_SZ > \ 85 QUIC_MAX_IPv6_PACKET_SZ ? QUIC_MAX_IPv4_PACKET_SZ : QUIC_MAX_IPv6_PACKET_SZ) 86 87#define QUIC_MIN_PACKET_OVERHEAD (QUIC_PACKET_HASH_SZ + QUIC_MIN_PUBHDR_SZ) 88 89#define QUIC_MAX_PAYLOAD_SZ (QUIC_MAX_PACKET_SZ - QUIC_MIN_PACKET_OVERHEAD) 90 91#define QUIC_WUF_SZ 13 /* Type (1) + Stream ID (4) + Offset (8) */ 92#define QUIC_BLOCKED_FRAME_SZ 5 /* Type (1) + Stream ID (4) */ 93#define QUIC_RST_STREAM_SZ 17 /* Type (1) + Stream ID (4) + Offset (8) + 94 Error code (4) */ 95#define QUIC_GOAWAY_FRAME_SZ 11 /* Type (1) + Error code (4) + Stream ID (4) + 96 Reason phrase length (2) */ 97 98/* Bitmask to be used as bits 4 and 5 (0x30) in common header's flag field: */ 99enum lsquic_packno_bits 100{ 101 PACKNO_LEN_1 = 0, 102 PACKNO_LEN_2 = 1, 103 PACKNO_LEN_4 = 2, 104 PACKNO_LEN_6 = 3, 105}; 106 107enum lsquic_packno_bits 108calc_packno_bits (lsquic_packno_t packno, lsquic_packno_t least_unacked, 109 uint64_t n_in_flight); 110 111#define packno_bits2len(b) (((b) << 1) + !(b)) 112 113lsquic_packno_t 114restore_packno (lsquic_packno_t cur_packno, 115 enum lsquic_packno_bits cur_packno_bits, 116 lsquic_packno_t max_packno); 117 118#endif 119