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