1 #ifndef OSSL_QUIC_CHANNEL_LOCAL_H
2 # define OSSL_QUIC_CHANNEL_LOCAL_H
4 # include "internal/quic_channel.h"
6 # ifndef OPENSSL_NO_QUIC
9 * QUIC Channel Structure
10 * ======================
12 * QUIC channel internals. It is intended that only the QUIC_CHANNEL
13 * implementation and the RX depacketiser be allowed to access this structure
14 * directly. As the RX depacketiser has no state of its own and computes over a
15 * QUIC_CHANNEL structure, it can be viewed as an extention of the QUIC_CHANNEL
16 * implementation. While the RX depacketiser could be provided with adequate
17 * accessors to do what it needs, this would weaken the abstraction provided by
18 * the QUIC_CHANNEL to other components; moreover the coupling of the RX
19 * depacketiser to QUIC_CHANNEL internals is too deep and bespoke to make this
22 * Other components should not include this header.
24 struct quic_channel_st {
29 * Master synchronisation mutex used for thread assisted mode
30 * synchronisation. We don't own this; the instantiator of the channel
31 * passes it to us and is responsible for freeing it after channel
37 * Callback used to get the current time.
39 OSSL_TIME (*now_cb)(void *arg);
43 * The associated TLS 1.3 connection data. Used to provide the handshake
44 * layer; its 'network' side is plugged into the crypto stream for each EL
45 * (other than the 0-RTT EL).
51 * The transport parameter block we will send or have sent.
52 * Freed after sending or when connection is freed.
54 unsigned char *local_transport_params;
56 /* Asynchronous I/O reactor. */
59 /* Our current L4 peer address, if any. */
60 BIO_ADDR cur_peer_addr;
62 /* Network-side read and write BIOs. */
63 BIO *net_rbio, *net_wbio;
66 * Subcomponents of the connection. All of these components are instantiated
69 OSSL_QUIC_TX_PACKETISER *txp;
73 * Connection level FC. The stream_count RXFCs is used to manage
74 * MAX_STREAMS signalling.
78 QUIC_RXFC max_streams_bidi_rxfc, max_streams_uni_rxfc;
81 OSSL_CC_DATA *cc_data;
82 const OSSL_CC_METHOD *cc_method;
86 * RX demuxer. We register incoming DCIDs with this. Since we currently only
87 * support client operation and use one L4 port per connection, we own the
88 * demuxer and register a single zero-length DCID with it.
92 /* Record layers in the TX and RX directions, plus the RX demuxer. */
97 * Send and receive parts of the crypto streams.
98 * crypto_send[QUIC_PN_SPACE_APP] is the 1-RTT crypto stream. There is no
99 * 0-RTT crypto stream.
101 QUIC_SSTREAM *crypto_send[QUIC_PN_SPACE_NUM];
102 QUIC_RSTREAM *crypto_recv[QUIC_PN_SPACE_NUM];
104 /* Internal state. */
106 * Client: The DCID used in the first Initial packet we transmit as a client.
107 * Server: The DCID used in the first Initial packet the client transmitted.
108 * Randomly generated and required by RFC to be at least 8 bytes.
110 QUIC_CONN_ID init_dcid;
113 * Client: The SCID found in the first Initial packet from the server.
114 * Not valid for servers.
115 * Valid if have_received_enc_pkt is set.
117 QUIC_CONN_ID init_scid;
120 * Client only: The SCID found in an incoming Retry packet we handled.
121 * Not valid for servers.
123 QUIC_CONN_ID retry_scid;
125 /* The DCID we currently use to talk to the peer and its sequence num. */
126 QUIC_CONN_ID cur_remote_dcid;
127 uint64_t cur_remote_seq_num;
128 uint64_t cur_retire_prior_to;
129 /* Server only: The DCID we currently expect the peer to use to talk to us. */
130 QUIC_CONN_ID cur_local_dcid;
132 /* Transport parameter values we send to our peer. */
133 uint64_t tx_init_max_stream_data_bidi_local;
134 uint64_t tx_init_max_stream_data_bidi_remote;
135 uint64_t tx_init_max_stream_data_uni;
137 /* Transport parameter values received from server. */
138 uint64_t rx_init_max_stream_data_bidi_local;
139 uint64_t rx_init_max_stream_data_bidi_remote;
140 uint64_t rx_init_max_stream_data_uni;
141 uint64_t rx_max_ack_delay; /* ms */
142 unsigned char rx_ack_delay_exp;
145 * Temporary staging area to store information about the incoming packet we
146 * are currently processing.
148 OSSL_QRX_PKT *qrx_pkt;
151 * Current limit on number of streams we may create. Set by transport
152 * parameters initially and then by MAX_STREAMS frames.
154 uint64_t max_local_streams_bidi;
155 uint64_t max_local_streams_uni;
157 /* The negotiated maximum idle timeout in milliseconds. */
158 uint64_t max_idle_timeout;
161 * Maximum payload size in bytes for datagrams sent to our peer, as
162 * negotiated by transport parameters.
164 uint64_t rx_max_udp_payload_size;
165 /* Maximum active CID limit, as negotiated by transport parameters. */
166 uint64_t rx_active_conn_id_limit;
169 * Used to allocate stream IDs. This is a stream ordinal, i.e., a stream ID
170 * without the low two bits designating type and initiator. Shift and or in
171 * the type bits to convert to a stream ID.
173 uint64_t next_local_stream_ordinal_bidi;
174 uint64_t next_local_stream_ordinal_uni;
177 * Used to track which stream ordinals within a given stream type have been
178 * used by the remote peer. This is an optimisation used to determine
179 * which streams should be implicitly created due to usage of a higher
182 uint64_t next_remote_stream_ordinal_bidi;
183 uint64_t next_remote_stream_ordinal_uni;
186 * Application error code to be used for STOP_SENDING/RESET_STREAM frames
187 * used to autoreject incoming streams.
189 uint64_t incoming_stream_auto_reject_aec;
191 /* Valid if we are in the TERMINATING or TERMINATED states. */
192 QUIC_TERMINATE_CAUSE terminate_cause;
195 * Deadline at which we move to TERMINATING state. Valid if in the
198 OSSL_TIME terminate_deadline;
201 * Deadline at which connection dies due to idle timeout if no further
204 OSSL_TIME idle_deadline;
207 * Deadline at which we should send an ACK-eliciting packet to ensure
208 * idle timeout does not occur.
210 OSSL_TIME ping_deadline;
213 * State tracking. QUIC connection-level state is best represented based on
214 * whether various things have happened yet or not, rather than as an
215 * explicit FSM. We do have a coarse state variable which tracks the basic
216 * state of the connection's lifecycle, but more fine-grained conditions of
217 * the Active state are tracked via flags below. For more details, see
218 * doc/designs/quic-design/connection-state-machine.md. We are in the Open
219 * state if the state is QUIC_CSM_STATE_ACTIVE and handshake_confirmed is
222 unsigned int state : 3;
225 * Have we received at least one encrypted packet from the peer?
226 * (If so, Retry and Version Negotiation messages should no longer
227 * be received and should be ignored if they do occur.)
229 unsigned int have_received_enc_pkt : 1;
232 * Have we sent literally any packet yet? If not, there is no point polling
235 unsigned int have_sent_any_pkt : 1;
238 * Are we currently doing proactive version negotiation?
240 unsigned int doing_proactive_ver_neg : 1;
242 /* We have received transport parameters from the peer. */
243 unsigned int got_remote_transport_params : 1;
246 * This monotonically transitions to 1 once the TLS state machine is
247 * 'complete', meaning that it has both sent a Finished and successfully
248 * verified the peer's Finished (see RFC 9001 s. 4.1.1). Note that it
249 * does not transition to 1 at both peers simultaneously.
251 * Handshake completion is not the same as handshake confirmation (see
254 unsigned int handshake_complete : 1;
257 * This monotonically transitions to 1 once the handshake is confirmed.
258 * This happens on the client when we receive a HANDSHAKE_DONE frame.
259 * At our option, we may also take acknowledgement of any 1-RTT packet
260 * we sent as a handshake confirmation.
262 unsigned int handshake_confirmed : 1;
265 * We are sending Initial packets based on a Retry. This means we definitely
266 * should not receive another Retry, and if we do it is an error.
268 unsigned int doing_retry : 1;
271 * We don't store the current EL here; the TXP asks the QTX which ELs
272 * are provisioned to determine which ELs to use.
275 /* Have statm, qsm been initialised? Used to track cleanup. */
276 unsigned int have_statm : 1;
277 unsigned int have_qsm : 1;
280 * Preferred ELs for transmission and reception. This is not strictly needed
281 * as it can be inferred from what keys we have provisioned, but makes
282 * determining the current EL simpler and faster. A separate EL for
283 * transmission and reception is not strictly necessary but makes things
284 * easier for interoperation with the handshake layer, which likes to invoke
285 * the yield secret callback at different times for TX and RX.
287 unsigned int tx_enc_level : 3;
288 unsigned int rx_enc_level : 3;
290 /* If bit n is set, EL n has been discarded. */
291 unsigned int el_discarded : 4;
294 * While in TERMINATING - CLOSING, set when we should generate a connection
297 unsigned int conn_close_queued : 1;
299 /* Are we in server mode? Never changes after instantiation. */
300 unsigned int is_server : 1;
303 * Set temporarily when the handshake layer has given us a new RX secret.
304 * Used to determine if we need to check our RX queues again.
306 unsigned int have_new_rx_secret : 1;
309 * Have we sent an ack-eliciting packet since the last successful packet
310 * reception? Used to determine when to bump idle timer (see RFC 9000 s.
313 unsigned int have_sent_ack_eliciting_since_rx : 1;
315 /* Should incoming streams automatically be rejected? */
316 unsigned int incoming_stream_auto_reject : 1;