QUIC QTX: Allow QLOG instance retrieval via callback
authorHugo Landau <hlandau@openssl.org>
Mon, 12 Feb 2024 09:49:58 +0000 (09:49 +0000)
committerTomas Mraz <tomas@openssl.org>
Mon, 19 Feb 2024 09:15:46 +0000 (10:15 +0100)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23535)

include/internal/quic_record_tx.h
ssl/quic/quic_record_tx.c

index 46f61a2e589e74d099389c49d9bf3b87f8367d15..3f1de5d90e497890ad0b759e72ae72ddd1488197 100644 (file)
@@ -49,8 +49,9 @@ typedef struct ossl_qtx_args_st {
     /* Maximum datagram payload length (MDPL) for TX purposes. */
     size_t          mdpl;
 
-    /* QLOG instance to use, or NULL. */
-    QLOG           *qlog;
+    /* Callback returning QLOG instance to use, or NULL. */
+    QLOG           *(*get_qlog_cb)(void *arg);
+    void           *get_qlog_cb_arg;
 } OSSL_QTX_ARGS;
 
 /* Instantiates a new QTX. */
@@ -68,8 +69,9 @@ void ossl_qtx_set_msg_callback(OSSL_QTX *qtx, ossl_msg_cb msg_callback,
                                SSL *msg_callback_ssl);
 void ossl_qtx_set_msg_callback_arg(OSSL_QTX *qtx, void *msg_callback_arg);
 
-/* Change QLOG instance in use after instantiation. */
-void ossl_qtx_set0_qlog(OSSL_QTX *qtx, QLOG *qlog);
+/* Change QLOG instance retrieval callback in use after instantiation. */
+void ossl_qtx_set_qlog_cb(OSSL_QTX *qtx, QLOG *(*get_qlog_cb)(void *arg),
+                          void *get_qlog_cb_arg);
 
 /*
  * Secret Management
index 5d6b84d98ffc2eb5272d674f4501ce41de0f6f51..8cc83d673d5886415786fc9332547e679b6d9ab4 100644 (file)
@@ -61,8 +61,9 @@ struct ossl_qtx_st {
     /* TX BIO. */
     BIO                        *bio;
 
-    /* QLOG instance if in use, or NULL. */
-    QLOG                       *qlog;
+    /* QLOG instance retrieval callback if in use, or NULL. */
+    QLOG                     *(*get_qlog_cb)(void *arg);
+    void                       *get_qlog_cb_arg;
 
     /* TX maximum datagram payload length. */
     size_t                      mdpl;
@@ -124,7 +125,9 @@ OSSL_QTX *ossl_qtx_new(const OSSL_QTX_ARGS *args)
     qtx->propq              = args->propq;
     qtx->bio                = args->bio;
     qtx->mdpl               = args->mdpl;
-    qtx->qlog               = args->qlog;
+    qtx->get_qlog_cb        = args->get_qlog_cb;
+    qtx->get_qlog_cb_arg    = args->get_qlog_cb_arg;
+
     return qtx;
 }
 
@@ -167,9 +170,11 @@ void ossl_qtx_set_mutator(OSSL_QTX *qtx, ossl_mutate_packet_cb mutatecb,
     qtx->mutatearg      = mutatearg;
 }
 
-void ossl_qtx_set0_qlog(OSSL_QTX *qtx, QLOG *qlog)
+void ossl_qtx_set_qlog_cb(OSSL_QTX *qtx, QLOG *(*get_qlog_cb)(void *arg),
+                          void *get_qlog_cb_arg)
 {
-    qtx->qlog = qlog;
+    qtx->get_qlog_cb        = get_qlog_cb;
+    qtx->get_qlog_cb_arg    = get_qlog_cb_arg;
 }
 
 int ossl_qtx_provide_secret(OSSL_QTX              *qtx,
@@ -738,6 +743,14 @@ static TXE *qtx_ensure_cons(OSSL_QTX *qtx)
     return txe;
 }
 
+static QLOG *qtx_get_qlog(OSSL_QTX *qtx)
+{
+    if (qtx->get_qlog_cb == NULL)
+        return NULL;
+
+    return qtx->get_qlog_cb(qtx->get_qlog_cb_arg);
+}
+
 static int qtx_mutate_write(OSSL_QTX *qtx, const OSSL_QTX_PKT *pkt, TXE *txe,
                             uint32_t enc_level)
 {
@@ -760,7 +773,7 @@ static int qtx_mutate_write(OSSL_QTX *qtx, const OSSL_QTX_PKT *pkt, TXE *txe,
     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,
+        ossl_qlog_event_transport_packet_sent(qtx_get_qlog(qtx), hdr, pkt->pn,
                                               iovec, num_iovec,
                                               qtx->datagram_count);