]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- More predictable testing for cachedb.
authorGeorge Thessalonikefs <george@nlnetlabs.nl>
Tue, 30 May 2023 21:33:48 +0000 (23:33 +0200)
committerGeorge Thessalonikefs <george@nlnetlabs.nl>
Tue, 30 May 2023 21:33:48 +0000 (23:33 +0200)
cachedb/cachedb.c
sldns/rrdef.h
testdata/stat_values.tdir/stat_values.test

index 36995d6c569a65b14108672b673ec3f60f788ff7..f40f4e15de0dee0411cbefb398ec2c3732a2b3fd 100644 (file)
@@ -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",
index 98fb257dc8cd7986dde9c5b571a37a285e83a32d..bfe3960a6baf36b7ab1cf50dc82daabe4437ddd9 100644 (file)
@@ -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;
 
index 60b6252794ac1cdbd31f64c8fb6d271081b0cad1..ca19a38271f855bff949eac0ff0c2dd330a72c2f 100644 (file)
@@ -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