lsquic_trans_params.h revision 9fc12041
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
95392f7a3SLiteSpeed Tech/* [draft-ietf-quic-transport-17], Section 18 */
105392f7a3SLiteSpeed Techenum transport_param_id
115392f7a3SLiteSpeed Tech{
125392f7a3SLiteSpeed Tech    TPI_ORIGINAL_CONNECTION_ID            =  0,
139fc12041SDmitri Tikhonov    TPI_MAX_IDLE_TIMEOUT                  =  1,
145392f7a3SLiteSpeed Tech    TPI_STATELESS_RESET_TOKEN             =  2,
155392f7a3SLiteSpeed Tech    TPI_MAX_PACKET_SIZE                   =  3,
165392f7a3SLiteSpeed Tech    TPI_INIT_MAX_DATA                     =  4,
175392f7a3SLiteSpeed Tech    TPI_INIT_MAX_STREAM_DATA_BIDI_LOCAL   =  5,
185392f7a3SLiteSpeed Tech    TPI_INIT_MAX_STREAM_DATA_BIDI_REMOTE  =  6,
195392f7a3SLiteSpeed Tech    TPI_INIT_MAX_STREAM_DATA_UNI          =  7,
205392f7a3SLiteSpeed Tech    TPI_INIT_MAX_STREAMS_BIDI             =  8,
215392f7a3SLiteSpeed Tech    TPI_INIT_MAX_STREAMS_UNI              =  9,
225392f7a3SLiteSpeed Tech    TPI_ACK_DELAY_EXPONENT                =  10,
235392f7a3SLiteSpeed Tech    TPI_MAX_ACK_DELAY                     =  11,
2492f6e17bSDmitri Tikhonov    TPI_DISABLE_ACTIVE_MIGRATION          =  12,
255392f7a3SLiteSpeed Tech    TPI_PREFERRED_ADDRESS                 =  13,
265392f7a3SLiteSpeed Tech    TPI_ACTIVE_CONNECTION_ID_LIMIT        =  14,
275392f7a3SLiteSpeed Tech#define MAX_TPI TPI_ACTIVE_CONNECTION_ID_LIMIT
285392f7a3SLiteSpeed Tech};
295392f7a3SLiteSpeed Tech
305392f7a3SLiteSpeed Tech#define NUMERIC_TRANS_PARAMS (\
315392f7a3SLiteSpeed Tech     (1 << TPI_MAX_PACKET_SIZE) \
325392f7a3SLiteSpeed Tech    |(1 << TPI_INIT_MAX_STREAMS_UNI) \
335392f7a3SLiteSpeed Tech    |(1 << TPI_INIT_MAX_STREAMS_UNI) \
345392f7a3SLiteSpeed Tech    |(1 << TPI_INIT_MAX_STREAMS_BIDI) \
355392f7a3SLiteSpeed Tech    |(1 << TPI_INIT_MAX_DATA) \
365392f7a3SLiteSpeed Tech    |(1 << TPI_INIT_MAX_STREAM_DATA_BIDI_LOCAL) \
375392f7a3SLiteSpeed Tech    |(1 << TPI_INIT_MAX_STREAM_DATA_BIDI_REMOTE) \
385392f7a3SLiteSpeed Tech    |(1 << TPI_INIT_MAX_STREAM_DATA_UNI) \
399fc12041SDmitri Tikhonov    |(1 << TPI_MAX_IDLE_TIMEOUT) \
405392f7a3SLiteSpeed Tech    |(1 << TPI_MAX_ACK_DELAY) \
415392f7a3SLiteSpeed Tech    |(1 << TPI_ACK_DELAY_EXPONENT) \
425392f7a3SLiteSpeed Tech    |(1 << TPI_ACTIVE_CONNECTION_ID_LIMIT) \
435392f7a3SLiteSpeed Tech    )
445392f7a3SLiteSpeed Tech
455392f7a3SLiteSpeed Tech#define IQUIC_MAX_SUPP_VERS ((2<<7) - 4)/sizeof(uint32_t)
465392f7a3SLiteSpeed Tech
475392f7a3SLiteSpeed Techenum trapa_flags
485392f7a3SLiteSpeed Tech{
495392f7a3SLiteSpeed Tech    TRAPA_RESET_TOKEN   = 1 << 0,   /* Reset token is set */
505392f7a3SLiteSpeed Tech    TRAPA_SERVER        = 1 << 1,   /* Server transport parameters */
515392f7a3SLiteSpeed Tech    TRAPA_PREFADDR_IPv4 = 1 << 2,   /* Preferred IPv4 address is set */
525392f7a3SLiteSpeed Tech    TRAPA_PREFADDR_IPv6 = 1 << 3,   /* Preferred IPv6 address is set */
535392f7a3SLiteSpeed Tech    TRAPA_ORIGINAL_CID  = 1 << 4,   /* Original CID is set */
5403e6b668SDmitri Tikhonov#if LSQUIC_TEST_QUANTUM_READINESS
5503e6b668SDmitri Tikhonov#define QUANTUM_READY_SZ 1200
5603e6b668SDmitri Tikhonov    /* https://github.com/quicwg/base-drafts/wiki/Quantum-Readiness-test */
5703e6b668SDmitri Tikhonov#define TPI_QUANTUM_READINESS 3127
5803e6b668SDmitri Tikhonov    TRAPA_QUANTUM_READY = 1 << 5,   /* Include "Quantum Readiness" TP */
5903e6b668SDmitri Tikhonov#endif
6010c41073SDmitri Tikhonov#define TPI_QL_BITS 0x1057     /* 1057 is 133t for "lost" */
617d09751dSDmitri Tikhonov    TRAPA_QL_BITS       = 1 << 6,   /* tp_loss_bits contains valid value */
627d09751dSDmitri Tikhonov    TRAPA_QL_BITS_OLD   = 1 << 7,   /* Send old-school boolean loss_bits TP.
637d09751dSDmitri Tikhonov                                     * Not set on decoded transport parameters.
647d09751dSDmitri Tikhonov                                     */
655392f7a3SLiteSpeed Tech};
665392f7a3SLiteSpeed Tech
675392f7a3SLiteSpeed Techstruct transport_params
685392f7a3SLiteSpeed Tech{
695392f7a3SLiteSpeed Tech    enum trapa_flags        tp_flags;
705392f7a3SLiteSpeed Tech
715392f7a3SLiteSpeed Tech    union {
725392f7a3SLiteSpeed Tech        struct {
735392f7a3SLiteSpeed Tech            uint64_t init_max_stream_data_bidi_local;
745392f7a3SLiteSpeed Tech            uint64_t init_max_stream_data_bidi_remote;
755392f7a3SLiteSpeed Tech            uint64_t init_max_stream_data_uni;
765392f7a3SLiteSpeed Tech            uint64_t init_max_data;
779fc12041SDmitri Tikhonov            uint64_t max_idle_timeout;
785392f7a3SLiteSpeed Tech            uint64_t init_max_streams_bidi;
795392f7a3SLiteSpeed Tech            uint64_t init_max_streams_uni;
805392f7a3SLiteSpeed Tech            uint64_t max_packet_size;
815392f7a3SLiteSpeed Tech            uint64_t ack_delay_exponent;
825392f7a3SLiteSpeed Tech            uint64_t max_ack_delay;
835392f7a3SLiteSpeed Tech            uint64_t active_connection_id_limit;
845392f7a3SLiteSpeed Tech        }               s;
85ff892190SDmitri Tikhonov        uint64_t        a[11];
865392f7a3SLiteSpeed Tech    }           tp_numerics_u;
875392f7a3SLiteSpeed Tech#define tp_init_max_stream_data_bidi_local tp_numerics_u.s.init_max_stream_data_bidi_local
885392f7a3SLiteSpeed Tech#define tp_init_max_stream_data_bidi_remote tp_numerics_u.s.init_max_stream_data_bidi_remote
895392f7a3SLiteSpeed Tech#define tp_init_max_stream_data_uni tp_numerics_u.s.init_max_stream_data_uni
905392f7a3SLiteSpeed Tech#define tp_init_max_data tp_numerics_u.s.init_max_data
919fc12041SDmitri Tikhonov#define tp_max_idle_timeout tp_numerics_u.s.max_idle_timeout
925392f7a3SLiteSpeed Tech#define tp_init_max_streams_bidi tp_numerics_u.s.init_max_streams_bidi
935392f7a3SLiteSpeed Tech#define tp_init_max_streams_uni tp_numerics_u.s.init_max_streams_uni
945392f7a3SLiteSpeed Tech#define tp_max_packet_size tp_numerics_u.s.max_packet_size
955392f7a3SLiteSpeed Tech#define tp_ack_delay_exponent tp_numerics_u.s.ack_delay_exponent
965392f7a3SLiteSpeed Tech#define tp_max_ack_delay tp_numerics_u.s.max_ack_delay
975392f7a3SLiteSpeed Tech#define tp_active_connection_id_limit tp_numerics_u.s.active_connection_id_limit
985392f7a3SLiteSpeed Tech
997d09751dSDmitri Tikhonov    unsigned char   tp_loss_bits;   /* Valid values 0, 1.  Set if TRAPA_QL_BITS is set. */
10092f6e17bSDmitri Tikhonov    signed char tp_disable_active_migration;
1015392f7a3SLiteSpeed Tech    uint8_t     tp_stateless_reset_token[IQUIC_SRESET_TOKEN_SZ];
1025392f7a3SLiteSpeed Tech    struct {
1035392f7a3SLiteSpeed Tech        uint8_t         ipv4_addr[4];
1045392f7a3SLiteSpeed Tech        uint16_t        ipv4_port;
1055392f7a3SLiteSpeed Tech        uint8_t         ipv6_addr[16];
1065392f7a3SLiteSpeed Tech        uint16_t        ipv6_port;
1075392f7a3SLiteSpeed Tech        lsquic_cid_t    cid;
1085392f7a3SLiteSpeed Tech        uint8_t         srst[IQUIC_SRESET_TOKEN_SZ];
1095392f7a3SLiteSpeed Tech    }           tp_preferred_address;
1105392f7a3SLiteSpeed Tech    lsquic_cid_t    tp_original_cid;
1115392f7a3SLiteSpeed Tech};
1125392f7a3SLiteSpeed Tech
1135392f7a3SLiteSpeed Tech#define TP_DEF_MAX_PACKET_SIZE 65527
1145392f7a3SLiteSpeed Tech#define TP_DEF_ACK_DELAY_EXP 3
1155392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAMS_UNI 0
1165392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAMS_BIDI 0
1175392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_DATA 0
11892f6e17bSDmitri Tikhonov#define TP_DEF_DISABLE_ACTIVE_MIGRATION 0
1195392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL 0
1205392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE 0
1215392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_UNI 0
1229fc12041SDmitri Tikhonov#define TP_DEF_MAX_IDLE_TIMEOUT 0
1235392f7a3SLiteSpeed Tech#define TP_DEF_MAX_ACK_DELAY 25
1249fc12041SDmitri Tikhonov#define TP_DEF_ACTIVE_CONNECTION_ID_LIMIT 2
1255392f7a3SLiteSpeed Tech
1265392f7a3SLiteSpeed Tech/* [draft-ietf-quic-transport-18], Section 18.1 */
1275392f7a3SLiteSpeed Tech#define TP_MAX_MAX_ACK_DELAY ((1u << 14) - 1)
1285392f7a3SLiteSpeed Tech
1295392f7a3SLiteSpeed Tech#define TP_DEFAULT_VALUES                                                             \
1305392f7a3SLiteSpeed Tech    .tp_active_connection_id_limit        =  TP_DEF_ACTIVE_CONNECTION_ID_LIMIT,       \
1319fc12041SDmitri Tikhonov    .tp_max_idle_timeout                  =  TP_DEF_MAX_IDLE_TIMEOUT,                 \
1325392f7a3SLiteSpeed Tech    .tp_max_ack_delay                     =  TP_DEF_MAX_ACK_DELAY,                    \
1335392f7a3SLiteSpeed Tech    .tp_max_packet_size                   =  TP_DEF_MAX_PACKET_SIZE,                  \
1345392f7a3SLiteSpeed Tech    .tp_ack_delay_exponent                =  TP_DEF_ACK_DELAY_EXP,                    \
1355392f7a3SLiteSpeed Tech    .tp_init_max_streams_bidi             =  TP_DEF_INIT_MAX_STREAMS_BIDI,            \
1365392f7a3SLiteSpeed Tech    .tp_init_max_streams_uni              =  TP_DEF_INIT_MAX_STREAMS_UNI,             \
1375392f7a3SLiteSpeed Tech    .tp_init_max_data                     =  TP_DEF_INIT_MAX_DATA,                    \
13892f6e17bSDmitri Tikhonov    .tp_disable_active_migration          =  TP_DEF_DISABLE_ACTIVE_MIGRATION,         \
1395392f7a3SLiteSpeed Tech    .tp_init_max_stream_data_bidi_local   =  TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL,  \
1405392f7a3SLiteSpeed Tech    .tp_init_max_stream_data_bidi_remote  =  TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE, \
1415392f7a3SLiteSpeed Tech    .tp_init_max_stream_data_uni          =  TP_DEF_INIT_MAX_STREAM_DATA_UNI
1425392f7a3SLiteSpeed Tech
1435392f7a3SLiteSpeed Tech#define TP_INITIALIZER() (struct transport_params) { TP_DEFAULT_VALUES }
1445392f7a3SLiteSpeed Tech
1455392f7a3SLiteSpeed Techint
1465392f7a3SLiteSpeed Techlsquic_tp_encode (const struct transport_params *,
1475392f7a3SLiteSpeed Tech                  unsigned char *buf, size_t bufsz);
1485392f7a3SLiteSpeed Tech
1495392f7a3SLiteSpeed Techint
1505392f7a3SLiteSpeed Techlsquic_tp_decode (const unsigned char *buf, size_t bufsz,
1515392f7a3SLiteSpeed Tech    /* This argument specifies whose transport parameters we are parsing.  If
1525392f7a3SLiteSpeed Tech     * true, we are parsing parameters sent by the server; if false, we are
1535392f7a3SLiteSpeed Tech     * parsing parameteres sent by the client.
1545392f7a3SLiteSpeed Tech     */
1555392f7a3SLiteSpeed Tech                  int is_server,
1565392f7a3SLiteSpeed Tech                  struct transport_params *);
1575392f7a3SLiteSpeed Tech
1585392f7a3SLiteSpeed Techvoid
1595392f7a3SLiteSpeed Techlsquic_tp_to_str (const struct transport_params *params, char *buf, size_t sz);
1605392f7a3SLiteSpeed Tech
1615392f7a3SLiteSpeed Tech#endif
162