]> granicus.if.org Git - pdns/commitdiff
dnsdist: Add `quiet` parameter to NetmaskGroupRule
authorPieter Lexis <pieter.lexis@powerdns.com>
Wed, 26 Jun 2019 14:35:23 +0000 (16:35 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Wed, 26 Jun 2019 14:47:54 +0000 (16:47 +0200)
pdns/dnsdist-lua-rules.cc
pdns/dnsdistdist/dnsdist-rules.hh
pdns/dnsdistdist/docs/rules-actions.rst

index b781e8c79ac5ecef92b8e0b98dc95ea2e9015cb6..98aae9ddb2acd1575e026532dc9efaadfb7105a2 100644 (file)
@@ -303,8 +303,8 @@ void setupLuaRules()
       return std::shared_ptr<DNSRule>(new SuffixMatchNodeRule(smn, quiet ? *quiet : false));
     });
 
-  g_lua.writeFunction("NetmaskGroupRule", [](const NetmaskGroup& nmg, boost::optional<bool> src) {
-      return std::shared_ptr<DNSRule>(new NetmaskGroupRule(nmg, src ? *src : true));
+  g_lua.writeFunction("NetmaskGroupRule", [](const NetmaskGroup& nmg, boost::optional<bool> src, boost::optional<bool> quiet) {
+      return std::shared_ptr<DNSRule>(new NetmaskGroupRule(nmg, src ? *src : true, quiet ? *quiet : false));
     });
 
   g_lua.writeFunction("benchRule", [](std::shared_ptr<DNSRule> rule, boost::optional<int> times_, boost::optional<string> suffix_)  {
index 4827a6aa0274ce1096aee356b3b25f2ac8cae56c..1d9944e5270b82859eed0b2592545fbc412b035e 100644 (file)
@@ -183,9 +183,10 @@ protected:
 class NetmaskGroupRule : public NMGRule
 {
 public:
-  NetmaskGroupRule(const NetmaskGroup& nmg, bool src) : NMGRule(nmg)
+  NetmaskGroupRule(const NetmaskGroup& nmg, bool src, bool quiet = false) : NMGRule(nmg)
   {
       d_src = src;
+      d_quiet = quiet;
   }
   bool matches(const DNSQuestion* dq) const override
   {
@@ -197,13 +198,18 @@ public:
 
   string toString() const override
   {
+    string ret = "Src: ";
     if(!d_src) {
-        return "Dst: "+d_nmg.toString();
+        ret = "Dst: ";
     }
-    return "Src: "+d_nmg.toString();
+    if (d_quiet) {
+      return ret + "in-group";
+    }
+    return ret + d_nmg.toString();
   }
 private:
   bool d_src;
+  bool d_quiet;
 };
 
 class TimedIPSetRule : public DNSRule, boost::noncopyable
index 58eff1c9c18ef27c23493df6a8ee4f36cc773631..26c8d4cc890af4a6c801eb1c9fbbcccfc815235f 100644 (file)
@@ -613,7 +613,10 @@ These ``DNSRule``\ s be one of the following items:
 
   :param int qps: The number of queries per second allowed, above this number the traffic is **not** matched anymore
 
-.. function:: NetmaskGroupRule(nmg[, src])
+.. function:: NetmaskGroupRule(nmg[, src[, quiet]])
+
+  .. versionchanged:: 1.4.0
+    ``quiet`` parameter added
 
   Matches traffic from/to the network range specified in ``nmg``.
 
@@ -622,6 +625,7 @@ These ``DNSRule``\ s be one of the following items:
 
   :param NetMaskGroup nmg: The NetMaskGroup to match on
   :param bool src: Whether to match source or destination address of the packet. Defaults to true (matches source)
+  :param bool quiet: Do not return the list of matched netmasks. Default is false.
 
 .. function:: OpcodeRule(code)