lsquic_trans_params.h revision 10c41073
1/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc.  See LICENSE. */
2/*
3 * lsquic_trans_params.h -- Transport parameters types and functions.
4 */
5
6#ifndef LSQUIC_TRANS_PARAMS_H
7#define LSQUIC_TRANS_PARAMS_H 1
8
9/* [draft-ietf-quic-transport-17], Section 18 */
10enum transport_param_id
11{
12    TPI_ORIGINAL_CONNECTION_ID            =  0,
13    TPI_IDLE_TIMEOUT                      =  1,
14    TPI_STATELESS_RESET_TOKEN             =  2,
15    TPI_MAX_PACKET_SIZE                   =  3,
16    TPI_INIT_MAX_DATA                     =  4,
17    TPI_INIT_MAX_STREAM_DATA_BIDI_LOCAL   =  5,
18    TPI_INIT_MAX_STREAM_DATA_BIDI_REMOTE  =  6,
19    TPI_INIT_MAX_STREAM_DATA_UNI          =  7,
20    TPI_INIT_MAX_STREAMS_BIDI             =  8,
21    TPI_INIT_MAX_STREAMS_UNI              =  9,
22    TPI_ACK_DELAY_EXPONENT                =  10,
23    TPI_MAX_ACK_DELAY                     =  11,
24    TPI_DISABLE_ACTIVE_MIGRATION          =  12,
25    TPI_PREFERRED_ADDRESS                 =  13,
26    TPI_ACTIVE_CONNECTION_ID_LIMIT        =  14,
27#define MAX_TPI TPI_ACTIVE_CONNECTION_ID_LIMIT
28};
29
30#define NUMERIC_TRANS_PARAMS (\
31     (1 << TPI_MAX_PACKET_SIZE) \
32    |(1 << TPI_INIT_MAX_STREAMS_UNI) \
33    |(1 << TPI_INIT_MAX_STREAMS_UNI) \
34    |(1 << TPI_INIT_MAX_STREAMS_BIDI) \
35    |(1 << TPI_INIT_MAX_DATA) \
36    |(1 << TPI_INIT_MAX_STREAM_DATA_BIDI_LOCAL) \
37    |(1 << TPI_INIT_MAX_STREAM_DATA_BIDI_REMOTE) \
38    |(1 << TPI_INIT_MAX_STREAM_DATA_UNI) \
39    |(1 << TPI_IDLE_TIMEOUT) \
40    |(1 << TPI_MAX_ACK_DELAY) \
41    |(1 << TPI_ACK_DELAY_EXPONENT) \
42    |(1 << TPI_ACTIVE_CONNECTION_ID_LIMIT) \
43    )
44
45#define IQUIC_MAX_SUPP_VERS ((2<<7) - 4)/sizeof(uint32_t)
46
47enum trapa_flags
48{
49    TRAPA_RESET_TOKEN   = 1 << 0,   /* Reset token is set */
50    TRAPA_SERVER        = 1 << 1,   /* Server transport parameters */
51    TRAPA_PREFADDR_IPv4 = 1 << 2,   /* Preferred IPv4 address is set */
52    TRAPA_PREFADDR_IPv6 = 1 << 3,   /* Preferred IPv6 address is set */
53    TRAPA_ORIGINAL_CID  = 1 << 4,   /* Original CID is set */
54#if LSQUIC_TEST_QUANTUM_READINESS
55#define QUANTUM_READY_SZ 1200
56    /* https://github.com/quicwg/base-drafts/wiki/Quantum-Readiness-test */
57#define TPI_QUANTUM_READINESS 3127
58    TRAPA_QUANTUM_READY = 1 << 5,   /* Include "Quantum Readiness" TP */
59#endif
60#define TPI_QL_BITS 0x1057     /* 1057 is 133t for "lost" */
61    TRAPA_QL_BITS       = 1 << 6,   /* tp_loss_bits contains valid value */
62    TRAPA_QL_BITS_OLD   = 1 << 7,   /* Send old-school boolean loss_bits TP.
63                                     * Not set on decoded transport parameters.
64                                     */
65};
66
67struct transport_params
68{
69    enum trapa_flags        tp_flags;
70
71    union {
72        struct {
73            uint64_t init_max_stream_data_bidi_local;
74            uint64_t init_max_stream_data_bidi_remote;
75            uint64_t init_max_stream_data_uni;
76            uint64_t init_max_data;
77            uint64_t idle_timeout;
78            uint64_t init_max_streams_bidi;
79            uint64_t init_max_streams_uni;
80            uint64_t max_packet_size;
81            uint64_t ack_delay_exponent;
82            uint64_t max_ack_delay;
83            uint64_t active_connection_id_limit;
84        }               s;
85        uint64_t        a[11];
86    }           tp_numerics_u;
87#define tp_init_max_stream_data_bidi_local tp_numerics_u.s.init_max_stream_data_bidi_local
88#define tp_init_max_stream_data_bidi_remote tp_numerics_u.s.init_max_stream_data_bidi_remote
89#define tp_init_max_stream_data_uni tp_numerics_u.s.init_max_stream_data_uni
90#define tp_init_max_data tp_numerics_u.s.init_max_data
91#define tp_idle_timeout tp_numerics_u.s.idle_timeout
92#define tp_init_max_streams_bidi tp_numerics_u.s.init_max_streams_bidi
93#define tp_init_max_streams_uni tp_numerics_u.s.init_max_streams_uni
94#define tp_max_packet_size tp_numerics_u.s.max_packet_size
95#define tp_ack_delay_exponent tp_numerics_u.s.ack_delay_exponent
96#define tp_max_ack_delay tp_numerics_u.s.max_ack_delay
97#define tp_active_connection_id_limit tp_numerics_u.s.active_connection_id_limit
98
99    unsigned char   tp_loss_bits;   /* Valid values 0, 1.  Set if TRAPA_QL_BITS is set. */
100    signed char tp_disable_active_migration;
101    uint8_t     tp_stateless_reset_token[IQUIC_SRESET_TOKEN_SZ];
102    struct {
103        uint8_t         ipv4_addr[4];
104        uint16_t        ipv4_port;
105        uint8_t         ipv6_addr[16];
106        uint16_t        ipv6_port;
107        lsquic_cid_t    cid;
108        uint8_t         srst[IQUIC_SRESET_TOKEN_SZ];
109    }           tp_preferred_address;
110    lsquic_cid_t    tp_original_cid;
111};
112
113#define TP_DEF_MAX_PACKET_SIZE 65527
114#define TP_DEF_ACK_DELAY_EXP 3
115#define TP_DEF_INIT_MAX_STREAMS_UNI 0
116#define TP_DEF_INIT_MAX_STREAMS_BIDI 0
117#define TP_DEF_INIT_MAX_DATA 0
118#define TP_DEF_DISABLE_ACTIVE_MIGRATION 0
119#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL 0
120#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE 0
121#define TP_DEF_INIT_MAX_STREAM_DATA_UNI 0
122#define TP_DEF_IDLE_TIMEOUT 0
123#define TP_DEF_MAX_ACK_DELAY 25
124#define TP_DEF_ACTIVE_CONNECTION_ID_LIMIT 0
125
126/* [draft-ietf-quic-transport-18], Section 18.1 */
127#define TP_MAX_MAX_ACK_DELAY ((1u << 14) - 1)
128
129#define TP_DEFAULT_VALUES                                                             \
130    .tp_active_connection_id_limit        =  TP_DEF_ACTIVE_CONNECTION_ID_LIMIT,       \
131    .tp_idle_timeout                      =  TP_DEF_IDLE_TIMEOUT,                     \
132    .tp_max_ack_delay                     =  TP_DEF_MAX_ACK_DELAY,                    \
133    .tp_max_packet_size                   =  TP_DEF_MAX_PACKET_SIZE,                  \
134    .tp_ack_delay_exponent                =  TP_DEF_ACK_DELAY_EXP,                    \
135    .tp_init_max_streams_bidi             =  TP_DEF_INIT_MAX_STREAMS_BIDI,            \
136    .tp_init_max_streams_uni              =  TP_DEF_INIT_MAX_STREAMS_UNI,             \
137    .tp_init_max_data                     =  TP_DEF_INIT_MAX_DATA,                    \
138    .tp_disable_active_migration          =  TP_DEF_DISABLE_ACTIVE_MIGRATION,         \
139    .tp_init_max_stream_data_bidi_local   =  TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL,  \
140    .tp_init_max_stream_data_bidi_remote  =  TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE, \
141    .tp_init_max_stream_data_uni          =  TP_DEF_INIT_MAX_STREAM_DATA_UNI
142
143#define TP_INITIALIZER() (struct transport_params) { TP_DEFAULT_VALUES }
144
145int
146lsquic_tp_encode (const struct transport_params *,
147                  unsigned char *buf, size_t bufsz);
148
149int
150lsquic_tp_decode (const unsigned char *buf, size_t bufsz,
151    /* This argument specifies whose transport parameters we are parsing.  If
152     * true, we are parsing parameters sent by the server; if false, we are
153     * parsing parameteres sent by the client.
154     */
155                  int is_server,
156                  struct transport_params *);
157
158void
159lsquic_tp_to_str (const struct transport_params *params, char *buf, size_t sz);
160
161#endif
162