]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add get*BindCount() functions
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 20 Feb 2020 15:02:33 +0000 (16:02 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 20 Feb 2020 15:02:33 +0000 (16:02 +0100)
Allow getting the number of binds of each kind to be able to iterate
over them.

pdns/dnsdist-console.cc
pdns/dnsdist-lua.cc
pdns/dnsdist.hh
pdns/dnsdistdist/docs/reference/config.rst
pdns/dnsdistdist/docs/reference/dnscrypt.rst

index 6c0dc6b7963ad2a1b6a7d15979f9df9f23d4b59d..f5d559a5c2f0d8ec1314dd030d1a1f7573baa864 100644 (file)
@@ -395,8 +395,11 @@ const std::vector<ConsoleKeyword> g_consoleKeywords{
   { "generateDNSCryptProviderKeys", true, "\"/path/to/providerPublic.key\", \"/path/to/providerPrivate.key\"", "generate a new provider keypair" },
   { "getAction", true, "n", "Returns the Action associated with rule n" },
   { "getBind", true, "n", "returns the listener at index n" },
+  { "getBindCount", true, "", "returns the number of listeners all kinds" },
   { "getDNSCryptBind", true, "n", "return the `DNSCryptContext` object corresponding to the bind `n`" },
+  { "geDNSCrypttBindCount", true, "", "returns the number of DNSCrypt listeners" },
   { "getDOHFrontend", true, "n", "returns the DOH frontend with index n" },
+  { "getDOHFrontendCount", true, "", "returns the number of DoH listeners" },
   { "getPool", true, "name", "return the pool named `name`, or \"\" for the default pool" },
   { "getPoolServers", true, "pool", "return servers part of this pool" },
   { "getQueryCounters", true, "[max=10]", "show current buffer of query counters, limited by 'max' if provided" },
@@ -407,6 +410,7 @@ const std::vector<ConsoleKeyword> g_consoleKeywords{
   { "getStatisticsCounters", true, "", "returns a map of statistic counters" },
   { "getTLSContext", true, "n", "returns the TLS context with index n" },
   { "getTLSFrontend", true, "n", "returns the TLS frontend with index n" },
+  { "getTLSFrontendCount", true, "", "returns the number of DoT listeners" },
   { "grepq", true, "Netmask|DNS Name|100ms|{\"::1\", \"powerdns.com\", \"100ms\"} [, n]", "shows the last n queries and responses matching the specified client address or range (Netmask), or the specified DNS Name, or slower than 100ms" },
   { "HTTPHeaderRule", true, "name, regex", "matches DoH queries with a HTTP header 'name' whose content matches the regular expression 'regex'"},
   { "HTTPPathRegexRule", true, "regex", "matches DoH queries whose HTTP path matches 'regex'"},
index fde5fd0ce90673b49598f4516f8d7189d90769d2..83b76a80c3de8e0c56fa42c15fb733a087f64f87 100644 (file)
@@ -565,7 +565,7 @@ static void setupLuaConfig(bool client, bool configCheck)
       try {
        ComboAddress loc(addr, 53);
         for (auto it = g_frontends.begin(); it != g_frontends.end(); ) {
-          /* TLS and DNSCrypt frontends are separate */
+          /* DoH, DoT and DNSCrypt frontends are separate */
           if ((*it)->tlsFrontend == nullptr && (*it)->dnscryptCtx == nullptr) {
             it = g_frontends.erase(it);
           }
@@ -1287,6 +1287,11 @@ static void setupLuaConfig(bool client, bool configCheck)
 #endif
     });
 
+  g_lua.writeFunction("getDNSCryptBindCount", []() {
+      setLuaNoSideEffect();
+      return g_dnsCryptLocals.size();
+    });
+
   g_lua.writeFunction("generateDNSCryptProviderKeys", [client](const std::string& publicKeyFile, const std::string privateKeyFile) {
       setLuaNoSideEffect();
 #ifdef HAVE_DNSCRYPT
@@ -1443,6 +1448,11 @@ static void setupLuaConfig(bool client, bool configCheck)
       return ret;
       });
 
+  g_lua.writeFunction("getBindCount", []() {
+      setLuaNoSideEffect();
+      return g_frontends.size();
+    });
+
   g_lua.writeFunction("help", [](boost::optional<std::string> command) {
       setLuaNoSideEffect();
       g_outputBuffer = "";
@@ -1967,6 +1977,11 @@ static void setupLuaConfig(bool client, bool configCheck)
         return result;
       });
 
+    g_lua.writeFunction("getDOHFrontendCount", []() {
+        setLuaNoSideEffect();
+        return g_dohlocals.size();
+      });
+
     g_lua.registerFunction<void(std::shared_ptr<DOHFrontend>::*)()>("reloadCertificates", [](std::shared_ptr<DOHFrontend> frontend) {
         if (frontend != nullptr) {
           frontend->reloadCertificates();
@@ -2125,6 +2140,11 @@ static void setupLuaConfig(bool client, bool configCheck)
         return result;
       });
 
+    g_lua.writeFunction("getTLSFrontendCount", []() {
+        setLuaNoSideEffect();
+        return g_tlslocals.size();
+      });
+
     g_lua.registerFunction<void(std::shared_ptr<TLSCtx>::*)()>("rotateTicketsKey", [](std::shared_ptr<TLSCtx> ctx) {
         if (ctx != nullptr) {
           ctx->rotateTicketsKey(time(nullptr));
index 99f85ee0c02c10e763fc5a069dc62b705d632d16..76ac18a7e4f658324c86174327fe4df172703951 100644 (file)
@@ -1043,7 +1043,6 @@ extern GlobalStateHolder<NetmaskGroup> g_ACL;
 
 extern ComboAddress g_serverControl; // not changed during runtime
 
-extern std::vector<std::tuple<ComboAddress, bool, bool, int, std::string, std::set<int>>> g_locals; // not changed at runtime (we hope XXX)
 extern std::vector<shared_ptr<TLSFrontend>> g_tlslocals;
 extern std::vector<shared_ptr<DOHFrontend>> g_dohlocals;
 extern std::vector<std::unique_ptr<ClientState>> g_frontends;
index cbd1de0d53d82c266c09e866e2711cbb1c99900d..7949cf2d6e62226d3de15b63ca79630198a13332 100644 (file)
@@ -728,6 +728,12 @@ Also called frontend or bind, the Client State object returned by :func:`getBind
 
   :param int index: The object index
 
+.. function:: getBindCount()
+
+  .. versionadded:: 1.5.0
+
+  Return the number of binds (Do53, DNSCrypt, DoH and DoT).
+
 ClientState functions
 ~~~~~~~~~~~~~~~~~~~~~
 
@@ -768,6 +774,12 @@ Status, Statistics and More
 
   Return the DOHFrontend object for the DNS over HTTPS bind of index ``idx``.
 
+.. function:: getDOHFrontendCount()
+
+  .. versionadded:: 1.5.0
+
+  Return the number of DOHFrontend binds.
+
 .. function:: getTLSContext(idx)
 
   .. versionadded:: 1.3.0
@@ -780,6 +792,12 @@ Status, Statistics and More
 
   Return the TLSFrontend object for the TLS bind of index ``idx``.
 
+.. function:: getTLSFrontendCount()
+
+  .. versionadded:: 1.5.0
+
+  Return the number of TLSFrontend binds.
+
 .. function:: grepq(selector[, num])
               grepq(selectors[, num])
 
index c012445dc35d41e029d2a8688d1eb7f4a5c15146..8d428a9ec0d13c78cb5bfa78661176d42b1493cb 100644 (file)
@@ -62,6 +62,12 @@ DNSCrypt objects and functions
 
   Return the :class:`DNSCryptContext` object corresponding to the bind ``n``.
 
+.. function:: getDNSCryptBindCount()
+
+  .. versionadded:: 1.5.0
+
+  Return the number of DNSCrypt binds.
+
 Certificates
 ------------