From 12796d0af8e740a5f02a4f36e56c469780405890 Mon Sep 17 00:00:00 2001 From: George Thessalonikefs Date: Tue, 28 Jun 2022 17:05:28 +0200 Subject: [PATCH] - Fix for cached 0 TTL records to not trigger prefetching when serve-expired-client-timeout is set. --- daemon/worker.c | 2 +- doc/Changelog | 2 + ...rve_expired_client_timeout_no_prefetch.rpl | 110 ++++++++++++++++++ 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 testdata/serve_expired_client_timeout_no_prefetch.rpl diff --git a/daemon/worker.c b/daemon/worker.c index bf8c5d6b6..4fe57922e 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -1653,7 +1653,7 @@ lookup_cache: if((worker->env.cfg->prefetch && *worker->env.now >= ((struct reply_info*)e->data)->prefetch_ttl) || (worker->env.cfg->serve_expired && - *worker->env.now >= ((struct reply_info*)e->data)->ttl)) { + *worker->env.now > ((struct reply_info*)e->data)->ttl)) { time_t leeway = ((struct reply_info*)e-> data)->ttl - *worker->env.now; diff --git a/doc/Changelog b/doc/Changelog index 5d3bc17b0..6316504d0 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,5 +1,7 @@ 28 June 2022: George - Show the output of the exact .rpl run that failed with 'make test'. + - Fix for cached 0 TTL records to not trigger prefetching when + serve-expired-client-timeout is set. 28 June 2022: Wouter - Fix test program dohclient close to use portability routine. diff --git a/testdata/serve_expired_client_timeout_no_prefetch.rpl b/testdata/serve_expired_client_timeout_no_prefetch.rpl new file mode 100644 index 000000000..aed397d9e --- /dev/null +++ b/testdata/serve_expired_client_timeout_no_prefetch.rpl @@ -0,0 +1,110 @@ +; config options +server: + module-config: "validator iterator" + qname-minimisation: "no" + minimal-responses: no + serve-expired: yes + serve-expired-client-timeout: 1 + serve-expired-reply-ttl: 123 + ede: yes + ede-serve-expired: yes + +stub-zone: + name: "example.com" + stub-addr: 1.2.3.4 +CONFIG_END + +SCENARIO_BEGIN Test that no prefetch is triggered for 0TTL records with serve-expired and client-timeout enabled +; Scenario overview: +; - query for example.com. IN A +; - check that we get an answer for example.com. IN A with the correct TTL +; - query again right at the 0TTL cached entry +; - check that we get the cached answer with no prefetching triggered + +; ns.example.com. +RANGE_BEGIN 0 100 + ADDRESS 1.2.3.4 + ENTRY_BEGIN + MATCH opcode qtype qname + ADJUST copy_id + REPLY QR NOERROR + SECTION QUESTION + example.com. IN NS + SECTION ANSWER + example.com. IN NS ns.example.com. + SECTION ADDITIONAL + ns.example.com. IN A 1.2.3.4 + ENTRY_END +RANGE_END + +; ns.example.com. +RANGE_BEGIN 0 10 + ADDRESS 1.2.3.4 + ; response to A query + ENTRY_BEGIN + MATCH opcode qtype qname + ADJUST copy_id + REPLY QR NOERROR + SECTION QUESTION + example.com. IN A + SECTION ANSWER + example.com. 10 IN A 5.6.7.8 + SECTION AUTHORITY + example.com. IN NS ns.example.com. + SECTION ADDITIONAL + ns.example.com. IN A 1.2.3.4 + ENTRY_END +RANGE_END + +; Query with RD flag +STEP 0 QUERY +ENTRY_BEGIN + REPLY RD + SECTION QUESTION + example.com. IN A +ENTRY_END + +; Check that we got the correct answer (should be cached) +STEP 1 CHECK_ANSWER +ENTRY_BEGIN + MATCH all ttl + REPLY QR RD RA NOERROR + SECTION QUESTION + example.com. IN A + SECTION ANSWER + example.com. 10 IN A 5.6.7.8 + SECTION AUTHORITY + example.com. IN NS ns.example.com. + SECTION ADDITIONAL + ns.example.com. IN A 1.2.3.4 +ENTRY_END + +; Wait for the TTL to expire and produce a 0 TTL cached record. +STEP 10 TIME_PASSES ELAPSE 10 + +; Query again +STEP 20 QUERY +ENTRY_BEGIN + REPLY RD DO + SECTION QUESTION + example.com. IN A +ENTRY_END + +; This should come from the cache with no prefetch triggered (earlier bug). +STEP 21 CHECK_ANSWER +ENTRY_BEGIN + MATCH all ttl + REPLY QR RD RA DO NOERROR + SECTION QUESTION + example.com. IN A + SECTION ANSWER + example.com. 0 IN A 5.6.7.8 + SECTION AUTHORITY + example.com. 3590 IN NS ns.example.com. + SECTION ADDITIONAL + ns.example.com. 3590 IN A 1.2.3.4 +ENTRY_END + +; If a prefetch triggers the test will fail with 'messages pending'. + +SCENARIO_END