From 4c641a9a7360940afb2dfb8f2edf0a061de5aa71 Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Mon, 31 Aug 2020 14:44:19 +0200 Subject: [PATCH] dnsdist: Accept string in DNSDistPacketCache:expungeByName --- .../dnsdistdist/dnsdist-lua-bindings-packetcache.cc | 13 ++++++++++--- pdns/dnsdistdist/docs/reference/config.rst | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc b/pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc index 27c20b41b0..b6d687a759 100644 --- a/pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc +++ b/pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc @@ -116,13 +116,20 @@ void setupLuaBindingsPacketCache() } return static_cast(0); }); - g_lua.registerFunction::*)(const DNSName& dname, boost::optional qtype, boost::optional suffixMatch)>("expungeByName", []( + g_lua.registerFunction::*)(const boost::variant& dname, boost::optional qtype, boost::optional suffixMatch)>("expungeByName", []( std::shared_ptr& cache, - const DNSName& dname, + const boost::variant& dname, boost::optional qtype, boost::optional suffixMatch) { + DNSName qname; + if (dname.type() == typeid(DNSName)) { + qname = boost::get(dname); + } + if (dname.type() == typeid(string)) { + qname = DNSName(boost::get(dname)); + } if (cache) { - g_outputBuffer="Expunged " + std::to_string(cache->expungeByName(dname, qtype ? *qtype : QType(QType::ANY).getCode(), suffixMatch ? *suffixMatch : false)) + " records\n"; + g_outputBuffer="Expunged " + std::to_string(cache->expungeByName(qname, qtype ? *qtype : QType(QType::ANY).getCode(), suffixMatch ? *suffixMatch : false)) + " records\n"; } }); g_lua.registerFunction::*)()>("printStats", [](const std::shared_ptr& cache) { diff --git a/pdns/dnsdistdist/docs/reference/config.rst b/pdns/dnsdistdist/docs/reference/config.rst index 8487126c9c..7c3667e790 100644 --- a/pdns/dnsdistdist/docs/reference/config.rst +++ b/pdns/dnsdistdist/docs/reference/config.rst @@ -746,6 +746,9 @@ See :doc:`../guides/cache` for a how to. .. versionchanged:: 1.2.0 ``suffixMatch`` parameter added. + .. versionchanged:: 1.6.0 + ``name`` can now also be a string + Remove entries matching ``name`` and type from the cache. :param DNSName name: The name to expunge -- 2.47.2