Deleted Added
sdiff udiff text old ( 256281 ) new ( 269257 )
full compact
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.
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 "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
123need_to_update_rrset(void* nd, void* cd, uint32_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,
184 struct alloc_cache* alloc, uint32_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,
240 uint16_t qtype, uint16_t qclass, uint32_t flags, uint32_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
271rrset_array_lock(struct rrset_ref* ref, size_t count, uint32_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,
330 struct ub_packed_rrset_key* rrset, uint32_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,
369 struct ub_packed_rrset_key* rrset, uint32_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 ---