From aaec3572e4de2faf2a33074b7b9be05ad9332339 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Tue, 5 Jun 2007 15:04:01 +0000 Subject: [PATCH] debug work. git-svn-id: file:///svn/unbound/trunk@371 be551aaa-1e26-0410-a405-d3ace91eadb9 --- daemon/worker.c | 7 +++++++ doc/Changelog | 4 ++++ iterator/iter_delegpt.c | 2 +- iterator/iter_resptype.c | 2 +- iterator/iter_scrub.c | 18 ++++++++++-------- iterator/iter_utils.c | 10 ++++++++-- iterator/iterator.c | 4 ++++ testcode/unitdname.c | 37 +++++++++++++++++++++++++++++++++++++ util/alloc.c | 1 + util/data/packed_rrset.c | 2 +- util/net_help.c | 20 ++++++++++++++++---- 11 files changed, 90 insertions(+), 17 deletions(-) diff --git a/daemon/worker.c b/daemon/worker.c index d9e74f805..e1abbe519 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -215,9 +215,12 @@ static struct module_qstate* find_run_in(struct module_qstate* p) { struct module_qstate* q; + log_nametypeclass("find run in", p->qinfo.qname, p->qinfo.qtype, p->qinfo.qclass); for(p = p->subquery_first; p; p = p->subquery_next) { + log_nametypeclass("find run passed", p->qinfo.qname, p->qinfo.qtype, p->qinfo.qclass); if(p->ext_state[p->curmod] == module_state_initial) return p; + log_nametypeclass("find run morepass", p->qinfo.qname, p->qinfo.qtype, p->qinfo.qclass); if((q=find_run_in(p))) return q; } @@ -229,6 +232,7 @@ static struct module_qstate* find_runnable(struct module_qstate* subq) { struct module_qstate* p = subq; + log_info("find runnable"); if(p->subquery_next && p->subquery_next->ext_state[ p->subquery_next->curmod] == module_state_initial) return p->subquery_next; @@ -256,6 +260,8 @@ worker_process_query(struct worker* worker, struct work_query* w, region_free_all(worker->scratchpad); qstate->reply = NULL; s = qstate->ext_state[qstate->curmod]; + log_info("worker_process_query: module exit state is %s", + strextstate(s)); /* examine results, start further modules, etc. */ if(s == module_wait_subquery) { if(!qstate->subquery_first) { @@ -295,6 +301,7 @@ worker_process_query(struct worker* worker, struct work_query* w, qstate = nxt; entry = NULL; event = module_event_pass; + continue; } } break; diff --git a/doc/Changelog b/doc/Changelog index ab1f4f7b8..191367c7a 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -7,6 +7,10 @@ - priming gives LAME result, returns SERVFAIL. - debug routine to print dns_msg as handled by iterator. - memleak in config file stubs fixup. + - more small bugs, in scrubber, query compare no ID for lookup, + in dname validation for NS targets. + - sets entry.key for new special allocs. + - lognametypeclass can display unknown types and classes. 4 June 2007: Wouter - random selection of equally preferred nameserver targets. diff --git a/iterator/iter_delegpt.c b/iterator/iter_delegpt.c index d06293fe2..db907946e 100644 --- a/iterator/iter_delegpt.c +++ b/iterator/iter_delegpt.c @@ -262,7 +262,7 @@ delegpt_rrset_add_ns(struct delegpt* dp, struct region* region, for(i=0; icount; i++) { if(nsdata->rr_len[i] < 2+1) continue; /* len + root label */ if(dname_valid(nsdata->rr_data[i]+2, nsdata->rr_len[i]-2) != - (size_t)ldns_read_uint16(nsdata->rr_data[i])-2) + (size_t)ldns_read_uint16(nsdata->rr_data[i])) continue; /* bad format */ /* add rdata of NS (= wirefmt dname), skip rdatalen bytes */ if(!delegpt_add_ns(dp, region, nsdata->rr_data[i]+2)) diff --git a/iterator/iter_resptype.c b/iterator/iter_resptype.c index a61fa0a92..fc2d7031b 100644 --- a/iterator/iter_resptype.c +++ b/iterator/iter_resptype.c @@ -190,7 +190,7 @@ response_type_from_server(struct dns_msg* msg, struct query_info* request, /* If we are getting an NS set for the zone we * thought we were contacting, then it is an answer.*/ /* FIXME: is this correct? */ - if(query_dname_compare(s->rk.dname, origzone)) { + if(query_dname_compare(s->rk.dname, origzone) == 0) { return RESPONSE_TYPE_ANSWER; } /* If we are getting a referral upwards (or to diff --git a/iterator/iter_scrub.c b/iterator/iter_scrub.c index bedce57f0..3ae248f78 100644 --- a/iterator/iter_scrub.c +++ b/iterator/iter_scrub.c @@ -277,20 +277,21 @@ synth_cname_rrset(uint8_t** sname, size_t* snamelen, uint8_t* alias, static int pkt_strict_sub(ldns_buffer* pkt, uint8_t* sname, uint8_t* dr) { - uint8_t buf[LDNS_MAX_DOMAINLEN+1]; - /* decompress DNAME name */ - dname_pkt_copy(pkt, buf, dr); - return dname_strict_subdomain_c(sname, buf); + uint8_t buf1[LDNS_MAX_DOMAINLEN+1]; + uint8_t buf2[LDNS_MAX_DOMAINLEN+1]; + /* decompress names */ + dname_pkt_copy(pkt, buf1, sname); + dname_pkt_copy(pkt, buf2, dr); + return dname_strict_subdomain_c(buf1, buf2); } /** check subdomain with decompression */ static int -pkt_sub(ldns_buffer* pkt, uint8_t* sname, uint8_t* dr) +pkt_sub(ldns_buffer* pkt, uint8_t* comprname, uint8_t* zone) { uint8_t buf[LDNS_MAX_DOMAINLEN+1]; - /* decompress DNAME name */ - dname_pkt_copy(pkt, buf, dr); - return dname_subdomain_c(sname, buf); + dname_pkt_copy(pkt, buf, comprname); + return dname_subdomain_c(buf, zone); } /** @@ -452,6 +453,7 @@ scrub_sanitize(ldns_buffer* pkt, struct msg_parse* msg, uint8_t* zonename) struct rrset_parse* rrset, *prev; prev = NULL; rrset = msg->rrset_first; + log_nametypeclass("sanitize for", zonename, 0, 0); /* At this point, we brutally remove ALL rrsets that aren't * children of the originating zone. The idea here is that, diff --git a/iterator/iter_utils.c b/iterator/iter_utils.c index 83eaa2186..94fb6ec98 100644 --- a/iterator/iter_utils.c +++ b/iterator/iter_utils.c @@ -247,15 +247,21 @@ iter_dns_store(struct module_env* env, struct dns_msg* msg, int is_referral) /* store rrsets */ struct rrset_ref ref; uint32_t now = time(NULL); - size_t i; - reply_info_set_ttls(rep, now); + size_t i, j; for(i=0; irrset_count; i++) { + /* fixup rrset ttl */ + struct packed_rrset_data* data = (struct + packed_rrset_data*)rep->rrsets[i]->entry.data; + data->ttl += now; + for(j=0; jcount + data->rrsig_count; j++) + data->rr_ttl[j] += now; ref.key = rep->rrsets[i]; ref.id = rep->rrsets[i]->id; /*ignore ret: it was in the cache, ref updated */ (void)rrset_cache_update(env->rrset_cache, &ref, env->alloc, now); } + free(rep); return 1; } else { /* store msg, and rrsets */ diff --git a/iterator/iterator.c b/iterator/iterator.c index e84aed2b4..da9f8e99b 100644 --- a/iterator/iterator.c +++ b/iterator/iterator.c @@ -870,6 +870,8 @@ generate_target_query(struct module_qstate* qstate, struct iter_qstate* iq, free(subq); return 0; } + log_nametypeclass("new target", name, qtype, qclass); + delegpt_log(subiq->dp); return 1; } @@ -1141,6 +1143,7 @@ processQueryResponse(struct module_qstate* qstate, struct iter_qstate* iq, iq->dp = delegpt_from_message(iq->response, qstate->region); if(!iq->dp) return error_response(qstate, id, LDNS_RCODE_SERVFAIL); + delegpt_log(iq->dp); iq->num_current_queries = 0; iq->num_target_queries = -1; /* Count this as a referral. */ @@ -1258,6 +1261,7 @@ processPrimeResponse(struct module_qstate* qstate, struct iter_qstate* iq, log_nametypeclass("priming successful for", qstate->qinfo.qname, qstate->qinfo.qtype, qstate->qinfo.qclass); + delegpt_log(dp); foriq = (struct iter_qstate*)forq->minfo[id]; foriq->dp = dp; foriq->response = dns_copy_msg(iq->response, forq->region); diff --git a/testcode/unitdname.c b/testcode/unitdname.c index 8789d2b66..4473c40a8 100644 --- a/testcode/unitdname.c +++ b/testcode/unitdname.c @@ -361,6 +361,42 @@ dname_test_dname_lab_cmp() unit_assert(ml == 4); } +/** test dname_subdomain_c */ +static void +dname_test_subdomain() +{ + unit_assert(dname_subdomain_c( + (uint8_t*)"", + (uint8_t*)"")); + unit_assert(dname_subdomain_c( + (uint8_t*)"\003com", + (uint8_t*)"")); + unit_assert(!dname_subdomain_c( + (uint8_t*)"", + (uint8_t*)"\003com")); + unit_assert(dname_subdomain_c( + (uint8_t*)"\007example\003com", + (uint8_t*)"\003com")); + unit_assert(!dname_subdomain_c( + (uint8_t*)"\003com", + (uint8_t*)"\007example\003com")); + unit_assert(dname_subdomain_c( + (uint8_t*)"\007example\003com", + (uint8_t*)"")); + unit_assert(!dname_subdomain_c( + (uint8_t*)"\003net", + (uint8_t*)"\003com")); + unit_assert(!dname_subdomain_c( + (uint8_t*)"\003net", + (uint8_t*)"\003org")); + unit_assert(!dname_subdomain_c( + (uint8_t*)"\007example\003net", + (uint8_t*)"\003org")); + unit_assert(!dname_subdomain_c( + (uint8_t*)"\003net", + (uint8_t*)"\007example\003org")); +} + /** test dname_strict_subdomain */ static void dname_test_strict_subdomain() @@ -409,5 +445,6 @@ void dname_test() dname_test_dname_lab_cmp(); dname_test_pkt_dname_len(buff); dname_test_strict_subdomain(); + dname_test_subdomain(); ldns_buffer_free(buff); } diff --git a/util/alloc.c b/util/alloc.c index 3e25fbde8..cdebd3c52 100644 --- a/util/alloc.c +++ b/util/alloc.c @@ -52,6 +52,7 @@ alloc_setup_special(alloc_special_t* t) { memset(t, 0, sizeof(*t)); lock_rw_init(&t->entry.lock); + t->entry.key = t; } /** prealloc some entries in the cache. To minimize contention. diff --git a/util/data/packed_rrset.c b/util/data/packed_rrset.c index 1f2805764..dc1099b30 100644 --- a/util/data/packed_rrset.c +++ b/util/data/packed_rrset.c @@ -93,7 +93,7 @@ ub_rrset_compare(void* k1, void* k2) struct ub_packed_rrset_key* key1 = (struct ub_packed_rrset_key*)k1; struct ub_packed_rrset_key* key2 = (struct ub_packed_rrset_key*)k2; int c; - if(key1 == key2 || key1->id == key2->id) + if(key1 == key2) return 0; if(key1->rk.type != key2->rk.type) { if(key1->rk.type < key2->rk.type) diff --git a/util/net_help.c b/util/net_help.c index d0f1790f9..10e258a46 100644 --- a/util/net_help.c +++ b/util/net_help.c @@ -183,11 +183,23 @@ log_nametypeclass(const char* str, uint8_t* name, uint16_t type, uint16_t dclass) { char buf[LDNS_MAX_DOMAINLEN+1]; + char t[12], c[12]; + const char *ts, *cs; dname_str(name, buf); - log_info("%s <%s %s %s>", str, buf, - ldns_rr_descript(type)?ldns_rr_descript(type)->_name: "??", - ldns_lookup_by_id(ldns_rr_classes, (int)dclass)? - ldns_lookup_by_id(ldns_rr_classes, (int)dclass)->name:"??"); + if(ldns_rr_descript(type) && ldns_rr_descript(type)->_name) + ts = ldns_rr_descript(type)->_name; + else { + snprintf(t, 12, "TYPE%d", (int)type); + ts = t; + } + if(ldns_lookup_by_id(ldns_rr_classes, (int)dclass) && + ldns_lookup_by_id(ldns_rr_classes, (int)dclass)->name) + cs = ldns_lookup_by_id(ldns_rr_classes, (int)dclass)->name; + else { + snprintf(c, 12, "CLASS%d", (int)dclass); + cs = c; + } + log_info("%s <%s %s %s>", str, buf, ts, cs); } int