lsquic_trans_params.h revision 49f1f4f6
17d09751dSDmitri Tikhonov/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc.  See LICENSE. */
25392f7a3SLiteSpeed Tech/*
35392f7a3SLiteSpeed Tech * lsquic_trans_params.h -- Transport parameters types and functions.
45392f7a3SLiteSpeed Tech */
55392f7a3SLiteSpeed Tech
65392f7a3SLiteSpeed Tech#ifndef LSQUIC_TRANS_PARAMS_H
75392f7a3SLiteSpeed Tech#define LSQUIC_TRANS_PARAMS_H 1
85392f7a3SLiteSpeed Tech
91bdb91d1SDmitri Tikhonov/* Transport parameters are grouped by the type of their values: numeric,
101bdb91d1SDmitri Tikhonov * empty, and custom.
111bdb91d1SDmitri Tikhonov *
121bdb91d1SDmitri Tikhonov * The enum values are arbitrary.  The literal transport parameter ID
131bdb91d1SDmitri Tikhonov * *values* (e.g. 0x1057 for loss bits) are not exposed by the API.
141bdb91d1SDmitri Tikhonov */
155392f7a3SLiteSpeed Techenum transport_param_id
165392f7a3SLiteSpeed Tech{
171bdb91d1SDmitri Tikhonov    /*
181bdb91d1SDmitri Tikhonov     * Numeric transport parameters that have default values:
191bdb91d1SDmitri Tikhonov     */
201bdb91d1SDmitri Tikhonov    TPI_MAX_IDLE_TIMEOUT,
21fb73393fSDmitri Tikhonov    TPI_MAX_UDP_PAYLOAD_SIZE,
221bdb91d1SDmitri Tikhonov    TPI_INIT_MAX_DATA,
231bdb91d1SDmitri Tikhonov    TPI_INIT_MAX_STREAM_DATA_BIDI_LOCAL,
241bdb91d1SDmitri Tikhonov    TPI_INIT_MAX_STREAM_DATA_BIDI_REMOTE,
251bdb91d1SDmitri Tikhonov    TPI_INIT_MAX_STREAM_DATA_UNI,
261bdb91d1SDmitri Tikhonov    TPI_INIT_MAX_STREAMS_BIDI,
271bdb91d1SDmitri Tikhonov    TPI_INIT_MAX_STREAMS_UNI,
281bdb91d1SDmitri Tikhonov    TPI_ACK_DELAY_EXPONENT,
291bdb91d1SDmitri Tikhonov    TPI_MAX_ACK_DELAY,
301bdb91d1SDmitri Tikhonov    TPI_ACTIVE_CONNECTION_ID_LIMIT,         MAX_NUM_WITH_DEF_TPI = TPI_ACTIVE_CONNECTION_ID_LIMIT,
311bdb91d1SDmitri Tikhonov
321bdb91d1SDmitri Tikhonov    /*
331bdb91d1SDmitri Tikhonov     * Numeric transport parameters without default values:
341bdb91d1SDmitri Tikhonov     */
35feca77f5SDmitri Tikhonov    TPI_MIN_ACK_DELAY,
3649f1f4f6SDmitri Tikhonov    TPI_TIMESTAMPS,
371bdb91d1SDmitri Tikhonov    TPI_LOSS_BITS,                          MAX_NUMERIC_TPI = TPI_LOSS_BITS,
385392f7a3SLiteSpeed Tech
391bdb91d1SDmitri Tikhonov    /*
401bdb91d1SDmitri Tikhonov     * Empty transport parameters:
411bdb91d1SDmitri Tikhonov     */
42692a9102SDmitri Tikhonov    TPI_GREASE_QUIC_BIT,
431bdb91d1SDmitri Tikhonov    TPI_DISABLE_ACTIVE_MIGRATION,           MAX_EMPTY_TPI = TPI_DISABLE_ACTIVE_MIGRATION,
441bdb91d1SDmitri Tikhonov
451bdb91d1SDmitri Tikhonov    /*
461bdb91d1SDmitri Tikhonov     * Custom handlers:
471bdb91d1SDmitri Tikhonov     */
481bdb91d1SDmitri Tikhonov    TPI_PREFERRED_ADDRESS,
49fb73393fSDmitri Tikhonov        /* CIDs must be in a contiguous range for tp_cids array to work */
50fb73393fSDmitri Tikhonov#define FIRST_TP_CID TPI_ORIGINAL_DEST_CID
51fb73393fSDmitri Tikhonov    TPI_ORIGINAL_DEST_CID,
52fb73393fSDmitri Tikhonov    TPI_INITIAL_SOURCE_CID,
53fb73393fSDmitri Tikhonov#define LAST_TP_CID TPI_RETRY_SOURCE_CID
54fb73393fSDmitri Tikhonov    TPI_RETRY_SOURCE_CID,
5503e6b668SDmitri Tikhonov#if LSQUIC_TEST_QUANTUM_READINESS
5603e6b668SDmitri Tikhonov    /* https://github.com/quicwg/base-drafts/wiki/Quantum-Readiness-test */
571bdb91d1SDmitri Tikhonov#define QUANTUM_READY_SZ 1200
581bdb91d1SDmitri Tikhonov    TPI_QUANTUM_READINESS,
5903e6b668SDmitri Tikhonov#endif
601bdb91d1SDmitri Tikhonov    TPI_STATELESS_RESET_TOKEN,              LAST_TPI = TPI_STATELESS_RESET_TOKEN
615392f7a3SLiteSpeed Tech};
625392f7a3SLiteSpeed Tech
63fb73393fSDmitri Tikhonov#define TP_CID_IDX(tpi_) ((tpi_) - FIRST_TP_CID)
64fb73393fSDmitri Tikhonov
651bdb91d1SDmitri Tikhonov
665392f7a3SLiteSpeed Techstruct transport_params
675392f7a3SLiteSpeed Tech{
681bdb91d1SDmitri Tikhonov    /* Which transport parameters values are set: */
691bdb91d1SDmitri Tikhonov    unsigned                tp_set;
701bdb91d1SDmitri Tikhonov
711bdb91d1SDmitri Tikhonov    /* Which transport parameters were present (set by the decoder): */
721bdb91d1SDmitri Tikhonov    unsigned                tp_decoded;
731bdb91d1SDmitri Tikhonov
741bdb91d1SDmitri Tikhonov    uint64_t                tp_numerics[MAX_NUMERIC_TPI + 1];
751bdb91d1SDmitri Tikhonov
761bdb91d1SDmitri Tikhonov#define tp_init_max_stream_data_bidi_local  tp_numerics[TPI_INIT_MAX_STREAM_DATA_BIDI_LOCAL]
771bdb91d1SDmitri Tikhonov#define tp_init_max_stream_data_bidi_remote tp_numerics[TPI_INIT_MAX_STREAM_DATA_BIDI_REMOTE]
781bdb91d1SDmitri Tikhonov#define tp_init_max_stream_data_uni         tp_numerics[TPI_INIT_MAX_STREAM_DATA_UNI]
791bdb91d1SDmitri Tikhonov#define tp_init_max_data                    tp_numerics[TPI_INIT_MAX_DATA]
801bdb91d1SDmitri Tikhonov#define tp_max_idle_timeout                 tp_numerics[TPI_MAX_IDLE_TIMEOUT]
811bdb91d1SDmitri Tikhonov#define tp_init_max_streams_bidi            tp_numerics[TPI_INIT_MAX_STREAMS_BIDI]
821bdb91d1SDmitri Tikhonov#define tp_init_max_streams_uni             tp_numerics[TPI_INIT_MAX_STREAMS_UNI]
83fb73393fSDmitri Tikhonov#define tp_max_udp_payload_size             tp_numerics[TPI_MAX_UDP_PAYLOAD_SIZE]
841bdb91d1SDmitri Tikhonov#define tp_ack_delay_exponent               tp_numerics[TPI_ACK_DELAY_EXPONENT]
851bdb91d1SDmitri Tikhonov#define tp_max_ack_delay                    tp_numerics[TPI_MAX_ACK_DELAY]
861bdb91d1SDmitri Tikhonov#define tp_active_connection_id_limit       tp_numerics[TPI_ACTIVE_CONNECTION_ID_LIMIT]
871bdb91d1SDmitri Tikhonov#define tp_loss_bits                        tp_numerics[TPI_LOSS_BITS]
881bdb91d1SDmitri Tikhonov
895392f7a3SLiteSpeed Tech    uint8_t     tp_stateless_reset_token[IQUIC_SRESET_TOKEN_SZ];
905392f7a3SLiteSpeed Tech    struct {
915392f7a3SLiteSpeed Tech        uint8_t         ipv4_addr[4];
925392f7a3SLiteSpeed Tech        uint16_t        ipv4_port;
935392f7a3SLiteSpeed Tech        uint8_t         ipv6_addr[16];
945392f7a3SLiteSpeed Tech        uint16_t        ipv6_port;
955392f7a3SLiteSpeed Tech        lsquic_cid_t    cid;
965392f7a3SLiteSpeed Tech        uint8_t         srst[IQUIC_SRESET_TOKEN_SZ];
975392f7a3SLiteSpeed Tech    }           tp_preferred_address;
98fb73393fSDmitri Tikhonov    lsquic_cid_t    tp_cids[3];
99fb73393fSDmitri Tikhonov#define tp_original_dest_cid tp_cids[TP_CID_IDX(TPI_ORIGINAL_DEST_CID)]
100fb73393fSDmitri Tikhonov#define tp_initial_source_cid tp_cids[TP_CID_IDX(TPI_INITIAL_SOURCE_CID)]
101fb73393fSDmitri Tikhonov#define tp_retry_source_cid tp_cids[TP_CID_IDX(TPI_RETRY_SOURCE_CID)]
1025392f7a3SLiteSpeed Tech};
1035392f7a3SLiteSpeed Tech
104fb73393fSDmitri Tikhonov#define MAX_TP_STR_SZ ((LAST_TPI + 1) *                                     \
105fb73393fSDmitri Tikhonov    (34 /* longest entry in tt2str */ + 2 /* semicolon */ + 2 /* colon */)  \
106fb73393fSDmitri Tikhonov  + INET_ADDRSTRLEN + INET6_ADDRSTRLEN + 5 /* Port */ * 2                   \
107fb73393fSDmitri Tikhonov  + MAX_CID_LEN * 2 * 4 /* there are four CIDs */                           \
108fb73393fSDmitri Tikhonov  + 11 * (MAX_NUMERIC_TPI + 1)                                              \
109fb73393fSDmitri Tikhonov  + IQUIC_SRESET_TOKEN_SZ * 2 * 2 /* there are two reset tokens */)
110fb73393fSDmitri Tikhonov
111fb73393fSDmitri Tikhonov#define TP_DEF_MAX_UDP_PAYLOAD_SIZE 65527
1125392f7a3SLiteSpeed Tech#define TP_DEF_ACK_DELAY_EXP 3
1135392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAMS_UNI 0
1145392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAMS_BIDI 0
1155392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_DATA 0
11692f6e17bSDmitri Tikhonov#define TP_DEF_DISABLE_ACTIVE_MIGRATION 0
1175392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL 0
1185392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE 0
1195392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_UNI 0
1209fc12041SDmitri Tikhonov#define TP_DEF_MAX_IDLE_TIMEOUT 0
1215392f7a3SLiteSpeed Tech#define TP_DEF_MAX_ACK_DELAY 25
1229fc12041SDmitri Tikhonov#define TP_DEF_ACTIVE_CONNECTION_ID_LIMIT 2
1235392f7a3SLiteSpeed Tech
1245392f7a3SLiteSpeed Tech/* [draft-ietf-quic-transport-18], Section 18.1 */
1255392f7a3SLiteSpeed Tech#define TP_MAX_MAX_ACK_DELAY ((1u << 14) - 1)
1265392f7a3SLiteSpeed Tech
1275392f7a3SLiteSpeed Tech#define TP_DEFAULT_VALUES                                                             \
1281bdb91d1SDmitri Tikhonov    .tp_set = ((1 << (MAX_NUM_WITH_DEF_TPI + 1)) - 1),                                \
1295392f7a3SLiteSpeed Tech    .tp_active_connection_id_limit        =  TP_DEF_ACTIVE_CONNECTION_ID_LIMIT,       \
1309fc12041SDmitri Tikhonov    .tp_max_idle_timeout                  =  TP_DEF_MAX_IDLE_TIMEOUT,                 \
1315392f7a3SLiteSpeed Tech    .tp_max_ack_delay                     =  TP_DEF_MAX_ACK_DELAY,                    \
132fb73393fSDmitri Tikhonov    .tp_max_udp_payload_size              =  TP_DEF_MAX_UDP_PAYLOAD_SIZE,             \
1335392f7a3SLiteSpeed Tech    .tp_ack_delay_exponent                =  TP_DEF_ACK_DELAY_EXP,                    \
1345392f7a3SLiteSpeed Tech    .tp_init_max_streams_bidi             =  TP_DEF_INIT_MAX_STREAMS_BIDI,            \
1355392f7a3SLiteSpeed Tech    .tp_init_max_streams_uni              =  TP_DEF_INIT_MAX_STREAMS_UNI,             \
1365392f7a3SLiteSpeed Tech    .tp_init_max_data                     =  TP_DEF_INIT_MAX_DATA,                    \
1375392f7a3SLiteSpeed Tech    .tp_init_max_stream_data_bidi_local   =  TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL,  \
1385392f7a3SLiteSpeed Tech    .tp_init_max_stream_data_bidi_remote  =  TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE, \
1395392f7a3SLiteSpeed Tech    .tp_init_max_stream_data_uni          =  TP_DEF_INIT_MAX_STREAM_DATA_UNI
1405392f7a3SLiteSpeed Tech
1415392f7a3SLiteSpeed Tech#define TP_INITIALIZER() (struct transport_params) { TP_DEFAULT_VALUES }
1425392f7a3SLiteSpeed Tech
1435392f7a3SLiteSpeed Techint
1441bdb91d1SDmitri Tikhonovlsquic_tp_encode (const struct transport_params *, int is_server,
145fb3e20e0SDmitri Tikhonov                  unsigned char *const buf, size_t bufsz);
1465392f7a3SLiteSpeed Tech
1475392f7a3SLiteSpeed Techint
148fb3e20e0SDmitri Tikhonovlsquic_tp_decode (const unsigned char *const buf, size_t bufsz,
1495392f7a3SLiteSpeed Tech    /* This argument specifies whose transport parameters we are parsing.  If
1505392f7a3SLiteSpeed Tech     * true, we are parsing parameters sent by the server; if false, we are
1515392f7a3SLiteSpeed Tech     * parsing parameteres sent by the client.
1525392f7a3SLiteSpeed Tech     */
1535392f7a3SLiteSpeed Tech                  int is_server,
1545392f7a3SLiteSpeed Tech                  struct transport_params *);
1555392f7a3SLiteSpeed Tech
156fb73393fSDmitri Tikhonovvoid
157fb73393fSDmitri Tikhonovlsquic_tp_to_str (const struct transport_params *params, char *buf, size_t sz);
158fb73393fSDmitri Tikhonov
159bc520ef7SDmitri Tikhonovint
160fb73393fSDmitri Tikhonovlsquic_tp_encode_27 (const struct transport_params *, int is_server,
161fb3e20e0SDmitri Tikhonov                  unsigned char *const buf, size_t bufsz);
162bc520ef7SDmitri Tikhonov
163bc520ef7SDmitri Tikhonovint
164fb3e20e0SDmitri Tikhonovlsquic_tp_decode_27 (const unsigned char *const buf, size_t bufsz,
165fb73393fSDmitri Tikhonov                  int is_server,
166fb73393fSDmitri Tikhonov                  struct transport_params *);
167bc520ef7SDmitri Tikhonov
1685392f7a3SLiteSpeed Techvoid
169fb73393fSDmitri Tikhonovlsquic_tp_to_str_27 (const struct transport_params *params, char *buf, size_t sz);
1705392f7a3SLiteSpeed Tech
1711bdb91d1SDmitri Tikhonovint
1721bdb91d1SDmitri Tikhonovlsquic_tp_has_pref_ipv4 (const struct transport_params *);
1731bdb91d1SDmitri Tikhonov
1741bdb91d1SDmitri Tikhonovint
1751bdb91d1SDmitri Tikhonovlsquic_tp_has_pref_ipv6 (const struct transport_params *);
1761bdb91d1SDmitri Tikhonov
177fb73393fSDmitri Tikhonovextern const char * const lsquic_tpi2str[LAST_TPI + 1];
178fb73393fSDmitri Tikhonov
17949f1f4f6SDmitri Tikhonov/* From [draft-huitema-quic-ts-03] */
18049f1f4f6SDmitri Tikhonov#define TS_WANT_THEM            1
18149f1f4f6SDmitri Tikhonov#define TS_GENERATE_THEM        2
18249f1f4f6SDmitri Tikhonov
1835392f7a3SLiteSpeed Tech#endif
184