zone.c revision e9871cc76550575415977c37a9c971726c86203f
/*
* Copyright (C) 1999, 2000 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.
*/
/* $Id: zone.c,v 1.229 2000/10/10 22:00:12 bwelling Exp $ */
#include <config.h>
#include <isc/ratelimiter.h>
#include <isc/taskpool.h>
#include <dns/callbacks.h>
#include <dns/masterdump.h>
#include <dns/rdatalist.h>
#include <dns/rdataset.h>
#include <dns/rdatastruct.h>
#include <dns/resolver.h>
#define DNS_ZONE_VALID(zone) \
#define DNS_NOTIFY_VALID(notify) \
#define DNS_STUB_VALID(stub) \
#define DNS_ZONEMGR_VALID(stub) \
#define DNS_LOAD_VALID(load) \
#define DNS_FORWARD_VALID(load) \
#define DNS_IO_VALID(load) \
#define RANGE(a, b, c) (((a) < (b)) ? (b) : ((a) < (c) ? (a) : (c)))
/*
* Default values.
*/
#ifndef DNS_MAX_EXPIRE
#endif
#ifndef DNS_DUMP_DELAY
#endif
typedef struct dns_notify dns_notify_t;
typedef struct dns_stub dns_stub_t;
typedef struct dns_load dns_load_t;
typedef struct dns_forward dns_forward_t;
struct dns_zone {
/* Unlocked */
unsigned int magic;
/* Locked */
unsigned int erefs;
unsigned int irefs;
char *dbname;
char *journal;
unsigned int flags;
unsigned int options;
unsigned int db_argc;
char **db_argv;
#ifndef NOMINUM_PUBLIC
#endif /* NOMINUM_PUBLIC */
#ifndef NOMINUM_PUBLIC
#endif /* NOMINUM_PUBLIC */
unsigned int masterscnt;
unsigned int curmaster;
unsigned int notifycnt;
/* Access Control Lists */
#ifndef NOMINUM_PUBLIC
#endif /* NOMINUM_PUBLIC */
/*
* Zones in certain states such as "waiting for zone transfer"
* or "zone transfer in progress" are kept on per-state linked lists
* in the zone manager using the 'statelink' field. The 'statelist'
* field points at the list the zone is currently on. It the zone
* is not on any such list, statelist is NULL.
*/
};
#define DNS_ZONE_FLAG(z,f) (((z)->flags & (f)) != 0)
/* XXX MPA these may need to go back into zone.h */
/* #define DNS_ZONEFLG_UNUSED 0x00000010U */ /* unused */
* uptodate */
* messages */
* reload */
* zone with no masters
* occured */
SOA (if not set, we are still using
default timer values) */
#define DNS_ZONE_OPTION(z,o) (((z)->options & (o)) != 0)
struct dns_zonemgr {
unsigned int magic;
int refs; /* Locked by rwlock */
isc_task_t * task;
/* Locked by rwlock. */
/* Locked by conflock. */
int transfersin;
int transfersperns;
/* Locked by iolock */
};
/*
* Hold notify state.
*/
struct dns_notify {
#ifndef NOMINUM_PUBLIC
unsigned int flags;
#endif /* NOMINUM_PUBLIC */
};
#ifndef NOMINUM_PUBLIC
#define DNS_NOTIFY_NOSOA 0x0001U
#endif /* NOMINUM_PUBLIC */
/*
* dns_stub holds state while performing a 'stub' transfer.
* 'db' is the zone's 'db' or a new one if this is the initial
* transfer.
*/
struct dns_stub {
};
/*
* Hold load state.
*/
struct dns_load {
};
/*
* Hold forward state.
*/
struct dns_forward {
void *callback_arg;
};
/*
* Hold IO request state.
*/
struct dns_io {
};
static void cancel_refresh(dns_zone_t *);
...);
#ifndef NOMINUM_PUBLIC
#endif /* NOMINUM_PUBLIC */
#if 0
/* ondestroy example */
#endif
dns_stub_t *stub);
#ifdef NOMINUM_PUBLIC
#else /* NOMINUM_PUBLIC */
unsigned int flags,
#endif /* NOMINUM_PUBLIC */
dns_zone_t *zone);
static isc_result_t
const char *templat);
const unsigned int dbargc_default = 1;
const char *dbargv_default[] = { "rbt" };
/***
*** Public functions.
***/
return (ISC_R_NOMEMORY);
if (result != ISC_R_SUCCESS) {
"isc_mutex_init() failed: %s",
return (ISC_R_UNEXPECTED);
}
/* XXX MPA check that all elements are initialised */
zone->expiretime = 0;
zone->refreshtime = 0;
#ifndef NOMINUM_PUBLIC
#endif /* NOMINUM_PUBLIC */
#ifndef NOMINUM_PUBLIC
#endif /* NOMINUM_PUBLIC */
zone->masterscnt = 0;
#ifndef NOMINUM_PUBLIC
#endif /* NOMINUM_PUBLIC */
/* Must be after magic is set. */
if (result != ISC_R_SUCCESS)
goto free_mutex;
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
}
/*
* Free a zone. Because we require that there be no more
* outstanding events or references, no locking is necessary.
*/
static void
/*
* Managed objects. Order is important.
*/
/* Unmanaged objects */
#ifndef NOMINUM_PUBLIC
#else /* NOMINUM_PUBLIC */
#endif /* NOMINUM_PUBLIC */
#ifndef NOMINUM_PUBLIC
#endif /* NOMINUM_PUBLIC */
/* last stuff */
}
/*
* Single shot.
*/
void
/*
* Test and set.
*/
}
}
void
}
/*
* Single shot.
*/
void
/*
* Test and set.
*/
}
static void
unsigned int i;
/* Free the old database argument list. */
}
}
unsigned int i;
/* Set up a new database argument list. */
goto nomem;
for (i = 0; i < dbargc; i++)
for (i = 0; i < dbargc; i++) {
goto nomem;
}
/* Free the old list. */
goto unlock;
for (i = 0; i < dbargc; i++) {
}
}
return (result);
}
void
}
}
}
return (result);
}
else
return (result);
}
static isc_result_t
int len;
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
}
return (result);
}
char *
}
const char me[] = "dns_zone_load";
/*
* The zone has no master file (maybe it is the built-in
* version.bind. CH zone). Do nothing.
*/
goto cleanup;
}
/*
* Don't do the load if the file that stores the zone is older
* than the last time the zone was loaded. If the zone has not
* been loaded yet, zone->loadtime will be the epoch.
*/
"skipping: database file older than last load");
goto cleanup;
}
/*
* Store the current time before the zone is loaded, so that if the
* file changes between the time of the load and the time that
* zone->loadtime is set, then the file will still be reloaded
* the next time dns_zone_load is called.
*/
if (result != ISC_R_SUCCESS)
goto cleanup;
&db);
if (result != ISC_R_SUCCESS)
goto cleanup;
if (!dns_db_ispersistent(db))
if (result == DNS_R_CONTINUE) {
goto cleanup;
}
dns_db_detach(&db);
return (result);
}
static void
if (result == ISC_R_CANCELED)
goto fail;
goto fail;
return;
fail:
}
static isc_result_t
return (ISC_R_NOMEMORY);
if (result != ISC_R_SUCCESS)
goto cleanup;
if (result != ISC_R_SUCCESS) {
if (result == ISC_R_SUCCESS)
goto cleanup;
} else
} else {
}
return (result);
return (result);
}
static isc_result_t
{
const char me[] = "dns_zone_load";
unsigned int soacount = 0;
unsigned int nscount = 0;
/*
* Initiate zone transfer? We may need a error code that
* indicates that the "permanent" form does not exist.
* XXX better error feedback to log.
*/
if (result != ISC_R_SUCCESS) {
if (result == ISC_R_FILENOTFOUND)
"no database file");
else
"database %s: dns_db_load failed: %s",
} else
"database %s: dns_db_load failed: %s",
goto cleanup;
}
"number of nodes in database: %u",
/*
* Apply update log, if any.
*/
result != ISC_R_RANGE) {
"dns_journal_rollforward returned: %s",
goto cleanup;
}
"journal out of sync with zone");
goto cleanup;
}
"dns_journal_rollforward: %s",
if (result == ISC_R_SUCCESS)
}
/*
* Obtain ns and soa counts for top of zone.
*/
nscount = 0;
soacount = 0;
if (result != ISC_R_SUCCESS) {
}
/*
* Master / Slave / Stub zones require both NS and SOA records at
* the top of the zone.
*/
case dns_zone_master:
case dns_zone_slave:
case dns_zone_stub:
if (soacount != 1) {
"has %d SOA records", soacount);
goto cleanup;
}
if (nscount == 0)
"zone serial has gone backwards");
}
}
isc_time_t t;
if (result == ISC_R_SUCCESS)
else
}
break;
default:
goto cleanup;
}
#if 0
/* destroy notification example. */
{
zone,
sizeof(isc_event_t));
}
#endif
if (result != ISC_R_SUCCESS)
goto cleanup;
} else {
}
if (needdump)
return (result);
/* Mark the zone for immediate refresh. */
}
return (result);
}
static void
{
/*
* DNS_ZONEFLG_EXITING can only be set if erefs == 0.
*/
}
}
static isc_result_t
unsigned int *nscount)
{
unsigned int count;
if (result == ISC_R_NOTFOUND) {
*nscount = 0;
goto invalidate_rdataset;
}
else if (result != ISC_R_SUCCESS)
goto invalidate_rdataset;
count = 0;
while (result == ISC_R_SUCCESS) {
count++;
}
return (result);
}
static isc_result_t
unsigned int *soacount,
{
unsigned int count;
if (result != ISC_R_SUCCESS)
goto invalidate_rdataset;
count = 0;
while (result == ISC_R_SUCCESS) {
count++;
if (count == 1)
}
if (count > 0) {
}
return (result);
}
/*
* zone must be locked.
*/
static isc_result_t
{
if (result != ISC_R_SUCCESS) {
goto closeversion;
}
if (result != ISC_R_SUCCESS)
}
minimum);
if (result != ISC_R_SUCCESS)
}
return (answer);
}
void
}
void
/*
* We just detached the last external reference.
*/
/*
* This zone is being managed. Post
* its control event and let it clean
* up synchronously in the context of
* its task.
*/
} else {
/*
* This zone is not being managed; it has
* no task and can have no outstanding
* events. Free it immediately.
*/
/*
* Unmanaged zones should not have non-null views;
* we have no way of detaching from the view here
* without causing deadlock because this code is called
* with the view already locked.
*/
}
}
if (free_now)
}
void
}
void
}
}
}
void
if (value)
else
}
void
{
if (value)
else
}
unsigned int
}
return (ISC_R_SUCCESS);
}
return (&zone->xfrsource4);
}
return (ISC_R_SUCCESS);
}
return (&zone->xfrsource6);
}
{
}
goto unlock;
return (ISC_R_NOMEMORY);
}
return (ISC_R_SUCCESS);
}
#ifndef NOMINUM_PUBLIC
{
return (result);
}
#else /* NOMINUM_PUBLIC */
#endif /* NOMINUM_PUBLIC */
{
#ifndef NOMINUM_PUBLIC
unsigned int i;
#endif /* NOMINUM_PUBLIC */
#ifndef NOMINUM_PUBLIC
}
#endif /* NOMINUM_PUBLIC */
}
#ifndef NOMINUM_PUBLIC
for (i = 0; i < zone->masterscnt; i++) {
zone->masterkeynames[i],
sizeof(dns_name_t));
}
}
}
#endif /* NOMINUM_PUBLIC */
zone->masterscnt = 0;
/*
* If count == 0, don't allocate any space for masters or keynames
* so internally, those pointers are NULL if count == 0
*/
if (count == 0)
goto unlock;
/*
* masters must countain count elements!
*/
count * sizeof(isc_sockaddr_t));
goto unlock;
}
#ifndef NOMINUM_PUBLIC
/*
* if keynames is non-NULL, it must contain count elements!
*/
count * sizeof(dns_name_t *));
goto unlock;
}
for (i = 0; i < count; i++)
for (i = 0; i < count; i++) {
sizeof(dns_name_t));
goto allocfail;
newname[i]);
if (result != ISC_R_SUCCESS) {
for (i = 0; i < count; i++)
newname[i],
goto unlock;
}
}
}
}
#endif /* NOMINUM_PUBLIC */
return (result);
}
else
return (result);
}
/*
* Co-ordinates the starting of routine jobs.
*/
void
const char me[] = "dns_zone_maintenance";
/*
* Configuring the view of this zone may have
* failed, for example because the config file
* had a syntax error. In that case, the view
* adb or resolver, and we had better not try
* to do maintenance on it.
*/
return;
/*
* Expire check.
*/
case dns_zone_slave:
case dns_zone_stub:
}
break;
default:
break;
}
/*
* Up to date check.
*/
case dns_zone_slave:
case dns_zone_stub:
break;
default:
break;
}
/*
* Do we need to consolidate the backing store?
*/
case dns_zone_master:
case dns_zone_slave:
if (result != ISC_R_SUCCESS)
"failed: %s",
}
break;
default:
break;
}
/*
* Do we need to send out notify messages?
*/
case dns_zone_master:
case dns_zone_slave:
break;
default:
break;
}
}
void
}
void
}
static void
/*
* 'zone' locked by caller.
*/
if (result != ISC_R_SUCCESS)
}
}
void
return;
/*
* Set DNS_ZONEFLG_REFRESH so that there is only one refresh operation
* in progress at a time.
*/
if (zone->masterscnt == 0) {
if ((oldflags & DNS_ZONEFLG_NOMASTERS) == 0)
"no masters");
return;
}
return;
/*
* Set the next refresh time as if refresh check has failed.
* Setting this to the retry time will do that. XXXMLG
* If we are successful it will be reset using zone->refresh.
*/
"refresh time (%u/%u), now %u",
/*
* When lacking user-specified timer values from the SOA,
* do exponential backoff of the retry time up to a
* maximum of six hours.
*/
/* initiate soa query */
}
return (result);
}
return (result);
}
static void
/*
* Do we have a place to dump to and are we loaded?
*/
return;
/* add some noise */
}
static isc_result_t
/*
* 'zone' locked by caller.
*/
if (result != ISC_R_SUCCESS) {
/*
* Try again in a short while.
*/
return (result);
}
return (ISC_R_SUCCESS);
}
dns_db_detach(&db);
return (result);
}
void
}
static void
/*
* Locked by caller.
*/
}
}
static void
/*
* Locked by caller.
*/
}
#ifndef NOMINUM_PUBLIC
/*
* Note: the only reason this is protected is to avoid a compiler warning
* about an unused static function. The protection can be removed if
* this is needed elsewhere.
*/
static void
const char me[] = "zone_deletefile";
/*
* Locked by caller.
*/
return;
if (result != ISC_R_SUCCESS) {
"failed to delete '%s': %s",
}
}
#endif /* NOMINUM_PUBLIC */
void
}
void
}
void
}
void
}
#ifndef NOMINUM_PUBLIC
void
}
}
#endif /* NOMINUM_PUBLIC */
static isc_boolean_t
continue;
return (ISC_TRUE);
return (ISC_TRUE);
}
return (ISC_FALSE);
}
static void
/*
* Caller holds zone lock.
*/
if (!locked)
if (!locked)
}
}
static isc_result_t
return (ISC_R_NOMEMORY);
#ifndef NOMINUM_PUBLIC
#endif /* NOMINUM_PUBLIC */
return (ISC_R_SUCCESS);
}
/*
* XXXAG should check for DNS_ZONEFLG_EXITING
*/
static void
isc_event_free(&ev);
if (result == DNS_EVENT_ADBMOREADDRESSES) {
return;
}
if (result == DNS_EVENT_ADBNOMOREADDRESSES) {
}
}
static void
unsigned int options;
goto destroy;
/* Something failed? */
if (result != ISC_R_SUCCESS)
goto destroy;
/* More addresses pending? */
return;
/* We have as many addresses as we can get. */
}
static isc_result_t
isc_event_t *e;
notify, sizeof(isc_event_t));
if (e == NULL)
return (ISC_R_NOMEMORY);
if (result != ISC_R_SUCCESS)
isc_event_free(&e);
return (result);
}
static void
char addrbuf[ISC_SOCKADDR_FORMATSIZE];
goto cleanup;
}
goto cleanup;
}
#ifdef NOMINUM_PUBLIC
#else /* NOMINUM_PUBLIC */
#endif /* NOMINUM_PUBLIC */
if (result != ISC_R_SUCCESS)
goto cleanup;
addrbuf);
if (result != ISC_R_SUCCESS)
}
static void
/*
* Zone lock held by caller.
*/
continue;
if (result != ISC_R_SUCCESS)
goto cleanup;
if (result != ISC_R_SUCCESS)
goto cleanup;
}
}
#ifndef NOMINUM_PUBLIC
static void
const char me[] = "zone_notifyforward";
unsigned int i;
/*
* Locked by caller.
*/
/*
* Enqueue notify requests for 'also-notify' servers.
*/
for (i = 0; i < zone->masterscnt; i++) {
continue;
if (result != ISC_R_SUCCESS) {
return;
}
if (result != ISC_R_SUCCESS) {
return;
}
}
}
#endif /* NOMINUM_PUBLIC */
void
unsigned int i;
return;
if (notifytype == dns_notifytype_no)
return;
/*
* Enqueue notify requests for 'also-notify' servers.
*/
continue;
if (result != ISC_R_SUCCESS) {
return;
}
if (result != ISC_R_SUCCESS) {
return;
}
}
if (notifytype == dns_notifytype_explicit)
return;
/*
* Process NS RRset to generate notifies.
*/
if (result != ISC_R_SUCCESS)
goto cleanup1;
if (result != ISC_R_SUCCESS)
goto cleanup2;
/*
* Find master server's name.
*/
while (result == ISC_R_SUCCESS) {
if (result != ISC_R_SUCCESS)
continue;
if (result != ISC_R_SUCCESS)
continue;
if (result != ISC_R_NOMORE)
break;
}
if (result != ISC_R_NOMORE)
goto cleanup3;
if (result != ISC_R_SUCCESS)
goto cleanup3;
while (result == ISC_R_SUCCESS) {
if (result != ISC_R_SUCCESS)
continue;
/*
* don't notify the master server.
*/
continue;
}
if (isqueued) {
continue;
}
if (result != ISC_R_SUCCESS)
continue;
if (result != ISC_R_SUCCESS) {
continue;
}
}
if (dns_name_dynamic(&master))
}
/***
*** Private
***/
static inline isc_result_t
{
/*
* Extract NS RRset from message.
*/
NULL, &nsrdataset);
if (result != ISC_R_SUCCESS)
goto fail;
/*
* Add NS rdataset.
*/
if (result != ISC_R_SUCCESS)
goto fail;
nsrdataset, 0, NULL);
if (result != ISC_R_SUCCESS)
goto fail;
/*
* Add glue rdatasets.
*/
result == ISC_R_SUCCESS;
continue;
}
&rdataset);
if (result == ISC_R_SUCCESS) {
if (result != ISC_R_SUCCESS)
goto fail;
if (result != ISC_R_SUCCESS)
goto fail;
}
&rdataset);
if (result == ISC_R_SUCCESS) {
if (result != ISC_R_SUCCESS)
goto fail;
if (result != ISC_R_SUCCESS)
goto fail;
}
&rdataset);
if (result == ISC_R_SUCCESS) {
if (result != ISC_R_SUCCESS)
goto fail;
if (result != ISC_R_SUCCESS)
goto fail;
}
}
if (result != ISC_R_NOMORE)
goto fail;
return (ISC_R_SUCCESS);
fail:
return (result);
}
static void
const char me[] = "stub_callback";
char master[ISC_SOCKADDR_FORMATSIZE];
goto next_master;
}
goto next_master;
}
if (result != ISC_R_SUCCESS)
goto next_master;
if (result != ISC_R_SUCCESS)
goto next_master;
/*
* Unexpected rcode.
*/
char rcode[128];
"unexpected rcode (%.*s) from %s",
goto next_master;
}
/*
* We need complete messages.
*/
"truncated TCP response from %s", master);
goto next_master;
}
goto same_master;
}
/*
* If non-auth log and next master.
*/
"non-authorative answer from %s", master);
goto next_master;
}
/*
* Sanity checks.
*/
if (cnamecnt != 0) {
"found unexpected CNAME %s", master);
goto next_master;
}
if (nscnt == 0) {
"no NS records from %s", master);
goto next_master;
}
/*
* Save answer.
*/
if (result != ISC_R_SUCCESS) {
"unable to save ns records from %s", master);
goto next_master;
}
/*
* Tidy up.
*/
}
"refresh time (%u/%u), now %u",
goto free_stub;
goto free_stub;
}
goto free_stub;
goto detach;
return;
}
/*
* An SOA query has finished (successfully or not).
*/
static void
const char me[] = "refresh_callback";
char master[ISC_SOCKADDR_FORMATSIZE];
/*
* if timeout log and next master;
*/
goto next_master;
}
if (result != ISC_R_SUCCESS)
goto next_master;
if (result != ISC_R_SUCCESS) {
"failure in request to %s: %s",
goto next_master;
}
/*
* Unexpected rcode.
*/
char rcode[128];
"unexpected rcode (%.*s) from %s",
goto next_master;
}
/*
* If truncated punt to zone transfer which will query again.
*/
"truncated UDP answer initiating "
"TCP zone xfer %s",
master);
goto tcp_transfer;
} else {
"truncated TCP response from %s",
master);
goto next_master;
}
goto same_master;
}
}
/*
* if non-auth log and next master;
*/
"non-authorative answer from %s", master);
goto next_master;
}
/*
* There should not be a CNAME record at top of zone.
*/
if (cnamecnt != 0) {
"CNAME at top of zone discovered: master %s", master);
goto next_master;
}
/*
* if referral log and next master;
*/
"referral from: master %s", master);
goto next_master;
}
/*
* if nodata log and next master;
*/
"NODATA from master %s", master);
goto next_master;
}
/*
* Only one soa at top of zone.
*/
if (soacnt != 1) {
"Answer SOA count (%d) != 1: master %s",
goto next_master;
}
/*
* Extract serial
*/
if (result != ISC_R_SUCCESS) {
"unable to get soa record from %s", master);
goto next_master;
}
if (result != ISC_R_SUCCESS) {
goto next_master;
}
if (result != ISC_R_SUCCESS) {
goto next_master;
}
} else {
}
isc_time_t t;
isc_time_set(&t, now, 0);
if (result != ISC_R_SUCCESS)
"isc_file_settime(%s): %s",
}
"refresh time (%u/%u), now %u",
goto next_master;
} else {
goto next_master;
}
return;
}
return;
}
return;
return;
}
static void
const char me[] = "queue_soa_query";
isc_event_t *e;
return;
}
if (e == NULL) {
return;
}
/*
* Attach so that we won't clean up
* until the event is delivered.
*/
if (result != ISC_R_SUCCESS) {
isc_event_free(&e);
}
}
static inline isc_result_t
{
&message);
if (result != ISC_R_SUCCESS)
goto cleanup;
if (result != ISC_R_SUCCESS)
goto cleanup;
if (result != ISC_R_SUCCESS)
goto cleanup;
/*
* Make question.
*/
return (ISC_R_SUCCESS);
return (result);
}
static void
const char me[] = "soa_query";
return;
}
/*
* XXX Optimisation: Create message when zone is setup and reuse.
*/
if (result != ISC_R_SUCCESS)
goto cleanup;
DNS_REQUESTOPT_TCP : 0;
if (result != ISC_R_SUCCESS) {
"dns_request_create failed: %s",
goto cleanup;
}
return;
return;
}
static void
const char me[] = "ns_query";
goto cleanup;
/*
* Attach so that the zone won't disappear from under us.
*/
/*
* If a db exists we will update it, otherwise we create a
* new one and attach it to the zone once we have the NS
* RRset and glue.
*/
else {
if (result != ISC_R_SUCCESS) {
"dns_db_create failed: %s",
goto cleanup;
}
}
/*
* Update SOA record.
*/
&node);
if (result != ISC_R_SUCCESS) {
"dns_db_findnode failed: %s",
goto cleanup;
}
soardataset, 0, NULL);
if (result != ISC_R_SUCCESS) {
"dns_db_addrdataset failed: %s",
goto cleanup;
}
}
/*
* XXX Optimisation: Create message when zone is setup and reuse.
*/
/*
* Always use TCP so that we shouldn't truncate in additional section.
*/
if (result != ISC_R_SUCCESS) {
"dns_request_create failed: %s",
goto cleanup;
}
return;
}
return;
}
/*
* Handle the control event. Note that although this event causes the zone
* to shut down, it is not a shutdown event in the sense of the task library.
*/
static void
/*
* If we were waiting for xfrin quota, step out of
* the queue.
*/
}
}
}
static void
const char me[] = "zone_timer";
/* XXX if we use a view, we need to lock its configuration, too. */
}
static isc_result_t
const char me[] = "zone_settimer";
isc_stdtime_t next = 0;
case dns_zone_master:
}
break;
case dns_zone_slave:
/*FALLTHROUGH*/
case dns_zone_stub:
}
}
break;
default:
break;
}
if (next == 0) {
"settimer inactive");
} else {
"settimer %d %d = %d seconds",
}
if (result != ISC_R_SUCCESS)
return (result);
return (ISC_R_SUCCESS);
}
static void
const char me[] = "cancel_refresh";
/*
* Locked by caller.
*/
}
static isc_result_t
#ifdef NOMINUM_PUBLIC
#else /* NOMINUM_PUBLIC */
#endif /* NOMINUM_PUBLIC */
{
isc_region_t r;
isc_buffer_t *b = NULL;
&message);
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS)
goto cleanup;
if (result != ISC_R_SUCCESS)
goto cleanup;
/*
* Make question.
*/
temprdataset = NULL;
#ifndef NOMINUM_PUBLIC
if ((flags & DNS_NOTIFY_NOSOA) != 0)
goto done;
#endif /* NOMINUM_PUBLIC */
/*
* If the zone is dialup we are done as we don't want to send
* the current soa so as to force a refresh query.
*/
goto done;
if (result != ISC_R_SUCCESS)
goto soa_cleanup;
if (result != ISC_R_SUCCESS)
goto soa_cleanup;
if (result != ISC_R_SUCCESS)
goto soa_cleanup;
if (result != ISC_R_SUCCESS)
goto soa_cleanup;
if (result != ISC_R_SUCCESS)
goto soa_cleanup;
dns_rdatatype_none, 0, &rdataset,
NULL);
if (result != ISC_R_SUCCESS)
goto soa_cleanup;
if (result != ISC_R_SUCCESS)
goto soa_cleanup;
dns_rdata_toregion(&rdata, &r);
if (result != ISC_R_SUCCESS)
goto soa_cleanup;
isc_buffer_usedregion(b, &r);
if (result != ISC_R_NOMORE)
goto soa_cleanup;
temprdatalist->covers = 0;
if (result != ISC_R_SUCCESS)
goto soa_cleanup;
temprdataset = NULL;
if (temprdataset != NULL)
if (temprdatalist != NULL)
done:
return (ISC_R_SUCCESS);
if (temprdataset != NULL)
return (result);
}
{
const char me[] = "dns_zone_notifyreceive";
unsigned int i;
char fromtext[ISC_SOCKADDR_FORMATSIZE];
#ifndef NOMINUM_PUBLIC
int match = 0;
#endif /* NOMINUM_PUBLIC */
/*
* If type != T_SOA return DNS_R_REFUSED. We don't yet support
* ROLLOVER.
*
* SOA: RFC 1996
* Check that 'from' is a valid notify source, (zone->masters).
* Return DNS_R_REFUSED if not.
*
* If the notify message contains a serial number check it
* against the zones serial and return if <= current serial
*
* If a refresh check is progress, if so just record the
* fact we received a NOTIFY and from where and return.
* We will perform a new refresh check when the current one
* completes. Return ISC_R_SUCCESS.
*
* Otherwise initiate a refresh check using 'from' as the
* first address to check. Return ISC_R_SUCCESS.
*/
/*
* We only handle NOTIFY (SOA) at the present.
*/
"FORMERR no question: %s", fromtext);
return (DNS_R_FORMERR);
}
"REFUSED zone does not match");
return (DNS_R_NOTIMP);
}
/*
* If we are a master zone just succeed.
*/
return (ISC_R_SUCCESS);
}
for (i = 0; i < zone->masterscnt; i++)
break;
#ifndef NOMINUM_PUBLIC
/*
* Accept notify requests from non masters if they are on
* 'zone->notify_acl'. If DNS_ZONEOPT_NOTIFYFORWARD is set
* then forward the notify.
*/
/* Accept notify. */
} else
#endif /* NOMINUM_PUBLIC */
if (i >= zone->masterscnt) {
"REFUSED notify from non master: %s", fromtext);
return (DNS_R_REFUSED);
}
/*
* If the zone is loaded and there are answers check the serial
* to see if we need to do a refresh. Do not worry about this
* check if we are a dialup zone as we use the notify request
* to trigger a refresh check.
*/
&rdataset);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
isc_uint32_t serial = 0;
if (result == ISC_R_SUCCESS) {
"zone up to date: %s",
fromtext);
return (ISC_R_SUCCESS);
}
}
}
}
#ifndef NOMINUM_PUBLIC
if (forward) {
return (ISC_R_SUCCESS);
}
#endif /* NOMINUM_PUBLIC */
/*
* If we got this far and there was a refresh in progress just
* let it complete. Record where we got the notify from so we
* can perform a refresh check when the current one completes
*/
"refresh in progress, refresh check queued: %s",
fromtext);
return (ISC_R_SUCCESS);
}
fromtext);
return (ISC_R_SUCCESS);
}
#ifndef NOMINUM_PUBLIC
void
}
#endif /* NOMINUM_PUBLIC */
void
}
void
}
void
}
#ifndef NOMINUM_PUBLIC
return (zone->notify_acl);
}
#endif /* NOMINUM_PUBLIC */
}
return (zone->update_acl);
}
}
void
}
#ifndef NOMINUM_PUBLIC
void
}
#endif /* NOMINUM_PUBLIC */
void
}
void
}
void
}
return (zone->check_names);
}
void
}
return (zone->journalsize);
}
static void
/*
* Leave space for terminating '\0'.
*/
if (result != ISC_R_SUCCESS)
}
static void
char message[4096];
return;
}
static void
char message[4096];
return;
}
static int
{
int count = 0;
while (result == ISC_R_SUCCESS) {
count++;
}
}
return (count);
}
void
}
}
void
}
}
}
}
void
}
void
}
const char *
}
void
if (idlein == 0)
}
}
void
if (idleout == 0)
}
}
static void
char rcode[128];
char addrbuf[ISC_SOCKADDR_FORMATSIZE];
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS)
"NOTIFY answer from %s: %.*s",
else
"NOTIFY to %s failed: %s", addrbuf,
}
return (result);
}
static isc_result_t
/*
* The initial version of a slave zone is always dumped;
* subsequent versions may be journalled instead if this
* is enabled in the configuration.
*/
zone->diff_on_reload) {
"generating diffs");
if (result != ISC_R_SUCCESS)
goto fail;
} else {
"dumping new zone version");
/* XXX should use temporary file and rename */
if (result != ISC_R_SUCCESS)
goto fail;
/*
* Update the time the zone was updated, so
* dns_zone_load can avoid loading it when
* the server is reloaded. If isc_time_now
* fails for some reason, all that happens is
* the timestamp is not updated.
*/
}
"removing journal file");
}
}
"replacing zone database");
return (ISC_R_SUCCESS);
fail:
return (result);
}
static void
const char me[] = "zone_xfrdone";
unsigned int soacount;
unsigned int nscount;
switch (result) {
case ISC_R_SUCCESS:
/*FALLTHROUGH*/
case DNS_R_UPTODATE:
/*
* Has the zone expired underneath us?
*/
goto same_master;
/*
* This is not neccessary if we just performed a AXFR
* however it is necessary for an IXFR / UPTODATE and
* won't hurt with an AXFR.
*/
isc_time_t t;
isc_time_set(&t, now, 0);
if (result != ISC_R_SUCCESS)
"isc_file_settime(%s): %s",
}
/*
* Update the zone structure's data from the actual
* SOA received.
*/
nscount = 0;
soacount = 0;
if (result == ISC_R_SUCCESS) {
if (soacount != 1)
"has %d SOA record%s", soacount,
if (nscount == 0)
"no NS records");
zone->maxrefresh);
}
/*
*/
} else {
"refresh time (%u/%u), now %u",
}
break;
#ifndef NOMINUM_PUBLIC
case DNS_R_ZONETOOLARGE:
"transfer aborted, zone unloaded",
}
break;
#endif /* NOMINUM_PUBLIC */
default:
else {
}
break;
}
/*
* If creating the transfer object failed, zone->xfr is NULL.
* Otherwise, we are called as the done callback of a zone
* transfer object that just entered its shutting-down
* state. Since we are no longer responsible for shutting
* it down, we can detach our reference.
*/
/*
* This transfer finishing freed up a transfer quota slot.
* Let any zones waiting for quota have it.
*/
/*
* Retry with a different server if necessary.
*/
}
static void
static char me[] = "zone_loaddone";
if (result == ISC_R_SUCCESS)
}
void
}
void
}
void
}
return (zone->sigvalidityinterval);
}
static void
const char me[] = "queue_xfrin";
if (result == ISC_R_QUOTA) {
"zone transfer deferred due to quota");
} else if (result != ISC_R_SUCCESS) {
"starting zone transfer: %s",
}
}
/*
* This event callback is called when a zone has received
* any necessary zone transfer quota. This is the time
* to go ahead and start the transfer.
*/
static void
const char me[] = "got_transfer_quota";
char mastertext[256];
goto cleanup;
}
/*
* Decide whether we should request IXFR or AXFR.
*/
"no database exists yet, requesting AXFR of "
"initial version from %s", mastertext);
} else {
; /* Using peer setting */
} else {
}
"IXFR disabled, requesting AXFR from %s",
} else {
"requesting IXFR from %s",
}
}
/*
* Determine if we should attempt to sign the request with TSIG.
*/
#ifndef NOMINUM_PUBLIC
/*
* First, look for a tsig key in the master statement, then
* try for a server key.
*/
}
#endif /* NOMINUM_PUBLIC */
"error getting tsig key "
"for zone transfer: %s",
}
/*
* Any failure in this function is handled like a failed
* zone transfer. This ensures that we get removed from
* zmgr->xfrin_in_progress.
*/
if (result != ISC_R_SUCCESS)
return;
}
/*
* Update forwarding support.
*/
static void
}
static isc_result_t
return (ISC_R_NOMORE);
}
/*
* Always use TCP regardless of whether the original update
* used TCP.
* XXX The timeout may but a bit small if we are far down a
* transfer graph and the master has to try several masters.
* XXX should be using xfrsource{4,6}.
*/
return (result);
}
static void
const char me[] = "forward_callback";
char master[ISC_SOCKADDR_FORMATSIZE];
goto next_master;
}
if (result != ISC_R_SUCCESS)
goto next_master;
if (result != ISC_R_SUCCESS)
goto next_master;
/*
* Pass these rcodes back to client.
*/
case dns_rcode_noerror:
case dns_rcode_yxdomain:
case dns_rcode_yxrrset:
case dns_rcode_nxrrset:
case dns_rcode_refused:
case dns_rcode_nxdomain:
break;
case dns_rcode_notzone:
case dns_rcode_notauth: {
char rcode[128];
"unexpected response: master %s returned: %.*s",
goto next_master;
}
/* Try another server for these rcodes. */
case dns_rcode_formerr:
case dns_rcode_servfail:
case dns_rcode_notimp:
case dns_rcode_badvers:
default:
goto next_master;
}
/* call callback */
return;
if (result != ISC_R_SUCCESS) {
/* call callback */
}
}
{
return (ISC_R_NOMEMORY);
goto cleanup;
}
if (result != ISC_R_SUCCESS)
goto cleanup;
if (result != ISC_R_SUCCESS)
goto cleanup;
if (result != ISC_R_SUCCESS) {
}
return (result);
}
/***
*** Zone manager.
***/
{
return (ISC_R_NOMEMORY);
if (result != ISC_R_SUCCESS) {
"isc_rwlock_init() failed: %s",
goto free_mem;
}
if (result != ISC_R_SUCCESS) {
"isc_rwlock_init() failed: %s",
goto free_rwlock;
}
/* Create the zone task pool. */
if (result != ISC_R_SUCCESS)
goto free_conflock;
/* Create a single task for queueing of SOA queries. */
if (result != ISC_R_SUCCESS)
goto free_taskpool;
if (result != ISC_R_SUCCESS)
goto free_task;
/* 20 refresh queries / notifies per second. */
if (result != ISC_R_SUCCESS) {
"isc_mutex_init() failed: %s",
goto free_rl;
}
return (ISC_R_SUCCESS);
#if 0
#endif
return (result);
}
/*
* Set the task name. The tag will arbitrarily point to one
* of the zones sharing the task (in practice, the one
* to be managed last).
*/
if (result != ISC_R_SUCCESS)
goto cleanup_task;
goto unlock;
return (result);
}
void
if (free_now)
}
void
}
void
if (free_now)
}
dns_zone_t *p;
p != NULL;
p = ISC_LIST_NEXT(p, link))
{
}
return (ISC_R_SUCCESS);
}
void
}
static void
}
void
}
void
}
void
}
int
return (zmgr->transfersin);
}
void
}
int
return (zmgr->transfersperns);
}
/*
* Try to start a new incoming zone transfer to fill a quota
* slot that was just vacated.
*
* Requires:
* The zone manager is locked by the caller.
*/
static void
static char me[] = "zmgr_resume_xfrs";
{
if (result == ISC_R_SUCCESS) {
/*
* We successfully filled the slot. We're done.
*/
break;
} else if (result == ISC_R_QUOTA) {
/*
* Not enough quota. This is probably the per-server
* quota, because we only get called when a unit of
* global quota has just been freed. Try the next
* zone, it may succeed if it uses another master.
*/
continue;
} else {
"starting zone transfer: %s",
break;
}
}
}
/*
* Try to start an incoming zone transfer for 'zone', quota permitting.
*
* Requires:
* The zone manager is locked by the caller.
*
* Returns:
* ISC_R_SUCCESS There was enough quota and we attempted to
* start a transfer. zone_xfrdone() has been or will
* be called.
* ISC_R_QUOTA Not enough quota.
* Others Failure.
*/
static isc_result_t
int nxfrsin, nxfrsperns;
dns_zone_t *x;
isc_event_t *e;
/*
* Find any configured information about the server we'd
* like to transfer this zone from.
*/
/*
* Determine the total maximum number of simultaneous
* transfers allowed, and the maximum for this specific
* master.
*/
/*
* Count the total number of transfers that are in progress,
* and the number of transfers in progress from this master.
* We linearly scan a list of all transfers; if this turns
* out to be too slow, we could hash on the master address.
*/
nxfrsin = nxfrsperns = 0;
x != NULL;
x = ISC_LIST_NEXT(x, statelink))
{
nxfrsin++;
nxfrsperns++;
}
/* Enforce quota. */
if (nxfrsin >= maxtransfersin)
return (ISC_R_QUOTA);
if (nxfrsperns >= maxtransfersperns)
return (ISC_R_QUOTA);
/*
* We have sufficient quota. Move the zone to the "xfrin_in_progress"
* list and send it an event to let it start the actual transfer in the
* context of its own task.
*/
sizeof(isc_event_t));
if (e == NULL)
return (ISC_R_NOMEMORY);
/*
* Make sure the zone does not go away before it has processed
* the event; in effect, the event is attached to the zone.
*
* XXXAG This should be done as soon as the zone goes on the
* queue, using irefs.
*/
return (ISC_R_SUCCESS);
}
void
}
}
/*
* Get permission to request a file handle from the OS.
* An event will be sent to action when one is available.
* There are two queues available (high and low), the high
* queue will be serviced before the low one.
*
* zonemgr_putio() must be called after the event is delivered to
* 'action'.
*/
static isc_result_t
{
return (ISC_R_NOMEMORY);
return (ISC_R_NOMEMORY);
}
if (queue) {
else
}
if (!queue) {
}
return (ISC_R_SUCCESS);
}
static void
else
}
}
static void
/*
* If we are queued to be run then dequeue.
*/
else
}
if (send_event) {
}
}
static void
char *buf;
int buflen;
const char me[] = "zone_saveunique";
return;
if (result != ISC_R_SUCCESS)
goto cleanup;
if (result != ISC_R_SUCCESS)
goto cleanup;
}
#if 0
/* Hook for ondestroy notifcation from a database. */
static void
"database (%p) destroyed", (void*) db);
}
#endif