]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
4336. [bug] Don't emit records with zero ttl unless the records
authorMark Andrews <marka@isc.org>
Mon, 21 Mar 2016 02:22:21 +0000 (13:22 +1100)
committerMark Andrews <marka@isc.org>
Mon, 21 Mar 2016 02:22:21 +0000 (13:22 +1100)
                        were learnt with a zero ttl. [RT #41687]

CHANGES
bin/tests/system/mkeys/ns2/named.args
bin/tests/system/resolver/ns6/example.net.db.in
bin/tests/system/resolver/ns7/named1.conf
bin/tests/system/resolver/ns7/named2.conf
bin/tests/system/resolver/tests.sh
lib/dns/rbtdb.c
lib/dns/zone.c

diff --git a/CHANGES b/CHANGES
index 96d261a45066a23e79ed556612a4628556e21d68..c93e9631de363385322615b1f443a787172f45e7 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+4336.  [bug]           Don't emit records with zero ttl unless the records
+                       were learnt with a zero ttl. [RT #41687]
+
 4335.  [bug]           zone->view could be detached too early. [RT #41942]
 
 4334.  [func]          'named -V' now reports zlib version. [RT #41913]
index a29041f6e3744cadf9d65f97365dec40608c3d9a..ded06e551a7628952116d86a383c655235f42898 100644 (file)
@@ -1 +1 @@
--m record,size,mctx -T clienttest -c named.conf -d 99 -X named.lock -g -T mkeytimers=2/10/15
+-m record,size,mctx -T clienttest -c named.conf -d 99 -X named.lock -g -T mkeytimers=3/10/15
index c45de7fe9e2aeaf70dc7bdb56b8bceeeff7ca8b8..aac7483b0cce8be0a99798a3470138b3f0b3bf61 100644 (file)
@@ -21,3 +21,5 @@ $TTL 600
 ns     IN A    10.53.0.6
 mail   IN A    10.53.0.6
 fetch 10 IN TXT A short ttl
+non-zero 10 IN TXT A short ttl
+zero 0 IN TXT A zero ttl
index 6f2b6556014e245e26808568be061dd841b4da9f..6f6b685937c6e17d74f7b1f042058311dd2e8677 100644 (file)
@@ -29,6 +29,10 @@ options {
        recursion yes;
        empty-zones-enable yes;
        disable-empty-zone 20.172.in-addr.arpa;
+       /*
+        * I: check prefetch disabled
+        * I: check zero ttl not returned
+        */
        prefetch 0;
        querylog yes;
 };
index 30c8a5a771d20220762ee83f762fcbd99d80ddb6..52f2cbb9763b738e39ab36d735955dfd804f2051 100644 (file)
@@ -29,6 +29,10 @@ options {
        recursion yes;
        empty-zones-enable yes;
        disable-empty-zone 20.172.in-addr.arpa;
+       /*
+        * I: check prefetch disabled
+        * I: check zero ttl not returned
+        */
        prefetch 0;
        querylog yes;
 };
index 708780f68a76dbb0110d319df5e049358a71e994..397b7855d0d32b696294597664a075a5ccb617de 100755 (executable)
@@ -435,24 +435,24 @@ n=`expr $n + 1`
 echo "I:check prefetch disabled (${n})"
 ret=0
 $DIG @10.53.0.7 -p 5300 fetch.example.net txt > dig.out.1.${n} || ret=1
-ttl1=`awk '/"A" "short" "ttl"/ { print $2 - 1 }' dig.out.1.${n}`
+ttl1=`awk '/"A" "short" "ttl"/ { print $2 - 2 }' dig.out.1.${n}`
 # sleep so we are in expire range
 sleep ${ttl1:-0}
-# look for zero ttl, allow for one miss at getting zero ttl
+# look for ttl = 1, allow for one miss at getting zero ttl
 zerotonine="0 1 2 3 4 5 6 7 8 9"
 for i in $zerotonine $zerotonine $zerotonine $zerotonine
 do 
        $DIG @10.53.0.7 -p 5300 fetch.example.net txt > dig.out.2.${n} || ret=1
        ttl2=`awk '/"A" "short" "ttl"/ { print $2 }' dig.out.2.${n}`
-       test ${ttl2:-1} -eq 0 && break
+       test ${ttl2:-2} -eq 1 && break
        $PERL -e 'select(undef, undef, undef, 0.05);' 
 done
-test ${ttl2:-1} -eq 0 || ret=1
+test ${ttl2:-2} -eq 1 || ret=1
 # delay so that any prefetched record will have a lower ttl than expected
 sleep 3
 # check that prefetch has not occured
 $DIG @10.53.0.7 -p 5300 fetch.example.net txt > dig.out.3.${n} || ret=1
-ttl=`awk '/"A" "short" "ttl"/ { print $2 - 1 }' dig.out.3.${n}`
+ttl=`awk '/"A" "short" "ttl"/ { print $2 - 2 }' dig.out.3.${n}`
 test ${ttl:-0} -eq ${ttl1:-1} || ret=1
 if [ $ret != 0 ]; then echo "I:failed"; fi
 status=`expr $status + $ret`
@@ -474,7 +474,6 @@ if [ $ret != 0 ]; then echo "I:failed"; fi
 status=`expr $status + $ret`
 
 n=`expr $n + 1`
-
 echo "I:check that E was logged on EDNS queries in the query log (${n})"
 ret=0
 $DIG @10.53.0.5 -p 5300 +edns edns.fetchall.tld any > dig.out.2.${n} || ret=1
@@ -657,5 +656,37 @@ grep "status: NXDOMAIN" dig.out.ns5.test${n} > /dev/null || ret=1
 if [ $ret != 0 ]; then echo "I:failed"; fi
 status=`expr $status + $ret`
 
+n=`expr $n + 1`
+echo "I:check zero ttl not returned for learnt non zero ttl records (${n})"
+ret=0
+# use prefetch disabled server
+$DIG @10.53.0.7 -p 5300 non-zero.example.net txt > dig.out.1.${n} || ret=1
+ttl1=`awk '/"A" "short" "ttl"/ { print $2 - 2 }' dig.out.1.${n}`
+# sleep so we are in expire range
+sleep ${ttl1:-0}
+# look for ttl = 1, allow for one miss at getting zero ttl
+zerotonine="0 1 2 3 4 5 6 7 8 9"
+zerotonine="$zerotonine $zerotonine $zerotonine"
+for i in $zerotonine $zerotonine $zerotonine $zerotonine
+do
+       $DIG @10.53.0.7 -p 5300 non-zero.example.net txt > dig.out.2.${n} || ret=1
+       ttl2=`awk '/"A" "short" "ttl"/ { print $2 }' dig.out.2.${n}`
+       test ${ttl2:-1} -eq 0 && break
+       test ${ttl2:-1} -ge ${ttl1:-0} && break
+       $PERL -e 'select(undef, undef, undef, 0.05);'
+done
+test ${ttl2:-1} -eq 0 && ret=1
+test ${ttl2:-1} -ge ${ttl1:-0} || break
+if [ $ret != 0 ]; then echo "I:failed"; fi
+status=`expr $status + $ret`
+
+n=`expr $n + 1`
+echo "I:check zero ttl is returned for learnt zero ttl records (${n})"
+ret=0
+$DIG @10.53.0.7 -p 5300 zero.example.net txt > dig.out.1.${n} || ret=1
+ttl=`awk '/"A" "zero" "ttl"/ { print $2 }' dig.out.1.${n}`
+test ${ttl:-1} -eq 0 || ret=1
+if [ $ret != 0 ]; then echo "I:failed"; fi
+status=`expr $status + $ret`
 echo "I:exit status: $status"
 exit $status
index 5a971926510e894fac9eebb375f2dd6aeb61bdb4..ee1e4b5ec567ad6ef2912bacbcae28c789929796 100644 (file)
@@ -478,6 +478,7 @@ typedef ISC_LIST(dns_rbtnode_t)         rbtnodelist_t;
 #define RDATASET_ATTR_NEGATIVE          0x0100
 #define RDATASET_ATTR_PREFETCH          0x0200
 #define RDATASET_ATTR_CASESET           0x0400
+#define RDATASET_ATTR_ZEROTTL           0x0800
 
 typedef struct acache_cbarg {
        dns_rdatasetadditional_t        type;
@@ -524,6 +525,8 @@ struct acachectl {
        (((header)->attributes & RDATASET_ATTR_PREFETCH) != 0)
 #define CASESET(header) \
        (((header)->attributes & RDATASET_ATTR_CASESET) != 0)
+#define ZEROTTL(header) \
+       (((header)->attributes & RDATASET_ATTR_ZEROTTL) != 0)
 
 #define DEFAULT_NODE_LOCK_COUNT         7       /*%< Should be prime. */
 
@@ -4549,7 +4552,8 @@ check_stale_rdataset(dns_rbtnode_t *node, rdatasetheader_t *header,
        UNUSED(lock);
 #endif
 
-       if (header->rdh_ttl < search->now) {
+       if (header->rdh_ttl < search->now ||
+           (header->rdh_ttl == search->now && !ZEROTTL(header))) {
                /*
                 * This rdataset is stale.  If no one else is using the
                 * node, we can clean it up right now, otherwise we mark
@@ -6598,6 +6602,8 @@ addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
        newheader->type = RBTDB_RDATATYPE_VALUE(rdataset->type,
                                                rdataset->covers);
        newheader->attributes = 0;
+       if (rdataset->ttl == 0U)
+               newheader->attributes |= RDATASET_ATTR_ZEROTTL;
        newheader->noqname = NULL;
        newheader->closest = NULL;
        newheader->count = init_count++;
index 6878ffe4b46ee7e773ea511c23d259fcbe4e3fd9..94d0a530dafb2740e3e569324cf3fe9a9948c083 100644 (file)
@@ -3672,7 +3672,8 @@ compute_tag(dns_name_t *name, dns_rdata_dnskey_t *dnskey, isc_mem_t *mctx,
  */
 static void
 trust_key(dns_zone_t *zone, dns_name_t *keyname,
-         dns_rdata_dnskey_t *dnskey, isc_mem_t *mctx) {
+         dns_rdata_dnskey_t *dnskey, isc_mem_t *mctx)
+{
        isc_result_t result;
        dns_rdata_t rdata = DNS_RDATA_INIT;
        unsigned char data[4096];