]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Comment on the use of 'poolname', add option to QPSPoolAction as well
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 12 Jan 2022 15:24:43 +0000 (16:24 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 12 Jan 2022 15:24:43 +0000 (16:24 +0100)
pdns/dnsdist-lua-actions.cc
pdns/dnsdist.cc
pdns/dnsdistdist/docs/rules-actions.rst

index 1ce6cc7500abea3f8204b6a8846272e77e9e6c4d..df7189205a32eaaa479f32e3e7732fc4dae553ee 100644 (file)
@@ -278,6 +278,7 @@ public:
   DNSAction::Action operator()(DNSQuestion* dq, std::string* ruleresult) const override
   {
     if (d_stopProcessing) {
+      /* we need to do it that way to keep compatiblity with custom Lua actions returning DNSAction.Pool, 'poolname' */
       *ruleresult = d_pool;
       return Action::Pool;
     }
@@ -289,24 +290,31 @@ public:
 
   std::string toString() const override
   {
-    return "to pool "+d_pool;
+    return "to pool " + d_pool;
   }
 
 private:
-  std::string d_pool;
-  bool d_stopProcessing;
+  const std::string d_pool;
+  const bool d_stopProcessing;
 };
 
 
 class QPSPoolAction : public DNSAction
 {
 public:
-  QPSPoolAction(unsigned int limit, const std::string& pool) : d_qps(QPSLimiter(limit, limit)), d_pool(pool) {}
+  QPSPoolAction(unsigned int limit, const std::string& pool, bool stopProcessing) : d_qps(QPSLimiter(limit, limit)), d_pool(pool), d_stopProcessing(stopProcessing) {}
   DNSAction::Action operator()(DNSQuestion* dq, std::string* ruleresult) const override
   {
     if (d_qps.lock()->check()) {
-      *ruleresult = d_pool;
-      return Action::Pool;
+      if (d_stopProcessing) {
+        /* we need to do it that way to keep compatiblity with custom Lua actions returning DNSAction.Pool, 'poolname' */
+        *ruleresult = d_pool;
+        return Action::Pool;
+      }
+      else {
+        dq->poolname = d_pool;
+        return Action::None;
+      }
     }
     else {
       return Action::None;
@@ -314,12 +322,13 @@ public:
   }
   std::string toString() const override
   {
-    return "max " +std::to_string(d_qps.lock()->getRate())+" to pool "+d_pool;
+    return "max " + std::to_string(d_qps.lock()->getRate()) + " to pool " + d_pool;
   }
 
 private:
   mutable LockGuarded<QPSLimiter> d_qps;
   const std::string d_pool;
+  const bool d_stopProcessing;
 };
 
 class RCodeAction : public DNSAction
@@ -2151,15 +2160,15 @@ void setupLuaActions(LuaContext& luaCtx)
     });
 
   luaCtx.writeFunction("PoolAction", [](const std::string& a, boost::optional<bool> stopProcessing) {
-    return std::shared_ptr<DNSAction>(new PoolAction(a, stopProcessing.get_value_or(true)));
+      return std::shared_ptr<DNSAction>(new PoolAction(a, stopProcessing.get_value_or(true)));
     });
 
   luaCtx.writeFunction("QPSAction", [](int limit) {
       return std::shared_ptr<DNSAction>(new QPSAction(limit));
     });
 
-  luaCtx.writeFunction("QPSPoolAction", [](int limit, const std::string& a) {
-      return std::shared_ptr<DNSAction>(new QPSPoolAction(limit, a));
+  luaCtx.writeFunction("QPSPoolAction", [](int limit, const std::string& a, boost::optional<bool> stopProcessing) {
+      return std::shared_ptr<DNSAction>(new QPSPoolAction(limit, a, stopProcessing.get_value_or(true)));
     });
 
   luaCtx.writeFunction("SpoofAction", [](boost::variant<std::string,vector<pair<int, std::string>>> inp, boost::optional<responseParams_t> vars) {
index 31fc9ad247fee999b5d41ab3bf83472750262bfa..b63d3c2f49ed2de9c6f13940ee79c5c06672149a 100644 (file)
@@ -833,7 +833,9 @@ bool processRulesResult(const DNSAction::Action& action, DNSQuestion& dq, std::s
     return true;
     break;
   case DNSAction::Action::Pool:
-    dq.poolname=ruleresult;
+    /* we need to keep this because a custom Lua action can return
+       DNSAction.Spoof, 'poolname' */
+    dq.poolname = ruleresult;
     return true;
     break;
   case DNSAction::Action::NoRecurse:
index 592cc47a6b3cc7b65c02a792eab32dc672bd92f5..69fd508edaae09d099072178287e95f233ad0573 100644 (file)
@@ -1223,11 +1223,15 @@ The following actions exist.
 
 .. function:: QPSPoolAction(maxqps, poolname)
 
-  Send the packet into the specified pool only if it does not exceed the ``maxqps`` queries per second limits.
+  .. versionchanged:: 1.8.0
+    Added the ``stop`` optional parameter.
+
+  Send the packet into the specified pool only if it does not exceed the ``maxqps`` queries per second limits. If ``stop`` is set to false, subsequent rules will be processed after this action.
   Letting the subsequent rules apply otherwise.
 
   :param int maxqps: The QPS limit for that pool
   :param string poolname: The name of the pool
+  :param bool stop: Whether to stop processing rules after this action. Default is true, meaning the remaining rules will not be processed.
 
 .. function:: RCodeAction(rcode [, options])