* `newNMG()`: return a new NetmaskTree<DynBlock>
* member `add(ComboAddress, msg[, seconds])`: insert a new address into a DynBlock
* NetmaskGroup related
- * nothing yet
+ * function `newNMG()`: returns a NetmaskGroup
+ * member `addMask(mask)`: adds `mask` to the NetmaskGroup
+ * member `match(ComboAddress)`: checks if ComboAddress is matched by this NetmaskGroup
+ * member `clear()`: clears the NetmaskGroup
+ * member `size()`: returns number of netmasks in this NetmaskGroup
* QPSLimiter related:
* `newQPSLimiter(rate, burst)`: configure a QPS limiter with that rate and that burst capacity
* member `check()`: check if this QPSLimiter has a token for us. If yes, you must use it.
{
typedef NetmaskTree<DynBlock> nmts_t;
g_lua.writeFunction("newCA", [](const std::string& name) { return ComboAddress(name); });
- g_lua.writeFunction("newNMG", []() { return nmts_t(); });
- g_lua.registerFunction<void(nmts_t::*)(const ComboAddress&, const std::string&, boost::optional<int> seconds)>("add",
- [](nmts_t& s, const ComboAddress& ca, const std::string& msg, boost::optional<int> seconds)
- {
- struct timespec until;
- clock_gettime(CLOCK_MONOTONIC, &until);
- until.tv_sec += seconds ? *seconds : 10;
-
- s.insert(Netmask(ca)).second={msg, until};
- });
-
- g_lua.writeFunction("setDynBlockNMG", [](const nmts_t& nmg) {
- setLuaSideEffect();
- g_dynblockNMG.setState(nmg);
- });
+
+
+ g_lua.writeFunction("newNMG", []() { return NetmaskGroup(); });
+ g_lua.registerFunction<void(NetmaskGroup::*)(const std::string&mask)>("addMask", [](NetmaskGroup&nmg, const std::string& mask)
+ {
+ nmg.addMask(mask);
+ });
+
+ g_lua.registerFunction("match", (bool (NetmaskGroup::*)(const ComboAddress&) const)&NetmaskGroup::match);
+ g_lua.registerFunction("size", &NetmaskGroup::size);
+ g_lua.registerFunction("clear", &NetmaskGroup::clear);
+
g_lua.writeFunction("showDynBlocks", []() {
setLuaNoSideEffect();
block=newDNSName("powerdns.org.")
-- called before we distribute a question
+
+truncateNMG = newNMG()
+truncateNMG:addMask("213.244.0.0/16")
+truncateNMG:addMask("2001:503:ba3e::2:30")
+truncateNMG:addMask("fe80::/16")
+
+print(string.format("Have %d entries in truncate NMG", truncateNMG:size()))
+
function blockFilter(remote, qname, qtype, dh)
- if(qtype==255)
+ if(qtype==255 or truncateNMG:match(remote))
then
-- print("any query, tc=1")
dh:setTC(true)