- Add test for cachedb serve expired.

This commit is contained in:
W.C.A. Wijngaards
2024-04-10 12:36:21 +02:00
parent cccf5e73c0
commit b990be88ef
7 changed files with 310 additions and 4 deletions
+31
View File
@@ -52,6 +52,7 @@
#include "util/data/msgreply.h"
#include "util/data/msgencode.h"
#include "util/data/dname.h"
#include "util/storage/slabhash.h"
#include "util/edns.h"
#include "util/config_file.h"
#include "services/listen_dnsport.h"
@@ -65,6 +66,7 @@
#include "sldns/wire2str.h"
#include "sldns/str2wire.h"
#include "daemon/remote.h"
#include "daemon/daemon.h"
#include "util/timeval_func.h"
#include <signal.h>
struct worker;
@@ -154,6 +156,7 @@ repevt_string(enum replay_event_type t)
case repevt_assign: return "ASSIGN";
case repevt_traffic: return "TRAFFIC";
case repevt_infra_rtt: return "INFRA_RTT";
case repevt_flush_message: return "FLUSH_MESSAGE";
default: return "UNKNOWN";
}
}
@@ -691,6 +694,30 @@ do_infra_rtt(struct replay_runtime* runtime)
free(dp);
}
/** Flush message from message cache. */
static void
do_flush_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;
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("remove 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);
slabhash_remove(runtime->daemon->env->msg_cache, h, &k);
}
/** perform exponential backoff on the timeout */
static void
expon_timeout_backoff(struct replay_runtime* runtime)
@@ -796,6 +823,10 @@ do_moment_and_advance(struct replay_runtime* runtime)
do_infra_rtt(runtime);
advance_moment(runtime);
break;
case repevt_flush_message:
do_flush_message(runtime);
advance_moment(runtime);
break;
default:
fatal_exit("testbound: unknown event type %d",
runtime->now->evt_type);
+7
View File
@@ -348,6 +348,13 @@ replay_moment_read(char* remain, FILE* in, const char* name,
mom->string = strdup(m);
if(!mom->string) fatal_exit("out of memory");
if(!mom->variable) fatal_exit("out of memory");
} else if(parse_keyword(&remain, "FLUSH_MESSAGE")) {
mom->evt_type = repevt_flush_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);
+6
View File
@@ -85,6 +85,7 @@
* The file contents is macro expanded before match.
* 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 ERROR
* ; following entry starts on the next line, ENTRY_BEGIN.
* ; more STEP items
@@ -148,6 +149,7 @@ struct fake_timer;
struct replay_var;
struct infra_cache;
struct sldns_buffer;
struct daemon;
/**
* A replay scenario.
@@ -212,6 +214,8 @@ struct replay_moment {
repevt_assign,
/** store infra rtt cache entry: addr and string (int) */
repevt_infra_rtt,
/** flush message cache entry */
repevt_flush_message,
/** cause traffic to flow */
repevt_traffic
}
@@ -297,6 +301,8 @@ struct replay_runtime {
/** ref the infra cache (was passed to outside_network_create) */
struct infra_cache* infra;
/** the daemon structure passed in worker call to remote accept open */
struct daemon* daemon;
/** the current time in seconds */
time_t now_secs;
+4 -2
View File
@@ -48,6 +48,7 @@
#include "testcode/fake_event.h"
#include "daemon/remote.h"
#include "libunbound/worker.h"
#include "daemon/worker.h"
#include "util/config_file.h"
#include "sldns/keyraw.h"
#ifdef UB_ON_WINDOWS
@@ -532,9 +533,10 @@ void daemon_remote_clear(struct daemon_remote* ATTR_UNUSED(rc))
}
int daemon_remote_open_accept(struct daemon_remote* ATTR_UNUSED(rc),
struct listen_port* ATTR_UNUSED(ports),
struct worker* ATTR_UNUSED(worker))
struct listen_port* ATTR_UNUSED(ports), struct worker* worker)
{
struct replay_runtime* runtime = (struct replay_runtime*)worker->base;
runtime->daemon = worker->daemon;
return 1;
}