adb.c revision 64828244e04e86dfa40f0a4f0c05f27923da499d
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews/*
d362465c77b375be2707bc83cebc731d0645d12dAutomatic Updater * Copyright (C) 1999 Internet Software Consortium.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
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.
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews *
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
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * SOFTWARE.
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews */
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
2e20dea9fc0a84217c7debdef8b4b6c6f04d3998Mark Andrews/*
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * Implementation notes
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * --------------------
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence *
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.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence *
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews */
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews#include <config.h>
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington#include <stdio.h>
e43b9a20054cdda6946ab758e1c2005f2b25641aBrian Wellington#include <string.h>
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews#include <isc/assertions.h>
8b61d2012063306528286680bd9f086fa868d86eMark Andrews#include <isc/magic.h>
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews#include <isc/mutex.h>
19d1b1667d073850d4366352aaf8319efc5debeeBrian Wellington#include <isc/mutexblock.h>
19d1b1667d073850d4366352aaf8319efc5debeeBrian Wellington#include <isc/event.h>
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence#include <dns/address.h>
19d1b1667d073850d4366352aaf8319efc5debeeBrian Wellington#include <dns/name.h>
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence#include "../isc/util.h"
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews#define DNS_ADB_MAGIC 0x44616462 /* Dadb. */
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)
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff/*
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * Lengths of lists needs to be powers of two.
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews */
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
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff#define FREE_ITEMS 16 /* free count for memory pools */
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff#define FILL_COUNT 8 /* fill count for memory pools */
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff#define DNS_ADB_INVALIDBUCKET (-1) /* invalid bucket address */
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Grafftypedef struct dns_adbname dns_adbname_t;
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
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstruct dns_adb {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews unsigned int magic;
28fc90e6c81338c5f34e065fdda49d320e362583Mark Andrews
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff isc_mutex_t lock;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff isc_mem_t *mctx;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff isc_mutex_t mplock;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff isc_mempool_t *nmp; /* dns_adbname_t */
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff isc_mempool_t *nhmp; /* dns_adbnamehook_t */
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff isc_mempool_t *zimp; /* dns_adbzoneinfo_t */
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff isc_mempool_t *emp; /* dns_adbentry_t */
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff isc_mempool_t *ahmp; /* dns_adbhandle_t */
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff isc_mempool_t *aimp; /* dns_adbaddrinfo_t */
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington /*
19d1b1667d073850d4366352aaf8319efc5debeeBrian Wellington * Bucketized locks and lists for names.
8126e45e8cc3fd54517c034dd30a42928f5206e3Andreas Gustafsson */
8126e45e8cc3fd54517c034dd30a42928f5206e3Andreas Gustafsson dns_adbnamelist_t names[DNS_ADBNAMELIST_LENGTH];
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews isc_mutex_t namelocks[DNS_ADBNAMELIST_LENGTH];
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews /*
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * Bucketized locks for entries.
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews */
046a9aca49bdc25bd57d75fd0dd34c021722f095Mark Andrews dns_adbentrylist_t entries[DNS_ADBENTRYLIST_LENGTH];
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_mutex_t entrylocks[DNS_ADBENTRYLIST_LENGTH];
8068ceb2a9cc56d18016c3cd94a09e4bb0bc7b0dAndreas Gustafsson
bdfaef63f576f810fab27f64395faccf2fcd9434Francis Dupont /*
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * List of running and idle handles.
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews */
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews ISC_LIST(dns_adbhandle_t) running_handles;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews ISC_LIST(dns_adbhandle_t) idle_handles;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews};
046a9aca49bdc25bd57d75fd0dd34c021722f095Mark Andrews
046a9aca49bdc25bd57d75fd0dd34c021722f095Mark Andrewsstruct dns_adbname {
0ad8ee89c532951a55b7de25317eeca2c3b2ed63Andreas Gustafsson unsigned int magic;
0ad8ee89c532951a55b7de25317eeca2c3b2ed63Andreas Gustafsson dns_name_t name;
f53848e17123569387b279578f0100dca5407da5Mark Andrews ISC_LIST(dns_adbnamehook_t) namehooks;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews ISC_LINK(dns_adbname_t) link;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews};
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews/*
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * dns_adbnamehook_t
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews *
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.
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews */
59abb512d344bfa09012cc11b7d814966f035da4Mark Andrewsstruct dns_adbnamehook {
559bb1016f1b00a3661cb2790dc837a977057b86Mark Andrews unsigned int magic;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews dns_adbentry_t *entry;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews ISC_LINK(dns_adbnamehook_t) link;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews};
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews/*
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews * dns_adbzoneinfo_t
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews *
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 */
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstruct dns_adbzoneinfo {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews unsigned int magic;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews dns_name_t *zone;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews unsigned int lame_timer;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews ISC_LINK(dns_adbzoneinfo_t) link;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews};
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff/*
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.
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews */
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrewsstruct dns_adbentry {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews unsigned int magic;
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews int lock_bucket;
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews unsigned int refcount;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews unsigned int flags;
8b61d2012063306528286680bd9f086fa868d86eMark Andrews int goodness; /* bad <= 0 < good */
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews unsigned int srtt;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews isc_sockaddr_t sockaddr;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews ISC_LIST(dns_adbzoneinfo_t) zoneinfo;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff ISC_LINK(dns_adbentry_t) link;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff};
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews/*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Internal functions (and prototypes).
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic dns_adbname_t *new_adbname(dns_adb_t *);
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 Andrews int *);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic void print_dns_name(FILE *, dns_name_t *);
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrewsstatic void print_namehook_list(FILE *, dns_adbname_t *);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic dns_adbname_t *
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsnew_adbname(dns_adb_t *adb)
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews{
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews dns_adbname_t *name;
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff name = isc_mempool_get(adb->nmp);
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews if (name == NULL)
5e387b9ce6bafdfadedb5b34e4c33a4404e5d589Brian Wellington return (NULL);
5e387b9ce6bafdfadedb5b34e4c33a4404e5d589Brian Wellington
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews name->magic = DNS_ADBNAME_MAGIC;
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews dns_name_init(&name->name, NULL);
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews ISC_LIST_INIT(name->namehooks);
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews ISC_LINK_INIT(name, link);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews return (name);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff}
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic void
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrewsfree_adbname(dns_adb_t *adb, dns_adbname_t **name)
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews{
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews dns_adbname_t *n;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews INSIST(name != NULL && DNS_ADBNAME_VALID(*name));
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews n = *name;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews *name = NULL;
bdfaef63f576f810fab27f64395faccf2fcd9434Francis Dupont
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews INSIST(ISC_LIST_EMPTY(n->namehooks));
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews INSIST(!ISC_LINK_LINKED(n, link));
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews n->magic = 0;
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews dns_name_free(&n->name, adb->mctx);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews isc_mempool_put(adb->nmp, n);
8b61d2012063306528286680bd9f086fa868d86eMark Andrews}
8b61d2012063306528286680bd9f086fa868d86eMark Andrews
8b61d2012063306528286680bd9f086fa868d86eMark Andrewsstatic dns_adbnamehook_t *
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsnew_adbnamehook(dns_adb_t *adb, dns_adbentry_t *entry)
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews{
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews dns_adbnamehook_t *nh;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews nh = isc_mempool_get(adb->nhmp);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews if (nh == NULL)
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews return (NULL);
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington nh->magic = DNS_ADBNAMEHOOK_MAGIC;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews nh->entry = entry;
8b61d2012063306528286680bd9f086fa868d86eMark Andrews ISC_LINK_INIT(nh, link);
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington return (nh);
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington}
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellingtonstatic void
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellingtonfree_adbnamehook(dns_adb_t *adb, dns_adbnamehook_t **namehook)
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington{
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington dns_adbnamehook_t *nh;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington INSIST(namehook != NULL && DNS_ADBNAMEHOOK_VALID(*namehook));
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington nh = *namehook;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington *namehook = NULL;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington INSIST(nh->entry == NULL);
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington INSIST(!ISC_LINK_LINKED(nh, link));
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington nh->magic = 0;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington isc_mempool_put(adb->nhmp, nh);
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington}
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic dns_adbzoneinfo_t *
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsnew_adbzoneinfo(dns_adb_t *adb)
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews{
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews dns_adbzoneinfo_t *zi;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews zi = isc_mempool_get(adb->zimp);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews if (zi == NULL)
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington return (NULL);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
8b61d2012063306528286680bd9f086fa868d86eMark Andrews zi->magic = DNS_ADBZONEINFO_MAGIC;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews zi->zone = NULL;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews zi->lame_timer = 0;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews ISC_LINK_INIT(zi, link);
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews return (zi);
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews}
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrewsstatic dns_adbentry_t *
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrewsnew_adbentry(dns_adb_t *adb)
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews{
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews dns_adbentry_t *e;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews e = isc_mempool_get(adb->emp);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews if (e == NULL)
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews return (NULL);
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews e->magic = DNS_ADBENTRY_MAGIC;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews e->lock_bucket = DNS_ADB_INVALIDBUCKET;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews e->refcount = 0;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews e->flags = 0;
4be19dcd14cea678511f1d1b269ab89273e987eeMark Andrews e->goodness = 0;
4be19dcd14cea678511f1d1b269ab89273e987eeMark Andrews e->srtt = 0;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews ISC_LIST_INIT(e->zoneinfo);
4be19dcd14cea678511f1d1b269ab89273e987eeMark Andrews ISC_LINK_INIT(e, link);
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews return (e);
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews}
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrewsstatic void
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrewsfree_adbentry(dns_adb_t *adb, dns_adbentry_t **entry)
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews{
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews dns_adbentry_t *e;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews INSIST(entry != NULL && DNS_ADBENTRY_VALID(*entry));
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews e = *entry;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington *entry = NULL;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews INSIST(e->lock_bucket == DNS_ADB_INVALIDBUCKET);
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews INSIST(e->refcount == 0);
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews INSIST(ISC_LIST_EMPTY(e->zoneinfo));
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews INSIST(!ISC_LINK_LINKED(e, link));
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews
8b61d2012063306528286680bd9f086fa868d86eMark Andrews e->magic = 0;
8b61d2012063306528286680bd9f086fa868d86eMark Andrews isc_mempool_put(adb->emp, e);
8b61d2012063306528286680bd9f086fa868d86eMark Andrews}
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrewsstatic dns_adbhandle_t *
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrewsnew_adbhandle(dns_adb_t *adb)
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews{
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews dns_adbhandle_t *h;
f53848e17123569387b279578f0100dca5407da5Mark Andrews isc_result_t result;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews h = isc_mempool_get(adb->ahmp);
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews if (h == NULL)
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews return (NULL);
8b61d2012063306528286680bd9f086fa868d86eMark Andrews
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews /*
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews * public members
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews */
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews h->magic = 0;
8b61d2012063306528286680bd9f086fa868d86eMark Andrews h->adb = adb;
8b61d2012063306528286680bd9f086fa868d86eMark Andrews ISC_LIST_INIT(h->list);
8b61d2012063306528286680bd9f086fa868d86eMark Andrews
8b61d2012063306528286680bd9f086fa868d86eMark Andrews /*
4be19dcd14cea678511f1d1b269ab89273e987eeMark Andrews * private members
4be19dcd14cea678511f1d1b269ab89273e987eeMark Andrews */
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews result = isc_mutex_init(&h->lock);
4be19dcd14cea678511f1d1b269ab89273e987eeMark Andrews if (result != ISC_R_SUCCESS) {
4be19dcd14cea678511f1d1b269ab89273e987eeMark Andrews UNEXPECTED_ERROR(__FILE__, __LINE__,
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews "isc_mutex_init failed in new_adbhandle()");
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews isc_mempool_put(adb->ahmp, h);
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews return (NULL);
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews }
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews h->task = NULL;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews h->taskaction = NULL;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews h->arg = NULL;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews ISC_LINK_INIT(h, link);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews ISC_EVENT_INIT(&h->event, sizeof (isc_event_t), 0, 0, 0, NULL, NULL,
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington NULL, NULL, h);
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews h->magic = DNS_ADBHANDLE_MAGIC;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews return (h);
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews}
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews/*
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.
8b61d2012063306528286680bd9f086fa868d86eMark Andrews */
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic dns_adbaddrinfo_t *
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsnew_adbaddrinfo(dns_adb_t *adb, dns_adbentry_t *entry)
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews{
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews dns_adbaddrinfo_t *ai;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews ai = isc_mempool_get(adb->aimp);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews if (ai == NULL)
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews return (NULL);
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews ai->magic = DNS_ADBADDRINFO_MAGIC;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews ai->sockaddr = &entry->sockaddr;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews ai->goodness = entry->goodness;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews ai->srtt = entry->srtt;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews ai->flags = entry->flags;
8b61d2012063306528286680bd9f086fa868d86eMark Andrews ai->entry = entry;
8b61d2012063306528286680bd9f086fa868d86eMark Andrews ISC_LINK_INIT(ai, link);
8b61d2012063306528286680bd9f086fa868d86eMark Andrews
8b61d2012063306528286680bd9f086fa868d86eMark Andrews return (ai);
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews}
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews/*
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!
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews *
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * On the first call to this function, *bucketp must be set to
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * DNS_ADB_INVALIDBUCKET.
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews */
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic dns_adbname_t *
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsfind_name_and_lock(dns_adb_t *adb, dns_name_t *name, int *bucketp)
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews{
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews dns_adbname_t *adbname;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews unsigned int bucket;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews bucket = dns_name_hash(name, ISC_FALSE);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews bucket &= (DNS_ADBNAMELIST_LENGTH - 1);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
8b61d2012063306528286680bd9f086fa868d86eMark Andrews LOCK(&adb->namelocks[bucket]);
8b61d2012063306528286680bd9f086fa868d86eMark Andrews *bucketp = (int)bucket;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews adbname = ISC_LIST_HEAD(adb->names[bucket]);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews while (adbname != NULL) {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews if (dns_name_equal(name, &adbname->name))
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews return (adbname);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews adbname = ISC_LIST_NEXT(adbname, link);
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff }
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff return (NULL);
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff}
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews/*
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.
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews *
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.
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews */
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrewsstatic dns_adbentry_t *
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrewsfind_entry_and_lock(dns_adb_t *adb, isc_sockaddr_t *addr, int *bucketp)
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews{
5e387b9ce6bafdfadedb5b34e4c33a4404e5d589Brian Wellington dns_adbentry_t *entry;
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews int bucket;
5e387b9ce6bafdfadedb5b34e4c33a4404e5d589Brian Wellington
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews bucket = isc_sockaddr_hash(addr, ISC_TRUE);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews bucket &= (DNS_ADBENTRYLIST_LENGTH - 1);
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews if (*bucketp == DNS_ADB_INVALIDBUCKET) {
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews LOCK(&adb->entrylocks[bucket]);
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews *bucketp = bucket;
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson } else if (*bucketp != bucket) {
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews UNLOCK(&adb->entrylocks[*bucketp]);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews LOCK(&adb->entrylocks[bucket]);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews *bucketp = bucket;
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews }
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews
8b61d2012063306528286680bd9f086fa868d86eMark Andrews entry = ISC_LIST_HEAD(adb->entries[bucket]);
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews while (entry != NULL) {
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews if (isc_sockaddr_equal(addr, &entry->sockaddr))
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews return (entry);
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews entry = ISC_LIST_NEXT(entry, link);
668eb43f1f24c887b6972f6a1610b4b38b281080Brian Wellington }
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews return (NULL);
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews}
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrewsstatic void
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrewsdestroy(dns_adb_t *adb)
046a9aca49bdc25bd57d75fd0dd34c021722f095Mark Andrews{
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 adb->magic = 0;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
8b61d2012063306528286680bd9f086fa868d86eMark Andrews isc_mempool_destroy(&adb->nmp);
8b61d2012063306528286680bd9f086fa868d86eMark Andrews isc_mempool_destroy(&adb->nhmp);
390b2077fc751105e40174ceaa1ce34ef06e7dd4Mark Andrews isc_mempool_destroy(&adb->zimp);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_mempool_destroy(&adb->emp);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_mempool_destroy(&adb->ahmp);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_mempool_destroy(&adb->aimp);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_mutexblock_destroy(adb->entrylocks, DNS_ADBENTRYLIST_LENGTH);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_mutexblock_destroy(adb->namelocks, DNS_ADBNAMELIST_LENGTH);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_mutex_destroy(&adb->lock);
046a9aca49bdc25bd57d75fd0dd34c021722f095Mark Andrews isc_mutex_destroy(&adb->mplock);
046a9aca49bdc25bd57d75fd0dd34c021722f095Mark Andrews
046a9aca49bdc25bd57d75fd0dd34c021722f095Mark Andrews isc_mem_put(adb->mctx, adb, sizeof (dns_adb_t));
046a9aca49bdc25bd57d75fd0dd34c021722f095Mark Andrews}
046a9aca49bdc25bd57d75fd0dd34c021722f095Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews/*
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington * Public functions.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellingtonisc_result_t
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellingtondns_adb_create(isc_mem_t *mem, dns_adb_t **newadb)
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington{
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington dns_adb_t *adb;
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington isc_result_t result;
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington int i;
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington REQUIRE(mem != NULL);
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington REQUIRE(newadb != NULL && *newadb == NULL);
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington adb = isc_mem_get(mem, sizeof (dns_adb_t));
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington if (adb == NULL)
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington return (ISC_R_NOMEMORY);
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington /*
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 */
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington adb->magic = 0;
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington adb->nmp = NULL;
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington adb->nhmp = NULL;
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington adb->zimp = NULL;
8126e45e8cc3fd54517c034dd30a42928f5206e3Andreas Gustafsson adb->emp = NULL;
8126e45e8cc3fd54517c034dd30a42928f5206e3Andreas Gustafsson adb->ahmp = NULL;
8126e45e8cc3fd54517c034dd30a42928f5206e3Andreas Gustafsson adb->aimp = NULL;
8126e45e8cc3fd54517c034dd30a42928f5206e3Andreas Gustafsson
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff result = isc_mutex_init(&adb->lock);
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington if (result != ISC_R_SUCCESS)
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington goto fail1;
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington result = isc_mutex_init(&adb->mplock);
ac6afcd0caf72aaa2a537e0003de30b363b4a68bBrian Wellington if (result != ISC_R_SUCCESS)
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington goto fail1;
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington /*
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington * Initialize the bucket locks for names and elements.
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington * May as well initialize the list heads, too.
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews */
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews result = isc_mutexblock_init(adb->namelocks, DNS_ADBNAMELIST_LENGTH);
97f26b88f62b10a9c26a91ebe8387d2e498c2d00Andreas Gustafsson if (result != ISC_R_SUCCESS)
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews goto fail1;
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews for (i = 0 ; i < DNS_ADBNAMELIST_LENGTH ; i++)
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews ISC_LIST_INIT(adb->names[i]);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews for (i = 0 ; i < DNS_ADBENTRYLIST_LENGTH ; i++)
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews ISC_LIST_INIT(adb->entries[i]);
97f26b88f62b10a9c26a91ebe8387d2e498c2d00Andreas Gustafsson result = isc_mutexblock_init(adb->entrylocks, DNS_ADBENTRYLIST_LENGTH);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews if (result != ISC_R_SUCCESS)
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews goto fail2;
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews /*
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * Memory pools
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews */
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews#define MPINIT(t, p) do { \
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews result = isc_mempool_create(mem, sizeof (t), &(p)); \
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews if (result != ISC_R_SUCCESS) \
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews goto fail3; \
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews isc_mempool_setfreemax((p), FREE_ITEMS); \
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews isc_mempool_setfillcount((p), FILL_COUNT); \
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews} while (0)
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews#define MPINIT_LOCKED(t, p) do { \
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews MPINIT(t, p); \
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews isc_mempool_associatelock((p), &adb->mplock); \
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews} while (0)
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews MPINIT_LOCKED(dns_adbname_t, adb->nmp);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews MPINIT_LOCKED(dns_adbnamehook_t, adb->nhmp);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews MPINIT_LOCKED(dns_adbzoneinfo_t, adb->zimp);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews MPINIT_LOCKED(dns_adbentry_t, adb->emp);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews MPINIT_LOCKED(dns_adbhandle_t, adb->ahmp);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews MPINIT_LOCKED(dns_adbaddrinfo_t, adb->aimp);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews#undef MPINIT
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews#undef MPINIT_LOCKED
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews /*
2b66a51a7d72e9cc07917fb583ad528b0539d2a3Mark Andrews * Normal return.
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews */
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews adb->mctx = mem;
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews adb->magic = DNS_ADB_MAGIC;
9de0f9b0aed432ee357dbba8d1d807525f4b6d4aMark Andrews *newadb = adb;
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews return (ISC_R_SUCCESS);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews fail3: /* clean up entrylocks */
9de0f9b0aed432ee357dbba8d1d807525f4b6d4aMark Andrews isc_mutexblock_destroy(adb->entrylocks, DNS_ADBENTRYLIST_LENGTH);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews fail2: /* clean up namelocks */
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews isc_mutexblock_destroy(adb->namelocks, DNS_ADBNAMELIST_LENGTH);
2b66a51a7d72e9cc07917fb583ad528b0539d2a3Mark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews fail1: /* clean up only allocated memory */
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews if (adb->nmp != NULL)
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews isc_mempool_destroy(&adb->nmp);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews if (adb->nhmp != NULL)
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews isc_mempool_destroy(&adb->nhmp);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews if (adb->zimp != NULL)
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews isc_mempool_destroy(&adb->zimp);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews if (adb->emp != NULL)
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews isc_mempool_destroy(&adb->emp);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews if (adb->ahmp != NULL)
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews isc_mempool_destroy(&adb->ahmp);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews if (adb->aimp != NULL)
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews isc_mempool_destroy(&adb->aimp);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews isc_mutex_destroy(&adb->lock);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews isc_mutex_destroy(&adb->mplock);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews isc_mem_put(mem, adb, sizeof (dns_adb_t));
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews return (result);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews}
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrewsvoid
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrewsdns_adb_destroy(dns_adb_t **adbx)
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews{
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews dns_adb_t *adb;
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews REQUIRE(adbx != NULL && DNS_ADB_VALID(*adbx));
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews adb = *adbx;
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews *adbx = NULL;
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews /*
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * XXX Need to wait here until the adb is fully shut down.
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews */
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews /*
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * If all lists are empty, destroy the memory used by this
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * adb. XXX Need to implement this.
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews */
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews destroy(adb);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews}
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrewsisc_result_t
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 dns_adbhandle_t **handle)
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews{
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews REQUIRE(DNS_ADB_VALID(adb));
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews if (task != NULL) {
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews REQUIRE(action != NULL);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews }
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews REQUIRE(nsrdataset != NULL);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews REQUIRE(zone != NULL);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews REQUIRE(handle != NULL && *handle == NULL);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews /*
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * Iterate through the nsrdataset. For each name found, do a search
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * for it in our database.
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews *
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * Possibilities: Note that these are not always exclusive.
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews *
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 *
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 *
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 Andrews */
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews return (ISC_R_NOTIMPLEMENTED);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews}
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrewsisc_result_t
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 Andrews dns_adbhandle_t *handle)
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews{
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews REQUIRE(DNS_ADB_VALID(adb));
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews if (task != NULL) {
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews REQUIRE(action != NULL);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews }
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews REQUIRE(nsrdataset != NULL);
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews REQUIRE(zone != NULL);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews REQUIRE(DNS_ADBHANDLE_VALID(handle));
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews return (ISC_R_NOTIMPLEMENTED);
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews}
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrewsisc_result_t
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrewsdns_adb_deletename(dns_adb_t *adb, dns_name_t *host)
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews{
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews int name_bucket, addr_bucket;
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews dns_adbname_t *name;
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews dns_adbentry_t *entry;
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews dns_adbnamehook_t *namehook;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews REQUIRE(DNS_ADB_VALID(adb));
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews REQUIRE(host != NULL);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews name = NULL;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews entry = NULL;
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews namehook = NULL;
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff /*
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff * Find the name.
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews */
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews name_bucket = DNS_ADB_INVALIDBUCKET;
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews name = find_name_and_lock(adb, host, &name_bucket);
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews if (name == NULL) {
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews UNLOCK(&adb->namelocks[name_bucket]);
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff return (ISC_R_NOTFOUND);
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff }
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews /* XXX
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 */
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff /*
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff * Loop through the name and kill any namehooks and entries they
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff * point to.
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff */
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff addr_bucket = DNS_ADB_INVALIDBUCKET;
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff namehook = ISC_LIST_HEAD(name->namehooks);
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff while (namehook != NULL) {
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff INSIST(DNS_ADBNAMEHOOK_VALID(namehook));
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff /*
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff * Clean up the entry if needed.
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff */
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff entry = namehook->entry;
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff if (entry != NULL) {
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff INSIST(DNS_ADBENTRY_VALID(entry));
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews if (addr_bucket != entry->lock_bucket) {
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews if (addr_bucket != DNS_ADB_INVALIDBUCKET)
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews UNLOCK(&adb->entrylocks[addr_bucket]);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews addr_bucket = entry->lock_bucket;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews LOCK(&adb->entrylocks[addr_bucket]);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews }
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews INSIST(entry->refcount > 0);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews entry->refcount--;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews if (entry->refcount == 0) {
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews /* XXX kill zoneinfo here */
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews ISC_LIST_UNLINK(adb->entries[addr_bucket],
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews entry, link);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews entry->lock_bucket = DNS_ADB_INVALIDBUCKET;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews free_adbentry(adb, &entry);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews }
2cf81a3d8a8a12e81a762a0bc3d46e0b117733bfAutomatic Updater }
6ef15459b8fd3fc8b5672da4ad72c19a755dbe45Mark Andrews
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews /*
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews * Free the namehook
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews */
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews namehook->entry = NULL;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews ISC_LIST_UNLINK(name->namehooks, namehook, link);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews free_adbnamehook(adb, &namehook);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington namehook = ISC_LIST_HEAD(name->namehooks);
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington }
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington /*
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington * And lastly, unlink and free the name.
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews */
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff ISC_LIST_UNLINK(adb->names[name_bucket], name, link);
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff free_adbname(adb, &name);
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff if (name_bucket != DNS_ADB_INVALIDBUCKET)
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff UNLOCK(&adb->namelocks[name_bucket]);
240e57ab983296e6d52031a594d3345728191b48Mark Andrews if (addr_bucket != DNS_ADB_INVALIDBUCKET)
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff UNLOCK(&adb->entrylocks[addr_bucket]);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews return (DNS_R_SUCCESS);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews}
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews
056141f2878d1046306ef0ba035263a00de57f98Mark Andrewsisc_result_t
056141f2878d1046306ef0ba035263a00de57f98Mark Andrewsdns_adb_insert(dns_adb_t *adb, dns_name_t *host, isc_sockaddr_t *addr)
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews{
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews dns_adbname_t *name;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews isc_boolean_t free_name;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews dns_adbentry_t *entry;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews isc_boolean_t free_entry;
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson dns_adbnamehook_t *namehook;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews isc_boolean_t free_namehook;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews int name_bucket, addr_bucket; /* unlock if != DNS_ADB_INVALIDBUCKET */
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews isc_result_t result;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews REQUIRE(DNS_ADB_VALID(adb));
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews REQUIRE(host != NULL);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews REQUIRE(addr != NULL);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews name = NULL;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews free_name = ISC_FALSE;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews entry = NULL;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews free_entry = ISC_FALSE;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews namehook = NULL;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews free_namehook = ISC_FALSE;
2cf81a3d8a8a12e81a762a0bc3d46e0b117733bfAutomatic Updater result = ISC_R_UNEXPECTED;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews /*
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.
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews */
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews name_bucket = DNS_ADB_INVALIDBUCKET;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 name = find_name_and_lock(adb, host, &name_bucket);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (name == NULL) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 name = new_adbname(adb);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (name == NULL) {
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews result = ISC_R_NOMEMORY;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews goto out;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 free_name = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_name_dup(host, adb->mctx, &name->name);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS)
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews goto out;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews }
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews /*
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 */
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews addr_bucket = DNS_ADB_INVALIDBUCKET;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews entry = find_entry_and_lock(adb, addr, &addr_bucket);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews /*
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews * Case (1): new entry and namehook.
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews */
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews if (entry == NULL) {
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews entry = new_adbentry(adb);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews if (entry == NULL) {
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews result = ISC_R_NOMEMORY;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews goto out;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews }
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews free_entry = ISC_TRUE;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews }
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews /*
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews * Case (3): entry exists, we're linked.
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff */
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews namehook = ISC_LIST_HEAD(name->namehooks);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews while (namehook != NULL) {
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews if (namehook->entry == entry) {
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews result = ISC_R_EXISTS;
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews goto out;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews }
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews }
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews /*
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews * Case (2): New namehook, link to entry from above.
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews */
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews namehook = new_adbnamehook(adb, entry);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews if (namehook == NULL) {
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews result = ISC_R_NOMEMORY;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews goto out;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews }
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington free_namehook = ISC_TRUE;
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington ISC_LIST_APPEND(name->namehooks, namehook, link);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews entry->lock_bucket = addr_bucket;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews entry->refcount++;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews entry->sockaddr = *addr;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews /*
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 */
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews if (!ISC_LINK_LINKED(name, link))
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews ISC_LIST_PREPEND(adb->names[name_bucket], name, link);
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington if (!ISC_LINK_LINKED(entry, link))
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington ISC_LIST_PREPEND(adb->entries[addr_bucket], entry, link);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews UNLOCK(&adb->namelocks[name_bucket]);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews name_bucket = DNS_ADB_INVALIDBUCKET;
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews UNLOCK(&adb->entrylocks[addr_bucket]);
056141f2878d1046306ef0ba035263a00de57f98Mark Andrews addr_bucket = DNS_ADB_INVALIDBUCKET;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews return (ISC_R_SUCCESS);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
19d1b1667d073850d4366352aaf8319efc5debeeBrian Wellington out:
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews if (free_name)
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews free_adbname(adb, &name);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews if (free_entry)
04c22ceaf2d3812eaab69d79958d0e0d62048cd2Mark Andrews isc_mempool_put(adb->emp, entry);
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff if (free_namehook)
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff isc_mempool_put(adb->nhmp, namehook);
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff if (name_bucket != DNS_ADB_INVALIDBUCKET)
04c22ceaf2d3812eaab69d79958d0e0d62048cd2Mark Andrews UNLOCK(&adb->namelocks[name_bucket]);
04c22ceaf2d3812eaab69d79958d0e0d62048cd2Mark Andrews if (addr_bucket != DNS_ADB_INVALIDBUCKET)
04c22ceaf2d3812eaab69d79958d0e0d62048cd2Mark Andrews UNLOCK(&adb->entrylocks[addr_bucket]);
04c22ceaf2d3812eaab69d79958d0e0d62048cd2Mark Andrews
04c22ceaf2d3812eaab69d79958d0e0d62048cd2Mark Andrews return (result);
04c22ceaf2d3812eaab69d79958d0e0d62048cd2Mark Andrews}
04c22ceaf2d3812eaab69d79958d0e0d62048cd2Mark Andrews
04c22ceaf2d3812eaab69d79958d0e0d62048cd2Mark Andrewsvoid
04c22ceaf2d3812eaab69d79958d0e0d62048cd2Mark Andrewsdns_adb_cancel(dns_adb_t *adb, dns_adbhandle_t **handle)
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews{
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff REQUIRE(DNS_ADB_VALID(adb));
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff REQUIRE(handle != NULL && DNS_ADBHANDLE_VALID(*handle));
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews INSIST(1 == 0);
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews}
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrewsvoid
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrewsdns_adb_done(dns_adb_t *adb, dns_adbhandle_t **handle)
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews{
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff REQUIRE(DNS_ADB_VALID(adb));
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews REQUIRE(handle != NULL && DNS_ADBHANDLE_VALID(*handle));
cf70df7d0e24401a358f0b9c1a616ad0e8c783a6Mark Andrews
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff INSIST(1 == 0);
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff}
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graffvoid
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graffdns_adb_dump(dns_adb_t *adb, FILE *f)
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff{
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff int i;
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff isc_sockaddr_t *sa;
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff dns_adbname_t *name;
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff dns_adbentry_t *entry;
2cf81a3d8a8a12e81a762a0bc3d46e0b117733bfAutomatic Updater char tmp[512];
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff char *tmpp;
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff REQUIRE(DNS_ADB_VALID(adb));
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff REQUIRE(f != NULL);
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff /*
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.
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews */
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews LOCK(&adb->lock);
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews for (i = 0 ; i < DNS_ADBNAMELIST_LENGTH ; i++)
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews LOCK(&adb->namelocks[i]);
94baac869a70b529a24ff23d8dc899faa5d4fdc4Brian Wellington for (i = 0 ; i < DNS_ADBENTRYLIST_LENGTH ; i++)
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews LOCK(&adb->entrylocks[i]);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews /*
04c22ceaf2d3812eaab69d79958d0e0d62048cd2Mark Andrews * Dump the names
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews */
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews fprintf(f, "Names:\n");
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews for (i = 0 ; i < DNS_ADBNAMELIST_LENGTH ; i++) {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews name = ISC_LIST_HEAD(adb->names[i]);
2cf81a3d8a8a12e81a762a0bc3d46e0b117733bfAutomatic Updater if (name == NULL)
04c22ceaf2d3812eaab69d79958d0e0d62048cd2Mark Andrews continue;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews fprintf(f, "Name bucket %d:\n", i);
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews while (name != NULL) {
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews fprintf(f, "name %p\n", name);
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington if (!DNS_ADBNAME_VALID(name))
8b61d2012063306528286680bd9f086fa868d86eMark Andrews fprintf(f, "\tMAGIC %08x\n", name->magic);
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews fprintf(f, "\t");
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews print_dns_name(f, &name->name);
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington print_namehook_list(f, name);
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington name = ISC_LIST_NEXT(name, link);
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington }
dac1e1dd18b62be8cc3bec1a3656968b7b8633e6Brian Wellington }
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff /*
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff * Dump the entries
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff */
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff fprintf(f, "Entries:\n");
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff for (i = 0 ; i < DNS_ADBENTRYLIST_LENGTH ; i++) {
240e57ab983296e6d52031a594d3345728191b48Mark Andrews entry = ISC_LIST_HEAD(adb->entries[i]);
e903df2f012869e36251e9a76b13a9aa228fb1acMichael Graff if (entry == NULL)
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews continue;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews fprintf(f, "Entry bucket %d:\n", i);
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews while (entry != NULL) {
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews if (!DNS_ADBENTRY_VALID(entry))
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews fprintf(f, "\tMAGIC %08x\n", entry->magic);
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews if (entry->lock_bucket != i)
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews fprintf(f, "\tWRONG BUCKET! lock_bucket %d\n",
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews entry->lock_bucket);
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews sa = &entry->sockaddr;
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews tmpp = inet_ntop(sa->type.sa.sa_family, &sa->type.sa,
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson tmp, sizeof tmp);
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews if (tmpp == NULL)
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews tmpp = "CANNOT TRANSLATE ADDRESS!";
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews
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,
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews entry->srtt, tmpp);
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
c27767a7b946f4c6f08d33129691e2d6339e8350Brian Wellington entry = ISC_LIST_NEXT(entry, link);
c27767a7b946f4c6f08d33129691e2d6339e8350Brian Wellington }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence }
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
dcc7ea97174501f0409c0c919b3ca04083e4e1b8Andreas Gustafsson out:
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews /*
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews * Unlock everything
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews */
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews for (i = 0 ; i < DNS_ADBENTRYLIST_LENGTH ; i++)
7c2dce3c4d2c863ff268576f13c4ddd6f29d67edMark Andrews UNLOCK(&adb->entrylocks[i]);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 for (i = 0 ; i < DNS_ADBNAMELIST_LENGTH ; i++)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 UNLOCK(&adb->namelocks[i]);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 UNLOCK(&adb->lock);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrewsstatic void
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉print_dns_name(FILE *f, dns_name_t *name)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉{
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews char buf[257];
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews isc_buffer_t b;
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson INSIST(f != NULL);
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson memset(buf, 0, sizeof (buf));
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson isc_buffer_init(&b, buf, sizeof (buf) - 1, ISC_BUFFERTYPE_TEXT);
559bb1016f1b00a3661cb2790dc837a977057b86Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews dns_name_totext(name, ISC_FALSE, &b);
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews fprintf(f, buf); /* safe, since names < 256 chars, and we memset */
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews}
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrewsstatic void
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrewsprint_namehook_list(FILE *f, dns_adbname_t *n)
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff{
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews dns_adbnamehook_t *nh;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews nh = ISC_LIST_HEAD(n->namehooks);
94baac869a70b529a24ff23d8dc899faa5d4fdc4Brian Wellington if (nh == NULL)
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews fprintf(f, "\t\tNo name hooks\n");
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
559bb1016f1b00a3661cb2790dc837a977057b86Mark Andrews while (nh != NULL) {
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews fprintf(f, "\t\tHook %p -> entry %p\n", nh, nh->entry);
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington nh = ISC_LIST_NEXT(nh, link);
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington }
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington}
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington