QUIC QLOG: Allow PID to be overridden
authorHugo Landau <hlandau@openssl.org>
Mon, 29 Jan 2024 13:58:18 +0000 (13:58 +0000)
committerHugo Landau <hlandau@openssl.org>
Fri, 2 Feb 2024 11:50:30 +0000 (11:50 +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/qlog.h
ssl/quic/qlog.c
test/build.info

index 8d44ed00983af4f5649c5fc7f3602d919967bc1c..80c806d2a468ebced83628d4bff0707ac6a643de 100644 (file)
@@ -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);
index 6944a4f435d6828b2bcbbfc9560f4a2f6a7d5add..bad124b86d1eb6d99c4ff34f4522c5e6036b19f3 100644 (file)
@@ -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 */
index 00758cc850e340760ed3269590e678c4e2a18ec6..2bdf54589251113c1a6badca3739319556c2abbb 100644 (file)
@@ -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