]> granicus.if.org Git - pdns/commitdiff
added hooks to access port numbers of 'local' addresses, but turns out we don't alway...
authorbert hubert <bert.hubert@netherlabs.nl>
Thu, 7 Jan 2016 10:32:12 +0000 (11:32 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Thu, 7 Jan 2016 10:32:12 +0000 (11:32 +0100)
pdns/dnsdist-lua.cc
pdns/lua-recursor4.cc
pdns/powerdns-example-script.lua

index 23221aa432ab88c1ccb0e3c03c21fa53b56a37f6..e9b8b676db259dc6045c0bd92f2bbc6ff549322e 100644 (file)
@@ -788,7 +788,8 @@ vector<std::function<void(void)>> setupLua(bool client, const std::string& confi
 
 
   g_lua.registerFunction("tostring", &ComboAddress::toString);
-
+  g_lua.registerFunction("tostringWithPort", &ComboAddress::toStringWithPort);
+  g_lua.registerFunction<uint16_t(ComboAddress::*)()>("getPort", [](const ComboAddress& ca) { return ntohs(ca.sin4.sin_port); } );
   g_lua.registerFunction("isPartOf", &DNSName::isPartOf);
   g_lua.registerFunction<string(DNSName::*)()>("tostring", [](const DNSName&dn ) { return dn.toString(); });
   g_lua.writeFunction("newDNSName", [](const std::string& name) { return DNSName(name); });
index 64fb427338a0c48dccd92edd3a7564f9b21caddb..73b2a06f2900093cbfa6514dfaf9e7ca13bf6dac 100644 (file)
@@ -189,6 +189,9 @@ RecursorLua4::RecursorLua4(const std::string& fname)
   d_lw->registerFunction("__eq", &DNSName::operator==);
 
   d_lw->registerFunction<string(ComboAddress::*)()>("toString", [](const ComboAddress& ca) { return ca.toString(); });
+  d_lw->registerFunction<string(ComboAddress::*)()>("toStringWithPort", [](const ComboAddress& ca) { return ca.toStringWithPort(); });
+  d_lw->registerFunction<uint16_t(ComboAddress::*)()>("getPort", [](const ComboAddress& ca) { return ntohs(ca.sin4.sin_port); } );
+
   d_lw->writeFunction("newCA", [](const std::string& a) { return ComboAddress(a); });
 
   d_lw->registerFunction<bool(ComboAddress::*)(const ComboAddress&)>("equal", [](const ComboAddress& lhs, const ComboAddress& rhs) {
index 23a1ab2c151499c5739a99a5462ed386c3b16095..6b08dcedc5cc17b031fc27d5ddf9c6655df157b3 100644 (file)
@@ -92,8 +92,9 @@ badips:addMask("127.1.0.0/16")
 
 -- this check is applied before any packet parsing is done
 function ipfilter(rem, loc, dh)
-       print("ipfilter called, rem: ", rem:toString(), "loc: ",loc:toString(),"match:", badips:match(rem))
+       print("ipfilter called, rem: ", rem:toStringWithPort(), "loc: ",loc:toStringWithPort(),"match:", badips:match(rem))
        print("id: ",dh:getID(), "aa: ", dh:getAA(), "ad: ", dh:getAD(), "arcount: ", dh:getARCOUNT())
+       print("ports: ",rem:getPort(),loc:getPort())
        return badips:match(rem)
 end