]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Provide bindings to know which TLS provider is in use
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 26 Aug 2021 14:25:36 +0000 (16:25 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 26 Aug 2021 15:19:13 +0000 (17:19 +0200)
pdns/dnsdist-lua-bindings.cc
pdns/dnsdistdist/docs/reference/config.rst
pdns/dnsdistdist/test-dnsdisttcp_cc.cc
pdns/tcpiohandler.cc
pdns/tcpiohandler.hh

index f8c04b8d0e9c87359842ad7a338bca635c1f534a..7f0568ff8816fcdebfb2aca835db80e46f6b90a4 100644 (file)
@@ -354,10 +354,34 @@ void setupLuaBindings(LuaContext& luaCtx, bool client)
       setLuaNoSideEffect();
       return fe.local.toStringWithPort();
     });
-  luaCtx.registerFunction<std::string(ClientState::*)()>("__tostring", [](const ClientState& fe) {
+  luaCtx.registerFunction<std::string(ClientState::*)()const>("__tostring", [](const ClientState& fe) {
       setLuaNoSideEffect();
       return fe.local.toStringWithPort();
     });
+  luaCtx.registerFunction<std::string(ClientState::*)()const>("getType", [](const ClientState& fe) {
+      setLuaNoSideEffect();
+      return fe.getType();
+  });
+  luaCtx.registerFunction<std::string(ClientState::*)()const>("getConfiguredTLSProvider", [](const ClientState& fe) {
+      setLuaNoSideEffect();
+      if (fe.tlsFrontend != nullptr) {
+        return fe.tlsFrontend->getRequestedProvider();
+      }
+      else if (fe.dohFrontend != nullptr) {
+        return std::string("openssl");
+      }
+      return std::string();
+  });
+  luaCtx.registerFunction<std::string(ClientState::*)()const>("getEffectiveTLSProvider", [](const ClientState& fe) {
+      setLuaNoSideEffect();
+      if (fe.tlsFrontend != nullptr) {
+        return fe.tlsFrontend->getEffectiveProvider();
+      }
+      else if (fe.dohFrontend != nullptr) {
+        return std::string("openssl");
+      }
+      return std::string();
+  });
   luaCtx.registerMember("muted", &ClientState::muted);
 #ifdef HAVE_EBPF
   luaCtx.registerFunction<void(ClientState::*)(std::shared_ptr<BPFFilter>)>("attachFilter", [](ClientState& frontend, std::shared_ptr<BPFFilter> bpf) {
index 29913fa6d63395f8b321668886c9223359da024d..10f66916377aa5f611d830dc01ff6195427cdb3a 100644 (file)
@@ -854,6 +854,24 @@ ClientState functions
 
      Remove the BPF filter associated to this frontend, if any.
 
+  .. method:: ClientState:getEffectiveTLSProvider() -> string
+
+    .. versionadded:: 1.7.0
+
+    Return the name of the TLS provider actually used.
+
+  .. method:: ClientState:getRequestedTLSProvider() -> string
+
+    .. versionadded:: 1.7.0
+
+    Return the name of the TLS provider requested in the configuration.
+
+  .. method:: ClientState:getType() -> string
+
+    .. versionadded:: 1.7.0
+
+    Return the type of the frontend: UDP, UDP (DNSCrypt), TCP, TCP (DNSCrypt), TCP (DNS over TLS) or TCP (DNS over HTTPS).
+
   .. method:: ClientState:toString() -> string
 
     Return the address and port this frontend is listening on.
index 4f506fefc1ca517edb1d939dbbc7e84b31f467c5..8e479b4beef164be1faa44175f4e00afb816cb9b 100644 (file)
@@ -294,6 +294,11 @@ public:
   {
     return 0;
   }
+
+  std::string getName() const override
+  {
+    return "Mockup TLS";
+  }
 };
 
 class MockupFDMultiplexer : public FDMultiplexer
index daa49a1a59593fa9ccc312e4d92513fc3d0937b0..a6a90b8a89f6886584bcc738fed22d0314df1cfc 100644 (file)
@@ -562,6 +562,11 @@ public:
     return d_feContext->d_ticketKeys.getKeysCount();
   }
 
+  std::string getName() const override
+  {
+    return "openssl";
+  }
+
 private:
   std::shared_ptr<OpenSSLFrontendContext> d_feContext;
   std::unique_ptr<SSL_CTX, void(*)(SSL_CTX*)> d_tlsCtx; // client context
@@ -1204,6 +1209,11 @@ public:
     return *(d_ticketsKey.read_lock()) != nullptr ? 1 : 0;
   }
 
+  std::string getName() const override
+  {
+    return "gnutls";
+  }
+
 private:
   std::unique_ptr<gnutls_certificate_credentials_st, void(*)(gnutls_certificate_credentials_t)> d_creds;
   gnutls_priority_t d_priorityCache{nullptr};
index 6b8a4c1fba67556c9ae96e0ca5b06ee413c02826..89fde1f6bfd1111c531f17886f98be48a8f7d372 100644 (file)
@@ -98,6 +98,7 @@ public:
   }
 
   virtual size_t getTicketsKeysCount() = 0;
+  virtual std::string getName() const = 0;
 
 protected:
   std::atomic_flag d_rotatingTicketsKey;
@@ -178,6 +179,19 @@ public:
     return res;
   }
 
+  std::string getRequestedProvider() const
+  {
+    return d_provider;
+  }
+
+  std::string getEffectiveProvider() const
+  {
+    if (d_ctx) {
+      return d_ctx->getName();
+    }
+    return "";
+  }
+
   TLSConfig d_tlsConfig;
   TLSErrorCounters d_tlsCounters;
   ComboAddress d_addr;