zone.c revision f0ffc28f61a68b350fef9257f5f50e1ac866e0ab
7d32c065c7bb56f281651ae3dd2888f32ce4f1d9Bob Halley * Copyright (C) 1999-2002 Internet Software Consortium.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Permission to use, copy, modify, and distribute this software for any
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * purpose with or without fee is hereby granted, provided that the above
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * copyright notice and this permission notice appear in all copies.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence/* $Id: zone.c,v 1.365 2002/03/27 04:48:21 marka Exp $ */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#define ZONE_MAGIC ISC_MAGIC('Z', 'O', 'N', 'E')
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#define DNS_ZONE_VALID(zone) ISC_MAGIC_VALID(zone, ZONE_MAGIC)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#define NOTIFY_MAGIC ISC_MAGIC('N', 't', 'f', 'y')
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#define DNS_NOTIFY_VALID(notify) ISC_MAGIC_VALID(notify, NOTIFY_MAGIC)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#define STUB_MAGIC ISC_MAGIC('S', 't', 'u', 'b')
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews#define DNS_STUB_VALID(stub) ISC_MAGIC_VALID(stub, STUB_MAGIC)
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews#define ZONEMGR_MAGIC ISC_MAGIC('Z', 'm', 'g', 'r')
62c1de9d9485003ea5af13061f1d30f081442ee9Michael Graff#define DNS_ZONEMGR_VALID(stub) ISC_MAGIC_VALID(stub, ZONEMGR_MAGIC)
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson#define LOAD_MAGIC ISC_MAGIC('L', 'o', 'a', 'd')
96805adfc95a9e0c5b800869dd4afe55b5616f12James Brister#define DNS_LOAD_VALID(load) ISC_MAGIC_VALID(load, LOAD_MAGIC)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#define FORWARD_MAGIC ISC_MAGIC('F', 'o', 'r', 'w')
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff#define DNS_FORWARD_VALID(load) ISC_MAGIC_VALID(load, FORWARD_MAGIC)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#define DNS_IO_VALID(load) ISC_MAGIC_VALID(load, IO_MAGIC)
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews * Ensure 'a' is at least 'min' but not more than 'max'.
94a08e09db3dc844b6ee4841c368a2d7074a9c3fAndreas Gustafsson (((a) < (min)) ? (min) : ((a) < (max) ? (a) : (max)))
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Default values.
62c1de9d9485003ea5af13061f1d30f081442ee9Michael Graff#define MAX_XFER_TIME (2*3600) /* Documented default is 2 hours */
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence do { (z)->locked = ISC_FALSE; UNLOCK(&(z)->lock); } while (0)
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews /* Unlocked */
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews unsigned int magic;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews /* Locked */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int irefs;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff unsigned int flags;
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews unsigned int db_argc;
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews /* Access Control Lists */
d981ca645597116d227a48bf37cc5edc061c854dBob Halley * Zones in certain states such as "waiting for zone transfer"
d981ca645597116d227a48bf37cc5edc061c854dBob Halley * or "zone transfer in progress" are kept on per-state linked lists
f1b0e9107d5fc7669920b76b4e32f93e9d16c85cBob Halley * in the zone manager using the 'statelink' field. The 'statelist'
f1b0e9107d5fc7669920b76b4e32f93e9d16c85cBob Halley * field points at the list the zone is currently on. It the zone
f1b0e9107d5fc7669920b76b4e32f93e9d16c85cBob Halley * is not on any such list, statelist is NULL.
d981ca645597116d227a48bf37cc5edc061c854dBob Halley * Optional per-zone statistics counters (NULL if not present).
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley#define DNS_ZONE_FLAG(z,f) (ISC_TF(((z)->flags & (f)) != 0))
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley#define DNS_ZONE_SETFLAG(z,f) do { \
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley (z)->flags |= (f); \
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley#define DNS_ZONE_CLRFLAG(z,f) do { \
62c1de9d9485003ea5af13061f1d30f081442ee9Michael Graff (z)->flags &= ~(f); \
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley /* XXX MPA these may need to go back into zone.h */
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley#define DNS_ZONEFLG_REFRESH 0x00000001U /* refresh check in progress */
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley#define DNS_ZONEFLG_NEEDDUMP 0x00000002U /* zone need consolidation */
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley#define DNS_ZONEFLG_USEVC 0x00000004U /* use tcp for refresh query */
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews#define DNS_ZONEFLG_DUMPING 0x00000008U /* a dump is in progress */
struct dns_zonemgr {
unsigned int magic;
unsigned int serialqueryrate;
struct dns_notify {
unsigned int magic;
unsigned int flags;
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);
#define DNS_ZONE_JITTER_ADD(a, b, c) \
#define DNS_ZONE_TIME_ADD(a, b, c) \
return (ISC_R_NOMEMORY);
return (ISC_R_UNEXPECTED);
#ifdef DNS_ZONE_CHECKLOCK
goto free_mutex;
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
== ISC_R_SUCCESS);
== ISC_R_SUCCESS);
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;
&db);
goto cleanup;
goto cleanup;
goto cleanup;
return (result);
unsigned int options;
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);
if (count != 0) {
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:
case ISC_R_NOTFOUND:
if (again)
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;
addrbuf);
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;
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 same_master;
goto next_master;
goto next_master;
goto next_master;
goto same_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;
master);
goto same_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 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);
static isc_result_t
goto cleanup;
goto cleanup;
goto cleanup;
== 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);
return (result);
unsigned int count = 0;
switch (state) {
count++;
count++;
case DNS_ZONESTATE_SOAQUERY:
count++;
case DNS_ZONESTATE_ANY:
count++;
INSIST(0);
return (count);