rrset.c (256281) | rrset.c (269257) |
---|---|
1/* 2 * services/cache/rrset.c - Resource record set cache. 3 * 4 * Copyright (c) 2007, NLnet Labs. All rights reserved. 5 * 6 * This software is open source. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 7 unchanged lines hidden (view full) --- 16 * this list of conditions and the following disclaimer in the documentation 17 * and/or other materials provided with the distribution. 18 * 19 * Neither the name of the NLNET LABS nor the names of its contributors may 20 * be used to endorse or promote products derived from this software without 21 * specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 1/* 2 * services/cache/rrset.c - Resource record set cache. 3 * 4 * Copyright (c) 2007, NLnet Labs. All rights reserved. 5 * 6 * This software is open source. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 7 unchanged lines hidden (view full) --- 16 * this list of conditions and the following disclaimer in the documentation 17 * and/or other materials provided with the distribution. 18 * 19 * Neither the name of the NLNET LABS nor the names of its contributors may 20 * be used to endorse or promote products derived from this software without 21 * specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE 27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 * POSSIBILITY OF SUCH DAMAGE. | 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
34 */ 35 36/** 37 * \file 38 * 39 * This file contains the rrset cache. 40 */ 41#include "config.h" 42#include "services/cache/rrset.h" | 34 */ 35 36/** 37 * \file 38 * 39 * This file contains the rrset cache. 40 */ 41#include "config.h" 42#include "services/cache/rrset.h" |
43#include "ldns/rrdef.h" |
|
43#include "util/storage/slabhash.h" 44#include "util/config_file.h" 45#include "util/data/packed_rrset.h" 46#include "util/data/msgreply.h" 47#include "util/regional.h" 48#include "util/alloc.h" 49 50void --- 64 unchanged lines hidden (view full) --- 115 lru_touch(table, &key->entry); 116 } 117 lock_rw_unlock(&key->entry.lock); 118 lock_quick_unlock(&table->lock); 119} 120 121/** see if rrset needs to be updated in the cache */ 122static int | 44#include "util/storage/slabhash.h" 45#include "util/config_file.h" 46#include "util/data/packed_rrset.h" 47#include "util/data/msgreply.h" 48#include "util/regional.h" 49#include "util/alloc.h" 50 51void --- 64 unchanged lines hidden (view full) --- 116 lru_touch(table, &key->entry); 117 } 118 lock_rw_unlock(&key->entry.lock); 119 lock_quick_unlock(&table->lock); 120} 121 122/** see if rrset needs to be updated in the cache */ 123static int |
123need_to_update_rrset(void* nd, void* cd, uint32_t timenow, int equal, int ns) | 124need_to_update_rrset(void* nd, void* cd, time_t timenow, int equal, int ns) |
124{ 125 struct packed_rrset_data* newd = (struct packed_rrset_data*)nd; 126 struct packed_rrset_data* cached = (struct packed_rrset_data*)cd; 127 /* o store if rrset has been validated 128 * everything better than bogus data 129 * secure is preferred */ 130 if( newd->security == sec_status_secure && 131 cached->security != sec_status_secure) --- 44 unchanged lines hidden (view full) --- 176 ref->key->id = newid; 177 ref->id = newid; 178 } 179 lock_rw_unlock(&ref->key->entry.lock); 180} 181 182int 183rrset_cache_update(struct rrset_cache* r, struct rrset_ref* ref, | 125{ 126 struct packed_rrset_data* newd = (struct packed_rrset_data*)nd; 127 struct packed_rrset_data* cached = (struct packed_rrset_data*)cd; 128 /* o store if rrset has been validated 129 * everything better than bogus data 130 * secure is preferred */ 131 if( newd->security == sec_status_secure && 132 cached->security != sec_status_secure) --- 44 unchanged lines hidden (view full) --- 177 ref->key->id = newid; 178 ref->id = newid; 179 } 180 lock_rw_unlock(&ref->key->entry.lock); 181} 182 183int 184rrset_cache_update(struct rrset_cache* r, struct rrset_ref* ref, |
184 struct alloc_cache* alloc, uint32_t timenow) | 185 struct alloc_cache* alloc, time_t timenow) |
185{ 186 struct lruhash_entry* e; 187 struct ub_packed_rrset_key* k = ref->key; 188 hashvalue_t h = k->entry.hash; 189 uint16_t rrset_type = ntohs(k->rk.type); 190 int equal = 0; 191 log_assert(ref->id != 0 && k->id != 0); 192 /* looks up item with a readlock - no editing! */ --- 39 unchanged lines hidden (view full) --- 232 } 233 return 1; 234 } 235 return 0; 236} 237 238struct ub_packed_rrset_key* 239rrset_cache_lookup(struct rrset_cache* r, uint8_t* qname, size_t qnamelen, | 186{ 187 struct lruhash_entry* e; 188 struct ub_packed_rrset_key* k = ref->key; 189 hashvalue_t h = k->entry.hash; 190 uint16_t rrset_type = ntohs(k->rk.type); 191 int equal = 0; 192 log_assert(ref->id != 0 && k->id != 0); 193 /* looks up item with a readlock - no editing! */ --- 39 unchanged lines hidden (view full) --- 233 } 234 return 1; 235 } 236 return 0; 237} 238 239struct ub_packed_rrset_key* 240rrset_cache_lookup(struct rrset_cache* r, uint8_t* qname, size_t qnamelen, |
240 uint16_t qtype, uint16_t qclass, uint32_t flags, uint32_t timenow, | 241 uint16_t qtype, uint16_t qclass, uint32_t flags, time_t timenow, |
241 int wr) 242{ 243 struct lruhash_entry* e; 244 struct ub_packed_rrset_key key; 245 246 key.entry.key = &key; 247 key.entry.data = NULL; 248 key.rk.dname = qname; --- 14 unchanged lines hidden (view full) --- 263 } 264 /* we're done */ 265 return (struct ub_packed_rrset_key*)e->key; 266 } 267 return NULL; 268} 269 270int | 242 int wr) 243{ 244 struct lruhash_entry* e; 245 struct ub_packed_rrset_key key; 246 247 key.entry.key = &key; 248 key.entry.data = NULL; 249 key.rk.dname = qname; --- 14 unchanged lines hidden (view full) --- 264 } 265 /* we're done */ 266 return (struct ub_packed_rrset_key*)e->key; 267 } 268 return NULL; 269} 270 271int |
271rrset_array_lock(struct rrset_ref* ref, size_t count, uint32_t timenow) | 272rrset_array_lock(struct rrset_ref* ref, size_t count, time_t timenow) |
272{ 273 size_t i; 274 for(i=0; i<count; i++) { 275 if(i>0 && ref[i].key == ref[i-1].key) 276 continue; /* only lock items once */ 277 lock_rw_rdlock(&ref[i].key->entry.lock); 278 if(ref[i].id != ref[i].key->id || timenow > 279 ((struct packed_rrset_data*)(ref[i].key->entry.data)) --- 42 unchanged lines hidden (view full) --- 322 continue; /* only touch items once */ 323 rrset_cache_touch(r, ref[i].key, h[i], ref[i].id); 324 } 325 } 326} 327 328void 329rrset_update_sec_status(struct rrset_cache* r, | 273{ 274 size_t i; 275 for(i=0; i<count; i++) { 276 if(i>0 && ref[i].key == ref[i-1].key) 277 continue; /* only lock items once */ 278 lock_rw_rdlock(&ref[i].key->entry.lock); 279 if(ref[i].id != ref[i].key->id || timenow > 280 ((struct packed_rrset_data*)(ref[i].key->entry.data)) --- 42 unchanged lines hidden (view full) --- 323 continue; /* only touch items once */ 324 rrset_cache_touch(r, ref[i].key, h[i], ref[i].id); 325 } 326 } 327} 328 329void 330rrset_update_sec_status(struct rrset_cache* r, |
330 struct ub_packed_rrset_key* rrset, uint32_t now) | 331 struct ub_packed_rrset_key* rrset, time_t now) |
331{ 332 struct packed_rrset_data* updata = 333 (struct packed_rrset_data*)rrset->entry.data; 334 struct lruhash_entry* e; 335 struct packed_rrset_data* cachedata; 336 337 /* hash it again to make sure it has a hash */ 338 rrset->entry.hash = rrset_key_hash(&rrset->rk); --- 22 unchanged lines hidden (view full) --- 361 cachedata->rr_ttl[i] = updata->rr_ttl[i]+now; 362 } 363 } 364 lock_rw_unlock(&e->lock); 365} 366 367void 368rrset_check_sec_status(struct rrset_cache* r, | 332{ 333 struct packed_rrset_data* updata = 334 (struct packed_rrset_data*)rrset->entry.data; 335 struct lruhash_entry* e; 336 struct packed_rrset_data* cachedata; 337 338 /* hash it again to make sure it has a hash */ 339 rrset->entry.hash = rrset_key_hash(&rrset->rk); --- 22 unchanged lines hidden (view full) --- 362 cachedata->rr_ttl[i] = updata->rr_ttl[i]+now; 363 } 364 } 365 lock_rw_unlock(&e->lock); 366} 367 368void 369rrset_check_sec_status(struct rrset_cache* r, |
369 struct ub_packed_rrset_key* rrset, uint32_t now) | 370 struct ub_packed_rrset_key* rrset, time_t now) |
370{ 371 struct packed_rrset_data* updata = 372 (struct packed_rrset_data*)rrset->entry.data; 373 struct lruhash_entry* e; 374 struct packed_rrset_data* cachedata; 375 376 /* hash it again to make sure it has a hash */ 377 rrset->entry.hash = rrset_key_hash(&rrset->rk); --- 39 unchanged lines hidden --- | 371{ 372 struct packed_rrset_data* updata = 373 (struct packed_rrset_data*)rrset->entry.data; 374 struct lruhash_entry* e; 375 struct packed_rrset_data* cachedata; 376 377 /* hash it again to make sure it has a hash */ 378 rrset->entry.hash = rrset_key_hash(&rrset->rk); --- 39 unchanged lines hidden --- |