From: Bert Hubert Date: Wed, 18 Jun 2008 21:15:48 +0000 (+0000) Subject: add support for matchnetmask to be called with a table of IP addresses X-Git-Tag: rec-3.1.7.1~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6300ea8b890b039ae7b9e8e2dc6c4dc2bcec21c2;p=thirdparty%2Fpdns.git add support for matchnetmask to be called with a table of IP addresses git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1206 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/lua-pdns-recursor.cc b/pdns/lua-pdns-recursor.cc index 44302e6315..05ce832909 100644 --- a/pdns/lua-pdns-recursor.cc +++ b/pdns/lua-pdns-recursor.cc @@ -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; }