* 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
"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;
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);
+ });
+
}