QLOG: Wiring: QUIC CHANNEL
authorHugo Landau <hlandau@openssl.org>
Fri, 8 Sep 2023 11:17:27 +0000 (12:17 +0100)
committerHugo Landau <hlandau@openssl.org>
Fri, 2 Feb 2024 11:49:34 +0000 (11:49 +0000)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22037)

include/internal/quic_channel.h
ssl/quic/quic_channel.c
ssl/quic/quic_channel_local.h
ssl/quic/quic_impl.c

index b6b3e28352012db84e85d4c490b32d249264bc51..20d2ca86c427e3625249b6136d271574c3f54f55 100644 (file)
@@ -15,6 +15,7 @@
 # include "internal/quic_record_tx.h"
 # include "internal/quic_wire.h"
 # include "internal/quic_predef.h"
+# include "internal/qlog.h"
 # include "internal/time.h"
 # include "internal/thread.h"
 
@@ -118,6 +119,9 @@ typedef struct quic_channel_args_st {
 
     int             is_server;
     SSL             *tls;
+
+    /* Whether to use QLOG. */
+    int             use_qlog;
 } QUIC_CHANNEL_ARGS;
 
 /* Represents the cause for a connection's termination. */
index b5f019f40ed5218b7d66eebf0b4eef6ef903d22e..eb731f2c531eb4e1c3ce97327a04eb3a5fb93f8b 100644 (file)
@@ -103,6 +103,36 @@ static void ch_raise_version_neg_failure(QUIC_CHANNEL *ch);
 
 DEFINE_LHASH_OF_EX(QUIC_SRT_ELEM);
 
+QUIC_NEEDS_LOCK
+static QLOG *ch_get_qlog(QUIC_CHANNEL *ch)
+{
+#ifndef OPENSSL_NO_QLOG
+    QLOG_TRACE_INFO qti = {0};
+
+    if (ch->qlog != NULL)
+        return ch->qlog;
+
+    if (!ch->use_qlog)
+        return NULL;
+
+    qti.odcid       = ch->init_dcid;
+    qti.title       = NULL;
+    qti.description = NULL;
+    qti.group_id    = NULL;
+    qti.is_server   = ch->is_server;
+    qti.now_cb      = get_time;
+    qti.now_cb_arg  = ch;
+    if ((ch->qlog = ossl_qlog_new_from_env(&qti)) == NULL) {
+        ch->use_qlog = 0; /* don't try again */
+        return NULL;
+    }
+
+    return ch->qlog;
+#else
+    return NULL;
+#endif
+}
+
 /*
  * QUIC Channel Initialization and Teardown
  * ========================================
@@ -364,6 +394,13 @@ static void ch_cleanup(QUIC_CHANNEL *ch)
         ossl_list_ch_remove(&ch->port->channel_list, ch);
         ch->on_port_list = 0;
     }
+
+#ifndef OPENSSL_NO_QLOG
+    if (ch->qlog != NULL)
+        ossl_qlog_flush(ch->qlog); /* best effort */
+
+    ossl_qlog_free(ch->qlog);
+#endif
 }
 
 QUIC_CHANNEL *ossl_quic_channel_new(const QUIC_CHANNEL_ARGS *args)
@@ -378,6 +415,9 @@ QUIC_CHANNEL *ossl_quic_channel_new(const QUIC_CHANNEL_ARGS *args)
     ch->tls         = args->tls;
     ch->lcidm       = args->lcidm;
     ch->srtm        = args->srtm;
+#ifndef OPENSSL_NO_QLOG
+    ch->use_qlog    = args->use_qlog;
+#endif
 
     if (!ch_init(ch)) {
         OPENSSL_free(ch);
index cd9fe276a5806ae2284a5ef5e4ee10578940ebb2..2a31848158c3063d9f2e74bd83d424b39054144b 100644 (file)
@@ -49,6 +49,9 @@ struct quic_channel_st {
     /* SRTM we register SRTs with. */
     QUIC_SRTM                       *srtm;
 
+    /* Optional QLOG instance (or NULL). */
+    QLOG                            *qlog;
+
     /*
      * The transport parameter block we will send or have sent.
      * Freed after sending or when connection is freed.
@@ -425,6 +428,9 @@ struct quic_channel_st {
     /* Are we on the QUIC_PORT linked list of channels? */
     unsigned int                    on_port_list                        : 1;
 
+    /* Has QLOG been requested? */
+    unsigned int                    use_qlog                            : 1;
+
     /* Saved error stack in case permanent error was encountered */
     ERR_STATE                       *err_state;
 
index c7f35aba29205b9a01a862fa5120d25c0c8d65e1..1248013a4bb754d76c31bfe9e7a6b7f103edd953 100644 (file)
@@ -1508,6 +1508,9 @@ static int create_channel(QUIC_CONNECTION *qc)
         QUIC_RAISE_NON_NORMAL_ERROR(NULL, ERR_R_INTERNAL_ERROR, NULL);
         return 0;
     }
+#ifndef OPENSSL_NO_QLOG
+    args.use_qlog   = 1; /* disabled if env not set */
+#endif
 
     port_args.channel_ctx = qc->ssl.ctx;
     qc->port = ossl_quic_engine_create_port(qc->engine, &port_args);