zone.c revision 512661edd7d51c8c179cce89a855df6cec2fcdcd
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * Copyright (C) 1999, 2000 Internet Software Consortium.
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * Permission to use, copy, modify, and distribute this software for any
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * purpose with or without fee is hereby granted, provided that the above
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * copyright notice and this permission notice appear in all copies.
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley/* $Id: zone.c,v 1.174 2000/08/03 21:24:49 marka Exp $ */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#define RANGE(a, b, c) (((a) < (b)) ? (b) : ((a) < (c) ? (a) : (c)))
0e3ad060581e366d3e682caf2dd5d9ea2e0f4893Bob Halley * Default values.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#define MAX_XFER_TIME (2*3600) /* Documented default is 2 hours */
0e3ad060581e366d3e682caf2dd5d9ea2e0f4893Bob Halley /* Unlocked */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley unsigned int magic;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley /* Locked */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley unsigned int erefs;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley unsigned int irefs;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley unsigned int flags;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley unsigned int options;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley unsigned int db_argc;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#endif /* NOMINUM_PUBLIC */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley unsigned int masterscnt;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley unsigned int curmaster;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley unsigned int notifycnt;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /* Access Control Lists */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Zones in certain states such as "waiting for zone transfer"
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * or "zone transfer in progress" are kept on per-state linked lists
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halley * in the zone manager using the 'statelink' field. The 'statelist'
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halley * field points at the list the zone is currently on. It the zone
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * is not on any such list, statelist is NULL.
48481c9b6e19501457bcbc2995555412f352b99fBob Halley#define DNS_ZONE_FLAG(z,f) (((z)->flags & (f)) != 0)
48481c9b6e19501457bcbc2995555412f352b99fBob Halley /* XXX MPA these may need to go back into zone.h */
48481c9b6e19501457bcbc2995555412f352b99fBob Halley#define DNS_ZONEFLG_REFRESH 0x00000001U /* refresh check in progress */
48481c9b6e19501457bcbc2995555412f352b99fBob Halley#define DNS_ZONEFLG_NEEDDUMP 0x00000002U /* zone need consolidation */
48481c9b6e19501457bcbc2995555412f352b99fBob Halley#define DNS_ZONEFLG_USEVC 0x00000004U /* use tcp for refresh query */
48481c9b6e19501457bcbc2995555412f352b99fBob Halley/* #define DNS_ZONEFLG_UNUSED 0x00000008U */ /* unused */
48481c9b6e19501457bcbc2995555412f352b99fBob Halley/* #define DNS_ZONEFLG_UNUSED 0x00000010U */ /* unused */
48481c9b6e19501457bcbc2995555412f352b99fBob Halley#define DNS_ZONEFLG_LOADED 0x00000020U /* database has loaded */
b03b67a6f1ea2966367e7beb2ef276ed6a1d3f92Bob Halley#define DNS_ZONEFLG_EXITING 0x00000040U /* zone is being destroyed */
b03b67a6f1ea2966367e7beb2ef276ed6a1d3f92Bob Halley#define DNS_ZONEFLG_EXPIRED 0x00000080U /* zone has expired */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#define DNS_ZONEFLG_NEEDREFRESH 0x00000100U /* refresh check needed */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#define DNS_ZONEFLG_UPTODATE 0x00000200U /* zone contents are
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * uptodate */
b03b67a6f1ea2966367e7beb2ef276ed6a1d3f92Bob Halley#define DNS_ZONEFLG_NEEDNOTIFY 0x00000400U /* need to send out notify
b03b67a6f1ea2966367e7beb2ef276ed6a1d3f92Bob Halley * messages */
b03b67a6f1ea2966367e7beb2ef276ed6a1d3f92Bob Halley#define DNS_ZONEFLG_DIFFONRELOAD 0x00000800U /* generate a journal diff on
b03b67a6f1ea2966367e7beb2ef276ed6a1d3f92Bob Halley#define DNS_ZONEFLG_NOMASTERS 0x00001000U /* an attempt to refresh a
b03b67a6f1ea2966367e7beb2ef276ed6a1d3f92Bob Halley * zone with no masters
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson#define DNS_ZONE_OPTION(z,o) (((z)->options & (o)) != 0)
1ccbfca64ae86ace521053773001cb995352f96fBob Halley /* Locked by rwlock. */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /* Locked by conflock. */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * Hold notify state.
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * dns_stub holds state while performing a 'stub' transfer.
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * 'db' is the zone's 'db' or a new one if this is the initial
b8862d5130b88e7b1a257997d7909f769716d51cBob Halleystatic isc_result_t zone_settimer(dns_zone_t *, isc_stdtime_t);
b8862d5130b88e7b1a257997d7909f769716d51cBob Halleystatic void zone_log(dns_zone_t *zone, const char *, int, const char *msg,
b8862d5130b88e7b1a257997d7909f769716d51cBob Halleystatic isc_result_t dns_zone_tostr(dns_zone_t *zone, isc_mem_t *mctx,
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleystatic isc_result_t zone_replacedb(dns_zone_t *zone, dns_db_t *db,
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleystatic isc_result_t default_journal(dns_zone_t *zone);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleystatic void zone_xfrdone(dns_zone_t *zone, isc_result_t result);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleystatic void zone_shutdown(isc_task_t *, isc_event_t *);
0e3ad060581e366d3e682caf2dd5d9ea2e0f4893Bob Halley/* ondestroy example */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleystatic void dns_zonemgr_dbdestroyed(isc_task_t *task, isc_event_t *event);
1ccbfca64ae86ace521053773001cb995352f96fBob Halleystatic void refresh_callback(isc_task_t *, isc_event_t *);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleystatic void stub_callback(isc_task_t *, isc_event_t *);
1ccbfca64ae86ace521053773001cb995352f96fBob Halleystatic void soa_query(isc_task_t *, isc_event_t *);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleystatic void ns_query(dns_zone_t *zone, dns_rdataset_t *soardataset,
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleystatic int message_count(dns_message_t *msg, dns_section_t section,
1ccbfca64ae86ace521053773001cb995352f96fBob Halleystatic void notify_find_address(dns_notify_t *notify);
1ccbfca64ae86ace521053773001cb995352f96fBob Halleystatic isc_result_t notify_createmessage(dns_zone_t *zone,
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleystatic void notify_done(isc_task_t *task, isc_event_t *event);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleystatic void notify_send_toaddr(isc_task_t *task, isc_event_t *event);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleystatic void got_transfer_quota(isc_task_t *task, isc_event_t *event);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleystatic isc_result_t zmgr_start_xfrin_ifquota(dns_zonemgr_t *zmgr,
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleystatic void zmgr_resume_xfrs(dns_zonemgr_t *zmgr);
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyzone_get_from_db(dns_db_t *db, dns_name_t *origin, unsigned int *nscount,
ced5499494f8afba75c056eb2f3933de24a5f360Bob Halley char *s = NULL; \
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley#define ZONE_LOG(x,y) zone_log(zone, me, ISC_LOG_DEBUG(x), y)
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley#define DNS_ENTER zone_log(zone, me, ISC_LOG_DEBUG(1), "enter")
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley#define DNS_LEAVE zone_log(zone, me, ISC_LOG_DEBUG(1), "leave")
63e6086ef99eca768a4cd69871038181251905bbBob Halley *** Public functions.
1ccbfca64ae86ace521053773001cb995352f96fBob Halleydns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx) {
1ccbfca64ae86ace521053773001cb995352f96fBob Halley "isc_mutex_init() failed: %s",
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /* XXX MPA check that all elements are initialised */
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley#endif /* NOMINUM_PUBLIC */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley ISC_EVENT_INIT(&zone->ctlevent, sizeof(zone->ctlevent), 0, NULL,
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley DNS_EVENT_ZONECONTROL, zone_shutdown, zone, zone,
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * Free a zone. Because we require that there be no more
63e6086ef99eca768a4cd69871038181251905bbBob Halley * outstanding events or references, no locking is necessary.
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley * Managed objects. Order is important.
63e6086ef99eca768a4cd69871038181251905bbBob Halley dns_request_destroy(&zone->request); /* XXXMPA */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /* Unmanaged objects */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley dns_zone_setmasterswithkeys(zone, NULL, NULL, 0);
7f705ac9a20e82264113e561a515d54dde5bcea3Bob Halley#else /* NOMINUM_PUBLIC */
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley#endif /* NOMINUM_PUBLIC */
b687c057fbd8b88738300a5038538e589677fe18Bob Halley /* last stuff */
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley * Single shot.
1ccbfca64ae86ace521053773001cb995352f96fBob Halleydns_zone_setclass(dns_zone_t *zone, dns_rdataclass_t rdclass) {
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Test and set.
return (result);
return (result);
return (result);
static isc_result_t
int len;
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
return (result);
unsigned int soacount = 0;
unsigned int nscount = 0;
goto cleanup;
goto cleanup;
goto cleanup;
&db);
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
nscount = 0;
soacount = 0;
case dns_zone_master:
case dns_zone_slave:
case dns_zone_stub:
goto cleanup;
if (nscount == 0)
isc_time_t t;
goto cleanup;
zone,
sizeof(isc_event_t));
goto cleanup;
return (result);
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);
if (free_now)
static isc_result_t
if (value)
if (value)
goto cleanup;
goto cleanup;
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
goto unlock;
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
#ifndef NOMINUM_PUBLIC
return (result);
#ifndef NOMINUM_PUBLIC
#ifndef NOMINUM_PUBLIC
#ifndef NOMINUM_PUBLIC
sizeof(dns_name_t));
if (count == 0)
goto unlock;
goto unlock;
#ifndef NOMINUM_PUBLIC
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);
case dns_zone_slave:
case dns_zone_stub:
case dns_zone_slave:
case dns_zone_stub:
case dns_zone_master:
case dns_zone_master:
case dns_zone_slave:
return (result);
static isc_result_t
char *buf;
int buflen;
return (ISC_R_NOMEMORY);
goto cleanup;
goto cleanup;
&dns_master_style_default, f);
n = fflush(f);
n = ferror(f);
n = fclose(f);
return (result);
return (result);
static isc_boolean_t
return (ISC_TRUE);
return (ISC_TRUE);
return (ISC_FALSE);
static isc_result_t
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
goto detach;
goto detach;
unsigned int options;
static isc_result_t
isc_event_t *e;
if (e == NULL)
return (ISC_R_NOMEMORY);
isc_event_free(&e);
return (result);
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup1;
goto cleanup2;
goto cleanup3;
goto cleanup3;
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;
goto same_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 detach;
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;
isc_time_t t;
goto next_master;
goto next_master;
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);
goto cleanup;
DNS_REQUESTOPT_TCP : 0;
goto cleanup;
goto cleanup;
goto cleanup;
&node);
goto cleanup;
goto cleanup;
goto cleanup;
static isc_result_t
case dns_zone_master:
case dns_zone_slave:
case dns_zone_stub:
if (next == 0) {
return (result);
return (ISC_R_SUCCESS);
static isc_result_t
isc_region_t r;
&message);
goto fail;
goto cleanup;
goto cleanup;
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
NULL);
goto done;
goto done;
goto done;
isc_buffer_usedregion(b, &r);
goto done;
goto done;
done:
fail:
return (result);
return (DNS_R_FORMERR);
return (DNS_R_NOTIMP);
return (ISC_R_SUCCESS);
return (DNS_R_REFUSED);
&rdataset);
return (ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
int len;
int count = 0;
count++;
return (count);
if (idlein == 0)
if (idleout == 0)
return (ISC_FALSE);
return (result);
static isc_result_t
goto fail;
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:
isc_time_t t;
nscount = 0;
soacount = 0;
if (nscount == 0)
goto cleanup;
#ifndef NOMINUM_PUBLIC
if (gotkey) {
goto cleanup;
return (ISC_R_NOMEMORY);
goto free_mem;
goto free_rwlock;
goto free_conflock;
goto free_taskpool;
goto free_task;
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);