Path: blob/main/crypto/openssl/ssl/quic/quic_channel_local.h
48262 views
#ifndef OSSL_QUIC_CHANNEL_LOCAL_H1# define OSSL_QUIC_CHANNEL_LOCAL_H23# include "internal/quic_channel.h"45# ifndef OPENSSL_NO_QUIC67# include <openssl/lhash.h>8# include "internal/list.h"9# include "internal/quic_predef.h"10# include "internal/quic_fc.h"11# include "internal/quic_stream_map.h"12# include "internal/quic_tls.h"1314/*15* QUIC Channel Structure16* ======================17*18* QUIC channel internals. It is intended that only the QUIC_CHANNEL19* implementation and the RX depacketiser be allowed to access this structure20* directly. As the RX depacketiser has no state of its own and computes over a21* QUIC_CHANNEL structure, it can be viewed as an extension of the QUIC_CHANNEL22* implementation. While the RX depacketiser could be provided with adequate23* accessors to do what it needs, this would weaken the abstraction provided by24* the QUIC_CHANNEL to other components; moreover the coupling of the RX25* depacketiser to QUIC_CHANNEL internals is too deep and bespoke to make this26* desirable.27*28* Other components should not include this header.29*/30struct quic_channel_st {31QUIC_PORT *port;3233/*34* QUIC_PORT keeps the channels which belong to it on a list for bookkeeping35* purposes.36*/37OSSL_LIST_MEMBER(ch, QUIC_CHANNEL);38OSSL_LIST_MEMBER(incoming_ch, QUIC_CHANNEL);3940/*41* The associated TLS 1.3 connection data. Used to provide the handshake42* layer; its 'network' side is plugged into the crypto stream for each EL43* (other than the 0-RTT EL). Note that the `tls` SSL object is not "owned"44* by this channel. It is created and managed elsewhere and is guaranteed45* to be valid for the lifetime of the channel. Therefore we do not free it46* when we free the channel.47*/48QUIC_TLS *qtls;49SSL *tls;5051/* Port LCIDM we use to register LCIDs. */52QUIC_LCIDM *lcidm;53/* SRTM we register SRTs with. */54QUIC_SRTM *srtm;5556/* Optional QLOG instance (or NULL). */57QLOG *qlog;5859/*60* The transport parameter block we will send or have sent.61* Freed after sending or when connection is freed.62*/63unsigned char *local_transport_params;6465/*66* Pending new token to send once handshake is complete67*/68uint8_t *pending_new_token;69size_t pending_new_token_len;7071/* Our current L4 peer address, if any. */72BIO_ADDR cur_peer_addr;7374/*75* Subcomponents of the connection. All of these components are instantiated76* and owned by us.77*/78OSSL_QUIC_TX_PACKETISER *txp;79QUIC_TXPIM *txpim;80QUIC_CFQ *cfq;81/*82* Connection level FC. The stream_count RXFCs is used to manage83* MAX_STREAMS signalling.84*/85QUIC_TXFC conn_txfc;86QUIC_RXFC conn_rxfc, crypto_rxfc[QUIC_PN_SPACE_NUM];87QUIC_RXFC max_streams_bidi_rxfc, max_streams_uni_rxfc;88QUIC_STREAM_MAP qsm;89OSSL_STATM statm;90OSSL_CC_DATA *cc_data;91const OSSL_CC_METHOD *cc_method;92OSSL_ACKM *ackm;9394/* Record layers in the TX and RX directions. */95OSSL_QTX *qtx;96OSSL_QRX *qrx;9798/* Message callback related arguments */99ossl_msg_cb msg_callback;100void *msg_callback_arg;101SSL *msg_callback_ssl;102103/*104* Send and receive parts of the crypto streams.105* crypto_send[QUIC_PN_SPACE_APP] is the 1-RTT crypto stream. There is no106* 0-RTT crypto stream.107*/108QUIC_SSTREAM *crypto_send[QUIC_PN_SPACE_NUM];109QUIC_RSTREAM *crypto_recv[QUIC_PN_SPACE_NUM];110111/* Internal state. */112/*113* Client: The DCID used in the first Initial packet we transmit as a client.114* Server: The DCID used in the first Initial packet the client transmitted.115* Randomly generated and required by RFC to be at least 8 bytes.116*/117QUIC_CONN_ID init_dcid;118119/*120* Server: If this channel is created in response to an init packet sent121* after the server has sent a retry packet to do address validation, this122* field stores the original connection id from the first init packet sent123*/124QUIC_CONN_ID odcid;125126/*127* Client: The SCID found in the first Initial packet from the server.128* Not valid for servers.129* Valid if have_received_enc_pkt is set.130*/131QUIC_CONN_ID init_scid;132133/*134* Client only: The SCID found in an incoming Retry packet we handled.135* Not valid for servers.136*/137QUIC_CONN_ID retry_scid;138139/* Server only: The DCID we currently expect the peer to use to talk to us. */140QUIC_CONN_ID cur_local_cid;141142/*143* The DCID we currently use to talk to the peer and its sequence num.144*/145QUIC_CONN_ID cur_remote_dcid;146uint64_t cur_remote_seq_num;147uint64_t cur_retire_prior_to;148149/* Transport parameter values we send to our peer. */150uint64_t tx_init_max_stream_data_bidi_local;151uint64_t tx_init_max_stream_data_bidi_remote;152uint64_t tx_init_max_stream_data_uni;153uint64_t tx_max_ack_delay; /* ms */154155/* Transport parameter values received from server. */156uint64_t rx_init_max_stream_data_bidi_local;157uint64_t rx_init_max_stream_data_bidi_remote;158uint64_t rx_init_max_stream_data_uni;159uint64_t rx_max_ack_delay; /* ms */160unsigned char rx_ack_delay_exp;161162/* Diagnostic counters for testing purposes only. May roll over. */163uint16_t diag_num_rx_ack; /* Number of ACK frames received */164165/*166* Temporary staging area to store information about the incoming packet we167* are currently processing.168*/169OSSL_QRX_PKT *qrx_pkt;170171/*172* Current limit on number of streams we may create. Set by transport173* parameters initially and then by MAX_STREAMS frames.174*/175uint64_t max_local_streams_bidi;176uint64_t max_local_streams_uni;177178/* The idle timeout values we and our peer requested. */179uint64_t max_idle_timeout_local_req;180uint64_t max_idle_timeout_remote_req;181182/* The negotiated maximum idle timeout in milliseconds. */183uint64_t max_idle_timeout;184185/*186* Maximum payload size in bytes for datagrams sent to our peer, as187* negotiated by transport parameters.188*/189uint64_t rx_max_udp_payload_size;190/* Maximum active CID limit, as negotiated by transport parameters. */191uint64_t rx_active_conn_id_limit;192193/*194* Used to allocate stream IDs. This is a stream ordinal, i.e., a stream ID195* without the low two bits designating type and initiator. Shift and or in196* the type bits to convert to a stream ID.197*/198uint64_t next_local_stream_ordinal_bidi;199uint64_t next_local_stream_ordinal_uni;200201/*202* Used to track which stream ordinals within a given stream type have been203* used by the remote peer. This is an optimisation used to determine204* which streams should be implicitly created due to usage of a higher205* stream ordinal.206*/207uint64_t next_remote_stream_ordinal_bidi;208uint64_t next_remote_stream_ordinal_uni;209210/*211* Application error code to be used for STOP_SENDING/RESET_STREAM frames212* used to autoreject incoming streams.213*/214uint64_t incoming_stream_auto_reject_aec;215216/*217* Override packet count threshold at which we do a spontaneous TXKU.218* Usually UINT64_MAX in which case a suitable value is chosen based on AEAD219* limit advice from the QRL utility functions. This is intended for testing220* use only. Usually set to UINT64_MAX.221*/222uint64_t txku_threshold_override;223224/* Valid if we are in the TERMINATING or TERMINATED states. */225QUIC_TERMINATE_CAUSE terminate_cause;226227/*228* Deadline at which we move to TERMINATING state. Valid if in the229* TERMINATING state.230*/231OSSL_TIME terminate_deadline;232233/*234* Deadline at which connection dies due to idle timeout if no further235* events occur.236*/237OSSL_TIME idle_deadline;238239/*240* Deadline at which we should send an ACK-eliciting packet to ensure241* idle timeout does not occur.242*/243OSSL_TIME ping_deadline;244245/*246* The deadline at which the period in which it is RECOMMENDED that we not247* initiate any spontaneous TXKU ends. This is zero if no such deadline248* applies.249*/250OSSL_TIME txku_cooldown_deadline;251252/*253* The deadline at which we take the QRX out of UPDATING and back to NORMAL.254* Valid if rxku_in_progress in 1.255*/256OSSL_TIME rxku_update_end_deadline;257258/*259* The first (application space) PN sent with a new key phase. Valid if the260* QTX key epoch is greater than 0. Once a packet we sent with a PN p (p >=261* txku_pn) is ACKed, the TXKU is considered completed and txku_in_progress262* becomes 0. For sanity's sake, such a PN p should also be <= the highest263* PN we have ever sent, of course.264*/265QUIC_PN txku_pn;266267/*268* The (application space) PN which triggered RXKU detection. Valid if269* rxku_pending_confirm.270*/271QUIC_PN rxku_trigger_pn;272273/*274* State tracking. QUIC connection-level state is best represented based on275* whether various things have happened yet or not, rather than as an276* explicit FSM. We do have a coarse state variable which tracks the basic277* state of the connection's lifecycle, but more fine-grained conditions of278* the Active state are tracked via flags below. For more details, see279* doc/designs/quic-design/connection-state-machine.md. We are in the Open280* state if the state is QUIC_CHANNEL_STATE_ACTIVE and handshake_confirmed is281* set.282*/283unsigned int state : 3;284285/*286* Have we received at least one encrypted packet from the peer?287* (If so, Retry and Version Negotiation messages should no longer288* be received and should be ignored if they do occur.)289*/290unsigned int have_received_enc_pkt : 1;291292/*293* Have we successfully processed any packet, including a Version294* Negotiation packet? If so, further Version Negotiation packets should be295* ignored.296*/297unsigned int have_processed_any_pkt : 1;298299/*300* Have we sent literally any packet yet? If not, there is no point polling301* RX.302*/303unsigned int have_sent_any_pkt : 1;304305/*306* Are we currently doing proactive version negotiation?307*/308unsigned int doing_proactive_ver_neg : 1;309310/* We have received transport parameters from the peer. */311unsigned int got_remote_transport_params : 1;312/* We have generated our local transport parameters. */313unsigned int got_local_transport_params : 1;314315/*316* This monotonically transitions to 1 once the TLS state machine is317* 'complete', meaning that it has both sent a Finished and successfully318* verified the peer's Finished (see RFC 9001 s. 4.1.1). Note that it319* does not transition to 1 at both peers simultaneously.320*321* Handshake completion is not the same as handshake confirmation (see322* below).323*/324unsigned int handshake_complete : 1;325326/*327* This monotonically transitions to 1 once the handshake is confirmed.328* This happens on the client when we receive a HANDSHAKE_DONE frame.329* At our option, we may also take acknowledgement of any 1-RTT packet330* we sent as a handshake confirmation.331*/332unsigned int handshake_confirmed : 1;333334/*335* We are sending Initial packets based on a Retry. This means we definitely336* should not receive another Retry, and if we do it is an error.337*/338unsigned int doing_retry : 1;339340/*341* We don't store the current EL here; the TXP asks the QTX which ELs342* are provisioned to determine which ELs to use.343*/344345/* Have statm, qsm been initialised? Used to track cleanup. */346unsigned int have_statm : 1;347unsigned int have_qsm : 1;348349/*350* Preferred ELs for transmission and reception. This is not strictly needed351* as it can be inferred from what keys we have provisioned, but makes352* determining the current EL simpler and faster. A separate EL for353* transmission and reception is not strictly necessary but makes things354* easier for interoperation with the handshake layer, which likes to invoke355* the yield secret callback at different times for TX and RX.356*/357unsigned int tx_enc_level : 3;358unsigned int rx_enc_level : 3;359360/* If bit n is set, EL n has been discarded. */361unsigned int el_discarded : 4;362363/*364* While in TERMINATING - CLOSING, set when we should generate a connection365* close frame.366*/367unsigned int conn_close_queued : 1;368369/* Are we in server mode? Never changes after instantiation. */370unsigned int is_server : 1;371372/*373* Set temporarily when the handshake layer has given us a new RX secret.374* Used to determine if we need to check our RX queues again.375*/376unsigned int have_new_rx_secret : 1;377378/* Have we ever called QUIC_TLS yet during RX processing? */379unsigned int did_tls_tick : 1;380/* Has any CRYPTO frame been processed during this tick? */381unsigned int did_crypto_frame : 1;382383/*384* Have we sent an ack-eliciting packet since the last successful packet385* reception? Used to determine when to bump idle timer (see RFC 9000 s.386* 10.1).387*/388unsigned int have_sent_ack_eliciting_since_rx : 1;389390/* Should incoming streams automatically be rejected? */391unsigned int incoming_stream_auto_reject : 1;392393/*394* 1 if a key update sequence was locally initiated, meaning we sent the395* TXKU first and the resultant RXKU shouldn't result in our triggering396* another TXKU. 0 if a key update sequence was initiated by the peer,397* meaning we detect a RXKU first and have to generate a TXKU in response.398*/399unsigned int ku_locally_initiated : 1;400401/*402* 1 if we have triggered TXKU (whether spontaneous or solicited) but are403* waiting for any PN using that new KP to be ACKed. While this is set, we404* are not allowed to trigger spontaneous TXKU (but solicited TXKU is405* potentially still possible).406*/407unsigned int txku_in_progress : 1;408409/*410* We have received an RXKU event and currently are going through411* UPDATING/COOLDOWN on the QRX. COOLDOWN is currently not used. Since RXKU412* cannot be detected in this state, this doesn't cause a protocol error or413* anything similar if a peer tries TXKU in this state. That traffic would414* simply be dropped. It's only used to track that our UPDATING timer is415* active so we know when to take the QRX out of UPDATING and back to416* NORMAL.417*/418unsigned int rxku_in_progress : 1;419420/*421* We have received an RXKU but have yet to send an ACK for it, which means422* no further RXKUs are allowed yet. Note that we cannot detect further423* RXKUs anyway while the QRX remains in the UPDATING/COOLDOWN states, so424* this restriction comes into play if we take more than PTO time to send425* an ACK for it (not likely).426*/427unsigned int rxku_pending_confirm : 1;428429/* Temporary variable indicating rxku_pending_confirm is to become 0. */430unsigned int rxku_pending_confirm_done : 1;431432/*433* If set, RXKU is expected (because we initiated a spontaneous TXKU).434*/435unsigned int rxku_expected : 1;436437/* Permanent net error encountered */438unsigned int net_error : 1;439440/*441* Protocol error encountered. Note that you should refer to the state field442* rather than this. This is only used so we can ignore protocol errors443* after the first protocol error, but still record the first protocol error444* if it happens during the TERMINATING state.445*/446unsigned int protocol_error : 1;447448/* Are we using addressed mode? */449unsigned int addressed_mode : 1;450451/* Are we on the QUIC_PORT linked list of channels? */452unsigned int on_port_list : 1;453454/* Has qlog been requested? */455unsigned int use_qlog : 1;456457/* Has qlog been requested? */458unsigned int is_tserver_ch : 1;459460/* Saved error stack in case permanent error was encountered */461ERR_STATE *err_state;462463/* Scratch area for use by RXDP to store decoded ACK ranges. */464OSSL_QUIC_ACK_RANGE *ack_range_scratch;465size_t num_ack_range_scratch;466467/* Title for qlog purposes. We own this copy. */468char *qlog_title;469};470471# endif472473#endif474475476