Blame SOURCES/bind99-rh1549130.patch

24159a
From 02412bfe731d0cb229eb22f0ca4e8fbaed601cbe Mon Sep 17 00:00:00 2001
24159a
From: Mark Andrews <marka@isc.org>
24159a
Date: Fri, 27 May 2016 09:59:46 +1000
24159a
Subject: [PATCH] 4377.   [bug]           Don't reuse zero TTL responses beyond
24159a
 the current                         client set (excludes ANY/SIG/RRSIG
24159a
 queries).                         [RT #42142]
24159a
24159a
(cherry picked from commit aabcb1fde0ca255ff30f0a5c10cbd39f798cc5b7)
24159a
24159a
REDIRECT macro is 9.11.0+
24159a
---
24159a
 bin/named/query.c                 | 31 +++++++++++++++
24159a
 bin/tests/system/zero/ans5/ans.pl | 81 +++++++++++++++++++++++++++++++++++++++
24159a
 bin/tests/system/zero/ns1/root.db |  2 +
24159a
 bin/tests/system/zero/tests.sh    | 13 +++++++
24159a
 4 files changed, 127 insertions(+)
24159a
 create mode 100644 bin/tests/system/zero/ans5/ans.pl
24159a
24159a
diff --git a/bin/named/query.c b/bin/named/query.c
24159a
index 2c44e9ff53..3b402f1d01 100644
24159a
--- a/bin/named/query.c
24159a
+++ b/bin/named/query.c
24159a
@@ -6816,6 +6816,37 @@ query_find(ns_client_t *client, dns_fetchevent_t *event, dns_rdatatype_t qtype)
24159a
 		goto cleanup;
24159a
 
24159a
 	case DNS_R_CNAME:
24159a
+		/*
24159a
+		 * If we have a zero ttl from the cache refetch it.
24159a
+		 */
24159a
+		if (!is_zone && event == NULL && rdataset->ttl == 0 &&
24159a
+		    RECURSIONOK(client))
24159a
+		{
24159a
+			if (dns_rdataset_isassociated(rdataset))
24159a
+				dns_rdataset_disassociate(rdataset);
24159a
+			if (sigrdataset != NULL &&
24159a
+			    dns_rdataset_isassociated(sigrdataset))
24159a
+				dns_rdataset_disassociate(sigrdataset);
24159a
+			if (node != NULL)
24159a
+				dns_db_detachnode(db, &node);
24159a
+
24159a
+			result = query_recurse(client, qtype,
24159a
+					       client->query.qname,
24159a
+					       NULL, NULL, resuming);
24159a
+			if (result == ISC_R_SUCCESS) {
24159a
+				client->query.attributes |=
24159a
+					NS_QUERYATTR_RECURSING;
24159a
+				if (dns64)
24159a
+					client->query.attributes |=
24159a
+						NS_QUERYATTR_DNS64;
24159a
+				if (dns64_exclude)
24159a
+					client->query.attributes |=
24159a
+					      NS_QUERYATTR_DNS64EXCLUDE;
24159a
+			} else
24159a
+				RECURSE_ERROR(result);
24159a
+			goto cleanup;
24159a
+		}
24159a
+
24159a
 		/*
24159a
 		 * Keep a copy of the rdataset.  We have to do this because
24159a
 		 * query_addrrset may clear 'rdataset' (to prevent the
24159a
diff --git a/bin/tests/system/zero/ans5/ans.pl b/bin/tests/system/zero/ans5/ans.pl
24159a
new file mode 100644
24159a
index 0000000000..9dfa18e444
24159a
--- /dev/null
24159a
+++ b/bin/tests/system/zero/ans5/ans.pl
24159a
@@ -0,0 +1,81 @@
24159a
+#!/usr/bin/perl -w
24159a
+#
24159a
+# Copyright (C) 2015  Internet Systems Consortium, Inc. ("ISC")
24159a
+#
24159a
+# Permission to use, copy, modify, and/or distribute this software for any
24159a
+# purpose with or without fee is hereby granted, provided that the above
24159a
+# copyright notice and this permission notice appear in all copies.
24159a
+#
24159a
+# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
24159a
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
24159a
+# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
24159a
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
24159a
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
24159a
+# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24159a
+# PERFORMANCE OF THIS SOFTWARE.
24159a
+
24159a
+#
24159a
+# Don't respond if the "norespond" file exists; otherwise respond to
24159a
+# any A or AAAA query.
24159a
+#
24159a
+
24159a
+use IO::File;
24159a
+use IO::Socket;
24159a
+use Net::DNS;
24159a
+use Net::DNS::Packet;
24159a
+
24159a
+my $sock = IO::Socket::INET->new(LocalAddr => "10.53.0.5",
24159a
+   LocalPort => 5300, Proto => "udp") or die "$!";
24159a
+
24159a
+my $pidf = new IO::File "ans.pid", "w" or die "cannot open pid file: $!";
24159a
+print $pidf "$$\n" or die "cannot write pid file: $!";
24159a
+$pidf->close or die "cannot close pid file: $!";
24159a
+sub rmpid { unlink "ans.pid"; exit 1; };
24159a
+
24159a
+$SIG{INT} = \&rmpid;
24159a
+$SIG{TERM} = \&rmpid;
24159a
+
24159a
+my $octet = 0;
24159a
+
24159a
+for (;;) {
24159a
+	$sock->recv($buf, 512);
24159a
+
24159a
+	print "**** request from " , $sock->peerhost, " port ", $sock->peerport, "\n";
24159a
+
24159a
+	my $packet;
24159a
+
24159a
+	if ($Net::DNS::VERSION > 0.68) {
24159a
+		$packet = new Net::DNS::Packet(\$buf, 0);
24159a
+		$@ and die $@;
24159a
+	} else {
24159a
+		my $err;
24159a
+		($packet, $err) = new Net::DNS::Packet(\$buf, 0);
24159a
+		$err and die $err;
24159a
+	}
24159a
+
24159a
+	print "REQUEST:\n";
24159a
+	$packet->print;
24159a
+
24159a
+	$packet->header->qr(1);
24159a
+
24159a
+	my @questions = $packet->question;
24159a
+	my $qname = $questions[0]->qname;
24159a
+	my $qtype = $questions[0]->qtype;
24159a
+
24159a
+	$packet->header->aa(1);
24159a
+	if ($qtype eq "A") {
24159a
+		$packet->push("answer",
24159a
+			      new Net::DNS::RR($qname .
24159a
+					       " 0 A 192.0.2." . $octet));
24159a
+		$octet = $octet + 1;
24159a
+	} elsif ($qtype eq "AAAA") {
24159a
+		$packet->push("answer",
24159a
+			      new Net::DNS::RR($qname .
24159a
+						" 300 AAAA 2001:db8:beef::1"));
24159a
+	}
24159a
+
24159a
+	$sock->send($packet->data);
24159a
+	print "RESPONSE:\n";
24159a
+	$packet->print;
24159a
+	print "\n";
24159a
+}
24159a
diff --git a/bin/tests/system/zero/ns1/root.db b/bin/tests/system/zero/ns1/root.db
24159a
index 69aca86fb8..beb97cb693 100644
24159a
--- a/bin/tests/system/zero/ns1/root.db
24159a
+++ b/bin/tests/system/zero/ns1/root.db
24159a
@@ -22,3 +22,5 @@ example. NS ns2.example.
24159a
 ns2.example. A 10.53.0.2
24159a
 example. NS ns4.example.
24159a
 ns4.example. A 10.53.0.4
24159a
+increment. NS incrementns.
24159a
+incrementns A 10.53.0.5
24159a
diff --git a/bin/tests/system/zero/tests.sh b/bin/tests/system/zero/tests.sh
24159a
index 15c2906a92..bbb78f0fd8 100644
24159a
--- a/bin/tests/system/zero/tests.sh
24159a
+++ b/bin/tests/system/zero/tests.sh
24159a
@@ -44,5 +44,18 @@ done
24159a
 if [ $ret != 0 ]; then echo "I:failed"; fi
24159a
 status=`expr $status + $ret`
24159a
 
24159a
+echo "I:check repeated recursive lookups of non recurring zero ttl responses get new values"
24159a
+count=`(
24159a
+dig +short -p 5300 @10.53.0.3 foo.increment
24159a
+dig +short -p 5300 @10.53.0.3 foo.increment
24159a
+dig +short -p 5300 @10.53.0.3 foo.increment
24159a
+dig +short -p 5300 @10.53.0.3 foo.increment
24159a
+dig +short -p 5300 @10.53.0.3 foo.increment
24159a
+dig +short -p 5300 @10.53.0.3 foo.increment
24159a
+dig +short -p 5300 @10.53.0.3 foo.increment
24159a
+) | sort -u | wc -l `
24159a
+if [ $count -ne 7 ] ; then echo "I:failed (count=$count)"; ret=1; fi
24159a
+status=`expr $status + $ret`
24159a
+
24159a
 echo "I:exit status: $status"
24159a
 exit $status
24159a
-- 
24159a
2.14.4
24159a