]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Convert remaining files to structured logging
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 23 Dec 2025 15:46:39 +0000 (16:46 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 19 Jan 2026 10:01:23 +0000 (11:01 +0100)
Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
pdns/dnsdistdist/Makefile.am
pdns/tcpiohandler.cc
pdns/threadname.cc

index 401caf0c5e719b4f9366e68c8c12d985f89f7c7b..184a86deb12025df106b7fde73f33ba5fc4e3aba 100644 (file)
@@ -623,6 +623,7 @@ fuzz_targets_deps = standalone_fuzz_target_runner.o
 fuzz_target_dnsdistcache_SOURCES = \
        channel.hh channel.cc \
        dns.cc dns.hh \
+       dnscrypt.cc dnscrypt.hh \
        dnsdist-cache.cc dnsdist-cache.hh \
        dnsdist-configuration.cc dnsdist-configuration.hh \
        dnsdist-crypto.cc dnsdist-crypto.hh \
@@ -631,11 +632,13 @@ fuzz_target_dnsdistcache_SOURCES = \
        dnsdist-ecs.cc dnsdist-ecs.hh \
        dnsdist-idstate.cc dnsdist-idstate.hh \
        dnsdist-logging.cc dnsdist-logging.hh \
+       dnsdist-opentelemetry.cc dnsdist-opentelemetry.hh \
        dnsdist-protocols.cc dnsdist-protocols.hh \
        dnslabeltext.cc \
        dnsname.cc dnsname.hh \
        dnsparser.cc dnsparser.hh \
        dnswriter.cc dnswriter.hh \
+       dolog.cc dolog.hh \
        ednsoptions.cc ednsoptions.hh \
        ednssubnet.cc ednssubnet.hh \
        ext/json11/json11.cpp \
@@ -646,6 +649,7 @@ fuzz_target_dnsdistcache_SOURCES = \
        logging.cc logging.hh \
        misc.cc misc.hh \
        packetcache.hh \
+       protozero-trace.cc protozero-trace.hh \
        qtype.cc qtype.hh \
        svc-records.cc svc-records.hh
 
index 3dfd588246313481f10aea2dfa63c4c3f8e21911..0138655824ba45cb3fd7cc75a99518ad469cf756 100644 (file)
@@ -3,6 +3,7 @@
 #include "dolog.hh"
 #include "iputils.hh"
 #include "lock.hh"
+#include "logging.hh"
 #include "tcpiohandler.hh"
 
 const bool TCPIOHandler::s_disableConnectForUnitTests = false;
@@ -68,7 +69,12 @@ public:
 
     auto [ctx, warnings] = libssl_init_server_context(tlsConfig);
     for (const auto& warning : warnings) {
+#if defined(DNSDIST)
+      SLOG(warnlog("%s", warning),
+           dnsdist::logging::getTopLogger()->info(Logr::Warning, warning));
+#else /* DNSDIST */
       warnlog("%s", warning);
+#endif /* DNSDIST */
     }
     // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer): it cannot be initialized before calling libssl_init_server_context()
     d_ocspResponses = std::move(ctx.d_ocspResponses);
@@ -155,7 +161,8 @@ public:
     d_socket = socket;
 
     if (!d_conn) {
-      vinfolog("Error creating TLS object");
+      VERBOSESLOG(infolog("Error creating TLS object"),
+                  dnsdist::logging::getTopLogger()->info(Logr::Info, "Error creating server-side TLS object"));
       if (shouldDoVerboseLogging()) {
         ERR_print_errors_fp(stderr);
       }
@@ -175,7 +182,8 @@ public:
     d_socket = socket;
 
     if (!d_conn) {
-      vinfolog("Error creating TLS object");
+      VERBOSESLOG(infolog("Error creating TLS object"),
+                  dnsdist::logging::getTopLogger()->info(Logr::Info, "Error creating client-side TLS object"));
       if (shouldDoVerboseLogging()) {
         ERR_print_errors_fp(stderr);
       }
@@ -829,8 +837,13 @@ public:
 
       SSL_CTX_set_verify(d_tlsCtx.get(), SSL_VERIFY_PEER, nullptr);
 #if (OPENSSL_VERSION_NUMBER < 0x10002000L)
+#if defined(DNSDIST)
+      SLOG(warnlog("TLS hostname validation requested but not supported for OpenSSL < 1.0.2"),
+           dnsdist::logging::getTopLogger()->info(Logr::Warning, "TLS hostname validation requested but not supported for OpenSSL < 1.0.2"));
+#else /* DNSDIST */
       warnlog("TLS hostname validation requested but not supported for OpenSSL < 1.0.2");
-#endif
+#endif /* DNSDIST */
+#endif /* OPENSSL_VERSION_NUMBER < 0x10002000L */
     }
 
     /* we need to set SSL_SESS_CACHE_CLIENT for the "new ticket" callback (below) to be called,
@@ -1442,7 +1455,8 @@ public:
         else if (res == GNUTLS_E_AGAIN) {
           return IOState::NeedWrite;
         }
-        vinfolog("Warning, non-fatal error while writing to TLS connection: %s", gnutls_strerror(res));
+        VERBOSESLOG(infolog("Warning, non-fatal error while writing to TLS connection: %s", gnutls_strerror(res)),
+                    dnsdist::logging::getTopLogger()->error(Logr::Info, gnutls_strerror(res), "Non-fatal error while writing to TLS connection", "tls.provider", Logging::Loggable("GnuTLS")));
       }
     }
     while (pos < toWrite);
@@ -1478,7 +1492,8 @@ public:
         else if (res == GNUTLS_E_AGAIN) {
           return IOState::NeedRead;
         }
-        vinfolog("Warning, non-fatal error while writing to TLS connection: %s", gnutls_strerror(res));
+        VERBOSESLOG(infolog("Warning, non-fatal error while writing to TLS connection: %s", gnutls_strerror(res)),
+                    dnsdist::logging::getTopLogger()->error(Logr::Info, gnutls_strerror(res), "Non-fatal error while writing to TLS connection", "tls.provider", Logging::Loggable("GnuTLS")));
       }
     }
     while (pos < toRead);
@@ -1516,7 +1531,8 @@ public:
           }
         }
         else {
-          vinfolog("Non-fatal error while reading from TLS connection: %s", gnutls_strerror(res));
+          VERBOSESLOG(infolog("Non-fatal error while reading from TLS connection: %s", gnutls_strerror(res)),
+                      dnsdist::logging::getTopLogger()->error(Logr::Info, gnutls_strerror(res), "Non-fatal error while reading from TLS connection", "tls.provider", Logging::Loggable("GnuTLS")));
         }
       }
 
@@ -1559,7 +1575,8 @@ public:
           }
         }
         else {
-          vinfolog("Non-fatal error while writing to TLS connection: %s", gnutls_strerror(res));
+          VERBOSESLOG(infolog("Non-fatal error while writing to TLS connection: %s", gnutls_strerror(res)),
+                      dnsdist::logging::getTopLogger()->error(Logr::Info, gnutls_strerror(res), "Non-fatal error while writing to TLS connection", "tls.provider", Logging::Loggable("GnuTLS")));
         }
       }
     }
@@ -1742,7 +1759,12 @@ public:
     for (const auto& file : frontend.d_tlsConfig.d_ocspFiles) {
       rc = gnutls_certificate_set_ocsp_status_request_file(d_creds.get(), file.c_str(), count);
       if (rc != GNUTLS_E_SUCCESS) {
+#if defined(DNSDIST)
+        SLOG(warnlog("Error loading OCSP response from file '%s' for certificate ('%s') and key ('%s') for TLS context on %s: %s", file, frontend.d_tlsConfig.d_certKeyPairs.at(count).d_cert, frontend.d_tlsConfig.d_certKeyPairs.at(count).d_key.value(), frontend.d_addr.toStringWithPort(), gnutls_strerror(rc)),
+             dnsdist::logging::getTopLogger()->error(Logr::Warning, gnutls_strerror(rc), "Error loading OCSP response for TLS context", "tls.provider", Logging::Loggable("GnuTLS"), "frontend.address", Logging::Loggable(frontend.d_addr), "tls.ocsp_file", Logging::Loggable(file), "tls.certificate_file", Logging::Loggable(frontend.d_tlsConfig.d_certKeyPairs.at(count).d_cert), "tls.key_file", Logging::Loggable(frontend.d_tlsConfig.d_certKeyPairs.at(count).d_key.value())));
+#else /* DNSDIST */
         warnlog("Error loading OCSP response from file '%s' for certificate ('%s') and key ('%s') for TLS context on %s: %s", file, frontend.d_tlsConfig.d_certKeyPairs.at(count).d_cert, frontend.d_tlsConfig.d_certKeyPairs.at(count).d_key.value(), frontend.d_addr.toStringWithPort(), gnutls_strerror(rc));
+#endif /* DNSDIST */
       }
       ++count;
     }
index 90b7b974a14afa608a6a5a32ab7382b8b4ff8d88..25e9efb9a2b08c18d1da4661c8ccf91bcaa23bcf 100644 (file)
@@ -71,11 +71,11 @@ void setThreadName(const std::string& threadName) {
 
   if (retval != 0) {
 #ifdef DNSDIST
-    warnlog("Could not set thread name %s for thread: %s", threadName, strerror(retval));
+    SLOG(warnlog("Could not set thread name %s for thread: %s", threadName, strerror(retval)),
+         dnsdist::logging::getTopLogger()->withName("runtime")->error(Logr::Warning, retval, "Could not set thread name", "name", Logging::Loggable(threadName)));
 #else
     SLOG(g_log<<Logger::Warning<<"Could not set thread name "<<threadName<<" for thread: "<<strerror(retval)<<endl,
          g_slog->withName("runtime")->error(Logr::Warning, retval, "Could not set thread name", "name", Logging::Loggable(threadName)));
 #endif
   }
 }
-