lsquic_trans_params.h revision fb73393f
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, 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, 48fb73393fSDmitri Tikhonov /* CIDs must be in a contiguous range for tp_cids array to work */ 49fb73393fSDmitri Tikhonov#define FIRST_TP_CID TPI_ORIGINAL_DEST_CID 50fb73393fSDmitri Tikhonov TPI_ORIGINAL_DEST_CID, 51fb73393fSDmitri Tikhonov TPI_INITIAL_SOURCE_CID, 52fb73393fSDmitri Tikhonov#define LAST_TP_CID TPI_RETRY_SOURCE_CID 53fb73393fSDmitri Tikhonov TPI_RETRY_SOURCE_CID, 5403e6b668SDmitri Tikhonov#if LSQUIC_TEST_QUANTUM_READINESS 5503e6b668SDmitri Tikhonov /* https://github.com/quicwg/base-drafts/wiki/Quantum-Readiness-test */ 561bdb91d1SDmitri Tikhonov#define QUANTUM_READY_SZ 1200 571bdb91d1SDmitri Tikhonov TPI_QUANTUM_READINESS, 5803e6b668SDmitri Tikhonov#endif 591bdb91d1SDmitri Tikhonov TPI_STATELESS_RESET_TOKEN, LAST_TPI = TPI_STATELESS_RESET_TOKEN 605392f7a3SLiteSpeed Tech}; 615392f7a3SLiteSpeed Tech 62fb73393fSDmitri Tikhonov#define TP_CID_IDX(tpi_) ((tpi_) - FIRST_TP_CID) 63fb73393fSDmitri Tikhonov 641bdb91d1SDmitri Tikhonov 655392f7a3SLiteSpeed Techstruct transport_params 665392f7a3SLiteSpeed Tech{ 671bdb91d1SDmitri Tikhonov /* Which transport parameters values are set: */ 681bdb91d1SDmitri Tikhonov unsigned tp_set; 691bdb91d1SDmitri Tikhonov 701bdb91d1SDmitri Tikhonov /* Which transport parameters were present (set by the decoder): */ 711bdb91d1SDmitri Tikhonov unsigned tp_decoded; 721bdb91d1SDmitri Tikhonov 731bdb91d1SDmitri Tikhonov uint64_t tp_numerics[MAX_NUMERIC_TPI + 1]; 741bdb91d1SDmitri Tikhonov 751bdb91d1SDmitri Tikhonov#define tp_init_max_stream_data_bidi_local tp_numerics[TPI_INIT_MAX_STREAM_DATA_BIDI_LOCAL] 761bdb91d1SDmitri Tikhonov#define tp_init_max_stream_data_bidi_remote tp_numerics[TPI_INIT_MAX_STREAM_DATA_BIDI_REMOTE] 771bdb91d1SDmitri Tikhonov#define tp_init_max_stream_data_uni tp_numerics[TPI_INIT_MAX_STREAM_DATA_UNI] 781bdb91d1SDmitri Tikhonov#define tp_init_max_data tp_numerics[TPI_INIT_MAX_DATA] 791bdb91d1SDmitri Tikhonov#define tp_max_idle_timeout tp_numerics[TPI_MAX_IDLE_TIMEOUT] 801bdb91d1SDmitri Tikhonov#define tp_init_max_streams_bidi tp_numerics[TPI_INIT_MAX_STREAMS_BIDI] 811bdb91d1SDmitri Tikhonov#define tp_init_max_streams_uni tp_numerics[TPI_INIT_MAX_STREAMS_UNI] 82fb73393fSDmitri Tikhonov#define tp_max_udp_payload_size tp_numerics[TPI_MAX_UDP_PAYLOAD_SIZE] 831bdb91d1SDmitri Tikhonov#define tp_ack_delay_exponent tp_numerics[TPI_ACK_DELAY_EXPONENT] 841bdb91d1SDmitri Tikhonov#define tp_max_ack_delay tp_numerics[TPI_MAX_ACK_DELAY] 851bdb91d1SDmitri Tikhonov#define tp_active_connection_id_limit tp_numerics[TPI_ACTIVE_CONNECTION_ID_LIMIT] 861bdb91d1SDmitri Tikhonov#define tp_loss_bits tp_numerics[TPI_LOSS_BITS] 871bdb91d1SDmitri Tikhonov 885392f7a3SLiteSpeed Tech uint8_t tp_stateless_reset_token[IQUIC_SRESET_TOKEN_SZ]; 895392f7a3SLiteSpeed Tech struct { 905392f7a3SLiteSpeed Tech uint8_t ipv4_addr[4]; 915392f7a3SLiteSpeed Tech uint16_t ipv4_port; 925392f7a3SLiteSpeed Tech uint8_t ipv6_addr[16]; 935392f7a3SLiteSpeed Tech uint16_t ipv6_port; 945392f7a3SLiteSpeed Tech lsquic_cid_t cid; 955392f7a3SLiteSpeed Tech uint8_t srst[IQUIC_SRESET_TOKEN_SZ]; 965392f7a3SLiteSpeed Tech } tp_preferred_address; 97fb73393fSDmitri Tikhonov lsquic_cid_t tp_cids[3]; 98fb73393fSDmitri Tikhonov#define tp_original_dest_cid tp_cids[TP_CID_IDX(TPI_ORIGINAL_DEST_CID)] 99fb73393fSDmitri Tikhonov#define tp_initial_source_cid tp_cids[TP_CID_IDX(TPI_INITIAL_SOURCE_CID)] 100fb73393fSDmitri Tikhonov#define tp_retry_source_cid tp_cids[TP_CID_IDX(TPI_RETRY_SOURCE_CID)] 1015392f7a3SLiteSpeed Tech}; 1025392f7a3SLiteSpeed Tech 103fb73393fSDmitri Tikhonov#define MAX_TP_STR_SZ ((LAST_TPI + 1) * \ 104fb73393fSDmitri Tikhonov (34 /* longest entry in tt2str */ + 2 /* semicolon */ + 2 /* colon */) \ 105fb73393fSDmitri Tikhonov + INET_ADDRSTRLEN + INET6_ADDRSTRLEN + 5 /* Port */ * 2 \ 106fb73393fSDmitri Tikhonov + MAX_CID_LEN * 2 * 4 /* there are four CIDs */ \ 107fb73393fSDmitri Tikhonov + 11 * (MAX_NUMERIC_TPI + 1) \ 108fb73393fSDmitri Tikhonov + IQUIC_SRESET_TOKEN_SZ * 2 * 2 /* there are two reset tokens */) 109fb73393fSDmitri Tikhonov 110fb73393fSDmitri Tikhonov#define TP_DEF_MAX_UDP_PAYLOAD_SIZE 65527 1115392f7a3SLiteSpeed Tech#define TP_DEF_ACK_DELAY_EXP 3 1125392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAMS_UNI 0 1135392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAMS_BIDI 0 1145392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_DATA 0 11592f6e17bSDmitri Tikhonov#define TP_DEF_DISABLE_ACTIVE_MIGRATION 0 1165392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL 0 1175392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE 0 1185392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_UNI 0 1199fc12041SDmitri Tikhonov#define TP_DEF_MAX_IDLE_TIMEOUT 0 1205392f7a3SLiteSpeed Tech#define TP_DEF_MAX_ACK_DELAY 25 1219fc12041SDmitri Tikhonov#define TP_DEF_ACTIVE_CONNECTION_ID_LIMIT 2 1225392f7a3SLiteSpeed Tech 1235392f7a3SLiteSpeed Tech/* [draft-ietf-quic-transport-18], Section 18.1 */ 1245392f7a3SLiteSpeed Tech#define TP_MAX_MAX_ACK_DELAY ((1u << 14) - 1) 1255392f7a3SLiteSpeed Tech 1265392f7a3SLiteSpeed Tech#define TP_DEFAULT_VALUES \ 1271bdb91d1SDmitri Tikhonov .tp_set = ((1 << (MAX_NUM_WITH_DEF_TPI + 1)) - 1), \ 1285392f7a3SLiteSpeed Tech .tp_active_connection_id_limit = TP_DEF_ACTIVE_CONNECTION_ID_LIMIT, \ 1299fc12041SDmitri Tikhonov .tp_max_idle_timeout = TP_DEF_MAX_IDLE_TIMEOUT, \ 1305392f7a3SLiteSpeed Tech .tp_max_ack_delay = TP_DEF_MAX_ACK_DELAY, \ 131fb73393fSDmitri Tikhonov .tp_max_udp_payload_size = TP_DEF_MAX_UDP_PAYLOAD_SIZE, \ 1325392f7a3SLiteSpeed Tech .tp_ack_delay_exponent = TP_DEF_ACK_DELAY_EXP, \ 1335392f7a3SLiteSpeed Tech .tp_init_max_streams_bidi = TP_DEF_INIT_MAX_STREAMS_BIDI, \ 1345392f7a3SLiteSpeed Tech .tp_init_max_streams_uni = TP_DEF_INIT_MAX_STREAMS_UNI, \ 1355392f7a3SLiteSpeed Tech .tp_init_max_data = TP_DEF_INIT_MAX_DATA, \ 1365392f7a3SLiteSpeed Tech .tp_init_max_stream_data_bidi_local = TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL, \ 1375392f7a3SLiteSpeed Tech .tp_init_max_stream_data_bidi_remote = TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE, \ 1385392f7a3SLiteSpeed Tech .tp_init_max_stream_data_uni = TP_DEF_INIT_MAX_STREAM_DATA_UNI 1395392f7a3SLiteSpeed Tech 1405392f7a3SLiteSpeed Tech#define TP_INITIALIZER() (struct transport_params) { TP_DEFAULT_VALUES } 1415392f7a3SLiteSpeed Tech 1425392f7a3SLiteSpeed Techint 1431bdb91d1SDmitri Tikhonovlsquic_tp_encode (const struct transport_params *, int is_server, 1445392f7a3SLiteSpeed Tech unsigned char *buf, size_t bufsz); 1455392f7a3SLiteSpeed Tech 1465392f7a3SLiteSpeed Techint 1475392f7a3SLiteSpeed Techlsquic_tp_decode (const unsigned char *buf, size_t bufsz, 1485392f7a3SLiteSpeed Tech /* This argument specifies whose transport parameters we are parsing. If 1495392f7a3SLiteSpeed Tech * true, we are parsing parameters sent by the server; if false, we are 1505392f7a3SLiteSpeed Tech * parsing parameteres sent by the client. 1515392f7a3SLiteSpeed Tech */ 1525392f7a3SLiteSpeed Tech int is_server, 1535392f7a3SLiteSpeed Tech struct transport_params *); 1545392f7a3SLiteSpeed Tech 155fb73393fSDmitri Tikhonovvoid 156fb73393fSDmitri Tikhonovlsquic_tp_to_str (const struct transport_params *params, char *buf, size_t sz); 157fb73393fSDmitri Tikhonov 158bc520ef7SDmitri Tikhonovint 159fb73393fSDmitri Tikhonovlsquic_tp_encode_27 (const struct transport_params *, int is_server, 160bc520ef7SDmitri Tikhonov unsigned char *buf, size_t bufsz); 161bc520ef7SDmitri Tikhonov 162bc520ef7SDmitri Tikhonovint 163fb73393fSDmitri Tikhonovlsquic_tp_decode_27 (const unsigned char *buf, size_t bufsz, 164fb73393fSDmitri Tikhonov int is_server, 165fb73393fSDmitri Tikhonov struct transport_params *); 166bc520ef7SDmitri Tikhonov 1675392f7a3SLiteSpeed Techvoid 168fb73393fSDmitri Tikhonovlsquic_tp_to_str_27 (const struct transport_params *params, char *buf, size_t sz); 1695392f7a3SLiteSpeed Tech 1701bdb91d1SDmitri Tikhonovint 1711bdb91d1SDmitri Tikhonovlsquic_tp_has_pref_ipv4 (const struct transport_params *); 1721bdb91d1SDmitri Tikhonov 1731bdb91d1SDmitri Tikhonovint 1741bdb91d1SDmitri Tikhonovlsquic_tp_has_pref_ipv6 (const struct transport_params *); 1751bdb91d1SDmitri Tikhonov 176fb73393fSDmitri Tikhonovextern const char * const lsquic_tpi2str[LAST_TPI + 1]; 177fb73393fSDmitri Tikhonov 1785392f7a3SLiteSpeed Tech#endif 179