lsquic_trans_params.h revision ff892190
1/* Copyright (c) 2017 - 2019 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/* [draft-ietf-quic-transport-17], Section 18 */ 10enum transport_param_id 11{ 12 TPI_ORIGINAL_CONNECTION_ID = 0, 13 TPI_IDLE_TIMEOUT = 1, 14 TPI_STATELESS_RESET_TOKEN = 2, 15 TPI_MAX_PACKET_SIZE = 3, 16 TPI_INIT_MAX_DATA = 4, 17 TPI_INIT_MAX_STREAM_DATA_BIDI_LOCAL = 5, 18 TPI_INIT_MAX_STREAM_DATA_BIDI_REMOTE = 6, 19 TPI_INIT_MAX_STREAM_DATA_UNI = 7, 20 TPI_INIT_MAX_STREAMS_BIDI = 8, 21 TPI_INIT_MAX_STREAMS_UNI = 9, 22 TPI_ACK_DELAY_EXPONENT = 10, 23 TPI_MAX_ACK_DELAY = 11, 24 TPI_DISABLE_ACTIVE_MIGRATION = 12, 25 TPI_PREFERRED_ADDRESS = 13, 26 TPI_ACTIVE_CONNECTION_ID_LIMIT = 14, 27#define MAX_TPI TPI_ACTIVE_CONNECTION_ID_LIMIT 28}; 29 30#define NUMERIC_TRANS_PARAMS (\ 31 (1 << TPI_MAX_PACKET_SIZE) \ 32 |(1 << TPI_INIT_MAX_STREAMS_UNI) \ 33 |(1 << TPI_INIT_MAX_STREAMS_UNI) \ 34 |(1 << TPI_INIT_MAX_STREAMS_BIDI) \ 35 |(1 << TPI_INIT_MAX_DATA) \ 36 |(1 << TPI_INIT_MAX_STREAM_DATA_BIDI_LOCAL) \ 37 |(1 << TPI_INIT_MAX_STREAM_DATA_BIDI_REMOTE) \ 38 |(1 << TPI_INIT_MAX_STREAM_DATA_UNI) \ 39 |(1 << TPI_IDLE_TIMEOUT) \ 40 |(1 << TPI_MAX_ACK_DELAY) \ 41 |(1 << TPI_ACK_DELAY_EXPONENT) \ 42 |(1 << TPI_ACTIVE_CONNECTION_ID_LIMIT) \ 43 ) 44 45#define IQUIC_MAX_SUPP_VERS ((2<<7) - 4)/sizeof(uint32_t) 46 47enum trapa_flags 48{ 49 TRAPA_RESET_TOKEN = 1 << 0, /* Reset token is set */ 50 TRAPA_SERVER = 1 << 1, /* Server transport parameters */ 51 TRAPA_PREFADDR_IPv4 = 1 << 2, /* Preferred IPv4 address is set */ 52 TRAPA_PREFADDR_IPv6 = 1 << 3, /* Preferred IPv6 address is set */ 53 TRAPA_ORIGINAL_CID = 1 << 4, /* Original CID is set */ 54#if LSQUIC_TEST_QUANTUM_READINESS 55#define QUANTUM_READY_SZ 1200 56 /* https://github.com/quicwg/base-drafts/wiki/Quantum-Readiness-test */ 57#define TPI_QUANTUM_READINESS 3127 58 TRAPA_QUANTUM_READY = 1 << 5, /* Include "Quantum Readiness" TP */ 59#endif 60#define TPI_QL_BITS 0x1055 /* 1055 is 133t for "loss" */ 61 TRAPA_QL_BITS = 1 << 6, 62}; 63 64struct transport_params 65{ 66 enum trapa_flags tp_flags; 67 68 union { 69 struct { 70 uint64_t init_max_stream_data_bidi_local; 71 uint64_t init_max_stream_data_bidi_remote; 72 uint64_t init_max_stream_data_uni; 73 uint64_t init_max_data; 74 uint64_t idle_timeout; 75 uint64_t init_max_streams_bidi; 76 uint64_t init_max_streams_uni; 77 uint64_t max_packet_size; 78 uint64_t ack_delay_exponent; 79 uint64_t max_ack_delay; 80 uint64_t active_connection_id_limit; 81 } s; 82 uint64_t a[11]; 83 } tp_numerics_u; 84#define tp_init_max_stream_data_bidi_local tp_numerics_u.s.init_max_stream_data_bidi_local 85#define tp_init_max_stream_data_bidi_remote tp_numerics_u.s.init_max_stream_data_bidi_remote 86#define tp_init_max_stream_data_uni tp_numerics_u.s.init_max_stream_data_uni 87#define tp_init_max_data tp_numerics_u.s.init_max_data 88#define tp_idle_timeout tp_numerics_u.s.idle_timeout 89#define tp_init_max_streams_bidi tp_numerics_u.s.init_max_streams_bidi 90#define tp_init_max_streams_uni tp_numerics_u.s.init_max_streams_uni 91#define tp_max_packet_size tp_numerics_u.s.max_packet_size 92#define tp_ack_delay_exponent tp_numerics_u.s.ack_delay_exponent 93#define tp_max_ack_delay tp_numerics_u.s.max_ack_delay 94#define tp_active_connection_id_limit tp_numerics_u.s.active_connection_id_limit 95 96 signed char tp_disable_active_migration; 97 uint8_t tp_stateless_reset_token[IQUIC_SRESET_TOKEN_SZ]; 98 struct { 99 uint8_t ipv4_addr[4]; 100 uint16_t ipv4_port; 101 uint8_t ipv6_addr[16]; 102 uint16_t ipv6_port; 103 lsquic_cid_t cid; 104 uint8_t srst[IQUIC_SRESET_TOKEN_SZ]; 105 } tp_preferred_address; 106 lsquic_cid_t tp_original_cid; 107}; 108 109#define TP_DEF_MAX_PACKET_SIZE 65527 110#define TP_DEF_ACK_DELAY_EXP 3 111#define TP_DEF_INIT_MAX_STREAMS_UNI 0 112#define TP_DEF_INIT_MAX_STREAMS_BIDI 0 113#define TP_DEF_INIT_MAX_DATA 0 114#define TP_DEF_DISABLE_ACTIVE_MIGRATION 0 115#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL 0 116#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE 0 117#define TP_DEF_INIT_MAX_STREAM_DATA_UNI 0 118#define TP_DEF_IDLE_TIMEOUT 0 119#define TP_DEF_MAX_ACK_DELAY 25 120#define TP_DEF_ACTIVE_CONNECTION_ID_LIMIT 0 121 122/* [draft-ietf-quic-transport-18], Section 18.1 */ 123#define TP_MAX_MAX_ACK_DELAY ((1u << 14) - 1) 124 125#define TP_DEFAULT_VALUES \ 126 .tp_active_connection_id_limit = TP_DEF_ACTIVE_CONNECTION_ID_LIMIT, \ 127 .tp_idle_timeout = TP_DEF_IDLE_TIMEOUT, \ 128 .tp_max_ack_delay = TP_DEF_MAX_ACK_DELAY, \ 129 .tp_max_packet_size = TP_DEF_MAX_PACKET_SIZE, \ 130 .tp_ack_delay_exponent = TP_DEF_ACK_DELAY_EXP, \ 131 .tp_init_max_streams_bidi = TP_DEF_INIT_MAX_STREAMS_BIDI, \ 132 .tp_init_max_streams_uni = TP_DEF_INIT_MAX_STREAMS_UNI, \ 133 .tp_init_max_data = TP_DEF_INIT_MAX_DATA, \ 134 .tp_disable_active_migration = TP_DEF_DISABLE_ACTIVE_MIGRATION, \ 135 .tp_init_max_stream_data_bidi_local = TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL, \ 136 .tp_init_max_stream_data_bidi_remote = TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE, \ 137 .tp_init_max_stream_data_uni = TP_DEF_INIT_MAX_STREAM_DATA_UNI 138 139#define TP_INITIALIZER() (struct transport_params) { TP_DEFAULT_VALUES } 140 141int 142lsquic_tp_encode (const struct transport_params *, 143 unsigned char *buf, size_t bufsz); 144 145int 146lsquic_tp_decode (const unsigned char *buf, size_t bufsz, 147 /* This argument specifies whose transport parameters we are parsing. If 148 * true, we are parsing parameters sent by the server; if false, we are 149 * parsing parameteres sent by the client. 150 */ 151 int is_server, 152 struct transport_params *); 153 154void 155lsquic_tp_to_str (const struct transport_params *params, char *buf, size_t sz); 156 157#endif 158