zone.c revision da4535c4b43a7a39712c9a87325127ee2f22a2ad
5cd4555ad444fd391002ae32450572054369fd42Rob Austein * Copyright (C) 1999-2001 Internet Software Consortium.
4b01d45a49f1c2cc4bddc9a1b4c78232867de134Andreas Gustafsson * Permission to use, copy, modify, and distribute this software for any
938440694b33cd752e9e4b71a526368b4811c177Tinderbox User * purpose with or without fee is hereby granted, provided that the above
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews * copyright notice and this permission notice appear in all copies.
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
4b01d45a49f1c2cc4bddc9a1b4c78232867de134Andreas Gustafsson * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
4b01d45a49f1c2cc4bddc9a1b4c78232867de134Andreas Gustafsson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
4b01d45a49f1c2cc4bddc9a1b4c78232867de134Andreas Gustafsson * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews/* $Id: zone.c,v 1.345 2001/09/12 03:46:32 marka Exp $ */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONE_VALID(zone) ISC_MAGIC_VALID(zone, ZONE_MAGIC)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define NOTIFY_MAGIC ISC_MAGIC('N', 't', 'f', 'y')
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_NOTIFY_VALID(notify) ISC_MAGIC_VALID(notify, NOTIFY_MAGIC)
821350367e2c7313c02eb275e8e05d5193b47cfdJeremy C. Reed#define STUB_MAGIC ISC_MAGIC('S', 't', 'u', 'b')
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_STUB_VALID(stub) ISC_MAGIC_VALID(stub, STUB_MAGIC)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define ZONEMGR_MAGIC ISC_MAGIC('Z', 'm', 'g', 'r')
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONEMGR_VALID(stub) ISC_MAGIC_VALID(stub, ZONEMGR_MAGIC)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_LOAD_VALID(load) ISC_MAGIC_VALID(load, LOAD_MAGIC)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define FORWARD_MAGIC ISC_MAGIC('F', 'o', 'r', 'w')
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_FORWARD_VALID(load) ISC_MAGIC_VALID(load, FORWARD_MAGIC)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_IO_VALID(load) ISC_MAGIC_VALID(load, IO_MAGIC)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Ensure 'a' is at least 'min' but not more than 'max'.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein (((a) < (min)) ? (min) : ((a) < (max) ? (a) : (max)))
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Default values.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define MAX_XFER_TIME (2*3600) /* Documented default is 2 hours */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein do { (z)->locked = ISC_FALSE; UNLOCK(&(z)->lock); } while (0)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /* Unlocked */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein unsigned int magic;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /* Locked */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein unsigned int irefs;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein unsigned int flags;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein unsigned int options;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein unsigned int db_argc;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein unsigned int curmaster;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein unsigned int notifycnt;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /* Access Control Lists */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Zones in certain states such as "waiting for zone transfer"
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * or "zone transfer in progress" are kept on per-state linked lists
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * in the zone manager using the 'statelink' field. The 'statelist'
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * field points at the list the zone is currently on. It the zone
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * is not on any such list, statelist is NULL.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Optional per-zone statistics counters (NULL if not present).
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONE_FLAG(z,f) (ISC_TF(((z)->flags & (f)) != 0))
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONE_SETFLAG(z,f) do { \
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein (z)->flags |= (f); \
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONE_CLRFLAG(z,f) do { \
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein (z)->flags &= ~(f); \
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /* XXX MPA these may need to go back into zone.h */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONEFLG_REFRESH 0x00000001U /* refresh check in progress */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONEFLG_NEEDDUMP 0x00000002U /* zone need consolidation */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONEFLG_USEVC 0x00000004U /* use tcp for refresh query */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONEFLG_DUMPING 0x00000008U /* a dump is in progress */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONEFLG_HASINCLUDE 0x00000010U /* $INCLUDE in zone file */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONEFLG_LOADED 0x00000020U /* database has loaded */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONEFLG_EXITING 0x00000040U /* zone is being destroyed */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONEFLG_EXPIRED 0x00000080U /* zone has expired */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONEFLG_NEEDREFRESH 0x00000100U /* refresh check needed */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONEFLG_UPTODATE 0x00000200U /* zone contents are
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * uptodate */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONEFLG_NEEDNOTIFY 0x00000400U /* need to send out notify
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * messages */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONEFLG_DIFFONRELOAD 0x00000800U /* generate a journal diff on
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONEFLG_NOMASTERS 0x00001000U /* an attempt to refresh a
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * zone with no masters
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * occured */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONEFLG_LOADING 0x00002000U /* load from disk in progress*/
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONEFLG_HAVETIMERS 0x00004000U /* timer values have been set
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * from SOA (if not set, we
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * are still using
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * default timer values) */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONEFLG_FORCEXFER 0x00008000U /* Force a zone xfer */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONEFLAG_NOIXFR 0x00100000U /* IXFR failed, force AXFR */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONE_OPTION(z,o) (((z)->options & (o)) != 0)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein/* Flags for zone_load() */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#define DNS_ZONELOADFLAG_NOSTAT 0x00000001U /* Do not stat() master files */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein unsigned int magic;
int transfersin;
int transfersperns;
unsigned int serialqueryrate;
struct dns_notify {
unsigned int magic;
unsigned int flags;
unsigned int attempt;
struct dns_stub {
unsigned int magic;
struct dns_load {
unsigned int magic;
struct dns_forward {
unsigned int magic;
void *callback_arg;
struct dns_io {
unsigned int magic;
unsigned int flags,
static isc_result_t
const char *templat);
return (ISC_R_NOMEMORY);
return (ISC_R_UNEXPECTED);
#ifdef DNS_ZONE_CHECKLOCK
goto free_mutex;
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
goto nomem;
for (i = 0; i < dbargc; i++)
for (i = 0; i < dbargc; i++) {
goto nomem;
goto unlock;
for (i = 0; i < dbargc; i++) {
return (result);
return (result);
static isc_result_t
char *copy;
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
return (result);
static isc_result_t
char *journal;
return (ISC_R_NOMEMORY);
return (result);
return (result);
static isc_boolean_t
static isc_result_t
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
&filetime);
goto cleanup;
goto cleanup;
&db);
goto cleanup;
goto cleanup;
goto cleanup;
return (result);
goto fail;
goto fail;
fail:
goto fail;
goto fail;
fail:
static isc_result_t
return (ISC_R_NOMEMORY);
goto cleanup;
goto cleanup;
unsigned int options;
return (result);
return (result);
return (result);
static isc_result_t
unsigned int soacount = 0;
unsigned int nscount = 0;
goto cleanup;
goto cleanup;
goto cleanup;
nscount = 0;
soacount = 0;
case dns_zone_master:
case dns_zone_slave:
case dns_zone_stub:
if (nscount == 0) {
goto cleanup;
isc_time_t t;
goto cleanup;
zone,
sizeof(isc_event_t));
goto cleanup;
if (needdump)
return (result);
return (result);
static isc_boolean_t
return (ISC_TRUE);
return (ISC_FALSE);
static isc_result_t
unsigned int *nscount)
unsigned int count;
*nscount = 0;
goto invalidate_rdataset;
goto invalidate_rdataset;
count = 0;
count++;
return (result);
static isc_result_t
unsigned int *soacount,
unsigned int count;
goto invalidate_rdataset;
count = 0;
count++;
if (count > 0) {
return (result);
static isc_result_t
goto closeversion;
minimum);
return (answer);
unsigned int refs;
if (refs == 0) {
if (free_now)
if (free_needed)
if (value)
if (value)
return (ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
goto unlock;
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
return (result);
sizeof(dns_name_t));
if (count == 0)
goto unlock;
goto unlock;
goto unlock;
for (i = 0; i < count; i++)
for (i = 0; i < count; i++) {
sizeof(dns_name_t));
goto allocfail;
newname[i]);
for (i = 0; i < count; i++)
newname[i],
goto unlock;
return (result);
return (result);
static inline isc_boolean_t
if (!dumping) {
return (dumping);
case dns_zone_slave:
case dns_zone_stub:
case dns_zone_slave:
case dns_zone_stub:
case dns_zone_master:
case dns_zone_slave:
if (!dumping) {
case dns_zone_master:
case dns_zone_slave:
goto unlock;
goto unlock;
if (!dumping)
return (result);
if (!dumping)
return (result);
switch (tresult) {
case ISC_R_SUCCESS:
case ISC_R_NOSPACE:
static isc_result_t
redo:
goto fail;
goto fail;
if (compact) {
fail:
if (again)
goto redo;
return (result);
return (DNS_R_NOTLOADED);
return (result);
static isc_boolean_t
return (ISC_TRUE);
return (ISC_TRUE);
return (ISC_FALSE);
if (!locked)
if (!locked)
if (locked)
static isc_result_t
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
unsigned int options;
goto destroy;
goto destroy;
static isc_result_t
isc_event_t *e;
if (e == NULL)
return (ISC_R_NOMEMORY);
isc_event_free(&e);
return (result);
int timeout;
goto cleanup;
goto cleanup;
goto cleanup;
addrbuf);
case PF_INET:
case PF_INET6:
goto cleanup_key;
&new);
goto cleanup;
goto cleanup;
unsigned int flags = 0;
goto cleanup1;
goto cleanup2;
&master);
goto cleanup3;
goto cleanup3;
if (!loggednotify) {
serial);
if (isqueued) {
static inline isc_result_t
goto fail;
goto fail;
goto fail;
&rdataset);
goto fail;
goto fail;
&rdataset);
goto fail;
goto fail;
&rdataset);
goto fail;
goto fail;
goto fail;
return (ISC_R_SUCCESS);
fail:
return (result);
goto next_master;
goto next_master;
goto next_master;
goto next_master;
goto next_master;
master);
goto next_master;
goto same_master;
master);
goto next_master;
if (cnamecnt != 0) {
goto next_master;
if (nscnt == 0) {
goto next_master;
goto next_master;
goto free_stub;
goto free_stub;
goto free_stub;
goto done;
done:
goto same_master;
master);
goto next_master;
goto next_master;
goto next_master;
goto next_master;
master);
goto tcp_transfer;
master);
goto next_master;
goto same_master;
goto next_master;
if (cnamecnt != 0) {
goto next_master;
goto next_master;
goto next_master;
goto next_master;
goto next_master;
goto next_master;
goto next_master;
goto next_master;
goto next_master;
goto detach;
goto detach;
goto detach;
isc_event_t *e;
if (e == NULL) {
isc_event_free(&e);
static inline isc_result_t
&message);
goto cleanup;
goto cleanup;
goto cleanup;
return (ISC_R_SUCCESS);
return (result);
int timeout;
goto cleanup;
goto cleanup;
DNS_REQUESTOPT_TCP : 0;
case PF_INET:
case PF_INET6:
goto cleanup;
goto cleanup;
if (cancel)
int timeout;
goto cleanup;
goto cleanup;
&node);
goto cleanup;
goto cleanup;
case PF_INET:
case PF_INET6:
goto cleanup;
goto cleanup;
goto unlock;
if (free_needed)
case dns_zone_master:
case dns_zone_slave:
case dns_zone_stub:
static isc_result_t
isc_region_t r;
&message);
return (result);
goto cleanup;
goto cleanup;
goto done;
goto soa_cleanup;
goto soa_cleanup;
goto soa_cleanup;
goto soa_cleanup;
goto soa_cleanup;
NULL);
goto soa_cleanup;
goto soa_cleanup;
goto soa_cleanup;
isc_buffer_usedregion(b, &r);
goto soa_cleanup;
goto soa_cleanup;
done:
return (ISC_R_SUCCESS);
return (result);
int match = 0;
return (DNS_R_FORMERR);
return (DNS_R_NOTIMP);
return (ISC_R_SUCCESS);
match > 0)
return (DNS_R_REFUSED);
&rdataset);
fromtext);
return (ISC_R_SUCCESS);
fromtext);
return (ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
const char *fmt, ...)
int count = 0;
count++;
return (count);
if (idlein == 0)
return (result);
static isc_result_t
goto fail;
if (dump)
goto fail;
return (ISC_R_SUCCESS);
fail:
return (result);
unsigned int soacount;
unsigned int nscount;
switch (result) {
case ISC_R_SUCCESS:
case DNS_R_UPTODATE:
goto same_master;
&now);
nscount = 0;
soacount = 0;
if (nscount == 0)
case DNS_R_BADIXFR:
goto same_master;
goto cleanup;
static isc_result_t
return (ISC_R_NOMORE);
case PF_INET:
case PF_INET6:
goto unlock;
return (result);
goto next_master;
goto next_master;
goto next_master;
case dns_rcode_noerror:
case dns_rcode_yxdomain:
case dns_rcode_yxrrset:
case dns_rcode_nxrrset:
case dns_rcode_refused:
case dns_rcode_nxdomain:
case dns_rcode_notzone:
case dns_rcode_notauth: {
goto next_master;
case dns_rcode_formerr:
case dns_rcode_servfail:
case dns_rcode_notimp:
case dns_rcode_badvers:
goto next_master;
return (ISC_R_NOMEMORY);
goto cleanup;
goto cleanup;
goto cleanup;
return (result);
return (ISC_R_NOMORE);
return (ISC_R_SUCCESS);
return (ISC_R_NOMORE);
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
goto free_mem;
goto free_rwlock;
goto free_taskpool;
goto free_task;
goto free_rl;
return (ISC_R_SUCCESS);
return (result);
goto cleanup_task;
goto unlock;
return (result);
if (free_now)
if (free_now)
dns_zone_t *p;
p != NULL;
return (ISC_R_SUCCESS);
static isc_result_t
dns_zone_t *x;
isc_event_t *e;
x != NULL;
nxfrsin++;
nxfrsperns++;
return (ISC_R_QUOTA);
return (ISC_R_QUOTA);
sizeof(isc_event_t));
if (e == NULL)
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
static isc_result_t
return (ISC_R_NOMEMORY);
return (ISC_R_NOMEMORY);
if (queue) {
if (!queue) {
return (ISC_R_SUCCESS);
if (send_event) {
char *buf;
int buflen;
goto cleanup;
goto cleanup;
if (value == 0)
ns = 0;
if (on) {
goto done;
goto done;
done:
return (result);
switch (dialup) {
case dns_dialuptype_no:
case dns_dialuptype_yes:
case dns_dialuptype_notify:
case dns_dialuptype_refresh:
case dns_dialuptype_passive:
INSIST(0);
unsigned int count = 0;
switch (state) {
count++;
count++;
case DNS_ZONESTATE_SOAQUERY:
count++;
case DNS_ZONESTATE_ANY:
count++;
INSIST(0);
return (count);