]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
Fill missing addresses for a delegation from the cache (if possible).
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Fri, 20 Jul 2007 07:14:36 +0000 (07:14 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Fri, 20 Jul 2007 07:14:36 +0000 (07:14 +0000)
git-svn-id: file:///svn/unbound/trunk@442 be551aaa-1e26-0410-a405-d3ace91eadb9

iterator/iterator.c
services/cache/dns.c
services/cache/dns.h

index 44641923d5fb6a6c7a63403a186349f14d1b7c59..f6d6b9b9d041bd5e68ba79929c9303e252ed9535 100644 (file)
@@ -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++;
index f6045fe170a9eeb7eac4817988bd715324fdf9b8..00da8e0ee51e17eae4e646649612a4ea7c6de9d7 100644 (file)
@@ -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, 
index 396b70f484083ae3ada48172ec3a0d572757a98a..a9849d954ae9b432008a7297fd3f553edee0a67d 100644 (file)
@@ -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 */