lsquic_trans_params.h revision ff892190
15392f7a3SLiteSpeed Tech/* Copyright (c) 2017 - 2019 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,
135392f7a3SLiteSpeed Tech    TPI_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) \
395392f7a3SLiteSpeed Tech    |(1 << TPI_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
6002b6086dSDmitri Tikhonov#define TPI_QL_BITS 0x1055     /* 1055 is 133t for "loss" */
6102b6086dSDmitri Tikhonov    TRAPA_QL_BITS       = 1 << 6,
625392f7a3SLiteSpeed Tech};
635392f7a3SLiteSpeed Tech
645392f7a3SLiteSpeed Techstruct transport_params
655392f7a3SLiteSpeed Tech{
665392f7a3SLiteSpeed Tech    enum trapa_flags        tp_flags;
675392f7a3SLiteSpeed Tech
685392f7a3SLiteSpeed Tech    union {
695392f7a3SLiteSpeed Tech        struct {
705392f7a3SLiteSpeed Tech            uint64_t init_max_stream_data_bidi_local;
715392f7a3SLiteSpeed Tech            uint64_t init_max_stream_data_bidi_remote;
725392f7a3SLiteSpeed Tech            uint64_t init_max_stream_data_uni;
735392f7a3SLiteSpeed Tech            uint64_t init_max_data;
745392f7a3SLiteSpeed Tech            uint64_t idle_timeout;
755392f7a3SLiteSpeed Tech            uint64_t init_max_streams_bidi;
765392f7a3SLiteSpeed Tech            uint64_t init_max_streams_uni;
775392f7a3SLiteSpeed Tech            uint64_t max_packet_size;
785392f7a3SLiteSpeed Tech            uint64_t ack_delay_exponent;
795392f7a3SLiteSpeed Tech            uint64_t max_ack_delay;
805392f7a3SLiteSpeed Tech            uint64_t active_connection_id_limit;
815392f7a3SLiteSpeed Tech        }               s;
82ff892190SDmitri Tikhonov        uint64_t        a[11];
835392f7a3SLiteSpeed Tech    }           tp_numerics_u;
845392f7a3SLiteSpeed Tech#define tp_init_max_stream_data_bidi_local tp_numerics_u.s.init_max_stream_data_bidi_local
855392f7a3SLiteSpeed Tech#define tp_init_max_stream_data_bidi_remote tp_numerics_u.s.init_max_stream_data_bidi_remote
865392f7a3SLiteSpeed Tech#define tp_init_max_stream_data_uni tp_numerics_u.s.init_max_stream_data_uni
875392f7a3SLiteSpeed Tech#define tp_init_max_data tp_numerics_u.s.init_max_data
885392f7a3SLiteSpeed Tech#define tp_idle_timeout tp_numerics_u.s.idle_timeout
895392f7a3SLiteSpeed Tech#define tp_init_max_streams_bidi tp_numerics_u.s.init_max_streams_bidi
905392f7a3SLiteSpeed Tech#define tp_init_max_streams_uni tp_numerics_u.s.init_max_streams_uni
915392f7a3SLiteSpeed Tech#define tp_max_packet_size tp_numerics_u.s.max_packet_size
925392f7a3SLiteSpeed Tech#define tp_ack_delay_exponent tp_numerics_u.s.ack_delay_exponent
935392f7a3SLiteSpeed Tech#define tp_max_ack_delay tp_numerics_u.s.max_ack_delay
945392f7a3SLiteSpeed Tech#define tp_active_connection_id_limit tp_numerics_u.s.active_connection_id_limit
955392f7a3SLiteSpeed Tech
9692f6e17bSDmitri Tikhonov    signed char tp_disable_active_migration;
975392f7a3SLiteSpeed Tech    uint8_t     tp_stateless_reset_token[IQUIC_SRESET_TOKEN_SZ];
985392f7a3SLiteSpeed Tech    struct {
995392f7a3SLiteSpeed Tech        uint8_t         ipv4_addr[4];
1005392f7a3SLiteSpeed Tech        uint16_t        ipv4_port;
1015392f7a3SLiteSpeed Tech        uint8_t         ipv6_addr[16];
1025392f7a3SLiteSpeed Tech        uint16_t        ipv6_port;
1035392f7a3SLiteSpeed Tech        lsquic_cid_t    cid;
1045392f7a3SLiteSpeed Tech        uint8_t         srst[IQUIC_SRESET_TOKEN_SZ];
1055392f7a3SLiteSpeed Tech    }           tp_preferred_address;
1065392f7a3SLiteSpeed Tech    lsquic_cid_t    tp_original_cid;
1075392f7a3SLiteSpeed Tech};
1085392f7a3SLiteSpeed Tech
1095392f7a3SLiteSpeed Tech#define TP_DEF_MAX_PACKET_SIZE 65527
1105392f7a3SLiteSpeed Tech#define TP_DEF_ACK_DELAY_EXP 3
1115392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAMS_UNI 0
1125392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAMS_BIDI 0
1135392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_DATA 0
11492f6e17bSDmitri Tikhonov#define TP_DEF_DISABLE_ACTIVE_MIGRATION 0
1155392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL 0
1165392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE 0
1175392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_UNI 0
1185392f7a3SLiteSpeed Tech#define TP_DEF_IDLE_TIMEOUT 0
1195392f7a3SLiteSpeed Tech#define TP_DEF_MAX_ACK_DELAY 25
1205392f7a3SLiteSpeed Tech#define TP_DEF_ACTIVE_CONNECTION_ID_LIMIT 0
1215392f7a3SLiteSpeed Tech
1225392f7a3SLiteSpeed Tech/* [draft-ietf-quic-transport-18], Section 18.1 */
1235392f7a3SLiteSpeed Tech#define TP_MAX_MAX_ACK_DELAY ((1u << 14) - 1)
1245392f7a3SLiteSpeed Tech
1255392f7a3SLiteSpeed Tech#define TP_DEFAULT_VALUES                                                             \
1265392f7a3SLiteSpeed Tech    .tp_active_connection_id_limit        =  TP_DEF_ACTIVE_CONNECTION_ID_LIMIT,       \
1275392f7a3SLiteSpeed Tech    .tp_idle_timeout                      =  TP_DEF_IDLE_TIMEOUT,                     \
1285392f7a3SLiteSpeed Tech    .tp_max_ack_delay                     =  TP_DEF_MAX_ACK_DELAY,                    \
1295392f7a3SLiteSpeed Tech    .tp_max_packet_size                   =  TP_DEF_MAX_PACKET_SIZE,                  \
1305392f7a3SLiteSpeed Tech    .tp_ack_delay_exponent                =  TP_DEF_ACK_DELAY_EXP,                    \
1315392f7a3SLiteSpeed Tech    .tp_init_max_streams_bidi             =  TP_DEF_INIT_MAX_STREAMS_BIDI,            \
1325392f7a3SLiteSpeed Tech    .tp_init_max_streams_uni              =  TP_DEF_INIT_MAX_STREAMS_UNI,             \
1335392f7a3SLiteSpeed Tech    .tp_init_max_data                     =  TP_DEF_INIT_MAX_DATA,                    \
13492f6e17bSDmitri Tikhonov    .tp_disable_active_migration          =  TP_DEF_DISABLE_ACTIVE_MIGRATION,         \
1355392f7a3SLiteSpeed Tech    .tp_init_max_stream_data_bidi_local   =  TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL,  \
1365392f7a3SLiteSpeed Tech    .tp_init_max_stream_data_bidi_remote  =  TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE, \
1375392f7a3SLiteSpeed Tech    .tp_init_max_stream_data_uni          =  TP_DEF_INIT_MAX_STREAM_DATA_UNI
1385392f7a3SLiteSpeed Tech
1395392f7a3SLiteSpeed Tech#define TP_INITIALIZER() (struct transport_params) { TP_DEFAULT_VALUES }
1405392f7a3SLiteSpeed Tech
1415392f7a3SLiteSpeed Techint
1425392f7a3SLiteSpeed Techlsquic_tp_encode (const struct transport_params *,
1435392f7a3SLiteSpeed Tech                  unsigned char *buf, size_t bufsz);
1445392f7a3SLiteSpeed Tech
1455392f7a3SLiteSpeed Techint
1465392f7a3SLiteSpeed Techlsquic_tp_decode (const unsigned char *buf, size_t bufsz,
1475392f7a3SLiteSpeed Tech    /* This argument specifies whose transport parameters we are parsing.  If
1485392f7a3SLiteSpeed Tech     * true, we are parsing parameters sent by the server; if false, we are
1495392f7a3SLiteSpeed Tech     * parsing parameteres sent by the client.
1505392f7a3SLiteSpeed Tech     */
1515392f7a3SLiteSpeed Tech                  int is_server,
1525392f7a3SLiteSpeed Tech                  struct transport_params *);
1535392f7a3SLiteSpeed Tech
1545392f7a3SLiteSpeed Techvoid
1555392f7a3SLiteSpeed Techlsquic_tp_to_str (const struct transport_params *params, char *buf, size_t sz);
1565392f7a3SLiteSpeed Tech
1575392f7a3SLiteSpeed Tech#endif
158