From efd19f766f3d056162766ebe041501cfd2ccdba2 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Tue, 23 May 2017 10:07:10 +0000 Subject: [PATCH] fix minimum ttl, verbose domain and ce determination and fix unit test qname length git-svn-id: file:///svn/unbound/trunk@4181 be551aaa-1e26-0410-a405-d3ace91eadb9 --- services/authzone.c | 28 +++++++++++++++++++++++++++- testcode/unitauth.c | 13 +++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/services/authzone.c b/services/authzone.c index 2298fc34d..e9c3e5076 100644 --- a/services/authzone.c +++ b/services/authzone.c @@ -1459,7 +1459,7 @@ az_add_negative_soa(struct auth_zone* z, struct regional* region, /* last 4 bytes are minimum ttl in network format */ if(d->count == 0) return 0; if(d->rr_len[0] < 2+4) return 0; - minimum = sldns_read_uint32(d->rr_data[0]+(d->rr_len[0]-2-4)); + minimum = sldns_read_uint32(d->rr_data[0]+(d->rr_len[0]-4)); d->ttl = (time_t)minimum; d->rr_ttl[0] = (time_t)minimum; msg->rep->ttl = get_rrset_ttl(msg->rep->rrsets[0]); @@ -2170,6 +2170,31 @@ auth_zone_generate_answer(struct auth_zone* z, struct query_info* qinfo, * to generate answers from that is above the query */ node_exists = az_find_ce(z, qinfo, node, node_exact, &ce, &rrset); + if(verbosity >= VERB_ALGO) { + char zname[256], qname[256], nname[256], cename[256], + tpstr[32], rrstr[32]; + sldns_wire2str_dname_buf(qinfo->qname, qinfo->qname_len, qname, + sizeof(qname)); + sldns_wire2str_type_buf(qinfo->qtype, tpstr, sizeof(tpstr)); + sldns_wire2str_dname_buf(z->name, z->namelen, zname, + sizeof(zname)); + if(node) + sldns_wire2str_dname_buf(node->name, node->namelen, + nname, sizeof(nname)); + else snprintf(nname, sizeof(nname), "NULL"); + if(ce) + sldns_wire2str_dname_buf(ce->name, ce->namelen, + cename, sizeof(cename)); + else snprintf(cename, sizeof(cename), "NULL"); + if(rrset) sldns_wire2str_type_buf(az_rrset_type(rrset), + rrstr, sizeof(rrstr)); + else snprintf(rrstr, sizeof(rrstr), "NULL"); + log_info("auth_zone %s query %s %s, domain %s %s %s, " + "ce %s, rrset %s", zname, qname, tpstr, nname, + (node_exact?"exact":"notexact"), + (node_exists?"exist":"notexist"), cename, rrstr); + } + if(node_exists) { /* the node is fine, generate answer from node */ return az_generate_answer_with_node(z, qinfo, region, *msg, @@ -2191,6 +2216,7 @@ int auth_zones_lookup(struct auth_zones* az, struct query_info* qinfo, z = auth_zone_find(az, dp_nm, dp_nmlen, qinfo->qclass); if(!z) { lock_rw_unlock(&az->lock); + verbose(VERB_ALGO, "no auth zone for query, fallback"); /* no auth zone, fallback to internet */ *fallback = 1; return 0; diff --git a/testcode/unitauth.c b/testcode/unitauth.c index d6908bd1d..bca2e9ddb 100644 --- a/testcode/unitauth.c +++ b/testcode/unitauth.c @@ -133,7 +133,7 @@ static const char* zone_example_com = /** queries for example.com: zone, query, flags, answer. end with NULL */ static struct q_ans example_com_queries[] = { - {"example.com", "www.example.com A", "", + {"example.com", "www.example.com. A", "", ";flags QR AA rcode NOERROR\n" ";answer section\n" "www.example.com. 3600 IN A 10.0.0.2\n" @@ -307,6 +307,7 @@ q_ans_parse(struct q_ans* q, struct regional* region, if(!*qinfo) fatal_exit("out of memory"); (*qinfo)->qname = regional_alloc_init(region, buf, dname_len); if(!(*qinfo)->qname) fatal_exit("out of memory"); + (*qinfo)->qname_len = dname_len; (*qinfo)->qtype = sldns_wirerr_get_type(buf, len, dname_len); (*qinfo)->qclass = sldns_wirerr_get_class(buf, len, dname_len); } @@ -386,8 +387,12 @@ q_ans_query(struct q_ans* q, struct auth_zones* az, struct query_info* qinfo, int ret, fallback = 0; struct dns_msg* msg = NULL; char* ans_str; + int oldv = verbosity; + /* increase verbosity to printout logic in authzone */ + if(vbmp) verbosity = 4; ret = auth_zones_lookup(az, qinfo, region, &msg, &fallback, dp_nm, dp_nmlen); + if(vbmp) verbosity = oldv; /* check the answer */ ans_str = msgtostr(msg); @@ -445,7 +450,7 @@ check_queries(const char* name, const char* zone, struct q_ans* queries) static void authzone_read_test(void) { - if(vbmp) log_info("Testing read auth zone"); + if(vbmp) printf("Testing read auth zone\n"); check_read_exact("example.com", zone_example_com); } @@ -453,7 +458,7 @@ authzone_read_test(void) static void authzone_query_test(void) { - if(vbmp) log_info("Testing query auth zone"); + if(vbmp) printf("Testing query auth zone\n"); check_queries("example.com", zone_example_com, example_com_queries); } @@ -465,5 +470,5 @@ authzone_test(void) atexit(tmpfilecleanup); authzone_read_test(); authzone_query_test(); - /* exit(0);*/ /* DEBUG */ + /*exit(0);*/ /* DEBUG */ }