zone.c revision 25d161ae439d88bf1064cc5cda7becc2f1b91be6
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * Copyright (C) 1999, 2000 Internet Software Consortium.
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley * Permission to use, copy, modify, and distribute this software for any
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley * purpose with or without fee is hereby granted, provided that the above
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley * copyright notice and this permission notice appear in all copies.
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
15a44745412679c30a6d022733925af70a38b715David Lawrence * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
15a44745412679c30a6d022733925af70a38b715David Lawrence * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
15a44745412679c30a6d022733925af70a38b715David Lawrence * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
15a44745412679c30a6d022733925af70a38b715David Lawrence * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15a44745412679c30a6d022733925af70a38b715David Lawrence * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
15a44745412679c30a6d022733925af70a38b715David Lawrence * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
b2ca6fd3a8293440b4d263723525396059cf2400Brian Wellington/* $Id: zone.c,v 1.107 2000/05/10 04:47:03 marka Exp $ */
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley/* XXX remove once config changes are in place */
b12f0228b32775ee688ed21ddbf3a116c1adfb43Michael Graff#define dns_zone_uptodate(x) zone_log(x, me, ISC_LOG_INFO, "dns_zone_uptodate")
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley#define MAX_XFER_TIME (2*3600) /* Documented default is 2 hours. */
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley#define RANGE(a, b, c) (((a) < (b)) ? (b) : ((a) < (c) ? (a) : (c)))
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleytypedef struct dns_zone_checkservers dns_zone_checkservers_t;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleytypedef enum {
e496615043400500492fa7b891c515c8e7cb7d08Bob Halley /* Unlocked */
e496615043400500492fa7b891c515c8e7cb7d08Bob Halley unsigned int magic;
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halley /* Locked */
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halley unsigned int erefs;
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halley unsigned int irefs;
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley unsigned int flags;
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley unsigned int db_argc;
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley unsigned int curmaster;
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley unsigned int notifycnt;
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley /* Access Control Lists */
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley#define DNS_ZONE_FLAG(z,f) (((z)->flags & (f)) != 0)
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley /* XXX MPA these may need to go back into zone.h */
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley#define DNS_ZONE_F_REFRESH 0x00000001U /* refresh check in progress */
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley#define DNS_ZONE_F_NEEDDUMP 0x00000002U /* zone need consolidation */
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley#define DNS_ZONE_F_SERVERS 0x00000004U /* servers check in progress */
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley#define DNS_ZONE_F_PARENTS 0x00000008U /* parents check in progress */
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley#define DNS_ZONE_F_CHILDREN 0x00000010U /* child check in progress */
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley#define DNS_ZONE_F_LOADED 0x00000020U /* database has loaded */
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley#define DNS_ZONE_F_EXITING 0x00000040U /* zone is being destroyed */
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley#define DNS_ZONE_F_EXPIRED 0x00000080U /* zone has expired */
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley#define DNS_ZONE_F_NEEDREFRESH 0x00000100U /* refresh check needed */
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley#define DNS_ZONE_F_UPTODATE 0x00000200U /* zone contents are
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley * uptodate */
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley#define DNS_ZONE_F_NEEDNOTIFY 0x00000400U /* need to send out notify
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley * messages */
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley#define DNS_ZONE_F_DIFFONRELOAD 0x00000800U /* generate a journal diff on
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley#define DNS_ZONE_OPTION(z,o) (((z)->options & (o)) != 0)
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley /* Locked by rwlock. */
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley /* Locked by conflock. */
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley /* Contains its own lock. */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Hold notify state.
0180ccf72c79b98eb8ee5abbb7331aec6951dd9fBob Halleystatic isc_result_t zone_settimer(dns_zone_t *, isc_stdtime_t);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleystatic void zone_log(dns_zone_t *zone, const char *, int, const char *msg,
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic void dns_zone_transfer_in(dns_zone_t *zone);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleystatic isc_result_t dns_zone_tostr(dns_zone_t *zone, isc_mem_t *mctx,
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleystatic isc_result_t replacedb(dns_zone_t *zone, dns_db_t *db,
078d49b63324f01d98301ee21671abee0c41fcdeBob Halleystatic isc_result_t default_journal(dns_zone_t *zone);
0180ccf72c79b98eb8ee5abbb7331aec6951dd9fBob Halleystatic void releasezone(dns_zonemgr_t *zmgr, dns_zone_t *zone);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleystatic void xfrdone(dns_zone_t *zone, isc_result_t result);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleystatic void zone_shutdown(isc_task_t *, isc_event_t *);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley/* ondestroy example */
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleystatic void dns_zonemgr_dbdestroyed(isc_task_t *task, isc_event_t *event);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleystatic void refresh_callback(isc_task_t *, isc_event_t *);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleystatic void soa_query(dns_zone_t *, isc_taskaction_t);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleystatic int message_count(dns_message_t *msg, dns_section_t section,
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleystatic void checkservers_callback(isc_task_t *task, isc_event_t *event);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleystatic void add_address_tocheck(dns_message_t *msg,
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halleystatic void record_serial(void);
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafssonstatic void notify_find_address(notify_t *notify);
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafssonstatic void notify_send(notify_t *notify);
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafssonstatic isc_result_t notify_createmessage(dns_zone_t *zone,
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafssonstatic void notify_done(isc_task_t *task, isc_event_t *event);
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafssonstatic isc_result_t zone_dump(dns_zone_t *);
88a6fef4944a00d8350ffd8b64ef58c694b8335eMark Andrews#define ZONE_LOG(x,y) zone_log(zone, me, ISC_LOG_DEBUG(x), y)
76883e8cee593f45c65b0936e5d6e8f778d6e3efMichael Graff#define DNS_ENTER zone_log(zone, me, ISC_LOG_DEBUG(1), "enter")
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff#define DNS_LEAVE zone_log(zone, me, ISC_LOG_DEBUG(1), "leave")
69be7837c920fac5c71a73e8fad586f9a2711e96Michael Graff *** Public functions.
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafssondns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx) {
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson isc_sockaddr_fromin(&sockaddr_any4, &in4addr_any, 0);
54f959d12b5a1f9315fbf6a776c6d349316e9686Bob Halley isc_sockaddr_fromin6(&sockaddr_any6, &in6addr_any, 0);
8dfa9caeec8e68db0c937e347a3d6629e7627d54Bob Halley "isc_mutex_init() failed: %s",
84185d19c7a9ef1ac23cc6236c8773697d4efeb1Brian Wellington /* XXX MPA check that all elements are initialised */
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley ISC_EVENT_INIT(&zone->ctlevent, sizeof(zone->ctlevent), 0, NULL,
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley DNS_EVENT_ZONECONTROL, zone_shutdown, zone, zone,
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley * Managed objects. Order is important.
69be7837c920fac5c71a73e8fad586f9a2711e96Michael Graff dns_request_cancel(zone->request); /* XXXMPA */
69be7837c920fac5c71a73e8fad586f9a2711e96Michael Graff dns_request_destroy(&zone->request); /* XXXMPA */
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson dns_zonemgr_releasezone(zone->zmgr, zone);
43b8fb75704f290a48fc96461140b42b2488348dMark Andrews /* unmanaged objects */
ccbfddc70ef38263daca312d29bb8c5077e24785Bob Halley /* last stuff */
92296c744ef9ef36de499eb10b3e27800d8b24a5Mark Andrews * Single shot.
13eaef2df27683658868c3828c18880d7419a16aDavid Lawrencedns_zone_setclass(dns_zone_t *zone, dns_rdataclass_t rdclass) {
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley * Test and set.
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews REQUIRE(zone->rdclass == dns_rdataclass_none ||
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews * Single shot.
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrewsdns_zone_settype(dns_zone_t *zone, dns_zonetype_t type) {
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews * Test and set.
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews REQUIRE(zone->type == dns_zone_none || zone->type == type);
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafssondns_zone_setdbtype(dns_zone_t *zone, char *db_type) {
84185d19c7a9ef1ac23cc6236c8773697d4efeb1Brian Wellington zone->db_type = isc_mem_strdup(zone->mctx, db_type);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffdns_zone_setview(dns_zone_t *zone, dns_view_t *view) {
d981ca645597116d227a48bf37cc5edc061c854dBob Halleydns_zone_setorigin(dns_zone_t *zone, dns_name_t *origin) {
d981ca645597116d227a48bf37cc5edc061c854dBob Halley result = dns_name_dup(origin, zone->mctx, &zone->origin);
return (result);
static isc_result_t
int len;
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
return (result);
case dns_zone_master:
case dns_zone_slave:
case dns_zone_stub:
case dns_zone_hint:
case dns_zone_forward:
case dns_zone_cache:
int soacount = 0;
int nscount = 0;
case dns_zone_forward:
case dns_zone_none:
goto cleanup;
case dns_zone_master:
case dns_zone_slave:
case dns_zone_stub:
case dns_zone_hint:
case dns_zone_cache:
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
nscount = 0;
soacount = 0;
NULL);
nscount++;
NULL);
if (soacount == 0)
soacount++;
case dns_zone_master:
case dns_zone_slave:
case dns_zone_stub:
if (nscount == 0)
goto cleanup;
case dns_zone_hint:
if (nscount == 0) {
goto cleanup;
case dns_zone_cache:
goto cleanup;
zone,
sizeof(isc_event_t));
goto cleanup;
if (soacount != 0)
return (result);
#ifdef notyet
NULL);
sizeof *checkservers);
#ifdef notyet
switch (state) {
case get_a6:
case get_aaaa:
case get_a:
case get_ns:
case get_soa:
goto cleanup;
switch (state) {
case get_a6:
case get_aaaa:
case get_a:
case get_ns:
case get_soa:
goto cleanup;
goto cleanup_msgsoa;
goto cleanup_msgsoa;
goto cleanup_msgsoa;
server);
goto cleanup_zonesoa;
goto cleanup_zonesoa;
server);
#ifdef notyet
switch (type) {
case dns_rdatatype_a:
dns_rdata_freestruct(&a);
case dns_rdatatype_a6:
INSIST(0);
if (free_now)
if (doexitcheck)
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);
goto unlock;
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
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:
case dns_zone_master:
case dns_zone_slave:
case dns_zone_stub:
#ifdef notyet
case dns_zone_master:
case dns_zone_slave:
case dns_zone_stub:
case dns_zone_master:
case dns_zone_slave:
case dns_zone_stub:
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);
#ifdef notyet
static isc_result_t
(void)tmgr;
return (ISC_R_SUCCESS);
return (ISC_R_UNEXPECTED);
return (ISC_R_UNEXPECTED);
isc_socket_t *s;
== ISC_R_SUCCESS);
s = NULL;
return (result);
isc_socket_detach(&s);
return (ISC_R_SUCCESS);
static isc_result_t
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
goto detach;
goto detach;
unsigned int options;
#ifdef notyet
#ifdef notyet
case AF_INET:
case AF_INET6:
goto cleanup;
goto cleanup;
#ifdef notyet
case AF_INET:
case AF_INET6:
goto cleanup0;
goto cleanup0;
goto cleanup1;
goto cleanup2;
goto cleanup3;
goto cleanup3;
char *master;
goto next_master;
goto next_master;
goto next_master;
goto next_master;
master);
goto tcp_transfer;
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;
&message);
goto cleanup;
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);
const char *fmt, ...) {
int len;
int res = 0;
res++;
return (res);
if (idlein == 0)
if (idleout == 0)
#ifdef notyet
record_serial() {
return (ISC_FALSE);
return (result);
static isc_result_t
goto fail;
if (dump) {
goto fail;
return (ISC_R_SUCCESS);
fail:
return (result);
switch (result) {
case ISC_R_SUCCESS:
case DNS_R_UPTODATE:
if (again)
return (ISC_R_NOMEMORY);
goto free_mem;
goto free_rwlock;
goto free_conflock;
goto free_transferlist;
goto free_taskpool;
return (ISC_R_SUCCESS);
return (result);
goto cleanup_task;
goto unlock;
return (result);
dns_zone_t *p;
p != NULL;
return (ISC_R_SUCCESS);