]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: remove zoneid from luaSynth parameters 14993/head
authorBozhan Liang <lbz@rivensbane.com>
Mon, 6 Jan 2025 13:11:55 +0000 (21:11 +0800)
committerBozhan Liang <lbz@rivensbane.com>
Mon, 6 Jan 2025 13:11:55 +0000 (21:11 +0800)
pdns/lua-auth4.hh
pdns/lua-record.cc
pdns/packethandler.cc

index b9a90835b2a29e2ad9b285b72142abeb9ccb5c74..7697f4e2ea5d8140b926eab704e7879091796d57 100644 (file)
@@ -45,5 +45,5 @@ private:
   luacall_axfr_filter_t d_axfr_filter;
   luacall_prequery_t d_prequery;
 };
-std::vector<shared_ptr<DNSRecordContent>> luaSynth(const std::string& code, const DNSName& query, const DNSRecord& zone_record,
-                                                   const DNSName& zone, int zoneid, const DNSPacket& dnsp, uint16_t qtype, unique_ptr<AuthLua4>& LUA);
+std::vector<shared_ptr<DNSRecordContent>> luaSynth(const std::string& code, const DNSName& query, const DNSZoneRecord& zone_record,
+                                                   const DNSName& zone, const DNSPacket& dnsp, uint16_t qtype, unique_ptr<AuthLua4>& LUA);
index d5f7866f2fa91e8f31b56caf70d22b5783c211b4..71f55b47aa1379933b3c07c484d6096eb3f14888 100644 (file)
@@ -654,9 +654,8 @@ typedef struct AuthLuaRecordContext
 {
   ComboAddress          bestwho;
   DNSName               qname;
-  DNSRecord             zone_record;
+  DNSZoneRecord         zone_record;
   DNSName               zone;
-  int                   zoneid;
 } lua_record_ctx_t;
 
 static thread_local unique_ptr<lua_record_ctx_t> s_lua_record_ctx;
@@ -766,7 +765,7 @@ static std::vector<std::shared_ptr<EntryHashesHolder>> getCHashedEntries(const i
 
 static std::string pickConsistentWeightedHashed(const ComboAddress& bestwho, const std::vector<std::pair<int, std::string>>& items)
 {
-  const auto& zoneId = s_lua_record_ctx->zoneid;
+  const auto& zoneId = s_lua_record_ctx->zone_record.domain_id;
   const auto queryName = s_lua_record_ctx->qname.toString();
   unsigned int sel = std::numeric_limits<unsigned int>::max();
   unsigned int min = std::numeric_limits<unsigned int>::max();
@@ -917,7 +916,7 @@ static void setupLuaRecords(LuaContext& lua) // NOLINT(readability-function-cogn
     });
   lua.writeFunction("createForward", []() {
       static string allZerosIP{"0.0.0.0"};
-      DNSName record_name{s_lua_record_ctx->zone_record.d_name};
+      DNSName record_name{s_lua_record_ctx->zone_record.dr.d_name};
       if (!record_name.isWildcard()) {
         return allZerosIP;
       }
@@ -980,7 +979,7 @@ static void setupLuaRecords(LuaContext& lua) // NOLINT(readability-function-cogn
 
   lua.writeFunction("createForward6", []() {
       static string allZerosIP{"::"};
-      DNSName record_name{s_lua_record_ctx->zone_record.d_name};
+      DNSName record_name{s_lua_record_ctx->zone_record.dr.d_name};
       if (!record_name.isWildcard()) {
         return allZerosIP;
       }
@@ -1397,7 +1396,7 @@ static void setupLuaRecords(LuaContext& lua) // NOLINT(readability-function-cogn
         return;
       }
       try {
-        vector<DNSZoneRecord> drs = lookup(rec, QType::LUA, s_lua_record_ctx->zoneid);
+        vector<DNSZoneRecord> drs = lookup(rec, QType::LUA, s_lua_record_ctx->zone_record.domain_id);
         for(const auto& dr : drs) {
           auto lr = getRR<LUARecordContent>(dr.dr);
           lua.executeCode(lr->getCode());
@@ -1409,7 +1408,7 @@ static void setupLuaRecords(LuaContext& lua) // NOLINT(readability-function-cogn
     });
 }
 
-std::vector<shared_ptr<DNSRecordContent>> luaSynth(const std::string& code, const DNSName& query, const DNSRecord& zone_record, const DNSName& zone, int zoneid, const DNSPacket& dnsp, uint16_t qtype, unique_ptr<AuthLua4>& LUA)
+std::vector<shared_ptr<DNSRecordContent>> luaSynth(const std::string& code, const DNSName& query, const DNSZoneRecord& zone_record, const DNSName& zone, const DNSPacket& dnsp, uint16_t qtype, unique_ptr<AuthLua4>& LUA)
 {
   if(!LUA ||                  // we don't have a Lua state yet
      !g_LuaRecordSharedState) { // or we want a new one even if we had one
@@ -1425,11 +1424,10 @@ std::vector<shared_ptr<DNSRecordContent>> luaSynth(const std::string& code, cons
   s_lua_record_ctx->qname = query;
   s_lua_record_ctx->zone_record = zone_record;
   s_lua_record_ctx->zone = zone;
-  s_lua_record_ctx->zoneid = zoneid;
 
   lua.writeVariable("qname", query);
   lua.writeVariable("zone", zone);
-  lua.writeVariable("zoneid", zoneid);
+  lua.writeVariable("zoneid", zone_record.domain_id);
   lua.writeVariable("who", dnsp.getInnerRemote());
   lua.writeVariable("localwho", dnsp.getLocal());
   lua.writeVariable("dh", (dnsheader*)&dnsp.d);
index 18435977596db88e0a271949e609fe4f54533afc..8483814d1954ded32b400d6e0eeade41493717d3 100644 (file)
@@ -427,7 +427,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, rr.dr, d_sd.qname, d_sd.domain_id, p, rec->d_type, s_LUA);
+            auto recvec=luaSynth(rec->getCode(), target, rr, d_sd.qname, p, rec->d_type, s_LUA);
             for (const auto& r : recvec) {
               rr.dr.d_type = rec->d_type; // might be CNAME
               rr.dr.setContent(r);
@@ -1622,7 +1622,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, rr.dr, d_sd.qname, d_sd.domain_id, p, rec->d_type, s_LUA);
+            auto recvec=luaSynth(rec->getCode(), target, rr, d_sd.qname, 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