]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
implemented src parameter for NetmaskGroupRule
authorReinier Schoof <reinier@skoef.nl>
Tue, 5 Jul 2016 19:11:25 +0000 (21:11 +0200)
committerReinier Schoof <reinier@skoef.nl>
Tue, 5 Jul 2016 19:11:25 +0000 (21:11 +0200)
pdns/README-dnsdist.md
pdns/dnsdist-lua.cc
pdns/dnsrulactions.hh

index b4076558c4942f40e3731e2a25df2df97b7867b8..0043ff3607515ad29c8d04f75f4a53b21f60b826 100644 (file)
@@ -1215,7 +1215,7 @@ instantiate a server with additional parameters
     * `DNSSECRule()`: matches queries with the DO flag set
     * `MaxQPSIPRule(qps, v4Mask=32, v6Mask=64)`: matches traffic exceeding the qps limit per subnet
     * `MaxQPSRule(qps)`: matches traffic **not** exceeding this qps limit
-    * `NetmaskGroupRule()`: matches traffic from the specified network range
+    * `NetmaskGroupRule(nmg, [src-bool])`: matches traffic from the specified network range. Pass `false` as second parameter to match NetmaskGroup  against destination address instead of source address
     * `NotRule()`: matches if the sub-rule does not match
     * `OrRule()`: matches if at least one of the sub-rules matches
     * `OpcodeRule()`: matches queries with the specified opcode
index ebd6e41889d6afbadc2d94e9aa07e9041b82d65c..ca39e25ab4b0809ba0400a6cbd4bfe61a1c22866 100644 (file)
@@ -779,8 +779,8 @@ vector<std::function<void(void)>> setupLua(bool client, const std::string& confi
       return std::shared_ptr<DNSRule>(new SuffixMatchNodeRule(smn, quiet ? *quiet : false));
     });
 
-  g_lua.writeFunction("NetmaskGroupRule", [](const NetmaskGroup& nmg) {
-      return std::shared_ptr<DNSRule>(new NetmaskGroupRule(nmg));
+  g_lua.writeFunction("NetmaskGroupRule", [](const NetmaskGroup& nmg, bool src = true) {
+      return std::shared_ptr<DNSRule>(new NetmaskGroupRule(nmg, src));
     });
 
   g_lua.writeFunction("benchRule", [](std::shared_ptr<DNSRule> rule, boost::optional<int> times_, boost::optional<string> suffix_)  {
index d364157460d28b1202cd804925a6bd466f46fffa..e5422270a97730bcfddd7111b2dd82876f4bc8b9 100644 (file)
@@ -90,16 +90,27 @@ protected:
 class NetmaskGroupRule : public NMGRule
 {
 public:
-  NetmaskGroupRule(const NetmaskGroup& nmg) : NMGRule(nmg) {}
+  NetmaskGroupRule(const NetmaskGroup& nmg, bool src) : NMGRule(nmg)
+  {
+      d_src = src;
+  }
   bool matches(const DNSQuestion* dq) const override
   {
+    if(!d_src) {
+        return d_nmg.match(*dq->local);
+    }
     return d_nmg.match(*dq->remote);
   }
 
   string toString() const override
   {
+    if(!d_src) {
+        return "Dst: "+d_nmg.toString();
+    }
     return "Src: "+d_nmg.toString();
   }
+private:
+  bool d_src;
 };
 
 class AllRule : public DNSRule