]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
"rndc flushtree ." failed to flush the cache 12579/head
authorEvan Hunt <each@isc.org>
Fri, 14 Aug 2026 00:17:44 +0000 (17:17 -0700)
committerEvan Hunt <each@isc.org>
Fri, 14 Aug 2026 00:17:44 +0000 (17:17 -0700)
`rndc flushtree` flushes cache data below a specified name. If the name
specified is the DNS root, that should fully empty the cache, the same
as `rndc flush`.  However, there was a bug causing that command to have
no effect on the cache at all; this has been fixed.

bin/named/server.c
bin/tests/system/cacheclean/tests.sh
lib/dns/cache.c
lib/dns/include/dns/cache.h
lib/dns/include/dns/view.h

index 89a30b07fd28bd92cd1c2f906bfaf6bc21f2607d..e9e018a97ee686b531ae745e45bb3190563abcaf 100644 (file)
@@ -11476,7 +11476,11 @@ flushnode_cache(dns_view_t *view, const dns_name_t *name, const char *target,
         * if some of the views share a single cache.  But since the
         * operation is lightweight we prefer simplicity here.
         */
-       result = dns_view_flushnode(view, name, tree);
+       if (dns_name_equal(name, dns_rootname)) {
+               result = dns_view_flushcache(view, false);
+       } else {
+               result = dns_view_flushnode(view, name, tree);
+       }
        if (result != ISC_R_SUCCESS) {
                isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER,
                              ISC_LOG_ERROR,
index fe71c2f8627d57242529bfc90bf6990a8782beed..cb0e0e822e39305ba29f0021646c0b4e9616e36f 100755 (executable)
@@ -278,5 +278,21 @@ grep EXPIRE: dig.out.expire >/dev/null || ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=$((status + ret))
 
+n=$((n + 1))
+echo_i "check 'flushtree .' is equivalent to 'flush' ($n)"
+ret=0
+clear_cache
+dump_cache
+grep -v DATE ns2/named_dump.db.test$n >ns2/named_dump.db.test$n.a
+load_cache
+dump_cache
+grep -v DATE ns2/named_dump.db.test$n >ns2/named_dump.db.test$n.b
+$RNDC $RNDCOPTS flushtree . || ret=1
+dump_cache
+grep -v DATE ns2/named_dump.db.test$n >ns2/named_dump.db.test$n.c
+cmp -s ns2/named_dump.db.test$n.a ns2/named_dump.db.test$n.b && ret=1
+cmp -s ns2/named_dump.db.test$n.a ns2/named_dump.db.test$n.c || ret=1
+status=$((status + ret))
+
 echo_i "exit status: $status"
 [ $status -eq 0 ] || exit 1
index f0bc00ab85ad13562929b69bc576458ffbd33bb4..6c070dd9c27be3a2fe8637ec37117c123d352455 100644 (file)
@@ -418,9 +418,7 @@ dns_cache_flushnode(dns_cache_t *cache, const dns_name_t *name, bool tree) {
        dns_dbnode_t *node = NULL;
        dns_db_t *db = NULL;
 
-       if (tree && dns_name_equal(name, dns_rootname)) {
-               return dns_cache_flush(cache);
-       }
+       REQUIRE(!(tree && dns_name_equal(name, dns_rootname)));
 
        LOCK(&cache->lock);
        if (cache->db != NULL) {
index 1ac822ad717f42beafbd82c37d09f4790732481f..9913a5cb6a223c7acc2d6420fba640584d5f4c24 100644 (file)
@@ -200,12 +200,16 @@ dns_cache_flush(dns_cache_t *cache);
 isc_result_t
 dns_cache_flushnode(dns_cache_t *cache, const dns_name_t *name, bool tree);
 /*
- * Flush a given name from the cache.  If 'tree' is true, then
- * also flush all names under 'name'.
+ * Flush the data for node 'name' from the cache.
+ *
+ * If 'tree' is true, then also flush all nodes under 'name'. (Note that
+ * flushing of a tree only works for names below the root. To flush the
+ * entire tree, use dns_cache_flush().)
  *
  * Requires:
  *\li  'cache' to be valid.
  *\li  'name' to be valid.
+ *\li  if 'tree' is true, then 'name' is not root.
  *
  * Returns:
  *\li  #ISC_R_SUCCESS
index 453ac9d1b063f2fc007fd277be47b3f7a05b9c38..5ef6377fd5c0ff5ebe325725db9874a9c13f0741 100644 (file)
@@ -853,10 +853,9 @@ isc_result_t
 dns_view_flushcache(dns_view_t *view, bool fixuponly);
 /*%<
  * Flush the view's cache (and ADB).  If 'fixuponly' is true, it only updates
- * the internal reference to the cache DB with omitting actual flush operation.
+ * the internal reference to the cache DB, omitting actual flush operation.
  * 'fixuponly' is intended to be used for a view that shares a cache with
- * a different view.  dns_view_flushcache() is a backward compatible version
- * that always sets fixuponly to false.
+ * a different view.
  *
  * Requires:
  *     'view' is valid.