]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Do not store tags set by gettag(_ffi) into the PC by keeping them separate.
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 14 Jul 2023 10:52:08 +0000 (12:52 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 20 Jul 2023 08:28:53 +0000 (10:28 +0200)
We do pass them to the other Lua functions, but take care to erase them
aagin before creating the partial PB message stored into the cache.

pdns/recursordist/pdns_recursor.cc
pdns/recursordist/rec-main.hh
regression-tests.recursor-dnssec/test_Protobuf.py

index 1b982ab1f11f627e4ce0c20697d6e9ff03ccb576..ba9771580d7c29c3efe969bd71632e981887a0f4 100644 (file)
@@ -906,6 +906,18 @@ static uint32_t capPacketCacheTTL(const struct dnsheader& hdr, uint32_t ttl, boo
   return ttl;
 }
 
+static void addPolicyTagsToPBMessageIfNeeded(DNSComboWriter& comboWriter, pdns::ProtoZero::RecMessage& pbMessage)
+{
+  if (!comboWriter.d_gettagPolicyTags.empty()) {
+    for (const auto& tag : comboWriter.d_gettagPolicyTags) {
+      comboWriter.d_policyTags.erase(tag);
+    }
+  }
+  if (!comboWriter.d_policyTags.empty()) {
+    pbMessage.addPolicyTags(comboWriter.d_policyTags);
+  }
+}
+
 void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexity): https://github.com/PowerDNS/pdns/issues/12791
 {
   auto comboWriter = std::unique_ptr<DNSComboWriter>(static_cast<DNSComboWriter*>(arg));
@@ -1681,6 +1693,8 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi
       }
       pbMessage.setInBytes(packet.size());
       pbMessage.setValidationState(resolver.getValidationState());
+      // See if we want to store the policyTags into th PC
+      addPolicyTagsToPBMessageIfNeeded(*comboWriter, pbMessage);
 
       // Take s snap of the current protobuf buffer state to store in the PC
       pbDataForCache = boost::make_optional(RecursorPacketCache::PBData{
@@ -1774,7 +1788,7 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi
       pbMessage.setDeviceId(dnsQuestion.deviceId);
       pbMessage.setDeviceName(dnsQuestion.deviceName);
       pbMessage.setToPort(comboWriter->d_destination.getPort());
-      pbMessage.addPolicyTags(comboWriter->d_policyTags);
+      pbMessage.addPolicyTags(comboWriter->d_gettagPolicyTags);
 
       for (const auto& metaValue : dnsQuestion.meta) {
         pbMessage.setMeta(metaValue.first, metaValue.second.stringVal, metaValue.second.intVal);
index 6d7dbc78fa607d92b6a95d8b8151eff0259cdd9c..da2cd43cfa2011d47b4888020f11d1cc8b65c7bc 100644 (file)
@@ -59,7 +59,7 @@ struct DNSComboWriter
   }
 
   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(std::move(luaContext)), d_data(std::move(data))
+    d_mdp(true, query), d_now(now), d_query(query), d_policyTags(std::move(policyTags)), d_gettagPolicyTags(d_policyTags), d_records(std::move(records)), d_luaContext(std::move(luaContext)), d_data(std::move(data))
   {
   }
 
@@ -125,6 +125,7 @@ struct DNSComboWriter
   };
   std::string d_query;
   std::unordered_set<std::string> d_policyTags;
+  const std::unordered_set<std::string> d_gettagPolicyTags;
   std::string d_routingTag;
   std::vector<DNSRecord> d_records;
 
index f2789e2efe1fa47d6fc24c6be992736ede3debd1..79d57e45618dd58363b011488521af5bacfb3af0 100644 (file)
@@ -96,7 +96,7 @@ class TestRecursorProtobuf(RecursorTest):
 
         #print("in getFirstProtobufMessage")
         for param in protobufServersParameters:
-          print(param.port)
+          #print(param.port)
           failed = 0
 
           while param.queue.empty:
@@ -944,6 +944,27 @@ auth-zones=example=configs/%s/example.zone""" % _confdir
         res = self.sendUDPQuery(query)
         self.assertRRsetInAnswer(res, expected)
 
+        # check the protobuf messages corresponding to the UDP query and answer
+        msg = self.getFirstProtobufMessage()
+        self.checkProtobufQuery(msg, dnsmessage_pb2.PBDNSMessage.UDP, query, dns.rdataclass.IN, dns.rdatatype.A, name)
+        self.checkProtobufTags(msg, [ self._tag_from_gettag ])
+        # then the response
+        msg = self.getFirstProtobufMessage()
+        self.checkProtobufResponse(msg, dnsmessage_pb2.PBDNSMessage.UDP, res)
+        self.assertEqual(len(msg.response.rrs), 1)
+        rr = msg.response.rrs[0]
+        # we have max-cache-ttl set to 15
+        self.checkProtobufResponseRecord(rr, dns.rdataclass.IN, dns.rdatatype.A, name, 15)
+        self.assertEqual(socket.inet_ntop(socket.AF_INET, rr.rdata), '192.0.2.84')
+        tags = [ self._tag_from_gettag ] + self._tags
+        #print(msg)
+        self.checkProtobufTags(msg, tags)
+        self.checkNoRemainingMessage()
+
+        # Again to check PC case
+        res = self.sendUDPQuery(query)
+        self.assertRRsetInAnswer(res, expected)
+
         # check the protobuf messages corresponding to the UDP query and answer
         msg = self.getFirstProtobufMessage()
         self.checkProtobufQuery(msg, dnsmessage_pb2.PBDNSMessage.UDP, query, dns.rdataclass.IN, dns.rdatatype.A, name)
@@ -998,8 +1019,8 @@ auth-zones=example=configs/%s/example.zone""" % _confdir
         self.checkNoRemainingMessage()
         self.assertEqual(len(msg.response.tags), 1)
         ts1 = msg.response.tags[0]
-        #print(ts1)
-        # Again
+
+        # Again to check PC case
         res = self.sendUDPQuery(query)
         self.assertRRsetInAnswer(res, expected)
 
@@ -1013,7 +1034,6 @@ auth-zones=example=configs/%s/example.zone""" % _confdir
         self.checkNoRemainingMessage()
         self.assertEqual(len(msg.response.tags), 1)
         ts2 = msg.response.tags[0]
-        #print(ts2)
         self.assertNotEqual(ts1, ts2)
 
 class ProtobufSelectedFromLuaTest(TestRecursorProtobuf):