From: Remi Gacogne Date: Sat, 18 Mar 2017 20:42:33 +0000 (+0100) Subject: dnsdist: Add `NetmaskGroup::addMasks()` to fill a NMG from `exceeds*` results X-Git-Tag: rec-4.1.0-alpha1~157^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a25c01b7ca67f58fd7bd274b8e2455b636616ee;p=thirdparty%2Fpdns.git dnsdist: Add `NetmaskGroup::addMasks()` to fill a NMG from `exceeds*` results --- diff --git a/pdns/README-dnsdist.md b/pdns/README-dnsdist.md index b3acec5df6..d6ade37f6d 100644 --- a/pdns/README-dnsdist.md +++ b/pdns/README-dnsdist.md @@ -1594,6 +1594,8 @@ instantiate a server with additional parameters * NetmaskGroup related * function `newNMG()`: returns a NetmaskGroup * member `addMask(mask)`: adds `mask` to the NetmaskGroup. Prefix with `!` to exclude this mask from matching. + * member `addMask(table)`: adds the keys of `table` to the NetmaskGroup. `table` should be a table whose keys + are `ComboAddress` objects and values are integers, as returned by `exceed*` functions * 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 diff --git a/pdns/dnsdist-lua2.cc b/pdns/dnsdist-lua2.cc index e7016f05b8..1bd3a1bc82 100644 --- a/pdns/dnsdist-lua2.cc +++ b/pdns/dnsdist-lua2.cc @@ -206,9 +206,15 @@ void moreLua(bool client) g_lua.writeFunction("newNMG", []() { return NetmaskGroup(); }); g_lua.registerFunction("addMask", [](NetmaskGroup&nmg, const std::string& mask) - { - nmg.addMask(mask); - }); + { + nmg.addMask(mask); + }); + g_lua.registerFunction& map)>("addMasks", [](NetmaskGroup&nmg, const std::map& map) + { + for (const auto& entry : map) { + nmg.addMask(Netmask(entry.first)); + } + }); g_lua.registerFunction("match", (bool (NetmaskGroup::*)(const ComboAddress&) const)&NetmaskGroup::match); g_lua.registerFunction("size", &NetmaskGroup::size);