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);
{
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;
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();
});
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;
}
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;
}
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());
});
}
-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
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);
// 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);
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