zone.c revision c583a85db061a6a6eb4e4df27c0a5afa33d26f36
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * Copyright (C) 1999 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 DISCLAIMS
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /* $Id: zone.c,v 1.11 1999/09/23 23:17:21 halley Exp $ */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff/* XXX remove once config changes are in place */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#define dns_zone_uptodate(x) dns_zone_logerror(x, "dns_zone_uptodate")
1ccbfca64ae86ace521053773001cb995352f96fBob Halley ((zone) != NULL && (zone)->magic == ZONE_MAGIC_USED)
0e3ad060581e366d3e682caf2dd5d9ea2e0f4893Bob Halley ((zone) != NULL && (zone)->magic == ZONE_MAGIC_FREE)
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley ((server != NULL) && (server)->magic == CHECKSERVERS_MAGIC)
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Grafftypedef enum {
1ccbfca64ae86ace521053773001cb995352f96fBob Halley /* Unlocked */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley unsigned int magic;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley /* Locked */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley unsigned int references;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * XXX merge w/ updatelog to
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * locate transaction log
1ccbfca64ae86ace521053773001cb995352f96fBob Halley unsigned int flags;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley unsigned int options;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley unsigned int setoptions;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley unsigned int db_argc;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley unsigned int masterscnt;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley unsigned int curmaster;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley unsigned int notifycnt;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /* Access Control Lists */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#define DNS_ZONE_FLAG(z,f) (((z)->flags & (f)) != 0)
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /* XXX MPA these may need to go back into zone.h */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#define DNS_ZONE_F_REFRESH 0x00000001U /* refresh check in progress */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley#define DNS_ZONE_F_NEEDDUMP 0x00000002U /* zone need consolidation */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley#define DNS_ZONE_F_SERVERS 0x00000004U /* servers check in progress */
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley#define DNS_ZONE_F_PARENTS 0x00000008U /* parents check in progress */
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley#define DNS_ZONE_F_CHILDREN 0x00000010U /* child check in progress */
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley#define DNS_ZONE_F_LOADED 0x00000020U /* database has loaded */
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley#define DNS_ZONE_F_EXITING 0x00000040U /* zone is being destroyed */
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley#define DNS_ZONE_F_EXPIRED 0x00000080U /* zone has expired */
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley#define DNS_ZONE_F_NEEDREFRESH 0x00000100U /* refresh check needed */
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley#define DNS_ZONE_F_UPTODATE 0x00000200U /* zone contents are
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley * uptodate */
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley#define DNS_ZONE_OPTION(z,o) ((((z)->setoptions & (o)) != 0) ? \
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley (((z)->options & (o)) != 0) : \
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halleystatic void refresh_callback(isc_task_t *, isc_event_t *);
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halleystatic void zone_shutdown(isc_task_t *, isc_event_t *);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleystatic void soa_query(dns_zone_t *, isc_taskaction_t);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleystatic dns_result_t zone_settimer(dns_zone_t *, isc_stdtime_t);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleystatic dns_result_t dns_notify(dns_name_t *, isc_sockaddr_t *, dns_rdatatype_t,
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halley dns_rdataclass_t, isc_sockaddr_t *, isc_mem_t *);
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halleystatic void checkservers_callback(isc_task_t *task, isc_event_t *event);
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halleystatic void dns_zone_logerror(dns_zone_t *zone, const char *msg, ...);
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halleystatic int message_count(dns_message_t *msg, dns_section_t section,
48481c9b6e19501457bcbc2995555412f352b99fBob Halleystatic void sockaddr_fromaddr(isc_sockaddr_t *sockaddr, dns_c_addr_t *a,
48481c9b6e19501457bcbc2995555412f352b99fBob Halley unsigned int port);
48481c9b6e19501457bcbc2995555412f352b99fBob Halleystatic void add_address_tocheck(dns_message_t *msg,
48481c9b6e19501457bcbc2995555412f352b99fBob Halleyextern void dns_zone_transfer_in(dns_zone_t *zone);
48481c9b6e19501457bcbc2995555412f352b99fBob Halleystatic void record_serial(void);
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley *** Public functions.
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halleydns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx) {
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley "isc_mutex_init() failed: %s",
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley /* XXX MPA check that all elements are initialised */
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson zone->check_names = dns_c_severity_ignore;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley /* managed objects */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff /* order is important */
0e3ad060581e366d3e682caf2dd5d9ea2e0f4893Bob Halley dns_resolver_destroyfetch(&zone->fetch, zone->task);
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley /* unmanaged objects */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /* last stuff */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Single shot.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleydns_zone_setclass(dns_zone_t *zone, dns_rdataclass_t rdclass) {
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Single shot.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleydns_zone_settype(dns_zone_t *zone, dns_zonetype_t type) {
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley REQUIRE(zone->type == dns_zone_none || zone->type == type);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffdns_zone_setdbtype(dns_zone_t *zone, char *db_type) {
d2615909402705135d0560ad9d11f4302053c17cBob Halley zone->db_type = isc_mem_strdup(zone->mctx, db_type);
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halleydns_zone_setorigin(dns_zone_t *zone, char *origin) {
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley isc_buffer_init(&buffer, origin, strlen(origin), ISC_BUFFERTYPE_TEXT);
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley return (dns_name_fromtext(dns_fixedname_name(&zone->origin),
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffdns_zone_setdatabase(dns_zone_t *zone, const char *database) {
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley zone->database = isc_mem_strdup(zone->mctx, database);
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halleydns_zone_setupdatelog(dns_zone_t *zone, char *updatelog) {
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley zone->updatelog = isc_mem_strdup(zone->mctx, updatelog);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleydns_zone_setixfrlog(dns_zone_t *zone, const char *ixfrlog) {
1ccbfca64ae86ace521053773001cb995352f96fBob Halley zone->ixfrlog = isc_mem_strdup(zone->mctx, ixfrlog);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley REQUIRE(dns_name_countlabels(dns_fixedname_name(&zone->origin)) != 0);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley /*FALLTHROUGH*/
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley result = dns_db_create(zone->mctx, zone->db_type,
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * XXX Initiate zone transfer? We may need a error code that
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * indicates that the "permanent" form does not exist.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * XXX apply update log to zone.
0b157747b398ab59f42f584adc70a6c97d771abeBob Halley * Obtain ns and soa counts for top of zone.
1ccbfca64ae86ace521053773001cb995352f96fBob Halley result = dns_db_findnode(zone->top, dns_fixedname_name(&zone->origin),
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley result = dns_db_findrdataset(zone->top, node, version,
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff result = dns_db_findrdataset(zone->top, node, version,
1ccbfca64ae86ace521053773001cb995352f96fBob Halley dns_db_closeversion(zone->top, &version, ISC_FALSE);
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley * Master / Slave / Stub zones require both NS and SOA records at
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley * the top of the zone.
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff * Hint zones only require NS records.
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley * Cache zones have no reqirements.
if (soacount != 0)
return (DNS_R_SUCCESS);
#ifdef notyet
NULL);
sizeof *checkservers);
#ifdef notyet
char *master;
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;
server);
server);
goto cleanup_msgsoa;
goto cleanup_msgsoa;
goto cleanup_msgsoa;
server);
goto cleanup_zonesoa;
goto cleanup_zonesoa;
server);
switch (type) {
case dns_rdatatype_a:
dns_rdata_freestruct(&a);
case dns_rdatatype_a6:
INSIST(0);
if (value)
if (value)
unsigned int *optionsmask)
char **new;
return (DNS_R_NOMEMORY);
return (DNS_R_NOMEMORY);
return (DNS_R_SUCCESS);
return (DNS_R_SUCCESS);
return (DNS_R_NOMEMORY);
return (DNS_R_SUCCESS);
return (DNS_R_NOMEMORY);
return (DNS_R_SUCCESS);
dns_db_t *
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_stub:
case dns_zone_master:
case dns_zone_slave:
case dns_zone_stub:
case dns_zone_master:
case dns_zone_slave:
case dns_zone_stub:
&rdsiter);
goto retry;
return (result);
return (DNS_R_UNEXPECTED);
return (DNS_R_UNEXPECTED);
return (DNS_R_UNEXPECTED);
isc_socket_t *s;
== ISC_R_SUCCESS);
s = NULL;
return (result);
isc_socket_detach(&s);
return (DNS_R_SUCCESS);
return (DNS_R_NOTIMPLEMENTED);
goto cleanup1;
goto cleanup2;
char *master;
goto next_master;
goto next_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;
#ifdef notyet
static dns_result_t
case dns_zone_master:
case dns_zone_slave:
case dns_zone_stub:
if (next == 0) {
ISC_TRUE);
return (DNS_R_UNEXPECTED);
return (DNS_R_SUCCESS);
static dns_result_t
return (result);
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
return (result);
return (DNS_R_REFUSED);
return (DNS_R_REFUSED);
&rdataset);
return (DNS_R_SUCCESS);
return (DNS_R_SUCCESS);
return (DNS_R_SUCCESS);
return (ISC_R_NOTIMPLEMENTED);
isc_uint32_t i;
case dns_c_zone_master:
return (iresult);
return (iresult);
return (result);
return (result);
case dns_c_zone_slave:
return (iresult);
return (iresult);
return (result);
return (result);
/* czone->u.szone.ixfr_tmp; XXX*/
return (result);
return (result);
case dns_c_zone_forward:
#ifdef notyet
case dns_c_zone_stub:
return (iresult);
return (iresult);
return (result);
case dns_c_zone_hint:
return (iresult);
return (result);
return (DNS_R_SUCCESS);
int len;
&buffer);
len = 0;
int res = 0;
res++;
return (res);
unsigned int port) {
case AF_INET:
case AF_INET6:
INSIST(0);
record_serial() {