From: bert hubert Date: Mon, 28 Dec 2015 10:12:22 +0000 (+0000) Subject: make ipfilter get passed the dnsheader, make dnsheader useful for lua X-Git-Tag: dnsdist-1.0.0-alpha2~137^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f5062066366874f42c7a307cdc93bb67ad44da2d;p=pdns make ipfilter get passed the dnsheader, make dnsheader useful for lua --- diff --git a/pdns/lua-recursor4.cc b/pdns/lua-recursor4.cc index 12916218a..64fb42733 100644 --- a/pdns/lua-recursor4.cc +++ b/pdns/lua-recursor4.cc @@ -167,6 +167,21 @@ struct DynMetric RecursorLua4::RecursorLua4(const std::string& fname) { d_lw = new LuaContext; + + d_lw->registerFunction("getID", [](dnsheader& dh) { return dh.id; }); + d_lw->registerFunction("getCD", [](dnsheader& dh) { return dh.cd; }); + d_lw->registerFunction("getTC", [](dnsheader& dh) { return dh.tc; }); + d_lw->registerFunction("getRA", [](dnsheader& dh) { return dh.ra; }); + d_lw->registerFunction("getAD", [](dnsheader& dh) { return dh.ad; }); + d_lw->registerFunction("getAA", [](dnsheader& dh) { return dh.aa; }); + d_lw->registerFunction("getRD", [](dnsheader& dh) { return dh.rd; }); + d_lw->registerFunction("getRCODE", [](dnsheader& dh) { return dh.rcode; }); + d_lw->registerFunction("getOPCODE", [](dnsheader& dh) { return dh.opcode; }); + d_lw->registerFunction("getQDCOUNT", [](dnsheader& dh) { return ntohs(dh.qdcount); }); + d_lw->registerFunction("getANCOUNT", [](dnsheader& dh) { return ntohs(dh.ancount); }); + d_lw->registerFunction("getNSCOUNT", [](dnsheader& dh) { return ntohs(dh.nscount); }); + d_lw->registerFunction("getARCOUNT", [](dnsheader& dh) { return ntohs(dh.arcount); }); + d_lw->writeFunction("newDN", [](const std::string& dom){ return DNSName(dom); }); d_lw->registerFunction("isPartOf", &DNSName::isPartOf); d_lw->registerFunction("equal", @@ -306,7 +321,7 @@ bool RecursorLua4::preoutquery(const ComboAddress& ns, const ComboAddress& reque bool RecursorLua4::ipfilter(const ComboAddress& remote, const ComboAddress& local, const struct dnsheader& dh) { if(d_ipfilter) - return d_ipfilter({remote}, {local}); + return d_ipfilter(remote, local, dh); return false; // don't block } diff --git a/pdns/lua-recursor4.hh b/pdns/lua-recursor4.hh index 6af51a509..ee8b56c63 100644 --- a/pdns/lua-recursor4.hh +++ b/pdns/lua-recursor4.hh @@ -49,7 +49,7 @@ private: typedef std::function)> luacall_t; luacall_t d_preresolve, d_nxdomain, d_nodata, d_postresolve, d_preoutquery, d_postoutquery; bool genhook(luacall_t& func, const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector& res, int& ret, bool* variable); - typedef std::function ipfilter_t; + typedef std::function ipfilter_t; ipfilter_t d_ipfilter; }; diff --git a/pdns/powerdns-example-script.lua b/pdns/powerdns-example-script.lua index 8177b0ab3..23a1ab2c1 100644 --- a/pdns/powerdns-example-script.lua +++ b/pdns/powerdns-example-script.lua @@ -91,8 +91,9 @@ badips = newNMG() badips:addMask("127.1.0.0/16") -- this check is applied before any packet parsing is done -function ipfilter(loc, rem) - print("ipfilter called, rem: ", rem:toString(), badips:match(rem)) +function ipfilter(rem, loc, dh) + print("ipfilter called, rem: ", rem:toString(), "loc: ",loc:toString(),"match:", badips:match(rem)) + print("id: ",dh:getID(), "aa: ", dh:getAA(), "ad: ", dh:getAD(), "arcount: ", dh:getARCOUNT()) return badips:match(rem) end