QLOG: Events: Implement connectivity:connection_closed
authorHugo Landau <hlandau@openssl.org>
Fri, 8 Sep 2023 12:07:04 +0000 (13:07 +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/qlog_event_helpers.h
include/internal/qlog_events.h
ssl/quic/qlog_event_helpers.c
ssl/quic/quic_channel.c

index de9022659ee9064ac614888c175b23405c7ee597..4a19a79e2529a6f116a95b08c43f9723afc1ec32 100644 (file)
@@ -13,6 +13,7 @@
 # include <openssl/ssl.h>
 # include "internal/qlog.h"
 # include "internal/quic_types.h"
+# include "internal/quic_channel.h"
 
 /* connectivity:connection_started */
 void ossl_qlog_event_connectivity_connection_started(QLOG *qlog,
@@ -25,4 +26,8 @@ void ossl_qlog_event_connectivity_connection_state_updated(QLOG *qlog,
                                                            int handshake_complete,
                                                            int handshake_confirmed);
 
+/* connectivity:connection_closed */
+void ossl_qlog_event_connectivity_connection_closed(QLOG *qlog,
+                                                    const QUIC_TERMINATE_CAUSE *tcause);
+
 #endif
index 83c7c4276fb121a828909a213af2b9f8e96b7b81..ec365c0009897aff28e886f9e60b6fdebf1af668 100644 (file)
@@ -8,4 +8,5 @@
  */
 QLOG_EVENT(connectivity, connection_started)
 QLOG_EVENT(connectivity, connection_state_updated)
+QLOG_EVENT(connectivity, connection_closed)
 QLOG_EVENT(transport, parameters_set)
index 66157fe444eb2a6cad5412909e7526ee0d5e12c7..d8deac6e02e356de2501ebfca7aa40b42feab2c7 100644 (file)
@@ -10,6 +10,7 @@
 #include "internal/qlog_event_helpers.h"
 #include "internal/common.h"
 #include "internal/quic_channel.h"
+#include "internal/quic_error.h"
 
 void ossl_qlog_event_connectivity_connection_started(QLOG *qlog,
                                                      const QUIC_CONN_ID *init_dcid)
@@ -71,3 +72,76 @@ void ossl_qlog_event_connectivity_connection_state_updated(QLOG *qlog,
     QLOG_EVENT_END()
 #endif
 }
+
+#ifndef OPENSSL_NO_QLOG
+static const char *quic_err_to_qlog(uint64_t error_code)
+{
+    switch (error_code) {
+        case QUIC_ERR_INTERNAL_ERROR:
+            return "internal_error";
+        case QUIC_ERR_CONNECTION_REFUSED:
+            return "connection_refused";
+        case QUIC_ERR_FLOW_CONTROL_ERROR:
+            return "flow_control_error";
+        case QUIC_ERR_STREAM_LIMIT_ERROR:
+            return "stream_limit_error";
+        case QUIC_ERR_STREAM_STATE_ERROR:
+            return "stream_state_error";
+        case QUIC_ERR_FINAL_SIZE_ERROR:
+            return "final_size_error";
+        case QUIC_ERR_FRAME_ENCODING_ERROR:
+            return "frame_encoding_error";
+        case QUIC_ERR_TRANSPORT_PARAMETER_ERROR:
+            return "transport_parameter_error";
+        case QUIC_ERR_CONNECTION_ID_LIMIT_ERROR:
+            return "connection_id_limit_error";
+        case QUIC_ERR_PROTOCOL_VIOLATION:
+            return "protocol_violation";
+        case QUIC_ERR_INVALID_TOKEN:
+            return "invalid_token";
+        case QUIC_ERR_APPLICATION_ERROR:
+            return "application_error";
+        case QUIC_ERR_CRYPTO_BUFFER_EXCEEDED:
+            return "crypto_buffer_exceeded";
+        case QUIC_ERR_KEY_UPDATE_ERROR:
+            return "key_update_error";
+        case QUIC_ERR_AEAD_LIMIT_REACHED:
+            return "aead_limit_reached";
+        case QUIC_ERR_NO_VIABLE_PATH:
+            return "no_viable_path";
+        default:
+            return NULL;
+    }
+}
+#endif
+
+void ossl_qlog_event_connectivity_connection_closed(QLOG *qlog,
+                                                    const QUIC_TERMINATE_CAUSE *tcause)
+{
+#ifndef OPENSSL_NO_QLOG
+    QLOG_EVENT_BEGIN(qlog, connectivity, connection_closed)
+        QLOG_STR("owner", tcause->remote ? "remote" : "local");
+        if (tcause->app) {
+            QLOG_U64("application_code", tcause->error_code);
+        } else {
+            const char *m = quic_err_to_qlog(tcause->error_code);
+            char ce[32];
+
+            if (tcause->error_code >= QUIC_ERR_CRYPTO_ERR_BEGIN
+                && tcause->error_code <= QUIC_ERR_CRYPTO_ERR_END) {
+                snprintf(ce, sizeof(ce), "crypto_error_0x%03llx",
+                         (unsigned long long)tcause->error_code);
+                m = ce;
+            }
+            /* TODO(QLOG): Consider adding ERR information in the output. */
+
+            if (m != NULL)
+                QLOG_STR("connection_code", m);
+            else
+                QLOG_U64("connection_code", tcause->error_code);
+        }
+
+        QLOG_STR_LEN("reason", tcause->reason, tcause->reason_len);
+    QLOG_EVENT_END()
+#endif
+}
index 0cd9df1b2c65dcd161e408e5074e1fdf4e46f962..9e8f30bf1ebd6b2058954a97c5ce01f9d8d68e17 100644 (file)
@@ -2822,6 +2822,8 @@ static void ch_start_terminating(QUIC_CHANNEL *ch,
     case QUIC_CHANNEL_STATE_ACTIVE:
         copy_tcause(&ch->terminate_cause, tcause);
 
+        ossl_qlog_event_connectivity_connection_closed(ch_get_qlog(ch), tcause);
+
         if (!force_immediate) {
             ch_record_state_transition(ch, tcause->remote
                                            ? QUIC_CHANNEL_STATE_TERMINATING_DRAINING