Commit c02eeba031 for bind
commit c02eeba03185c363bd5fad2e85c3041095c2137f
Author: Alessio Podda <alessio@isc.org>
Date: Sun Oct 5 08:15:09 2025 +0200
Skip expensive string lookups in zone creation in the common case
Both the search for rfc1918 names and for zone template labels are
implemented in linear time in the number of possible cases.
In hosting-type setups with lots of zones, these checks can
significantly delay startup time. This commit adds a pre-check to skip
the expensive checks when possible.
diff --git a/lib/dns/name.c b/lib/dns/name.c
index 7317a29c8f..fc0762ef99 100644
--- a/lib/dns/name.c
+++ b/lib/dns/name.c
@@ -1860,6 +1860,8 @@ dns_name_isdnssd(const dns_name_t *name) {
return false;
}
+static unsigned char inaddr_prefix[] = "\007IN-ADDR\004ARPA";
+
static unsigned char inaddr10[] = "\00210\007IN-ADDR\004ARPA";
static unsigned char inaddr16172[] = "\00216\003172\007IN-ADDR\004ARPA";
@@ -1881,6 +1883,8 @@ static unsigned char inaddr31172[] = "\00231\003172\007IN-ADDR\004ARPA";
static unsigned char inaddr168192[] = "\003168\003192\007IN-ADDR\004ARPA";
+static dns_name_t const rfc1918prefix = DNS_NAME_INITABSOLUTE(inaddr_prefix);
+
static dns_name_t const rfc1918names[] = {
DNS_NAME_INITABSOLUTE(inaddr10), DNS_NAME_INITABSOLUTE(inaddr16172),
DNS_NAME_INITABSOLUTE(inaddr17172), DNS_NAME_INITABSOLUTE(inaddr18172),
@@ -1897,6 +1901,13 @@ bool
dns_name_isrfc1918(const dns_name_t *name) {
size_t i;
+ /*
+ * Even better, this could be a trie or a perfect hashmap
+ */
+ if (!dns_name_issubdomain(name, &rfc1918prefix)) {
+ return false;
+ }
+
for (i = 0; i < (sizeof(rfc1918names) / sizeof(*rfc1918names)); i++) {
if (dns_name_issubdomain(name, &rfc1918names[i])) {
return true;
diff --git a/lib/dns/zoneproperties.c b/lib/dns/zoneproperties.c
index 0f086a4f05..b95083fa87 100644
--- a/lib/dns/zoneproperties.c
+++ b/lib/dns/zoneproperties.c
@@ -453,6 +453,12 @@ dns_zone_expandzonefile(isc_buffer_t *b, const char *filename,
names.viewname = "";
}
+ if (strpbrk(filename, "$%") == NULL) {
+ putmem(b, filename, strlen(filename));
+ isc_buffer_putuint8(b, 0);
+ return;
+ }
+
/* Normalize the name by converting to lower case */
result = dns_name_downcase(zonename, names.zonename);
INSIST(result == ISC_R_SUCCESS);