]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add `NetmaskGroup::addMasks()` to fill a NMG from `exceeds*` results 5185/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Sat, 18 Mar 2017 20:42:33 +0000 (21:42 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 20 Mar 2017 21:19:11 +0000 (22:19 +0100)
pdns/README-dnsdist.md
pdns/dnsdist-lua2.cc

index b3acec5df67740352ca27b087b7bd5686fc88b07..d6ade37f6da4c4abe68b0aa4b6aad7f0751307ea 100644 (file)
@@ -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
index e7016f05b8f07309080aba4ce24322133faf4487..1bd3a1bc8201c241a00bcf28e2778d9b267a864a 100644 (file)
@@ -206,9 +206,15 @@ void moreLua(bool client)
 
   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);
-                        });
+                         {
+                           nmg.addMask(mask);
+                         });
+    g_lua.registerFunction<void(NetmaskGroup::*)(const std::map<ComboAddress,int>& map)>("addMasks", [](NetmaskGroup&nmg, const std::map<ComboAddress,int>& 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);