]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
In cache, set rdataset TTL to 0 when the header is not active
authorOndřej Surý <ondrej@isc.org>
Sun, 2 Feb 2025 10:44:00 +0000 (11:44 +0100)
committerOndřej Surý <ondrej@isc.org>
Mon, 3 Feb 2025 14:53:34 +0000 (15:53 +0100)
When the header has been marked as ANCIENT, but the ttl hasn't been
reset (this happens in couple of places), the rdataset TTL would be
set to the header timestamp instead to a reasonable TTL value.

Since this header has been already expired (ANCIENT is set), set the
rdataset TTL to 0 and don't reuse this field to print the expiration
time when dumping the cache.  Instead of printing the time, we now
just print 'expired (awaiting cleanup'.

(cherry picked from commit 1bbb57f81b50bb594327428938a129a51d8ca493)

bin/tests/system/serve-stale/tests.sh
lib/dns/masterdump.c
lib/dns/qpcache.c
lib/dns/rbtdb.c

index dc5e7d9d9f1dd7460e4cff8f70d4e891d4019be6..6dc3c20308a10aba8c08ad4f8011bcfaedb6445e 100755 (executable)
@@ -1649,7 +1649,7 @@ if [ $ret != 0 ]; then echo_i "failed"; fi
 status=$((status + ret))
 # Check that expired records are not dumped.
 ret=0
-grep "; expired since .* (awaiting cleanup)" ns5/named_dump.db.test$n && ret=1
+grep "; expired (awaiting cleanup)" ns5/named_dump.db.test$n && ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=$((status + ret))
 
@@ -1665,13 +1665,13 @@ status=$((status + ret))
 echo_i "check rndc dump expired data.example ($n)"
 ret=0
 awk '/; expired/ { x=$0; getline; print x, $0}' ns5/named_dump.db.test$n \
-  | grep "; expired since .* (awaiting cleanup) data\.example\..*A text record with a 2 second ttl" >/dev/null 2>&1 || ret=1
+  | grep "; expired (awaiting cleanup) data\.example\..*A text record with a 2 second ttl" >/dev/null 2>&1 || ret=1
 awk '/; expired/ { x=$0; getline; print x, $0}' ns5/named_dump.db.test$n \
-  | grep "; expired since .* (awaiting cleanup) nodata\.example\." >/dev/null 2>&1 || ret=1
+  | grep "; expired (awaiting cleanup) nodata\.example\." >/dev/null 2>&1 || ret=1
 awk '/; expired/ { x=$0; getline; print x, $0}' ns5/named_dump.db.test$n \
-  | grep "; expired since .* (awaiting cleanup) nxdomain\.example\." >/dev/null 2>&1 || ret=1
+  | grep "; expired (awaiting cleanup) nxdomain\.example\." >/dev/null 2>&1 || ret=1
 awk '/; expired/ { x=$0; getline; print x, $0}' ns5/named_dump.db.test$n \
-  | grep "; expired since .* (awaiting cleanup) othertype\.example\." >/dev/null 2>&1 || ret=1
+  | grep "; expired (awaiting cleanup) othertype\.example\." >/dev/null 2>&1 || ret=1
 # Also make sure the not expired data does not have an expired comment.
 awk '/; authanswer/ { x=$0; getline; print x, $0}' ns5/named_dump.db.test$n \
   | grep "; authanswer longttl\.example.*A text record with a 600 second ttl" >/dev/null 2>&1 || ret=1
index 9c98ffd552eff985431d9061c67d18aa0e01782a..7b8346320a22b3ff495af8601372a8e2fa3d01f8 100644 (file)
@@ -1164,15 +1164,7 @@ again:
                        if (STALE(rds)) {
                                fprintf(f, "; stale\n");
                        } else if (ANCIENT(rds)) {
-                               isc_buffer_t b;
-                               char buf[sizeof("YYYYMMDDHHMMSS")];
-                               memset(buf, 0, sizeof(buf));
-                               isc_buffer_init(&b, buf, sizeof(buf) - 1);
-                               dns_time64_totext((uint64_t)rds->ttl, &b);
-                               fprintf(f,
-                                       "; expired since %s "
-                                       "(awaiting cleanup)\n",
-                                       buf);
+                               fprintf(f, "; expired (awaiting cleanup)\n");
                        }
                        result = dump_rdataset(mctx, name, rds, ctx, buffer, f);
                        if (result != ISC_R_SUCCESS) {
index 01b8bf1321b4ee7bd0f6084d845ad83c56699dcb..83ce178ee08e54878c9cfb26791ae2a1cf29175b 100644 (file)
@@ -1103,7 +1103,7 @@ bindrdataset(qpcache_t *qpdb, qpcnode_t *node, dns_slabheader_t *header,
                rdataset->attributes |= DNS_RDATASETATTR_STALE;
        } else if (!ACTIVE(header, now)) {
                rdataset->attributes |= DNS_RDATASETATTR_ANCIENT;
-               rdataset->ttl = header->ttl;
+               rdataset->ttl = 0;
        }
 
        rdataset->count = atomic_fetch_add_relaxed(&header->count, 1);
index a708f7b7feb637a1bb4b1fed419bc2a60d420312..1a53ede50311d8d31f1989ea9baae6770e3d95d5 100644 (file)
@@ -2194,7 +2194,7 @@ dns__rbtdb_bindrdataset(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node,
                rdataset->attributes |= DNS_RDATASETATTR_STALE;
        } else if (IS_CACHE(rbtdb) && !ACTIVE(header, now)) {
                rdataset->attributes |= DNS_RDATASETATTR_ANCIENT;
-               rdataset->ttl = header->ttl;
+               rdataset->ttl = 0;
        }
 
        rdataset->count = atomic_fetch_add_relaxed(&header->count, 1);