lsquic_mini_conn_ietf.h revision e68b0452
1/* Copyright (c) 2017 - 2020 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 30struct ietf_mini_conn 31{ 32 struct lsquic_conn imc_conn; 33 struct conn_cid_elem imc_cces[3]; 34 struct lsquic_engine_public *imc_enpub; 35 lsquic_time_t imc_created; 36 enum { 37 IMC_ENC_SESS_INITED = 1 << 0, 38 IMC_QUEUED_ACK_INIT = 1 << 1, 39 IMC_QUEUED_ACK_HSK = IMC_QUEUED_ACK_INIT << PNS_HSK, 40 IMC_QUEUED_ACK_APP = IMC_QUEUED_ACK_INIT << PNS_APP, 41 IMC_ERROR = 1 << 4, 42 IMC_HSK_OK = 1 << 5, 43 IMC_HSK_FAILED = 1 << 6, 44 IMC_HAVE_TP = 1 << 7, 45 IMC_RETRY_MODE = 1 << 8, 46 IMC_RETRY_DONE = 1 << 9, 47 IMC_IGNORE_INIT = 1 << 10, 48#define IMCBIT_PNS_BIT_SHIFT 11 49 IMC_MAX_PNS_BIT_0 = 1 << 11, 50 IMC_MAX_PNS_BIT_1 = 1 << 12, 51 IMC_TLS_ALERT = 1 << 13, 52 IMC_ABORT_ERROR = 1 << 14, 53 IMC_ABORT_ISAPP = 1 << 15, 54 IMC_BAD_TRANS_PARAMS = 1 << 16, 55 IMC_ADDR_VALIDATED = 1 << 17, 56 IMC_HSK_PACKET_SENT = 1 << 18, 57 IMC_CLOSE_RECVD = 1 << 19, 58 IMC_PARSE_FAILED = 1 << 20, 59 IMC_PATH_CHANGED = 1 << 21, 60 IMC_HSK_DONE_SENT = 1 << 22, 61 } imc_flags; 62 struct mini_crypto_stream imc_streams[N_ENC_LEVS]; 63 void *imc_stream_ps[N_ENC_LEVS]; 64 struct { 65 struct stream_frame *frame; /* Latest frame - on stack - be careful. */ 66 enum enc_level enc_level; 67 } imc_last_in; 68 TAILQ_HEAD(, lsquic_packet_in) imc_app_packets; 69 TAILQ_HEAD(, lsquic_packet_out) imc_packets_out; 70 TAILQ_HEAD(, stream_frame) imc_crypto_frames; 71 packno_set_t imc_sent_packnos; 72 packno_set_t imc_recvd_packnos[N_PNS]; 73 packno_set_t imc_acked_packnos[N_PNS]; 74 lsquic_time_t imc_largest_recvd[N_PNS]; 75 struct lsquic_rtt_stats imc_rtt_stats; 76 unsigned imc_error_code; 77 unsigned imc_bytes_in; 78 unsigned imc_bytes_out; 79 unsigned short imc_crypto_frames_sz; 80 /* We need to read in the length of ClientHello to check when we have fed 81 * it to the crypto layer. 82 */ 83 unsigned short imc_ch_len; 84 unsigned char imc_next_packno; 85 unsigned char imc_hsk_count; 86 /* We don't send more than eight in the first flight, and so it's OK to 87 * use uint8_t. This value is also used as a boolean: when ECN black 88 * hole is detected, it is set to zero to indicate that black hole 89 * detection is no longer active. 90 */ 91 uint8_t imc_ecn_packnos; 92 uint8_t imc_ack_exp; 93 uint8_t imc_ecn_counts_in[N_PNS][4]; 94 uint8_t imc_ecn_counts_out[N_PNS][4]; 95 uint8_t imc_incoming_ecn; 96 uint8_t imc_tls_alert; 97#define IMICO_MAX_STASHED_FRAMES 10u 98 unsigned char imc_n_crypto_frames; 99 struct network_path imc_path; 100}; 101 102/* [draft-ietf-quic-transport-24] Section 7.4 103 * 104 " Implementations MUST support buffering at least 4096 bytes of data 105 " received in CRYPTO frames out of order. Endpoints MAY choose to 106 " allow more data to be buffered during the handshake. A larger limit 107 " during the handshake could allow for larger keys or credentials to be 108 " exchanged. An endpoint's buffer size does not need to remain 109 " constant during the life of the connection. 110 */ 111#define IMICO_MAX_BUFFERED_CRYPTO (6u * 1024u) 112 113struct lsquic_conn * 114lsquic_mini_conn_ietf_new (struct lsquic_engine_public *, 115 const struct lsquic_packet_in *, 116 enum lsquic_version, int is_ipv4, const struct lsquic_cid *, 117 size_t udp_payload_size); 118 119int 120lsquic_mini_conn_ietf_ecn_ok (const struct ietf_mini_conn *); 121#endif 122