]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Keep remote in Lua context, to make dblookup search within the current view.
authorMiod Vallat <miod.vallat@powerdns.com>
Wed, 7 May 2025 06:47:25 +0000 (08:47 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Mon, 26 May 2025 11:49:13 +0000 (13:49 +0200)
pdns/lua-record.cc
pdns/packethandler.cc
pdns/test-ueberbackend_cc.cc
pdns/ueberbackend.cc
pdns/ueberbackend.hh

index edfca3068f72cae3db546dc1fcb82b28f7010791..d3b16dfb7374e6db722484c124a7df4413244efc 100644 (file)
@@ -629,13 +629,13 @@ static std::vector<DNSZoneRecord> lookup(const DNSName& name, uint16_t qtype, do
   return ret;
 }
 
-static bool getAuth(const ZoneName& name, uint16_t qtype, SOAData* soaData)
+static bool getAuth(const ZoneName& name, uint16_t qtype, SOAData* soaData, Netmask remote)
 {
   static LockGuarded<UeberBackend> s_ub;
 
   {
     auto ueback = s_ub.lock();
-    return ueback->getAuth(name, qtype, soaData);
+    return ueback->getAuth(name, qtype, soaData, remote);
   }
 }
 
@@ -748,6 +748,7 @@ typedef struct AuthLuaRecordContext
   DNSName               qname;
   DNSZoneRecord         zone_record;
   DNSName               zone;
+  Netmask               remote;
 } lua_record_ctx_t;
 
 static thread_local unique_ptr<lua_record_ctx_t> s_lua_record_ctx;
@@ -1579,7 +1580,7 @@ static vector<string> lua_dblookup(const string& record, uint16_t qtype)
   try {
     SOAData soaData;
 
-    if (!getAuth(rec, qtype, &soaData)) {
+    if (!getAuth(rec, qtype, &soaData, s_lua_record_ctx->remote)) {
       return ret;
     }
 
@@ -1778,6 +1779,7 @@ 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->remote = dnsp.getRealRemote();
 
   lua.writeVariable("qname", query);
   lua.writeVariable("zone", zone);
index d32fc6efaa914499036f4e061d0a9b2b9d5af211..b586c6aae1b12e650972727d2623c52dc784921f 100644 (file)
@@ -1597,7 +1597,7 @@ bool PacketHandler::opcodeQueryInner2(DNSPacket& pkt, queryState &state, bool re
     return true;
   }
 
-  if(!B.getAuth(ZoneName(state.target), pkt.qtype, &d_sd, true, &pkt)) {
+  if(!B.getAuth(ZoneName(state.target), pkt.qtype, &d_sd, pkt.getRealRemote(), true, &pkt)) {
     DLOG(g_log<<Logger::Error<<"We have no authority over zone '"<<state.target<<"'"<<endl);
     if (!retargeted) {
       state.r->setA(false); // drop AA if we never had a SOA in the first place
index bafec12cb2b7a3049d386df1f068b6cf7deebd79..8226da4dcf21e087777d3e87a1af74a8837e5f2b 100644 (file)
@@ -1007,7 +1007,7 @@ BOOST_AUTO_TEST_CASE(test_child_zone) {
     {
       // test getAuth() for DS
       SOAData sd;
-      BOOST_REQUIRE(ub.getAuth(ZoneName("powerdns.com."), QType::DS, &sd));
+      BOOST_REQUIRE(ub.getAuth(ZoneName("powerdns.com."), QType::DS, &sd, Netmask{}));
       BOOST_CHECK_EQUAL(sd.zonename.toString(), "com.");
       BOOST_CHECK_EQUAL(sd.domain_id, 1);
     }
@@ -1015,7 +1015,7 @@ BOOST_AUTO_TEST_CASE(test_child_zone) {
     {
       // test getAuth() for A
       SOAData sd;
-      BOOST_REQUIRE(ub.getAuth(ZoneName("powerdns.com."), QType::A, &sd));
+      BOOST_REQUIRE(ub.getAuth(ZoneName("powerdns.com."), QType::A, &sd, Netmask{}));
       BOOST_CHECK_EQUAL(sd.zonename.toString(), "powerdns.com.");
       BOOST_CHECK_EQUAL(sd.domain_id, 2);
     }
@@ -1067,7 +1067,7 @@ BOOST_AUTO_TEST_CASE(test_multi_backends_best_soa) {
 
       // test getAuth()
       SOAData sd;
-      BOOST_REQUIRE(ub.getAuth(ZoneName("2.4.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa."), QType::PTR, &sd));
+      BOOST_REQUIRE(ub.getAuth(ZoneName("2.4.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa."), QType::PTR, &sd, Netmask{}));
       BOOST_CHECK_EQUAL(sd.zonename.toString(), "d.0.1.0.0.2.ip6.arpa.");
       BOOST_CHECK_EQUAL(sd.domain_id, 1);
 
index d151232fbe6473a321d72a456b443cf764818a70..67e3c85f18b4b0fe507bd61c99ccd42105e60a68 100644 (file)
@@ -519,7 +519,7 @@ static bool foundTarget(const ZoneName& target, const ZoneName& shorter, const Q
   return false;
 }
 
-bool UeberBackend::getAuth(const ZoneName& target, const QType& qtype, SOAData* soaData, bool cachedOk, DNSPacket* pkt_p)
+bool UeberBackend::getAuth(const ZoneName& target, const QType& qtype, SOAData* soaData, Netmask remote, bool cachedOk, DNSPacket* pkt_p)
 {
   // A backend can respond to our authority request with the 'best' match it
   // has. For example, when asked for a.b.c.example.com. it might respond with
@@ -532,10 +532,6 @@ bool UeberBackend::getAuth(const ZoneName& target, const QType& qtype, SOAData*
   ZoneName shorter(target);
   vector<pair<size_t, SOAData>> bestMatches(backends.size(), pair(target.operator const DNSName&().wirelength() + 1, SOAData()));
 
-  Netmask remote;
-  if (pkt_p != nullptr) {
-    remote = pkt_p->getRealRemote();
-  }
   std::string view{};
   if (g_zoneCache.isEnabled()) {
     Netmask _remote(remote);
index ea172f2a711906e7616f4d33ed6a8d49a71f5e87..af85b1a541b88e7f1f3f923b7562799a35be478e 100644 (file)
@@ -100,7 +100,7 @@ public:
   void lookupEnd();
 
   /** Determines if we are authoritative for a zone, and at what level */
-  bool getAuth(const ZoneName& target, const QType& qtype, SOAData* soaData, bool cachedOk = true, DNSPacket* pkt_p = nullptr);
+  bool getAuth(const ZoneName& target, const QType& qtype, SOAData* soaData, Netmask remote, bool cachedOk = true, DNSPacket* pkt_p = nullptr);
   /** Load SOA info from backends, ignoring the cache.*/
   bool getSOAUncached(const ZoneName& domain, SOAData& soaData);
   void getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled);