From: Peter van Dijk Date: Mon, 3 Jun 2019 20:52:49 +0000 (+0200) Subject: make LUA state reuse optional X-Git-Tag: dnsdist-1.4.0-beta1~4^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=32829819a9d93bcaa9dd3ab83bd5f399ad30a3dd;p=thirdparty%2Fpdns.git make LUA state reuse optional --- diff --git a/pdns/common_startup.cc b/pdns/common_startup.cc index bd57fc5423..1d1e51fea1 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 1e1290ed57..b57b4bcd5f 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 3d757415fe..0e2b9102b8 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);