adb.c revision 743bbdc18f839499862e4fb28ec32f607b1632dc
c07c2a862e0f9d671e2961cd179c7b28d7b04f10Mark Andrews * Copyright (C) 2004-2010 Internet Systems Consortium, Inc. ("ISC")
c07c2a862e0f9d671e2961cd179c7b28d7b04f10Mark Andrews * Copyright (C) 1999-2003 Internet Software Consortium.
c07c2a862e0f9d671e2961cd179c7b28d7b04f10Mark Andrews * Permission to use, copy, modify, and/or distribute this software for any
c07c2a862e0f9d671e2961cd179c7b28d7b04f10Mark Andrews * purpose with or without fee is hereby granted, provided that the above
c07c2a862e0f9d671e2961cd179c7b28d7b04f10Mark Andrews * copyright notice and this permission notice appear in all copies.
c07c2a862e0f9d671e2961cd179c7b28d7b04f10Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
c07c2a862e0f9d671e2961cd179c7b28d7b04f10Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
c07c2a862e0f9d671e2961cd179c7b28d7b04f10Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
c07c2a862e0f9d671e2961cd179c7b28d7b04f10Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
c07c2a862e0f9d671e2961cd179c7b28d7b04f10Mark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
c07c2a862e0f9d671e2961cd179c7b28d7b04f10Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
c07c2a862e0f9d671e2961cd179c7b28d7b04f10Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
c07c2a862e0f9d671e2961cd179c7b28d7b04f10Mark Andrews/* $Id: adb.c,v 1.252 2010/12/16 09:51:29 jinmei Exp $ */
c07c2a862e0f9d671e2961cd179c7b28d7b04f10Mark Andrews * In finds, if task == NULL, no events will be generated, and no events
c07c2a862e0f9d671e2961cd179c7b28d7b04f10Mark Andrews * have been sent. If task != NULL but taskaction == NULL, an event has been
c07c2a862e0f9d671e2961cd179c7b28d7b04f10Mark Andrews * posted but not yet freed. If neither are NULL, no event was posted.
c07c2a862e0f9d671e2961cd179c7b28d7b04f10Mark Andrews#include <isc/string.h> /* Required for HP/UX (and others?) */
#ifndef ADB_STALE_MARGIN
struct dns_adb {
unsigned int magic;
int next_cleanbucket;
unsigned int irefcnt;
unsigned int erefcnt;
struct dns_adbname {
unsigned int magic;
unsigned int partial_result;
unsigned int flags;
int lock_bucket;
unsigned int chains;
unsigned int fetch_err;
unsigned int fetch6_err;
struct dns_adbfetch {
unsigned int magic;
struct dns_adbnamehook {
unsigned int magic;
struct dns_adblameinfo {
unsigned int magic;
struct dns_adbentry {
unsigned int magic;
int lock_bucket;
unsigned int refcnt;
unsigned int flags;
unsigned int srtt;
dns_adbentry_t *);
isc_sockaddr_t *, int *,
static void water(void *, int);
((o) & DNS_ADBFIND_STARTATZONE))
(r) == DNS_R_NCACHENXRRSET)
(r) == DNS_R_NXRRSET)
(r) == DNS_R_NCACHENXDOMAIN)
(r) == DNS_R_NXRRSET || \
(r) == DNS_R_HINTNXRRSET)
static const char *errnames[] = {
static inline dns_ttl_t
return (ttl);
static isc_result_t
int addr_bucket;
unsigned int findoptions;
goto fail;
now);
goto fail;
fail:
if (new_addresses_added) {
return (ISC_R_SUCCESS);
return (result);
static isc_boolean_t
int bucket;
name = *n;
*n = NULL;
if (result)
return (result);
if (result)
return (result);
static isc_boolean_t
static inline isc_boolean_t
int bucket;
return (result);
dns_adbentry_t *e;
if (e == NULL)
if (e->refcnt == 0) {
static inline isc_boolean_t
int bucket;
return (result);
static isc_boolean_t
int bucket;
return (result);
static isc_boolean_t
int bucket;
if (result)
return (result);
static isc_boolean_t
int addr_bucket;
return (result);
static isc_result_t
unsigned int nlabels;
int order;
return (result);
return (result);
return (result);
return (result);
return (result);
NULL);
return (result);
return (result);
return (ISC_R_SUCCESS);
unsigned int addrs)
switch (evtype) {
if ((notify) != 0) {
if (wanted == 0)
if (process) {
static inline isc_boolean_t
return (result);
int bucket;
if (lock)
if (lock)
static inline isc_boolean_t
int bucket;
if (lock)
if (lock)
if (!destroy_entry)
return (result);
if (result)
return (result);
static inline dns_adbname_t *
return (NULL);
return (NULL);
return (name);
dns_adbname_t *n;
n = *name;
n->magic = 0;
static inline dns_adbnamehook_t *
return (NULL);
return (nh);
static inline dns_adblameinfo_t *
return (NULL);
return (NULL);
return (li);
static inline dns_adbentry_t *
dns_adbentry_t *e;
isc_uint32_t r;
if (e == NULL)
return (NULL);
e->refcnt = 0;
e->flags = 0;
isc_random_get(&r);
e->expires = 0;
dns_adbentry_t *e;
e = *entry;
e->magic = 0;
static inline dns_adbfind_t *
dns_adbfind_t *h;
if (h == NULL)
return (NULL);
h->magic = 0;
h->partial_result = 0;
h->options = 0;
h->flags = 0;
return (NULL);
static inline dns_adbfetch_t *
dns_adbfetch_t *f;
if (f == NULL)
return (NULL);
f->magic = 0;
dns_adbfetch_t *f;
f = *fetch;
f->magic = 0;
static inline isc_boolean_t
static inline dns_adbaddrinfo_t *
return (NULL);
return (ai);
static inline dns_adbname_t *
int bucket;
return (adbname);
return (NULL);
static inline dns_adbentry_t *
int bucket;
return (entry);
return (NULL);
static isc_boolean_t
return (ISC_FALSE);
return (is_bad);
int bucket;
goto nextv4;
goto out;
goto nextv6;
goto out;
out:
static isc_boolean_t
return (result);
return (result);
return (result);
return (result);
return (result);
return (result);
int scans = 0;
for (victims = 0;
scans++;
victims++;
goto next;
victims++;
next:
if (!overmem)
static isc_boolean_t
return (result);
return (result);
if (result)
return (result);
static isc_boolean_t
return (result);
if (!result)
return (result);
static isc_boolean_t
return (result);
return (ISC_R_NOMEMORY);
goto fail0b;
goto fail0c;
goto fail0d;
goto fail0e;
goto fail1;
for (i = 0; i < NBUCKETS; i++) {
for (i = 0; i < NBUCKETS; i++) {
goto fail2;
#define MPINIT(t, p, n) do { \
goto fail3; \
isc_mempool_setname((p), n); \
goto fail3;
return (ISC_R_SUCCESS);
return (result);
if (need_exit_check) {
if (!need_check_exit)
if (need_check_exit)
int bucket;
unsigned int wanted_addresses;
unsigned int wanted_fetches;
unsigned int query_pending;
wanted_fetches = 0;
query_pending = 0;
if (now == 0)
return (ISC_R_NOMEMORY);
goto out;
goto out;
adbname);
goto post_copy;
adbname);
goto v6;
adbname);
goto post_copy;
goto fetch;
goto v6;
v6:
adbname);
goto fetch;
adbname);
goto post_copy;
goto fetch;
if (wanted_fetches != 0 &&
adbname);
adbname);
if (alias)
if (want_event) {
if (alias) {
goto out;
out:
if (want_event) {
return (result);
int bucket;
int bucket;
int unlock_bucket;
goto cleanup;
for (i = 0; i < NBUCKETS; i++)
for (i = 0; i < NBUCKETS; i++)
if (debug)
for (i = 0; i < NBUCKETS; i++)
for (i = 0; i < NBUCKETS; i++)
for (i = 0; i < NBUCKETS; i++) {
if (debug)
if (debug)
if (debug)
if (debug)
for (i = 0; i < NBUCKETS; i++) {
for (i = 0; i < NBUCKETS; i++)
for (i = 0; i < NBUCKETS; i++)
if (debug)
const char *tmpp;
case AF_INET:
case AF_INET6:
if (debug)
if (NAME_FETCH_A(n))
if (NAME_FETCH_AAAA(n))
static isc_result_t
switch (result) {
case DNS_R_GLUE:
case DNS_R_HINT:
case ISC_R_SUCCESS:
case DNS_R_NXDOMAIN:
case DNS_R_NXRRSET:
adbname);
adbname);
case DNS_R_NCACHENXDOMAIN:
case DNS_R_NCACHENXRRSET:
case DNS_R_CNAME:
case DNS_R_DNAME:
adbname);
return (result);
int bucket;
unsigned int address_type;
address_type = 0;
if (want_check_exit) {
goto out;
name);
goto check_result;
goto out;
out:
static isc_result_t
unsigned int options;
if (start_at_zone) {
adbname);
goto cleanup;
goto cleanup;
goto cleanup;
return (result);
int bucket;
goto unlock;
goto unlock;
return (result);
int bucket;
unsigned int new_srtt;
int bucket;
int bucket;
goto unlock;
goto unlock;
return (result);
int bucket;
if (want_check_exit) {
for (i = 0; i < NBUCKETS; i++)
for (i = 0; i < NBUCKETS; i++)
#ifdef DUMP_ADB_AFTER_CLEANING
int bucket;