From 6cb0026c634139b0e0aecb57691330b3bd7a475b Mon Sep 17 00:00:00 2001 From: Hugo Landau Date: Mon, 29 Jan 2024 13:58:18 +0000 Subject: [PATCH] QUIC QLOG: Allow PID to be overridden Reviewed-by: Matt Caswell Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/22037) --- include/internal/qlog.h | 1 + ssl/quic/qlog.c | 20 +++++++++++++------- test/build.info | 5 +++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/internal/qlog.h b/include/internal/qlog.h index 8d44ed0098..80c806d2a4 100644 --- a/include/internal/qlog.h +++ b/include/internal/qlog.h @@ -34,6 +34,7 @@ typedef struct qlog_trace_info_st { int is_server; OSSL_TIME (*now_cb)(void *arg); void *now_cb_arg; + uint64_t override_process_id; } QLOG_TRACE_INFO; QLOG *ossl_qlog_new(const QLOG_TRACE_INFO *info); diff --git a/ssl/quic/qlog.c b/ssl/quic/qlog.c index 6944a4f435..bad124b86d 100644 --- a/ssl/quic/qlog.c +++ b/ssl/quic/qlog.c @@ -59,10 +59,11 @@ QLOG *ossl_qlog_new(const QLOG_TRACE_INFO *info) if (qlog == NULL) return NULL; - qlog->info.odcid = info->odcid; - qlog->info.is_server = info->is_server; - qlog->info.now_cb = info->now_cb; - qlog->info.now_cb_arg = info->now_cb_arg; + qlog->info.odcid = info->odcid; + qlog->info.is_server = info->is_server; + qlog->info.now_cb = info->now_cb; + qlog->info.now_cb_arg = info->now_cb_arg; + qlog->info.override_process_id = info->override_process_id; if (info->title != NULL && (qlog->info.title = OPENSSL_strdup(info->title)) == NULL) @@ -249,7 +250,7 @@ int ossl_qlog_enabled(QLOG *qlog, uint32_t event_type) if (qlog == NULL) return 0; - return bit_get(qlog->enabled, event_type); + return bit_get(qlog->enabled, event_type) != 0; } /* @@ -305,10 +306,15 @@ static void qlog_event_seq_header(QLOG *qlog) ossl_json_key(&qlog->json, "system_info"); ossl_json_object_begin(&qlog->json); { + if (qlog->info.override_process_id != 0) { + ossl_json_key(&qlog->json, "process_id"); + ossl_json_u64(&qlog->json, qlog->info.override_process_id); + } else { #if defined(OPENSSL_SYS_UNIX) || defined(OPENSSL_SYS_WINDOWS) - ossl_json_key(&qlog->json, "process_id"); - ossl_json_u64(&qlog->json, (uint64_t)getpid()); + ossl_json_key(&qlog->json, "process_id"); + ossl_json_u64(&qlog->json, (uint64_t)getpid()); #endif + } } /* system_info */ ossl_json_object_end(&qlog->json); } /* common_fields */ diff --git a/test/build.info b/test/build.info index 00758cc850..2bdf545892 100644 --- a/test/build.info +++ b/test/build.info @@ -374,6 +374,10 @@ IF[{- !$disabled{tests} -}] INCLUDE[quic_multistream_test]=../include ../apps/include DEPEND[quic_multistream_test]=../libcrypto.a ../libssl.a libtestutil.a + SOURCE[quic_qlog_test]=quic_qlog_test.c + INCLUDE[quic_qlog_test]=../include ../apps/include + DEPEND[quic_qlog_test]=../libcrypto.a ../libssl.a libtestutil.a + SOURCE[asynctest]=asynctest.c INCLUDE[asynctest]=../include ../apps/include DEPEND[asynctest]=../libcrypto @@ -1181,6 +1185,7 @@ ENDIF PROGRAMS{noinst}=quic_srtm_test quic_lcidm_test quic_rcidm_test PROGRAMS{noinst}=quic_fifd_test quic_txp_test quic_tserver_test PROGRAMS{noinst}=quic_client_test quic_cc_test quic_multistream_test + PROGRAMS{noinst}=quic_qlog_test ENDIF SOURCE[quic_ackm_test]=quic_ackm_test.c cc_dummy.c -- 2.39.5