Commit 85969d17d8 for bind
commit 85969d17d80841ad7a92c4147c62ee77742377dd
Author: Aram Sargsyan <aram@isc.org>
Date: Tue Dec 1 20:09:41 2026 +0000
Add a new fetches-per-zone system test
This test checks whether a referral into a zone that is at its
fetches-per-zone limit works as expected.
diff --git a/bin/tests/system/fetchlimit_referral/ans1/ans.py b/bin/tests/system/fetchlimit_referral/ans1/ans.py
new file mode 100644
index 0000000000..d1baf4faab
--- /dev/null
+++ b/bin/tests/system/fetchlimit_referral/ans1/ans.py
@@ -0,0 +1,62 @@
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# SPDX-License-Identifier: MPL-2.0
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+import dns.name
+import dns.rcode
+import dns.rdataclass
+import dns.rdatatype
+import dns.rrset
+
+from isctest.asyncserver import AsyncDnsServer
+from isctest.asyncserver.handlers import SingleResponseHandler
+from isctest.asyncserver.matchers import Qname, Qtype
+from isctest.template import ANS2
+
+
+def rrset(
+ owner: str | dns.name.Name,
+ rdtype: dns.rdatatype.RdataType,
+ rdata: str,
+ ttl: int = 300,
+) -> dns.rrset.RRset:
+ return dns.rrset.from_text(owner, ttl, dns.rdataclass.IN, rdtype, rdata)
+
+
+def ns(owner: str | dns.name.Name, target: str) -> dns.rrset.RRset:
+ return rrset(owner, dns.rdatatype.NS, target)
+
+
+def a(owner: str | dns.name.Name, address: str) -> dns.rrset.RRset:
+ return rrset(owner, dns.rdatatype.A, address)
+
+
+class ReferralWithAnswerHandler(SingleResponseHandler):
+ """
+ The referral with an unrelated record in the ANSWER section, which the
+ resolver processes as an answer that may be a delegation rather than as a
+ plain referral.
+ """
+
+ matcher = Qname("example.") & Qtype(dns.rdatatype.DS)
+ rcode = dns.rcode.NOERROR
+ answer = [a("unrelated.", "192.0.2.1")]
+ authority = [ns(matcher.of(Qname).qname, f"ns.{matcher.of(Qname).qname}")]
+ additional = [a(f"ns.{matcher.of(Qname).qname}", ANS2.ip)]
+
+
+def main() -> None:
+ server = AsyncDnsServer()
+ server.install_response_handlers(ReferralWithAnswerHandler())
+ server.run()
+
+
+if __name__ == "__main__":
+ main()
diff --git a/bin/tests/system/fetchlimit_referral/ans1/zones/root.db b/bin/tests/system/fetchlimit_referral/ans1/zones/root.db
new file mode 100644
index 0000000000..af04e9cd7f
--- /dev/null
+++ b/bin/tests/system/fetchlimit_referral/ans1/zones/root.db
@@ -0,0 +1,8 @@
+$ORIGIN .
+$TTL 3600
+. SOA . . 0 0 0 0 3600
+. NS a.root-servers.nil.
+a.root-servers.nil. A 10.53.0.1
+
+example. NS ns.example.
+ns.example. A 10.53.0.2
diff --git a/bin/tests/system/fetchlimit_referral/ans2/ans.py b/bin/tests/system/fetchlimit_referral/ans2/ans.py
new file mode 100644
index 0000000000..58ff8932e5
--- /dev/null
+++ b/bin/tests/system/fetchlimit_referral/ans2/ans.py
@@ -0,0 +1,23 @@
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# SPDX-License-Identifier: MPL-2.0
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+from isctest.asyncserver import AsyncDnsServer
+from isctest.asyncserver.handlers import IgnoreAllQueries
+
+
+def main() -> None:
+ server = AsyncDnsServer()
+ server.install_response_handlers(IgnoreAllQueries())
+ server.run()
+
+
+if __name__ == "__main__":
+ main()
diff --git a/bin/tests/system/fetchlimit_referral/ns3/named.conf.j2 b/bin/tests/system/fetchlimit_referral/ns3/named.conf.j2
new file mode 100644
index 0000000000..0dad2b7d9c
--- /dev/null
+++ b/bin/tests/system/fetchlimit_referral/ns3/named.conf.j2
@@ -0,0 +1,9 @@
+options {
+ {% include_indented "_common/options.conf.j2" %}
+ recursion yes;
+ dnssec-validation no;
+ fetches-per-zone 10 drop;
+};
+
+{% include "_common/controls.conf.j2" %}
+{% include "_common/root.hint.conf" %}
diff --git a/bin/tests/system/fetchlimit_referral/tests_fetchlimit_referral.py b/bin/tests/system/fetchlimit_referral/tests_fetchlimit_referral.py
new file mode 100644
index 0000000000..6fc58765ac
--- /dev/null
+++ b/bin/tests/system/fetchlimit_referral/tests_fetchlimit_referral.py
@@ -0,0 +1,63 @@
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# SPDX-License-Identifier: MPL-2.0
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+"""
+A referral into a zone that is at its fetches-per-zone limit.
+
+ns3 is a resolver with "fetches-per-zone 10". ans1 is the root server
+and delegates example. to ans2, which never answers, so fetches for
+names below example. stay counted in that zone until it is at its
+limit. A DS query for example. is then sent to the parent zone's
+server, ans1, whose referral to example. also carries a record in its
+answer section. The fetch cannot follow the referral, so the client
+must get SERVFAIL.
+
+The limit leaves room for the fetches the resolver starts in the root
+zone on its own behalf while it handles the first query (priming, QNAME
+minimization).
+"""
+
+from re import compile as Re
+
+import socket
+
+import dns.query
+
+import isctest
+
+FETCHES_PER_ZONE = 10 # as in ns3/named.conf.j2
+
+
+def hold_query(sock, ns3, named_port, name):
+ msg = isctest.query.create(name, "A")
+ dns.query.send_udp(sock, msg, (ns3.ip, named_port))
+
+
+def test_referral_with_answer_into_full_zone(ns3, ans2, named_port):
+ # One query more than the limit, as the resolver's own lookups in
+ # example. may or may not have taken one of the slots; the log tells
+ # when the zone is full.
+ with socket.socket(
+ socket.AF_INET, socket.SOCK_DGRAM
+ ) as sock, ns3.watch_log_from_here() as full:
+ # The delegation is cached once ans2 sees the first query; the
+ # fetches after it start in example. right away.
+ with ans2.watch_log_from_here() as held:
+ hold_query(sock, ns3, named_port, "hold0.example.")
+ held.wait_for_line(Re(r"Received hold0\.example/IN/A "))
+ for i in range(1, FETCHES_PER_ZONE + 1):
+ hold_query(sock, ns3, named_port, f"hold{i}.example.")
+ full.wait_for_line(Re(r"too many simultaneous fetches for example "))
+
+ # TCP, so that a resolver that died is noticed at once.
+ msg = isctest.query.create("example.", "DS")
+ res = isctest.query.tcp(msg, ns3.ip)
+ isctest.check.servfail(res)