lsquic_trans_params.h revision feca77f5
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 */ 411bdb91d1SDmitri Tikhonov TPI_DISABLE_ACTIVE_MIGRATION, MAX_EMPTY_TPI = TPI_DISABLE_ACTIVE_MIGRATION, 421bdb91d1SDmitri Tikhonov 431bdb91d1SDmitri Tikhonov /* 441bdb91d1SDmitri Tikhonov * Custom handlers: 451bdb91d1SDmitri Tikhonov */ 461bdb91d1SDmitri Tikhonov TPI_PREFERRED_ADDRESS, 471bdb91d1SDmitri Tikhonov TPI_ORIGINAL_CONNECTION_ID, 4803e6b668SDmitri Tikhonov#if LSQUIC_TEST_QUANTUM_READINESS 4903e6b668SDmitri Tikhonov /* https://github.com/quicwg/base-drafts/wiki/Quantum-Readiness-test */ 501bdb91d1SDmitri Tikhonov#define QUANTUM_READY_SZ 1200 511bdb91d1SDmitri Tikhonov TPI_QUANTUM_READINESS, 5203e6b668SDmitri Tikhonov#endif 531bdb91d1SDmitri Tikhonov TPI_STATELESS_RESET_TOKEN, LAST_TPI = TPI_STATELESS_RESET_TOKEN 545392f7a3SLiteSpeed Tech}; 555392f7a3SLiteSpeed Tech 561bdb91d1SDmitri Tikhonov 575392f7a3SLiteSpeed Techstruct transport_params 585392f7a3SLiteSpeed Tech{ 591bdb91d1SDmitri Tikhonov /* Which transport parameters values are set: */ 601bdb91d1SDmitri Tikhonov unsigned tp_set; 611bdb91d1SDmitri Tikhonov 621bdb91d1SDmitri Tikhonov /* Which transport parameters were present (set by the decoder): */ 631bdb91d1SDmitri Tikhonov unsigned tp_decoded; 641bdb91d1SDmitri Tikhonov 651bdb91d1SDmitri Tikhonov uint64_t tp_numerics[MAX_NUMERIC_TPI + 1]; 661bdb91d1SDmitri Tikhonov 671bdb91d1SDmitri Tikhonov#define tp_init_max_stream_data_bidi_local tp_numerics[TPI_INIT_MAX_STREAM_DATA_BIDI_LOCAL] 681bdb91d1SDmitri Tikhonov#define tp_init_max_stream_data_bidi_remote tp_numerics[TPI_INIT_MAX_STREAM_DATA_BIDI_REMOTE] 691bdb91d1SDmitri Tikhonov#define tp_init_max_stream_data_uni tp_numerics[TPI_INIT_MAX_STREAM_DATA_UNI] 701bdb91d1SDmitri Tikhonov#define tp_init_max_data tp_numerics[TPI_INIT_MAX_DATA] 711bdb91d1SDmitri Tikhonov#define tp_max_idle_timeout tp_numerics[TPI_MAX_IDLE_TIMEOUT] 721bdb91d1SDmitri Tikhonov#define tp_init_max_streams_bidi tp_numerics[TPI_INIT_MAX_STREAMS_BIDI] 731bdb91d1SDmitri Tikhonov#define tp_init_max_streams_uni tp_numerics[TPI_INIT_MAX_STREAMS_UNI] 741bdb91d1SDmitri Tikhonov#define tp_max_packet_size tp_numerics[TPI_MAX_PACKET_SIZE] 751bdb91d1SDmitri Tikhonov#define tp_ack_delay_exponent tp_numerics[TPI_ACK_DELAY_EXPONENT] 761bdb91d1SDmitri Tikhonov#define tp_max_ack_delay tp_numerics[TPI_MAX_ACK_DELAY] 771bdb91d1SDmitri Tikhonov#define tp_active_connection_id_limit tp_numerics[TPI_ACTIVE_CONNECTION_ID_LIMIT] 781bdb91d1SDmitri Tikhonov#define tp_loss_bits tp_numerics[TPI_LOSS_BITS] 791bdb91d1SDmitri Tikhonov 805392f7a3SLiteSpeed Tech uint8_t tp_stateless_reset_token[IQUIC_SRESET_TOKEN_SZ]; 815392f7a3SLiteSpeed Tech struct { 825392f7a3SLiteSpeed Tech uint8_t ipv4_addr[4]; 835392f7a3SLiteSpeed Tech uint16_t ipv4_port; 845392f7a3SLiteSpeed Tech uint8_t ipv6_addr[16]; 855392f7a3SLiteSpeed Tech uint16_t ipv6_port; 865392f7a3SLiteSpeed Tech lsquic_cid_t cid; 875392f7a3SLiteSpeed Tech uint8_t srst[IQUIC_SRESET_TOKEN_SZ]; 885392f7a3SLiteSpeed Tech } tp_preferred_address; 895392f7a3SLiteSpeed Tech lsquic_cid_t tp_original_cid; 905392f7a3SLiteSpeed Tech}; 915392f7a3SLiteSpeed Tech 925392f7a3SLiteSpeed Tech#define TP_DEF_MAX_PACKET_SIZE 65527 935392f7a3SLiteSpeed Tech#define TP_DEF_ACK_DELAY_EXP 3 945392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAMS_UNI 0 955392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAMS_BIDI 0 965392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_DATA 0 9792f6e17bSDmitri Tikhonov#define TP_DEF_DISABLE_ACTIVE_MIGRATION 0 985392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL 0 995392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE 0 1005392f7a3SLiteSpeed Tech#define TP_DEF_INIT_MAX_STREAM_DATA_UNI 0 1019fc12041SDmitri Tikhonov#define TP_DEF_MAX_IDLE_TIMEOUT 0 1025392f7a3SLiteSpeed Tech#define TP_DEF_MAX_ACK_DELAY 25 1039fc12041SDmitri Tikhonov#define TP_DEF_ACTIVE_CONNECTION_ID_LIMIT 2 1045392f7a3SLiteSpeed Tech 1055392f7a3SLiteSpeed Tech/* [draft-ietf-quic-transport-18], Section 18.1 */ 1065392f7a3SLiteSpeed Tech#define TP_MAX_MAX_ACK_DELAY ((1u << 14) - 1) 1075392f7a3SLiteSpeed Tech 1085392f7a3SLiteSpeed Tech#define TP_DEFAULT_VALUES \ 1091bdb91d1SDmitri Tikhonov .tp_set = ((1 << (MAX_NUM_WITH_DEF_TPI + 1)) - 1), \ 1105392f7a3SLiteSpeed Tech .tp_active_connection_id_limit = TP_DEF_ACTIVE_CONNECTION_ID_LIMIT, \ 1119fc12041SDmitri Tikhonov .tp_max_idle_timeout = TP_DEF_MAX_IDLE_TIMEOUT, \ 1125392f7a3SLiteSpeed Tech .tp_max_ack_delay = TP_DEF_MAX_ACK_DELAY, \ 1135392f7a3SLiteSpeed Tech .tp_max_packet_size = TP_DEF_MAX_PACKET_SIZE, \ 1145392f7a3SLiteSpeed Tech .tp_ack_delay_exponent = TP_DEF_ACK_DELAY_EXP, \ 1155392f7a3SLiteSpeed Tech .tp_init_max_streams_bidi = TP_DEF_INIT_MAX_STREAMS_BIDI, \ 1165392f7a3SLiteSpeed Tech .tp_init_max_streams_uni = TP_DEF_INIT_MAX_STREAMS_UNI, \ 1175392f7a3SLiteSpeed Tech .tp_init_max_data = TP_DEF_INIT_MAX_DATA, \ 1185392f7a3SLiteSpeed Tech .tp_init_max_stream_data_bidi_local = TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL, \ 1195392f7a3SLiteSpeed Tech .tp_init_max_stream_data_bidi_remote = TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE, \ 1205392f7a3SLiteSpeed Tech .tp_init_max_stream_data_uni = TP_DEF_INIT_MAX_STREAM_DATA_UNI 1215392f7a3SLiteSpeed Tech 1225392f7a3SLiteSpeed Tech#define TP_INITIALIZER() (struct transport_params) { TP_DEFAULT_VALUES } 1235392f7a3SLiteSpeed Tech 1245392f7a3SLiteSpeed Techint 1251bdb91d1SDmitri Tikhonovlsquic_tp_encode (const struct transport_params *, int is_server, 1265392f7a3SLiteSpeed Tech unsigned char *buf, size_t bufsz); 1275392f7a3SLiteSpeed Tech 1285392f7a3SLiteSpeed Techint 1295392f7a3SLiteSpeed Techlsquic_tp_decode (const unsigned char *buf, size_t bufsz, 1305392f7a3SLiteSpeed Tech /* This argument specifies whose transport parameters we are parsing. If 1315392f7a3SLiteSpeed Tech * true, we are parsing parameters sent by the server; if false, we are 1325392f7a3SLiteSpeed Tech * parsing parameteres sent by the client. 1335392f7a3SLiteSpeed Tech */ 1345392f7a3SLiteSpeed Tech int is_server, 1355392f7a3SLiteSpeed Tech struct transport_params *); 1365392f7a3SLiteSpeed Tech 1375392f7a3SLiteSpeed Techvoid 1385392f7a3SLiteSpeed Techlsquic_tp_to_str (const struct transport_params *params, char *buf, size_t sz); 1395392f7a3SLiteSpeed Tech 1401bdb91d1SDmitri Tikhonovint 1411bdb91d1SDmitri Tikhonovlsquic_tp_has_pref_ipv4 (const struct transport_params *); 1421bdb91d1SDmitri Tikhonov 1431bdb91d1SDmitri Tikhonovint 1441bdb91d1SDmitri Tikhonovlsquic_tp_has_pref_ipv6 (const struct transport_params *); 1451bdb91d1SDmitri Tikhonov 1465392f7a3SLiteSpeed Tech#endif 147