]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth LUA: move LUA state up into the PacketHandler so we can reuse it in TCP as well
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Thu, 14 Apr 2022 12:18:36 +0000 (14:18 +0200)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Tue, 5 Jul 2022 13:11:55 +0000 (15:11 +0200)
fixes #11522

pdns/lua-auth4.hh
pdns/lua-record.cc
pdns/packethandler.cc
pdns/packethandler.hh

index bac43dd2670db29f48339a8e4fb4a17ef16d8ecb..62e9646227126be5960d30a1852ebb21a814b57a 100644 (file)
@@ -43,4 +43,4 @@ private:
   luacall_prequery_t d_prequery;
 };
 std::vector<shared_ptr<DNSRecordContent>> 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<AuthLua4>& s_LUA);
index 303389cee1b9361f0cc56d9492ad0060c6838dbd..9a081899cf6e722b3d4a2f42d3268e41a0a2e068 100644 (file)
@@ -578,7 +578,6 @@ static vector< pair<int, string> > convIntStringPairList(const std::unordered_ma
   return result;
 }
 
-static thread_local unique_ptr<AuthLua4> s_LUA;
 bool g_LuaRecordSharedState;
 
 typedef struct AuthLuaRecordContext
@@ -591,10 +590,8 @@ typedef struct AuthLuaRecordContext
 
 static thread_local unique_ptr<lua_record_ctx_t> 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<shared_ptr<DNSRecordContent>> luaSynth(const std::string& code, const DNSName& query, const DNSName& zone, int zoneid, const DNSPacket& dnsp, uint16_t qtype)
+std::vector<shared_ptr<DNSRecordContent>> luaSynth(const std::string& code, const DNSName& query, const DNSName& zone, int zoneid, const DNSPacket& dnsp, uint16_t qtype, unique_ptr<AuthLua4>& 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<AuthLua4>();
-    setupLuaRecords();
+    setupLuaRecords(*s_LUA->getLua());
   }
 
   std::vector<shared_ptr<DNSRecordContent>> ret;
index be09f070878a9ec5177ffb2e0a643ab42523a269..24c8174122f1df263acf641bd01657085f4f02c1 100644 (file)
@@ -413,7 +413,7 @@ bool PacketHandler::getBestWildcard(DNSPacket& p, const DNSName &target, DNSName
           //    noCache=true;
           DLOG(g_log<<"Executing Lua: '"<<rec->getCode()<<"'"<<endl);
           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);
             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<DNSPacket> 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
index e9e79f391fbddf9a50374bb7053970c59cfd825c..3bd0511fc317400e6c13db7e9fd6c7ce8e8dab39 100644 (file)
@@ -117,7 +117,7 @@ private:
   SOAData d_sd;
   std::unique_ptr<AuthLua4> d_pdl;
   std::unique_ptr<AuthLua4> d_update_policy_lua;
-
+  std::unique_ptr<AuthLua4> s_LUA;
   UeberBackend B; // every thread an own instance
   DNSSECKeeper d_dk; // B is shared with DNSSECKeeper
 };