From 25d96f49ef3f5ccedcfe38141d10df3728eff166 Mon Sep 17 00:00:00 2001 From: MagicBear Date: Tue, 22 Dec 2015 23:10:33 +0800 Subject: [PATCH] luabackend: edns-subnet support --- modules/luabackend/lua_functions.cc | 19 ++++++++++++++++++- modules/luabackend/luabackend.hh | 1 + modules/luabackend/minimal.cc | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/luabackend/lua_functions.cc b/modules/luabackend/lua_functions.cc index a8d3f8dbc..816bcac6d 100644 --- a/modules/luabackend/lua_functions.cc +++ b/modules/luabackend/lua_functions.cc @@ -111,8 +111,9 @@ int l_dnspacket (lua_State *lua) { lua_pushstring(lua, lb->dnspacket->getRemote().c_str()); lua_pushnumber(lua, lb->dnspacket->getRemotePort()); lua_pushstring(lua, lb->dnspacket->getLocal().c_str()); + lua_pushstring(lua, lb->dnspacket->getRealRemote().toString().c_str()); - return 3; + return 4; } int l_logger (lua_State *lua) { @@ -307,6 +308,22 @@ bool LUABackend::getValueFromTable(lua_State *lua, const std::string& key, uint1 return ret; } +bool LUABackend::getValueFromTable(lua_State *lua, const std::string& key, uint8_t& value) { + lua_pushstring(lua, key.c_str()); + lua_gettable(lua, -2); + + bool ret = false; + + if(!lua_isnil(lua, -1)) { + value = (uint8_t)lua_tonumber(lua, -1); + ret = true; + } + + lua_pop(lua, 1); + + return ret; +} + bool LUABackend::getValueFromTable(lua_State *lua, const std::string& key, int& value) { lua_pushstring(lua, key.c_str()); lua_gettable(lua, -2); diff --git a/modules/luabackend/luabackend.hh b/modules/luabackend/luabackend.hh index 0a90553e3..1b2a38045 100644 --- a/modules/luabackend/luabackend.hh +++ b/modules/luabackend/luabackend.hh @@ -160,6 +160,7 @@ private: #endif bool getValueFromTable(lua_State *lua, const std::string& key, uint32_t& value); bool getValueFromTable(lua_State *lua, const std::string& key, uint16_t& value); + bool getValueFromTable(lua_State *lua, const std::string& key, uint8_t& value); bool getValueFromTable(lua_State *lua, const std::string& key, int& value); bool getValueFromTable(lua_State *lua, const std::string& key, bool& value); diff --git a/modules/luabackend/minimal.cc b/modules/luabackend/minimal.cc index a2a1abb51..ec0991377 100644 --- a/modules/luabackend/minimal.cc +++ b/modules/luabackend/minimal.cc @@ -157,6 +157,7 @@ bool LUABackend::get(DNSResourceRecord &rr) { rr.ttl = ::arg().asNum( "default-ttl" ); getValueFromTable(lua, "content", rr.content); + getValueFromTable(lua, "scopeMask", rr.scopeMask); lua_pop(lua, 1 ); -- 2.40.0