From cc0e7aa9cfc34ed2791bb5435f46180df81e1c69 Mon Sep 17 00:00:00 2001 From: Andrey Domas Date: Mon, 4 Mar 2019 14:23:02 +0300 Subject: [PATCH] DNSNameSet and QNameSetRule, minor fixes --- pdns/dnsdist-lua-bindings.cc | 2 +- pdns/dnsdistdist/dnsdist-rules.hh | 2 +- pdns/dnsdistdist/docs/reference/dnsnameset.rst | 2 +- pdns/dnsdistdist/docs/rules-actions.rst | 8 ++++++-- pdns/dnsname.hh | 3 ++- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pdns/dnsdist-lua-bindings.cc b/pdns/dnsdist-lua-bindings.cc index ee966ab588..72c3614c88 100644 --- a/pdns/dnsdist-lua-bindings.cc +++ b/pdns/dnsdist-lua-bindings.cc @@ -180,7 +180,7 @@ void setupLuaBindings(bool client) /* DNSNameSet */ g_lua.registerFunction("toString", [](const DNSNameSet&dns ) { return dns.toString(); }); g_lua.registerFunction("add", [](DNSNameSet& dns, DNSName& dn) { dns.insert(dn); }); - g_lua.registerFunction("contains", [](DNSNameSet& dns, DNSName& dn) { return dns.find(dn) != dns.end(); }); + g_lua.registerFunction("check", [](DNSNameSet& dns, DNSName& dn) { return dns.find(dn) != dns.end(); }); g_lua.registerFunction("delete",(size_t (DNSNameSet::*)(const DNSName&)) &DNSNameSet::erase); g_lua.registerFunction("size",(size_t (DNSNameSet::*)() const) &DNSNameSet::size); g_lua.registerFunction("clear",(void (DNSNameSet::*)()) &DNSNameSet::clear); diff --git a/pdns/dnsdistdist/dnsdist-rules.hh b/pdns/dnsdistdist/dnsdist-rules.hh index c29e48d65c..166b9282af 100644 --- a/pdns/dnsdistdist/dnsdist-rules.hh +++ b/pdns/dnsdistdist/dnsdist-rules.hh @@ -545,7 +545,7 @@ private: class QNameSetRule : public DNSRule { public: - QNameSetRule(const DNSNameSet names) : qname_idx(names) {} + QNameSetRule(const DNSNameSet& names) : qname_idx(names) {} bool matches(const DNSQuestion* dq) const override { return qname_idx.find(*dq->qname) != qname_idx.end(); diff --git a/pdns/dnsdistdist/docs/reference/dnsnameset.rst b/pdns/dnsdistdist/docs/reference/dnsnameset.rst index 49b28602c5..2344dc3a63 100644 --- a/pdns/dnsdistdist/docs/reference/dnsnameset.rst +++ b/pdns/dnsdistdist/docs/reference/dnsnameset.rst @@ -53,7 +53,7 @@ Functions and methods of a ``DNSNameSet`` :param DNSName name The name to remove. - .. method:: DNSNameSet:contains(name) -> bool + .. method:: DNSNameSet:check(name) -> bool Returns true if the set contains the name. diff --git a/pdns/dnsdistdist/docs/rules-actions.rst b/pdns/dnsdistdist/docs/rules-actions.rst index b6f2d980e4..50b215b0c6 100644 --- a/pdns/dnsdistdist/docs/rules-actions.rst +++ b/pdns/dnsdistdist/docs/rules-actions.rst @@ -611,9 +611,11 @@ These ``DNSRule``\ s be one of the following items: :param string qname: Qname to match .. function:: QNameSetRule(set) - Matches if the set contains qname. + Matches if the set contains excact qname. - :param DNSNameSet set: Set with qnames. + To match subdomain names, see :func:`SuffixMatchNodeRule`. + + :param DNSNameSet set: Set with qnames. .. function:: QNameLabelsCountRule(min, max) @@ -718,6 +720,8 @@ These ``DNSRule``\ s be one of the following items: Matches based on a group of domain suffixes for rapid testing of membership. Pass true as second parameter to prevent listing of all domains matched. + To match domain names exactly, see :func:`QNameSetRule`. + :param SuffixMatchNode smb: The SuffixMatchNode to match on :param bool quiet: Do not return the list of matched domains. Default is false. diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index 0f64376f6e..a8ea1a9228 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -379,7 +380,7 @@ bool DNSName::operator==(const DNSName& rhs) const extern const DNSName g_rootdnsname, g_wildcarddnsname; -struct DNSNameSet: public std::set { +struct DNSNameSet: public std::unordered_set { std::string toString() const { std::ostringstream oss; std::copy(begin(), end(), std::ostream_iterator(oss, "\n")); -- 2.47.2