From: HÃ¥kan Lindqvist Date: Wed, 20 Apr 2016 22:23:45 +0000 (+0200) Subject: Add getRemoteRaw function to expose the raw remote address to Lua policy scripts X-Git-Tag: rec-4.0.0-alpha3~17^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a9d83110ce0eb9702b3b68ce0c8a5dd48cd1d03;p=thirdparty%2Fpdns.git Add getRemoteRaw function to expose the raw remote address to Lua policy scripts --- diff --git a/pdns/lua-auth.cc b/pdns/lua-auth.cc index 47c7edb3c1..70f1aabd3c 100644 --- a/pdns/lua-auth.cc +++ b/pdns/lua-auth.cc @@ -195,6 +195,18 @@ static int ldp_getRemote(lua_State *L) { return 1; } +static int ldp_getRemoteRaw(lua_State *L) { + DNSPacket *p=ldp_checkDNSPacket(L); + const ComboAddress& ca=p->d_remote; + if(ca.sin4.sin_family == AF_INET) { + lua_pushlstring(L, (const char*)&ca.sin4.sin_addr.s_addr, 4); + } + else { + lua_pushlstring(L, (const char*)&ca.sin6.sin6_addr.s6_addr, 16); + } + return 1; +} + static int ldp_getRcode(lua_State *L) { DNSPacket *p=ldp_checkDNSPacket(L); lua_pushnumber(L, p->d.rcode); @@ -224,6 +236,7 @@ static const struct luaL_Reg ldp_methods [] = { {"getZone", ldp_getZone}, {"addRecords", ldp_addRecords}, {"getRemote", ldp_getRemote}, + {"getRemoteRaw", ldp_getRemoteRaw}, {"getSize", ldp_getSize}, {"getRRCounts", ldp_getRRCounts}, {"getRcode", ldp_getRcode},