adb.c revision e51511aa3281f8dc384eb1283115c7f8d5c402ae
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * Copyright (C) 1999 Internet Software Consortium.
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * Permission to use, copy, modify, and distribute this software for any
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * purpose with or without fee is hereby granted, provided that the above
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * copyright notice and this permission notice appear in all copies.
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Implementation notes
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * --------------------
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * In handles, if task == NULL, no events will be generated, and no events
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * have been sent. If task != NULL but taskaction == NULL, an event has been
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * posted but not yet freed. If neigher are NULL, no event was posted.
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff#define DNS_ADB_VALID(x) ISC_MAGIC_VALID(x, DNS_ADB_MAGIC)
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff#define DNS_ADBNAME_MAGIC 0x6164624e /* adbN. */
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff#define DNS_ADBNAME_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBNAME_MAGIC)
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff#define DNS_ADBNAMEHOOK_MAGIC 0x61644e48 /* adNH. */
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff#define DNS_ADBNAMEHOOK_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBNAMEHOOK_MAGIC)
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff#define DNS_ADBZONEINFO_MAGIC 0x6164625a /* adbZ. */
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff#define DNS_ADBZONEINFO_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBZONEINFO_MAGIC)
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff#define DNS_ADBENTRY_MAGIC 0x61646245 /* adbE. */
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff#define DNS_ADBENTRY_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBENTRY_MAGIC)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Lengths of lists needs to be powers of two.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff#define DNS_ADBNAMELIST_LENGTH 16 /* how many buckets for names */
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff#define DNS_ADBENTRYLIST_LENGTH 16 /* how many buckets for addresses */
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff#define FREE_ITEMS 16 /* free count for memory pools */
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff#define FILL_COUNT 8 /* fill count for memory pools */
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff#define DNS_ADB_INVALIDBUCKET (-1) /* invalid bucket address */
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Grafftypedef ISC_LIST(dns_adbname_t) dns_adbnamelist_t;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Grafftypedef struct dns_adbnamehook dns_adbnamehook_t;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Grafftypedef struct dns_adbzoneinfo dns_adbzoneinfo_t;
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Grafftypedef ISC_LIST(dns_adbentry_t) dns_adbentrylist_t;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff unsigned int magic;
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff unsigned int refcnt;
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff * Bucketized locks and lists for names.
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff dns_adbnamelist_t names[DNS_ADBNAMELIST_LENGTH];
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff isc_mutex_t namelocks[DNS_ADBNAMELIST_LENGTH];
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff * Bucketized locks for entries.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff dns_adbentrylist_t entries[DNS_ADBENTRYLIST_LENGTH];
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff isc_mutex_t entrylocks[DNS_ADBENTRYLIST_LENGTH];
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff * List of running and idle handles.
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff unsigned int magic;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * dns_adbnamehook_t
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * This is a small widget that dangles off a dns_adbname_t. It contains a
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * pointer to the address information about this host, and a link to the next
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * namehook that will contain the next address this host has.
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff unsigned int magic;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * dns_adbzoneinfo_t
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * This is a small widget that holds zone-specific information about an
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * address. Currently limited to lameness, but could just as easily be
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * extended to other types of information about zones.
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff unsigned int magic;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * An address entry. It holds quite a bit of information about addresses,
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * including edns state, rtt, and of course the address of the host.
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff unsigned int magic;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff unsigned int flags;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff unsigned int srtt;
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Internal functions (and prototypes).
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffnew_adbnamehook(dns_adb_t *, dns_adbentry_t *);
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffnew_adbaddrinfo(dns_adb_t *, dns_adbentry_t *);
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Grafffind_name_and_lock(dns_adb_t *, dns_name_t *, int *);
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Grafffind_entry_and_lock(dns_adb_t *, isc_sockaddr_t *, int *);
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffstatic inline void
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffstatic inline void
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffstatic inline void
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffinc_adb_refcnt(dns_adb_t *adb, isc_boolean_t lock)
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffstatic inline void
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffdec_adb_refcnt(dns_adb_t *adb, isc_boolean_t lock)
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffstatic inline void
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Grafffree_adbname(dns_adb_t *adb, dns_adbname_t **name)
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff INSIST(name != NULL && DNS_ADBNAME_VALID(*name));
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graffnew_adbnamehook(dns_adb_t *adb, dns_adbentry_t *entry)
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffstatic inline void
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Grafffree_adbnamehook(dns_adb_t *adb, dns_adbnamehook_t **namehook)
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff INSIST(namehook != NULL && DNS_ADBNAMEHOOK_VALID(*namehook));
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffstatic inline void
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Grafffree_adbentry(dns_adb_t *adb, dns_adbentry_t **entry)
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff INSIST(entry != NULL && DNS_ADBENTRY_VALID(*entry));
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff INSIST(e->lock_bucket == DNS_ADB_INVALIDBUCKET);
519b4a1a27c8b767a57a981dda69a3c6394bd49dMichael Graff * public members
519b4a1a27c8b767a57a981dda69a3c6394bd49dMichael Graff * private members
519b4a1a27c8b767a57a981dda69a3c6394bd49dMichael Graff "isc_mutex_init failed in new_adbhandle()");
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff ISC_EVENT_INIT(&h->event, sizeof (isc_event_t), 0, 0, 0, NULL, NULL,
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Copy bits from the entry into the newly allocated addrinfo. The entry
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * must be locked, and the reference count must be bumped up by one
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * if this function returns a valid pointer.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graffnew_adbaddrinfo(dns_adb_t *adb, dns_adbentry_t *entry)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Search for the name. NOTE: The bucket is kept locked on both
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * success and failure, so it must always be unlocked by the caller!
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * On the first call to this function, *bucketp must be set to
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * DNS_ADB_INVALIDBUCKET.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Grafffind_name_and_lock(dns_adb_t *adb, dns_name_t *name, int *bucketp)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Search for the address. NOTE: The bucket is kept locked on both
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * success and failure, so it must always be unlocked by the caller.
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * On the first call to this function, *bucketp must be set to
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * DNS_ADB_INVALIDBUCKET. This will cause a lock to occur. On
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * later calls (within the same "lock path") it can be left alone, so
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * if this function is called multiple times locking is only done if
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * the bucket changes.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Grafffind_entry_and_lock(dns_adb_t *adb, isc_sockaddr_t *addr, int *bucketp)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff if (isc_sockaddr_equal(addr, &entry->sockaddr))
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff isc_mutexblock_destroy(adb->entrylocks, DNS_ADBENTRYLIST_LENGTH);
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff isc_mutexblock_destroy(adb->namelocks, DNS_ADBNAMELIST_LENGTH);
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff isc_mem_put(adb->mctx, adb, sizeof (dns_adb_t));
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * Public functions.
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graffdns_adb_create(isc_mem_t *mem, dns_adb_t **newadb)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Initialize things here that cannot fail, and especially things
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * that must be NULL for the error return to work properly.
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff result = isc_condition_init(&adb->shutdown_cond);
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff * Initialize the bucket locks for names and elements.
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff * May as well initialize the list heads, too.
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff result = isc_mutexblock_init(adb->namelocks, DNS_ADBNAMELIST_LENGTH);
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff for (i = 0 ; i < DNS_ADBNAMELIST_LENGTH ; i++)
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff for (i = 0 ; i < DNS_ADBENTRYLIST_LENGTH ; i++)
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff result = isc_mutexblock_init(adb->entrylocks, DNS_ADBENTRYLIST_LENGTH);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Memory pools
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff#define MPINIT(t, p) do { \
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff result = isc_mempool_create(mem, sizeof (t), &(p)); \
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff#define MPINIT_LOCKED(t, p) do { \
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff isc_mempool_associatelock((p), &adb->mplock); \
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Normal return.
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff isc_mutexblock_destroy(adb->entrylocks, DNS_ADBENTRYLIST_LENGTH);
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff isc_mutexblock_destroy(adb->namelocks, DNS_ADBNAMELIST_LENGTH);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff REQUIRE(adbx != NULL && DNS_ADB_VALID(*adbx));
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff * If all lists are empty, destroy the memory used by this
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graffdns_adb_lookup(dns_adb_t *adb, isc_task_t *task, isc_taskaction_t *action,
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff void *arg, dns_rdataset_t *nsrdataset, dns_name_t *zone,
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff REQUIRE(nsrdataset->type == dns_rdatatype_ns);
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff * Bump our reference count to the adb, so it cannot go away while
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff * we're using it.
50b5857f1ad137624a18ce67b26b9941e316b007Michael Graff * Iterate through the nsrdataset. For each name found, do a search
50b5857f1ad137624a18ce67b26b9941e316b007Michael Graff * for it in our database.
50b5857f1ad137624a18ce67b26b9941e316b007Michael Graff * Possibilities: Note that these are not always exclusive.
50b5857f1ad137624a18ce67b26b9941e316b007Michael Graff * No name found. In this case, allocate a new name header,
50b5857f1ad137624a18ce67b26b9941e316b007Michael Graff * an initial namehook or two, and a job id. If any of these
50b5857f1ad137624a18ce67b26b9941e316b007Michael Graff * allocations fail, clean up and simply skip this address.
50b5857f1ad137624a18ce67b26b9941e316b007Michael Graff * Name found, valid addresses present. Allocate one addrinfo
50b5857f1ad137624a18ce67b26b9941e316b007Michael Graff * structure for each found and append it to the linked list
50b5857f1ad137624a18ce67b26b9941e316b007Michael Graff * of addresses for this header.
50b5857f1ad137624a18ce67b26b9941e316b007Michael Graff * Name found, queries pending. In this case, if a task was
50b5857f1ad137624a18ce67b26b9941e316b007Michael Graff * passed in, allocate a job id, attach it to the name's job
50b5857f1ad137624a18ce67b26b9941e316b007Michael Graff * list and remember to tell the caller that there will be
50b5857f1ad137624a18ce67b26b9941e316b007Michael Graff * more info coming later.
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff use_hints = dns_name_equal(zone, dns_rootname);
3c5148c4d98af51d6dcb449c6dbd45fe8c645f61Michael Graffdns_adb_refresh(dns_adb_t *adb, isc_task_t *task, isc_taskaction_t *action,
3c5148c4d98af51d6dcb449c6dbd45fe8c645f61Michael Graff void *arg, dns_rdataset_t *nsrdataset, dns_name_t *zone,
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graffdns_adb_deletename(dns_adb_t *adb, dns_name_t *host)
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * Find the name.
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff name = find_name_and_lock(adb, host, &name_bucket);
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * If any jobs are attached to this name, notify them that things
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * are going away by canceling their requests.
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * Loop through the name and kill any namehooks and entries they
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * Clean up the entry if needed.
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff /* XXX kill zoneinfo here */
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * Free the namehook
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff ISC_LIST_UNLINK(name->namehooks, namehook, link);
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * And lastly, unlink and free the name.
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff ISC_LIST_UNLINK(adb->names[name_bucket], name, link);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graffdns_adb_insert(dns_adb_t *adb, dns_name_t *host, isc_sockaddr_t *addr)
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff int name_bucket, addr_bucket; /* unlock if != DNS_ADB_INVALIDBUCKET */
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * First, see if the host is already in the database. If it is,
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * don't make a new host entry. If not, copy the name and name's
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * contents into our structure and allocate what we'll need
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * to attach things together.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff name = find_name_and_lock(adb, host, &name_bucket);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff result = dns_name_dup(host, adb->mctx, &name->name);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Now, while keeping the name locked, search for the address.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Three possibilities: One, the address doesn't exist.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Two, the address exists, but we aren't linked to it.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Three, the address exists and we are linked to it.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * (1) causes a new entry and namehook to be created.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * (2) causes only a new namehook.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * (3) is an error.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff entry = find_entry_and_lock(adb, addr, &addr_bucket);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Case (1): new entry and namehook.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Case (3): entry exists, we're linked.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Case (2): New namehook, link to entry from above.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff ISC_LIST_APPEND(name->namehooks, namehook, link);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * If needed, string up the name and entry. Do the name last, since
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * adding multiple addresses is simplified in that case.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff ISC_LIST_PREPEND(adb->names[name_bucket], name, link);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff ISC_LIST_PREPEND(adb->entries[addr_bucket], entry, link);
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graffdns_adb_cancel(dns_adb_t *adb, dns_adbhandle_t **handle)
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff REQUIRE(handle != NULL && DNS_ADBHANDLE_VALID(*handle));
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graffdns_adb_done(dns_adb_t *adb, dns_adbhandle_t **handle)
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff REQUIRE(handle != NULL && DNS_ADBHANDLE_VALID(*handle));
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * Lock the adb itself, lock all the name buckets, then lock all
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * the entry buckets. This should put the adb into a state where
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * nothing can change, so we can iterate through everything and
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * print at our leasure.
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff for (i = 0 ; i < DNS_ADBNAMELIST_LENGTH ; i++)
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff for (i = 0 ; i < DNS_ADBENTRYLIST_LENGTH ; i++)
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * Dump the names
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff for (i = 0 ; i < DNS_ADBNAMELIST_LENGTH ; i++) {
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * Dump the entries
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff for (i = 0 ; i < DNS_ADBENTRYLIST_LENGTH ; i++) {
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff fprintf(f, "\tWRONG BUCKET! lock_bucket %d\n",
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff tmpp = inet_ntop(sa->type.sa.sa_family, &sa->type.sa,
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff fprintf(f, "\trefcount %u flags %08x goodness %d"
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff " srtt %u host %s\n",
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff entry->refcount, entry->flags, entry->goodness,
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff * Unlock everything
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff for (i = 0 ; i < DNS_ADBENTRYLIST_LENGTH ; i++)
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff for (i = 0 ; i < DNS_ADBNAMELIST_LENGTH ; i++)
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff isc_buffer_init(&b, buf, sizeof (buf) - 1, ISC_BUFFERTYPE_TEXT);
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff fprintf(f, buf); /* safe, since names < 256 chars, and we memset */
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff fprintf(f, "\t\tHook %p -> entry %p\n", nh, nh->entry);