From: Peter van Dijk Date: Thu, 14 Apr 2022 12:18:36 +0000 (+0200) Subject: auth LUA: move LUA state up into the PacketHandler so we can reuse it in TCP as well X-Git-Tag: auth-4.8.0-alpha0~1^2~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d43d0b932e915c5c26f1e38204a7f877951576ea;p=thirdparty%2Fpdns.git auth LUA: move LUA state up into the PacketHandler so we can reuse it in TCP as well fixes #11522 --- diff --git a/pdns/lua-auth4.hh b/pdns/lua-auth4.hh index bac43dd267..62e9646227 100644 --- a/pdns/lua-auth4.hh +++ b/pdns/lua-auth4.hh @@ -43,4 +43,4 @@ private: luacall_prequery_t d_prequery; }; std::vector> luaSynth(const std::string& code, const DNSName& qname, - const DNSName& zone, int zoneid, const DNSPacket& dnsp, uint16_t qtype); + const DNSName& zone, int zoneid, const DNSPacket& dnsp, uint16_t qtype, unique_ptr& s_LUA); diff --git a/pdns/lua-record.cc b/pdns/lua-record.cc index 303389cee1..9a081899cf 100644 --- a/pdns/lua-record.cc +++ b/pdns/lua-record.cc @@ -578,7 +578,6 @@ static vector< pair > convIntStringPairList(const std::unordered_ma return result; } -static thread_local unique_ptr s_LUA; bool g_LuaRecordSharedState; typedef struct AuthLuaRecordContext @@ -591,10 +590,8 @@ typedef struct AuthLuaRecordContext static thread_local unique_ptr s_lua_record_ctx; -static void setupLuaRecords() +static void setupLuaRecords(LuaContext& lua) { - LuaContext& lua = *s_LUA->getLua(); - lua.writeFunction("latlon", []() { double lat = 0, lon = 0; getLatLon(s_lua_record_ctx->bestwho.toString(), lat, lon); @@ -1098,12 +1095,12 @@ static void setupLuaRecords() }); } -std::vector> luaSynth(const std::string& code, const DNSName& query, const DNSName& zone, int zoneid, const DNSPacket& dnsp, uint16_t qtype) +std::vector> luaSynth(const std::string& code, const DNSName& query, const DNSName& zone, int zoneid, const DNSPacket& dnsp, uint16_t qtype, unique_ptr& s_LUA) { 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(); - setupLuaRecords(); + setupLuaRecords(*s_LUA->getLua()); } std::vector> ret; diff --git a/pdns/packethandler.cc b/pdns/packethandler.cc index be09f07087..24c8174122 100644 --- a/pdns/packethandler.cc +++ b/pdns/packethandler.cc @@ -413,7 +413,7 @@ bool PacketHandler::getBestWildcard(DNSPacket& p, const DNSName &target, DNSName // noCache=true; DLOG(g_log<<"Executing Lua: '"<getCode()<<"'"<getCode(), target, d_sd.qname, d_sd.domain_id, p, rec->d_type); + auto recvec=luaSynth(rec->getCode(), target, d_sd.qname, d_sd.domain_id, p, rec->d_type, s_LUA); for(const auto& r : recvec) { rr.dr.d_type = rec->d_type; // might be CNAME rr.dr.d_content = r; @@ -1567,7 +1567,7 @@ std::unique_ptr PacketHandler::doQuestion(DNSPacket& p) if(rec->d_type == QType::CNAME || rec->d_type == p.qtype.getCode() || (p.qtype.getCode() == QType::ANY && rec->d_type != QType::RRSIG)) { noCache=true; try { - auto recvec=luaSynth(rec->getCode(), target, d_sd.qname, d_sd.domain_id, p, rec->d_type); + auto recvec=luaSynth(rec->getCode(), target, d_sd.qname, d_sd.domain_id, p, rec->d_type, s_LUA); if(!recvec.empty()) { for(const auto& r_it : recvec) { rr.dr.d_type = rec->d_type; // might be CNAME diff --git a/pdns/packethandler.hh b/pdns/packethandler.hh index e9e79f391f..3bd0511fc3 100644 --- a/pdns/packethandler.hh +++ b/pdns/packethandler.hh @@ -117,7 +117,7 @@ private: SOAData d_sd; std::unique_ptr d_pdl; std::unique_ptr d_update_policy_lua; - + std::unique_ptr s_LUA; UeberBackend B; // every thread an own instance DNSSECKeeper d_dk; // B is shared with DNSSECKeeper };