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 #define TX_PACKETISER_RES_FAILURE 0
86 #define TX_PACKETISER_RES_NO_PKT 1
87 #define TX_PACKETISER_RES_SENT_PKT 2
88 int ossl_quic_tx_packetiser_generate(OSSL_QUIC_TX_PACKETISER *txp,
92 * Returns 1 if one or more packets would be generated if
93 * ossl_quic_tx_packetiser_generate were called.
95 * If TX_PACKETISER_BYPASS_CC is set in flags, congestion control is
96 * ignored for the purposes of making this determination.
98 #define TX_PACKETISER_BYPASS_CC (1U << 0)
100 int ossl_quic_tx_packetiser_has_pending(OSSL_QUIC_TX_PACKETISER *txp,
105 * Set the token used in Initial packets. The callback is called when the buffer
106 * is no longer needed; for example, when the TXP is freed or when this function
107 * is called again with a new buffer.
109 void ossl_quic_tx_packetiser_set_initial_token(OSSL_QUIC_TX_PACKETISER *txp,
110 const unsigned char *token,
112 ossl_quic_initial_token_free_fn *free_cb,
115 /* Change the DCID the TXP uses to send outgoing packets. */
116 int ossl_quic_tx_packetiser_set_cur_dcid(OSSL_QUIC_TX_PACKETISER *txp,
117 const QUIC_CONN_ID *dcid);
119 /* Change the SCID the TXP uses to send outgoing (long) packets. */
120 int ossl_quic_tx_packetiser_set_cur_scid(OSSL_QUIC_TX_PACKETISER *txp,
121 const QUIC_CONN_ID *scid);
123 /* Change the destination L4 address the TXP uses to send datagrams. */
124 int ossl_quic_tx_packetiser_set_peer(OSSL_QUIC_TX_PACKETISER *txp,
125 const BIO_ADDR *peer);
128 * Inform the TX packetiser that an EL has been discarded. Idempotent.
130 * This does not inform the QTX as well; the caller must also inform the QTX.
132 * The TXP will no longer reference the crypto[enc_level] QUIC_SSTREAM which was
133 * provided in the TXP arguments. However, it is the callers responsibility to
134 * free that QUIC_SSTREAM if desired.
136 int ossl_quic_tx_packetiser_discard_enc_level(OSSL_QUIC_TX_PACKETISER *txp,
140 * Informs the TX packetiser that the handshake is complete. The TX packetiser
141 * will not send 1-RTT application data until the handshake is complete,
142 * as the authenticity of the peer is not confirmed until the handshake
143 * complete event occurs.
145 void ossl_quic_tx_packetiser_notify_handshake_complete(OSSL_QUIC_TX_PACKETISER *txp);
147 /* Asks the TXP to generate a HANDSHAKE_DONE frame in the next 1-RTT packet. */
148 void ossl_quic_tx_packetiser_schedule_handshake_done(OSSL_QUIC_TX_PACKETISER *txp);
150 /* Asks the TXP to ensure the next packet in the given PN space is ACK-eliciting. */
151 void ossl_quic_tx_packetiser_schedule_ack_eliciting(OSSL_QUIC_TX_PACKETISER *txp,
155 * Schedules a connection close. *f and f->reason are copied. This operation is
156 * irreversible and causes all further packets generated by the TXP to contain a
157 * CONNECTION_CLOSE frame. This function fails if it has already been called
158 * successfully; the information in *f cannot be changed after the first
159 * successful call to this function.
161 int ossl_quic_tx_packetiser_schedule_conn_close(OSSL_QUIC_TX_PACKETISER *txp,
162 const OSSL_QUIC_FRAME_CONN_CLOSE *f);