]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/cache: return records that are going to be expired next second
authorMarek Vavruša <marek.vavrusa@nic.cz>
Sun, 7 Jun 2015 12:12:28 +0000 (14:12 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Sun, 7 Jun 2015 12:12:28 +0000 (14:12 +0200)
lib/cache.c
tests/test_cache.c

index 9606ce44c22d995d13c6bc82dfd9ebc71cb00f93..0d69cadf59b04cb4a8d4d3801cd788cd4b1c09f8 100644 (file)
@@ -152,7 +152,7 @@ int kr_cache_peek(struct kr_cache_txn *txn, uint8_t tag, const knot_dname_t *nam
        } else {
                /* Check if the record is still valid. */
                uint32_t drift = *timestamp - found->timestamp;
-               if (drift < found->ttl) {
+               if (drift <= found->ttl) {
                        *timestamp = drift;
                        txn->owner->stats.hit += 1;
                        return kr_ok();
@@ -264,7 +264,7 @@ int kr_cache_materialize(knot_rrset_t *dst, const knot_rrset_t *src, uint32_t dr
        knot_rdata_t *rd = knot_rdataset_at(&src->rrs, 0);
        knot_rdata_t *rd_dst = NULL;
        for (uint16_t i = 0; i < src->rrs.rr_count; ++i) {
-               if (knot_rdata_ttl(rd) > drift) {
+               if (knot_rdata_ttl(rd) >= drift) {
                        /* Append record */
                        if (knot_rdataset_add(&dst->rrs, rd, mm) != 0) {
                                knot_rrset_clear(dst, mm);
index a629766a31ba4853fdfc85d134927e0347ef88e4..f72a69a7a4f35c3d1578bcb0c94245428fe07822 100644 (file)
@@ -360,7 +360,7 @@ static void test_query(void **state)
 /* Test cache read (simulate aged entry) */
 static void test_query_aged(void **state)
 {
-       uint32_t timestamp = CACHE_TIME + CACHE_TTL;
+       uint32_t timestamp = CACHE_TIME + CACHE_TTL + 1;
        knot_rrset_t cache_rr;
        knot_rrset_init(&cache_rr, global_rr.owner, global_rr.type, global_rr.rclass);