lsquic_trans_params.h revision 92f6e17b
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}; 55 56struct transport_params 57{ 58 enum trapa_flags tp_flags; 59 60 union { 61 struct { 62 uint64_t init_max_stream_data_bidi_local; 63 uint64_t init_max_stream_data_bidi_remote; 64 uint64_t init_max_stream_data_uni; 65 uint64_t init_max_data; 66 uint64_t idle_timeout; 67 uint64_t init_max_streams_bidi; 68 uint64_t init_max_streams_uni; 69 uint64_t max_packet_size; 70 uint64_t ack_delay_exponent; 71 uint64_t max_ack_delay; 72 uint64_t active_connection_id_limit; 73 } s; 74 uint64_t a[10]; 75 } tp_numerics_u; 76#define tp_init_max_stream_data_bidi_local tp_numerics_u.s.init_max_stream_data_bidi_local 77#define tp_init_max_stream_data_bidi_remote tp_numerics_u.s.init_max_stream_data_bidi_remote 78#define tp_init_max_stream_data_uni tp_numerics_u.s.init_max_stream_data_uni 79#define tp_init_max_data tp_numerics_u.s.init_max_data 80#define tp_idle_timeout tp_numerics_u.s.idle_timeout 81#define tp_init_max_streams_bidi tp_numerics_u.s.init_max_streams_bidi 82#define tp_init_max_streams_uni tp_numerics_u.s.init_max_streams_uni 83#define tp_max_packet_size tp_numerics_u.s.max_packet_size 84#define tp_ack_delay_exponent tp_numerics_u.s.ack_delay_exponent 85#define tp_max_ack_delay tp_numerics_u.s.max_ack_delay 86#define tp_active_connection_id_limit tp_numerics_u.s.active_connection_id_limit 87 88 signed char tp_disable_active_migration; 89 uint8_t tp_stateless_reset_token[IQUIC_SRESET_TOKEN_SZ]; 90 struct { 91 uint8_t ipv4_addr[4]; 92 uint16_t ipv4_port; 93 uint8_t ipv6_addr[16]; 94 uint16_t ipv6_port; 95 lsquic_cid_t cid; 96 uint8_t srst[IQUIC_SRESET_TOKEN_SZ]; 97 } tp_preferred_address; 98 lsquic_cid_t tp_original_cid; 99}; 100 101#define TP_DEF_MAX_PACKET_SIZE 65527 102#define TP_DEF_ACK_DELAY_EXP 3 103#define TP_DEF_INIT_MAX_STREAMS_UNI 0 104#define TP_DEF_INIT_MAX_STREAMS_BIDI 0 105#define TP_DEF_INIT_MAX_DATA 0 106#define TP_DEF_DISABLE_ACTIVE_MIGRATION 0 107#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL 0 108#define TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE 0 109#define TP_DEF_INIT_MAX_STREAM_DATA_UNI 0 110#define TP_DEF_IDLE_TIMEOUT 0 111#define TP_DEF_MAX_ACK_DELAY 25 112#define TP_DEF_ACTIVE_CONNECTION_ID_LIMIT 0 113 114/* [draft-ietf-quic-transport-18], Section 18.1 */ 115#define TP_MAX_MAX_ACK_DELAY ((1u << 14) - 1) 116 117#define TP_DEFAULT_VALUES \ 118 .tp_active_connection_id_limit = TP_DEF_ACTIVE_CONNECTION_ID_LIMIT, \ 119 .tp_idle_timeout = TP_DEF_IDLE_TIMEOUT, \ 120 .tp_max_ack_delay = TP_DEF_MAX_ACK_DELAY, \ 121 .tp_max_packet_size = TP_DEF_MAX_PACKET_SIZE, \ 122 .tp_ack_delay_exponent = TP_DEF_ACK_DELAY_EXP, \ 123 .tp_init_max_streams_bidi = TP_DEF_INIT_MAX_STREAMS_BIDI, \ 124 .tp_init_max_streams_uni = TP_DEF_INIT_MAX_STREAMS_UNI, \ 125 .tp_init_max_data = TP_DEF_INIT_MAX_DATA, \ 126 .tp_disable_active_migration = TP_DEF_DISABLE_ACTIVE_MIGRATION, \ 127 .tp_init_max_stream_data_bidi_local = TP_DEF_INIT_MAX_STREAM_DATA_BIDI_LOCAL, \ 128 .tp_init_max_stream_data_bidi_remote = TP_DEF_INIT_MAX_STREAM_DATA_BIDI_REMOTE, \ 129 .tp_init_max_stream_data_uni = TP_DEF_INIT_MAX_STREAM_DATA_UNI 130 131#define TP_INITIALIZER() (struct transport_params) { TP_DEFAULT_VALUES } 132 133int 134lsquic_tp_encode (const struct transport_params *, 135 unsigned char *buf, size_t bufsz); 136 137int 138lsquic_tp_decode (const unsigned char *buf, size_t bufsz, 139 /* This argument specifies whose transport parameters we are parsing. If 140 * true, we are parsing parameters sent by the server; if false, we are 141 * parsing parameteres sent by the client. 142 */ 143 int is_server, 144 struct transport_params *); 145 146void 147lsquic_tp_to_str (const struct transport_params *params, char *buf, size_t sz); 148 149#endif 150