lsquic_trans_params.h revision b1a7c3f9
1/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_trans_params.h -- Transport parameters types and functions. 4 */ 5 6#ifndef LSQUIC_TRANS_PARAMS_H 7#define LSQUIC_TRANS_PARAMS_H 1 8 9/* Transport parameters are grouped by the type of their values: numeric, 10 * empty, and custom. 11 * 12 * The enum values are arbitrary. The literal transport parameter ID 13 * *values* (e.g. 0x1057 for loss bits) are not exposed by the API. 14 */ 15enum transport_param_id 16{ 17 /* 18 * Numeric transport parameters that have default values: 19 */ 20 TPI_MAX_IDLE_TIMEOUT, 21 TPI_MAX_UDP_PAYLOAD_SIZE, 22 TPI_INIT_MAX_DATA, 23 TPI_INIT_MAX_STREAM_DATA_BIDI_LOCAL, 24 TPI_INIT_MAX_STREAM_DATA_BIDI_REMOTE, 25 TPI_INIT_MAX_STREAM_DATA_UNI, 26 TPI_INIT_MAX_STREAMS_BIDI, 27 TPI_INIT_MAX_STREAMS_UNI, 28 TPI_ACK_DELAY_EXPONENT, 29 TPI_MAX_ACK_DELAY, 30 TPI_ACTIVE_CONNECTION_ID_LIMIT, MAX_NUM_WITH_DEF_TPI = TPI_ACTIVE_CONNECTION_ID_LIMIT, 31 32 /* 33 * Numeric transport parameters without default values: 34 */ 35 TPI_MIN_ACK_DELAY, 36 TPI_TIMESTAMPS, 37 TPI_MAX_DATAGRAM_FRAME_SIZE, 38 TPI_LOSS_BITS, MAX_NUMERIC_TPI = TPI_LOSS_BITS, 39 40 /* 41 * Empty transport parameters: 42 */ 43 TPI_GREASE_QUIC_BIT, 44 TPI_DISABLE_ACTIVE_MIGRATION, MAX_EMPTY_TPI = TPI_DISABLE_ACTIVE_MIGRATION, 45 46 /* 47 * Custom handlers: 48 */ 49 TPI_PREFERRED_ADDRESS, 50 /* CIDs must be in a contiguous range for tp_cids array to work */ 51#define FIRST_TP_CID TPI_ORIGINAL_DEST_CID 52 TPI_ORIGINAL_DEST_CID, 53 TPI_INITIAL_SOURCE_CID, 54#define LAST_TP_CID TPI_RETRY_SOURCE_CID 55 TPI_RETRY_SOURCE_CID, 56#if LSQUIC_TEST_QUANTUM_READINESS 57 TPI_QUANTUM_READINESS, 58#endif 59 TPI_STATELESS_RESET_TOKEN, LAST_TPI = TPI_STATELESS_RESET_TOKEN 60}; 61 62#define TP_CID_IDX(tpi_) ((tpi_) - FIRST_TP_CID) 63 64 65struct transport_params 66{ 67 /* Which transport parameters values are set: */ 68 unsigned tp_set; 69 70 /* Which transport parameters were present (set by the decoder): */ 71 unsigned tp_decoded; 72 73 uint64_t tp_numerics[MAX_NUMERIC_TPI + 1]; 74 75#define tp_init_max_stream_data_bidi_local tp_numerics[TPI_INIT_MAX_STREAM_DATA_BIDI_LOCAL] 76#define tp_init_max_stream_data_bidi_remote tp_numerics[TPI_INIT_MAX_STREAM_DATA_BIDI_REMOTE] 77#define tp_init_max_stream_data_uni tp_numerics[TPI_INIT_MAX_STREAM_DATA_UNI] 78#define tp_init_max_data tp_numerics[TPI_INIT_MAX_DATA] 79#define tp_max_idle_timeout tp_numerics[TPI_MAX_IDLE_TIMEOUT] 80#define tp_init_max_streams_bidi tp_numerics[TPI_INIT_MAX_STREAMS_BIDI] 81#define tp_init_max_streams_uni tp_numerics[TPI_INIT_MAX_STREAMS_UNI] 82#define tp_max_udp_payload_size tp_numerics[TPI_MAX_UDP_PAYLOAD_SIZE] 83#define tp_ack_delay_exponent tp_numerics[TPI_ACK_DELAY_EXPONENT] 84#define tp_max_ack_delay tp_numerics[TPI_MAX_ACK_DELAY] 85#define tp_active_connection_id_limit tp_numerics[TPI_ACTIVE_CONNECTION_ID_LIMIT] 86#define tp_loss_bits tp_numerics[TPI_LOSS_BITS] 87 88 uint8_t tp_stateless_reset_token[IQUIC_SRESET_TOKEN_SZ]; 89 struct { 90 uint8_t ipv4_addr[4]; 91 uint16_t ipv4_port; 92 uint8_t ipv6_addr[16]; 93 uint16_t ipv6_port; 94 lsquic_cid_t cid; 95 uint8_t srst[IQUIC_SRESET_TOKEN_SZ]; 96 } tp_preferred_address; 97 lsquic_cid_t tp_cids[3]; 98#define tp_original_dest_cid tp_cids[TP_CID_IDX(TPI_ORIGINAL_DEST_CID)] 99#define tp_initial_source_cid tp_cids[TP_CID_IDX(TPI_INITIAL_SOURCE_CID)] 100#define tp_retry_source_cid tp_cids[TP_CID_IDX(TPI_RETRY_SOURCE_CID)] 101}; 102 103#define MAX_TP_STR_SZ ((LAST_TPI + 1) * \ 104 (34 /* longest entry in tt2str */ + 2 /* semicolon */ + 2 /* colon */) \ 105 + INET_ADDRSTRLEN + INET6_ADDRSTRLEN + 5 /* Port */ * 2 \ 106 + MAX_CID_LEN * 2 * 4 /* there are four CIDs */ \ 107 + 11 * (MAX_NUMERIC_TPI + 1) \ 108 + IQUIC_SRESET_TOKEN_SZ * 2 * 2 /* there are two reset tokens */) 109 110#define TP_DEF_MAX_UDP_PAYLOAD_SIZE 65527 111#define TP_DEF_ACK_DELAY_EXP 3 112#define TP_DEF_INIT_MAX_STREAMS_UNI 0 113#define TP_DEF_INIT_MAX_STREAMS_BIDI 0 114#define TP_DEF_INIT_MAX_DATA 0 115#define TP_DEF_DISABLE_ACTIVE_MIGRATION 0 116#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL 0 117#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE 0 118#define TP_DEF_INIT_MAX_STREAM_DATA_UNI 0 119#define TP_DEF_MAX_IDLE_TIMEOUT 0 120#define TP_DEF_MAX_ACK_DELAY 25 121#define TP_DEF_ACTIVE_CONNECTION_ID_LIMIT 2 122 123/* [draft-ietf-quic-transport-18], Section 18.1 */ 124#define TP_MAX_MAX_ACK_DELAY ((1u << 14) - 1) 125 126#define TP_DEFAULT_VALUES \ 127 .tp_set = ((1 << (MAX_NUM_WITH_DEF_TPI + 1)) - 1), \ 128 .tp_active_connection_id_limit = TP_DEF_ACTIVE_CONNECTION_ID_LIMIT, \ 129 .tp_max_idle_timeout = TP_DEF_MAX_IDLE_TIMEOUT, \ 130 .tp_max_ack_delay = TP_DEF_MAX_ACK_DELAY, \ 131 .tp_max_udp_payload_size = TP_DEF_MAX_UDP_PAYLOAD_SIZE, \ 132 .tp_ack_delay_exponent = TP_DEF_ACK_DELAY_EXP, \ 133 .tp_init_max_streams_bidi = TP_DEF_INIT_MAX_STREAMS_BIDI, \ 134 .tp_init_max_streams_uni = TP_DEF_INIT_MAX_STREAMS_UNI, \ 135 .tp_init_max_data = TP_DEF_INIT_MAX_DATA, \ 136 .tp_init_max_stream_data_bidi_local = TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL, \ 137 .tp_init_max_stream_data_bidi_remote = TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE, \ 138 .tp_init_max_stream_data_uni = TP_DEF_INIT_MAX_STREAM_DATA_UNI 139 140#define TP_INITIALIZER() (struct transport_params) { TP_DEFAULT_VALUES } 141 142int 143lsquic_tp_encode (const struct transport_params *, int is_server, 144 unsigned char *const buf, size_t bufsz); 145 146int 147lsquic_tp_decode (const unsigned char *const buf, size_t bufsz, 148 /* This argument specifies whose transport parameters we are parsing. If 149 * true, we are parsing parameters sent by the server; if false, we are 150 * parsing parameteres sent by the client. 151 */ 152 int is_server, 153 struct transport_params *); 154 155void 156lsquic_tp_to_str (const struct transport_params *params, char *buf, size_t sz); 157 158int 159lsquic_tp_encode_27 (const struct transport_params *, int is_server, 160 unsigned char *const buf, size_t bufsz); 161 162int 163lsquic_tp_decode_27 (const unsigned char *const buf, size_t bufsz, 164 int is_server, 165 struct transport_params *); 166 167void 168lsquic_tp_to_str_27 (const struct transport_params *params, char *buf, size_t sz); 169 170int 171lsquic_tp_has_pref_ipv4 (const struct transport_params *); 172 173int 174lsquic_tp_has_pref_ipv6 (const struct transport_params *); 175 176extern const char * const lsquic_tpi2str[LAST_TPI + 1]; 177 178/* From [draft-huitema-quic-ts-03] */ 179#define TS_WANT_THEM 1 180#define TS_GENERATE_THEM 2 181 182#if LSQUIC_TEST_QUANTUM_READINESS 183size_t 184lsquic_tp_get_quantum_sz (void); 185#endif 186 187#endif 188