lsquic_trans_params.h revision bc520ef7
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_PACKET_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_LOSS_BITS, MAX_NUMERIC_TPI = TPI_LOSS_BITS, 37 38 /* 39 * Empty transport parameters: 40 */ 41 TPI_DISABLE_ACTIVE_MIGRATION, MAX_EMPTY_TPI = TPI_DISABLE_ACTIVE_MIGRATION, 42 43 /* 44 * Custom handlers: 45 */ 46 TPI_PREFERRED_ADDRESS, 47 TPI_ORIGINAL_CONNECTION_ID, 48#if LSQUIC_TEST_QUANTUM_READINESS 49 /* https://github.com/quicwg/base-drafts/wiki/Quantum-Readiness-test */ 50#define QUANTUM_READY_SZ 1200 51 TPI_QUANTUM_READINESS, 52#endif 53 TPI_STATELESS_RESET_TOKEN, LAST_TPI = TPI_STATELESS_RESET_TOKEN 54}; 55 56 57struct transport_params 58{ 59 /* Which transport parameters values are set: */ 60 unsigned tp_set; 61 62 /* Which transport parameters were present (set by the decoder): */ 63 unsigned tp_decoded; 64 65 uint64_t tp_numerics[MAX_NUMERIC_TPI + 1]; 66 67#define tp_init_max_stream_data_bidi_local tp_numerics[TPI_INIT_MAX_STREAM_DATA_BIDI_LOCAL] 68#define tp_init_max_stream_data_bidi_remote tp_numerics[TPI_INIT_MAX_STREAM_DATA_BIDI_REMOTE] 69#define tp_init_max_stream_data_uni tp_numerics[TPI_INIT_MAX_STREAM_DATA_UNI] 70#define tp_init_max_data tp_numerics[TPI_INIT_MAX_DATA] 71#define tp_max_idle_timeout tp_numerics[TPI_MAX_IDLE_TIMEOUT] 72#define tp_init_max_streams_bidi tp_numerics[TPI_INIT_MAX_STREAMS_BIDI] 73#define tp_init_max_streams_uni tp_numerics[TPI_INIT_MAX_STREAMS_UNI] 74#define tp_max_packet_size tp_numerics[TPI_MAX_PACKET_SIZE] 75#define tp_ack_delay_exponent tp_numerics[TPI_ACK_DELAY_EXPONENT] 76#define tp_max_ack_delay tp_numerics[TPI_MAX_ACK_DELAY] 77#define tp_active_connection_id_limit tp_numerics[TPI_ACTIVE_CONNECTION_ID_LIMIT] 78#define tp_loss_bits tp_numerics[TPI_LOSS_BITS] 79 80 uint8_t tp_stateless_reset_token[IQUIC_SRESET_TOKEN_SZ]; 81 struct { 82 uint8_t ipv4_addr[4]; 83 uint16_t ipv4_port; 84 uint8_t ipv6_addr[16]; 85 uint16_t ipv6_port; 86 lsquic_cid_t cid; 87 uint8_t srst[IQUIC_SRESET_TOKEN_SZ]; 88 } tp_preferred_address; 89 lsquic_cid_t tp_original_cid; 90}; 91 92#define TP_DEF_MAX_PACKET_SIZE 65527 93#define TP_DEF_ACK_DELAY_EXP 3 94#define TP_DEF_INIT_MAX_STREAMS_UNI 0 95#define TP_DEF_INIT_MAX_STREAMS_BIDI 0 96#define TP_DEF_INIT_MAX_DATA 0 97#define TP_DEF_DISABLE_ACTIVE_MIGRATION 0 98#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL 0 99#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE 0 100#define TP_DEF_INIT_MAX_STREAM_DATA_UNI 0 101#define TP_DEF_MAX_IDLE_TIMEOUT 0 102#define TP_DEF_MAX_ACK_DELAY 25 103#define TP_DEF_ACTIVE_CONNECTION_ID_LIMIT 2 104 105/* [draft-ietf-quic-transport-18], Section 18.1 */ 106#define TP_MAX_MAX_ACK_DELAY ((1u << 14) - 1) 107 108#define TP_DEFAULT_VALUES \ 109 .tp_set = ((1 << (MAX_NUM_WITH_DEF_TPI + 1)) - 1), \ 110 .tp_active_connection_id_limit = TP_DEF_ACTIVE_CONNECTION_ID_LIMIT, \ 111 .tp_max_idle_timeout = TP_DEF_MAX_IDLE_TIMEOUT, \ 112 .tp_max_ack_delay = TP_DEF_MAX_ACK_DELAY, \ 113 .tp_max_packet_size = TP_DEF_MAX_PACKET_SIZE, \ 114 .tp_ack_delay_exponent = TP_DEF_ACK_DELAY_EXP, \ 115 .tp_init_max_streams_bidi = TP_DEF_INIT_MAX_STREAMS_BIDI, \ 116 .tp_init_max_streams_uni = TP_DEF_INIT_MAX_STREAMS_UNI, \ 117 .tp_init_max_data = TP_DEF_INIT_MAX_DATA, \ 118 .tp_init_max_stream_data_bidi_local = TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL, \ 119 .tp_init_max_stream_data_bidi_remote = TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE, \ 120 .tp_init_max_stream_data_uni = TP_DEF_INIT_MAX_STREAM_DATA_UNI 121 122#define TP_INITIALIZER() (struct transport_params) { TP_DEFAULT_VALUES } 123 124int 125lsquic_tp_encode (const struct transport_params *, int is_server, 126 unsigned char *buf, size_t bufsz); 127 128int 129lsquic_tp_decode (const unsigned char *buf, size_t bufsz, 130 /* This argument specifies whose transport parameters we are parsing. If 131 * true, we are parsing parameters sent by the server; if false, we are 132 * parsing parameteres sent by the client. 133 */ 134 int is_server, 135 struct transport_params *); 136 137int 138lsquic_tp_encode_id25 (const struct transport_params *, int is_server, 139 unsigned char *buf, size_t bufsz); 140 141int 142lsquic_tp_decode_id25 (const unsigned char *buf, size_t bufsz, 143 int is_server, struct transport_params *); 144 145void 146lsquic_tp_to_str (const struct transport_params *params, char *buf, size_t sz); 147 148int 149lsquic_tp_has_pref_ipv4 (const struct transport_params *); 150 151int 152lsquic_tp_has_pref_ipv6 (const struct transport_params *); 153 154#endif 155