From 32829819a9d93bcaa9dd3ab83bd5f399ad30a3dd Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Mon, 3 Jun 2019 22:52:49 +0200 Subject: [PATCH] make LUA state reuse optional --- pdns/common_startup.cc | 1 + pdns/common_startup.hh | 1 + pdns/lua-record.cc | 12 ++++++------ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pdns/common_startup.cc b/pdns/common_startup.cc index bd57fc542..1d1e51fea 100644 --- a/pdns/common_startup.cc +++ b/pdns/common_startup.cc @@ -511,6 +511,7 @@ void mainthread() g_8bitDNS = ::arg().mustDo("8bit-dns"); #ifdef HAVE_LUA_RECORDS g_doLuaRecord = ::arg().mustDo("enable-lua-records"); + g_LuaRecordSharedState = (::arg()["enable-lua-records"] == "shared"); g_luaRecordExecLimit = ::arg().asNum("lua-records-exec-limit"); #endif diff --git a/pdns/common_startup.hh b/pdns/common_startup.hh index 1e1290ed5..b57b4bcd5 100644 --- a/pdns/common_startup.hh +++ b/pdns/common_startup.hh @@ -57,6 +57,7 @@ extern bool g_anyToTcp; extern bool g_8bitDNS; #ifdef HAVE_LUA_RECORDS extern bool g_doLuaRecord; +extern bool g_LuaRecordSharedState; #endif // HAVE_LUA_RECORDS #endif // COMMON_STARTUP_HH diff --git a/pdns/lua-record.cc b/pdns/lua-record.cc index 3d757415f..0e2b9102b 100644 --- a/pdns/lua-record.cc +++ b/pdns/lua-record.cc @@ -465,19 +465,19 @@ static vector > convWIplist(std::unordered_map alua; +static thread_local unique_ptr s_LUA; +bool g_LuaRecordSharedState; std::vector> luaSynth(const std::string& code, const DNSName& query, const DNSName& zone, int zoneid, const DNSPacket& dnsp, uint16_t qtype) { - if(!alua) { - cerr<<"initializing AuthLua4"<(); + if(!s_LUA || // we don't have a Lua state yet + !g_LuaRecordSharedState) { // or we want a new one even if we had one + s_LUA = make_unique(); } std::vector> ret; - LuaContext& lua = *alua->getLua(); + LuaContext& lua = *s_LUA->getLua(); lua.writeVariable("qname", query); lua.writeVariable("who", dnsp.getRemote()); lua.writeVariable("dh", (dnsheader*)&dnsp.d); -- 2.40.0