From 62287e64f747b682a1d9f144180d1b46f823d11e Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Fri, 20 Jul 2007 07:14:36 +0000 Subject: [PATCH] Fill missing addresses for a delegation from the cache (if possible). git-svn-id: file:///svn/unbound/trunk@442 be551aaa-1e26-0410-a405-d3ace91eadb9 --- iterator/iterator.c | 3 +++ services/cache/dns.c | 37 +++++++++++++++++++++++++++++++++++++ services/cache/dns.h | 11 +++++++++++ 3 files changed, 51 insertions(+) diff --git a/iterator/iterator.c b/iterator/iterator.c index 44641923d..f6d6b9b9d 100644 --- a/iterator/iterator.c +++ b/iterator/iterator.c @@ -1078,6 +1078,9 @@ 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); + if(!cache_fill_missing(qstate->env, iq->qchase.qclass, + qstate->region, iq->dp)) + return error_response(qstate, id, LDNS_RCODE_SERVFAIL); delegpt_log(iq->dp); /* Count this as a referral. */ iq->referral_count++; diff --git a/services/cache/dns.c b/services/cache/dns.c index f6045fe17..00da8e0ee 100644 --- a/services/cache/dns.c +++ b/services/cache/dns.c @@ -204,6 +204,43 @@ find_add_addrs(struct module_env* env, uint16_t qclass, struct region* region, return 1; } +/** find and add A and AAAA records for missing nameservers in delegpt */ +int +cache_fill_missing(struct module_env* env, uint16_t qclass, + struct region* region, struct delegpt* dp) +{ + struct delegpt_ns* ns; + struct ub_packed_rrset_key* akey; + uint32_t now = time(NULL); + for(ns = dp->nslist; ns; ns = ns->next) { + if(ns->resolved) + continue; + akey = rrset_cache_lookup(env->rrset_cache, ns->name, + ns->namelen, LDNS_RR_TYPE_A, qclass, 0, now, 0); + if(akey) { + if(!delegpt_add_rrset_A(dp, region, akey)) { + lock_rw_unlock(&akey->entry.lock); + return 0; + } + log_nametypeclass(VERB_ALGO, "found in cache", + ns->name, LDNS_RR_TYPE_A, qclass); + lock_rw_unlock(&akey->entry.lock); + } + akey = rrset_cache_lookup(env->rrset_cache, ns->name, + ns->namelen, LDNS_RR_TYPE_AAAA, qclass, 0, now, 0); + if(akey) { + if(!delegpt_add_rrset_AAAA(dp, region, akey)) { + lock_rw_unlock(&akey->entry.lock); + return 0; + } + log_nametypeclass(VERB_ALGO, "found in cache", + ns->name, LDNS_RR_TYPE_AAAA, qclass); + lock_rw_unlock(&akey->entry.lock); + } + } + return 1; +} + /** find and add DS or NSEC to delegation msg */ static void find_add_ds(struct module_env* env, struct region* region, diff --git a/services/cache/dns.h b/services/cache/dns.h index 396b70f48..a9849d954 100644 --- a/services/cache/dns.h +++ b/services/cache/dns.h @@ -107,6 +107,17 @@ struct dns_msg* dns_cache_lookup(struct module_env* env, uint8_t* qname, size_t qnamelen, uint16_t qtype, uint16_t qclass, struct region* region, struct region* scratch); +/** + * find and add A and AAAA records for missing nameservers in delegpt + * @param env: module environment with rrset cache + * @param qclass: which class to look in. + * @param region: where to store new dp info. + * @param dp: delegation point to fill missing entries. + * @return false on alloc failure. + */ +int cache_fill_missing(struct module_env* env, uint16_t qclass, + struct region* region, struct delegpt* dp); + /** Find covering DNAME */ #endif /* SERVICES_CACHE_DNS_H */ -- 2.47.2