Skip to content

Commit

Permalink
auth: remove zoneid from luaSynth parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
BozhanL committed Jan 6, 2025
1 parent 644694f commit 7c62e29
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pdns/lua-auth4.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
16 changes: 7 additions & 9 deletions pdns/lua-record.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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());
Expand All @@ -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
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions pdns/packethandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7c62e29

Please sign in to comment.