From: Hugo Landau Date: Fri, 8 Sep 2023 11:17:27 +0000 (+0100) Subject: QLOG: Wiring: QUIC CHANNEL X-Git-Tag: openssl-3.3.0-alpha1~227 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2031c0e928f19d2fbdc88d4f5ac4424d700099d9;p=thirdparty%2Fopenssl.git QLOG: Wiring: QUIC CHANNEL Reviewed-by: Matt Caswell Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/22037) --- diff --git a/include/internal/quic_channel.h b/include/internal/quic_channel.h index b6b3e283520..20d2ca86c42 100644 --- a/include/internal/quic_channel.h +++ b/include/internal/quic_channel.h @@ -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. */ diff --git a/ssl/quic/quic_channel.c b/ssl/quic/quic_channel.c index b5f019f40ed..eb731f2c531 100644 --- a/ssl/quic/quic_channel.c +++ b/ssl/quic/quic_channel.c @@ -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); diff --git a/ssl/quic/quic_channel_local.h b/ssl/quic/quic_channel_local.h index cd9fe276a58..2a31848158c 100644 --- a/ssl/quic/quic_channel_local.h +++ b/ssl/quic/quic_channel_local.h @@ -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; diff --git a/ssl/quic/quic_impl.c b/ssl/quic/quic_impl.c index c7f35aba292..1248013a4bb 100644 --- a/ssl/quic/quic_impl.c +++ b/ssl/quic/quic_impl.c @@ -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);