adb.c revision 3c5148c4d98af51d6dcb449c6dbd45fe8c645f61
ca41b452ede6feaa9d8739ec3cae19389a7b0d03Bob Halley * Copyright (C) 1999 Internet Software Consortium.
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * Permission to use, copy, modify, and distribute this software for any
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * purpose with or without fee is hereby granted, provided that the above
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * copyright notice and this permission notice appear in all copies.
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley * Implementation notes
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * --------------------
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * In handles, if task == NULL, no events will be generated, and no events
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * have been sent. If task != NULL but taskaction == NULL, an event has been
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * posted but not yet freed. If neigher are NULL, no event was posted.
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley#include "../isc/util.h"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley#define DNS_ADB_VALID(x) ISC_MAGIC_VALID(x, DNS_ADB_MAGIC)
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley#define DNS_ADBNAME_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBNAME_MAGIC)
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley#define DNS_ADBNAMEHOOK_MAGIC 0x61644e48 /* adNH. */
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley#define DNS_ADBNAMEHOOK_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBNAMEHOOK_MAGIC)
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley#define DNS_ADBZONEINFO_MAGIC 0x6164625a /* adbZ. */
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley#define DNS_ADBZONEINFO_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBZONEINFO_MAGIC)
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley#define DNS_ADBENTRY_VALID(x) ISC_MAGIC_VALID(x, DNS_ADBENTRY_MAGIC)
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley * Lengths of lists needs to be powers of two.
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley#define DNS_ADBNAMELIST_LENGTH 16 /* how many buckets for names */
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley#define DNS_ADBENTRYLIST_LENGTH 16 /* how many buckets for addresses */
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley#define FREE_ITEMS 16 /* free count for memory pools */
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley#define FILL_COUNT 8 /* fill count for memory pools */
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halleytypedef ISC_LIST(dns_adbname_t) dns_adbnamelist_t;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halleytypedef ISC_LIST(dns_adbentry_t) dns_adbentrylist_t;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley unsigned int magic;
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence * Bucketized locks and lists for names.
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence dns_adbnamelist_t names[DNS_ADBNAMELIST_LENGTH];
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence isc_mutex_t namelocks[DNS_ADBNAMELIST_LENGTH];
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley * Bucketized locks for entries.
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley dns_adbentrylist_t entries[DNS_ADBENTRYLIST_LENGTH];
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley * List of running and idle handles.
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley unsigned int magic;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley * dns_adbnamehook_t
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley * This is a small widget that dangles off a dns_adbname_t. It contains a
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley * pointer to the address information about this host, and a link to the next
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley * namehook that will contain the next address this host has.
94e25967cda41b886e33ec254b917d21df21a187Bob Halley unsigned int magic;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley * dns_adbzoneinfo_t
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * This is a small widget that holds zone-specific information about an
f47bb8d1f3a2e3edae11942d0d7e62e96caa5720Bob Halley * address. Currently limited to lameness, but could just as easily be
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * extended to other types of information about zones.
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley unsigned int magic;
94e25967cda41b886e33ec254b917d21df21a187Bob Halley unsigned int lame_timer;
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley * An address entry. It holds quite a bit of information about addresses,
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley * including edns state, rtt, and of course the address of the host.
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley unsigned int magic;
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley unsigned int refcount;
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley unsigned int flags;
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley unsigned int srtt;
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley * Internal functions (and prototypes).
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halleystatic dns_adbnamehook_t *new_adbnamehook(dns_adb_t *, dns_adbentry_t *);
94e25967cda41b886e33ec254b917d21df21a187Bob Halleystatic dns_adbzoneinfo_t *new_adbzoneinfo(dns_adb_t *);
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halleystatic dns_adbhandle_t *new_adbhandle(dns_adb_t *);
94e25967cda41b886e33ec254b917d21df21a187Bob Halleystatic dns_adbaddrinfo_t *new_adbaddrinfo(dns_adb_t *, dns_adbentry_t *);
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halleystatic dns_adbname_t *find_name_and_lock(dns_adb_t *, dns_name_t *, int *);
94e25967cda41b886e33ec254b917d21df21a187Bob Halleystatic dns_adbentry_t *find_entry_and_lock(dns_adb_t *, isc_sockaddr_t *,
94e25967cda41b886e33ec254b917d21df21a187Bob Halleynew_adbnamehook(dns_adb_t *adb, dns_adbentry_t *entry)
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence * public members
return (NULL);
static dns_adbaddrinfo_t *
return (NULL);
return (ai);
static dns_adbname_t *
unsigned int bucket;
return (adbname);
return (NULL);
static dns_adbentry_t *
unsigned int bucket;
return (entry);
return (NULL);
return (ISC_R_NOMEMORY);
goto fail1;
goto fail1;
goto fail1;
for (i = 0 ; i < DNS_ADBNAMELIST_LENGTH ; i++)
for (i = 0 ; i < DNS_ADBENTRYLIST_LENGTH ; i++)
goto fail2;
#define MPINIT(t, p) do { \
goto fail3; \
#define MPINIT_LOCKED(t, p) do { \
MPINIT(t, p); \
return (ISC_R_SUCCESS);
return (result);
return (ISC_R_NOTIMPLEMENTED);
return (ISC_R_NOTIMPLEMENTED);
goto out;
goto out;
goto out;
goto out;
goto out;
return (ISC_R_SUCCESS);
out:
if (free_namedata)
if (free_name)
if (free_entry)
if (free_namehook)
return (result);