From ba461517f8739ef51fa04209ef5f3ecda755d9f7 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Sat, 5 Mar 2016 19:49:07 +0100 Subject: [PATCH] propogate calculated packet cache tag to preresolve (the other hooks could get it with a typing exercise) --- pdns/lua-recursor4.cc | 18 ++++++++++-------- pdns/lua-recursor4.hh | 5 +++-- pdns/pdns_recursor.cc | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/pdns/lua-recursor4.cc b/pdns/lua-recursor4.cc index 2c27519c26..3cd731c769 100644 --- a/pdns/lua-recursor4.cc +++ b/pdns/lua-recursor4.cc @@ -30,7 +30,7 @@ bool RecursorLua4::postresolve(const ComboAddress& remote,const ComboAddress& lo } -bool RecursorLua4::preresolve(const ComboAddress& remote, const ComboAddress& local, const DNSName& query, const QType& qtype, vector& ret, const vector >* ednsOpts, int& res, bool* variable) +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) { return false; } @@ -294,6 +294,7 @@ RecursorLua4::RecursorLua4(const std::string& fname) d_lw->registerMember("localaddr", &DNSQuestion::local); d_lw->registerMember("remoteaddr", &DNSQuestion::remote); d_lw->registerMember("rcode", &DNSQuestion::rcode); + d_lw->registerMember("tag", &DNSQuestion::tag); d_lw->registerMember("variable", &DNSQuestion::variable); d_lw->registerMember("followupFunction", &DNSQuestion::followupFunction); d_lw->registerMember("followupPrefix", &DNSQuestion::followupPrefix); @@ -395,29 +396,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, int& ret, bool* variable) +bool RecursorLua4::preresolve(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector& res, const vector >* ednsOpts, unsigned int tag, int& ret, bool* variable) { - return genhook(d_preresolve, remote, local, query, qtype, res, ednsOpts, ret, variable); + return genhook(d_preresolve, remote, local, query, qtype, res, ednsOpts, tag, ret, variable); } bool RecursorLua4::nxdomain(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector& res, int& ret, bool* variable) { - return genhook(d_nxdomain, remote, local, query, qtype, res, 0, ret, variable); + return genhook(d_nxdomain, remote, local, query, qtype, res, 0, 0, ret, variable); } bool RecursorLua4::nodata(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector& res, int& ret, bool* variable) { - return genhook(d_nodata, remote, local, query, qtype, res, 0, ret, variable); + return genhook(d_nodata, remote, local, query, qtype, res, 0, 0, ret, variable); } bool RecursorLua4::postresolve(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector& res, int& ret, bool* variable) { - return genhook(d_postresolve, remote, local, query, qtype, res, 0, ret, variable); + return genhook(d_postresolve, remote, local, query, qtype, res, 0, 0, ret, variable); } bool RecursorLua4::preoutquery(const ComboAddress& ns, const ComboAddress& requestor, const DNSName& query, const QType& qtype, vector& res, int& ret) { - return genhook(d_preoutquery, ns, requestor, query, qtype, res, 0, ret, 0); + return genhook(d_preoutquery, ns, requestor, query, qtype, res, 0, 0, ret, 0); } bool RecursorLua4::ipfilter(const ComboAddress& remote, const ComboAddress& local, const struct dnsheader& dh) @@ -434,7 +435,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, int& ret, bool* variable) +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, int& ret, bool* variable) { if(!func) return false; @@ -445,6 +446,7 @@ bool RecursorLua4::genhook(luacall_t& func, const ComboAddress& remote,const Com dq->local=local; dq->remote=remote; dq->records = res; + dq->tag = tag; dq->ednsOptions = ednsOpts; bool handled=func(dq); if(variable) *variable |= dq->variable; // could still be set to indicate this *name* is variable diff --git a/pdns/lua-recursor4.hh b/pdns/lua-recursor4.hh index 9ff7aa278b..49353b055b 100644 --- a/pdns/lua-recursor4.hh +++ b/pdns/lua-recursor4.hh @@ -12,7 +12,7 @@ class RecursorLua4 : public boost::noncopyable public: explicit RecursorLua4(const std::string& fname); - bool preresolve(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector& res, const vector >* ednsOpts, int& ret, bool* variable); + bool preresolve(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector& res, const vector >* ednsOpts, unsigned int tag, 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, int& ret, bool* variable); @@ -33,6 +33,7 @@ private: ComboAddress local, remote; int rcode{0}; // struct dnsheader, packet length would be great + int tag{0}; vector records; void addAnswer(uint16_t type, const std::string& content, boost::optional ttl, boost::optional name); void addRecord(uint16_t type, const std::string& content, DNSResourceRecord::Place place, boost::optional ttl, boost::optional name); @@ -59,7 +60,7 @@ private: LuaContext* d_lw; 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, int& ret, bool* variable); + 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, 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 b59fd66bbf..c21c2fa16e 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -709,7 +709,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, 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), ret, dc->d_ednsOpts.empty() ? 0 : &dc->d_ednsOpts, dc->d_tag, res, &variableAnswer)) { try { res = sr.beginResolve(dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), dc->d_mdp.d_qclass, ret); } -- 2.47.2