]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add better ZEROTTL handling in bindrdataset()
authorOndřej Surý <ondrej@isc.org>
Sun, 2 Feb 2025 12:38:04 +0000 (13:38 +0100)
committerOndřej Surý <ondrej@isc.org>
Mon, 3 Feb 2025 14:53:34 +0000 (15:53 +0100)
If we know that the header has ZEROTTL set, the server should never send
stale records for it and the TTL should never be anything else than 0.
The comment was already there, but the code was not matching the
comment.

(cherry picked from commit cfee6aa56557f9fde8bd47949c5165edaf350113)

lib/dns/qpcache.c
lib/dns/rbtdb.c

index 83ce178ee08e54878c9cfb26791ae2a1cf29175b..25a93431d20a85857200fa741a402ef208f23e2a 100644 (file)
@@ -1058,7 +1058,7 @@ bindrdataset(qpcache_t *qpdb, qpcnode_t *node, dns_slabheader_t *header,
                 * (these records should not be cached anyway).
                 */
 
-               if (KEEPSTALE(qpdb) && stale_ttl > now) {
+               if (!ZEROTTL(header) && KEEPSTALE(qpdb) && stale_ttl > now) {
                        stale = true;
                } else {
                        /*
@@ -1073,6 +1073,7 @@ bindrdataset(qpcache_t *qpdb, qpcnode_t *node, dns_slabheader_t *header,
        rdataset->rdclass = qpdb->common.rdclass;
        rdataset->type = DNS_TYPEPAIR_TYPE(header->type);
        rdataset->covers = DNS_TYPEPAIR_COVERS(header->type);
+       rdataset->ttl = !ZEROTTL(header) ? header->ttl - now : 0;
        rdataset->ttl = header->ttl - now;
        rdataset->trust = header->trust;
        rdataset->resign = 0;
index 1a53ede50311d8d31f1989ea9baae6770e3d95d5..cd81fe45501c12f356986be48f981bd0cdd9241b 100644 (file)
@@ -2150,7 +2150,7 @@ dns__rbtdb_bindrdataset(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node,
                 * (these records should not be cached anyway).
                 */
 
-               if (KEEPSTALE(rbtdb) && stale_ttl > now) {
+               if (!ZEROTTL(header) && KEEPSTALE(rbtdb) && stale_ttl > now) {
                        stale = true;
                } else {
                        /*
@@ -2165,7 +2165,7 @@ dns__rbtdb_bindrdataset(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node,
        rdataset->rdclass = rbtdb->common.rdclass;
        rdataset->type = DNS_TYPEPAIR_TYPE(header->type);
        rdataset->covers = DNS_TYPEPAIR_COVERS(header->type);
-       rdataset->ttl = header->ttl - now;
+       rdataset->ttl = !ZEROTTL(header) ? header->ttl - now : 0;
        rdataset->trust = header->trust;
 
        if (NEGATIVE(header)) {