]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add a 'getAddressAndPort()' method to DOHFrontend and TLSFrontend objects
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 15 Apr 2022 10:57:53 +0000 (12:57 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 15 Apr 2022 10:57:53 +0000 (12:57 +0200)
pdns/dnsdist-lua.cc
pdns/dnsdistdist/docs/reference/config.rst

index 1bdaf55a74041f163ab3946dc70af3806e61c0bf..706572e4b0e92977824af13341467ffb8fcb6a2e 100644 (file)
@@ -2544,6 +2544,13 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
     }
   });
 
+  luaCtx.registerFunction<std::string (std::shared_ptr<DOHFrontend>::*)()const>("getAddressAndPort", [](const std::shared_ptr<DOHFrontend>& frontend) {
+    if (frontend == nullptr) {
+      return std::string();
+    }
+    return frontend->d_local.toStringWithPort();
+  });
+
   luaCtx.writeFunction("addTLSLocal", [client](const std::string& addr, boost::variant<std::string, std::shared_ptr<TLSCertKeyPair>, LuaArray<std::string>, LuaArray<std::shared_ptr<TLSCertKeyPair>>> certFiles, LuaTypeOrArrayOf<std::string> keyFiles, boost::optional<localbind_t> vars) {
     if (client) {
       return;
@@ -2702,6 +2709,13 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
     }
   });
 
+  luaCtx.registerFunction<std::string (std::shared_ptr<TLSFrontend>::*)()const>("getAddressAndPort", [](const std::shared_ptr<TLSFrontend>& frontend) {
+    if (frontend == nullptr) {
+      return std::string();
+    }
+    return frontend->d_addr.toStringWithPort();
+  });
+
   luaCtx.registerFunction<void (std::shared_ptr<TLSFrontend>::*)()>("rotateTicketsKey", [](std::shared_ptr<TLSFrontend>& frontend) {
     if (frontend == nullptr) {
       return;
index 33987be6b3c9263b28347432130e9057d831519e..d77dfc168a0f14f91e3e7f271599b8b753c08bd8 100644 (file)
@@ -1720,6 +1720,12 @@ DOHFrontend
 
   This object represents an address and port dnsdist is listening on for DNS over HTTPS queries.
 
+  .. method:: DOHFrontend:getAddressAndPort() -> string
+
+     .. versionadded:: 1.7.1
+
+     Return the address and port this frontend is listening on.
+
   .. method:: DOHFrontend:loadNewCertificatesAndKeys(certFile(s), keyFile(s))
 
      .. versionadded:: 1.6.1
@@ -1789,6 +1795,12 @@ TLSFrontend
 
   This object represents the configuration of a listening frontend for DNS over TLS queries. To each frontend is associated a TLSContext.
 
+  .. method:: TLSFrontend:getAddressAndPort() -> string
+
+     .. versionadded:: 1.7.1
+
+     Return the address and port this frontend is listening on.
+
   .. method:: TLSFrontend:loadNewCertificatesAndKeys(certFile(s), keyFile(s))
 
      Create and switch to a new TLS context using the same options than were passed to the corresponding `addTLSLocal()` directive, but loading new certificates and keys from the selected files, replacing the existing ones.