]> granicus.if.org Git - pdns/commitdiff
dnsdist: Add `showResponseRules()`, `{mv,rm,top}ResponseRule()`
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 19 May 2016 10:17:18 +0000 (12:17 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 19 May 2016 10:17:18 +0000 (12:17 +0200)
pdns/README-dnsdist.md
pdns/dnsdist-console.cc
pdns/dnsdist-lua2.cc

index 70bb432f4f8d9a248b337bca0e89041e26e9c448..2b40c35787a88702df947f283895e0e564222670 100644 (file)
@@ -1078,9 +1078,13 @@ instantiate a server with additional parameters
  * Rule management related:
     * `getAction(num)`: returns the Action associate with rule 'num'.
     * `showRules()`: show all defined rules (Pool, Block, QPS, addAnyTCRule)
-    * `rmRule(n)`: remove rule n
+    * `mvResponseRule(from, to)`: move response rule 'from' to a position where it is in front of 'to'. 'to' can be one larger than the largest rule,
+     in which case the rule will be moved to the last position.
     * `mvRule(from, to)`: move rule 'from' to a position where it is in front of 'to'. 'to' can be one larger than the largest rule,
      in which case the rule will be moved to the last position.
+    * `rmResponseRule(n)`: remove response rule n
+    * `rmRule(n)`: remove rule n
+    * `topResponseRule()`: move the last response rule to the first position
     * `topRule()`: move the last rule to the first position
  * Built-in Actions for Rules:
     * `AllowAction()`: let these packets go through
index f3ba05124752c579538d05a57f5b3cfa434708e5..eb1476dcd630aa41ded7a52c576faed8c35540bb 100644 (file)
@@ -234,22 +234,23 @@ char* my_generator(const char* text, int state)
       "generateDNSCryptCertificate(", "generateDNSCryptProviderKeys(", "getPoolServers(", "getResponseRing(",
       "getServer(", "getServers()", "grepq(",
       "leastOutstanding", "LogAction(",
-      "makeKey()", "MaxQPSIPRule(", "MaxQPSRule(", "mvRule(",
+      "makeKey()", "MaxQPSIPRule(", "MaxQPSRule(", "mvResponseRule(",
+      "mvRule(",
       "newDNSName(", "newQPSLimiter(", "newRemoteLogger(", "newServer(",
       "newServerPolicy(", "newSuffixMatchNode(", "NoRecurseAction(",
       "PoolAction(", "printDNSCryptProviderFingerprint(",
-      "RegexRule(", "RemoteLogAction(", "RemoteLogResponseAction(", "rmRule(",
-      "rmServer(", "roundrobin",
+      "RegexRule(", "RemoteLogAction(", "RemoteLogResponseAction(", "rmResponseRule(",
+      "rmRule(", "rmServer(", "roundrobin",
       "QTypeRule(",
       "setACL(", "setDNSSECPool(", "setECSOverride(",
       "setECSSourcePrefixV4(", "setECSSourcePrefixV6(", "setKey(", "setLocal(",
       "setMaxTCPClientThreads(", "setMaxTCPQueuedConnections(", "setMaxUDPOutstanding(", "setServerPolicy(",
       "setServerPolicyLua(",
       "setTCPRecvTimeout(", "setTCPSendTimeout(", "setVerboseHealthChecks(", "show(", "showACL()",
-      "showDNSCryptBinds()", "showDynBlocks()", "showResponseLatency()", "showRules()",
-      "showServerPolicy()", "showServers()", "shutdown()", "SpoofAction(",
+      "showDNSCryptBinds()", "showDynBlocks()", "showResponseLatency()", "showResponseRules()",
+      "showRules()", "showServerPolicy()", "showServers()", "shutdown()", "SpoofAction(",
       "TCAction(", "testCrypto()", "topBandwidth(", "topClients(",
-      "topQueries(", "topResponses(", "topRule()", "topSlow(",
+      "topQueries(", "topResponses(", "topResponseRule()", "topRule()", "topSlow(",
       "truncateTC(",
       "webserver(", "whashed", "wrandom" };
   static int s_counter=0;
index ada1ebbd77859fabd218f5ad9aa9a12145900316..16799a6bfe107bc4b3bb71365334f4ad80ea2e68 100644 (file)
@@ -606,4 +606,57 @@ void moreLua(bool client)
 
     g_lua.registerFunction("getStats", &DNSAction::getStats);
 
+    g_lua.writeFunction("showResponseRules", []() {
+        setLuaNoSideEffect();
+        boost::format fmt("%-3d %9d %-50s %s\n");
+        g_outputBuffer += (fmt % "#" % "Matches" % "Rule" % "Action").str();
+        int num=0;
+        for(const auto& lim : g_resprulactions.getCopy()) {
+          string name = lim.first->toString();
+          g_outputBuffer += (fmt % num % lim.first->d_matches % name % lim.second->toString()).str();
+          ++num;
+        }
+      });
+
+    g_lua.writeFunction("rmResponseRule", [](unsigned int num) {
+        setLuaSideEffect();
+        auto rules = g_resprulactions.getCopy();
+        if(num >= rules.size()) {
+          g_outputBuffer = "Error: attempt to delete non-existing rule\n";
+          return;
+        }
+        rules.erase(rules.begin()+num);
+        g_resprulactions.setState(rules);
+      });
+
+    g_lua.writeFunction("topResponseRule", []() {
+        setLuaSideEffect();
+        auto rules = g_resprulactions.getCopy();
+        if(rules.empty())
+          return;
+        auto subject = *rules.rbegin();
+        rules.erase(std::prev(rules.end()));
+        rules.insert(rules.begin(), subject);
+        g_resprulactions.setState(rules);
+      });
+
+    g_lua.writeFunction("mvResponseRule", [](unsigned int from, unsigned int to) {
+        setLuaSideEffect();
+        auto rules = g_resprulactions.getCopy();
+        if(from >= rules.size() || to > rules.size()) {
+          g_outputBuffer = "Error: attempt to move rules from/to invalid index\n";
+          return;
+        }
+        auto subject = rules[from];
+        rules.erase(rules.begin()+from);
+        if(to == rules.size())
+          rules.push_back(subject);
+        else {
+          if(from < to)
+            --to;
+          rules.insert(rules.begin()+to, subject);
+        }
+        g_resprulactions.setState(rules);
+      });
+
 }