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