]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add getRemoteRaw function to expose the raw remote address to Lua policy scripts
authorHåkan Lindqvist <h@qw.se>
Wed, 20 Apr 2016 22:23:45 +0000 (00:23 +0200)
committerHåkan Lindqvist <h@qw.se>
Wed, 20 Apr 2016 22:23:45 +0000 (00:23 +0200)
pdns/lua-auth.cc

index 47c7edb3c1d14b11154402ef00e86207f08fe731..70f1aabd3c1ebba3d2bf4af8025affc523d7fb50 100644 (file)
@@ -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},