lsquic_trans_params.h revision afe3d363
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,
211bdb91d1SDmitri Tikhonov    TPI_MAX_PACKET_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,
361bdb91d1SDmitri Tikhonov    TPI_LOSS_BITS,                          MAX_NUMERIC_TPI = TPI_LOSS_BITS,
375392f7a3SLiteSpeed Tech
381bdb91d1SDmitri Tikhonov    /*
391bdb91d1SDmitri Tikhonov     * Empty transport parameters:
401bdb91d1SDmitri Tikhonov     */
41afe3d363SDmitri Tikhonov    TPI_TIMESTAMPS,
421bdb91d1SDmitri Tikhonov    TPI_DISABLE_ACTIVE_MIGRATION,           MAX_EMPTY_TPI = TPI_DISABLE_ACTIVE_MIGRATION,
431bdb91d1SDmitri Tikhonov
441bdb91d1SDmitri Tikhonov    /*
451bdb91d1SDmitri Tikhonov     * Custom handlers:
461bdb91d1SDmitri Tikhonov     */
471bdb91d1SDmitri Tikhonov    TPI_PREFERRED_ADDRESS,
481bdb91d1SDmitri Tikhonov    TPI_ORIGINAL_CONNECTION_ID,
4903e6b668SDmitri Tikhonov#if LSQUIC_TEST_QUANTUM_READINESS
5003e6b668SDmitri Tikhonov    /* https://github.com/quicwg/base-drafts/wiki/Quantum-Readiness-test */
511bdb91d1SDmitri Tikhonov#define QUANTUM_READY_SZ 1200
521bdb91d1SDmitri Tikhonov    TPI_QUANTUM_READINESS,
5303e6b668SDmitri Tikhonov#endif
541bdb91d1SDmitri Tikhonov    TPI_STATELESS_RESET_TOKEN,              LAST_TPI = TPI_STATELESS_RESET_TOKEN
555392f7a3SLiteSpeed Tech};
565392f7a3SLiteSpeed Tech
571bdb91d1SDmitri Tikhonov
585392f7a3SLiteSpeed Techstruct transport_params
595392f7a3SLiteSpeed Tech{
601bdb91d1SDmitri Tikhonov    /* Which transport parameters values are set: */
611bdb91d1SDmitri Tikhonov    unsigned                tp_set;
621bdb91d1SDmitri Tikhonov
631bdb91d1SDmitri Tikhonov    /* Which transport parameters were present (set by the decoder): */
641bdb91d1SDmitri Tikhonov    unsigned                tp_decoded;
651bdb91d1SDmitri Tikhonov
661bdb91d1SDmitri Tikhonov    uint64_t                tp_numerics[MAX_NUMERIC_TPI + 1];
671bdb91d1SDmitri Tikhonov
681bdb91d1SDmitri Tikhonov#define tp_init_max_stream_data_bidi_local  tp_numerics[TPI_INIT_MAX_STREAM_DATA_BIDI_LOCAL]
691bdb91d1SDmitri Tikhonov#define tp_init_max_stream_data_bidi_remote tp_numerics[TPI_INIT_MAX_STREAM_DATA_BIDI_REMOTE]
701bdb91d1SDmitri Tikhonov#define tp_init_max_stream_data_uni         tp_numerics[TPI_INIT_MAX_STREAM_DATA_UNI]
711bdb91d1SDmitri Tikhonov#define tp_init_max_data                    tp_numerics[TPI_INIT_MAX_DATA]
721bdb91d1SDmitri Tikhonov#define tp_max_idle_timeout                 tp_numerics[TPI_MAX_IDLE_TIMEOUT]
731bdb91d1SDmitri Tikhonov#define tp_init_max_streams_bidi            tp_numerics[TPI_INIT_MAX_STREAMS_BIDI]
741bdb91d1SDmitri Tikhonov#define tp_init_max_streams_uni             tp_numerics[TPI_INIT_MAX_STREAMS_UNI]
751bdb91d1SDmitri Tikhonov#define tp_max_packet_size                  tp_numerics[TPI_MAX_PACKET_SIZE]
761bdb91d1SDmitri Tikhonov#define tp_ack_delay_exponent               tp_numerics[TPI_ACK_DELAY_EXPONENT]
771bdb91d1SDmitri Tikhonov#define tp_max_ack_delay                    tp_numerics[TPI_MAX_ACK_DELAY]
781bdb91d1SDmitri Tikhonov#define tp_active_connection_id_limit       tp_numerics[TPI_ACTIVE_CONNECTION_ID_LIMIT]
791bdb91d1SDmitri Tikhonov#define tp_loss_bits                        tp_numerics[TPI_LOSS_BITS]
801bdb91d1SDmitri Tikhonov
815392f7a3SLiteSpeed Tech    uint8_t     tp_stateless_reset_token[IQUIC_SRESET_TOKEN_SZ];
825392f7a3SLiteSpeed Tech    struct {
835392f7a3SLiteSpeed Tech        uint8_t         ipv4_addr[4];
845392f7a3SLiteSpeed Tech        uint16_t        ipv4_port;
855392f7a3SLiteSpeed Tech        uint8_t         ipv6_addr[16];
865392f7a3SLiteSpeed Tech        uint16_t        ipv6_port;
875392f7a3SLiteSpeed Tech        lsquic_cid_t    cid;
885392f7a3SLiteSpeed Tech        uint8_t         srst[IQUIC_SRESET_TOKEN_SZ];
895392f7a3SLiteSpeed Tech    }           tp_preferred_address;
905392f7a3SLiteSpeed Tech    lsquic_cid_t    tp_original_cid;
915392f7a3SLiteSpeed Tech};
925392f7a3SLiteSpeed Tech
935392f7a3SLiteSpeed Tech#define TP_DEF_MAX_PACKET_SIZE 65527
945392f7a3SLiteSpeed Tech#define TP_DEF_ACK_DELAY_EXP 3
955392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAMS_UNI 0
965392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAMS_BIDI 0
975392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_DATA 0
9892f6e17bSDmitri Tikhonov#define TP_DEF_DISABLE_ACTIVE_MIGRATION 0
995392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL 0
1005392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE 0
1015392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_UNI 0
1029fc12041SDmitri Tikhonov#define TP_DEF_MAX_IDLE_TIMEOUT 0
1035392f7a3SLiteSpeed Tech#define TP_DEF_MAX_ACK_DELAY 25
1049fc12041SDmitri Tikhonov#define TP_DEF_ACTIVE_CONNECTION_ID_LIMIT 2
1055392f7a3SLiteSpeed Tech
1065392f7a3SLiteSpeed Tech/* [draft-ietf-quic-transport-18], Section 18.1 */
1075392f7a3SLiteSpeed Tech#define TP_MAX_MAX_ACK_DELAY ((1u << 14) - 1)
1085392f7a3SLiteSpeed Tech
1095392f7a3SLiteSpeed Tech#define TP_DEFAULT_VALUES                                                             \
1101bdb91d1SDmitri Tikhonov    .tp_set = ((1 << (MAX_NUM_WITH_DEF_TPI + 1)) - 1),                                \
1115392f7a3SLiteSpeed Tech    .tp_active_connection_id_limit        =  TP_DEF_ACTIVE_CONNECTION_ID_LIMIT,       \
1129fc12041SDmitri Tikhonov    .tp_max_idle_timeout                  =  TP_DEF_MAX_IDLE_TIMEOUT,                 \
1135392f7a3SLiteSpeed Tech    .tp_max_ack_delay                     =  TP_DEF_MAX_ACK_DELAY,                    \
1145392f7a3SLiteSpeed Tech    .tp_max_packet_size                   =  TP_DEF_MAX_PACKET_SIZE,                  \
1155392f7a3SLiteSpeed Tech    .tp_ack_delay_exponent                =  TP_DEF_ACK_DELAY_EXP,                    \
1165392f7a3SLiteSpeed Tech    .tp_init_max_streams_bidi             =  TP_DEF_INIT_MAX_STREAMS_BIDI,            \
1175392f7a3SLiteSpeed Tech    .tp_init_max_streams_uni              =  TP_DEF_INIT_MAX_STREAMS_UNI,             \
1185392f7a3SLiteSpeed Tech    .tp_init_max_data                     =  TP_DEF_INIT_MAX_DATA,                    \
1195392f7a3SLiteSpeed Tech    .tp_init_max_stream_data_bidi_local   =  TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL,  \
1205392f7a3SLiteSpeed Tech    .tp_init_max_stream_data_bidi_remote  =  TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE, \
1215392f7a3SLiteSpeed Tech    .tp_init_max_stream_data_uni          =  TP_DEF_INIT_MAX_STREAM_DATA_UNI
1225392f7a3SLiteSpeed Tech
1235392f7a3SLiteSpeed Tech#define TP_INITIALIZER() (struct transport_params) { TP_DEFAULT_VALUES }
1245392f7a3SLiteSpeed Tech
1255392f7a3SLiteSpeed Techint
1261bdb91d1SDmitri Tikhonovlsquic_tp_encode (const struct transport_params *, int is_server,
1275392f7a3SLiteSpeed Tech                  unsigned char *buf, size_t bufsz);
1285392f7a3SLiteSpeed Tech
1295392f7a3SLiteSpeed Techint
1305392f7a3SLiteSpeed Techlsquic_tp_decode (const unsigned char *buf, size_t bufsz,
1315392f7a3SLiteSpeed Tech    /* This argument specifies whose transport parameters we are parsing.  If
1325392f7a3SLiteSpeed Tech     * true, we are parsing parameters sent by the server; if false, we are
1335392f7a3SLiteSpeed Tech     * parsing parameteres sent by the client.
1345392f7a3SLiteSpeed Tech     */
1355392f7a3SLiteSpeed Tech                  int is_server,
1365392f7a3SLiteSpeed Tech                  struct transport_params *);
1375392f7a3SLiteSpeed Tech
138bc520ef7SDmitri Tikhonovint
139bc520ef7SDmitri Tikhonovlsquic_tp_encode_id25 (const struct transport_params *, int is_server,
140bc520ef7SDmitri Tikhonov                  unsigned char *buf, size_t bufsz);
141bc520ef7SDmitri Tikhonov
142bc520ef7SDmitri Tikhonovint
143bc520ef7SDmitri Tikhonovlsquic_tp_decode_id25 (const unsigned char *buf, size_t bufsz,
144bc520ef7SDmitri Tikhonov                  int is_server, struct transport_params *);
145bc520ef7SDmitri Tikhonov
1465392f7a3SLiteSpeed Techvoid
1475392f7a3SLiteSpeed Techlsquic_tp_to_str (const struct transport_params *params, char *buf, size_t sz);
1485392f7a3SLiteSpeed Tech
1491bdb91d1SDmitri Tikhonovint
1501bdb91d1SDmitri Tikhonovlsquic_tp_has_pref_ipv4 (const struct transport_params *);
1511bdb91d1SDmitri Tikhonov
1521bdb91d1SDmitri Tikhonovint
1531bdb91d1SDmitri Tikhonovlsquic_tp_has_pref_ipv6 (const struct transport_params *);
1541bdb91d1SDmitri Tikhonov
1555392f7a3SLiteSpeed Tech#endif
156