adb.c revision c5734964e6400f9e6d8c3f057fcccab596929dea
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * Copyright (C) 2004-2014 Internet Systems Consortium, Inc. ("ISC")
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * Copyright (C) 1999-2003 Internet Software Consortium.
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * Permission to use, copy, modify, and/or distribute this software for any
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * purpose with or without fee is hereby granted, provided that the above
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley * copyright notice and this permission notice appear in all copies.
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * PERFORMANCE OF THIS SOFTWARE.
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * In finds, if task == NULL, no events will be generated, and no events
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley * have been sent. If task != NULL but taskaction == NULL, an event has been
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley * posted but not yet freed. If neither are NULL, no event was posted.
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#include <isc/string.h> /* Required for HP/UX (and others?) */
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#define DNS_ADB_MAGIC ISC_MAGIC('D', 'a', 'd', 'b')
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#define DNS_ADB_VALID(x) ISC_MAGIC_VALID(x, DNS_ADB_MAGIC)
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#define DNS_ADBNAME_MAGIC ISC_MAGIC('a', 'd', 'b', 'N')
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#define DNS_ADBNAME_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBNAME_MAGIC)
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#define DNS_ADBNAMEHOOK_MAGIC ISC_MAGIC('a', 'd', 'N', 'H')
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#define DNS_ADBNAMEHOOK_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBNAMEHOOK_MAGIC)
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#define DNS_ADBLAMEINFO_MAGIC ISC_MAGIC('a', 'd', 'b', 'Z')
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#define DNS_ADBLAMEINFO_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBLAMEINFO_MAGIC)
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#define DNS_ADBENTRY_MAGIC ISC_MAGIC('a', 'd', 'b', 'E')
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#define DNS_ADBENTRY_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBENTRY_MAGIC)
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#define DNS_ADBFETCH_MAGIC ISC_MAGIC('a', 'd', 'F', '4')
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#define DNS_ADBFETCH_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBFETCH_MAGIC)
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#define DNS_ADBFETCH6_MAGIC ISC_MAGIC('a', 'd', 'F', '6')
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#define DNS_ADBFETCH6_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBFETCH6_MAGIC)
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * For type 3 negative cache entries, we will remember that the address is
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * broken for this long. XXXMLG This is also used for actual addresses, too.
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * The intent is to keep us from constantly asking about A/AAAA records
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * if the zone has extremely low TTLs.
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#define ADB_CACHE_MAXIMUM 86400 /*%< seconds (86400 = 24 hours) */
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * The period in seconds after which an ADB name entry is regarded as stale
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * and forced to be cleaned up.
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * TODO: This should probably be configurable at run-time.
struct dns_adb {
unsigned int magic;
int next_cleanbucket;
unsigned int irefcnt;
unsigned int erefcnt;
unsigned int nnames;
unsigned int namescnt;
unsigned int *name_refcnt;
unsigned int nentries;
unsigned int entriescnt;
unsigned int *entry_refcnt;
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;
unsigned char plain;
unsigned char plainto;
unsigned char edns;
unsigned char * sit;
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);
dns_adbentry_t *e;
unsigned int i, n, bucket;
goto check_exit;
if (nbuckets[i] != 0)
n = nbuckets[i];
goto done;
goto cleanup;
goto cleanup;
goto cleanup;
newentry_refcnt[i] = 0;
while (e != NULL) {
while (e != NULL) {
goto done;
sizeof(*newentries) * n);
sizeof(*newdeadentries) * n);
sizeof(*newentrylocks) * n);
sizeof(*newentry_sd) * n);
sizeof(*newentry_refcnt) * n);
done:
unsigned int i, n, bucket;
goto check_exit;
if (nbuckets[i] != 0)
n = nbuckets[i];
goto done;
goto cleanup;
goto cleanup;
goto cleanup;
newname_refcnt[i] = 0;
goto done;
sizeof(*newname_refcnt) * n);
done:
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
unsigned int bucket;
return (result);
static isc_boolean_t
unsigned 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;
e->udpsize = 0;
e->edns = 0;
e->plain = 0;
e->plainto = 0;
e->to4096 = 0;
e->to1432 = 0;
e->to1232 = 0;
e->to512 = 0;
e->sitlen = 0;
isc_random_get(&r);
e->lastage = 0;
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 fail0f;
goto fail0g;
goto fail1; \
goto fail1; \
goto fail1;
goto fail2;
#define MPINIT(t, p, n) do { \
goto fail3; \
isc_mempool_setname((p), n); \
goto fail3;
goto fail3;
return (ISC_R_SUCCESS);
return (result);
if (need_exit_check) {
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);
namebuf[0] = 0;
goto out;
goto out;
goto post_copy;
goto v6;
goto post_copy;
goto fetch;
goto v6;
v6:
goto fetch;
goto post_copy;
goto fetch;
if (wanted_fetches != 0 &&
if (alias)
if (want_event) {
if (alias) {
goto out;
out:
if (want_event) {
return (result);
int bucket;
int bucket;
int unlock_bucket;
goto cleanup;
if (debug)
if (debug)
if (debug)
if (debug)
if (debug)
if (debug)
#ifdef ISC_PLATFORM_USESIT
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;
int bucket;
int bucket;
int bucket;
return (noedns);
int bucket;
int bucket;
int bucket;
int bucket;
int bucket;
unsigned int size;
return (size);
int bucket;
unsigned int size;
if (lookups > 0 &&
return (size);
int bucket;
int bucket;
len = 0;
return (len);
int bucket;
goto unlock;
goto unlock;
return (result);
int bucket;
if (want_check_exit) {
#ifdef DUMP_ADB_AFTER_CLEANING
int bucket;