mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-04 16:45:24 +00:00
snapshot address.[ch]
This commit is contained in:
144
lib/dns/adb.c
144
lib/dns/adb.c
@@ -17,46 +17,180 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <isc/assertions.h>
|
||||
|
||||
#include <dns/address.h>
|
||||
|
||||
#define VCHECK(a,b) (((a) != NULL) && ((a)->magic == (b)))
|
||||
|
||||
#define DNS_ADB_MAGIC 0x44616462 /* Dadb. */
|
||||
#define DNS_ADB_VALID(x) ((x) != NULL && (x)->magic == DNS_ADB_MAGIC)
|
||||
#define DNS_ADB_VALID(x) VCHECK(x, DNS_ADB_MAGIC)
|
||||
#define DNS_ADBNAME_MAGIC 0x6164624e /* adbN. */
|
||||
#define DNS_ADBNAME_VALID(x) VCHECK(x, DNS_ADBNAME_MAGIC)
|
||||
#define DNS_ADBNAMEHOOK_MAGIC 0x61644e48 /* adNH. */
|
||||
#define DNS_ADBNAMEHOOK_VALID(x) VCHECK(x, DNS_ADBNAMEHOOK_MAGIC)
|
||||
#define DNS_ADBZONEINFO_MAGIC 0x6164625a /* adbZ. */
|
||||
#define DNS_ADBZONEINFO_VALID(x) VCHECK(x, DNS_ADBZONEINFO_MAGIC)
|
||||
#define DNS_ADBENTRY_MAGIC 0x61646245 /* adbE. */
|
||||
#define DNS_ADBENTRY_VALID(x) VCHECK(x, DNS_ADBENTRY_MAGIC)
|
||||
#define DNS_ADBHANDLE_MAGIC 0x61646248 /* adbH. */
|
||||
#define DNS_ADBHANDLE_VALID(x) VCHECK(x, DNS_ADBHANDLE_MAGIC)
|
||||
#define DNS_ADBADDRINFO_MAGIC 0x61644149 /* adAI. */
|
||||
#define DNS_ADBADDRINFO_VALID(x) VCHECK(x, DNS_ADBADDRINFO_MAGIC)
|
||||
|
||||
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;
|
||||
|
||||
isc_mutex_t lock;
|
||||
isc_mem_t *mctx;
|
||||
|
||||
isc_mempool_t *nmp; /* dns_adbname_t */
|
||||
isc_mempool_t *nhmp; /* dns_adbnamehook_t */
|
||||
isc_mempool_t *zimp; /* dns_adbzoneinfo_t */
|
||||
isc_mempool_t *emp; /* dns_adbentry_t */
|
||||
isc_mempool_t *ahmp; /* dns_adbhandle_t */
|
||||
isc_mempool_t *aimp; /* dns_adbaddrinfo_t */
|
||||
|
||||
ISC_LIST(dns_adbname_t) names;
|
||||
};
|
||||
|
||||
struct dns_adbhandle {
|
||||
struct dns_adbname {
|
||||
unsigned int magic;
|
||||
dns_name_t *name;
|
||||
ISC_LIST(dns_adbnamehook_t) namehooks;
|
||||
};
|
||||
|
||||
/*
|
||||
* 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_adbentry_t *address;
|
||||
ISC_LINK(dns_adbnamehook_t) link;
|
||||
};
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
dns_name_t *zone;
|
||||
unsigned int lame_timer;
|
||||
|
||||
ISC_LINK(dns_adbzoneinfo_t) link;
|
||||
};
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
unsigned int lock_bucket;
|
||||
unsigned int refcount;
|
||||
|
||||
unsigned int flags;
|
||||
int goodness; /* bad <= 0 < good */
|
||||
unsigned int srtt;
|
||||
isc_sockaddr_t sockaddr;
|
||||
|
||||
ISC_LIST(dns_adbzoneinfo_t) zoneinfo;
|
||||
|
||||
ISC_LINK(dns_adbentry_t) link;
|
||||
};
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
dns_adb_t *adb;
|
||||
|
||||
isc_task_t *task;
|
||||
isc_taskaction_t *taskaction;
|
||||
void *arg;
|
||||
dns_name_t *zone;
|
||||
|
||||
dns_adbaddrlist_t addrlist;
|
||||
|
||||
ISC_LINK(dns_adbhandle_t) link;
|
||||
};
|
||||
|
||||
/*
|
||||
* Internal functions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Public functions.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
dns_adb_create(isc_mem_t *mem, dns_adb_t **newadb)
|
||||
{
|
||||
REQUIRE(mem != NULL);
|
||||
REQUIRE(newadb != NULL && *newadb == NULL);
|
||||
|
||||
return (ISC_R_NOTIMPLEMENTED);
|
||||
}
|
||||
|
||||
void
|
||||
dns_adb_destroy(dns_adb_t **adb)
|
||||
{
|
||||
REQUIRE(adb != NULL);
|
||||
REQUIRE(DNS_ADB_VALID(*adb));
|
||||
|
||||
INSIST(1 == 0);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
dns_adb_lookup(dns_adb_t *adb, isc_task_t *task, isc_taskaction_t *action,
|
||||
void *arg, dns_rdataset_t *nsdataset, dns_name_t *zone,
|
||||
void *arg, dns_rdataset_t *nsrdataset, dns_name_t *zone,
|
||||
dns_adbhandle_t **handle)
|
||||
{
|
||||
REQUIRE(DNS_ADB_VALID(adb));
|
||||
if (task != NULL) {
|
||||
REQUIRE(action != NULL);
|
||||
}
|
||||
REQUIRE(nsrdataset != NULL);
|
||||
REQUIRE(zone != NULL);
|
||||
REQUIRE(handle != NULL && *handle == NULL);
|
||||
|
||||
return (ISC_R_NOTIMPLEMENTED);
|
||||
}
|
||||
|
||||
void
|
||||
dns_adb_cancel(dns_adb_t *adb, dns_adbhandle_t *adbhandle)
|
||||
dns_adb_cancel(dns_adb_t *adb, dns_adbhandle_t **handle)
|
||||
{
|
||||
REQUIRE(DNS_ADB_VALID(adb));
|
||||
REQUIRE(handle != NULL && DNS_ADBHANDLE_VALID(*handle));
|
||||
|
||||
INSIST(1 == 0);
|
||||
}
|
||||
|
||||
void
|
||||
dns_adb_done(dns_adb_t *adb, dns_adbhandle_t *adbhandle)
|
||||
dns_adb_done(dns_adb_t *adb, dns_adbhandle_t **handle)
|
||||
{
|
||||
REQUIRE(DNS_ADB_VALID(adb));
|
||||
REQUIRE(handle != NULL && DNS_ADBHANDLE_VALID(*handle));
|
||||
|
||||
INSIST(1 == 0);
|
||||
}
|
||||
|
@@ -112,17 +112,21 @@ typedef struct dns_adbhandle dns_adbhandle_t;
|
||||
*/
|
||||
typedef struct dns_adbentry dns_adbentry_t;
|
||||
|
||||
/* The answers to queries come back as a list of these. */
|
||||
typedef struct dns_adbaddr dns_adbaddr_t;
|
||||
typedef ISC_LIST(dns_adbaddr_t) dns_adbaddrlist_t;
|
||||
struct dns_adbaddr {
|
||||
ISC_LINK(dns_adbaddr_t) link;
|
||||
isc_sockaddr_t *sockaddr;
|
||||
/* dns_adbaddr_t
|
||||
*
|
||||
* The answers to queries come back as a list of these.
|
||||
*/
|
||||
typedef struct dns_adbaddrinfo dns_adbaddrinfo_t;
|
||||
typedef ISC_LIST(dns_adbaddrinfo_t) dns_adbaddrlist_t;
|
||||
struct dns_adbaddrinfo {
|
||||
unsigned int magic; /* private */
|
||||
|
||||
isc_sockaddr_t *sockaddr; /* read only */
|
||||
int goodness;
|
||||
unsigned int srtt; /* microseconds */
|
||||
unsigned int flags;
|
||||
unsigned int hostid;
|
||||
dns_adbentry_t *entry;
|
||||
dns_adbentry_t *entry; /* private */
|
||||
dns_adbaddrlist_t link;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -145,6 +149,9 @@ struct dns_adbaddr {
|
||||
**** FUNCTIONS
|
||||
****/
|
||||
|
||||
|
||||
isc_result_t
|
||||
dns_adb_create(isc_mem_t *mem, dns_adb_t **newadb);
|
||||
/*
|
||||
* Create a new ADB.
|
||||
*
|
||||
@@ -160,10 +167,10 @@ struct dns_adbaddr {
|
||||
* ISC_R_NOMEMORY after resource allocation failure.
|
||||
*
|
||||
*/
|
||||
isc_result_t
|
||||
dns_adb_create(isc_mem_t *mem, dns_adb_t **newadb);
|
||||
|
||||
|
||||
void
|
||||
dns_adb_destroy(dns_adb_t **adb);
|
||||
/*
|
||||
* Delete the ADB. Sets *ADB to NULL. Cancels any outstanding requests.
|
||||
*
|
||||
@@ -173,10 +180,12 @@ dns_adb_create(isc_mem_t *mem, dns_adb_t **newadb);
|
||||
* dns_adb_create().
|
||||
*
|
||||
*/
|
||||
void
|
||||
dns_adb_destroy(dns_adb_t **adb);
|
||||
|
||||
|
||||
isc_result_t
|
||||
dns_adb_lookup(dns_adb_t *adb, isc_task_t *task, isc_taskaction_t *action,
|
||||
void *arg, dns_rdataset_t *nsrdataset, dns_name_t *zone,
|
||||
dns_adbhandle_t **handle);
|
||||
/*
|
||||
* Main interface for clients. The adb will iterate over the rdata items in
|
||||
* NSDATASET and will build up a list of found addresses, and perhaps start
|
||||
@@ -211,7 +220,7 @@ dns_adb_destroy(dns_adb_t **adb);
|
||||
* *nsdataset be a valid dns_rdataset_t with a non-zero number of NS
|
||||
* records in it.
|
||||
*
|
||||
* addrlist != NULL && *addrlist == NULL.
|
||||
* zone != NULL and *zone be a valid dns_name_t.
|
||||
*
|
||||
* handle != NULL && *handle == NULL.
|
||||
*
|
||||
@@ -229,11 +238,10 @@ dns_adb_destroy(dns_adb_t **adb);
|
||||
* No internal reference to "nsrdataset" exists after this function
|
||||
* returns.
|
||||
*/
|
||||
isc_result_t
|
||||
dns_adb_lookup(dns_adb_t *adb, isc_task_t *task, isc_taskaction_t *action,
|
||||
void *arg, dns_rdataset_t *nsdataset, dns_name_t *zone,
|
||||
dns_adbhandle_t **handle);
|
||||
|
||||
|
||||
void
|
||||
dns_adb_cancel(dns_adb_t *adb, dns_adbhandle_t **handle);
|
||||
/*
|
||||
* Cancels any outstanding lookups for this handle.
|
||||
*
|
||||
@@ -241,7 +249,7 @@ dns_adb_lookup(dns_adb_t *adb, isc_task_t *task, isc_taskaction_t *action,
|
||||
*
|
||||
* 'adb' be a valid dns_adb_t pointer.
|
||||
*
|
||||
* 'adbhandle' be valid dns_adbhandle_t pointer.
|
||||
* 'handle' != NULL && *handle be a valid dns_adbhandle_t.
|
||||
*
|
||||
* Ensures:
|
||||
*
|
||||
@@ -249,9 +257,10 @@ dns_adb_lookup(dns_adb_t *adb, isc_task_t *task, isc_taskaction_t *action,
|
||||
* after this function returns, and all internal uses of that task
|
||||
* will be quickly shut down.
|
||||
*/
|
||||
void
|
||||
dns_adb_cancel(dns_adb_t *adb, dns_adbhandle_t *adbhandle);
|
||||
|
||||
|
||||
void
|
||||
dns_adb_done(dns_adb_t *adb, dns_adbhandle_t **handle);
|
||||
/*
|
||||
* Stops any internal lookups for this handle.
|
||||
*
|
||||
@@ -259,7 +268,7 @@ dns_adb_cancel(dns_adb_t *adb, dns_adbhandle_t *adbhandle);
|
||||
*
|
||||
* 'adb' be a valid dns_adb_t pointer.
|
||||
*
|
||||
* 'adbhandle' be valid dns_adbhandle_t pointer.
|
||||
* 'handle' != NULL and *handle be valid dns_adbhandle_t pointer.
|
||||
*
|
||||
* Ensures:
|
||||
*
|
||||
@@ -271,12 +280,10 @@ dns_adb_cancel(dns_adb_t *adb, dns_adbhandle_t *adbhandle);
|
||||
* The task used to launch this handle can be used internally for
|
||||
* a short time after this function returns.
|
||||
*/
|
||||
void
|
||||
dns_adb_done(dns_adb_t *adb, dns_adbhandle_t *adbhandle);
|
||||
|
||||
|
||||
/*
|
||||
* Need functions/macros to:
|
||||
* XXX Need functions/macros to:
|
||||
*
|
||||
* Remove an address from a handle's linked list. This is needed
|
||||
* because the data pointed to by a dns_adbaddr_t is reference counted.
|
||||
|
Reference in New Issue
Block a user