]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Store LuaContext shared pointer for the query in the ComboWriter object
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 14 Feb 2022 08:25:16 +0000 (09:25 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 14 Feb 2022 11:30:19 +0000 (12:30 +0100)
pdns/pdns_recursor.cc
pdns/recursordist/rec-main.hh
pdns/syncres.hh

index 6c816aa39a690f442d7562854ba6fb1d8ef0b48c..44076faa2b520e1a2c684c09e7576cd4ebc02575 100644 (file)
@@ -631,7 +631,7 @@ int followCNAMERecords(vector<DNSRecord>& ret, const QType qtype, int rcode)
     return rcode;
   }
 
-  rcode = directResolve(target, qtype, QClass::IN, resolved, t_pdl); // XXX correct to use t_pdl?
+  rcode = directResolve(target, qtype, QClass::IN, resolved, t_pdl);
 
   for (DNSRecord& rr : resolved) {
     ret.push_back(std::move(rr));
@@ -645,7 +645,7 @@ int getFakeAAAARecords(const DNSName& qname, ComboAddress prefix, vector<DNSReco
      again, possibly encountering the same CNAME(s), and we don't want to trigger the CNAME
      loop detection. */
   vector<DNSRecord> newRecords;
-  int rcode = directResolve(qname, QType::A, QClass::IN, newRecords, t_pdl); // XXX correct to use t_pdl?
+  int rcode = directResolve(qname, QType::A, QClass::IN, newRecords, t_pdl);
 
   ret.reserve(ret.size() + newRecords.size());
   for (auto& record : newRecords) {
@@ -725,7 +725,7 @@ int getFakePTRRecords(const DNSName& qname, vector<DNSRecord>& ret)
   rr.d_content = std::make_shared<CNAMERecordContent>(newquery);
   ret.push_back(rr);
 
-  int rcode = directResolve(DNSName(newquery), QType::PTR, QClass::IN, ret, t_pdl); // XXX correct to use t_pdl?
+  int rcode = directResolve(DNSName(newquery), QType::PTR, QClass::IN, ret, t_pdl);
 
   g_stats.dns64prefixanswers++;
   return rcode;
@@ -877,8 +877,8 @@ void startDoResolve(void* p)
     sr.setId(MT->getTid());
 
     bool DNSSECOK = false;
-    if (t_pdl) {
-      sr.setLuaEngine(t_pdl);
+    if (dc->d_luaContext) {
+      sr.setLuaEngine(dc->d_luaContext);
     }
     if (g_dnssecmode != DNSSECMode::Off) {
       sr.setDoDNSSEC(true);
@@ -944,7 +944,6 @@ void startDoResolve(void* p)
     dq.meta = std::move(dc->d_meta);
     dq.fromAuthIP = &sr.d_fromAuthIP;
 
-    auto srLua = sr.getLuaEngine();
     RunningResolveGuard tcpGuard(dc);
 
     if (ednsExtRCode != 0 || dc->d_mdp.d_header.opcode == Opcode::Notify) {
@@ -976,8 +975,8 @@ void startDoResolve(void* p)
       sr.setCacheOnly();
     }
 
-    if (srLua) {
-      srLua->prerpz(dq, res, sr.d_eventTrace);
+    if (dc->d_luaContext) {
+      dc->d_luaContext->prerpz(dq, res, sr.d_eventTrace);
     }
 
     // Check if the client has a policy attached to it
@@ -1024,7 +1023,7 @@ void startDoResolve(void* p)
     }
 
     // if there is a RecursorLua active, and it 'took' the query in preResolve, we don't launch beginResolve
-    if (!srLua || !srLua->preresolve(dq, res, sr.d_eventTrace)) {
+    if (!dc->d_luaContext || !dc->d_luaContext->preresolve(dq, res, sr.d_eventTrace)) {
 
       if (!g_dns64PrefixReverse.empty() && dq.qtype == QType::PTR && dq.qname.isPartOf(g_dns64PrefixReverse)) {
         res = getFakePTRRecords(dq.qname, ret);
@@ -1035,7 +1034,7 @@ void startDoResolve(void* p)
 
       if (wantsRPZ && appliedPolicy.d_kind != DNSFilterEngine::PolicyKind::NoAction) {
 
-        if (srLua && srLua->policyHitEventFilter(dc->d_source, dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), dc->d_tcp, appliedPolicy, dc->d_policyTags, sr.d_discardedPolicies)) {
+        if (dc->d_luaContext && dc->d_luaContext->policyHitEventFilter(dc->d_source, dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), dc->d_tcp, appliedPolicy, dc->d_policyTags, sr.d_discardedPolicies)) {
           /* reset to no match */
           appliedPolicy = DNSFilterEngine::Policy();
         }
@@ -1110,10 +1109,10 @@ void startDoResolve(void* p)
         }
       }
 
-      if (srLua || (g_dns64Prefix && dq.qtype == QType::AAAA && !vStateIsBogus(dq.validationState))) {
+      if (dc->d_luaContext || (g_dns64Prefix && dq.qtype == QType::AAAA && !vStateIsBogus(dq.validationState))) {
         if (res == RCode::NoError) {
           if (answerIsNOData(dc->d_mdp.d_qtype, res, ret)) {
-            if (srLua && srLua->nodata(dq, res, sr.d_eventTrace)) {
+            if (dc->d_luaContext && dc->d_luaContext->nodata(dq, res, sr.d_eventTrace)) {
               shouldNotValidate = true;
               auto policyResult = handlePolicyHit(appliedPolicy, dc, sr, res, ret, pw, tcpGuard);
               if (policyResult == PolicyResult::HaveAnswer) {
@@ -1129,7 +1128,7 @@ void startDoResolve(void* p)
             }
           }
         }
-        else if (res == RCode::NXDomain && srLua && srLua->nxdomain(dq, res, sr.d_eventTrace)) {
+        else if (res == RCode::NXDomain && dc->d_luaContext && dc->d_luaContext->nxdomain(dq, res, sr.d_eventTrace)) {
           shouldNotValidate = true;
           auto policyResult = handlePolicyHit(appliedPolicy, dc, sr, res, ret, pw, tcpGuard);
           if (policyResult == PolicyResult::HaveAnswer) {
@@ -1140,11 +1139,11 @@ void startDoResolve(void* p)
           }
         }
 
-        if (srLua) {
-          if (srLua->d_postresolve_ffi) {
+        if (dc->d_luaContext) {
+          if (dc->d_luaContext->d_postresolve_ffi) {
             RecursorLua4::PostResolveFFIHandle handle(dq);
             sr.d_eventTrace.add(RecEventTrace::LuaPostResolveFFI);
-            bool pr = srLua->postresolve_ffi(handle);
+            bool pr = dc->d_luaContext->postresolve_ffi(handle);
             sr.d_eventTrace.add(RecEventTrace::LuaPostResolveFFI, pr, false);
             if (pr) {
               shouldNotValidate = true;
@@ -1155,7 +1154,7 @@ void startDoResolve(void* p)
               }
             }
           }
-          else if (srLua->postresolve(dq, res, sr.d_eventTrace)) {
+          else if (dc->d_luaContext->postresolve(dq, res, sr.d_eventTrace)) {
             shouldNotValidate = true;
             auto policyResult = handlePolicyHit(appliedPolicy, dc, sr, res, ret, pw, tcpGuard);
             // haveAnswer case redundant
@@ -1166,7 +1165,7 @@ void startDoResolve(void* p)
         }
       }
     }
-    else if (srLua) {
+    else if (dc->d_luaContext) {
       // preresolve returned true
       shouldNotValidate = true;
       auto policyResult = handlePolicyHit(appliedPolicy, dc, sr, res, ret, pw, tcpGuard);
@@ -1991,7 +1990,7 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr
     return 0;
   }
 
-  auto dc = std::make_unique<DNSComboWriter>(question, g_now, std::move(policyTags), std::move(data), std::move(records));
+  auto dc = std::make_unique<DNSComboWriter>(question, g_now, std::move(policyTags), t_pdl, std::move(data), std::move(records));
   dc->setSocket(fd);
   dc->d_tag = ctag;
   dc->d_qhash = qhash;
index e4f712238f67c8128851daa184e49f861bf0f413..81c04607605ea90753759f8e258c4dba577c293d 100644 (file)
@@ -53,8 +53,8 @@ struct DNSComboWriter
   {
   }
 
-  DNSComboWriter(const std::string& query, const struct timeval& now, std::unordered_set<std::string>&& policyTags, LuaContext::LuaObject&& data, std::vector<DNSRecord>&& records) :
-    d_mdp(true, query), d_now(now), d_query(query), d_policyTags(std::move(policyTags)), d_records(std::move(records)), d_data(std::move(data))
+  DNSComboWriter(const std::string& query, const struct timeval& now, std::unordered_set<std::string>&& policyTags, shared_ptr<RecursorLua4> luaContext, LuaContext::LuaObject&& data, std::vector<DNSRecord>&& records) :
+    d_mdp(true, query), d_now(now), d_query(query), d_policyTags(std::move(policyTags)), d_records(std::move(records)), d_luaContext(luaContext), d_data(std::move(data))
   {
   }
 
@@ -119,7 +119,11 @@ struct DNSComboWriter
   std::unordered_set<std::string> d_policyTags;
   std::string d_routingTag;
   std::vector<DNSRecord> d_records;
+
+  // d_data is tied to this LuaContext so we need to keep it alive and use it, not a newer one, as long as d_data exists
+  shared_ptr<RecursorLua4> d_luaContext;
   LuaContext::LuaObject d_data;
+
   EDNSSubnetOpts d_ednssubnet;
   shared_ptr<TCPConnection> d_tcpConnection;
   boost::optional<uint16_t> d_extendedErrorCode{boost::none};
index 4a8e04799f013b307c10acfab972a0b154cb9260..dd777e00f9b4fbcbffc770bef99da264c8cecc90 100644 (file)
@@ -687,11 +687,6 @@ public:
     d_pdl = pdl;
   }
 
-  shared_ptr<RecursorLua4> getLuaEngine()
-  {
-    return d_pdl;
-  }
-
   bool wasVariable() const
   {
     return d_wasVariable;