From: George Thessalonikefs Date: Tue, 30 May 2023 21:33:48 +0000 (+0200) Subject: - More predictable testing for cachedb. X-Git-Tag: release-1.18.0rc1~24^2~24^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3c3fd7a795698bbae764167653d06d62e1d4e420;p=thirdparty%2Funbound.git - More predictable testing for cachedb. --- diff --git a/cachedb/cachedb.c b/cachedb/cachedb.c index 36995d6c5..f40f4e15d 100644 --- a/cachedb/cachedb.c +++ b/cachedb/cachedb.c @@ -111,6 +111,15 @@ testframe_init(struct module_env* env, struct cachedb_env* cachedb_env) log_err("out of memory"); return 0; } + /* Register an EDNS option (65534) to bypass the worker cache lookup + * for testing */ + if(!edns_register_option(LDNS_EDNS_UNBOUND_CACHEDB_TESTFRAME_TEST, + 1 /* bypass cache */, + 0 /* no aggregation */, env)) { + log_err("testframe_init, could not register test opcode"); + free(d); + return 0; + } lock_basic_init(&d->lock); lock_protect(&d->lock, d, sizeof(*d)); return 1; @@ -627,11 +636,15 @@ cachedb_extcache_store(struct module_qstate* qstate, struct cachedb_env* ie) * See if unbound's internal cache can answer the query */ static int -cachedb_intcache_lookup(struct module_qstate* qstate) +cachedb_intcache_lookup(struct module_qstate* qstate, struct cachedb_env* cde) { uint8_t* dpname=NULL; size_t dpnamelen=0; struct dns_msg* msg; + /* for testframe bypass this lookup */ + if(cde->backend == &testframe_backend) { + return 0; + } if(iter_stub_fwd_no_cache(qstate, &qstate->qinfo, &dpname, &dpnamelen)) return 0; /* no cache for these queries */ @@ -707,7 +720,7 @@ cachedb_handle_query(struct module_qstate* qstate, /* lookup inside unbound's internal cache. * This does not look for expired entries. */ - if(cachedb_intcache_lookup(qstate)) { + if(cachedb_intcache_lookup(qstate, ie)) { if(verbosity >= VERB_ALGO) { if(qstate->return_msg->rep) log_dns_msg("cachedb internal cache lookup", diff --git a/sldns/rrdef.h b/sldns/rrdef.h index 98fb257dc..bfe3960a6 100644 --- a/sldns/rrdef.h +++ b/sldns/rrdef.h @@ -436,7 +436,8 @@ enum sldns_enum_edns_option LDNS_EDNS_KEEPALIVE = 11, /* draft-ietf-dnsop-edns-tcp-keepalive*/ LDNS_EDNS_PADDING = 12, /* RFC7830 */ LDNS_EDNS_EDE = 15, /* RFC8914 */ - LDNS_EDNS_CLIENT_TAG = 16 /* draft-bellis-dnsop-edns-tags-01 */ + LDNS_EDNS_CLIENT_TAG = 16, /* draft-bellis-dnsop-edns-tags-01 */ + LDNS_EDNS_UNBOUND_CACHEDB_TESTFRAME_TEST = 65534 }; typedef enum sldns_enum_edns_option sldns_edns_option; diff --git a/testdata/stat_values.tdir/stat_values.test b/testdata/stat_values.tdir/stat_values.test index 60b625279..ca19a3827 100644 --- a/testdata/stat_values.tdir/stat_values.test +++ b/testdata/stat_values.tdir/stat_values.test @@ -50,7 +50,7 @@ FILTERED_STATS_FILE=filtered_stats.$$ FOUND_STATS_FILE=found_stats.$$ REST_STATS_FILE=rest_stats.$$ -DEBUG=1 +DEBUG=0 # Write stats to $STATS_FILE. # Call this when you want to get stats from unbound. @@ -95,7 +95,7 @@ check_expected_stats () { else echo "! bad expected stats:" cat $FILTERED_STATS_FILE - exit 1 + end 1 fi } @@ -109,7 +109,7 @@ check_rest_stats () { fi if grep -v "=0$" $REST_STATS_FILE; then echo "! bad rest stats" - exit 1 + end 1 else echo "OK" fi @@ -426,9 +426,9 @@ wait_unbound_up unbound.log echo echo "[ Check cachedb cache miss. ]" echo "> dig www.example.com." -dig @127.0.0.1 -p $UNBOUND_PORT 0ttl.example.com. | tee outfile +dig @127.0.0.1 +ednsopt=65534 -p $UNBOUND_PORT www.example.com. | tee outfile echo "> check answer" -if grep "0.0.0.1" outfile; then +if grep "10.20.30.40" outfile; then echo "OK" else end 1 @@ -446,7 +446,7 @@ num.query.flags.AD=1 num.query.edns.present=1 num.query.udpout=1 num.query.cachedb=0 -msg.cache.count=0 +msg.cache.count=1 rrset.cache.count=1 infra.cache.count=1 num.answer.rcode.NOERROR=1" @@ -454,9 +454,9 @@ num.answer.rcode.NOERROR=1" echo echo "[ Check cachedb cache hit. ]" echo "> dig www.example.com." -dig @127.0.0.1 -p $UNBOUND_PORT 0ttl.example.com. | tee outfile +dig @127.0.0.1 +ednsopt=65534 -p $UNBOUND_PORT www.example.com. | tee outfile echo "> check answer" -if grep "0.0.0.1" outfile; then +if grep "10.20.30.40" outfile; then echo "OK" else end 1 @@ -482,25 +482,25 @@ num.answer.rcode.NOERROR=1" echo echo "[ Check cachedb cache hit with stat reset ]" echo "> dig www.example.com." -dig @127.0.0.1 -p $UNBOUND_PORT 0ttl.example.com. | tee outfile +dig @127.0.0.1 +ednsopt=65534 -p $UNBOUND_PORT www.example.com. | tee outfile echo "> check answer" -if grep "0.0.0.1" outfile; then +if grep "10.20.30.40" outfile; then echo "OK" else end 1 fi check_stats "\ total.num.queries=1 -total.num.cachemiss=0 -total.num.cachehits=1 -total.num.recursivereplies=0 +total.num.cachemiss=1 +total.num.cachehits=0 +total.num.recursivereplies=1 num.query.type.A=1 num.query.class.IN=1 num.query.opcode.QUERY=1 num.query.flags.RD=1 num.query.flags.AD=1 num.query.edns.present=1 -num.query.cachedb=0 +num.query.cachedb=1 msg.cache.count=1 rrset.cache.count=1 infra.cache.count=1