From 0f697c45010c89cfd7a6bf023443ddc4b375c7a7 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Mon, 10 Apr 2017 19:23:49 +0200 Subject: [PATCH] add & document QNameRule --- pdns/README-dnsdist.md | 3 +++ pdns/dnsdist-console.cc | 1 + pdns/dnsdist-lua.cc | 4 ++++ pdns/dnsrulactions.hh | 21 ++++++++++++++++++++- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/pdns/README-dnsdist.md b/pdns/README-dnsdist.md index 04e25eabc..6ae77d63f 100644 --- a/pdns/README-dnsdist.md +++ b/pdns/README-dnsdist.md @@ -343,6 +343,7 @@ Rules have selectors and actions. Current selectors are: * QPS Limit total * QPS Limit per IP address or subnet * QClass (QClassRule) + * QName (QNameRule) * QType (QTypeRule) * RegexRule on query name * RE2Rule on query name (optional) @@ -427,6 +428,7 @@ A DNS rule can be: * an OrRule * a QClassRule * a QNameLabelsCountRule + * a QNameRule * a QNameWireLengthRule * a QTypeRule * a RCodeRule @@ -1411,6 +1413,7 @@ instantiate a server with additional parameters * `OpcodeRule()`: matches queries with the specified opcode * `QClassRule(qclass)`: matches queries with the specified qclass (numeric) * `QNameLabelsCountRule(min, max)`: matches if the qname has less than `min` or more than `max` labels + * `QNameRule(qname)`: matches queries with the specified qname * `QNameWireLengthRule(min, max)`: matches if the qname's length on the wire is less than `min` or more than `max` bytes * `QTypeRule(qtype)`: matches queries with the specified qtype * `RCodeRule(rcode)`: matches queries or responses the specified rcode diff --git a/pdns/dnsdist-console.cc b/pdns/dnsdist-console.cc index bc4febd4a..167d03109 100644 --- a/pdns/dnsdist-console.cc +++ b/pdns/dnsdist-console.cc @@ -349,6 +349,7 @@ const std::vector g_consoleKeywords{ { "rmServer", true, "n", "remove server with index n" }, { "roundrobin", false, "", "Simple round robin over available servers" }, { "QNameLabelsCountRule", true, "min, max", "matches if the qname has less than `min` or more than `max` labels" }, + { "QNameRule", true, "qname", "matches queries with the specified qname" }, { "QNameWireLengthRule", true, "min, max", "matches if the qname's length on the wire is less than `min` or more than `max` bytes" }, { "QTypeRule", true, "qtype", "matches queries with the specified qtype" }, { "RCodeRule", true, "rcode", "matches responses with the specified rcode" }, diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index fe0abd01b..6723e9700 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -922,6 +922,10 @@ vector> setupLua(bool client, const std::string& confi return std::shared_ptr(new AllRule()); }); + g_lua.writeFunction("QNameRule", [](const std::string& qname) { + return std::shared_ptr(new QNameRule(DNSName(qname))); + }); + g_lua.writeFunction("QTypeRule", [](boost::variant str) { uint16_t qtype; if(auto dir = boost::get(&str)) { diff --git a/pdns/dnsrulactions.hh b/pdns/dnsrulactions.hh index eec9cb24b..a9cf5e50d 100644 --- a/pdns/dnsrulactions.hh +++ b/pdns/dnsrulactions.hh @@ -300,13 +300,32 @@ public: if(d_quiet) return "qname==in-set"; else - return "qname=="+d_smn.toString(); + return "qname in "+d_smn.toString(); } private: SuffixMatchNode d_smn; bool d_quiet; }; +class QNameRule : public DNSRule +{ +public: + QNameRule(const DNSName& qname) : d_qname(qname) + { + } + bool matches(const DNSQuestion* dq) const override + { + return d_qname==*dq->qname; + } + string toString() const override + { + return "qname=="+d_qname.toString(); + } +private: + DNSName d_qname; +}; + + class QTypeRule : public DNSRule { public: -- 2.40.0