]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Extended test for cachedb serve expired.
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Wed, 10 Apr 2024 11:08:23 +0000 (13:08 +0200)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Wed, 10 Apr 2024 11:08:23 +0000 (13:08 +0200)
doc/Changelog
testcode/fake_event.c
testcode/replay.c
testcode/replay.h
testdata/cachedb_expired.crpl

index c28d2517cfd9a5c5c02e3538a498366efa65a81c..7cda9db83768da06185387d71ebda9bd7cce18e9 100644 (file)
@@ -4,6 +4,7 @@
          checks cachedb before serving the expired response.
        - Fixup compile without cachedb.
        - Add test for cachedb serve expired.
+       - Extended test for cachedb serve expired.
 
 9 April 2024: Yorgos
        - Merge #1043 from xiaoxiaoafeifei: Add loongarch support; updates
index 053f88569fc9f91a0c196d5344a48af20449da86..09269289dd440bb8bd7434c1875fe8d617d4e758 100644 (file)
@@ -157,6 +157,7 @@ repevt_string(enum replay_event_type t)
        case repevt_traffic:     return "TRAFFIC";
        case repevt_infra_rtt:   return "INFRA_RTT";
        case repevt_flush_message: return "FLUSH_MESSAGE";
+       case repevt_expire_message: return "EXPIRE_MESSAGE";
        default:                 return "UNKNOWN";
        }
 }
@@ -718,6 +719,42 @@ do_flush_message(struct replay_runtime* runtime)
        slabhash_remove(runtime->daemon->env->msg_cache, h, &k);
 }
 
+/** Expire message from message cache. */
+static void
+do_expire_message(struct replay_runtime* runtime)
+{
+       struct replay_moment* now = runtime->now;
+       uint8_t rr[1024];
+       size_t rr_len = sizeof(rr), dname_len = 0;
+       hashvalue_type h;
+       struct query_info k;
+       struct lruhash_entry* e;
+
+       if(sldns_str2wire_rr_question_buf(now->string, rr, &rr_len,
+               &dname_len, NULL, 0, NULL, 0) != 0)
+               fatal_exit("could not parse '%s'", now->string);
+
+       log_info("expire message %s", now->string);
+       k.qname = rr;
+       k.qname_len = dname_len;
+       k.qtype = sldns_wirerr_get_type(rr, rr_len, dname_len);
+       k.qclass = sldns_wirerr_get_class(rr, rr_len, dname_len);
+       k.local_alias = NULL;
+       h = query_info_hash(&k, 0);
+
+       e = slabhash_lookup(runtime->daemon->env->msg_cache, h, &k, 0);
+       if(e) {
+               struct msgreply_entry* msg = (struct msgreply_entry*)e->key;
+               struct reply_info* rep = (struct reply_info*)msg->entry.data;
+               time_t expired = runtime->now_secs;
+               expired -= 3;
+               rep->ttl = expired;
+               rep->prefetch_ttl = expired;
+               rep->serve_expired_ttl = expired;
+               lock_rw_unlock(&msg->entry.lock);
+       }
+}
+
 /** perform exponential backoff on the timeout */
 static void
 expon_timeout_backoff(struct replay_runtime* runtime)
@@ -827,6 +864,10 @@ do_moment_and_advance(struct replay_runtime* runtime)
                do_flush_message(runtime);
                advance_moment(runtime);
                break;
+       case repevt_expire_message:
+               do_expire_message(runtime);
+               advance_moment(runtime);
+               break;
        default:
                fatal_exit("testbound: unknown event type %d",
                        runtime->now->evt_type);
index 813e74ca4be32b24ba9bb307cc2c790eaef4c58d..95dde405f6419dcabcf5aca174d8090170cdb920 100644 (file)
@@ -355,6 +355,13 @@ replay_moment_read(char* remain, FILE* in, const char* name,
                strip_end_white(remain);
                mom->string = strdup(remain);
                if(!mom->string) fatal_exit("out of memory");
+       } else if(parse_keyword(&remain, "EXPIRE_MESSAGE")) {
+               mom->evt_type = repevt_expire_message;
+               while(isspace((unsigned char)*remain))
+                       remain++;
+               strip_end_white(remain);
+               mom->string = strdup(remain);
+               if(!mom->string) fatal_exit("out of memory");
        } else {
                log_err("%d: unknown event type %s", pstate->lineno, remain);
                free(mom);
index 5f5d410b8f1e48882ccfecacfae68f68fdc1163e..809e8ee397780d005ebe6e349709a08b92993780 100644 (file)
@@ -86,6 +86,7 @@
  *     o CHECK_TEMPFILE [fname] - followed by FILE_BEGIN [to match] FILE_END
  *     o INFRA_RTT [ip] [dp] [rtt] - update infra cache entry with rtt.
  *     o FLUSH_MESSAGE name type class - flushes entry in message cache.
+ *     o EXPIRE_MESSAGE name type class - expires entry in message cache.
  *     o ERROR
  * ; following entry starts on the next line, ENTRY_BEGIN.
  * ; more STEP items
@@ -216,6 +217,8 @@ struct replay_moment {
                repevt_infra_rtt,
                /** flush message cache entry */
                repevt_flush_message,
+               /** expire message cache entry */
+               repevt_expire_message,
                /** cause traffic to flow */
                repevt_traffic
        }
index 8f9c126942e724c3f7d162dd855b8e956d4af13d..60fdba7dcec343ba4b16a56233433ad51e0c3118 100644 (file)
@@ -19,7 +19,7 @@ CONFIG_END
 SCENARIO_BEGIN Test cachedb and serve expired.
 
 ; K.ROOT-SERVERS.NET.
-RANGE_BEGIN 0 300
+RANGE_BEGIN 0 400
        ADDRESS 193.0.14.129
 ENTRY_BEGIN
 MATCH opcode qtype qname
@@ -47,7 +47,7 @@ ENTRY_END
 RANGE_END
 
 ; a.gtld-servers.net.
-RANGE_BEGIN 0 300
+RANGE_BEGIN 0 400
        ADDRESS 192.5.6.30
 ENTRY_BEGIN
 MATCH opcode subdomain
@@ -73,7 +73,7 @@ ENTRY_END
 RANGE_END
 
 ; ns2.example.com.
-RANGE_BEGIN 0 300
+RANGE_BEGIN 0 400
        ADDRESS 1.2.3.5
 ENTRY_BEGIN
 MATCH opcode qname qtype
@@ -256,4 +256,69 @@ SECTION ANSWER
 www.example.com. 10 IN A 1.2.3.4
 ENTRY_END
 
+; expire the entry in cache
+STEP 220 EXPIRE_MESSAGE www.example.com. IN A
+
+; cache is expired, cachedb valid
+STEP 230 QUERY
+ENTRY_BEGIN
+REPLY RD
+SECTION QUESTION
+www.example.com. IN A
+ENTRY_END
+
+STEP 240 CHECK_ANSWER
+ENTRY_BEGIN
+MATCH all ttl
+REPLY QR RD RA NOERROR
+SECTION QUESTION
+www.example.com. IN A
+SECTION ANSWER
+www.example.com. 10 IN A 1.2.3.4
+ENTRY_END
+
+; it is now expired
+STEP 250 TIME_PASSES ELAPSE 20
+; expire the entry in cache
+STEP 260 EXPIRE_MESSAGE www.example.com. IN A
+
+; cache is expired, cachedb is expired
+STEP 270 QUERY
+ENTRY_BEGIN
+REPLY RD
+SECTION QUESTION
+www.example.com. IN A
+ENTRY_END
+
+STEP 280 CHECK_ANSWER
+ENTRY_BEGIN
+MATCH all ttl
+REPLY QR RD RA NOERROR
+SECTION QUESTION
+www.example.com. IN A
+SECTION ANSWER
+www.example.com. 0 IN A 1.2.3.4
+ENTRY_END
+
+STEP 290 TRAFFIC
+; the expired message is updated.
+
+; cache is valid, cachedb is valid
+STEP 300 QUERY
+ENTRY_BEGIN
+REPLY RD
+SECTION QUESTION
+www.example.com. IN A
+ENTRY_END
+
+STEP 310 CHECK_ANSWER
+ENTRY_BEGIN
+MATCH all ttl
+REPLY QR RD RA NOERROR
+SECTION QUESTION
+www.example.com. IN A
+SECTION ANSWER
+www.example.com. 10 IN A 1.2.3.4
+ENTRY_END
+
 SCENARIO_END