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
extern bool g_8bitDNS;
#ifdef HAVE_LUA_RECORDS
extern bool g_doLuaRecord;
+extern bool g_LuaRecordSharedState;
#endif // HAVE_LUA_RECORDS
#endif // COMMON_STARTUP_HH
return ret;
}
-thread_local unique_ptr<AuthLua4> alua;
+static thread_local unique_ptr<AuthLua4> s_LUA;
+bool g_LuaRecordSharedState;
std::vector<shared_ptr<DNSRecordContent>> luaSynth(const std::string& code, const DNSName& query, const DNSName& zone, int zoneid, const DNSPacket& dnsp, uint16_t qtype)
{
- if(!alua) {
- cerr<<"initializing AuthLua4"<<endl;
-
- alua = make_unique<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<AuthLua4>();
}
std::vector<shared_ptr<DNSRecordContent>> 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);