adb.c revision 2113dfd6e20a9ca16000ed226517b4660087c1f2
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Copyright (C) 1999-2003 Internet Software Consortium.
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halley * Permission to use, copy, modify, and distribute this software for any
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halley * purpose with or without fee is hereby granted, provided that the above
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * copyright notice and this permission notice appear in all copies.
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
15a44745412679c30a6d022733925af70a38b715David Lawrence * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15a44745412679c30a6d022733925af70a38b715David Lawrence * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15a44745412679c30a6d022733925af70a38b715David Lawrence * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15a44745412679c30a6d022733925af70a38b715David Lawrence * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15a44745412679c30a6d022733925af70a38b715David Lawrence * PERFORMANCE OF THIS SOFTWARE.
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson/* $Id: adb.c,v 1.227 2006/08/30 23:09:18 marka Exp $ */
fca5f81ad69098ea8abba130c7f841c951ef91c2Bob Halley * In finds, if task == NULL, no events will be generated, and no events
e419f613d8591885df608cb73065921be07dd12eBob Halley * have been sent. If task != NULL but taskaction == NULL, an event has been
e419f613d8591885df608cb73065921be07dd12eBob Halley * posted but not yet freed. If neither are NULL, no event was posted.
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * After we have cleaned all buckets, dump the database contents.
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence#include <isc/string.h> /* Required for HP/UX (and others?) */
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence#define DNS_ADB_MAGIC ISC_MAGIC('D', 'a', 'd', 'b')
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington#define DNS_ADB_VALID(x) ISC_MAGIC_VALID(x, DNS_ADB_MAGIC)
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence#define DNS_ADBNAME_MAGIC ISC_MAGIC('a', 'd', 'b', 'N')
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence#define DNS_ADBNAME_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBNAME_MAGIC)
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence#define DNS_ADBNAMEHOOK_MAGIC ISC_MAGIC('a', 'd', 'N', 'H')
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence#define DNS_ADBNAMEHOOK_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBNAMEHOOK_MAGIC)
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence#define DNS_ADBLAMEINFO_MAGIC ISC_MAGIC('a', 'd', 'b', 'Z')
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence#define DNS_ADBLAMEINFO_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBLAMEINFO_MAGIC)
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence#define DNS_ADBENTRY_MAGIC ISC_MAGIC('a', 'd', 'b', 'E')
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence#define DNS_ADBENTRY_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBENTRY_MAGIC)
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence#define DNS_ADBFETCH_MAGIC ISC_MAGIC('a', 'd', 'F', '4')
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence#define DNS_ADBFETCH_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBFETCH_MAGIC)
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson#define DNS_ADBFETCH6_MAGIC ISC_MAGIC('a', 'd', 'F', '6')
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson#define DNS_ADBFETCH6_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBFETCH6_MAGIC)
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * The number of buckets needs to be a prime (for good hashing).
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * XXXRTH How many buckets do we need?
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington#define NBUCKETS 1009 /*%< how many buckets for names/addrs */
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * For type 3 negative cache entries, we will remember that the address is
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * broken for this long. XXXMLG This is also used for actual addresses, too.
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * The intent is to keep us from constantly asking about A/AAAA records
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington * if the zone has extremely low TTLs.
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff#define ADB_CACHE_MAXIMUM 86400 /*%< seconds (86400 = 24 hours) */
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson * Wake up every CLEAN_SECONDS and clean CLEAN_BUCKETS buckets, so that all
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * buckets are cleaned in CLEAN_PERIOD seconds.
98d010a24a9f1b4b45ce9791845941ef90426d0cBrian Wellington/*% See #CLEAN_PERIOD */
98d010a24a9f1b4b45ce9791845941ef90426d0cBrian Wellington/*% See #CLEAN_PERIOD */
98d010a24a9f1b4b45ce9791845941ef90426d0cBrian Wellington#define CLEAN_BUCKETS ((NBUCKETS * CLEAN_SECONDS) / CLEAN_PERIOD)
98d010a24a9f1b4b45ce9791845941ef90426d0cBrian Wellington#define FREE_ITEMS 64 /*%< free count for memory pools */
98d010a24a9f1b4b45ce9791845941ef90426d0cBrian Wellington#define FILL_COUNT 16 /*%< fill count for memory pools */
98d010a24a9f1b4b45ce9791845941ef90426d0cBrian Wellington#define DNS_ADB_INVALIDBUCKET (-1) /*%< invalid bucket address */
98d010a24a9f1b4b45ce9791845941ef90426d0cBrian Wellington#define DNS_ADB_MINADBSIZE (1024*1024) /*%< 1 Megabyte */
98d010a24a9f1b4b45ce9791845941ef90426d0cBrian Wellingtontypedef ISC_LIST(dns_adbname_t) dns_adbnamelist_t;
98d010a24a9f1b4b45ce9791845941ef90426d0cBrian Wellingtontypedef struct dns_adbnamehook dns_adbnamehook_t;
98d010a24a9f1b4b45ce9791845941ef90426d0cBrian Wellingtontypedef ISC_LIST(dns_adbnamehook_t) dns_adbnamehooklist_t;
98d010a24a9f1b4b45ce9791845941ef90426d0cBrian Wellingtontypedef struct dns_adblameinfo dns_adblameinfo_t;
98d010a24a9f1b4b45ce9791845941ef90426d0cBrian Wellingtontypedef ISC_LIST(dns_adbentry_t) dns_adbentrylist_t;
98d010a24a9f1b4b45ce9791845941ef90426d0cBrian Wellingtontypedef struct dns_adbfetch6 dns_adbfetch6_t;
98d010a24a9f1b4b45ce9791845941ef90426d0cBrian Wellington/*% dns adb structure */
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington isc_mutex_t reflock; /*%< Covers irefcnt, erefcnt */
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington isc_mempool_t *nhmp; /*%< dns_adbnamehook_t */
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington isc_mempool_t *limp; /*%< dns_adblameinfo_t */
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson isc_mempool_t *ahmp; /*%< dns_adbfind_t */
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington isc_mempool_t *aimp; /*%< dns_adbaddrinfo_t */
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington isc_mempool_t *afmp; /*%< dns_adbfetch_t */
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson * Bucketized locks and lists for names.
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington * XXXRTH Have a per-bucket structure that contains all of these?
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington /*% See dns_adbnamelist_t */
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington /*% See dns_adbnamelist_t */
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington /*% See dns_adbnamelist_t */
94766449d6125cd5870891b70d46573e5deaceb4Brian Wellington * Bucketized locks for entries.
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington * XXXRTH Have a per-bucket structure that contains all of these?
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson isc_boolean_t entry_sd[NBUCKETS]; /*%< shutting down */
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * XXXMLG Document these structures.
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington/*% dns_adbname structure */
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington/*% The adbfetch structure */
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington * This is a small widget that dangles off a dns_adbname_t. It contains a
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington * pointer to the address information about this host, and a link to the next
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington * namehook that will contain the next address this host has.
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson * This is a small widget that holds qname-specific information about an
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington * address. Currently limited to lameness, but could just as easily be
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington * extended to other types of information about zones.
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson * An address entry. It holds quite a bit of information about addresses,
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington * including edns state (in "flags"), rtt, and of course the address of
aa863b2d1e3739ac958c510aa7d61137860c3b7eBrian Wellington unsigned int srtt;
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * A nonzero 'expires' field indicates that the entry should
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * persist until that time. This allows entries found
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * using dns_adb_findaddrinfo() to persist for a limited time
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * even though they are not necessarily associated with a
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington * Internal functions (and prototypes).
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonstatic inline dns_adbname_t *new_adbname(dns_adb_t *, dns_name_t *);
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellingtonstatic inline void free_adbname(dns_adb_t *, dns_adbname_t **);
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellingtonstatic inline dns_adbnamehook_t *new_adbnamehook(dns_adb_t *,
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonstatic inline void free_adbnamehook(dns_adb_t *, dns_adbnamehook_t **);
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonstatic inline dns_adblameinfo_t *new_adblameinfo(dns_adb_t *, dns_name_t *,
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellingtonstatic inline void free_adblameinfo(dns_adb_t *, dns_adblameinfo_t **);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencestatic inline dns_adbentry_t *new_adbentry(dns_adb_t *);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencestatic inline void free_adbentry(dns_adb_t *, dns_adbentry_t **);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencestatic inline dns_adbfind_t *new_adbfind(dns_adb_t *);
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafssonstatic inline isc_boolean_t free_adbfind(dns_adb_t *, dns_adbfind_t **);
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellingtonstatic inline dns_adbaddrinfo_t *new_adbaddrinfo(dns_adb_t *, dns_adbentry_t *,
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellingtonstatic inline dns_adbfetch_t *new_adbfetch(dns_adb_t *);
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellingtonstatic inline void free_adbfetch(dns_adb_t *, dns_adbfetch_t **);
17a3fcecd069130a5f318685493b0db5639a77c9Brian Wellingtonstatic inline dns_adbname_t *find_name_and_lock(dns_adb_t *, dns_name_t *,
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson unsigned int, int *);
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellingtonstatic inline dns_adbentry_t *find_entry_and_lock(dns_adb_t *,
01446841be2b73f9a2ead74056df2d5342414041Andreas Gustafssonstatic void dump_adb(dns_adb_t *, FILE *, isc_boolean_t debug, isc_stdtime_t);
17a3fcecd069130a5f318685493b0db5639a77c9Brian Wellingtonstatic void print_dns_name(FILE *, dns_name_t *);
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonstatic void print_namehook_list(FILE *, const char *legend,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencestatic void print_find_list(FILE *, dns_adbname_t *);
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonstatic void print_fetch_list(FILE *, dns_adbname_t *);
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonstatic inline isc_boolean_t dec_adb_irefcnt(dns_adb_t *);
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonstatic inline void inc_adb_irefcnt(dns_adb_t *);
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonstatic inline void inc_adb_erefcnt(dns_adb_t *);
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellingtonstatic inline void inc_entry_refcnt(dns_adb_t *, dns_adbentry_t *,
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellingtonstatic inline isc_boolean_t dec_entry_refcnt(dns_adb_t *, dns_adbentry_t *,
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellingtonstatic inline void violate_locking_hierarchy(isc_mutex_t *, isc_mutex_t *);
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellingtonstatic isc_boolean_t clean_namehooks(dns_adb_t *, dns_adbnamehooklist_t *);
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellingtonstatic void clean_target(dns_adb_t *, dns_name_t *);
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellingtonstatic void clean_finds_at_name(dns_adbname_t *, isc_eventtype_t,
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington unsigned int);
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellingtonstatic isc_boolean_t check_expire_namehooks(dns_adbname_t *, isc_stdtime_t,
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graffstatic void cancel_fetches_at_name(dns_adbname_t *);
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellingtonstatic isc_result_t dbfind_name(dns_adbname_t *, isc_stdtime_t,
6f071989da905bb5ab2c6dfd01a71ee5ecea5918Brian Wellingtonstatic isc_result_t fetch_name(dns_adbname_t *, isc_boolean_t,
6f071989da905bb5ab2c6dfd01a71ee5ecea5918Brian Wellingtonstatic void timer_cleanup(isc_task_t *, isc_event_t *);
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellingtonstatic isc_boolean_t shutdown_names(dns_adb_t *);
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellingtonstatic isc_boolean_t shutdown_entries(dns_adb_t *);
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellingtonstatic inline void link_name(dns_adb_t *, int, dns_adbname_t *);
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellingtonstatic inline isc_boolean_t unlink_name(dns_adb_t *, dns_adbname_t *);
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellingtonstatic inline void link_entry(dns_adb_t *, int, dns_adbentry_t *);
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellingtonstatic inline isc_boolean_t unlink_entry(dns_adb_t *, dns_adbentry_t *);
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellingtonstatic isc_boolean_t kill_name(dns_adbname_t **, isc_eventtype_t);
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellingtonstatic void water(void *, int);
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafssonstatic void dump_entry(FILE *, dns_adbentry_t *, isc_boolean_t, isc_stdtime_t);
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson * MUST NOT overlap DNS_ADBFIND_* flags!
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington#define FIND_EVENTSENT(h) (((h)->flags & FIND_EVENT_SENT) != 0)
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington#define FIND_EVENTFREED(h) (((h)->flags & FIND_EVENT_FREED) != 0)
777ac454c0cdec27dc11d80b9b2a8d7239d833a8Brian Wellington#define NAME_STARTATZONE DNS_ADBFIND_STARTATZONE
17a3fcecd069130a5f318685493b0db5639a77c9Brian Wellington#define NAME_DEAD(n) (((n)->flags & NAME_IS_DEAD) != 0)
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson#define NAME_NEEDSPOKE(n) (((n)->flags & NAME_NEEDS_POKE) != 0)
1b1e1fda4638334b484aa38c15f53a131c0b0fdfAndreas Gustafsson#define NAME_GLUEOK(n) (((n)->flags & NAME_GLUE_OK) != 0)
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington#define NAME_HINTOK(n) (((n)->flags & NAME_HINT_OK) != 0)
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington * To the name, address classes are all that really exist. If it has a
17a3fcecd069130a5f318685493b0db5639a77c9Brian Wellington * V6 address it doesn't care if it came from a AAAA query.
fe5ba8ddb55b2b3ee139e13b7891817117ad4e63Brian Wellington#define NAME_HAS_V4(n) (!ISC_LIST_EMPTY((n)->v4))
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#define NAME_HAS_V6(n) (!ISC_LIST_EMPTY((n)->v6))
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington#define NAME_HAS_ADDRS(n) (NAME_HAS_V4(n) || NAME_HAS_V6(n))
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington * Fetches are broken out into A and AAAA types. In some cases,
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington * however, it makes more sense to test for a particular class of fetches,
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington * like V4 or V6 above.
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington * Note: since we have removed the support of A6 in adb, FETCH_A and FETCH_AAAA
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington * are now equal to FETCH_V4 and FETCH_V6, respectively.
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington#define NAME_FETCH_A(n) ((n)->fetch_a != NULL)
e27021ee1f37185ab839a7a3b6bc078c24255e62Brian Wellington#define NAME_FETCH_AAAA(n) ((n)->fetch_aaaa != NULL)
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington#define NAME_FETCH_V6(n) (NAME_FETCH_AAAA(n))
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews#define NAME_FETCH(n) (NAME_FETCH_V4(n) || NAME_FETCH_V6(n))
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington * Find options and tests to see if there are addresses on the list.
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson#define FIND_WANTEVENT(fn) (((fn)->options & DNS_ADBFIND_WANTEVENT) != 0)
c70908209ee26c51a8e7242a56fdb73847249728Brian Wellington#define FIND_WANTEMPTYEVENT(fn) (((fn)->options & DNS_ADBFIND_EMPTYEVENT) != 0)
c70908209ee26c51a8e7242a56fdb73847249728Brian Wellington#define FIND_AVOIDFETCHES(fn) (((fn)->options & DNS_ADBFIND_AVOIDFETCHES) \
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington#define FIND_STARTATZONE(fn) (((fn)->options & DNS_ADBFIND_STARTATZONE) \
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson#define FIND_HINTOK(fn) (((fn)->options & DNS_ADBFIND_HINTOK) != 0)
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington#define FIND_GLUEOK(fn) (((fn)->options & DNS_ADBFIND_GLUEOK) != 0)
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington#define FIND_HAS_ADDRS(fn) (!ISC_LIST_EMPTY((fn)->list))
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington#define FIND_RETURNLAME(fn) (((fn)->options & DNS_ADBFIND_RETURNLAME) != 0)
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington * These are currently used on simple unsigned ints, so they are
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington * not really associated with any particular type.
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson#define WANT_INET(x) (((x) & DNS_ADBFIND_INET) != 0)
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington#define WANT_INET6(x) (((x) & DNS_ADBFIND_INET6) != 0)
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington#define EXPIRE_OK(exp, now) ((exp == INT_MAX) || (exp < now))
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington * Find out if the flags on a name (nf) indicate if it is a hint or
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington * glue, and compare this to the appropriate bits set in o, to see if
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington * this is ok.
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington#define GLUE_OK(nf, o) (!NAME_GLUEOK(nf) || (((o) & DNS_ADBFIND_GLUEOK) != 0))
d1cbf714097e900ed1703529584d3e1a50e8a4a8Brian Wellington#define HINT_OK(nf, o) (!NAME_HINTOK(nf) || (((o) & DNS_ADBFIND_HINTOK) != 0))
d1cbf714097e900ed1703529584d3e1a50e8a4a8Brian Wellington#define GLUEHINT_OK(nf, o) (GLUE_OK(nf, o) || HINT_OK(nf, o))
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington#define STARTATZONE_MATCHES(nf, o) (((nf)->flags & NAME_STARTATZONE) == \
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington#define NCACHE_RESULT(r) ((r) == DNS_R_NCACHENXDOMAIN || \
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington#define AUTH_NX(r) ((r) == DNS_R_NXDOMAIN || \
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington#define NXDOMAIN_RESULT(r) ((r) == DNS_R_NXDOMAIN || \
e27021ee1f37185ab839a7a3b6bc078c24255e62Brian Wellington#define NXRRSET_RESULT(r) ((r) == DNS_R_NCACHENXRRSET || \
c70908209ee26c51a8e7242a56fdb73847249728Brian Wellington * Error state rankings.
e27021ee1f37185ab839a7a3b6bc078c24255e62Brian Wellington#define FIND_ERR_SUCCESS 0 /* highest rank */
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonstatic const char *errnames[] = {
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington "unexpected",
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington#define NEWERR(old, new) (ISC_MIN((old), (new)))
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonstatic isc_result_t find_err_map[FIND_ERR_MAX] = {
94766449d6125cd5870891b70d46573e5deaceb4Brian WellingtonDP(int level, const char *format, ...) ISC_FORMAT_PRINTF(2, 3);
94766449d6125cd5870891b70d46573e5deaceb4Brian Wellington DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_ADB,
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington * Requires the adbname bucket be locked and that no entry buckets be locked.
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington * This code handles A and AAAA rdatasets only.
94766449d6125cd5870891b70d46573e5deaceb4Brian Wellingtonimport_rdataset(dns_adbname_t *adbname, dns_rdataset_t *rdataset,
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington dns_adbentry_t *foundentry; /* NO CLEAN UP! */
5c6117688525d0e8d247f50c63364f66bd8d4185Brian Wellington INSIST((rdtype == dns_rdatatype_a) || (rdtype == dns_rdatatype_aaaa));
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington foundentry = find_entry_and_lock(adb, &sockaddr, &addr_bucket);
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson if (addr_bucket != DNS_ADB_INVALIDBUCKET)
f439363eeb4052fddc0e3ec648658548daa10506Brian Wellington DP(NCACHE_LEVEL, "expire_v4 set to MIN(%u,%u) import_rdataset",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence adbname->expire_v4 = ISC_MIN(adbname->expire_v4,
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington DP(NCACHE_LEVEL, "expire_v6 set to MIN(%u,%u) import_rdataset",
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington adbname->expire_v6 = ISC_MIN(adbname->expire_v6,
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington * Lie a little here. This is more or less so code that cares
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington * can find out if any new information was added or not.
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington * Requires the name's bucket be locked.
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellingtonkill_name(dns_adbname_t **n, isc_eventtype_t ev) {
368b37b616234fce3d23099eb180f1dd38e1fb62Mark Andrews * If we're dead already, just check to see if we should go
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington * away now or not.
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington if (NAME_DEAD(name) && !NAME_FETCH(name)) {
93c786e0924aeca2c258e32355349e6ae60a0f72Andreas Gustafsson * Clean up the name's various lists. These two are destructive
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * in that they will always empty the list.
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley clean_finds_at_name(name, ev, DNS_ADBFIND_ADDRESSMASK);
d6643ef587324e40d8bda63e9f80be8141e101edBrian Wellington * If fetches are running, cancel them. If none are running, we can
d6643ef587324e40d8bda63e9f80be8141e101edBrian Wellington * just kill the name here.
5c29047792191d6141f69b2684314d0b762fedebBrian Wellington * Requires the name's bucket be locked and no entry buckets be locked.
feb40fc5f911d0b2050fb9fd34950a52930b981dBrian Wellingtoncheck_expire_namehooks(dns_adbname_t *name, isc_stdtime_t now,
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * Check to see if we need to remove the v4 addresses
feb40fc5f911d0b2050fb9fd34950a52930b981dBrian Wellington (expire || EXPIRE_OK(name->expire_v4, now))) {
c50936eb40263b65ebf6afe4e6556e2dc67c10e4Brian Wellington DP(DEF_LEVEL, "expiring v4 for name %p", name);
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * Check to see if we need to remove the v6 addresses
a9ba7e65644c50e1549b38150ba8d4787e1fe643Brian Wellington * Check to see if we need to remove the alias target.
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley if (expire || EXPIRE_OK(name->expire_target, now)) {
78951552dccf0d0004d61072bbc71fa4b1aab30fAndreas Gustafsson * Requires the name's bucket be locked.
78951552dccf0d0004d61072bbc71fa4b1aab30fAndreas Gustafssonstatic inline void
78951552dccf0d0004d61072bbc71fa4b1aab30fAndreas Gustafssonlink_name(dns_adb_t *adb, int bucket, dns_adbname_t *name) {
78951552dccf0d0004d61072bbc71fa4b1aab30fAndreas Gustafsson INSIST(name->lock_bucket == DNS_ADB_INVALIDBUCKET);
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington ISC_LIST_PREPEND(adb->names[bucket], name, plink);
78951552dccf0d0004d61072bbc71fa4b1aab30fAndreas Gustafsson * Requires the name's bucket be locked.
78951552dccf0d0004d61072bbc71fa4b1aab30fAndreas Gustafssonunlink_name(dns_adb_t *adb, dns_adbname_t *name) {
a9ba7e65644c50e1549b38150ba8d4787e1fe643Brian Wellington ISC_LIST_UNLINK(adb->names[bucket], name, plink);
a9ba7e65644c50e1549b38150ba8d4787e1fe643Brian Wellington if (adb->name_sd[bucket] && adb->name_refcnt[bucket] == 0)
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * Requires the entry's bucket be locked.
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonstatic inline void
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonlink_entry(dns_adb_t *adb, int bucket, dns_adbentry_t *entry) {
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington ISC_LIST_PREPEND(adb->entries[bucket], entry, plink);
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * Requires the entry's bucket be locked.
77c67dfb2607618f5e7940486daebafd42a502abBrian Wellingtonunlink_entry(dns_adb_t *adb, dns_adbentry_t *entry) {
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellington ISC_LIST_UNLINK(adb->entries[bucket], entry, plink);
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellington entry->lock_bucket = DNS_ADB_INVALIDBUCKET;
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington if (adb->entry_sd[bucket] && adb->entry_refcnt[bucket] == 0)
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellingtonstatic inline void
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellingtonviolate_locking_hierarchy(isc_mutex_t *have, isc_mutex_t *want) {
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellington if (isc_mutex_trylock(want) != ISC_R_SUCCESS) {
d6643ef587324e40d8bda63e9f80be8141e101edBrian Wellington * The ADB _MUST_ be locked before calling. Also, exit conditions must be
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington * checked after calling this function.
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * This bucket has no names. We must decrement the
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * irefcnt ourselves, since it will not be
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * automatically triggered by a name being unlinked.
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * Run through the list. For each name, clean up finds
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * found there, and cancel any fetches running. When
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * all the fetches are canceled, the name will destroy
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * The ADB _MUST_ be locked before calling. Also, exit conditions must be
d6643ef587324e40d8bda63e9f80be8141e101edBrian Wellington * checked after calling this function.
77c67dfb2607618f5e7940486daebafd42a502abBrian Wellington for (bucket = 0; bucket < NBUCKETS; bucket++) {
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * This bucket has no entries. We must decrement the
25496cebadd170fd5fae2aabf0469eef551259aaBrian Wellington * irefcnt ourselves, since it will not be
25496cebadd170fd5fae2aabf0469eef551259aaBrian Wellington * automatically triggered by an entry being unlinked.
25496cebadd170fd5fae2aabf0469eef551259aaBrian Wellington * Run through the list. Cleanup any entries not
25496cebadd170fd5fae2aabf0469eef551259aaBrian Wellington * associated with names, and which are not in use.
25496cebadd170fd5fae2aabf0469eef551259aaBrian Wellington * Name bucket must be locked
26e5029fd55434db52702313a49e3dc7d47bd328Brian Wellingtoncancel_fetches_at_name(dns_adbname_t *name) {
26e5029fd55434db52702313a49e3dc7d47bd328Brian Wellington dns_resolver_cancelfetch(name->fetch_a->fetch);
25496cebadd170fd5fae2aabf0469eef551259aaBrian Wellington dns_resolver_cancelfetch(name->fetch_aaaa->fetch);
25496cebadd170fd5fae2aabf0469eef551259aaBrian Wellington * Assumes the name bucket is locked.
25496cebadd170fd5fae2aabf0469eef551259aaBrian Wellingtonclean_namehooks(dns_adb_t *adb, dns_adbnamehooklist_t *namehooks) {
25496cebadd170fd5fae2aabf0469eef551259aaBrian Wellington * Clean up the entry if needed.
3ce4b8b03ebd017c1d1b320429219ba91e705ea4Andreas Gustafsson if (addr_bucket != DNS_ADB_INVALIDBUCKET)
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley result = dec_entry_refcnt(adb, entry, ISC_FALSE);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews * Free the namehook
25496cebadd170fd5fae2aabf0469eef551259aaBrian Wellingtonclean_target(dns_adb_t *adb, dns_name_t *target) {
25496cebadd170fd5fae2aabf0469eef551259aaBrian Wellingtonset_target(dns_adb_t *adb, dns_name_t *name, dns_name_t *fname,
25496cebadd170fd5fae2aabf0469eef551259aaBrian Wellington dns_rdataset_t *rdataset, dns_name_t *target)
93c786e0924aeca2c258e32355349e6ae60a0f72Andreas Gustafsson REQUIRE(dns_name_countlabels(target) == 0);
93c786e0924aeca2c258e32355349e6ae60a0f72Andreas Gustafsson if (rdataset->type == dns_rdatatype_cname) {
93c786e0924aeca2c258e32355349e6ae60a0f72Andreas Gustafsson * Copy the CNAME's target into the target name.
fe5ba8ddb55b2b3ee139e13b7891817117ad4e63Brian Wellington result = dns_rdata_tostruct(&rdata, &cname, NULL);
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington result = dns_name_dup(&cname.cname, adb->mctx, target);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence INSIST(rdataset->type == dns_rdatatype_dname);
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley namereln = dns_name_fullcompare(name, fname, &order, &nlabels);
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * Get the target name of the DNAME.
93c786e0924aeca2c258e32355349e6ae60a0f72Andreas Gustafsson result = dns_rdata_tostruct(&rdata, &dname, NULL);
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * Construct the new target name.
d6643ef587324e40d8bda63e9f80be8141e101edBrian Wellington dns_name_split(name, nlabels, prefix, NULL);
d6643ef587324e40d8bda63e9f80be8141e101edBrian Wellington result = dns_name_concatenate(prefix, &dname.dname, new_target,
d6643ef587324e40d8bda63e9f80be8141e101edBrian Wellington result = dns_name_dup(new_target, adb->mctx, target);
ba393f380e4cd93029f6a7291d6c2d14f9022b3cBrian Wellington * Assumes nothing is locked, since this is called by the client.
ba393f380e4cd93029f6a7291d6c2d14f9022b3cBrian Wellington * Assumes the name bucket is locked.
d6643ef587324e40d8bda63e9f80be8141e101edBrian Wellingtonclean_finds_at_name(dns_adbname_t *name, isc_eventtype_t evtype,
75f6c57d9544aa77a3b1a04587b4702c07343c90Brian Wellington "ENTER clean_finds_at_name, name %p, evtype %08x, addrs %08x",
feb40fc5f911d0b2050fb9fd34950a52930b981dBrian Wellington wanted = find->flags & DNS_ADBFIND_ADDRESSMASK;
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington DP(ISC_LOG_DEBUG(3), "DNS_EVENT_ADBMOREADDRESSES");
5c6117688525d0e8d247f50c63364f66bd8d4185Brian Wellington DP(ISC_LOG_DEBUG(3), "DNS_EVENT_ADBNOMOREADDRESSES");
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington wanted = find->flags & DNS_ADBFIND_ADDRESSMASK;
c70908209ee26c51a8e7242a56fdb73847249728Brian Wellington DP(DEF_LEVEL, "cfan: processing find %p", find);
e1f16346db02486f751c6db683fffe53c866c186Andreas Gustafsson * Unlink the find from the name, letting the caller
e1f16346db02486f751c6db683fffe53c866c186Andreas Gustafsson * call dns_adb_destroyfind() on it to clean it up
e83cae7fa837e4757c687035d6f6c0900f152749Brian Wellington find->result_v4 = find_err_map[name->fetch_err];
e83cae7fa837e4757c687035d6f6c0900f152749Brian Wellington find->result_v6 = find_err_map[name->fetch6_err];
e83cae7fa837e4757c687035d6f6c0900f152749Brian Wellington "sending event %p to task %p for find %p",
e83cae7fa837e4757c687035d6f6c0900f152749Brian Wellington isc_task_sendanddetach(&task, (isc_event_t **)&ev);
94766449d6125cd5870891b70d46573e5deaceb4Brian Wellington DP(DEF_LEVEL, "cfan: skipping find %p", find);
94766449d6125cd5870891b70d46573e5deaceb4Brian Wellington DP(ENTER_LEVEL, "EXIT clean_finds_at_name, name %p", name);
94766449d6125cd5870891b70d46573e5deaceb4Brian Wellingtonstatic inline void
94766449d6125cd5870891b70d46573e5deaceb4Brian Wellington * The caller must be holding the adb lock.
94766449d6125cd5870891b70d46573e5deaceb4Brian Wellington * If there aren't any external references either, we're
94766449d6125cd5870891b70d46573e5deaceb4Brian Wellington * done. Send the control event to initiate shutdown.
94766449d6125cd5870891b70d46573e5deaceb4Brian Wellington INSIST(!adb->cevent_sent); /* Sanity check. */
32b2cdf212de957e3f9b0efca59f098ed4fb42deBrian Wellington ISC_LIST_UNLINK(adb->whenshutdown, event, ev_link);
c70908209ee26c51a8e7242a56fdb73847249728Brian Wellington if (adb->irefcnt == 0 && adb->erefcnt == 0)
32b2cdf212de957e3f9b0efca59f098ed4fb42deBrian Wellingtonstatic inline void
94766449d6125cd5870891b70d46573e5deaceb4Brian Wellingtonstatic inline void
94766449d6125cd5870891b70d46573e5deaceb4Brian Wellingtonstatic inline void
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrenceinc_entry_refcnt(dns_adb_t *adb, dns_adbentry_t *entry, isc_boolean_t lock) {
5c6117688525d0e8d247f50c63364f66bd8d4185Brian Wellingtondec_entry_refcnt(dns_adb_t *adb, dns_adbentry_t *entry, isc_boolean_t lock) {
e83cae7fa837e4757c687035d6f6c0900f152749Brian Wellington (adb->entry_sd[bucket] || entry->expires == 0)) {
613efcd8fbd0d1ce0d0afd1ac85d95cf85bffc27Brian Wellington entry->lock_bucket = DNS_ADB_INVALIDBUCKET;
613efcd8fbd0d1ce0d0afd1ac85d95cf85bffc27Brian Wellingtonnew_adbname(dns_adb_t *adb, dns_name_t *dnsname) {
25496cebadd170fd5fae2aabf0469eef551259aaBrian Wellington if (dns_name_dup(dnsname, adb->mctx, &name->name) != ISC_R_SUCCESS) {
613efcd8fbd0d1ce0d0afd1ac85d95cf85bffc27Brian Wellingtonstatic inline void
613efcd8fbd0d1ce0d0afd1ac85d95cf85bffc27Brian Wellingtonfree_adbname(dns_adb_t *adb, dns_adbname_t **name) {
6036112f4874637240d461c3ccbcb8dbfb1f405bAndreas Gustafsson INSIST(name != NULL && DNS_ADBNAME_VALID(*name));
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington INSIST(n->lock_bucket == DNS_ADB_INVALIDBUCKET);
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonnew_adbnamehook(dns_adb_t *adb, dns_adbentry_t *entry) {
5c6117688525d0e8d247f50c63364f66bd8d4185Brian Wellingtonstatic inline void
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellingtonfree_adbnamehook(dns_adb_t *adb, dns_adbnamehook_t **namehook) {
613efcd8fbd0d1ce0d0afd1ac85d95cf85bffc27Brian Wellington INSIST(namehook != NULL && DNS_ADBNAMEHOOK_VALID(*namehook));
ec371edc34e2adb9e337b774d1a6e613f5863655Brian Wellingtonnew_adblameinfo(dns_adb_t *adb, dns_name_t *qname, dns_rdatatype_t qtype) {
613efcd8fbd0d1ce0d0afd1ac85d95cf85bffc27Brian Wellington if (dns_name_dup(qname, adb->mctx, &li->qname) != ISC_R_SUCCESS) {
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonstatic inline void
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonfree_adblameinfo(dns_adb_t *adb, dns_adblameinfo_t **lameinfo) {
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington INSIST(lameinfo != NULL && DNS_ADBLAMEINFO_VALID(*lameinfo));
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellingtonstatic inline void
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellingtonfree_adbentry(dns_adb_t *adb, dns_adbentry_t **entry) {
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley INSIST(entry != NULL && DNS_ADBENTRY_VALID(*entry));
60783293cc27f74a84ec93c95c5d46edd30bd8e0Brian Wellington INSIST(e->lock_bucket == DNS_ADB_INVALIDBUCKET);
94766449d6125cd5870891b70d46573e5deaceb4Brian Wellington * Public members.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * private members
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley ISC_EVENT_INIT(&h->event, sizeof(isc_event_t), 0, 0, 0, NULL, NULL,
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halleystatic inline dns_adbfetch_t *
e419f613d8591885df608cb73065921be07dd12eBob Halleystatic inline void
e419f613d8591885df608cb73065921be07dd12eBob Halleyfree_adbfetch(dns_adb_t *adb, dns_adbfetch_t **fetch) {
e419f613d8591885df608cb73065921be07dd12eBob Halley INSIST(fetch != NULL && DNS_ADBFETCH_VALID(*fetch));
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington if (dns_rdataset_isassociated(&f->rdataset))
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonfree_adbfind(dns_adb_t *adb, dns_adbfind_t **findp) {
e419f613d8591885df608cb73065921be07dd12eBob Halley INSIST(findp != NULL && DNS_ADBFIND_VALID(*findp));
e419f613d8591885df608cb73065921be07dd12eBob Halley INSIST(find->name_bucket == DNS_ADB_INVALIDBUCKET);
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halley * Copy bits from the entry into the newly allocated addrinfo. The entry
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halley * must be locked, and the reference count must be bumped up by one
e419f613d8591885df608cb73065921be07dd12eBob Halley * if this function returns a valid pointer.
264fd373f3f6cc7f271bdff14a020385620015f1Andreas Gustafssonnew_adbaddrinfo(dns_adb_t *adb, dns_adbentry_t *entry, in_port_t port) {
264fd373f3f6cc7f271bdff14a020385620015f1Andreas Gustafsson isc_sockaddr_setport(&ai->sockaddr, port);
e419f613d8591885df608cb73065921be07dd12eBob Halleystatic inline void
e419f613d8591885df608cb73065921be07dd12eBob Halleyfree_adbaddrinfo(dns_adb_t *adb, dns_adbaddrinfo_t **ainfo) {
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley INSIST(ainfo != NULL && DNS_ADBADDRINFO_VALID(*ainfo));
fe5ba8ddb55b2b3ee139e13b7891817117ad4e63Brian Wellington * Search for the name. NOTE: The bucket is kept locked on both
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson * success and failure, so it must always be unlocked by the caller!
ef97e09e20da2133adc731cf7e29e72d04dfc93fAndreas Gustafsson * On the first call to this function, *bucketp must be set to
1872808932603066d401d3de97db11af8ffee78aAndreas Gustafsson * DNS_ADB_INVALIDBUCKET.
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halleystatic inline dns_adbname_t *
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halleyfind_name_and_lock(dns_adb_t *adb, dns_name_t *name,
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley bucket = dns_name_fullhash(name, ISC_FALSE) % NBUCKETS;
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington adbname = ISC_LIST_HEAD(adb->names[bucket]);
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson * Search for the address. NOTE: The bucket is kept locked on both
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson * success and failure, so it must always be unlocked by the caller.
1b1e1fda4638334b484aa38c15f53a131c0b0fdfAndreas Gustafsson * On the first call to this function, *bucketp must be set to
1b1e1fda4638334b484aa38c15f53a131c0b0fdfAndreas Gustafsson * DNS_ADB_INVALIDBUCKET. This will cause a lock to occur. On
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington * later calls (within the same "lock path") it can be left alone, so
1b1e1fda4638334b484aa38c15f53a131c0b0fdfAndreas Gustafsson * if this function is called multiple times locking is only done if
1b1e1fda4638334b484aa38c15f53a131c0b0fdfAndreas Gustafsson * the bucket changes.
1b1e1fda4638334b484aa38c15f53a131c0b0fdfAndreas Gustafssonfind_entry_and_lock(dns_adb_t *adb, isc_sockaddr_t *addr, int *bucketp) {
1b1e1fda4638334b484aa38c15f53a131c0b0fdfAndreas Gustafsson bucket = isc_sockaddr_hash(addr, ISC_TRUE) % NBUCKETS;
1b1e1fda4638334b484aa38c15f53a131c0b0fdfAndreas Gustafsson entry = ISC_LIST_HEAD(adb->entries[bucket]);
1b1e1fda4638334b484aa38c15f53a131c0b0fdfAndreas Gustafsson if (isc_sockaddr_equal(addr, &entry->sockaddr))
1b1e1fda4638334b484aa38c15f53a131c0b0fdfAndreas Gustafsson * Entry bucket MUST be locked!
1b1e1fda4638334b484aa38c15f53a131c0b0fdfAndreas Gustafssonentry_is_lame(dns_adb_t *adb, dns_adbentry_t *entry, dns_name_t *qname,
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);
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);
for (i = 0; i < CLEAN_BUCKETS; i++) {
== ISC_FALSE);
#ifdef DUMP_ADB_AFTER_CLEANING
return (ISC_R_NOMEMORY);
goto fail0b;
goto fail0c;
goto fail0d;
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;
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;
if (overmem) {