lsquic_trans_params.h revision afe3d363
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/* Transport parameters are grouped by the type of their values: numeric,
10 * empty, and custom.
11 *
12 * The enum values are arbitrary.  The literal transport parameter ID
13 * *values* (e.g. 0x1057 for loss bits) are not exposed by the API.
14 */
15enum transport_param_id
16{
17    /*
18     * Numeric transport parameters that have default values:
19     */
20    TPI_MAX_IDLE_TIMEOUT,
21    TPI_MAX_PACKET_SIZE,
22    TPI_INIT_MAX_DATA,
23    TPI_INIT_MAX_STREAM_DATA_BIDI_LOCAL,
24    TPI_INIT_MAX_STREAM_DATA_BIDI_REMOTE,
25    TPI_INIT_MAX_STREAM_DATA_UNI,
26    TPI_INIT_MAX_STREAMS_BIDI,
27    TPI_INIT_MAX_STREAMS_UNI,
28    TPI_ACK_DELAY_EXPONENT,
29    TPI_MAX_ACK_DELAY,
30    TPI_ACTIVE_CONNECTION_ID_LIMIT,         MAX_NUM_WITH_DEF_TPI = TPI_ACTIVE_CONNECTION_ID_LIMIT,
31
32    /*
33     * Numeric transport parameters without default values:
34     */
35    TPI_MIN_ACK_DELAY,
36    TPI_LOSS_BITS,                          MAX_NUMERIC_TPI = TPI_LOSS_BITS,
37
38    /*
39     * Empty transport parameters:
40     */
41    TPI_TIMESTAMPS,
42    TPI_DISABLE_ACTIVE_MIGRATION,           MAX_EMPTY_TPI = TPI_DISABLE_ACTIVE_MIGRATION,
43
44    /*
45     * Custom handlers:
46     */
47    TPI_PREFERRED_ADDRESS,
48    TPI_ORIGINAL_CONNECTION_ID,
49#if LSQUIC_TEST_QUANTUM_READINESS
50    /* https://github.com/quicwg/base-drafts/wiki/Quantum-Readiness-test */
51#define QUANTUM_READY_SZ 1200
52    TPI_QUANTUM_READINESS,
53#endif
54    TPI_STATELESS_RESET_TOKEN,              LAST_TPI = TPI_STATELESS_RESET_TOKEN
55};
56
57
58struct transport_params
59{
60    /* Which transport parameters values are set: */
61    unsigned                tp_set;
62
63    /* Which transport parameters were present (set by the decoder): */
64    unsigned                tp_decoded;
65
66    uint64_t                tp_numerics[MAX_NUMERIC_TPI + 1];
67
68#define tp_init_max_stream_data_bidi_local  tp_numerics[TPI_INIT_MAX_STREAM_DATA_BIDI_LOCAL]
69#define tp_init_max_stream_data_bidi_remote tp_numerics[TPI_INIT_MAX_STREAM_DATA_BIDI_REMOTE]
70#define tp_init_max_stream_data_uni         tp_numerics[TPI_INIT_MAX_STREAM_DATA_UNI]
71#define tp_init_max_data                    tp_numerics[TPI_INIT_MAX_DATA]
72#define tp_max_idle_timeout                 tp_numerics[TPI_MAX_IDLE_TIMEOUT]
73#define tp_init_max_streams_bidi            tp_numerics[TPI_INIT_MAX_STREAMS_BIDI]
74#define tp_init_max_streams_uni             tp_numerics[TPI_INIT_MAX_STREAMS_UNI]
75#define tp_max_packet_size                  tp_numerics[TPI_MAX_PACKET_SIZE]
76#define tp_ack_delay_exponent               tp_numerics[TPI_ACK_DELAY_EXPONENT]
77#define tp_max_ack_delay                    tp_numerics[TPI_MAX_ACK_DELAY]
78#define tp_active_connection_id_limit       tp_numerics[TPI_ACTIVE_CONNECTION_ID_LIMIT]
79#define tp_loss_bits                        tp_numerics[TPI_LOSS_BITS]
80
81    uint8_t     tp_stateless_reset_token[IQUIC_SRESET_TOKEN_SZ];
82    struct {
83        uint8_t         ipv4_addr[4];
84        uint16_t        ipv4_port;
85        uint8_t         ipv6_addr[16];
86        uint16_t        ipv6_port;
87        lsquic_cid_t    cid;
88        uint8_t         srst[IQUIC_SRESET_TOKEN_SZ];
89    }           tp_preferred_address;
90    lsquic_cid_t    tp_original_cid;
91};
92
93#define TP_DEF_MAX_PACKET_SIZE 65527
94#define TP_DEF_ACK_DELAY_EXP 3
95#define TP_DEF_INIT_MAX_STREAMS_UNI 0
96#define TP_DEF_INIT_MAX_STREAMS_BIDI 0
97#define TP_DEF_INIT_MAX_DATA 0
98#define TP_DEF_DISABLE_ACTIVE_MIGRATION 0
99#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL 0
100#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE 0
101#define TP_DEF_INIT_MAX_STREAM_DATA_UNI 0
102#define TP_DEF_MAX_IDLE_TIMEOUT 0
103#define TP_DEF_MAX_ACK_DELAY 25
104#define TP_DEF_ACTIVE_CONNECTION_ID_LIMIT 2
105
106/* [draft-ietf-quic-transport-18], Section 18.1 */
107#define TP_MAX_MAX_ACK_DELAY ((1u << 14) - 1)
108
109#define TP_DEFAULT_VALUES                                                             \
110    .tp_set = ((1 << (MAX_NUM_WITH_DEF_TPI + 1)) - 1),                                \
111    .tp_active_connection_id_limit        =  TP_DEF_ACTIVE_CONNECTION_ID_LIMIT,       \
112    .tp_max_idle_timeout                  =  TP_DEF_MAX_IDLE_TIMEOUT,                 \
113    .tp_max_ack_delay                     =  TP_DEF_MAX_ACK_DELAY,                    \
114    .tp_max_packet_size                   =  TP_DEF_MAX_PACKET_SIZE,                  \
115    .tp_ack_delay_exponent                =  TP_DEF_ACK_DELAY_EXP,                    \
116    .tp_init_max_streams_bidi             =  TP_DEF_INIT_MAX_STREAMS_BIDI,            \
117    .tp_init_max_streams_uni              =  TP_DEF_INIT_MAX_STREAMS_UNI,             \
118    .tp_init_max_data                     =  TP_DEF_INIT_MAX_DATA,                    \
119    .tp_init_max_stream_data_bidi_local   =  TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL,  \
120    .tp_init_max_stream_data_bidi_remote  =  TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE, \
121    .tp_init_max_stream_data_uni          =  TP_DEF_INIT_MAX_STREAM_DATA_UNI
122
123#define TP_INITIALIZER() (struct transport_params) { TP_DEFAULT_VALUES }
124
125int
126lsquic_tp_encode (const struct transport_params *, int is_server,
127                  unsigned char *buf, size_t bufsz);
128
129int
130lsquic_tp_decode (const unsigned char *buf, size_t bufsz,
131    /* This argument specifies whose transport parameters we are parsing.  If
132     * true, we are parsing parameters sent by the server; if false, we are
133     * parsing parameteres sent by the client.
134     */
135                  int is_server,
136                  struct transport_params *);
137
138int
139lsquic_tp_encode_id25 (const struct transport_params *, int is_server,
140                  unsigned char *buf, size_t bufsz);
141
142int
143lsquic_tp_decode_id25 (const unsigned char *buf, size_t bufsz,
144                  int is_server, struct transport_params *);
145
146void
147lsquic_tp_to_str (const struct transport_params *params, char *buf, size_t sz);
148
149int
150lsquic_tp_has_pref_ipv4 (const struct transport_params *);
151
152int
153lsquic_tp_has_pref_ipv6 (const struct transport_params *);
154
155#endif
156