From: Remi Gacogne Date: Mon, 20 Jun 2016 09:55:08 +0000 (+0200) Subject: rec: Add `isTcp` to `dq`. Fix building without Lua. X-Git-Tag: auth-4.0.0-rc1~33^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F4017%2Fhead;p=thirdparty%2Fpdns.git rec: Add `isTcp` to `dq`. Fix building without Lua. --- diff --git a/docs/markdown/recursor/scripting.md b/docs/markdown/recursor/scripting.md index a00f6d83dd..bdcc9eef81 100644 --- a/docs/markdown/recursor/scripting.md +++ b/docs/markdown/recursor/scripting.md @@ -83,6 +83,7 @@ The DNSQuestion object contains at least the following fields: * qname - DNS native version of the name this query is for * qtype - type this query is for, can be compared against pdns.A, pdns.AAAA etc * rcode - current DNS Result Code, which can be overridden, including to several magical values +* isTcp - whether the query have been received over TCP or UDP * remoteaddr - address of the requestor * localaddr - address this query was received on * variable - a boolean which, if set, indicates the recursor should not packet cache this answer. Honored even when returning 'false'! Important when providing answers that vary over time or based on sender details. diff --git a/pdns/lua-recursor4.cc b/pdns/lua-recursor4.cc index 8a1f3a0dff..ec2076ef4a 100644 --- a/pdns/lua-recursor4.cc +++ b/pdns/lua-recursor4.cc @@ -14,28 +14,27 @@ RecursorLua4::RecursorLua4(const std::string &fname) throw std::runtime_error("Attempt to load a Lua script in a PowerDNS binary without Lua support"); } -bool RecursorLua4::nxdomain(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector& ret, int& res, bool* variable) +bool RecursorLua4::nxdomain(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, bool isTcp, vector& ret, int& res, bool* variable) { return false; } -bool RecursorLua4::nodata(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector& ret, int& res, bool* variable) +bool RecursorLua4::nodata(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, bool isTcp, vector& ret, int& res, bool* variable) { return false; } -bool RecursorLua4::postresolve(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector& ret, int& res, bool* variable) +bool RecursorLua4::postresolve(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, bool isTcp, vector& ret, std::string* appliedPolicy, std::vector* policyTags, int& res, bool* variable) { return false; } - -bool RecursorLua4::preresolve(const ComboAddress& remote, const ComboAddress& local, const DNSName& query, const QType& qtype, vector& ret, const vector >* ednsOpts, unsigned int tag, int& res, bool* variable) +bool RecursorLua4::preresolve(const ComboAddress& remote, const ComboAddress& local, const DNSName& query, const QType& qtype, bool isTcp, vector& ret, const vector >* ednsOpts, unsigned int tag, std::string* appliedPolicy, std::vector* policyTags, int& res, bool* variable) { return false; } -bool RecursorLua4::preoutquery(const ComboAddress& remote, const ComboAddress& local,const DNSName& query, const QType& qtype, vector& ret, int& res) +bool RecursorLua4::preoutquery(const ComboAddress& remote, const ComboAddress& local,const DNSName& query, const QType& qtype, bool isTcp, vector& ret, int& res) { return false; } @@ -303,6 +302,7 @@ RecursorLua4::RecursorLua4(const std::string& fname) d_lw->registerFunction("chopOff", [](DNSName&dn ) { return dn.chopOff(); }); d_lw->registerMember("qname", &DNSQuestion::qname); d_lw->registerMember("qtype", &DNSQuestion::qtype); + d_lw->registerMember("isTcp", &DNSQuestion::isTcp); d_lw->registerMember("localaddr", &DNSQuestion::local); d_lw->registerMember("remoteaddr", &DNSQuestion::remote); d_lw->registerMember("rcode", &DNSQuestion::rcode); @@ -448,29 +448,29 @@ RecursorLua4::RecursorLua4(const std::string& fname) d_gettag = d_lw->readVariable>("gettag").get_value_or(0); } -bool RecursorLua4::preresolve(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector& res, const vector >* ednsOpts, unsigned int tag, std::string* appliedPolicy, std::vector* policyTags, int& ret, bool* variable) +bool RecursorLua4::preresolve(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, bool isTcp, vector& res, const vector >* ednsOpts, unsigned int tag, std::string* appliedPolicy, std::vector* policyTags, int& ret, bool* variable) { - return genhook(d_preresolve, remote, local, query, qtype, res, ednsOpts, tag, appliedPolicy, policyTags, ret, variable); + return genhook(d_preresolve, remote, local, query, qtype, isTcp, res, ednsOpts, tag, appliedPolicy, policyTags, ret, variable); } -bool RecursorLua4::nxdomain(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector& res, int& ret, bool* variable) +bool RecursorLua4::nxdomain(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, bool isTcp, vector& res, int& ret, bool* variable) { - return genhook(d_nxdomain, remote, local, query, qtype, res, 0, 0, nullptr, nullptr, ret, variable); + return genhook(d_nxdomain, remote, local, query, qtype, isTcp, res, 0, 0, nullptr, nullptr, ret, variable); } -bool RecursorLua4::nodata(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector& res, int& ret, bool* variable) +bool RecursorLua4::nodata(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, bool isTcp, vector& res, int& ret, bool* variable) { - return genhook(d_nodata, remote, local, query, qtype, res, 0, 0, nullptr, nullptr, ret, variable); + return genhook(d_nodata, remote, local, query, qtype, isTcp, res, 0, 0, nullptr, nullptr, ret, variable); } -bool RecursorLua4::postresolve(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector& res, std::string* appliedPolicy, std::vector* policyTags, int& ret, bool* variable) +bool RecursorLua4::postresolve(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, bool isTcp, vector& res, std::string* appliedPolicy, std::vector* policyTags, int& ret, bool* variable) { - return genhook(d_postresolve, remote, local, query, qtype, res, 0, 0, appliedPolicy, policyTags, ret, variable); + return genhook(d_postresolve, remote, local, query, qtype, isTcp, res, 0, 0, appliedPolicy, policyTags, ret, variable); } -bool RecursorLua4::preoutquery(const ComboAddress& ns, const ComboAddress& requestor, const DNSName& query, const QType& qtype, vector& res, int& ret) +bool RecursorLua4::preoutquery(const ComboAddress& ns, const ComboAddress& requestor, const DNSName& query, const QType& qtype, bool isTcp, vector& res, int& ret) { - return genhook(d_preoutquery, ns, requestor, query, qtype, res, 0, 0, nullptr, nullptr, ret, 0); + return genhook(d_preoutquery, ns, requestor, query, qtype, isTcp, res, 0, 0, nullptr, nullptr, ret, 0); } bool RecursorLua4::ipfilter(const ComboAddress& remote, const ComboAddress& local, const struct dnsheader& dh) @@ -487,7 +487,7 @@ int RecursorLua4::gettag(const ComboAddress& remote, const Netmask& ednssubnet, return 0; } -bool RecursorLua4::genhook(luacall_t& func, const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector& res, const vector >* ednsOpts, unsigned int tag, std::string* appliedPolicy, std::vector* policyTags, int& ret, bool* variable) +bool RecursorLua4::genhook(luacall_t& func, const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, bool isTcp, vector& res, const vector >* ednsOpts, unsigned int tag, std::string* appliedPolicy, std::vector* policyTags, int& ret, bool* variable) { if(!func) return false; @@ -500,6 +500,7 @@ bool RecursorLua4::genhook(luacall_t& func, const ComboAddress& remote,const Com dq->records = res; dq->tag = tag; dq->ednsOptions = ednsOpts; + dq->isTcp = isTcp; bool handled=func(dq); if(variable) *variable |= dq->variable; // could still be set to indicate this *name* is variable, even if not 'handled' diff --git a/pdns/lua-recursor4.hh b/pdns/lua-recursor4.hh index 377015a5d6..cd2a6823d4 100644 --- a/pdns/lua-recursor4.hh +++ b/pdns/lua-recursor4.hh @@ -4,6 +4,10 @@ #include "namespaces.hh" #include "dnsrecords.hh" #include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + string GenUDPQueryResponse(const ComboAddress& dest, const string& query); class LuaContext; @@ -11,17 +15,19 @@ class LuaContext; class RecursorLua4 : public boost::noncopyable { private: +#ifdef HAVE_LUA std::unique_ptr d_lw; // this is way on top because it must get destroyed _last_ +#endif public: explicit RecursorLua4(const std::string& fname); ~RecursorLua4(); // this is so unique_ptr works with an incomplete type - bool preresolve(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector& res, const vector >* ednsOpts, unsigned int tag, std::string* appliedPolicy, std::vector* policyTags, int& ret, bool* variable); - bool nxdomain(const ComboAddress& remote, const ComboAddress& local, const DNSName& query, const QType& qtype, vector& res, int& ret, bool* variable); - bool nodata(const ComboAddress& remote, const ComboAddress& local, const DNSName& query, const QType& qtype, vector& res, int& ret, bool* variable); - bool postresolve(const ComboAddress& remote, const ComboAddress& local, const DNSName& query, const QType& qtype, vector& res, std::string* appliedPolicy, std::vector* policyTags, int& ret, bool* variable); + bool preresolve(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, bool isTcp, vector& res, const vector >* ednsOpts, unsigned int tag, std::string* appliedPolicy, std::vector* policyTags, int& ret, bool* variable); + bool nxdomain(const ComboAddress& remote, const ComboAddress& local, const DNSName& query, const QType& qtype, bool isTcp, vector& res, int& ret, bool* variable); + bool nodata(const ComboAddress& remote, const ComboAddress& local, const DNSName& query, const QType& qtype, bool isTcp, vector& res, int& ret, bool* variable); + bool postresolve(const ComboAddress& remote, const ComboAddress& local, const DNSName& query, const QType& qtype, bool isTcp, vector& res, std::string* appliedPolicy, std::vector* policyTags, int& ret, bool* variable); - bool preoutquery(const ComboAddress& ns, const ComboAddress& requestor, const DNSName& query, const QType& qtype, vector& res, int& ret); + bool preoutquery(const ComboAddress& ns, const ComboAddress& requestor, const DNSName& query, const QType& qtype, bool isTcp, vector& res, int& ret); bool ipfilter(const ComboAddress& remote, const ComboAddress& local, const struct dnsheader&); int gettag(const ComboAddress& remote, const Netmask& ednssubnet, const ComboAddress& local, const DNSName& query, uint16_t qtype); @@ -62,11 +68,12 @@ private: string appliedPolicy; std::vector policyTags; + bool isTcp; }; 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, const vector >* ednsOpts, unsigned int tag, std::string* appliedPolicy, std::vector* policyTags, int& ret, bool* variable); + bool genhook(luacall_t& func, const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, bool isTcp, vector& res, const vector >* ednsOpts, unsigned int tag, std::string* appliedPolicy, std::vector* policyTags, int& ret, bool* variable); typedef std::function ipfilter_t; ipfilter_t d_ipfilter; }; diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index c64261c8c1..e047800920 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -831,7 +831,7 @@ void startDoResolve(void *p) } - if(!t_pdl->get() || !(*t_pdl)->preresolve(dc->d_remote, dc->d_local, dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), ret, dc->d_ednsOpts.empty() ? 0 : &dc->d_ednsOpts, dc->d_tag, &appliedPolicy, &policyTags, res, &variableAnswer)) { + if(!t_pdl->get() || !(*t_pdl)->preresolve(dc->d_remote, dc->d_local, dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), dc->d_tcp, ret, dc->d_ednsOpts.empty() ? 0 : &dc->d_ednsOpts, dc->d_tag, &appliedPolicy, &policyTags, res, &variableAnswer)) { try { res = sr.beginResolve(dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), dc->d_mdp.d_qclass, ret); } @@ -893,13 +893,13 @@ void startDoResolve(void *p) if(i->d_type == dc->d_mdp.d_qtype && i->d_place == DNSResourceRecord::ANSWER) break; if(i == ret.cend()) - (*t_pdl)->nodata(dc->d_remote, dc->d_local, dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), ret, res, &variableAnswer); + (*t_pdl)->nodata(dc->d_remote, dc->d_local, dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), dc->d_tcp, ret, res, &variableAnswer); } else if(res == RCode::NXDomain) - (*t_pdl)->nxdomain(dc->d_remote, dc->d_local, dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), ret, res, &variableAnswer); + (*t_pdl)->nxdomain(dc->d_remote, dc->d_local, dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), dc->d_tcp, ret, res, &variableAnswer); - (*t_pdl)->postresolve(dc->d_remote, dc->d_local, dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), ret, &appliedPolicy, &policyTags, res, &variableAnswer); + (*t_pdl)->postresolve(dc->d_remote, dc->d_local, dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), dc->d_tcp, ret, &appliedPolicy, &policyTags, res, &variableAnswer); } } diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 9b8a02727c..c5147d4431 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -1060,7 +1060,7 @@ int SyncRes::doResolveAt(NsSet &nameservers, DNSName auth, bool flawedNSSet, con if(s_maxtotusec && d_totUsec > s_maxtotusec) throw ImmediateServFailException("Too much time waiting for "+qname.toString()+"|"+qtype.getName()+", timeouts: "+std::to_string(d_timeouts) +", throttles: "+std::to_string(d_throttledqueries) + ", queries: "+std::to_string(d_outqueries)+", "+std::to_string(d_totUsec/1000)+"msec"); - if(d_pdl && d_pdl->preoutquery(*remoteIP, d_requestor, qname, qtype, lwr.d_records, resolveret)) { + if(d_pdl && d_pdl->preoutquery(*remoteIP, d_requestor, qname, qtype, doTCP, lwr.d_records, resolveret)) { LOG(prefix<