1/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_mini_conn_ietf.h -- Mini connection used by the IETF QUIC 4 */ 5 6#ifndef LSQUIC_MINI_CONN_IETF_H 7#define LSQUIC_MINI_CONN_IETF_H 1 8 9struct lsquic_conn; 10struct lsquic_engine_public; 11struct lsquic_packet_in; 12 13enum { MCSBIT_WANTREAD, MCSBIT_WANTWRITE, }; 14 15struct mini_crypto_stream 16{ 17 unsigned mcs_read_off; 18 unsigned mcs_write_off; 19 enum { 20 MCS_WANTREAD = 1 << MCSBIT_WANTREAD, 21 MCS_WANTWRITE = 1 << MCSBIT_WANTWRITE, 22 MCS_CREATED = 1 << 2, 23 } mcs_flags:8; 24 enum enc_level mcs_enc_level:8; 25}; 26 27typedef uint64_t packno_set_t; 28#define MAX_PACKETS ((sizeof(packno_set_t) * 8) - 1) 29 30/* We do not handle packets in the App packet number space in the mini 31 * connection. They are all buffered to be handled later when the 32 * connection is promoted. This means we do not have to have data 33 * structures to track the App PNS. 34 */ 35#define IMICO_N_PNS (N_PNS - 1) 36 37struct ietf_mini_conn 38{ 39 struct lsquic_conn imc_conn; 40 struct conn_cid_elem imc_cces[3]; 41 struct lsquic_engine_public *imc_enpub; 42 lsquic_time_t imc_created; 43 enum { 44 IMC_ENC_SESS_INITED = 1 << 0, 45 IMC_QUEUED_ACK_INIT = 1 << 1, 46 IMC_QUEUED_ACK_HSK = IMC_QUEUED_ACK_INIT << PNS_HSK, 47 IMC_UNUSED3 = 1 << 3, 48 IMC_ERROR = 1 << 4, 49 IMC_HSK_OK = 1 << 5, 50 IMC_HSK_FAILED = 1 << 6, 51 IMC_HAVE_TP = 1 << 7, 52 IMC_RETRY_MODE = 1 << 8, 53 IMC_RETRY_DONE = 1 << 9, 54 IMC_IGNORE_INIT = 1 << 10, 55#define IMCBIT_PNS_BIT_SHIFT 11 56 IMC_MAX_PNS_BIT_0 = 1 << 11, 57 IMC_MAX_PNS_BIT_1 = 1 << 12, 58 IMC_TLS_ALERT = 1 << 13, 59 IMC_ABORT_ERROR = 1 << 14, 60 IMC_ABORT_ISAPP = 1 << 15, 61 IMC_BAD_TRANS_PARAMS = 1 << 16, 62 IMC_ADDR_VALIDATED = 1 << 17, 63 IMC_HSK_PACKET_SENT = 1 << 18, 64 IMC_CLOSE_RECVD = 1 << 19, 65 IMC_PARSE_FAILED = 1 << 20, 66 IMC_PATH_CHANGED = 1 << 21, 67 IMC_HSK_DONE_SENT = 1 << 22, 68 IMC_TRECHIST = 1 << 23, 69 } imc_flags; 70 struct mini_crypto_stream imc_streams[N_ENC_LEVS]; 71 void *imc_stream_ps[N_ENC_LEVS]; 72 struct { 73 struct stream_frame *frame; /* Latest frame - on stack - be careful. */ 74 enum enc_level enc_level; 75 } imc_last_in; 76 TAILQ_HEAD(, lsquic_packet_in) imc_app_packets; 77 TAILQ_HEAD(, lsquic_packet_out) imc_packets_out; 78 TAILQ_HEAD(, stream_frame) imc_crypto_frames; 79 packno_set_t imc_sent_packnos; 80 union { 81 packno_set_t bitmasks[IMICO_N_PNS]; 82 struct { 83 struct trechist_elem *hist_elems; 84 trechist_mask_t hist_masks[IMICO_N_PNS]; 85 } trechist; 86 } imc_recvd_packnos; 87 packno_set_t imc_acked_packnos[IMICO_N_PNS]; 88 lsquic_time_t imc_largest_recvd[IMICO_N_PNS]; 89 struct lsquic_rtt_stats imc_rtt_stats; 90 unsigned imc_error_code; 91 unsigned imc_bytes_in; 92 unsigned imc_bytes_out; 93 unsigned short imc_crypto_frames_sz; 94 /* We need to read in the length of ClientHello to check when we have fed 95 * it to the crypto layer. 96 */ 97 unsigned short imc_ch_len; 98 unsigned char imc_next_packno; 99 unsigned char imc_hsk_count; 100 /* We don't send more than eight in the first flight, and so it's OK to 101 * use uint8_t. This value is also used as a boolean: when ECN black 102 * hole is detected, it is set to zero to indicate that black hole 103 * detection is no longer active. 104 */ 105 uint8_t imc_ecn_packnos; 106 uint8_t imc_ack_exp; 107 uint8_t imc_ecn_counts_in[IMICO_N_PNS][4]; 108 uint8_t imc_incoming_ecn; 109 uint8_t imc_tls_alert; 110#define IMICO_MAX_DELAYED_PACKETS_UNVALIDATED 1u 111#define IMICO_MAX_DELAYED_PACKETS_VALIDATED 2u 112 unsigned char imc_delayed_packets_count; 113#define IMICO_MAX_STASHED_FRAMES 10u 114 unsigned char imc_n_crypto_frames; 115 struct network_path imc_path; 116}; 117 118/* [draft-ietf-quic-transport-24] Section 7.4 119 * 120 " Implementations MUST support buffering at least 4096 bytes of data 121 " received in CRYPTO frames out of order. Endpoints MAY choose to 122 " allow more data to be buffered during the handshake. A larger limit 123 " during the handshake could allow for larger keys or credentials to be 124 " exchanged. An endpoint's buffer size does not need to remain 125 " constant during the life of the connection. 126 */ 127#define IMICO_MAX_BUFFERED_CRYPTO (6u * 1024u) 128 129struct lsquic_conn * 130lsquic_mini_conn_ietf_new (struct lsquic_engine_public *, 131 const struct lsquic_packet_in *, 132 enum lsquic_version, int is_ipv4, const struct lsquic_cid *, 133 size_t udp_payload_size); 134 135int 136lsquic_mini_conn_ietf_ecn_ok (const struct ietf_mini_conn *); 137 138struct ietf_mini_rechist 139{ 140 const struct ietf_mini_conn *conn; 141 enum packnum_space pns; 142 union { 143 struct { 144 packno_set_t cur_set; 145 struct lsquic_packno_range range; /* We return a pointer to this */ 146 int cur_idx; 147 } bitmask; 148 struct trechist_iter trechist_iter; 149 } u; 150}; 151 152void 153lsquic_imico_rechist_init (struct ietf_mini_rechist *rechist, 154 const struct ietf_mini_conn *conn, enum packnum_space pns); 155 156const struct lsquic_packno_range * 157lsquic_imico_rechist_first (void *rechist_ctx); 158 159const struct lsquic_packno_range * 160lsquic_imico_rechist_next (void *rechist_ctx); 161 162#endif 163