]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
add support for matchnetmask to be called with a table of IP addresses
authorBert Hubert <bert.hubert@netherlabs.nl>
Wed, 18 Jun 2008 21:15:48 +0000 (21:15 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Wed, 18 Jun 2008 21:15:48 +0000 (21:15 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1206 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/lua-pdns-recursor.cc

index 44302e6315e5af42bf859006d3d3e28303d505d0..05ce8329094daa90d54ee31d847e56897ef9d481 100644 (file)
@@ -42,23 +42,42 @@ extern "C" {
 
 using namespace std;
 
+bool netmaskMatchTable(lua_State* lua, const std::string& ip)
+{
+  lua_pushnil(lua);  /* first key */
+  while (lua_next(lua, 2) != 0) {
+    string netmask=lua_tostring(lua, -1);
+    Netmask nm(netmask);
+    ComboAddress ca(ip);
+    lua_pop(lua, 1);
+    
+    if(nm.match(ip)) 
+      return true;
+  }
+  return false;
+}
+
 extern "C" int netmaskMatchLua(lua_State *lua)
 {
   bool result=false;
   if(lua_gettop(lua) >= 2) {
     string ip=lua_tostring(lua, 1);
-    for(int n=2 ; n <= lua_gettop(lua); ++n) { 
-      string netmask=lua_tostring(lua, n);
-      
-      Netmask nm(netmask);
-      ComboAddress ca(ip);
-      
-      result = nm.match(ip);
-      if(result)
-       break;
-      
+    if(lua_istable(lua, 2)) {
+      result = netmaskMatchTable(lua, ip);
+    }
+    else {
+      for(int n=2 ; n <= lua_gettop(lua); ++n) { 
+       string netmask=lua_tostring(lua, n);
+       Netmask nm(netmask);
+       ComboAddress ca(ip);
+       
+       result = nm.match(ip);
+       if(result)
+         break;
+      }
     }
   }
+  
   lua_pushboolean(lua, result);
   return 1;
 }