lsquic_trans_params.h revision 5392f7a3
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,
245392f7a3SLiteSpeed Tech    TPI_DISABLE_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 */
545392f7a3SLiteSpeed Tech};
555392f7a3SLiteSpeed Tech
565392f7a3SLiteSpeed Techstruct transport_params
575392f7a3SLiteSpeed Tech{
585392f7a3SLiteSpeed Tech    enum trapa_flags        tp_flags;
595392f7a3SLiteSpeed Tech
605392f7a3SLiteSpeed Tech    union {
615392f7a3SLiteSpeed Tech        struct {
625392f7a3SLiteSpeed Tech            uint64_t init_max_stream_data_bidi_local;
635392f7a3SLiteSpeed Tech            uint64_t init_max_stream_data_bidi_remote;
645392f7a3SLiteSpeed Tech            uint64_t init_max_stream_data_uni;
655392f7a3SLiteSpeed Tech            uint64_t init_max_data;
665392f7a3SLiteSpeed Tech            uint64_t idle_timeout;
675392f7a3SLiteSpeed Tech            uint64_t init_max_streams_bidi;
685392f7a3SLiteSpeed Tech            uint64_t init_max_streams_uni;
695392f7a3SLiteSpeed Tech            uint64_t max_packet_size;
705392f7a3SLiteSpeed Tech            uint64_t ack_delay_exponent;
715392f7a3SLiteSpeed Tech            uint64_t max_ack_delay;
725392f7a3SLiteSpeed Tech            uint64_t active_connection_id_limit;
735392f7a3SLiteSpeed Tech        }               s;
745392f7a3SLiteSpeed Tech        uint64_t        a[10];
755392f7a3SLiteSpeed Tech    }           tp_numerics_u;
765392f7a3SLiteSpeed Tech#define tp_init_max_stream_data_bidi_local tp_numerics_u.s.init_max_stream_data_bidi_local
775392f7a3SLiteSpeed Tech#define tp_init_max_stream_data_bidi_remote tp_numerics_u.s.init_max_stream_data_bidi_remote
785392f7a3SLiteSpeed Tech#define tp_init_max_stream_data_uni tp_numerics_u.s.init_max_stream_data_uni
795392f7a3SLiteSpeed Tech#define tp_init_max_data tp_numerics_u.s.init_max_data
805392f7a3SLiteSpeed Tech#define tp_idle_timeout tp_numerics_u.s.idle_timeout
815392f7a3SLiteSpeed Tech#define tp_init_max_streams_bidi tp_numerics_u.s.init_max_streams_bidi
825392f7a3SLiteSpeed Tech#define tp_init_max_streams_uni tp_numerics_u.s.init_max_streams_uni
835392f7a3SLiteSpeed Tech#define tp_max_packet_size tp_numerics_u.s.max_packet_size
845392f7a3SLiteSpeed Tech#define tp_ack_delay_exponent tp_numerics_u.s.ack_delay_exponent
855392f7a3SLiteSpeed Tech#define tp_max_ack_delay tp_numerics_u.s.max_ack_delay
865392f7a3SLiteSpeed Tech#define tp_active_connection_id_limit tp_numerics_u.s.active_connection_id_limit
875392f7a3SLiteSpeed Tech
885392f7a3SLiteSpeed Tech    signed char tp_disable_migration;
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;
985392f7a3SLiteSpeed Tech    lsquic_cid_t    tp_original_cid;
995392f7a3SLiteSpeed Tech};
1005392f7a3SLiteSpeed Tech
1015392f7a3SLiteSpeed Tech#define TP_DEF_MAX_PACKET_SIZE 65527
1025392f7a3SLiteSpeed Tech#define TP_DEF_ACK_DELAY_EXP 3
1035392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAMS_UNI 0
1045392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAMS_BIDI 0
1055392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_DATA 0
1065392f7a3SLiteSpeed Tech#define TP_DEF_DISABLE_MIGRATION 0
1075392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL 0
1085392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE 0
1095392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_UNI 0
1105392f7a3SLiteSpeed Tech#define TP_DEF_IDLE_TIMEOUT 0
1115392f7a3SLiteSpeed Tech#define TP_DEF_MAX_ACK_DELAY 25
1125392f7a3SLiteSpeed Tech#define TP_DEF_ACTIVE_CONNECTION_ID_LIMIT 0
1135392f7a3SLiteSpeed Tech
1145392f7a3SLiteSpeed Tech/* [draft-ietf-quic-transport-18], Section 18.1 */
1155392f7a3SLiteSpeed Tech#define TP_MAX_MAX_ACK_DELAY ((1u << 14) - 1)
1165392f7a3SLiteSpeed Tech
1175392f7a3SLiteSpeed Tech#define TP_DEFAULT_VALUES                                                             \
1185392f7a3SLiteSpeed Tech    .tp_active_connection_id_limit        =  TP_DEF_ACTIVE_CONNECTION_ID_LIMIT,       \
1195392f7a3SLiteSpeed Tech    .tp_idle_timeout                      =  TP_DEF_IDLE_TIMEOUT,                     \
1205392f7a3SLiteSpeed Tech    .tp_max_ack_delay                     =  TP_DEF_MAX_ACK_DELAY,                    \
1215392f7a3SLiteSpeed Tech    .tp_max_packet_size                   =  TP_DEF_MAX_PACKET_SIZE,                  \
1225392f7a3SLiteSpeed Tech    .tp_ack_delay_exponent                =  TP_DEF_ACK_DELAY_EXP,                    \
1235392f7a3SLiteSpeed Tech    .tp_init_max_streams_bidi             =  TP_DEF_INIT_MAX_STREAMS_BIDI,            \
1245392f7a3SLiteSpeed Tech    .tp_init_max_streams_uni              =  TP_DEF_INIT_MAX_STREAMS_UNI,             \
1255392f7a3SLiteSpeed Tech    .tp_init_max_data                     =  TP_DEF_INIT_MAX_DATA,                    \
1265392f7a3SLiteSpeed Tech    .tp_disable_migration                 =  TP_DEF_DISABLE_MIGRATION,                \
1275392f7a3SLiteSpeed Tech    .tp_init_max_stream_data_bidi_local   =  TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL,  \
1285392f7a3SLiteSpeed Tech    .tp_init_max_stream_data_bidi_remote  =  TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE, \
1295392f7a3SLiteSpeed Tech    .tp_init_max_stream_data_uni          =  TP_DEF_INIT_MAX_STREAM_DATA_UNI
1305392f7a3SLiteSpeed Tech
1315392f7a3SLiteSpeed Tech#define TP_INITIALIZER() (struct transport_params) { TP_DEFAULT_VALUES }
1325392f7a3SLiteSpeed Tech
1335392f7a3SLiteSpeed Techint
1345392f7a3SLiteSpeed Techlsquic_tp_encode (const struct transport_params *,
1355392f7a3SLiteSpeed Tech                  unsigned char *buf, size_t bufsz);
1365392f7a3SLiteSpeed Tech
1375392f7a3SLiteSpeed Techint
1385392f7a3SLiteSpeed Techlsquic_tp_decode (const unsigned char *buf, size_t bufsz,
1395392f7a3SLiteSpeed Tech    /* This argument specifies whose transport parameters we are parsing.  If
1405392f7a3SLiteSpeed Tech     * true, we are parsing parameters sent by the server; if false, we are
1415392f7a3SLiteSpeed Tech     * parsing parameteres sent by the client.
1425392f7a3SLiteSpeed Tech     */
1435392f7a3SLiteSpeed Tech                  int is_server,
1445392f7a3SLiteSpeed Tech                  struct transport_params *);
1455392f7a3SLiteSpeed Tech
1465392f7a3SLiteSpeed Techvoid
1475392f7a3SLiteSpeed Techlsquic_tp_to_str (const struct transport_params *params, char *buf, size_t sz);
1485392f7a3SLiteSpeed Tech
1495392f7a3SLiteSpeed Tech#endif
150