From: Otto Moerbeek Date: Wed, 12 Jul 2023 12:46:23 +0000 (+0200) Subject: Regression test for pb tags coming out of packet cache or not X-Git-Tag: rec-5.0.0-alpha1~99^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=461f4b239c8e903d2b242ef9b3f3493451182c2d;p=thirdparty%2Fpdns.git Regression test for pb tags coming out of packet cache or not --- diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index 2d5dc826f5..2d46bbe944 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -493,7 +493,7 @@ void protobufLogQuery(LocalStateHolder& luaconfsLocal, const boo msg.setRequestorId(requestorId); msg.setDeviceId(deviceId); msg.setDeviceName(deviceName); - + if (!policyTags.empty()) { msg.addPolicyTags(policyTags); } @@ -546,12 +546,14 @@ void protobufLogResponse(const struct dnsheader* header, LocalStateHolderprotobufExportConfig.logMappedFrom) { + pbMessage.setSocketFamily(source.sin4.sin_family); Netmask requestorNM(source, source.sin4.sin_family == AF_INET ? luaconfsLocal->protobufMaskV4 : luaconfsLocal->protobufMaskV6); auto requestor = requestorNM.getMaskedNetwork(); pbMessage.setFrom(requestor); pbMessage.setFromPort(source.getPort()); } else { + pbMessage.setSocketFamily(mappedSource.sin4.sin_family); Netmask requestorNM(mappedSource, mappedSource.sin4.sin_family == AF_INET ? luaconfsLocal->protobufMaskV4 : luaconfsLocal->protobufMaskV6); auto requestor = requestorNM.getMaskedNetwork(); pbMessage.setFrom(requestor); diff --git a/regression-tests.recursor-dnssec/test_Protobuf.py b/regression-tests.recursor-dnssec/test_Protobuf.py index 5c6fd0b451..698f5109d8 100644 --- a/regression-tests.recursor-dnssec/test_Protobuf.py +++ b/regression-tests.recursor-dnssec/test_Protobuf.py @@ -960,6 +960,62 @@ auth-zones=example=configs/%s/example.zone""" % _confdir self.checkProtobufTags(msg, tags) self.checkNoRemainingMessage() +class ProtobufTagCacheTest(TestRecursorProtobuf): + """ + This test makes sure that we correctly cache tags (actually not cache them) + """ + + _confdir = 'ProtobufTagCache' + _config_template = """ +auth-zones=example=configs/%s/example.zone""" % _confdir + _lua_config_file = """ + protobufServer({"127.0.0.1:%d", "127.0.0.1:%d"}, { logQueries=false, logResponses=true } ) + """ % (protobufServersParameters[0].port, protobufServersParameters[1].port) + _lua_dns_script_file = """ + function preresolve(dq) + if dq.qname:equal('tagged.example.') then + dq:addPolicyTag(''.. math.random()) + end + return false + end + """ + + def testTagged(self): + name = 'tagged.example.' + expected = dns.rrset.from_text(name, 0, dns.rdataclass.IN, 'A', '192.0.2.84') + query = dns.message.make_query(name, 'A', want_dnssec=True) + query.flags |= dns.flags.CD + res = self.sendUDPQuery(query) + self.assertRRsetInAnswer(res, expected) + + 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') + self.checkNoRemainingMessage() + self.assertEqual(len(msg.response.tags), 1) + ts1 = msg.response.tags[0] + print(ts1) + # Again + res = self.sendUDPQuery(query) + self.assertRRsetInAnswer(res, expected) + + 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') + self.checkNoRemainingMessage() + self.assertEqual(len(msg.response.tags), 1) + ts2 = msg.response.tags[0] + print(ts2) + self.assertNotEqual(ts1, ts2) + class ProtobufSelectedFromLuaTest(TestRecursorProtobuf): """ This test makes sure that we correctly export queries and responses but only if they have been selected from Lua.