summaryrefslogtreecommitdiffstats
path: root/ssl/quic
diff options
context:
space:
mode:
authorHugo Landau <hlandau@openssl.org>2024-01-29 12:36:29 +0000
committerHugo Landau <hlandau@openssl.org>2024-02-02 11:50:29 +0000
commit2acc1ebbd96afb5377af10cad6572617c906b06b (patch)
treeead0799eaa9297ac85d124a07692e3cd79b1552a /ssl/quic
parent572c449a10697d8424a6117df807700a688d753d (diff)
QUIC QTX: Refactor to enable qlog logging of injected frames
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Neil Horman <nhorman@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22037)
Diffstat (limited to 'ssl/quic')
-rw-r--r--ssl/quic/quic_record_tx.c66
1 files changed, 38 insertions, 28 deletions
diff --git a/ssl/quic/quic_record_tx.c b/ssl/quic/quic_record_tx.c
index 584776f834..663b163727 100644
--- a/ssl/quic/quic_record_tx.c
+++ b/ssl/quic/quic_record_tx.c
@@ -592,7 +592,8 @@ static int qtx_encrypt_into_txe(OSSL_QTX *qtx, struct iovec_cur *cur, TXE *txe,
* process.
*/
static int qtx_write(OSSL_QTX *qtx, const OSSL_QTX_PKT *pkt, TXE *txe,
- uint32_t enc_level)
+ uint32_t enc_level, QUIC_PKT_HDR *hdr,
+ const OSSL_QTX_IOVEC *iovec, size_t num_iovec)
{
int ret, needs_encrypt;
size_t hdr_len, pred_hdr_len, payload_len, pkt_len, space_left;
@@ -601,15 +602,12 @@ static int qtx_write(OSSL_QTX *qtx, const OSSL_QTX_PKT *pkt, TXE *txe,
QUIC_PKT_HDR_PTRS ptrs;
unsigned char *hdr_start;
OSSL_QRL_ENC_LEVEL *el = NULL;
- QUIC_PKT_HDR *hdr;
- const OSSL_QTX_IOVEC *iovec;
- size_t num_iovec;
/*
* Determine if the packet needs encryption and the minimum conceivable
* serialization length.
*/
- if (!ossl_quic_pkt_type_is_encrypted(pkt->hdr->type)) {
+ if (!ossl_quic_pkt_type_is_encrypted(hdr->type)) {
needs_encrypt = 0;
min_len = QUIC_MIN_VALID_PKT_LEN;
} else {
@@ -629,21 +627,8 @@ static int qtx_write(OSSL_QTX *qtx, const OSSL_QTX_PKT *pkt, TXE *txe,
}
/* Set some fields in the header we are responsible for. */
- if (pkt->hdr->type == QUIC_PKT_TYPE_1RTT)
- pkt->hdr->key_phase = (unsigned char)(el->key_epoch & 1);
-
- /* If we are running tests then mutate_packet may be non NULL */
- if (qtx->mutatecb != NULL) {
- if (!qtx->mutatecb(pkt->hdr, pkt->iovec, pkt->num_iovec, &hdr,
- &iovec, &num_iovec, qtx->mutatearg)) {
- ret = QTX_FAIL_GENERIC;
- goto err;
- }
- } else {
- hdr = pkt->hdr;
- iovec = pkt->iovec;
- num_iovec = pkt->num_iovec;
- }
+ if (hdr->type == QUIC_PKT_TYPE_1RTT)
+ hdr->key_phase = (unsigned char)(el->key_epoch & 1);
/* Walk the iovecs to determine actual input payload length. */
iovec_cur_init(&cur, iovec, num_iovec);
@@ -724,8 +709,6 @@ static int qtx_write(OSSL_QTX *qtx, const OSSL_QTX_PKT *pkt, TXE *txe,
assert(txe->data_len - orig_data_len == pkt_len);
}
- if (qtx->finishmutatecb != NULL)
- qtx->finishmutatecb(qtx->mutatearg);
return 1;
err:
@@ -734,8 +717,6 @@ err:
* TXE.
*/
txe->data_len = orig_data_len;
- if (qtx->finishmutatecb != NULL)
- qtx->finishmutatecb(qtx->mutatearg);
return ret;
}
@@ -757,6 +738,38 @@ static TXE *qtx_ensure_cons(OSSL_QTX *qtx)
return txe;
}
+static int qtx_mutate_write(OSSL_QTX *qtx, const OSSL_QTX_PKT *pkt, TXE *txe,
+ uint32_t enc_level)
+{
+ int ret;
+ QUIC_PKT_HDR *hdr;
+ const OSSL_QTX_IOVEC *iovec;
+ size_t num_iovec;
+
+ /* If we are running tests then mutate_packet may be non NULL */
+ if (qtx->mutatecb != NULL) {
+ if (!qtx->mutatecb(pkt->hdr, pkt->iovec, pkt->num_iovec, &hdr,
+ &iovec, &num_iovec, qtx->mutatearg))
+ return QTX_FAIL_GENERIC;
+ } else {
+ hdr = pkt->hdr;
+ iovec = pkt->iovec;
+ num_iovec = pkt->num_iovec;
+ }
+
+ ret = qtx_write(qtx, pkt, txe, enc_level,
+ hdr, iovec, num_iovec);
+ if (ret == 1)
+ ossl_qlog_event_transport_packet_sent(qtx->qlog, hdr, pkt->pn,
+ iovec, num_iovec,
+ qtx->datagram_count);
+
+ if (qtx->finishmutatecb != NULL)
+ qtx->finishmutatecb(qtx->mutatearg);
+
+ return ret;
+}
+
static int addr_eq(const BIO_ADDR *a, const BIO_ADDR *b)
{
return ((a == NULL || BIO_ADDR_family(a) == AF_UNSPEC)
@@ -827,11 +840,8 @@ int ossl_qtx_write_pkt(OSSL_QTX *qtx, const OSSL_QTX_PKT *pkt)
BIO_ADDR_clear(&txe->local);
}
- ret = qtx_write(qtx, pkt, txe, enc_level);
+ ret = qtx_mutate_write(qtx, pkt, txe, enc_level);
if (ret == 1) {
- ossl_qlog_event_transport_packet_sent(qtx->qlog, pkt->hdr, pkt->pn,
- pkt->iovec, pkt->num_iovec,
- qtx->datagram_count);
break;
} else if (ret == QTX_FAIL_INSUFFICIENT_LEN) {
if (was_coalescing) {