]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Optimize cname_and_other_data to stop as earliest as possible
authorOndřej Surý <ondrej@isc.org>
Mon, 29 Jan 2024 15:36:30 +0000 (16:36 +0100)
committerOndřej Surý <ondrej@isc.org>
Thu, 8 Feb 2024 07:33:36 +0000 (08:33 +0100)
Stop the cname_and_other_data processing if we already know that the
result is true.  Also, we know that CNAME will be placed in the priority
headers, so we can stop looking for CNAME if we haven't found CNAME and
we are past the priority headers.

bin/tests/system/resolver/tests.sh
lib/dns/rbtdb.c

index d9f2ab6f7ad86ca61520e79065d8f4377f234bd8..65ef9b928b383a5ebc5ca48b328bf042382f2b4a 100755 (executable)
@@ -482,10 +482,10 @@ dig_with_opts @10.53.0.5 fetchall.tld any >dig.out.2.${n} || ret=1
 ttl2=$(awk '/"A" "short" "ttl"/ { print $2 }' dig.out.2.${n})
 sleep 1
 # check that prefetch occurred;
-# note that only one record is prefetched, which is the TXT record in this case,
+# note that only one record is prefetched, which is the AAAA record in this case,
 # because of the order of the records in the cache
 dig_with_opts @10.53.0.5 fetchall.tld any >dig.out.3.${n} || ret=1
-ttl3=$(awk '/"A" "short" "ttl"/ { print $2 }' dig.out.3.${n})
+ttl3=$(awk '/::1/ { print $2 }' dig.out.3.${n})
 test "${ttl3:-0}" -gt "${ttl2:-1}" || ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=$((status + ret))
index 3169ebb6ee9938e1c612ad4146bcd4abcd77ac31..7b2df98ca7aef11519193e3972b526cd6c75cf59 100644 (file)
@@ -2391,7 +2391,7 @@ dns__rbtdb_allrdatasets(dns_db_t *db, dns_dbnode_t *node,
 static bool
 cname_and_other_data(dns_rbtnode_t *node, uint32_t serial) {
        dns_slabheader_t *header = NULL, *header_next = NULL;
-       bool cname, other_data;
+       bool cname = false, other_data = false;
        dns_rdatatype_t rdtype;
 
        /*
@@ -2401,10 +2401,16 @@ cname_and_other_data(dns_rbtnode_t *node, uint32_t serial) {
        /*
         * Look for CNAME and "other data" rdatasets active in our version.
         */
-       cname = false;
-       other_data = false;
        for (header = node->data; header != NULL; header = header_next) {
                header_next = header->next;
+               if (!prio_type(header->type)) {
+                       /*
+                        * CNAME is in the priority list, so if we are done
+                        * with the priority list, we know there will not be
+                        * CNAME, so we are safe to skip the rest of the types.
+                        */
+                       return (false);
+               }
                if (header->type == dns_rdatatype_cname) {
                        /*
                         * Look for an active extant CNAME.
@@ -2464,10 +2470,9 @@ cname_and_other_data(dns_rbtnode_t *node, uint32_t serial) {
                                }
                        }
                }
-       }
-
-       if (cname && other_data) {
-               return (true);
+               if (cname && other_data) {
+                       return (true);
+               }
        }
 
        return (false);