lsquic_packet_gquic.h revision a5fa05f9
17d09751dSDmitri Tikhonov/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc.  See LICENSE. */
25392f7a3SLiteSpeed Tech#ifndef LSQUIC_PACKET_GQUIC_H
35392f7a3SLiteSpeed Tech#define LSQUIC_PACKET_GQUIC_H 1
45392f7a3SLiteSpeed Tech
55392f7a3SLiteSpeed Tech#include <stdint.h>
65392f7a3SLiteSpeed Tech
75392f7a3SLiteSpeed Tech#include "lsquic_int_types.h"
85392f7a3SLiteSpeed Tech
95392f7a3SLiteSpeed Techenum PACKET_PUBLIC_FLAGS
105392f7a3SLiteSpeed Tech{
115392f7a3SLiteSpeed Tech  PACKET_PUBLIC_FLAGS_VERSION = 1,
125392f7a3SLiteSpeed Tech  PACKET_PUBLIC_FLAGS_RST = 2,
135392f7a3SLiteSpeed Tech  PACKET_PUBLIC_FLAGS_NONCE = 4,
145392f7a3SLiteSpeed Tech  PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID = 8,
155392f7a3SLiteSpeed Tech  PACKET_PUBLIC_FLAGS_MULTIPATH = 1 << 6,
165392f7a3SLiteSpeed Tech  PACKET_PUBLIC_FLAGS_TWO_OR_MORE_BYTES = 1 << 7,
175392f7a3SLiteSpeed Tech};
185392f7a3SLiteSpeed Tech
195392f7a3SLiteSpeed Tech#define GQUIC_FRAME_REGEN_MASK ((1 << QUIC_FRAME_ACK)                \
205392f7a3SLiteSpeed Tech  | (1 << QUIC_FRAME_PATH_CHALLENGE) | (1 << QUIC_FRAME_PATH_RESPONSE) \
21afe3d363SDmitri Tikhonov  | (1 << QUIC_FRAME_STOP_WAITING) | (1 << QUIC_FRAME_TIMESTAMP))
225392f7a3SLiteSpeed Tech
235392f7a3SLiteSpeed Tech#define GQUIC_FRAME_REGENERATE(frame_type) ((1 << (frame_type)) & GQUIC_FRAME_REGEN_MASK)
245392f7a3SLiteSpeed Tech
255392f7a3SLiteSpeed Tech#define GQUIC_FRAME_ACKABLE_MASK (                               \
265392f7a3SLiteSpeed Tech    (1 << QUIC_FRAME_STREAM)                                \
275392f7a3SLiteSpeed Tech  | (1 << QUIC_FRAME_RST_STREAM)                            \
285392f7a3SLiteSpeed Tech  | (1 << QUIC_FRAME_GOAWAY)                                \
295392f7a3SLiteSpeed Tech  | (1 << QUIC_FRAME_WINDOW_UPDATE)                         \
305392f7a3SLiteSpeed Tech  | (1 << QUIC_FRAME_PING)                                  \
315392f7a3SLiteSpeed Tech  | (1 << QUIC_FRAME_BLOCKED)                               \
325392f7a3SLiteSpeed Tech  | (1 << QUIC_FRAME_CRYPTO)                                \
335392f7a3SLiteSpeed Tech)
345392f7a3SLiteSpeed Tech
355392f7a3SLiteSpeed Tech#define GQUIC_FRAME_ACKABLE(frame_type) ((1 << (frame_type)) & GQUIC_FRAME_ACKABLE_MASK)
365392f7a3SLiteSpeed Tech
375392f7a3SLiteSpeed Tech#define GQUIC_FRAME_RETRANSMITTABLE_MASK (                       \
385392f7a3SLiteSpeed Tech    (1 << QUIC_FRAME_STREAM)                                \
395392f7a3SLiteSpeed Tech  | (1 << QUIC_FRAME_RST_STREAM)                            \
405392f7a3SLiteSpeed Tech  | (1 << QUIC_FRAME_GOAWAY)                                \
415392f7a3SLiteSpeed Tech  | (1 << QUIC_FRAME_WINDOW_UPDATE)                         \
425392f7a3SLiteSpeed Tech  | (1 << QUIC_FRAME_BLOCKED)                               \
435392f7a3SLiteSpeed Tech  | (1 << QUIC_FRAME_CONNECTION_CLOSE)                      \
445392f7a3SLiteSpeed Tech  | (1 << QUIC_FRAME_CRYPTO)                                \
455392f7a3SLiteSpeed Tech  | (1 << QUIC_FRAME_PING)                                  \
465392f7a3SLiteSpeed Tech)
475392f7a3SLiteSpeed Tech
485392f7a3SLiteSpeed Tech#define GQUIC_FRAME_RETRANSMITTABLE(frame_type) \
495392f7a3SLiteSpeed Tech                        ((1 << (frame_type)) & GQUIC_FRAME_RETRANSMITTABLE_MASK)
505392f7a3SLiteSpeed Tech
515392f7a3SLiteSpeed Tech#define GQUIC_MAX_PUBHDR_SZ (1 /* Type */ + 8 /* CID */ + 4 /* Version */ \
525392f7a3SLiteSpeed Tech                            + 32 /* Nonce */ + 6 /* Packet Number */ )
535392f7a3SLiteSpeed Tech
545392f7a3SLiteSpeed Tech#define GQUIC_MIN_PUBHDR_SZ (1 /* Type */ + 1 /* Packet number */)
555392f7a3SLiteSpeed Tech
565392f7a3SLiteSpeed Tech#define GQUIC_IETF_LONG_HEADER_SIZE (1 /* Type */ + 4 /* Version */ \
575392f7a3SLiteSpeed Tech                + 1 /* DCIL/SCIL */ + 8 /* CID */ + 4 /* Packet number */)
585392f7a3SLiteSpeed Tech
595392f7a3SLiteSpeed Tech/* XXX Nonce? */
605392f7a3SLiteSpeed Tech#define IQUIC_MAX_PUBHDR_SZ GQUIC_IETF_LONG_HEADER_SIZE
615392f7a3SLiteSpeed Tech
625392f7a3SLiteSpeed Tech#define IQUIC_MIN_PUBHDR_SZ (1 /* Type */ + 8 /* CID */ \
635392f7a3SLiteSpeed Tech                                                + 1 /* Packet number */)
645392f7a3SLiteSpeed Tech
655392f7a3SLiteSpeed Tech#define QUIC_MAX_PUBHDR_SZ (GQUIC_MAX_PUBHDR_SZ > IQUIC_MAX_PUBHDR_SZ \
665392f7a3SLiteSpeed Tech                                ? GQUIC_MAX_PUBHDR_SZ : IQUIC_MAX_PUBHDR_SZ)
675392f7a3SLiteSpeed Tech
685392f7a3SLiteSpeed Tech#define QUIC_MIN_PUBHDR_SZ (GQUIC_MIN_PUBHDR_SZ < IQUIC_MIN_PUBHDR_SZ \
695392f7a3SLiteSpeed Tech                                ? GQUIC_MIN_PUBHDR_SZ : IQUIC_MIN_PUBHDR_SZ)
705392f7a3SLiteSpeed Tech
715392f7a3SLiteSpeed Tech/* 12 bytes of FNV hash or encryption IV */
725392f7a3SLiteSpeed Tech#define GQUIC_PACKET_HASH_SZ 12
735392f7a3SLiteSpeed Tech
745392f7a3SLiteSpeed Tech/* [draft-hamilton-quic-transport-protocol-01], Section 7 */
755392f7a3SLiteSpeed Tech#define GQUIC_MAX_IPv4_PACKET_SZ 1370
765392f7a3SLiteSpeed Tech#define GQUIC_MAX_IPv6_PACKET_SZ 1350
775392f7a3SLiteSpeed Tech
785392f7a3SLiteSpeed Tech#define GQUIC_MAX_PACKET_SZ (GQUIC_MAX_IPv4_PACKET_SZ > \
795392f7a3SLiteSpeed Tech    GQUIC_MAX_IPv6_PACKET_SZ ? GQUIC_MAX_IPv4_PACKET_SZ : GQUIC_MAX_IPv6_PACKET_SZ)
805392f7a3SLiteSpeed Tech
815392f7a3SLiteSpeed Tech#define GQUIC_MIN_PACKET_OVERHEAD (GQUIC_PACKET_HASH_SZ + GQUIC_MIN_PUBHDR_SZ)
825392f7a3SLiteSpeed Tech
835392f7a3SLiteSpeed Tech#define GQUIC_MAX_PAYLOAD_SZ (GQUIC_MAX_PACKET_SZ - GQUIC_MIN_PACKET_OVERHEAD)
845392f7a3SLiteSpeed Tech
855392f7a3SLiteSpeed Tech#define GQUIC_WUF_SZ 13  /* Type (1) + Stream ID (4) + Offset (8) */
865392f7a3SLiteSpeed Tech#define GQUIC_BLOCKED_FRAME_SZ 5  /* Type (1) + Stream ID (4) */
875392f7a3SLiteSpeed Tech#define GQUIC_RST_STREAM_SZ 17    /* Type (1) + Stream ID (4) + Offset (8) +
885392f7a3SLiteSpeed Tech                                                            Error code (4) */
895392f7a3SLiteSpeed Tech#define GQUIC_GOAWAY_FRAME_SZ 11  /* Type (1) + Error code (4) + Stream ID (4) +
905392f7a3SLiteSpeed Tech                                                Reason phrase length (2) */
915392f7a3SLiteSpeed Tech
925392f7a3SLiteSpeed Tech#define gquic_packno_bits2len(b) (((b) << 1) + !(b))
935392f7a3SLiteSpeed Tech
945392f7a3SLiteSpeed Techlsquic_packno_t
95a5fa05f9SDmitri Tikhonovlsquic_restore_packno (lsquic_packno_t cur_packno,
965392f7a3SLiteSpeed Tech                unsigned packet_len,
975392f7a3SLiteSpeed Tech                lsquic_packno_t max_packno);
985392f7a3SLiteSpeed Tech
995392f7a3SLiteSpeed Tech#endif
100