From: Peter van Dijk Date: Mon, 13 Mar 2017 17:57:24 +0000 (+0100) Subject: stop (de)serializing dq.data X-Git-Tag: rec-4.1.0-alpha1~191^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5fd2577f98f122ba8c8faa65665d28092649e746;p=pdns stop (de)serializing dq.data --- diff --git a/ext/luawrapper/include/LuaContext.hpp b/ext/luawrapper/include/LuaContext.hpp index 9cf72ca2d..14e927fac 100644 --- a/ext/luawrapper/include/LuaContext.hpp +++ b/ext/luawrapper/include/LuaContext.hpp @@ -188,6 +188,17 @@ public: template class LuaFunctionCaller; + /** + * Opaque type that identifies a Lua object + */ + struct LuaObject { + LuaObject() = default; + LuaObject(lua_State* state, int index=-1) { + this->objectInRegistry = std::make_shared(state, index); + } + std::shared_ptr objectInRegistry; + }; + /** * Opaque type that identifies a Lua thread */ @@ -1833,6 +1844,23 @@ private: /**************************************************/ // specializations of the Pusher structure +// opaque Lua references +template<> +struct LuaContext::Pusher { + static const int minSize = 1; + static const int maxSize = 1; + + static PushedObject push(lua_State* state, const LuaContext::LuaObject& value) noexcept { + if (value.objectInRegistry.get()) { + PushedObject obj = value.objectInRegistry->pop(); + return obj; + } else { + lua_pushnil(state); + return PushedObject{state, 1}; + } + } +}; + // boolean template<> struct LuaContext::Pusher { @@ -2395,6 +2423,18 @@ private: /**************************************************/ // specializations of the Reader structures +// opaque Lua references +template<> +struct LuaContext::Reader +{ + static auto read(lua_State* state, int index) + -> boost::optional + { + LuaContext::LuaObject obj(state, index); + return obj; + } +}; + // reading null template<> struct LuaContext::Reader diff --git a/pdns/lua-recursor4.cc b/pdns/lua-recursor4.cc index 2fac53682..e871f9e31 100644 --- a/pdns/lua-recursor4.cc +++ b/pdns/lua-recursor4.cc @@ -32,9 +32,6 @@ #include "rec-snmp.hh" #include -#undef L -#include "ext/luawrapper/include/LuaContext.hpp" - static int followCNAMERecords(vector& ret, const QType& qtype) { vector resolved; @@ -587,7 +584,7 @@ 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, std::unordered_map& data) +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) { if(d_gettag) { auto ret = d_gettag(remote, ednssubnet, local, qname, qtype); @@ -600,7 +597,7 @@ unsigned int RecursorLua4::gettag(const ComboAddress& remote, const Netmask& edn } } } - const auto& dataret = std::get<2>(ret); + const auto dataret = std::get<2>(ret); if (dataret) { data = *dataret; } diff --git a/pdns/lua-recursor4.hh b/pdns/lua-recursor4.hh index 80a829622..fcaabc5f2 100644 --- a/pdns/lua-recursor4.hh +++ b/pdns/lua-recursor4.hh @@ -35,6 +35,12 @@ unsigned int getRecursorThreadId(); class LuaContext; +#if defined(HAVE_LUA) +#undef L +#include "ext/luawrapper/include/LuaContext.hpp" +#define L theL() +#endif + class RecursorLua4 : public boost::noncopyable { private: @@ -88,11 +94,11 @@ public: string udpAnswer; string udpCallback; - std::unordered_map data; + LuaContext::LuaObject data; DNSName followupName; }; - unsigned int gettag(const ComboAddress& remote, const Netmask& ednssubnet, const ComboAddress& local, const DNSName& qname, uint16_t qtype, std::vector* policyTags, std::unordered_map& data); + unsigned int gettag(const ComboAddress& remote, const Netmask& ednssubnet, const ComboAddress& local, const DNSName& qname, uint16_t qtype, std::vector* policyTags, LuaContext::LuaObject& data); bool prerpz(DNSQuestion& dq, int& ret); bool preresolve(DNSQuestion& dq, int& ret); @@ -112,7 +118,7 @@ public: d_postresolve); } - typedef std::function >,boost::optional > >(ComboAddress, Netmask, ComboAddress, DNSName, + typedef std::function >,boost::optional >(ComboAddress, Netmask, ComboAddress, DNSName, uint16_t)> gettag_t; gettag_t d_gettag; // public so you can query if we have this hooked diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 0551118db..e87a6a494 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -216,7 +216,7 @@ struct DNSComboWriter { shared_ptr d_tcpConnection; vector > d_ednsOpts; std::vector d_policyTags; - std::unordered_map d_data; + LuaContext::LuaObject d_data; }; @@ -1542,7 +1542,7 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr uint32_t qhash = 0; bool needECS = false; std::vector policyTags; - std::unordered_map data; + LuaContext::LuaObject data; #ifdef HAVE_PROTOBUF boost::uuids::uuid uniqueId; auto luaconfsLocal = g_luaconfs.getLocal();