From: bert hubert Date: Thu, 7 Jan 2016 10:32:12 +0000 (+0100) Subject: added hooks to access port numbers of 'local' addresses, but turns out we don't alway... X-Git-Tag: dnsdist-1.0.0-alpha2~119^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0a1123655032d128723dd008eea80f03f181598c;p=pdns added hooks to access port numbers of 'local' addresses, but turns out we don't always fill them out yet --- diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 23221aa43..e9b8b676d 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -788,7 +788,8 @@ vector> setupLua(bool client, const std::string& confi g_lua.registerFunction("tostring", &ComboAddress::toString); - + g_lua.registerFunction("tostringWithPort", &ComboAddress::toStringWithPort); + g_lua.registerFunction("getPort", [](const ComboAddress& ca) { return ntohs(ca.sin4.sin_port); } ); g_lua.registerFunction("isPartOf", &DNSName::isPartOf); g_lua.registerFunction("tostring", [](const DNSName&dn ) { return dn.toString(); }); g_lua.writeFunction("newDNSName", [](const std::string& name) { return DNSName(name); }); diff --git a/pdns/lua-recursor4.cc b/pdns/lua-recursor4.cc index 64fb42733..73b2a06f2 100644 --- a/pdns/lua-recursor4.cc +++ b/pdns/lua-recursor4.cc @@ -189,6 +189,9 @@ RecursorLua4::RecursorLua4(const std::string& fname) d_lw->registerFunction("__eq", &DNSName::operator==); d_lw->registerFunction("toString", [](const ComboAddress& ca) { return ca.toString(); }); + d_lw->registerFunction("toStringWithPort", [](const ComboAddress& ca) { return ca.toStringWithPort(); }); + d_lw->registerFunction("getPort", [](const ComboAddress& ca) { return ntohs(ca.sin4.sin_port); } ); + d_lw->writeFunction("newCA", [](const std::string& a) { return ComboAddress(a); }); d_lw->registerFunction("equal", [](const ComboAddress& lhs, const ComboAddress& rhs) { diff --git a/pdns/powerdns-example-script.lua b/pdns/powerdns-example-script.lua index 23a1ab2c1..6b08dcedc 100644 --- a/pdns/powerdns-example-script.lua +++ b/pdns/powerdns-example-script.lua @@ -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