Deleted Added
full compact
infra.c (256281) infra.c (269257)
1/*
2 * services/cache/infra.c - infrastructure cache, server rtt and capabilities
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/infra.c - infrastructure cache, server rtt and capabilities
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 infrastructure cache.
40 */
41#include "config.h"
34 */
35
36/**
37 * \file
38 *
39 * This file contains the infrastructure cache.
40 */
41#include "config.h"
42#include <ldns/rr.h>
42#include "ldns/rrdef.h"
43#include "services/cache/infra.h"
44#include "util/storage/slabhash.h"
45#include "util/storage/lookup3.h"
46#include "util/data/dname.h"
47#include "util/log.h"
48#include "util/net_help.h"
49#include "util/config_file.h"
50#include "iterator/iterator.h"

--- 133 unchanged lines hidden (view full) ---

184 k.entry.key = (void*)&k;
185 k.entry.data = NULL;
186 return slabhash_lookup(infra->hosts, k.entry.hash, &k, wr);
187}
188
189/** init the data elements */
190static void
191data_entry_init(struct infra_cache* infra, struct lruhash_entry* e,
43#include "services/cache/infra.h"
44#include "util/storage/slabhash.h"
45#include "util/storage/lookup3.h"
46#include "util/data/dname.h"
47#include "util/log.h"
48#include "util/net_help.h"
49#include "util/config_file.h"
50#include "iterator/iterator.h"

--- 133 unchanged lines hidden (view full) ---

184 k.entry.key = (void*)&k;
185 k.entry.data = NULL;
186 return slabhash_lookup(infra->hosts, k.entry.hash, &k, wr);
187}
188
189/** init the data elements */
190static void
191data_entry_init(struct infra_cache* infra, struct lruhash_entry* e,
192 uint32_t timenow)
192 time_t timenow)
193{
194 struct infra_data* data = (struct infra_data*)e->data;
195 data->ttl = timenow + infra->host_ttl;
196 rtt_init(&data->rtt);
197 data->edns_version = 0;
198 data->edns_lame_known = 0;
199 data->probedelay = 0;
200 data->isdnsseclame = 0;

--- 12 unchanged lines hidden (view full) ---

213 * @param addrlen: length of addr.
214 * @param name: name of zone
215 * @param namelen: length of name.
216 * @param tm: time now.
217 * @return: the new entry or NULL on malloc failure.
218 */
219static struct lruhash_entry*
220new_entry(struct infra_cache* infra, struct sockaddr_storage* addr,
193{
194 struct infra_data* data = (struct infra_data*)e->data;
195 data->ttl = timenow + infra->host_ttl;
196 rtt_init(&data->rtt);
197 data->edns_version = 0;
198 data->edns_lame_known = 0;
199 data->probedelay = 0;
200 data->isdnsseclame = 0;

--- 12 unchanged lines hidden (view full) ---

213 * @param addrlen: length of addr.
214 * @param name: name of zone
215 * @param namelen: length of name.
216 * @param tm: time now.
217 * @return: the new entry or NULL on malloc failure.
218 */
219static struct lruhash_entry*
220new_entry(struct infra_cache* infra, struct sockaddr_storage* addr,
221 socklen_t addrlen, uint8_t* name, size_t namelen, uint32_t tm)
221 socklen_t addrlen, uint8_t* name, size_t namelen, time_t tm)
222{
223 struct infra_data* data;
224 struct infra_key* key = (struct infra_key*)malloc(sizeof(*key));
225 if(!key)
226 return NULL;
227 data = (struct infra_data*)malloc(sizeof(struct infra_data));
228 if(!data) {
229 free(key);

--- 13 unchanged lines hidden (view full) ---

243 key->addrlen = addrlen;
244 memcpy(&key->addr, addr, addrlen);
245 data_entry_init(infra, &key->entry, tm);
246 return &key->entry;
247}
248
249int
250infra_host(struct infra_cache* infra, struct sockaddr_storage* addr,
222{
223 struct infra_data* data;
224 struct infra_key* key = (struct infra_key*)malloc(sizeof(*key));
225 if(!key)
226 return NULL;
227 data = (struct infra_data*)malloc(sizeof(struct infra_data));
228 if(!data) {
229 free(key);

--- 13 unchanged lines hidden (view full) ---

243 key->addrlen = addrlen;
244 memcpy(&key->addr, addr, addrlen);
245 data_entry_init(infra, &key->entry, tm);
246 return &key->entry;
247}
248
249int
250infra_host(struct infra_cache* infra, struct sockaddr_storage* addr,
251 socklen_t addrlen, uint8_t* nm, size_t nmlen, uint32_t timenow,
251 socklen_t addrlen, uint8_t* nm, size_t nmlen, time_t timenow,
252 int* edns_vs, uint8_t* edns_lame_known, int* to)
253{
254 struct lruhash_entry* e = infra_lookup_nottl(infra, addr, addrlen,
255 nm, nmlen, 0);
256 struct infra_data* data;
257 int wr = 0;
258 if(e && ((struct infra_data*)e->data)->ttl < timenow) {
259 /* it expired, try to reuse existing entry */

--- 52 unchanged lines hidden (view full) ---

312 data->probedelay = timenow + ((*to)+1999)/1000;
313 }
314 lock_rw_unlock(&e->lock);
315 return 1;
316}
317
318int
319infra_set_lame(struct infra_cache* infra, struct sockaddr_storage* addr,
252 int* edns_vs, uint8_t* edns_lame_known, int* to)
253{
254 struct lruhash_entry* e = infra_lookup_nottl(infra, addr, addrlen,
255 nm, nmlen, 0);
256 struct infra_data* data;
257 int wr = 0;
258 if(e && ((struct infra_data*)e->data)->ttl < timenow) {
259 /* it expired, try to reuse existing entry */

--- 52 unchanged lines hidden (view full) ---

312 data->probedelay = timenow + ((*to)+1999)/1000;
313 }
314 lock_rw_unlock(&e->lock);
315 return 1;
316}
317
318int
319infra_set_lame(struct infra_cache* infra, struct sockaddr_storage* addr,
320 socklen_t addrlen, uint8_t* nm, size_t nmlen, uint32_t timenow,
320 socklen_t addrlen, uint8_t* nm, size_t nmlen, time_t timenow,
321 int dnsseclame, int reclame, uint16_t qtype)
322{
323 struct infra_data* data;
324 struct lruhash_entry* e;
325 int needtoinsert = 0;
326 e = infra_lookup_nottl(infra, addr, addrlen, nm, nmlen, 1);
327 if(!e) {
328 /* insert it */

--- 40 unchanged lines hidden (view full) ---

369 * than nothing */
370 data->rtt.rto = RTT_MAX_TIMEOUT-1000;
371 lock_rw_unlock(&e->lock);
372}
373
374int
375infra_rtt_update(struct infra_cache* infra, struct sockaddr_storage* addr,
376 socklen_t addrlen, uint8_t* nm, size_t nmlen, int qtype,
321 int dnsseclame, int reclame, uint16_t qtype)
322{
323 struct infra_data* data;
324 struct lruhash_entry* e;
325 int needtoinsert = 0;
326 e = infra_lookup_nottl(infra, addr, addrlen, nm, nmlen, 1);
327 if(!e) {
328 /* insert it */

--- 40 unchanged lines hidden (view full) ---

369 * than nothing */
370 data->rtt.rto = RTT_MAX_TIMEOUT-1000;
371 lock_rw_unlock(&e->lock);
372}
373
374int
375infra_rtt_update(struct infra_cache* infra, struct sockaddr_storage* addr,
376 socklen_t addrlen, uint8_t* nm, size_t nmlen, int qtype,
377 int roundtrip, int orig_rtt, uint32_t timenow)
377 int roundtrip, int orig_rtt, time_t timenow)
378{
379 struct lruhash_entry* e = infra_lookup_nottl(infra, addr, addrlen,
380 nm, nmlen, 1);
381 struct infra_data* data;
382 int needtoinsert = 0;
383 int rto = 1;
384 if(!e) {
385 if(!(e = new_entry(infra, addr, addrlen, nm, nmlen, timenow)))

--- 34 unchanged lines hidden (view full) ---

420 rto = data->rtt.rto;
421
422 if(needtoinsert)
423 slabhash_insert(infra->hosts, e->hash, e, e->data, NULL);
424 else { lock_rw_unlock(&e->lock); }
425 return rto;
426}
427
378{
379 struct lruhash_entry* e = infra_lookup_nottl(infra, addr, addrlen,
380 nm, nmlen, 1);
381 struct infra_data* data;
382 int needtoinsert = 0;
383 int rto = 1;
384 if(!e) {
385 if(!(e = new_entry(infra, addr, addrlen, nm, nmlen, timenow)))

--- 34 unchanged lines hidden (view full) ---

420 rto = data->rtt.rto;
421
422 if(needtoinsert)
423 slabhash_insert(infra->hosts, e->hash, e, e->data, NULL);
424 else { lock_rw_unlock(&e->lock); }
425 return rto;
426}
427
428int infra_get_host_rto(struct infra_cache* infra,
428long long infra_get_host_rto(struct infra_cache* infra,
429 struct sockaddr_storage* addr, socklen_t addrlen, uint8_t* nm,
429 struct sockaddr_storage* addr, socklen_t addrlen, uint8_t* nm,
430 size_t nmlen, struct rtt_info* rtt, int* delay, uint32_t timenow,
430 size_t nmlen, struct rtt_info* rtt, int* delay, time_t timenow,
431 int* tA, int* tAAAA, int* tother)
432{
433 struct lruhash_entry* e = infra_lookup_nottl(infra, addr, addrlen,
434 nm, nmlen, 0);
435 struct infra_data* data;
431 int* tA, int* tAAAA, int* tother)
432{
433 struct lruhash_entry* e = infra_lookup_nottl(infra, addr, addrlen,
434 nm, nmlen, 0);
435 struct infra_data* data;
436 int ttl = -2;
436 long long ttl = -2;
437 if(!e) return -1;
438 data = (struct infra_data*)e->data;
439 if(data->ttl >= timenow) {
437 if(!e) return -1;
438 data = (struct infra_data*)e->data;
439 if(data->ttl >= timenow) {
440 ttl = (int)(data->ttl - timenow);
440 ttl = (long long)(data->ttl - timenow);
441 memmove(rtt, &data->rtt, sizeof(*rtt));
442 if(timenow < data->probedelay)
443 *delay = (int)(data->probedelay - timenow);
444 else *delay = 0;
445 }
446 *tA = (int)data->timeout_A;
447 *tAAAA = (int)data->timeout_AAAA;
448 *tother = (int)data->timeout_other;
449 lock_rw_unlock(&e->lock);
450 return ttl;
451}
452
453int
454infra_edns_update(struct infra_cache* infra, struct sockaddr_storage* addr,
455 socklen_t addrlen, uint8_t* nm, size_t nmlen, int edns_version,
441 memmove(rtt, &data->rtt, sizeof(*rtt));
442 if(timenow < data->probedelay)
443 *delay = (int)(data->probedelay - timenow);
444 else *delay = 0;
445 }
446 *tA = (int)data->timeout_A;
447 *tAAAA = (int)data->timeout_AAAA;
448 *tother = (int)data->timeout_other;
449 lock_rw_unlock(&e->lock);
450 return ttl;
451}
452
453int
454infra_edns_update(struct infra_cache* infra, struct sockaddr_storage* addr,
455 socklen_t addrlen, uint8_t* nm, size_t nmlen, int edns_version,
456 uint32_t timenow)
456 time_t timenow)
457{
458 struct lruhash_entry* e = infra_lookup_nottl(infra, addr, addrlen,
459 nm, nmlen, 1);
460 struct infra_data* data;
461 int needtoinsert = 0;
462 if(!e) {
463 if(!(e = new_entry(infra, addr, addrlen, nm, nmlen, timenow)))
464 return 0;

--- 15 unchanged lines hidden (view full) ---

480 else { lock_rw_unlock(&e->lock); }
481 return 1;
482}
483
484int
485infra_get_lame_rtt(struct infra_cache* infra,
486 struct sockaddr_storage* addr, socklen_t addrlen,
487 uint8_t* name, size_t namelen, uint16_t qtype,
457{
458 struct lruhash_entry* e = infra_lookup_nottl(infra, addr, addrlen,
459 nm, nmlen, 1);
460 struct infra_data* data;
461 int needtoinsert = 0;
462 if(!e) {
463 if(!(e = new_entry(infra, addr, addrlen, nm, nmlen, timenow)))
464 return 0;

--- 15 unchanged lines hidden (view full) ---

480 else { lock_rw_unlock(&e->lock); }
481 return 1;
482}
483
484int
485infra_get_lame_rtt(struct infra_cache* infra,
486 struct sockaddr_storage* addr, socklen_t addrlen,
487 uint8_t* name, size_t namelen, uint16_t qtype,
488 int* lame, int* dnsseclame, int* reclame, int* rtt, uint32_t timenow)
488 int* lame, int* dnsseclame, int* reclame, int* rtt, time_t timenow)
489{
490 struct infra_data* host;
491 struct lruhash_entry* e = infra_lookup_nottl(infra, addr, addrlen,
492 name, namelen, 0);
493 if(!e)
494 return 0;
495 host = (struct infra_data*)e->data;
496 *rtt = rtt_unclamped(&host->rtt);

--- 73 unchanged lines hidden ---
489{
490 struct infra_data* host;
491 struct lruhash_entry* e = infra_lookup_nottl(infra, addr, addrlen,
492 name, namelen, 0);
493 if(!e)
494 return 0;
495 host = (struct infra_data*)e->data;
496 *rtt = rtt_unclamped(&host->rtt);

--- 73 unchanged lines hidden ---