From 7c62e29c09eb1bf8901d280e7f94b175938434e4 Mon Sep 17 00:00:00 2001 From: Bozhan Liang Date: Mon, 6 Jan 2025 21:11:55 +0800 Subject: [PATCH] auth: remove zoneid from luaSynth parameters --- pdns/lua-auth4.hh | 4 ++-- pdns/lua-record.cc | 16 +++++++--------- pdns/packethandler.cc | 4 ++-- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/pdns/lua-auth4.hh b/pdns/lua-auth4.hh index b9a90835b2a2..7697f4e2ea5d 100644 --- a/pdns/lua-auth4.hh +++ b/pdns/lua-auth4.hh @@ -45,5 +45,5 @@ private: luacall_axfr_filter_t d_axfr_filter; luacall_prequery_t d_prequery; }; -std::vector> 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& LUA); +std::vector> luaSynth(const std::string& code, const DNSName& query, const DNSZoneRecord& zone_record, + const DNSName& zone, const DNSPacket& dnsp, uint16_t qtype, unique_ptr& LUA); diff --git a/pdns/lua-record.cc b/pdns/lua-record.cc index d5f7866f2fa9..71f55b47aa13 100644 --- a/pdns/lua-record.cc +++ b/pdns/lua-record.cc @@ -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 s_lua_record_ctx; @@ -766,7 +765,7 @@ static std::vector> getCHashedEntries(const i static std::string pickConsistentWeightedHashed(const ComboAddress& bestwho, const std::vector>& 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::max(); unsigned int min = std::numeric_limits::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 drs = lookup(rec, QType::LUA, s_lua_record_ctx->zoneid); + vector drs = lookup(rec, QType::LUA, s_lua_record_ctx->zone_record.domain_id); for(const auto& dr : drs) { auto lr = getRR(dr.dr); lua.executeCode(lr->getCode()); @@ -1409,7 +1408,7 @@ static void setupLuaRecords(LuaContext& lua) // NOLINT(readability-function-cogn }); } -std::vector> 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& LUA) +std::vector> luaSynth(const std::string& code, const DNSName& query, const DNSZoneRecord& zone_record, const DNSName& zone, const DNSPacket& dnsp, uint16_t qtype, unique_ptr& 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> 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); diff --git a/pdns/packethandler.cc b/pdns/packethandler.cc index 18435977596d..8483814d1954 100644 --- a/pdns/packethandler.cc +++ b/pdns/packethandler.cc @@ -427,7 +427,7 @@ bool PacketHandler::getBestWildcard(DNSPacket& p, const DNSName &target, DNSName // noCache=true; DLOG(g_log<<"Executing Lua: '"<getCode()<<"'"<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 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