From: Remi Gacogne Date: Thu, 20 Feb 2020 15:02:33 +0000 (+0100) Subject: dnsdist: Add get*BindCount() functions X-Git-Tag: rec-4.4.0-alpha0~15^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=265260f5909eb100707dcdc3165fe608d027c3ca;p=thirdparty%2Fpdns.git dnsdist: Add get*BindCount() functions Allow getting the number of binds of each kind to be able to iterate over them. --- diff --git a/pdns/dnsdist-console.cc b/pdns/dnsdist-console.cc index 6c0dc6b796..f5d559a5c2 100644 --- a/pdns/dnsdist-console.cc +++ b/pdns/dnsdist-console.cc @@ -395,8 +395,11 @@ const std::vector 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 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'"}, diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index fde5fd0ce9..83b76a80c3 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -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 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::*)()>("reloadCertificates", [](std::shared_ptr 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::*)()>("rotateTicketsKey", [](std::shared_ptr ctx) { if (ctx != nullptr) { ctx->rotateTicketsKey(time(nullptr)); diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index 99f85ee0c0..76ac18a7e4 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -1043,7 +1043,6 @@ extern GlobalStateHolder g_ACL; extern ComboAddress g_serverControl; // not changed during runtime -extern std::vector>> g_locals; // not changed at runtime (we hope XXX) extern std::vector> g_tlslocals; extern std::vector> g_dohlocals; extern std::vector> g_frontends; diff --git a/pdns/dnsdistdist/docs/reference/config.rst b/pdns/dnsdistdist/docs/reference/config.rst index cbd1de0d53..7949cf2d6e 100644 --- a/pdns/dnsdistdist/docs/reference/config.rst +++ b/pdns/dnsdistdist/docs/reference/config.rst @@ -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]) diff --git a/pdns/dnsdistdist/docs/reference/dnscrypt.rst b/pdns/dnsdistdist/docs/reference/dnscrypt.rst index c012445dc3..8d428a9ec0 100644 --- a/pdns/dnsdistdist/docs/reference/dnscrypt.rst +++ b/pdns/dnsdistdist/docs/reference/dnscrypt.rst @@ -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 ------------