From dff843b2784309feae4da299dd4b661a8f539dd0 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 12 Oct 2016 17:57:52 +0200 Subject: [PATCH] rec: Add a `tcp` parameter to `gettag()` since it's now called for TCP --- docs/markdown/recursor/scripting.md | 5 ++++- pdns/lua-recursor4.cc | 4 ++-- pdns/lua-recursor4.hh | 4 ++-- pdns/pdns_recursor.cc | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/markdown/recursor/scripting.md b/docs/markdown/recursor/scripting.md index ddc2f4cfb..dfd7a5747 100644 --- a/docs/markdown/recursor/scripting.md +++ b/docs/markdown/recursor/scripting.md @@ -153,7 +153,7 @@ end This hook does not get the full DNSQuestion object, since filling out the fields would require packet parsing, which is what we are trying to prevent with `ipfilter`. -### `function gettag(remote, ednssubnet, local, qname, qtype, ednsoptions)` +### `function gettag(remote, ednssubnet, local, qname, qtype, ednsoptions, tcp)` The `gettag` function is invoked when the Recursor attempts to discover in which packetcache an answer is available. @@ -175,6 +175,9 @@ through the entire Lua script. and the content accessible as a NULL-safe string object via `getContent()`. This table is empty unless the `gettag-needs-edns-options` parameter is set. +The `tcp` value (added in 4.1) is a boolean indicating whether the query was +received over `UDP` (false) or `TCP` (true). + ### `function prerpz(dq)` This hook is called before any filtering policy have been applied, making it diff --git a/pdns/lua-recursor4.cc b/pdns/lua-recursor4.cc index 6445db8c6..bb78ae793 100644 --- a/pdns/lua-recursor4.cc +++ b/pdns/lua-recursor4.cc @@ -587,10 +587,10 @@ bool RecursorLua4::ipfilter(const ComboAddress& remote, const ComboAddress& loca return false; // don't block } -unsigned int RecursorLua4::gettag(const ComboAddress& remote, const Netmask& ednssubnet, const ComboAddress& local, const DNSName& qname, uint16_t qtype, std::vector* policyTags, LuaContext::LuaObject& data, const std::map& ednsOptions) +unsigned int RecursorLua4::gettag(const ComboAddress& remote, const Netmask& ednssubnet, const ComboAddress& local, const DNSName& qname, uint16_t qtype, std::vector* policyTags, LuaContext::LuaObject& data, const std::map& ednsOptions, bool tcp) { if(d_gettag) { - auto ret = d_gettag(remote, ednssubnet, local, qname, qtype, ednsOptions); + auto ret = d_gettag(remote, ednssubnet, local, qname, qtype, ednsOptions, tcp); if (policyTags) { const auto& tags = std::get<1>(ret); diff --git a/pdns/lua-recursor4.hh b/pdns/lua-recursor4.hh index 7305b559d..227c1d16e 100644 --- a/pdns/lua-recursor4.hh +++ b/pdns/lua-recursor4.hh @@ -101,7 +101,7 @@ public: DNSName followupName; }; - unsigned int gettag(const ComboAddress& remote, const Netmask& ednssubnet, const ComboAddress& local, const DNSName& qname, uint16_t qtype, std::vector* policyTags, LuaContext::LuaObject& data, const std::map&); + unsigned int gettag(const ComboAddress& remote, const Netmask& ednssubnet, const ComboAddress& local, const DNSName& qname, uint16_t qtype, std::vector* policyTags, LuaContext::LuaObject& data, const std::map&, bool tcp); bool prerpz(DNSQuestion& dq, int& ret); bool preresolve(DNSQuestion& dq, int& ret); @@ -121,7 +121,7 @@ public: d_postresolve); } - typedef std::function >,boost::optional >(ComboAddress, Netmask, ComboAddress, DNSName, uint16_t, const std::map&)> gettag_t; + typedef std::function >,boost::optional >(ComboAddress, Netmask, ComboAddress, DNSName, uint16_t, const std::map&, bool)> gettag_t; gettag_t d_gettag; // public so you can query if we have this hooked private: diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 8db279729..e6d53b41f 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -1432,7 +1432,7 @@ static void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var) if(t_pdl->get() && (*t_pdl)->d_gettag) { try { - dc->d_tag = (*t_pdl)->gettag(conn->d_remote, dc->d_ednssubnet.source, dest, qname, qtype, &dc->d_policyTags, dc->d_data, ednsOptions); + dc->d_tag = (*t_pdl)->gettag(conn->d_remote, dc->d_ednssubnet.source, dest, qname, qtype, &dc->d_policyTags, dc->d_data, ednsOptions, true); } catch(std::exception& e) { if(g_logCommonErrors) @@ -1605,7 +1605,7 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr if(t_pdl->get() && (*t_pdl)->d_gettag) { try { - ctag=(*t_pdl)->gettag(fromaddr, ednssubnet.source, destaddr, qname, qtype, &policyTags, data, ednsOptions); + ctag=(*t_pdl)->gettag(fromaddr, ednssubnet.source, destaddr, qname, qtype, &policyTags, data, ednsOptions, false); } catch(std::exception& e) { if(g_logCommonErrors) -- 2.49.0