adb.c revision 64828244e04e86dfa40f0a4f0c05f27923da499d
d362465c77b375be2707bc83cebc731d0645d12dAutomatic Updater * Copyright (C) 1999 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Permission to use, copy, modify, and distribute this software for any
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * purpose with or without fee is hereby granted, provided that the above
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * Implementation notes
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * --------------------
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * In handles, if task == NULL, no events will be generated, and no events
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * have been sent. If task != NULL but taskaction == NULL, an event has been
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence * posted but not yet freed. If neigher are NULL, no event was posted.
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence#define DNS_ADB_VALID(x) ISC_MAGIC_VALID(x, DNS_ADB_MAGIC)
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence#define DNS_ADBNAME_MAGIC 0x6164624e /* adbN. */
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews#define DNS_ADBNAME_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBNAME_MAGIC)
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews#define DNS_ADBNAMEHOOK_MAGIC 0x61644e48 /* adNH. */
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews#define DNS_ADBNAMEHOOK_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBNAMEHOOK_MAGIC)
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews#define DNS_ADBZONEINFO_MAGIC 0x6164625a /* adbZ. */
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews#define DNS_ADBZONEINFO_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBZONEINFO_MAGIC)
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews#define DNS_ADBENTRY_MAGIC 0x61646245 /* adbE. */
28fc90e6c81338c5f34e065fdda49d320e362583Mark Andrews#define DNS_ADBENTRY_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBENTRY_MAGIC)
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * Lengths of lists needs to be powers of two.
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff#define DNS_ADBNAMELIST_LENGTH 16 /* how many buckets for names */
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff#define DNS_ADBENTRYLIST_LENGTH 16 /* how many buckets for addresses */
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff#define FREE_ITEMS 16 /* free count for memory pools */
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff#define FILL_COUNT 8 /* fill count for memory pools */
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff#define DNS_ADB_INVALIDBUCKET (-1) /* invalid bucket address */
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Grafftypedef ISC_LIST(dns_adbname_t) dns_adbnamelist_t;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Grafftypedef struct dns_adbnamehook dns_adbnamehook_t;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Grafftypedef struct dns_adbzoneinfo dns_adbzoneinfo_t;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Grafftypedef ISC_LIST(dns_adbentry_t) dns_adbentrylist_t;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews unsigned int magic;
19d1b1667d073850d4366352aaf8319efc5debeeBrian Wellington * Bucketized locks and lists for names.
8126e45e8cc3fd54517c034dd30a42928f5206e3Andreas Gustafsson dns_adbnamelist_t names[DNS_ADBNAMELIST_LENGTH];
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * Bucketized locks for entries.
046a9aca49bdc25bd57d75fd0dd34c021722f095Mark Andrews dns_adbentrylist_t entries[DNS_ADBENTRYLIST_LENGTH];
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_mutex_t entrylocks[DNS_ADBENTRYLIST_LENGTH];
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * List of running and idle handles.
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * dns_adbnamehook_t
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews * This is a small widget that dangles off a dns_adbname_t. It contains a
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews * pointer to the address information about this host, and a link to the next
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * namehook that will contain the next address this host has.
559bb1016f1b00a3661cb2790dc837a977057b86Mark Andrews unsigned int magic;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews * dns_adbzoneinfo_t
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews * This is a small widget that holds zone-specific information about an
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson * address. Currently limited to lameness, but could just as easily be
8126e45e8cc3fd54517c034dd30a42928f5206e3Andreas Gustafsson * extended to other types of information about zones.
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews unsigned int magic;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews * An address entry. It holds quite a bit of information about addresses,
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews * including edns state, rtt, and of course the address of the host.
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews unsigned int magic;
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews unsigned int refcount;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews unsigned int flags;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews unsigned int srtt;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Internal functions (and prototypes).
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic dns_adbnamehook_t *new_adbnamehook(dns_adb_t *, dns_adbentry_t *);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static dns_adbzoneinfo_t *new_adbzoneinfo(dns_adb_t *);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static dns_adbentry_t *new_adbentry(dns_adb_t *);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic dns_adbhandle_t *new_adbhandle(dns_adb_t *);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic dns_adbaddrinfo_t *new_adbaddrinfo(dns_adb_t *, dns_adbentry_t *);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic dns_adbname_t *find_name_and_lock(dns_adb_t *, dns_name_t *, int *);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic dns_adbentry_t *find_entry_and_lock(dns_adb_t *, isc_sockaddr_t *,
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic void print_dns_name(FILE *, dns_name_t *);
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrewsstatic void print_namehook_list(FILE *, dns_adbname_t *);
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrewsfree_adbname(dns_adb_t *adb, dns_adbname_t **name)
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews INSIST(name != NULL && DNS_ADBNAME_VALID(*name));
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsnew_adbnamehook(dns_adb_t *adb, dns_adbentry_t *entry)
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellingtonfree_adbnamehook(dns_adb_t *adb, dns_adbnamehook_t **namehook)
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington INSIST(namehook != NULL && DNS_ADBNAMEHOOK_VALID(*namehook));
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrewsfree_adbentry(dns_adb_t *adb, dns_adbentry_t **entry)
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews INSIST(entry != NULL && DNS_ADBENTRY_VALID(*entry));
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews INSIST(e->lock_bucket == DNS_ADB_INVALIDBUCKET);
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews * public members
4be19dcd14cea678511f1d1b269ab89273e987eeMark Andrews * private members
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews "isc_mutex_init failed in new_adbhandle()");
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews ISC_EVENT_INIT(&h->event, sizeof (isc_event_t), 0, 0, 0, NULL, NULL,
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews * Copy bits from the entry into the newly allocated addrinfo. The entry
8b61d2012063306528286680bd9f086fa868d86eMark Andrews * must be locked, and the reference count must be bumped up by one
8b61d2012063306528286680bd9f086fa868d86eMark Andrews * if this function returns a valid pointer.
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsnew_adbaddrinfo(dns_adb_t *adb, dns_adbentry_t *entry)
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews * Search for the name. NOTE: The bucket is kept locked on both
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * success and failure, so it must always be unlocked by the caller!
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * On the first call to this function, *bucketp must be set to
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * DNS_ADB_INVALIDBUCKET.
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsfind_name_and_lock(dns_adb_t *adb, dns_name_t *name, int *bucketp)
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews unsigned int bucket;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * Search for the address. NOTE: The bucket is kept locked on both
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * success and failure, so it must always be unlocked by the caller.
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews * On the first call to this function, *bucketp must be set to
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews * DNS_ADB_INVALIDBUCKET. This will cause a lock to occur. On
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews * later calls (within the same "lock path") it can be left alone, so
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews * if this function is called multiple times locking is only done if
8b61d2012063306528286680bd9f086fa868d86eMark Andrews * the bucket changes.
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrewsfind_entry_and_lock(dns_adb_t *adb, isc_sockaddr_t *addr, int *bucketp)
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews if (isc_sockaddr_equal(addr, &entry->sockaddr))
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_mutexblock_destroy(adb->entrylocks, DNS_ADBENTRYLIST_LENGTH);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_mutexblock_destroy(adb->namelocks, DNS_ADBNAMELIST_LENGTH);
046a9aca49bdc25bd57d75fd0dd34c021722f095Mark Andrews isc_mem_put(adb->mctx, adb, sizeof (dns_adb_t));
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington * Public functions.
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellingtondns_adb_create(isc_mem_t *mem, dns_adb_t **newadb)
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington REQUIRE(newadb != NULL && *newadb == NULL);
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington adb = isc_mem_get(mem, sizeof (dns_adb_t));
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington * Initialize things here that cannot fail, and especially things
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington * that must be NULL for the error return to work properly.
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington * Initialize the bucket locks for names and elements.
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington * May as well initialize the list heads, too.
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews result = isc_mutexblock_init(adb->namelocks, DNS_ADBNAMELIST_LENGTH);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews for (i = 0 ; i < DNS_ADBNAMELIST_LENGTH ; i++)
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews for (i = 0 ; i < DNS_ADBENTRYLIST_LENGTH ; i++)
97f26b88f62b10a9c26a91ebe8387d2e498c2d00Andreas Gustafsson result = isc_mutexblock_init(adb->entrylocks, DNS_ADBENTRYLIST_LENGTH);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * Memory pools
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews#define MPINIT(t, p) do { \
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews result = isc_mempool_create(mem, sizeof (t), &(p)); \
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews#define MPINIT_LOCKED(t, p) do { \
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews isc_mempool_associatelock((p), &adb->mplock); \
2b66a51a7d72e9cc07917fb583ad528b0539d2a3Mark Andrews * Normal return.
9de0f9b0aed432ee357dbba8d1d807525f4b6d4aMark Andrews isc_mutexblock_destroy(adb->entrylocks, DNS_ADBENTRYLIST_LENGTH);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews isc_mutexblock_destroy(adb->namelocks, DNS_ADBNAMELIST_LENGTH);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * XXX Need to wait here until the adb is fully shut down.
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * If all lists are empty, destroy the memory used by this
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * adb. XXX Need to implement this.
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrewsdns_adb_lookup(dns_adb_t *adb, isc_task_t *task, isc_taskaction_t *action,
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews void *arg, dns_rdataset_t *nsrdataset, dns_name_t *zone,
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * Iterate through the nsrdataset. For each name found, do a search
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * for it in our database.
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * Possibilities: Note that these are not always exclusive.
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * No name found. In this case, allocate a new name header,
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * an initial namehook or two, and a job id. If any of these
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * allocations fail, clean up and simply skip this address.
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * Name found, valid addresses present. Allocate one addrinfo
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * structure for each found and append it to the linked list
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * of addresses for this header.
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * Name found, queries pending. In this case, if a task was
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * passed in, allocate a job id, attach it to the name's job
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * list and remember to tell the caller that there will be
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * more info coming later.
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrewsdns_adb_refresh(dns_adb_t *adb, isc_task_t *task, isc_taskaction_t *action,
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews void *arg, dns_rdataset_t *nsrdataset, dns_name_t *zone,
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrewsdns_adb_deletename(dns_adb_t *adb, dns_name_t *host)
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff * Find the name.
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews name = find_name_and_lock(adb, host, &name_bucket);
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff * If any jobs are attached to this name, notify them that things
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff * are going away by canceling their requests.
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff * Loop through the name and kill any namehooks and entries they
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff * Clean up the entry if needed.
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews /* XXX kill zoneinfo here */
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews * Free the namehook
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews ISC_LIST_UNLINK(name->namehooks, namehook, link);
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington * And lastly, unlink and free the name.
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff ISC_LIST_UNLINK(adb->names[name_bucket], name, link);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrewsdns_adb_insert(dns_adb_t *adb, dns_name_t *host, isc_sockaddr_t *addr)
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews int name_bucket, addr_bucket; /* unlock if != DNS_ADB_INVALIDBUCKET */
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews * First, see if the host is already in the database. If it is,
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * don't make a new host entry. If not, copy the name and name's
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * contents into our structure and allocate what we'll need
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * to attach things together.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 name = find_name_and_lock(adb, host, &name_bucket);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_name_dup(host, adb->mctx, &name->name);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews * Now, while keeping the name locked, search for the address.
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews * Three possibilities: One, the address doesn't exist.
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews * Two, the address exists, but we aren't linked to it.
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews * Three, the address exists and we are linked to it.
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews * (1) causes a new entry and namehook to be created.
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews * (2) causes only a new namehook.
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews * (3) is an error.
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews entry = find_entry_and_lock(adb, addr, &addr_bucket);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews * Case (1): new entry and namehook.
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews * Case (3): entry exists, we're linked.
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews * Case (2): New namehook, link to entry from above.
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington ISC_LIST_APPEND(name->namehooks, namehook, link);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews * If needed, string up the name and entry. Do the name last, since
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews * adding multiple addresses is simplified in that case.
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews ISC_LIST_PREPEND(adb->names[name_bucket], name, link);
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington ISC_LIST_PREPEND(adb->entries[addr_bucket], entry, link);
04c22ceaf2d3812eaab69d79958d0e0d62048cd2Mark Andrewsdns_adb_cancel(dns_adb_t *adb, dns_adbhandle_t **handle)
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff REQUIRE(handle != NULL && DNS_ADBHANDLE_VALID(*handle));
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrewsdns_adb_done(dns_adb_t *adb, dns_adbhandle_t **handle)
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews REQUIRE(handle != NULL && DNS_ADBHANDLE_VALID(*handle));
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff * Lock the adb itself, lock all the name buckets, then lock all
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff * the entry buckets. This should put the adb into a state where
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * nothing can change, so we can iterate through everything and
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews * print at our leasure.
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews for (i = 0 ; i < DNS_ADBNAMELIST_LENGTH ; i++)
94baac869a70b529a24ff23d8dc899faa5d4fdc4Brian Wellington for (i = 0 ; i < DNS_ADBENTRYLIST_LENGTH ; i++)
04c22ceaf2d3812eaab69d79958d0e0d62048cd2Mark Andrews * Dump the names
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews for (i = 0 ; i < DNS_ADBNAMELIST_LENGTH ; i++) {
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff * Dump the entries
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff for (i = 0 ; i < DNS_ADBENTRYLIST_LENGTH ; i++) {
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews tmpp = inet_ntop(sa->type.sa.sa_family, &sa->type.sa,
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews fprintf(f, "\trefcount %u flags %08x goodness %d"
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews " srtt %u host %s\n",
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff entry->refcount, entry->flags, entry->goodness,
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * Unlock everything
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews for (i = 0 ; i < DNS_ADBENTRYLIST_LENGTH ; i++)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 for (i = 0 ; i < DNS_ADBNAMELIST_LENGTH ; i++)
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson isc_buffer_init(&b, buf, sizeof (buf) - 1, ISC_BUFFERTYPE_TEXT);
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews fprintf(f, buf); /* safe, since names < 256 chars, and we memset */
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews fprintf(f, "\t\tHook %p -> entry %p\n", nh, nh->entry);