2 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #ifndef OSSL_QUIC_TXP_H
11 # define OSSL_QUIC_TXP_H
13 # include <openssl/ssl.h>
14 # include "internal/quic_types.h"
15 # include "internal/quic_record_tx.h"
16 # include "internal/quic_cfq.h"
17 # include "internal/quic_txpim.h"
18 # include "internal/quic_stream.h"
19 # include "internal/quic_stream_map.h"
20 # include "internal/quic_fc.h"
21 # include "internal/bio_addr.h"
22 # include "internal/time.h"
24 # ifndef OPENSSL_NO_QUIC
30 typedef struct ossl_quic_tx_packetiser_args_st {
31 /* Configuration Settings */
32 QUIC_CONN_ID cur_scid; /* Current Source Connection ID we use. */
33 QUIC_CONN_ID cur_dcid; /* Current Destination Connection ID we use. */
34 BIO_ADDR peer; /* Current destination L4 address we use. */
35 uint32_t ack_delay_exponent; /* ACK delay exponent used when encoding. */
37 /* Injected Dependencies */
38 OSSL_QTX *qtx; /* QUIC Record Layer TX we are using */
39 QUIC_TXPIM *txpim; /* QUIC TX'd Packet Information Manager */
40 QUIC_CFQ *cfq; /* QUIC Control Frame Queue */
41 OSSL_ACKM *ackm; /* QUIC Acknowledgement Manager */
42 QUIC_STREAM_MAP *qsm; /* QUIC Streams Map */
43 QUIC_TXFC *conn_txfc; /* QUIC Connection-Level TX Flow Controller */
44 QUIC_RXFC *conn_rxfc; /* QUIC Connection-Level RX Flow Controller */
45 const OSSL_CC_METHOD *cc_method; /* QUIC Congestion Controller */
46 OSSL_CC_DATA *cc_data; /* QUIC Congestion Controller Instance */
47 OSSL_TIME (*now)(void *arg); /* Callback to get current time. */
51 * Injected dependencies - crypto streams.
53 * Note: There is no crypto stream for the 0-RTT EL.
54 * crypto[QUIC_PN_SPACE_APP] is the 1-RTT crypto stream.
56 QUIC_SSTREAM *crypto[QUIC_PN_SPACE_NUM];
57 } OSSL_QUIC_TX_PACKETISER_ARGS;
59 typedef struct ossl_quic_tx_packetiser_st OSSL_QUIC_TX_PACKETISER;
61 OSSL_QUIC_TX_PACKETISER *ossl_quic_tx_packetiser_new(const OSSL_QUIC_TX_PACKETISER_ARGS *args);
63 typedef void (ossl_quic_initial_token_free_fn)(const unsigned char *buf,
64 size_t buf_len, void *arg);
66 void ossl_quic_tx_packetiser_free(OSSL_QUIC_TX_PACKETISER *txp);
68 /* Generate normal packets containing most frame types. */
69 #define TX_PACKETISER_ARCHETYPE_NORMAL 0
70 /* Generate ACKs only. */
71 #define TX_PACKETISER_ARCHETYPE_ACK_ONLY 1
72 #define TX_PACKETISER_ARCHETYPE_NUM 2
75 * Generates a datagram by polling the various ELs to determine if they want to
76 * generate any frames, and generating a datagram which coalesces packets for
79 * archetype is a TX_PACKETISER_ARCHETYPE_* value.
81 * Returns TX_PACKETISER_RES_FAILURE on failure (e.g. allocation error),
82 * TX_PACKETISER_RES_NO_PKT if no packets were sent (e.g. because nothing wants
83 * to send anything), and TX_PACKETISER_RES_SENT_PKT if packets were sent.
85 * If an ACK-eliciting packet was sent, 1 is written to *sent_ack_eliciting,
86 * otherwise *sent_ack_eliciting is unchanged.
88 #define TX_PACKETISER_RES_FAILURE 0
89 #define TX_PACKETISER_RES_NO_PKT 1
90 #define TX_PACKETISER_RES_SENT_PKT 2
91 int ossl_quic_tx_packetiser_generate(OSSL_QUIC_TX_PACKETISER *txp,
93 int *sent_ack_eliciting);
96 * Returns 1 if one or more packets would be generated if
97 * ossl_quic_tx_packetiser_generate were called.
99 * If TX_PACKETISER_BYPASS_CC is set in flags, congestion control is
100 * ignored for the purposes of making this determination.
102 #define TX_PACKETISER_BYPASS_CC (1U << 0)
104 int ossl_quic_tx_packetiser_has_pending(OSSL_QUIC_TX_PACKETISER *txp,
109 * Set the token used in Initial packets. The callback is called when the buffer
110 * is no longer needed; for example, when the TXP is freed or when this function
111 * is called again with a new buffer.
113 void ossl_quic_tx_packetiser_set_initial_token(OSSL_QUIC_TX_PACKETISER *txp,
114 const unsigned char *token,
116 ossl_quic_initial_token_free_fn *free_cb,
119 /* Change the DCID the TXP uses to send outgoing packets. */
120 int ossl_quic_tx_packetiser_set_cur_dcid(OSSL_QUIC_TX_PACKETISER *txp,
121 const QUIC_CONN_ID *dcid);
123 /* Change the SCID the TXP uses to send outgoing (long) packets. */
124 int ossl_quic_tx_packetiser_set_cur_scid(OSSL_QUIC_TX_PACKETISER *txp,
125 const QUIC_CONN_ID *scid);
127 /* Change the destination L4 address the TXP uses to send datagrams. */
128 int ossl_quic_tx_packetiser_set_peer(OSSL_QUIC_TX_PACKETISER *txp,
129 const BIO_ADDR *peer);
132 * Inform the TX packetiser that an EL has been discarded. Idempotent.
134 * This does not inform the QTX as well; the caller must also inform the QTX.
136 * The TXP will no longer reference the crypto[enc_level] QUIC_SSTREAM which was
137 * provided in the TXP arguments. However, it is the callers responsibility to
138 * free that QUIC_SSTREAM if desired.
140 int ossl_quic_tx_packetiser_discard_enc_level(OSSL_QUIC_TX_PACKETISER *txp,
144 * Informs the TX packetiser that the handshake is complete. The TX packetiser
145 * will not send 1-RTT application data until the handshake is complete,
146 * as the authenticity of the peer is not confirmed until the handshake
147 * complete event occurs.
149 void ossl_quic_tx_packetiser_notify_handshake_complete(OSSL_QUIC_TX_PACKETISER *txp);
151 /* Asks the TXP to generate a HANDSHAKE_DONE frame in the next 1-RTT packet. */
152 void ossl_quic_tx_packetiser_schedule_handshake_done(OSSL_QUIC_TX_PACKETISER *txp);
154 /* Asks the TXP to ensure the next packet in the given PN space is ACK-eliciting. */
155 void ossl_quic_tx_packetiser_schedule_ack_eliciting(OSSL_QUIC_TX_PACKETISER *txp,
159 * Schedules a connection close. *f and f->reason are copied. This operation is
160 * irreversible and causes all further packets generated by the TXP to contain a
161 * CONNECTION_CLOSE frame. This function fails if it has already been called
162 * successfully; the information in *f cannot be changed after the first
163 * successful call to this function.
165 int ossl_quic_tx_packetiser_schedule_conn_close(OSSL_QUIC_TX_PACKETISER *txp,
166 const OSSL_QUIC_FRAME_CONN_CLOSE *f);