From: Yuri Schaeffer Date: Fri, 24 Apr 2015 09:31:50 +0000 (+0000) Subject: Decrease TTLs in subnetcache X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c009afc1803ff10f76ea5ddb77726339c3b135f7;p=thirdparty%2Funbound.git Decrease TTLs in subnetcache git-svn-id: file:///svn/unbound/branches/edns-subnet@3413 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/edns-subnet/subnetmod.c b/edns-subnet/subnetmod.c index 2b4865a0b..07bec5168 100644 --- a/edns-subnet/subnetmod.c +++ b/edns-subnet/subnetmod.c @@ -158,6 +158,7 @@ update_cache(struct module_qstate *qstate, int id) struct slabhash *subnet_msg_cache = ((struct subnet_env*)qstate->env->modinfo[id])->subnet_msg_cache; struct edns_data *edns = &qstate->edns_client_in; + size_t i; /** We already calculated hash upon lookup */ hashvalue_t h = qstate->minfo[id] ? @@ -193,6 +194,13 @@ update_cache(struct module_qstate *qstate, int id) return; } rep = reply_info_copy(qstate->return_msg->rep, qstate->env->alloc, NULL); + + /* store RRsets */ + for(i=0; irrset_count; i++) { + rep->ref[i].key = rep->rrsets[i]; + rep->ref[i].id = rep->rrsets[i]->id; + } + reply_info_set_ttls(rep, *qstate->env->now); rep->flags |= (BIT_RA | BIT_QR); /* fix flags to be sensible for */ rep->flags &= ~(BIT_AA | BIT_CD);/* a reply based on the cache */ addrtree_insert(tree, (addrkey_t*)edns->subnet_addr, @@ -218,7 +226,6 @@ lookup_and_reply(struct module_qstate *qstate, int id) struct edns_data *edns = &qstate->edns_client_in; struct addrtree *tree; struct addrnode *node; - struct reply_info *rep; if (iq) iq->qinfo_hash = h; /** Might be useful on cache miss */ e = slabhash_lookup(sne->subnet_msg_cache, h, &qstate->qinfo, 0); @@ -236,17 +243,15 @@ lookup_and_reply(struct module_qstate *qstate, int id) lock_rw_unlock(&e->lock); return 0; } - rep = node->elem; - rep = reply_info_copy(rep, env->alloc, qstate->region); + + qstate->return_msg = tomsg(env, &qstate->qinfo, + (struct reply_info *)node->elem, qstate->region, *env->now, + env->scratch); lock_rw_unlock(&e->lock); - qstate->return_msg = (struct dns_msg*)regional_alloc( - qstate->region, sizeof(struct dns_msg)); - if (!qstate->return_msg) { - log_err("subnet: found in cache but alloc failed"); + + if (!qstate->return_msg) { /** TTL expired */ return 0; } - qstate->return_msg->rep = rep; - memcpy(&qstate->return_msg->qinfo, &qstate->qinfo, sizeof(struct query_info)); if (edns->subnet_downstream) { /* relay to interested client */ memcpy(&qstate->edns_client_out, edns, sizeof(struct edns_data)); diff --git a/services/cache/dns.c b/services/cache/dns.c index c663b8e8b..124eaebca 100644 --- a/services/cache/dns.c +++ b/services/cache/dns.c @@ -454,7 +454,11 @@ gen_dns_msg(struct regional* region, struct query_info* q, size_t num) } /** generate dns_msg from cached message */ +#ifdef CLIENT_SUBNET +struct dns_msg* +#else static struct dns_msg* +#endif tomsg(struct module_env* env, struct query_info* q, struct reply_info* r, struct regional* region, time_t now, struct regional* scratch) { diff --git a/services/cache/dns.h b/services/cache/dns.h index 05a3e6296..03da9c38a 100644 --- a/services/cache/dns.h +++ b/services/cache/dns.h @@ -125,6 +125,13 @@ struct delegpt* dns_cache_find_delegation(struct module_env* env, uint8_t* qname, size_t qnamelen, uint16_t qtype, uint16_t qclass, struct regional* region, struct dns_msg** msg, time_t timenow); +#ifdef CLIENT_SUBNET +/** generate dns_msg from cached message */ +struct dns_msg* tomsg(struct module_env* env, struct query_info* q, + struct reply_info* r, struct regional* region, time_t now, + struct regional* scratch); +#endif + /** * Find cached message * @param env: module environment with the DNS cache.