adb.c revision 3024dbecbac365171bc6de0f3fa04951d6558be3
/*
* Copyright (C) 1999 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/*
* Implementation notes
* --------------------
*
* In handles, if task == NULL, no events will be generated, and no events
* have been sent. If task != NULL but taskaction == NULL, an event has been
* posted but not yet freed. If neigher are NULL, no event was posted.
*
*/
#include <config.h>
#include <isc/assertions.h>
#include <isc/mutexblock.h>
/*
* Lengths of lists needs to be powers of two.
*/
typedef struct dns_adbname dns_adbname_t;
typedef struct dns_adbnamehook dns_adbnamehook_t;
typedef struct dns_adbzoneinfo dns_adbzoneinfo_t;
struct dns_adb {
unsigned int magic;
/*
* Bucketized locks and lists for names.
*/
/*
* Bucketized locks for entries.
*/
/*
* List of running and idle handles.
*/
};
struct dns_adbname {
unsigned int magic;
};
/*
* dns_adbnamehook_t
*
* This is a small widget that dangles off a dns_adbname_t. It contains a
* pointer to the address information about this host, and a link to the next
* namehook that will contain the next address this host has.
*/
struct dns_adbnamehook {
unsigned int magic;
};
/*
* dns_adbzoneinfo_t
*
* This is a small widget that holds zone-specific information about an
* address. Currently limited to lameness, but could just as easily be
* extended to other types of information about zones.
*/
struct dns_adbzoneinfo {
unsigned int magic;
unsigned int lame_timer;
};
/*
* An address entry. It holds quite a bit of information about addresses,
* including edns state, rtt, and of course the address of the host.
*/
struct dns_adbentry {
unsigned int magic;
int lock_bucket;
unsigned int refcount;
unsigned int flags;
int goodness; /* bad <= 0 < good */
unsigned int srtt;
};
/*
* dns_adbhandle_t
*
* This is returned to the user, and contains all the state we need to do
* more fetches, return more information to the user, and to return the
* address list itself.
*/
struct dns_adbhandle {
unsigned int magic;
void *arg;
};
/*
* Internal functions (and prototypes).
*/
int *);
static dns_adbname_t *
{
return (NULL);
return (name);
}
static dns_adbnamehook_t *
{
return (NULL);
return (nh);
}
static dns_adbzoneinfo_t *
{
return (NULL);
zi->lame_timer = 0;
return (zi);
}
static dns_adbentry_t *
{
dns_adbentry_t *e;
if (e == NULL)
return (NULL);
e->magic = DNS_ADBENTRY_MAGIC;
e->lock_bucket = -1;
e->refcount = 0;
e->flags = 0;
e->goodness = 0;
e->srtt = 0;
ISC_LIST_INIT(e->zoneinfo);
ISC_LINK_INIT(e, link);
return (e);
}
static dns_adbhandle_t *
{
dns_adbhandle_t *h;
if (h == NULL)
return (NULL);
h->magic = DNS_ADBHANDLE_MAGIC;
h->taskaction = NULL;
ISC_LIST_INIT(h->list);
ISC_LINK_INIT(h, link);
return (h);
}
/*
* Copy bits from the entry into the newly allocated addrinfo. The entry
* must be locked, and the reference count must be bumped up by one
* if this function returns a valid pointer.
*/
static dns_adbaddrinfo_t *
{
return (NULL);
return (ai);
}
/*
* Search for the name. NOTE: The bucket is kept locked on both
* success and failure, so it must always be unlocked by the caller!
*/
static dns_adbname_t *
{
unsigned int bucket;
return (adbname);
}
return (NULL);
}
/*
* Search for the address. NOTE: The bucket is kept locked on both
* success and failure, so it must always be unlocked by the caller!
*/
static dns_adbentry_t *
{
unsigned int bucket;
return (entry);
}
return (NULL);
}
static void
{
}
/*
* Public functions.
*/
{
int i;
return (ISC_R_NOMEMORY);
/*
* Initialize things here that cannot fail, and especially things
* that must be NULL for the error return to work properly.
*/
if (result != ISC_R_SUCCESS)
goto fail1;
if (result != ISC_R_SUCCESS)
goto fail1;
/*
* Initialize the bucket locks for names and elements.
* May as well initialize the list heads, too.
*/
if (result != ISC_R_SUCCESS)
goto fail1;
for (i = 0 ; i < DNS_ADBNAMELIST_LENGTH ; i++)
for (i = 0 ; i < DNS_ADBENTRYLIST_LENGTH ; i++)
if (result != ISC_R_SUCCESS)
goto fail2;
/*
* Memory pools
*/
#define MPINIT(t, p) do { \
if (result != ISC_R_SUCCESS) \
goto fail3; \
isc_mempool_setfreemax((p), FREE_ITEMS); \
isc_mempool_setfillcount((p), FILL_COUNT); \
} while (0)
#define MPINIT_LOCKED(t, p) do { \
MPINIT(t, p); \
} while (0)
/*
* Normal return.
*/
return (ISC_R_SUCCESS);
fail3: /* clean up entrylocks */
fail2: /* clean up namelocks */
fail1: /* clean up only allocated memory */
return (result);
}
void
{
/*
* XXX Need to wait here until the adb is fully shut down.
*/
/*
* If all lists are empty, destroy the memory used by this
* adb. XXX Need to implement this.
*/
}
{
}
return (ISC_R_NOTIMPLEMENTED);
}
{
name_bucket = -1;
addr_bucket = -1;
/*
* First, see if the host is already in the database. If it is,
* don't make a new host entry. If not, copy the name and name's
* contents into our structure and allocate what we'll need
* to attach things together.
*/
goto out;
}
if (result != ISC_R_SUCCESS)
goto out;
}
/*
* Now, while keeping the name locked, search for the address.
* Three possibilities: One, the address doesn't exist.
* Two, the address exists, but we aren't linked to it.
* Three, the address exists and we are linked to it.
* (1) causes a new entry and namehook to be created.
* (2) causes only a new namehook.
* (3) is an error.
*/
/*
* Case (1): new entry and namehook.
*/
goto out;
}
}
/*
* Case (3): entry exists, we're linked.
*/
goto out;
}
}
/*
* Case (2): New namehook, link to entry from above.
*/
goto out;
}
/*
* If needed, string up the name and entry. Do the name last, since
* adding multiple addresses is simplified in that case.
*/
return (ISC_R_SUCCESS);
out:
if (free_namedata)
if (free_name)
if (free_entry)
if (free_namehook)
if (name_bucket != -1)
if (addr_bucket != -1)
return (result);
}
void
{
INSIST(1 == 0);
}
void
{
INSIST(1 == 0);
}