]> granicus.if.org Git - pdns/commitdiff
add NetmaskGroup to dnsdist Lua and document it, closes #3144
authorbert hubert <bert.hubert@netherlabs.nl>
Sat, 2 Jan 2016 13:15:28 +0000 (14:15 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Sat, 2 Jan 2016 15:53:33 +0000 (16:53 +0100)
pdns/README-dnsdist.md
pdns/dnsdist-lua2.cc
pdns/dnsdistconf.lua

index 17dd2508477d6e0786fb5df9ce896e33231acaa1..348446895a56bc38cfd5530e26ca66cb3cd8f18e 100644 (file)
@@ -854,7 +854,11 @@ instantiate a server with additional parameters
      * `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.
index d1838ec19d3ed909dd75a2da7f73f429a18616df..8bd81e2a63ca0ab4c667fb8d153856bba970fa0c 100644 (file)
@@ -121,21 +121,18 @@ void moreLua()
 {
   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();
index 4258c75cdd727b3c1a41d7a5e47a9eaf1cb0762b..bdb37edf356d1f269a7f848f690b164e4490b5dc 100644 (file)
@@ -46,8 +46,16 @@ addDomainBlock("isis.")
 
 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)