]> 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 08:47:58 +0000 (09:47 +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.

(cherry picked from commit 3f774c2a8ac46b2bbf1b3a4fa1d8d8c3ed3d78a9)

lib/dns/rbtdb.c

index 180bf435e15c00edc81554af596203080d388ab2..f1fd566e8053bfdce1102d89053b0908f0e0c2cf 100644 (file)
@@ -6069,7 +6069,7 @@ allrdatasets(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
 static bool
 cname_and_other_data(dns_rbtnode_t *node, rbtdb_serial_t serial) {
        rdatasetheader_t *header, *header_next;
-       bool cname, other_data;
+       bool cname = false, other_data = false;
        dns_rdatatype_t rdtype;
 
        /*
@@ -6079,10 +6079,16 @@ cname_and_other_data(dns_rbtnode_t *node, rbtdb_serial_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.
@@ -6134,11 +6140,11 @@ cname_and_other_data(dns_rbtnode_t *node, rbtdb_serial_t serial) {
                                        other_data = true;
                        }
                }
+               if (cname && other_data) {
+                       return (true);
+               }
        }
 
-       if (cname && other_data)
-               return (true);
-
        return (false);
 }