From: Pieter Lexis Date: Wed, 13 Feb 2019 15:11:28 +0000 (+0100) Subject: rec_control: add clear-dont-throttle-* functions X-Git-Tag: rec-4.2.0-beta1~7^2~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa7cc8af522b5f94df1044231b7c43b9e3d1a179;p=thirdparty%2Fpdns.git rec_control: add clear-dont-throttle-* functions --- diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 850cf935ae..d130d3e0a3 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -1373,6 +1373,105 @@ string addDontThrottleNetmasks(T begin, T end) { return ret + "\n"; } +template +string clearDontThrottleNames(T begin, T end) { + if(begin == end) + return "No names specified, doing nothing.\n"; + + if (begin + 1 == end && *begin == "*"){ + SuffixMatchNode smn; + g_dontThrottleNames.setState(smn); + string ret = "Cleared list of nameserver names that may not be throttled"; + g_log< toRemove; + while (begin != end) { + try { + if (*begin == "*") { + return "Please don't mix '*' with other names, nothing removed\n"; + } + toRemove.push_back(DNSName(*begin)); + } + catch (const std::exception &e) { + return "Problem parsing '" + *begin + "': "+ e.what() + ", nothing removed\n"; + } + begin++; + } + + string ret = "Removed"; + bool first = true; + auto dnt = g_dontThrottleNames.getCopy(); + for (const auto &name : toRemove) { + if (!first) { + ret += ","; + } + first = false; + ret += " " + name.toLogString(); + dnt.remove(name); + } + + g_dontThrottleNames.setState(dnt); + + ret += " from the list of nameservers that may not be throttled"; + g_log< +string clearDontThrottleNetmasks(T begin, T end) { + if(begin == end) + return "No netmasks specified, doing nothing.\n"; + + if (begin + 1 == end && *begin == "*"){ + auto nmg = g_dontThrottleNetmasks.getCopy(); + nmg.clear(); + g_dontThrottleNetmasks.setState(nmg); + + string ret = "Cleared list of nameserver addresses that may not be throttled"; + g_log< toRemove; + while (begin != end) { + try { + if (*begin == "*") { + return "Please don't mix '*' with other netmasks, nothing removed\n"; + } + auto n = Netmask(*begin); + toRemove.push_back(n); + } + catch(const std::exception &e) { + return "Problem parsing '" + *begin + "': "+ e.what() + ", nothing added\n"; + } + catch(const PDNSException &e) { + return "Problem parsing '" + *begin + "': "+ e.reason + ", nothing added\n"; + } + begin++; + } + + string ret = "Removed"; + bool first = true; + auto dnt = g_dontThrottleNetmasks.getCopy(); + for (const auto &mask : toRemove) { + if (!first) { + ret += ","; + } + first = false; + ret += " " + mask.toString(); + dnt.deleteMask(mask); + } + + g_dontThrottleNetmasks.setState(dnt); + + ret += " from the list of nameservers that may not be throttled"; + g_log< dump cache contents to the named file\n" @@ -1646,5 +1748,13 @@ string RecursorControlParser::getAnswer(const string& question, RecursorControlP return addDontThrottleNetmasks(begin, end); } + if (cmd == "clear-dont-throttle-names") { + return clearDontThrottleNames(begin, end); + } + + if (cmd == "clear-dont-throttle-netmasks") { + return clearDontThrottleNetmasks(begin, end); + } + return "Unknown command '"+cmd+"', try 'help'\n"; }