zone.c revision 39073e9734e5e0ebb88ab9e3b14a85b7a0b9578b
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/*
5fa46bc91672ef5737aee6f99763161511566c24Tinderbox User * Copyright (C) 1999 Internet Software Consortium.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Permission to use, copy, modify, and distribute this software for any
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * purpose with or without fee is hereby granted, provided that the above
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * copyright notice and this permission notice appear in all copies.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * SOFTWARE.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews /* $Id: zone.c,v 1.19 1999/10/13 23:32:02 marka Exp $ */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <config.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <string.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
f4b4e7c16211137332e50bcad3fef0d15639a4f1Brian Wellington#include <isc/assertions.h>
f4b4e7c16211137332e50bcad3fef0d15639a4f1Brian Wellington#include <isc/error.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <../isc/util.h> /* XXX MPA */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/timer.h>
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington#include <isc/print.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/serial.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/magic.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/confparser.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/db.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/dbiterator.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/dispatch.h>
229ce407c359b0b641759ba1fc4a5fa2054a44daBrian Wellington#include <dns/journal.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/master.h>
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington#include <dns/message.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/rcode.h>
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington#include <dns/rdata.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/rdatalist.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/rdatasetiter.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/rdatastruct.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/resolver.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/view.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/zone.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/zt.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/* XXX remove once config changes are in place */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define dns_zone_uptodate(x) dns_zone_logerror(x, "dns_zone_uptodate")
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define referral(x) ISC_FALSE
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington#include <stdarg.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington#define ZONE_MAGIC 0x5a4f4e45U
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington#define CHECKSERVERS_MAGIC 0x43484346U
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington#define DNS_ZONE_VALID(zone) \
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington ISC_MAGIC_VALID(zone, ZONE_MAGIC)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define DNS_CHECKSERVERS_VALID(server) \
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_MAGIC_VALID(zone, CHECKSERVERS_MAGIC)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#ifndef DNS_GLOBAL_OPTION /* XXX MPA */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define DNS_GLOBAL_OPTION(o) 0
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington#endif
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define DEFAULT_REFRESH 900 /*XXX*/
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define DEFAULT_RETRY 300 /*XXX*/
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define MAX_XFER_TIME 3600 /*XXX*/
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtontypedef enum {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington get_a6, get_aaaa, get_a, get_ns, get_soa
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington} dns_zone_state_t;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtontypedef struct dns_zone_checkservers {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_uint32_t magic;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_boolean_t name_known;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_name_t server;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_sockaddr_t address;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_zone_state_t state;
229ce407c359b0b641759ba1fc4a5fa2054a44daBrian Wellington dns_zone_t *zone;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_resolver_t *res;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_t *mctx;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_fetch_t *fetch;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LINK(struct dns_zone_checkservers) link;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington} dns_zone_checkservers_t;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstruct dns_zone {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /* Unlocked */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington unsigned int magic;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_mutex_t lock;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_mem_t *mctx;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /* Locked */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_db_t *top;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_timermgr_t *timgr;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_timer_t *timer;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int references;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_t origin;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char *database;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char *ixfrlog; /*
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence * XXX merge w/ updatelog to
571688b02f955f6304649866e768b1f81739cbedBrian Wellington * locate transaction log
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein */
571688b02f955f6304649866e768b1f81739cbedBrian Wellington char *updatelog;
571688b02f955f6304649866e768b1f81739cbedBrian Wellington isc_int32_t ixfrlogsize;
571688b02f955f6304649866e768b1f81739cbedBrian Wellington dns_rdataclass_t rdclass;
571688b02f955f6304649866e768b1f81739cbedBrian Wellington dns_zonetype_t type;
571688b02f955f6304649866e768b1f81739cbedBrian Wellington unsigned int flags;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int options;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int setoptions;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char * db_type;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int db_argc;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char ** db_argv;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_stdtime_t expiretime;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_stdtime_t refreshtime;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_stdtime_t dumptime;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_stdtime_t servertime;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_stdtime_t parenttime;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_stdtime_t childtime;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_uint32_t serial;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_uint32_t refresh;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_uint32_t retry;
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews isc_uint32_t expire;
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews isc_uint32_t minimum;
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews isc_sockaddr_t * masters;
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews unsigned int masterscnt;
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington in_port_t masterport;
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington unsigned int curmaster;
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington isc_sockaddr_t * notify;
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington unsigned int notifycnt;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington isc_sockaddr_t notifyfrom;
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington isc_task_t * task;
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington isc_sockaddr_t xfrsource;
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington /* Access Control Lists */
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington dns_c_ipmatchlist_t *update_acl;
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington dns_c_ipmatchlist_t *query_acl;
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington dns_c_ipmatchlist_t *xfr_acl;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington dns_c_severity_t check_names;
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington dns_c_pubkey_t *pubkey;
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews ISC_LIST(dns_zone_checkservers_t) checkservers;
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington dns_fetch_t *fetch;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_resolver_t *res;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_socketmgr_t *socketmgr;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_uint32_t xfrtime;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_boolean_t diff_on_reload;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington};
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define DNS_ZONE_FLAG(z,f) (((z)->flags & (f)) != 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* XXX MPA these may need to go back into zone.h */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define DNS_ZONE_F_REFRESH 0x00000001U /* refresh check in progress */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define DNS_ZONE_F_NEEDDUMP 0x00000002U /* zone need consolidation */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define DNS_ZONE_F_SERVERS 0x00000004U /* servers check in progress */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define DNS_ZONE_F_PARENTS 0x00000008U /* parents check in progress */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define DNS_ZONE_F_CHILDREN 0x00000010U /* child check in progress */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington#define DNS_ZONE_F_LOADED 0x00000020U /* database has loaded */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington#define DNS_ZONE_F_EXITING 0x00000040U /* zone is being destroyed */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington#define DNS_ZONE_F_EXPIRED 0x00000080U /* zone has expired */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington#define DNS_ZONE_F_NEEDREFRESH 0x00000100U /* refresh check needed */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define DNS_ZONE_F_UPTODATE 0x00000200U /* zone contents are
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * uptodate */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define DNS_ZONE_OPTION(z,o) ((((z)->setoptions & (o)) != 0) ? \
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (((z)->options & (o)) != 0) : \
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington DNS_GLOBAL_OPTION(o))
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic void refresh_callback(isc_task_t *, isc_event_t *);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic void zone_shutdown(isc_task_t *, isc_event_t *);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic void soa_query(dns_zone_t *, isc_taskaction_t);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic dns_result_t zone_settimer(dns_zone_t *, isc_stdtime_t);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic void cancel_refresh(dns_zone_t *);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic dns_result_t dns_notify(dns_name_t *, isc_sockaddr_t *, dns_rdatatype_t,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_rdataclass_t, isc_sockaddr_t *, isc_mem_t *);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic void checkservers_callback(isc_task_t *task, isc_event_t *event);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic void dns_zone_logerror(dns_zone_t *zone, const char *msg, ...);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic int message_count(dns_message_t *msg, dns_section_t section,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_rdatatype_t type);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington#if 0
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic void sockaddr_fromaddr(isc_sockaddr_t *sockaddr, dns_c_addr_t *a,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington in_port_t port);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington#endif
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic void add_address_tocheck(dns_message_t *msg,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_zone_checkservers_t *checkservers,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_rdatatype_t type);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonextern void dns_zone_transfer_in(dns_zone_t *zone);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic void record_serial(void);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_boolean_t dns_zone_equal(dns_zone_t *, dns_zone_t *);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic char * dns_zone_tostr(dns_zone_t *zone);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington/***
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington *** Public functions.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington ***/
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_result_t iresult;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_zone_t *zone;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_sockaddr_t sockaddr_any;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(zonep != NULL && *zonep == NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(mctx != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_sockaddr_fromin6(&sockaddr_any, &in6addr_any, 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone = isc_mem_get(mctx, sizeof *zone);
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington if (zone == NULL)
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington return (DNS_R_NOMEMORY);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington iresult = isc_mutex_init(&zone->lock);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington if (iresult != ISC_R_SUCCESS) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_mem_put(mctx, zone, sizeof *zone);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNEXPECTED_ERROR(__FILE__, __LINE__,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "isc_mutex_init() failed: %s",
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington isc_result_totext(iresult));
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews return (DNS_R_UNEXPECTED);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington }
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington /* XXX MPA check that all elements are initialised */
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington zone->mctx = mctx;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews zone->top = NULL;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews zone->timgr = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->references = 1; /* Implicit attach. */
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_name_init(&zone->origin, NULL);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->database = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->ixfrlog = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->ixfrlogsize = -1;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->updatelog = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->rdclass = dns_rdataclass_none;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->type = dns_zone_none;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->flags = 0;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington zone->options = 0;
18d0b5e54be891a1aa938c165b6d439859121ec8Mark Andrews zone->setoptions = 0;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington zone->db_type = NULL;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington zone->db_argc = 0;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->db_argv = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->expiretime = 0;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->refreshtime = 0;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington zone->dumptime = 0;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington zone->servertime = 0;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->parenttime = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->childtime = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->serial = 0;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington zone->refresh = DEFAULT_REFRESH;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington zone->retry = DEFAULT_RETRY;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington zone->expire = 0;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington zone->minimum = 0;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington zone->masters = NULL;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington zone->masterscnt = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->masterport = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->curmaster = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->notify = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->notifycnt = 0;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->task = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->update_acl = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->query_acl = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->xfr_acl = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->check_names = dns_c_severity_ignore;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->pubkey = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->fetch = NULL;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington zone->res = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->socketmgr = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->timer = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington ISC_LIST_INIT(zone->checkservers);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->xfrsource = sockaddr_any;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->xfrtime = MAX_XFER_TIME;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington zone->diff_on_reload = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->magic = ZONE_MAGIC;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf("create: %p: %s: references = %d\n", zone, dns_zone_tostr(zone),
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington zone->references);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson *zonep = zone;
de32cbd34e78bdd276e69cff239846760d4ee16eBrian Wellington return (DNS_R_SUCCESS);
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews}
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellingtonstatic void
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellingtonzone_free(dns_zone_t *zone) {
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington LOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(zone->references == 0);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews zone->flags |= DNS_ZONE_F_EXITING;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews UNLOCK(&zone->lock);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* managed objects */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* order is important */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (DNS_ZONE_FLAG(zone, DNS_ZONE_F_REFRESH))
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson cancel_refresh(zone);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (zone->timer != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_timer_detach(&zone->timer);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (zone->res != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_resolver_detach(&zone->res);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (zone->fetch != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_resolver_destroyfetch(zone->res, &zone->fetch);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (zone->timgr != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_timermgr_destroy(&zone->timgr);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (zone->task != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_task_destroy(&zone->task);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (zone->socketmgr != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_socketmgr_destroy(&zone->socketmgr);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* unmanaged objects */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (zone->database != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_free(zone->mctx, zone->database);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->database = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (zone->ixfrlog != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_free(zone->mctx, zone->ixfrlog);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->ixfrlog = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->ixfrlogsize = -1;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (zone->updatelog != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_free(zone->mctx, zone->updatelog);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->updatelog = NULL;
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater if (zone->db_type != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_free(zone->mctx, zone->db_type);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->db_type = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (zone->top != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_db_detach(&zone->top);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_zone_cleardbargs(zone);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_zone_clearmasters(zone);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson zone->masterport = 0;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_zone_clearnotify(zone);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson zone->check_names = dns_c_severity_ignore;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson zone->pubkey = NULL; /* XXX detach */
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (zone->update_acl != NULL)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_c_ipmatchlist_delete(NULL, &zone->update_acl);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (zone->query_acl != NULL)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_c_ipmatchlist_delete(NULL, &zone->query_acl);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (zone->xfr_acl != NULL)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_c_ipmatchlist_delete(NULL, &zone->xfr_acl);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (dns_name_dynamic(&zone->origin))
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_name_free(&zone->origin, zone->mctx);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson /* last stuff */
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_mutex_destroy(&zone->lock);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson zone->magic = 0;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_mem_put(zone->mctx, zone, sizeof *zone);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson}
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson/*
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater * Single shot.
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson */
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssonvoid
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssondns_zone_setclass(dns_zone_t *zone, dns_rdataclass_t rdclass) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson REQUIRE(DNS_ZONE_VALID(zone));
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson REQUIRE(rdclass != dns_rdataclass_none);
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews REQUIRE(zone->rdclass == dns_rdataclass_none ||
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson zone->rdclass == rdclass);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson zone->rdclass = rdclass;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson}
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson/*
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson * Single shot.
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson */
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssonvoid
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssondns_zone_settype(dns_zone_t *zone, dns_zonetype_t type) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson REQUIRE(DNS_ZONE_VALID(zone));
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson REQUIRE(type != dns_zone_none);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson REQUIRE(zone->type == dns_zone_none || zone->type == type);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson zone->type = type;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson}
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrewsdns_result_t
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssondns_zone_setdbtype(dns_zone_t *zone, char *db_type) {
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews dns_result_t result = DNS_R_SUCCESS;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson REQUIRE(DNS_ZONE_VALID(zone));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington LOCK(&zone->lock);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington if (zone->db_type != NULL)
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington isc_mem_free(zone->mctx, zone->db_type);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington zone->db_type = isc_mem_strdup(zone->mctx, db_type);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington if (zone->db_type == NULL)
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington result = DNS_R_NOMEMORY;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssondns_result_t
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssondns_zone_setorigin(dns_zone_t *zone, char *origin) {
6c7f722d31d12cf83964c8132f0a59ef70e34cb5Mark Andrews isc_buffer_t buffer;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_fixedname_t fixed;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_result_t result;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(origin != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews dns_fixedname_init(&fixed);
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews isc_buffer_init(&buffer, origin, strlen(origin), ISC_BUFFERTYPE_TEXT);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_add(&buffer, strlen(origin));
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = dns_name_fromtext(dns_fixedname_name(&fixed),
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson &buffer, dns_rootname, ISC_FALSE, NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != DNS_R_SUCCESS)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (result);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson LOCK(&zone->lock);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = dns_name_dup(dns_fixedname_name(&fixed), zone->mctx,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson &zone->origin);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson UNLOCK(&zone->lock);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews return (result);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson}
229ce407c359b0b641759ba1fc4a5fa2054a44daBrian Wellington
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssondns_result_t
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssondns_zone_setdatabase(dns_zone_t *zone, const char *database) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_result_t result = DNS_R_SUCCESS;
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews REQUIRE(DNS_ZONE_VALID(zone));
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews REQUIRE(database != NULL);
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews LOCK(&zone->lock);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (zone->database != NULL)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_mem_free(zone->mctx, zone->database);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->database = isc_mem_strdup(zone->mctx, database);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (zone->database == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = DNS_R_NOMEMORY;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssondns_result_t
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssondns_zone_setupdatelog(dns_zone_t *zone, char *updatelog) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_result_t result = DNS_R_SUCCESS;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson REQUIRE(DNS_ZONE_VALID(zone));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(updatelog != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington LOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (zone->updatelog != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_free(zone->mctx, zone->updatelog);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->updatelog = isc_mem_strdup(zone->mctx, updatelog);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (zone->updatelog == NULL)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = DNS_R_NOMEMORY;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington UNLOCK(&zone->lock);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (result);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondns_result_t
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondns_zone_setixfrlog(dns_zone_t *zone, const char *ixfrlog) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_result_t result = DNS_R_SUCCESS;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(ixfrlog != NULL);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington LOCK(&zone->lock);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (zone->ixfrlog != NULL)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_mem_free(zone->mctx, zone->ixfrlog);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington zone->ixfrlog = isc_mem_strdup(zone->mctx, ixfrlog);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (zone->ixfrlog == NULL)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = DNS_R_NOMEMORY;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington UNLOCK(&zone->lock);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (result);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonvoid
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondns_zone_validate(dns_zone_t *zone) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(dns_name_countlabels(&zone->origin) != 0);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(zone->type != dns_zone_none);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington switch (zone->rdclass) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington case dns_zone_master:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington case dns_zone_slave:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington case dns_zone_stub:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington case dns_zone_hint:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(zone->database != NULL);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /*FALLTHROUGH*/
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington case dns_zone_forward:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(zone->rdclass != dns_rdataclass_none);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington break;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington case dns_zone_cache:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(zone->rdclass == dns_rdataclass_none);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(zone->database == NULL);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington break;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(zone->db_type != NULL);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondns_result_t
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondns_zone_load(dns_zone_t *zone) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington int soacount = 0;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington int nscount = 0;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_result_t result;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_dbnode_t *node = NULL;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_dbversion_t *version = NULL;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_rdataset_t rdataset;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_boolean_t cache = ISC_FALSE;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_rdata_soa_t soa;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_rdata_t rdata;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_stdtime_t now;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_db_t *db = NULL;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson REQUIRE(DNS_ZONE_VALID(zone));
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (isc_stdtime_get(&now) != ISC_R_SUCCESS) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson /*XXX*/
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (DNS_R_UNEXPECTED);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington switch (zone->type) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson case dns_zone_forward:
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson case dns_zone_none:
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (DNS_R_SUCCESS);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson case dns_zone_master:
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson case dns_zone_slave:
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson case dns_zone_stub:
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson case dns_zone_hint:
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson cache = ISC_FALSE;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson break;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson case dns_zone_cache:
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson cache = ISC_TRUE;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington break;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington default:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST("bad zone type" == NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_db_create(zone->mctx, zone->db_type,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington &zone->origin,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington cache, zone->rdclass,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->db_argc, zone->db_argv, &db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != DNS_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_db_load(db, zone->database);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Initiate zone transfer? We may need a error code that
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * indicates that the "permanent" form does not exist.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * XXX better error feedback to log.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != DNS_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto cleanup;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Apply update log to zone iff we are not generating it.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (zone->ixfrlog != NULL && zone->diff_on_reload == ISC_FALSE) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_journal_rollforward(zone->mctx, db, zone->ixfrlog);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != DNS_R_SUCCESS && result != DNS_R_NOTFOUND &&
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result != DNS_R_UPTODATE)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto cleanup;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == DNS_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->flags |= DNS_ZONE_F_NEEDDUMP;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Obtain ns and soa counts for top of zone.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington nscount = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington soacount = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_db_currentversion(db, &version);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_db_findnode(db, &zone->origin, ISC_FALSE, &node);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == DNS_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_init(&rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_db_findrdataset(db, node, version,
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington dns_rdatatype_ns,
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington dns_rdatatype_none, 0, &rdataset,
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington NULL);
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington if (result == DNS_R_SUCCESS) {
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington result = dns_rdataset_first(&rdataset);
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington while (result == DNS_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington nscount++;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_next(&rdataset);
5e387b9ce6bafdfadedb5b34e4c33a4404e5d589Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_disassociate(&rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_db_findrdataset(db, node, version,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatatype_soa,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatatype_none, 0, &rdataset,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == DNS_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_first(&rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while (result == DNS_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_current(&rdataset, &rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (soacount == 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_tostruct(&rdata, &soa,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->mctx);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington soacount++;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_next(&rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_disassociate(&rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_invalidate(&rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_db_detachnode(db, &node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_db_closeversion(db, &version, ISC_FALSE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Master / Slave / Stub zones require both NS and SOA records at
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * the top of the zone.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Hint zones only require NS records.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Cache zones have no reqirements.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
7829fad4093f2c1985b1efb7cea00287ff015d2bckb
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington switch (zone->type) {
7829fad4093f2c1985b1efb7cea00287ff015d2bckb case dns_zone_master:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case dns_zone_slave:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case dns_zone_stub:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (soacount != 1 || nscount == 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (soacount != 0)
7829fad4093f2c1985b1efb7cea00287ff015d2bckb dns_rdata_freestruct(&soa);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (DNS_R_BADZONE);
7829fad4093f2c1985b1efb7cea00287ff015d2bckb }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->serial = soa.serial;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->refresh = soa.refresh;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->retry = soa.retry;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->expire = soa.expire;
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews zone->minimum = soa.minimum;
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews if (zone->type == dns_zone_slave ||
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->type == dns_zone_stub) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->expiretime = now /*XXX*/ + zone->expire;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->refreshtime = now + zone->refresh /*XXX*/;
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case dns_zone_hint:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (nscount == 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (soacount != 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_freestruct(&soa);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (DNS_R_BADZONE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case dns_zone_cache:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington default:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNEXPECTED_ERROR(__FILE__, __LINE__,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "unexpected zone type %d", zone->type);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (soacount != 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_freestruct(&soa);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (DNS_R_UNEXPECTED);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (zone->top != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_zone_replacedb(zone, db, ISC_FALSE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington else {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_db_attach(db, &zone->top);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->flags |= DNS_ZONE_F_LOADED;
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington cleanup:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (soacount != 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_freestruct(&soa);
c0d2891f6e08fcf5379dfb9a1bf8fbbb63f1952aMark Andrews if (db != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_db_detach(&db);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
c0d2891f6e08fcf5379dfb9a1bf8fbbb63f1952aMark Andrews}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#ifdef notyet
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonvoid
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_zone_checkservers(dns_zone_t *zone) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_t *zonename;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int i;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_zone_checkservers_t *checkservers;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_t rdataset;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_t rdata;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_dbnode_t *node = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_dbversion_t *version = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_result_t result;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_ns_t ns;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* XXX MPA */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * get NS list from database, add in notify also list
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zonename = &zone->origin;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_db_currentversion(zone->top, &version);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_db_findnode(zone->top, zonename, ISC_FALSE, &node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == DNS_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_init(&rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_db_findrdataset(zone->top, node, version,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_rdatatype_ns,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_rdatatype_none, 0, &rdataset,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == DNS_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_first(&rdataset);
18d0b5e54be891a1aa938c165b6d439859121ec8Mark Andrews while (result == DNS_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_current(&rdataset, &rdata);
229ce407c359b0b641759ba1fc4a5fa2054a44daBrian Wellington result = dns_rdata_tostruct(&rdata, &ns, zone->mctx);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != DNS_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington continue;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington checkservers = isc_mem_get(zone->mctx,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sizeof *checkservers);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (checkservers == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_init(&checkservers->server, NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_dup(&ns.name, zone->mctx,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington &checkservers->server);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington checkservers->name_known = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington checkservers->state = get_a; /* XXXMPA */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_zone_attach(zone, &checkservers->zone);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington checkservers->mctx = zone->mctx;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_resolver_attach(zone->res, &checkservers->res);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington checkservers->fetch = NULL;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington ISC_LINK_INIT(checkservers, link);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington checkservers->magic = CHECKSERVERS_MAGIC;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* XXX lookup A/AAAA/A6 records */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_next(&rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_disassociate(&rdataset);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_rdataset_invalidate(&rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_db_detachnode(zone->top, &node);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_db_closeversion(zone->top, &version, ISC_FALSE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Foreach NS in NS list perform a non-recursive query to obtain
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * NS list for zone (remove self from list).
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * callback to check:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * If NXDOMAIN -> log error.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * If NODATA -> log error.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * If referral -> log error.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * If non-auth -> log error.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * Compare NS list returned with server list if not identical
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * log error if current list is at least 3 x refresh old.
5e387b9ce6bafdfadedb5b34e4c33a4404e5d589Brian Wellington * Compare glue A/AAAA/A6 records.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Foreach NS in NS list perform a non-recursive query to obtain
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * SOA record for zone (remove self from list).
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt * callback to check:
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt * If NXDOMAIN -> log error.
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt * If NODATA -> log error.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * If referral -> log error.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * If no-auth -> log error.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Compare SOA serial with ixfr list and if older that 3x refresh
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * log error.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington LOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington for (i = 0 ; i < zone->notifycnt; i++) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington checkservers = isc_mem_get(zone->mctx, sizeof *checkservers);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews if (checkservers == NULL)
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_init(&checkservers->server, NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington checkservers->name_known = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington checkservers->state = get_ns;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington checkservers->address = zone->notify[i];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_zone_attach(zone, &checkservers->zone);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington checkservers->mctx = zone->mctx;
7a6f285bc933d08353d2f18290c85def575b6e57Andreas Gustafsson dns_resolver_attach(zone->res, &checkservers->res);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington checkservers->fetch = NULL;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington ISC_LINK_INIT(checkservers, link);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington checkservers->magic = CHECKSERVERS_MAGIC;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews ISC_LIST_APPEND(zone->checkservers, checkservers, link);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington dns_resolver_createfetch(zone->res, zonename, dns_rdatatype_ns,
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews NULL, NULL, NULL,
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews DNS_FETCHOPT_UNSHARED,
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews zone->task, checkservers_callback,
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews checkservers, &checkservers->fetch);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews }
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews UNLOCK(&zone->lock);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews}
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews#endif
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews#ifdef notyet
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrewsstatic void
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrewscheckservers_callback(isc_task_t *task, isc_event_t *event) {
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews dns_fetchdoneevent_t *devent = (dns_fetchdoneevent_t *)event;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews dns_zone_checkservers_t *checkservers = event->arg;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews dns_zone_state_t state;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews dns_zone_t *zone;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews dns_name_t *name;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews isc_mem_t *mctx;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews isc_sockaddr_t *address;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews dns_resolver_t *res;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews dns_message_t *msg;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews char *master;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews REQUIRE(DNS_CHECKSERVERS_VALID(checkservers));
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews state = checkservers->state;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington zone = checkservers->zone;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington name = &checkservers->server;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington address = &checkservers->address;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington mctx = checkservers->mctx;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington res = checkservers->res;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington task = task; /* unused */
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews master = isc_sockaddr_totext(&zone->masters[zone->curmaster],
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews zone->mctx);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews
3fb95bfcb2e478d721d378f0be5ff0a32269bc2aTinderbox User if (devent->result != DNS_R_SUCCESS) {
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews /* timeout */
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews switch (state) {
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington case get_a6:
6e93e6ea4557291e847aced6a88adcdf39f06843Andreas Gustafsson case get_aaaa:
6e93e6ea4557291e847aced6a88adcdf39f06843Andreas Gustafsson case get_a:
6e93e6ea4557291e847aced6a88adcdf39f06843Andreas Gustafsson dns_zone_logerror(zone,
6e93e6ea4557291e847aced6a88adcdf39f06843Andreas Gustafsson "unable to obtain address for (%s)");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case get_ns:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case get_soa:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_zone_logerror(zone,
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington "unable to obtain %s RRset from %s"
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington );
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington }
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington goto cleanup;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington msg = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_resolver_getanswer(event, &msg);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington switch (state) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case get_a6:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington add_address_tocheck(msg, checkservers, dns_rdatatype_a6);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_resolver_createfetch(res, name, dns_rdatatype_aaaa,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington NULL, NULL, NULL, 0, zone->task,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt checkservers_callback,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt checkservers, &checkservers->fetch);
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt checkservers->state = get_aaaa;
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt break;
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt case get_aaaa:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington add_address_tocheck(msg, checkservers, dns_rdatatype_a6);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_resolver_createfetch(res, name, dns_rdatatype_a,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington NULL, NULL, NULL, 0, zone->task,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington checkservers_callback,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington checkservers, &checkservers->fetch);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington checkservers->state = get_a;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case get_a:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington add_address_tocheck(msg, checkservers, dns_rdatatype_a);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews /* make NS query to address */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_resolver_createfetch(res, name, dns_rdatatype_ns,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington NULL, NULL, NULL,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington DNS_FETCHOPT_UNSHARED,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->task, checkservers_callback,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington checkservers, &checkservers->fetch);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington checkservers->state = get_ns;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case get_ns:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case get_soa:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (msg->rcode != dns_rcode_noerror) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char rcode[128];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_t rb;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&rb, rcode, sizeof rcode,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_BUFFERTYPE_TEXT);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rcode_totext(msg->rcode, &rb);
fefe1106d96d3a89b21315f665b36a67cdea3840Mark Andrews dns_zone_logerror(zone,
fefe1106d96d3a89b21315f665b36a67cdea3840Mark Andrews "server %s (%s) unexpected rcode = %.*s",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rb.used, rcode);
fefe1106d96d3a89b21315f665b36a67cdea3840Mark Andrews break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (msg->counts[DNS_SECTION_ANSWER] == 0) {
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews if (referral(msg))
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews dns_zone_logerror(zone,
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews "server %s (%s) referral response");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington else
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_zone_logerror(zone,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "server %s (%s) type = %s NODATA response");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt if ((msg->flags & DNS_MESSAGEFLAG_AA) == 0) {
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews dns_zone_logerror(zone,
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews "server %s (%s) not authorative");
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews }
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews if (state == get_ns) {
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews /* compare NS RR sets */
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews /* make soa query to address */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_resolver_createfetch(res, name, dns_rdatatype_soa,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington NULL, NULL, NULL,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington DNS_FETCHOPT_UNSHARED,
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews zone->task,
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews checkservers_callback,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington checkservers,
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews &checkservers->fetch);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews checkservers->state = get_soa;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews break;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews } else {
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews /* compare SOA RR sets */
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews goto cleanup;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews }
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews break;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews default:
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews UNEXPECTED_ERROR(__FILE__, __LINE__, "unexpected state");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_event_free(&event);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington cleanup:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_event_free(&event);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_UNLINK(zone->checkservers, checkservers, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington checkservers->magic = 0;
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington dns_zone_detach(&checkservers->zone);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_put(mctx, checkservers, sizeof *checkservers);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#endif
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#if 0
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
0a45f098e446a7f41c2a71d9dd0fd8f459b49c34Brian Wellingtoncmp_soa(dns_message_t *msg, dns_zone_t *zone, char *server) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_soa_t msgsoa, zonesoa;
0a45f098e446a7f41c2a71d9dd0fd8f459b49c34Brian Wellington dns_result_t result;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_t *rdataset = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_t zonerdataset;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_t rdata;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington dns_rdata_init(&rdata);
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington /*
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington * extract SOA from message
b1b0dca1464a11b8a63623e8567e744dccfbcb41Tatuya JINMEI 神明達哉 */
b1b0dca1464a11b8a63623e8567e744dccfbcb41Tatuya JINMEI 神明達哉 result = dns_message_findname(msg, DNS_SECTION_ANSWER,
ab381c1e22e0ed732170428937d20d13146d863aAutomatic Updater &zone->origin,
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington dns_rdatatype_soa,
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington dns_rdatatype_none, NULL, &rdataset);
b1b0dca1464a11b8a63623e8567e744dccfbcb41Tatuya JINMEI 神明達哉 if (result != DNS_R_SUCCESS) {
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington dns_zone_logerror(zone,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "Unable to extract SOA from answer: %s",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington server);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_first(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (DNS_R_SUCCESS != result)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_current(rdataset, &rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdata_tostruct(&rdata, &msgsoa, zone->mctx);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (DNS_R_SUCCESS != result)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_next(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (DNS_R_NOMORE != result) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_zone_logerror(zone,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "More that one SOA record returned: %s",
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews server);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto cleanup_msgsoa;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Get SOA record for zone.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_init(&zonerdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington LOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_db_find(zone->top, &zone->origin,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington NULL, dns_rdatatype_soa, dns_rdatatype_none,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington 0, 0, NULL, NULL, &zonerdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != DNS_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* XXXMPA */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto cleanup_msgsoa;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_first(&zonerdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (DNS_R_SUCCESS != result)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_current(&zonerdataset, &rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdata_tostruct(&rdata, &msgsoa, zone->mctx);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (DNS_R_SUCCESS != result)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_next(&zonerdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (DNS_R_NOMORE != result) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_zone_logerror(zone, "More that one SOA in zone");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto cleanup_msgsoa;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_disassociate(&zonerdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Check SOA contents. If serials do not match check to see
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * if the slave is ahead of us (i.e. we have reset the serial
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * number).
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * If the serials do match then check the other values for
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * consistancy.
b7cd261f2fca2c7138cdc6ae8ee434e9c0031303Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (msgsoa.serial != zonesoa.serial) {
cfcb0881d12db2b7cb33475b7d20ac6c9015203bMark Andrews if (!isc_serial_lt(msgsoa.serial, zonesoa.serial)) {
cfcb0881d12db2b7cb33475b7d20ac6c9015203bMark Andrews dns_zone_logerror(zone,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "slave serial not less than or equal to zone serial: %s",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington server);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto cleanup_zonesoa;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington record_serial();
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto cleanup_zonesoa;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (msgsoa.refresh != zonesoa.refresh ||
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington msgsoa.retry != zonesoa.retry ||
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington msgsoa.expire != zonesoa.expire ||
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington msgsoa.minimum != zonesoa.minimum ||
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_compare(&msgsoa.origin, &zonesoa.origin) != 0 ||
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_compare(&msgsoa.mname, &zonesoa.mname) != 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_zone_logerror(zone, "SOA contents differ: %s",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington server);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington cleanup_zonesoa:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_freestruct(&zonesoa);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington cleanup_msgsoa:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_freestruct(&msgsoa);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#endif
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonadd_address_tocheck(dns_message_t *msg, dns_zone_checkservers_t *checkservers,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatatype_t type)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_t *rdataset = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_result_t result;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_sockaddr_t sockaddr;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_in_a_t a;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_in_a6_t a6;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_t rdata;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (msg->rcode != dns_rcode_noerror)
7a6f285bc933d08353d2f18290c85def575b6e57Andreas Gustafsson return;
7a6f285bc933d08353d2f18290c85def575b6e57Andreas Gustafsson
7a6f285bc933d08353d2f18290c85def575b6e57Andreas Gustafsson if (msg->counts[DNS_SECTION_QUESTION] != 0 ||
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_message_findname(msg, DNS_SECTION_QUESTION,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington &checkservers->server,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington type, dns_rdatatype_none,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington NULL, &rdataset) != DNS_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_first(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while (DNS_R_SUCCESS == result) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_current(rdataset, &rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington switch (type) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case dns_rdatatype_a:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdata_tostruct(&rdata, &a,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington checkservers->mctx);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_sockaddr_fromin(&sockaddr, &a.in_addr, 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_freestruct(&a);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case dns_rdatatype_a6:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdata_tostruct(&rdata, &a6,
7a6f285bc933d08353d2f18290c85def575b6e57Andreas Gustafsson checkservers->mctx);
7a6f285bc933d08353d2f18290c85def575b6e57Andreas Gustafsson isc_sockaddr_fromin6(&sockaddr, &a6.in6_addr, 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_freestruct(&a6);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington default:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_next(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonvoid
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_zone_checkparents(dns_zone_t *zone) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* XXX MPA */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Obtain a parent NS list.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Remove LSL from zone name. Check to see if we are serving
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * zone otherwise make non-recursive query for NS set of
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * of given name. Follow referral until NXDOMAIN, NODATA or
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * answer is found. If NXDOMAIN or NODATA remove next LSL
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * and repeat.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * If self in NS list check masked NS list in parent against zone
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * ns list.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Foreach NS on parent NS list make non recursive query for NS set
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * of current zone (removed self from list if required).
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Check NS list return for agreement with zone's NS list.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonvoid
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondns_zone_checkchildren(dns_zone_t *zone) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /* XXX MPA */
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /*
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * For each child zone obtain NS list from parent zone.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * For each NS in list send non-recursive query for child zone's
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * NS list for zone.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington *
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * If NXDOMAIN is returned log error.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * If NODATA is return log error.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * If referral is return log error.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * If non-auth is return log error.
6e2871232f7ede047799480370aff444be1f5a13Automatic Updater * If NS list disagree's with parents NS list log error.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonvoid
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondns_zone_checkglue(dns_zone_t *zone) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /* XXX MPA */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /*
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * For each glue record in this zone, check with an authorative
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * server for the zone to ensure that there have not been any
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * changes.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellingtonvoid
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondns_zone_attach(dns_zone_t *source, dns_zone_t **target) {
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington REQUIRE(DNS_ZONE_VALID(source));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(target != NULL && *target == NULL);
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington LOCK(&source->lock);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(source->references > 0);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington source->references++;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington printf("%p: %s: references = %d\n", source, dns_zone_tostr(source),
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington source->references);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington INSIST(source->references != 0xffffffffU);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington UNLOCK(&source->lock);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington *target = source;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonvoid
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_zone_print(dns_zone_t *zone) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf("\t%p: %s: references = %d\n", zone, dns_zone_tostr(zone),
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->references);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic char *
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_zone_tostr(dns_zone_t *zone) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_t tbuf;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington static char outbuf[1024];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_result_t result;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&tbuf, outbuf, sizeof(outbuf) - 1,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_BUFFERTYPE_TEXT);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (dns_name_countlabels(&zone->origin) > 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_name_totext(&zone->origin, ISC_FALSE, &tbuf);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == DNS_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington outbuf[tbuf.used] = '\0';
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington else
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy(outbuf, "<name conversion failed>",
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews sizeof outbuf);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }else
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy(outbuf, "<unnamed zone>", sizeof outbuf);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (outbuf);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonvoid
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_zone_detach(dns_zone_t **zonep) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_zone_t *zone;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(zonep != NULL && DNS_ZONE_VALID(*zonep));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone = *zonep;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington LOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(zone->references > 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->references--;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf("%p: %s: references = %d\n", zone, dns_zone_tostr(zone),
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->references);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (zone->references == 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone_free(zone);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *zonep = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonvoid
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_zone_setflag(dns_zone_t *zone, unsigned int flags, isc_boolean_t value) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington LOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (value)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->flags |= flags;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington else
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->flags &= ~flags;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonvoid
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_zone_setoption(dns_zone_t *zone, unsigned int option, isc_boolean_t value)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington LOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (value)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->options |= option;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington else
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->options &= ~option;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->setoptions |= option;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonvoid
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_zone_clearoption(dns_zone_t *zone, unsigned int option) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington LOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->setoptions &= ~option;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonvoid
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_zone_getoptions(dns_zone_t *zone, unsigned int *options,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int *optionsmask)
f8abaa0fae7f75d9601c10b6a4af8dd907494d45Mark Andrews{
b55c30f2de6e1baaa3a9ba69b92f428f2c255ac3Mark Andrews REQUIRE(DNS_ZONE_VALID(zone));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(options != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(optionsmask != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington LOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *options = zone->options;
f8abaa0fae7f75d9601c10b6a4af8dd907494d45Mark Andrews *optionsmask = zone->setoptions;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_zone_adddbarg(dns_zone_t *zone, char *arg) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char **new = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(arg != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Allocate new 'db_argv' and set last to be copy of 'arg'.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington LOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington new = isc_mem_get(zone->mctx, (zone->db_argc + 1) * sizeof *new);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (new == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto cleanup;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington new[zone->db_argc] = isc_mem_strdup(zone->mctx, arg);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (new[zone->db_argc] == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto cleanup;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Copy old 'db_argv' if required the free it.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (zone->db_argc != 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington memcpy(new, zone->db_argv, zone->db_argc * sizeof *new);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_put(zone->mctx, zone->db_argv,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->db_argc * sizeof *new);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->db_argv = new;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->db_argc++;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (DNS_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington cleanup:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (new != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_put(zone->mctx, new,
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews (zone->db_argc + 1) * sizeof *new);
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews UNLOCK(&zone->lock);
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews return (DNS_R_NOMEMORY);
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews}
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews
4a30ede93d59137009db734661cde17612e8ffbeMark Andrewsvoid
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrewsdns_zone_cleardbargs(dns_zone_t *zone) {
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews unsigned int i;
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews REQUIRE(DNS_ZONE_VALID(zone));
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews LOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (zone->db_argc) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington for (i = 0 ; i < zone->db_argc; i++)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_free(zone->mctx, zone->db_argv[i]);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_put(zone->mctx, zone->db_argv,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->db_argc * sizeof *zone->db_argv);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->db_argc = 0;
7829fad4093f2c1985b1efb7cea00287ff015d2bckb zone->db_argv = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_result_t
793814f80703afdd69b59ade91e63efa81ae4178Evan Huntdns_zone_setxfrsource(dns_zone_t *zone, isc_sockaddr_t *xfrsource) {
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt REQUIRE(DNS_ZONE_VALID(zone));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington LOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->xfrsource = *xfrsource;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (DNS_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonisc_sockaddr_t *
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_zone_getxfrsource(dns_zone_t *zone) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (&zone->xfrsource);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrewsdns_result_t
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉dns_zone_addnotify(dns_zone_t *zone, isc_sockaddr_t *notify) {
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt isc_sockaddr_t *new;
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt REQUIRE(DNS_ZONE_VALID(zone));
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt LOCK(&zone->lock);
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt new = isc_mem_get(zone->mctx, (zone->notifycnt + 1) * sizeof *new);
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt if (new == NULL)
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt goto cleanup;
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt new[zone->notifycnt] = *notify;
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt if (zone->notifycnt > 0) {
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt memcpy(new, zone->notify, zone->notifycnt * sizeof *new);
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt isc_mem_put(zone->mctx, zone->notify,
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt zone->notifycnt * sizeof *new);
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt }
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt zone->notify = new;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->notifycnt++;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&zone->lock);
6fd4ab217ef8e37703b029eac5ab7ae4f7a663c9Brian Wellington return (DNS_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington cleanup:
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington UNLOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (DNS_R_NOMEMORY);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonvoid
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_zone_clearnotify(dns_zone_t *zone) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington LOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (zone->notify != NULL) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_mem_put(zone->mctx, zone->notify,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->notifycnt * sizeof *zone->notify);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->notify = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington zone->notifycnt = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_zone_addmaster(dns_zone_t *zone, isc_sockaddr_t *master) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_sockaddr_t *new;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington LOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington new = isc_mem_get(zone->mctx, (zone->masterscnt + 1) * sizeof *new);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (new == NULL) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (DNS_R_NOMEMORY);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington new[zone->masterscnt] = *master;
18d0b5e54be891a1aa938c165b6d439859121ec8Mark Andrews if (zone->masterscnt > 0) {
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington memcpy(new, zone->masters, zone->masterscnt * sizeof *new);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_put(zone->mctx, zone->masters,
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington zone->masterscnt * sizeof *new);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington }
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington zone->masters = new;
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington zone->masterscnt++;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (DNS_R_SUCCESS);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington}
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonvoid
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellingtondns_zone_clearmasters(dns_zone_t *zone) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington LOCK(&zone->lock);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington while (DNS_ZONE_FLAG(zone, DNS_ZONE_F_REFRESH)) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&zone->lock);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington cancel_refresh(zone);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington LOCK(&zone->lock);
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington }
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington if (zone->masters != NULL) {
34f991028382079af7c2b53bac6768803ff28f8cBrian Wellington isc_mem_put(zone->mctx, zone->masters,
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington zone->masterscnt * sizeof *zone->masters);
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington zone->masters = NULL;
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington zone->masterscnt = 0;
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington zone->curmaster = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNLOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_zone_getdb(dns_zone_t *zone, dns_db_t **dpb) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_result_t result = DNS_R_SUCCESS;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington LOCK(&zone->lock);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington if (zone->top == NULL)
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington result = DNS_R_NOTFOUND;
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington else
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington dns_db_attach(zone->top, dpb);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington UNLOCK(&zone->lock);
0a25550b464ad40e4d90ebff8ecf23595b05ae3bFrancis Dupont
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington return (result);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington}
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington/*
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington * Co-ordinates the starting of routine jobs.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonvoid
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_zone_maintenance(dns_zone_t *zone) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_stdtime_t now;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fprintf(stderr, "dns_zone_maintenance\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington if (isc_stdtime_get(&now) != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Expire check.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington switch (zone->type) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case dns_zone_slave:
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington case dns_zone_stub:
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington LOCK(&zone->lock);
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington if (now >= zone->expiretime &&
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington DNS_ZONE_FLAG(zone, DNS_ZONE_F_LOADED)) {
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington dns_zone_expire(zone);
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington zone->refreshtime = now;
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington }
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington UNLOCK(&zone->lock);
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington break;
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington default:
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington break;
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Up to date check.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington switch (zone->type) {
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington case dns_zone_slave:
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews case dns_zone_stub:
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews if (now >= zone->refreshtime &&
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 !DNS_ZONE_FLAG(zone, DNS_ZONE_F_REFRESH))
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_zone_refresh(zone);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 break;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews default:
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews break;
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews }
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Do we need to consolidate the backing store?
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington switch (zone->type) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case dns_zone_master:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington LOCK(&zone->lock);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (now >= zone->dumptime &&
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington DNS_ZONE_FLAG(zone, DNS_ZONE_F_LOADED) &&
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington DNS_ZONE_FLAG(zone, DNS_ZONE_F_NEEDDUMP)) {
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington dns_zone_dump(zone, stdout);
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington }
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington UNLOCK(&zone->lock);
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington break;
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington default:
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Check servers for zone.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington switch (zone->type) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case dns_zone_master:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case dns_zone_slave:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington case dns_zone_stub:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington#ifdef notyet
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (now >= zone->servertime &&
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington DNS_ZONE_FLAG(zone, DNS_ZONE_F_LOADED) &&
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington DNS_ZONE_OPTION(zone, DNS_ZONE_O_SERVERS) &&
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington !DNS_ZONE_FLAG(zone, DNS_ZONE_F_SERVERS))
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_zone_checkservers(zone);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington#endif
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington break;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington default:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington break;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /*
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * Check parent servers for zone.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington switch (zone->type) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington case dns_zone_master:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington case dns_zone_slave:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington case dns_zone_stub:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (now >= zone->parenttime &&
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington DNS_ZONE_FLAG(zone, DNS_ZONE_F_LOADED) &&
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington DNS_ZONE_OPTION(zone, DNS_ZONE_O_PARENTS) &&
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington !DNS_ZONE_FLAG(zone, DNS_ZONE_F_PARENTS))
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_zone_checkparents(zone);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington break;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington default:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington break;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /*
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * Check child servers for zone.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington switch (zone->type) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington case dns_zone_master:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington case dns_zone_slave:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington case dns_zone_stub:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (now >= zone->childtime &&
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington DNS_ZONE_FLAG(zone, DNS_ZONE_F_LOADED) &&
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington DNS_ZONE_OPTION(zone, DNS_ZONE_O_CHILDREN) &&
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington !DNS_ZONE_FLAG(zone, DNS_ZONE_F_CHILDREN))
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_zone_checkchildren(zone);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington break;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington default:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington break;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington (void) zone_settimer(zone, now); /*XXX*/
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
01dbc4fc00adc933af96e88bfce95c07ef1f3c39Mark Andrews
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonvoid
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondns_zone_expire(dns_zone_t *zone) {
01dbc4fc00adc933af96e88bfce95c07ef1f3c39Mark Andrews REQUIRE(DNS_ZONE_VALID(zone));
01dbc4fc00adc933af96e88bfce95c07ef1f3c39Mark Andrews
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (DNS_ZONE_FLAG(zone, DNS_ZONE_F_NEEDDUMP))
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_zone_dump(zone, stdout); /* XXX */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington zone->flags |= DNS_ZONE_F_EXPIRED;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_zone_setrefresh(zone, DEFAULT_REFRESH, DEFAULT_RETRY);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_zone_unload(zone);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonvoid
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondns_zone_refresh(dns_zone_t *zone) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_stdtime_t now;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(zone->masterscnt > 0);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (isc_stdtime_get(&now) != ISC_R_SUCCESS)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /*
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * Set DNS_ZONE_F_REFRESH so that there is only one refresh operation
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * in progress at the one time.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington LOCK(&zone->lock);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington zone->flags |= DNS_ZONE_F_REFRESH;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington UNLOCK(&zone->lock);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /*
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington * Set the next refresh time as if refresh check has failed.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * If we are successful it will be reset using zone->refresh.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington zone->refreshtime = now + zone->retry;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington zone->curmaster = 0;
b7cd261f2fca2c7138cdc6ae8ee434e9c0031303Brian Wellington /* initiate soa query */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington#ifdef notyet
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington soa_query(zone, refresh_callback);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington#endif
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondns_result_t
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondns_zone_dump(dns_zone_t *zone, FILE *fd) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_dbiterator_t *dbiterator = NULL;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_dbversion_t *version = NULL;
5d85bf183f957f9ea0902be1a6e3405b90bc7c0fBrian Wellington dns_result_t result;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_fixedname_t fname;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_name_t *name;
b7cd261f2fca2c7138cdc6ae8ee434e9c0031303Brian Wellington dns_rdatasetiter_t *rdsiter = NULL;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_dbnode_t *node = NULL;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_t text;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_region_t region;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char *buf = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int buflen = 1024;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_t rdataset;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_ZONE_VALID(zone));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_fixedname_init(&fname);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington name = dns_fixedname_name(&fname);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_db_currentversion(zone->top, &version);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_db_createiterator(zone->top, ISC_FALSE, &dbiterator);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == DNS_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_dbiterator_first(dbiterator);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while (result == DNS_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_dbiterator_current(dbiterator, &node, name);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != DNS_R_SUCCESS && result != DNS_R_NEWORIGIN)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_db_allrdatasets(zone->top, node, version, 0,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington &rdsiter);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != DNS_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_db_detachnode(zone->top, &node);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_init(&rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdatasetiter_first(rdsiter);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while (result == DNS_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatasetiter_current(rdsiter, &rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington retry:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (buf == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington buf = isc_mem_get(zone->mctx, buflen);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (buf == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = DNS_R_NOMEMORY;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&text, buf, buflen,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_BUFFERTYPE_TEXT);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == DNS_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_totext(&rdataset, name,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_FALSE,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_FALSE, &text);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == DNS_R_NOSPACE) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_put(zone->mctx, buf, buflen);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington buf = NULL;
buflen += 1024;
goto retry;
}
isc_buffer_used(&text, &region);
if (result == DNS_R_SUCCESS)
fprintf(fd, "%.*s", (int)region.length,
(char *)region.base);
dns_rdataset_disassociate(&rdataset);
if (result == DNS_R_SUCCESS)
result = dns_rdatasetiter_next(rdsiter);
}
dns_rdatasetiter_destroy(&rdsiter);
dns_db_detachnode(zone->top, &node);
if (result == DNS_R_NOMORE)
result = dns_dbiterator_next(dbiterator);
}
if (buf != NULL)
isc_mem_put(zone->mctx, buf, buflen);
dns_dbiterator_destroy(&dbiterator);
dns_db_closeversion(zone->top, &version, ISC_FALSE);
return (result);
}
void
dns_zone_unload(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
LOCK(&zone->lock);
dns_db_detach(&zone->top);
zone->flags &= ~DNS_ZONE_F_LOADED;
UNLOCK(&zone->lock);
}
void
dns_zone_unmount(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
/*XXX MPA*/
}
dns_result_t
dns_zone_manage(dns_zone_t *zone, isc_taskmgr_t *tmgr) {
#if 1
(void)zone;
(void)tmgr;
return (DNS_R_NOTIMPLEMENTED);
#else
isc_result_t iresult;
dns_result_t result;
/*
* XXXRTH Zones do not have resolvers!!!!
*/
REQUIRE(DNS_ZONE_VALID(zone));
REQUIRE(zone->task == NULL);
REQUIRE(zone->timgr == NULL);
iresult = isc_task_create(tmgr, zone->mctx, 0, &zone->task);
if (iresult != ISC_R_SUCCESS) {
/* XXX */
return (DNS_R_UNEXPECTED);
}
iresult = isc_task_onshutdown(zone->task, zone_shutdown, zone);
if (iresult != ISC_R_SUCCESS) {
/* XXX */
return (DNS_R_UNEXPECTED);
}
iresult = isc_timermgr_create(zone->mctx, &zone->timgr);
if (iresult != ISC_R_SUCCESS) {
/* XXX */
return (DNS_R_UNEXPECTED);
}
if (zone->res == NULL) {
isc_socket_t *s;
dns_dispatch_t *dispatch;
RUNTIME_CHECK(isc_socketmgr_create(zone->mctx, &zone->socketmgr)
== ISC_R_SUCCESS);
s = NULL;
RUNTIME_CHECK(isc_socket_create(zone->socketmgr, PF_INET,
isc_sockettype_udp, &s) == ISC_R_SUCCESS);
dispatch = NULL;
RUNTIME_CHECK(dns_dispatch_create(zone->mctx, s, zone->task,
4096, 1000, 1000, 4, &dispatch) == DNS_R_SUCCESS);
result = dns_resolver_create(zone->mctx, tmgr, 10, zone->timgr,
zone->rdclass, dispatch,
&zone->res);
if (result != DNS_R_SUCCESS)
return (result);
dns_dispatch_detach(&dispatch);
isc_socket_detach(&s);
}
dns_zone_maintenance(zone);
return (DNS_R_SUCCESS);
#endif
}
void
dns_zone_setrefresh(dns_zone_t *zone, isc_uint32_t refresh,
isc_uint32_t retry)
{
REQUIRE(DNS_ZONE_VALID(zone));
zone->refresh = refresh;
zone->retry = retry;
}
void
dns_zone_notify(dns_zone_t *zone) {
unsigned int i;
dns_name_t *origin = NULL;
isc_sockaddr_t addr;
dns_rdataset_t nsrdset;
dns_rdataset_t ardset;
dns_dbversion_t *version = NULL;
dns_result_t result;
dns_dbnode_t *node = NULL;
dns_rdata_ns_t ns;
dns_rdata_in_a_t a;
dns_rdata_t rdata;
REQUIRE(DNS_ZONE_VALID(zone));
if (!DNS_ZONE_OPTION(zone, DNS_ZONE_O_NOTIFY))
return;
origin = &zone->origin;
/*
* Enqueue notify request.
*/
for (i = 0; i < zone->notifycnt; i++) {
(void)dns_notify(origin, &zone->notify[i], dns_rdatatype_soa,
zone->rdclass, &zone->xfrsource, zone->mctx);
}
dns_db_currentversion(zone->top, &version);
result = dns_db_findnode(zone->top, origin, ISC_FALSE, &node);
if (result != DNS_R_SUCCESS)
goto cleanup1;
dns_rdataset_init(&nsrdset);
result = dns_db_findrdataset(zone->top, node, version,
dns_rdatatype_ns,
dns_rdatatype_none, 0, &nsrdset, NULL);
if (result != DNS_R_SUCCESS)
goto cleanup2;
result = dns_rdataset_first(&nsrdset);
while (result == DNS_R_SUCCESS) {
dns_rdataset_current(&nsrdset, &rdata);
result = dns_rdata_tostruct(&rdata, &ns, zone->mctx);
if (result != DNS_R_SUCCESS)
continue;
/*
* Look up address records.
*/
/* XXX MPA */
if (result == DNS_R_NOTFOUND) {
/*
* Query for address.
* Arrange for notify to be sent when
* we have it.
*/
/* XXX MPA*/
result = dns_rdataset_next(&nsrdset);
continue;
} else if (result != DNS_R_SUCCESS) {
result = dns_rdataset_next(&nsrdset);
continue;
}
result = dns_rdataset_first(&ardset);
while (result == DNS_R_SUCCESS) {
dns_rdataset_current(&ardset, &rdata);
result = dns_rdata_tostruct(&rdata, &a, zone->mctx);
if (result != DNS_R_SUCCESS)
continue;
/*
* Remove duplicates w/ notify list.
*/
isc_sockaddr_fromin(&addr, &a.in_addr, 0);
for (i = 0; i < zone->notifycnt; i++) {
if (isc_sockaddr_equal(&zone->notify[i], &addr))
break;
}
if (i == zone->notifycnt) {
(void)dns_notify(origin, &addr,
dns_rdatatype_soa,
zone->rdclass,
&zone->xfrsource, zone->mctx);
}
result = dns_rdataset_next(&ardset);
}
result = dns_rdataset_next(&nsrdset);
}
dns_rdataset_disassociate(&nsrdset);
cleanup2:
dns_db_detachnode(zone->top, &node);
cleanup1:
dns_db_closeversion(zone->top, &version, ISC_FALSE);
}
/***
*** Private
***/
static void
refresh_callback(isc_task_t *task, isc_event_t *event) {
#if 1
(void)task;
(void)event;
#else
dns_fetchevent_t *devent = (dns_fetchevent_t *)event;
dns_zone_t *zone;
dns_message_t *msg = NULL;
isc_uint32_t soacnt, cnamecnt, soacount, nscount;
isc_stdtime_t now;
char *master;
char *unknown = "<UNKNOWN>";
dns_rdataset_t *rdataset;
dns_rdata_t rdata;
dns_rdata_soa_t soa;
dns_result_t result;
isc_uint32_t serial;
zone = devent->arg;
INSIST(DNS_ZONE_VALID(zone));
/*
* if timeout log and next master;
*/
master = isc_sockaddr_totext(&zone->masters[zone->curmaster],
zone->mctx);
if (master == NULL)
master = unknown;
if (devent->result != DNS_R_SUCCESS) {
dns_zone_logerror(zone, "refresh: failure for %s: %s",
master, dns_result_totext(devent->result));
goto next_master;
}
dns_resolver_getanswer(event, &msg);
/*
* Unexpected rcode.
*/
if (msg->rcode != dns_rcode_noerror) {
char rcode[128];
isc_buffer_t rb;
isc_buffer_init(&rb, rcode, sizeof rcode, ISC_BUFFERTYPE_TEXT);
dns_rcode_totext(msg->rcode, &rb);
dns_zone_logerror(zone,
"refresh: unexpected rcode (%.*s) from %s\n",
rb.used, rcode, master);
goto next_master;
}
/*
* if non-auth log and next master;
*/
if ((msg->flags & DNS_MESSAGEFLAG_AA) == 0) {
dns_zone_logerror(zone,
"refresh: non-authorative answer from %s", master);
goto next_master;
}
/*
* There should not be a CNAME record at top of zone.
*/
cnamecnt = message_count(msg, DNS_SECTION_ANSWER, dns_rdatatype_cname);
soacnt = message_count(msg, DNS_SECTION_ANSWER, dns_rdatatype_soa);
if (cnamecnt != 0) {
dns_zone_logerror(zone,
"refresh: CNAME discovered: master %s", master);
goto next_master;
}
if (soacnt != 1) {
dns_zone_logerror(zone,
"refresh: SOA count (%d) != 1: master %s",
soacnt, master);
goto next_master;
}
nscount = message_count(msg, DNS_SECTION_AUTHORITY, dns_rdatatype_ns);
soacount = message_count(msg, DNS_SECTION_AUTHORITY, dns_rdatatype_soa);
/*
* if referral log and next master;
*/
if (soacnt == 0 && soacount == 0 && nscount != 0) {
dns_zone_logerror(zone,
"refresh: referral: master %s", master);
goto next_master;
}
/*
* if nodata log and next master;
*/
if (soacnt == 0 && nscount == 0) {
dns_zone_logerror(zone, "refresh: NODATA: master %s", master);
goto next_master;
}
/*
* Extract serial
*/
rdataset = NULL;
result = dns_message_findname(msg, DNS_SECTION_ANSWER, &zone->origin,
dns_rdatatype_soa, dns_rdatatype_none,
NULL, &rdataset);
if (result != DNS_R_SUCCESS) {
dns_zone_logerror(zone, "refresh: unable to get soa record");
goto next_master;
}
result = dns_rdataset_first(rdataset);
if (result != DNS_R_SUCCESS) {
dns_zone_logerror(zone, "refresh: dns_rdataset_first failed");
goto next_master;
}
dns_rdataset_current(rdataset, &rdata);
result = dns_rdata_tostruct(&rdata, &soa, zone->mctx);
if (result != DNS_R_SUCCESS) {
dns_zone_logerror(zone, "refresh: dns_rdata_tostruct failed");
goto next_master;
}
serial = soa.serial;
dns_rdata_freestruct(&soa);
if (!DNS_ZONE_FLAG(zone, DNS_ZONE_F_LOADED) ||
isc_serial_gt(serial, zone->serial)) {
dns_zone_transfer_in(zone);
isc_event_free(&event);
dns_resolver_destroyfetch(zone->res, &zone->fetch);
} else if (isc_serial_eq(soa.serial, zone->serial)) {
dns_zone_uptodate(zone);
goto next_master;
} else {
goto next_master;
}
if (master != unknown)
isc_mem_put(zone->mctx, master, strlen(master) + 1);
return;
next_master:
LOCK(&zone->lock);
if (master != unknown)
isc_mem_put(zone->mctx, master, strlen(master) + 1);
isc_event_free(&event);
dns_resolver_destroyfetch(zone->res, &zone->fetch);
zone->curmaster++;
if (zone->curmaster >= zone->masterscnt) {
zone->flags &= ~DNS_ZONE_F_REFRESH;
if (isc_stdtime_get(&now) != ISC_R_SUCCESS)
return;
zone_settimer(zone, now);
UNLOCK(&zone->lock);
return;
}
UNLOCK(&zone->lock);
soa_query(zone, refresh_callback);
return;
#endif
}
#ifdef notyet
static void
soa_query(dns_zone_t *zone, isc_taskaction_t callback) {
dns_name_t *zonename;
dns_result_t result;
zonename = &zone->origin;
LOCK(&zone->lock);
result = dns_resolver_createfetch(zone->res, zonename,
dns_rdatatype_soa,
NULL, NULL, NULL,
DNS_FETCHOPT_UNSHARED,
zone->task, callback, zone,
&zone->fetch);
UNLOCK(&zone->lock);
if (result != DNS_R_SUCCESS)
cancel_refresh(zone);
}
#endif
static void
zone_shutdown(isc_task_t *task, isc_event_t *event) {
dns_zone_t *zone = (dns_zone_t *)event->arg;
isc_event_free(&event);
task = task; /* XXX */
zone = zone; /* XXX */
}
static void
zone_timer(isc_task_t *task, isc_event_t *event) {
dns_zone_t *zone = (dns_zone_t *)event->arg;
fprintf(stderr, "zone_timer\n");
dns_zone_maintenance(zone);
isc_event_free(&event);
task = task; /* XXX */
}
static dns_result_t
zone_settimer(dns_zone_t *zone, isc_stdtime_t now) {
isc_stdtime_t next = 0;
isc_time_t expires;
isc_interval_t interval;
isc_result_t iresult;
REQUIRE(DNS_ZONE_VALID(zone));
switch (zone->type) {
case dns_zone_master:
if (DNS_ZONE_FLAG(zone, DNS_ZONE_F_NEEDDUMP))
next = zone->dumptime;
if (DNS_ZONE_FLAG(zone, DNS_ZONE_F_LOADED)) {
if (DNS_ZONE_OPTION(zone, DNS_ZONE_O_SERVERS) &&
(zone->servertime < next || next == 0))
next = zone->servertime;
if (DNS_ZONE_OPTION(zone, DNS_ZONE_O_PARENTS) &&
(zone->parenttime < next || next == 0))
next = zone->parenttime;
if (DNS_ZONE_OPTION(zone, DNS_ZONE_O_CHILDREN) &&
(zone->childtime < next || next == 0))
next = zone->childtime;
}
break;
case dns_zone_slave:
case dns_zone_stub:
if (!DNS_ZONE_FLAG(zone, DNS_ZONE_F_REFRESH))
next = zone->refreshtime;
if (DNS_ZONE_FLAG(zone, DNS_ZONE_F_LOADED)) {
if (zone->expiretime < next || next == 0)
next = zone->expiretime;
if (DNS_ZONE_OPTION(zone, DNS_ZONE_O_SERVERS) &&
(zone->servertime < next || next == 0))
next = zone->servertime;
if (DNS_ZONE_OPTION(zone, DNS_ZONE_O_PARENTS) &&
(zone->parenttime < next || next == 0))
next = zone->parenttime;
if (DNS_ZONE_OPTION(zone, DNS_ZONE_O_CHILDREN) &&
(zone->childtime < next || next == 0))
next = zone->childtime;
}
break;
default:
break;
}
fprintf(stdout, "settimer %d %d = %d seconds\n",
next, now, next - now);
if (next == 0) {
if (zone->timer != NULL)
isc_timer_detach(&zone->timer);
} else {
isc_time_settoepoch(&expires);
if (next <= now)
isc_interval_set(&interval, 0, 1);
else
isc_interval_set(&interval, next - now, 0);
if (zone->timer != NULL) {
iresult = isc_timer_reset(zone->timer,
isc_timertype_once,
&expires, &interval,
ISC_TRUE);
} else {
iresult = isc_timer_create(zone->timgr,
isc_timertype_once,
&expires, &interval,
zone->task, zone_timer,
zone, &zone->timer);
}
if (iresult != ISC_R_SUCCESS) {
/* XXX */
return (DNS_R_UNEXPECTED);
}
}
return (DNS_R_SUCCESS);
}
void
cancel_refresh(dns_zone_t *zone) {
isc_stdtime_t now;
REQUIRE(DNS_ZONE_VALID(zone));
/* XXX MPA*/
LOCK(&zone->lock);
zone->flags &= ~DNS_ZONE_F_REFRESH;
UNLOCK(&zone->lock);
if (isc_stdtime_get(&now) != ISC_R_SUCCESS)
return;
if (!DNS_ZONE_FLAG(zone, DNS_ZONE_F_EXITING))
zone_settimer(zone, now);
}
static dns_result_t
dns_notify(dns_name_t *name, isc_sockaddr_t *addr, dns_rdatatype_t type,
dns_rdataclass_t rdclass, isc_sockaddr_t *source, isc_mem_t *mctx)
{
dns_message_t *msg = NULL;
dns_result_t result;
isc_buffer_t target;
/* dns_rdatalist_t *rdatalist = NULL; */
dns_rdatalist_t rdatalist;
dns_rdataset_t *rdataset = NULL;
char buf[512];
result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &msg);
if (result != DNS_R_SUCCESS)
return (result);
msg->opcode = dns_opcode_notify;
msg->rdclass = rdclass;
msg->id = htons(3456); /* XXX */
/* result = dns_message_gettemprdatalist(msg, &rdatalist); */
ISC_LIST_INIT(rdatalist.rdata);
ISC_LINK_INIT(&rdatalist, link);
rdatalist.type = type;
rdatalist.rdclass = rdclass;
rdatalist.ttl = 0;
result = dns_message_gettemprdataset(msg, &rdataset);
if (result != DNS_R_SUCCESS)
goto cleanup;
dns_rdataset_init(rdataset);
dns_rdatalist_tordataset(&rdatalist, rdataset);
ISC_LIST_APPEND(name->list, rdataset, link);
dns_message_addname(msg, name, DNS_SECTION_QUESTION);
isc_buffer_init(&target, buf, sizeof buf, ISC_BUFFERTYPE_BINARY);
result = dns_message_renderbegin(msg, &target);
if (result != DNS_R_SUCCESS)
goto cleanup;
result = dns_message_rendersection(msg, DNS_SECTION_QUESTION, 0, 0);
if (result != DNS_R_SUCCESS)
goto cleanup;
result = dns_message_rendersection(msg, DNS_SECTION_ANSWER, 0, 0);
if (result != DNS_R_SUCCESS)
goto cleanup;
result = dns_message_rendersection(msg, DNS_SECTION_AUTHORITY, 0, 0);
if (result != DNS_R_SUCCESS)
goto cleanup;
result = dns_message_rendersection(msg, DNS_SECTION_ADDITIONAL, 0, 0);
if (result != DNS_R_SUCCESS)
goto cleanup;
/* XXX TSIG here */
result = dns_message_renderend(msg);
if (result != DNS_R_SUCCESS)
goto cleanup;
/* XXX Queue for sending */
addr = addr; /* XXX */
source = source; /* XXX */
cleanup:
dns_message_destroy(&msg);
return (result);
}
dns_result_t
dns_zone_notifyreceive(dns_zone_t *zone, isc_sockaddr_t *from,
dns_message_t *msg)
{
unsigned int i;
dns_rdata_soa_t soa;
dns_rdataset_t *rdataset = NULL;
dns_rdata_t rdata;
dns_result_t result;
REQUIRE(DNS_ZONE_VALID(zone));
/*
* If type != T_SOA return DNS_R_REFUSED. We don't yet support
* ROLLOVER.
*
* SOA: RFC 1996
* Check that 'from' is a valid notify source, (zone->masters).
* Return DNS_R_REFUSED if not.
*
* If the notify message contains a serial number check it
* against the zones serial and return if <= current serial
*
* If a refresh check is progress, if so just record the
* fact we received a NOTIFY and from where and return.
* We will perform a new refresh check when the current one
* completes. Return DNS_R_SUCCESS.
*
* Otherwise initiate a refresh check using 'from' as the
* first address to check. Return DNS_R_SUCCESS.
*/
/*
* We only handle NOTIFY (SOA) at the present.
*/
LOCK(&zone->lock);
if (msg->counts[DNS_SECTION_QUESTION] != 0 ||
dns_message_findname(msg, DNS_SECTION_QUESTION, &zone->origin,
dns_rdatatype_soa, dns_rdatatype_none,
NULL, NULL) != DNS_R_SUCCESS) {
UNLOCK(&zone->lock);
return (DNS_R_REFUSED);
}
for (i = 0; i < zone->masterscnt; i++)
if (isc_sockaddr_equal(from, &zone->masters[i]))
break;
if (i >= zone->masterscnt) {
UNLOCK(&zone->lock);
return (DNS_R_REFUSED);
}
/*
* If the zone is loaded and there are answers check the serial
* to see if we need to do a refresh. Do not worry about this
* check if we are a dialup zone as we use the notify request
* to trigger a refresh check.
*/
if (msg->counts[DNS_SECTION_ANSWER] > 0 &&
DNS_ZONE_FLAG(zone, DNS_ZONE_F_LOADED) &&
!DNS_ZONE_OPTION(zone, DNS_ZONE_O_DIALUP)) {
result = dns_message_findname(msg, DNS_SECTION_ANSWER,
&zone->origin,
dns_rdatatype_soa,
dns_rdatatype_none, NULL,
&rdataset);
if (result == DNS_R_SUCCESS)
result = dns_rdataset_first(rdataset);
if (result == DNS_R_SUCCESS) {
isc_uint32_t serial = 0;
dns_rdataset_current(rdataset, &rdata);
result = dns_rdata_tostruct(&rdata, &soa, zone->mctx);
if (result == DNS_R_SUCCESS) {
serial = soa.serial;
dns_rdata_freestruct(&soa);
if (isc_serial_le(serial, zone->serial))
return (DNS_R_SUCCESS);
}
}
}
/*
* If we got this far and there was a refresh in progress just
* let it complete. Record where we got the notify from so we
* can perform a refresh check when the current one completes
*/
if (DNS_ZONE_FLAG(zone, DNS_ZONE_F_REFRESH)) {
zone->flags |= DNS_ZONE_F_NEEDREFRESH;
zone->notifyfrom = *from;
UNLOCK(&zone->lock);
return (DNS_R_SUCCESS);
}
UNLOCK(&zone->lock);
dns_zone_refresh(zone);
return (DNS_R_SUCCESS);
}
isc_result_t
dns_zone_callback(dns_c_ctx_t *cfg, dns_c_zone_t *czone, dns_c_view_t *cview,
void *uap) {
dns_zone_callbackarg_t *cba = uap;
dns_name_t name;
dns_view_t *oldview = NULL;
dns_zone_t *oldzone = NULL;
dns_view_t *newview = NULL;
dns_zone_t *newzone = NULL;
dns_zone_t *tmpzone = NULL;
dns_result_t result;
isc_boolean_t boolean;
char *viewname;
REQUIRE(czone != NULL);
REQUIRE(cba != NULL);
/*
* Initialization.
*/
dns_name_init(&name, NULL);
/*
* Find views by name.
*/
if (cview != NULL)
dns_c_view_getname(NULL, cview, &viewname);
else
viewname = "default";
printf("view %s\n", viewname);
oldview = dns_view_findinlist(&cba->oldviews, viewname, czone->zclass);
newview = dns_view_findinlist(&cba->newviews, viewname, czone->zclass);
if (newview == NULL) {
result = dns_view_create(cba->mctx, czone->zclass, viewname,
&newview);
if (result != DNS_R_SUCCESS)
goto cleanup;
ISC_LIST_APPEND(cba->newviews, newview, link);
}
/*
* Create and populate a new zone structure.
*/
result = dns_zone_create(&newzone, cba->mctx);
if (result != DNS_R_SUCCESS)
goto cleanup;
result = dns_zone_copy(cfg, czone, newzone);
if (result != DNS_R_SUCCESS)
goto cleanup;
#if 0
/* XXX hints should be a zone */
if (dns_zone_gettype(newzone) == dns_zone_hint) {
dns_view_sethints(newview, newzone);
goto cleanup;
}
#endif
/*
* Find zone in mount table.
*/
result = dns_zone_getorigin(newzone, cba->mctx, &name);
if (result != DNS_R_SUCCESS)
goto cleanup;
dns_zone_print(newzone);
result = dns_zt_find(newview->zonetable, &name, NULL, &tmpzone);
if (result == DNS_R_SUCCESS) {
printf("zone already exists=\n");
result = DNS_R_EXISTS;
goto cleanup;
} else if (result != DNS_R_PARTIALMATCH && result != DNS_R_NOTFOUND)
goto cleanup;
if (oldview != NULL)
result = dns_zt_find(oldview->zonetable, &name, NULL, &oldzone);
else
result = DNS_R_NOTFOUND;
printf("dns_zt_find() returned %s\n", dns_result_totext(result));
if (result == DNS_R_NOTFOUND || result == DNS_R_PARTIALMATCH) {
if (result == DNS_R_PARTIALMATCH) {
dns_zone_print(oldzone);
}
result = dns_view_addzone(newview, newzone);
if (result != DNS_R_SUCCESS)
goto cleanup;
} else if (result == DNS_R_SUCCESS) {
dns_zone_print(oldzone);
/* Does the new configuration match the existing one? */
boolean = dns_zone_equal(newzone, oldzone);
printf("dns_zone_equal() returned %s\n", boolean ? "TRUE" : "FALSE");
if (boolean)
result = dns_view_addzone(newview, oldzone);
else
result = dns_view_addzone(newview, newzone);
}
cleanup:
if (dns_name_dynamic(&name))
dns_name_free(&name, cba->mctx);
if (tmpzone != NULL)
dns_zone_detach(&tmpzone);
if (newzone != NULL)
dns_zone_detach(&newzone);
if (oldzone != NULL)
dns_zone_detach(&oldzone);
return (result);
}
/*
* Copy / translate zone configuration data to dns_zone_t.
*/
dns_result_t
dns_zone_copy(dns_c_ctx_t *ctx, dns_c_zone_t *czone, dns_zone_t *zone) {
isc_result_t iresult;
dns_result_t result;
isc_boolean_t boolean;
const char *filename = NULL;
const char *ixfr = NULL;
dns_c_ipmatchlist_t *acl = 0;
dns_c_severity_t severity;
dns_c_iplist_t *iplist = NULL;
dns_c_pubkey_t *pubkey = NULL;
isc_uint32_t i;
isc_sockaddr_t sockaddr;
isc_int32_t size;
isc_int32_t xfrtime;
in_port_t port;
const char *origin;
char *o;
ctx = ctx; /* unused */
dns_zone_setclass(zone, czone->zclass);
origin = NULL;
result = dns_c_zone_getname(NULL, czone, &origin);
if (result != DNS_R_SUCCESS)
return (result);
o = isc_mem_strdup(zone->mctx, origin);
if (o == NULL)
return (DNS_R_NOMEMORY);
result = dns_zone_setorigin(zone, o);
isc_mem_free(zone->mctx, o);
if (result != DNS_R_SUCCESS)
return (result);
/* XXX needs to be an zone option */
result = dns_zone_setdbtype(zone, "rbt");
if (result != DNS_R_SUCCESS)
return (result);
switch (czone->ztype) {
case dns_c_zone_master:
dns_zone_settype(zone, dns_zone_master);
iresult = dns_c_zone_getfile(NULL /* isc_log_t */,
czone, &filename);
if (iresult != ISC_R_SUCCESS)
return (iresult);
result = dns_zone_setdatabase(zone, filename);
if (result != DNS_R_SUCCESS)
return (iresult);
iresult = dns_c_zone_getchecknames(NULL /* isc_log_t */,
czone, &severity);
if (iresult == ISC_R_SUCCESS)
dns_zone_setchecknames(zone, severity);
else
dns_zone_setchecknames(zone, dns_c_severity_fail);
iresult = dns_c_zone_getallowupd(NULL /* isc_log_t */,
czone, &acl);
if (iresult == ISC_R_SUCCESS) {
dns_zone_setupdateacl(zone, acl);
dns_c_ipmatchlist_delete(NULL, &acl);
} else
dns_zone_clearupdateacl(zone);
iresult = dns_c_zone_getallowquery(NULL /* isc_log_t */,
czone, &acl);
if (iresult == ISC_R_SUCCESS) {
dns_zone_setqueryacl(zone, acl);
dns_c_ipmatchlist_delete(NULL, &acl);
} else
dns_zone_clearqueryacl(zone);
iresult = dns_c_zone_getallowtransfer(NULL /* isc_log_t */,
czone, &acl);
if (iresult == ISC_R_SUCCESS) {
dns_zone_setxfracl(zone, acl);
dns_c_ipmatchlist_delete(NULL, &acl);
} else
dns_zone_clearxfracl(zone);
iresult = dns_c_zone_getdialup(NULL /* isc_log_t */,
czone, &boolean);
if (iresult == ISC_R_SUCCESS)
dns_zone_setoption(zone, DNS_ZONE_O_DIALUP, boolean);
else
dns_zone_clearoption(zone, DNS_ZONE_O_DIALUP);
iresult = dns_c_zone_getnotify(NULL /* isc_log_t */,
czone, &boolean);
if (iresult == ISC_R_SUCCESS)
dns_zone_setoption(zone, DNS_ZONE_O_NOTIFY, boolean);
else
dns_zone_clearoption(zone, DNS_ZONE_O_NOTIFY);
iresult = dns_c_zone_getalsonotify(NULL /* isc_log_t */,
czone, &iplist);
if (iresult == ISC_R_SUCCESS) {
for (i = 0; i < iplist->nextidx; i++) {
result = dns_zone_addnotify(zone,
&iplist->ips[i]);
if (result != DNS_R_SUCCESS)
return (result);
}
} else
dns_zone_clearnotify(zone);
iresult = dns_c_zone_getixfrbase(NULL /* isc_log_t */,
czone, &ixfr);
if (iresult == ISC_R_SUCCESS) {
result = dns_zone_setixfrlog(zone, ixfr);
if (result != DNS_R_SUCCESS)
return (result);
zone->diff_on_reload = ISC_TRUE;
} else
zone->diff_on_reload = ISC_FALSE;
czone->u.mzone.ixfr_tmp; /*XXX*/
iresult = dns_c_zone_getmaxixfrlog(NULL /* isc_log_t */,
czone, &size);
if (iresult == ISC_R_SUCCESS)
dns_zone_setixfrlogsize(zone, size);
czone->u.mzone.maint_ixfr_base; /*XXX*/
iresult = dns_c_zone_getpubkey(NULL /* isc_log_t */,
czone, &pubkey);
if (iresult == ISC_R_SUCCESS)
dns_zone_setpubkey(zone, pubkey);
else
dns_zone_setpubkey(zone, NULL);
/*
* should master port be seperate or just applied to
* isc_sockaddr_t's
*/
iresult = dns_c_zone_getmasterport(NULL /* isc_log_t */,
czone, &port);
if (iresult != ISC_R_SUCCESS)
port = 53;
dns_zone_setmasterport(zone, port);
iresult = dns_c_zone_getmasterips(NULL /* isc_log_t */,
czone, &iplist);
if (iresult == ISC_R_SUCCESS) {
for (i = 0; i < iplist->nextidx; i++) {
result = dns_zone_addmaster(zone,
&iplist->ips[i]);
if (result != DNS_R_SUCCESS)
return (result);
}
} else
dns_zone_clearmasters(zone);
iresult = dns_c_zone_gettransfersource(NULL /* isc_log_t */,
czone, &sockaddr);
if (iresult == ISC_R_SUCCESS) {
result = dns_zone_setxfrsource(zone, &sockaddr);
if (result != DNS_R_SUCCESS)
return (result);
}
iresult = dns_c_zone_getmaxtranstimein(NULL /* isc_log_t */,
czone, &xfrtime);
if (iresult == ISC_R_SUCCESS)
dns_zone_setxfrtime(zone, xfrtime);
else
dns_zone_setxfrtime(zone, MAX_XFER_TIME);
break;
case dns_c_zone_forward:
#ifdef notyet
/*
* forward zones are still in a state of flux
*/
czone->u.fzone.check_names; /* XXX unused in BIND 8 */
czone->u.fzone.forward; /* XXX*/
czone->u.fzone.forwarders; /* XXX*/
#endif
break;
case dns_c_zone_slave:
dns_zone_settype(zone, dns_zone_slave);
iresult = dns_c_zone_getfile(NULL /* isc_log_t */,
czone, &filename);
if (iresult != ISC_R_SUCCESS)
return (iresult);
result = dns_zone_setdatabase(zone, filename);
if (result != DNS_R_SUCCESS)
return (iresult);
iresult = dns_c_zone_getchecknames(NULL /* isc_log_t */,
czone, &severity);
if (iresult == ISC_R_SUCCESS)
dns_zone_setchecknames(zone, severity);
else
dns_zone_setchecknames(zone, dns_c_severity_warn);
iresult = dns_c_zone_getallowquery(NULL /* isc_log_t */,
czone, &acl);
if (iresult == ISC_R_SUCCESS) {
dns_zone_setqueryacl(zone, acl);
dns_c_ipmatchlist_delete(NULL, &acl);
} else
dns_zone_clearqueryacl(zone);
iresult = dns_c_zone_getpubkey(NULL /* isc_log_t */,
czone, &pubkey);
if (iresult == ISC_R_SUCCESS)
dns_zone_setpubkey(zone, pubkey);
else
dns_zone_setpubkey(zone, NULL);
iresult = dns_c_zone_getmasterport(NULL /* isc_log_t */,
czone, &port);
if (iresult != ISC_R_SUCCESS)
port = 53;
dns_zone_setmasterport(zone, port);
iresult = dns_c_zone_getmasterips(NULL /* isc_log_t */,
czone, &iplist);
if (iresult == ISC_R_SUCCESS) {
for (i = 0; i < iplist->nextidx; i++) {
result = dns_zone_addmaster(zone,
&iplist->ips[i]);
if (result != DNS_R_SUCCESS)
return (result);
}
} else
dns_zone_clearmasters(zone);
break;
case dns_c_zone_stub:
dns_zone_settype(zone, dns_zone_stub);
iresult = dns_c_zone_getfile(NULL /* isc_log_t */,
czone, &filename);
if (iresult != ISC_R_SUCCESS)
return (iresult);
result = dns_zone_setdatabase(zone, filename);
if (result != DNS_R_SUCCESS)
return (iresult);
iresult = dns_c_zone_getchecknames(NULL /* isc_log_t */,
czone, &severity);
if (iresult == ISC_R_SUCCESS)
dns_zone_setchecknames(zone, severity);
else
dns_zone_setchecknames(zone, dns_c_severity_warn);
iresult = dns_c_zone_getallowquery(NULL /* isc_log_t */,
czone, &acl);
if (iresult == ISC_R_SUCCESS) {
dns_zone_setqueryacl(zone, acl);
dns_c_ipmatchlist_delete(NULL, &acl);
} else
dns_zone_clearqueryacl(zone);
iresult = dns_c_zone_getpubkey(NULL /* isc_log_t */,
czone, &pubkey);
if (iresult == ISC_R_SUCCESS)
dns_zone_setpubkey(zone, pubkey);
else
dns_zone_setpubkey(zone, NULL);
iresult = dns_c_zone_getmasterport(NULL /* isc_log_t */,
czone, &port);
if (iresult != ISC_R_SUCCESS)
port = 53;
dns_zone_setmasterport(zone, port);
iresult = dns_c_zone_getmasterips(NULL /* isc_log_t */,
czone, &iplist);
if (iresult == ISC_R_SUCCESS) {
for (i = 0; i < iplist->nextidx; i++) {
result = dns_zone_addmaster(zone,
&iplist->ips[i]);
if (result != DNS_R_SUCCESS)
return (result);
}
} else
dns_zone_clearmasters(zone);
break;
case dns_c_zone_hint:
dns_zone_settype(zone, dns_zone_hint);
iresult = dns_c_zone_getfile(NULL /* isc_log_t */,
czone, &filename);
if (iresult != ISC_R_SUCCESS)
return (iresult);
result = dns_zone_setdatabase(zone, filename);
if (result != DNS_R_SUCCESS)
return (result);
iresult = dns_c_zone_getchecknames(NULL /* isc_log_t */,
czone, &severity);
if (iresult == ISC_R_SUCCESS)
dns_zone_setchecknames(zone, severity);
else
dns_zone_setchecknames(zone, dns_c_severity_fail);
iresult = dns_c_zone_getpubkey(NULL /* isc_log_t */,
czone, &pubkey);
if (iresult == ISC_R_SUCCESS)
dns_zone_setpubkey(zone, pubkey);
else
dns_zone_setpubkey(zone, NULL);
break;
}
return (DNS_R_SUCCESS);
}
void
dns_zone_setqueryacl(dns_zone_t *zone, dns_c_ipmatchlist_t *acl) {
REQUIRE(DNS_ZONE_VALID(zone));
LOCK(&zone->lock);
if (zone->query_acl != NULL)
dns_c_ipmatchlist_delete(NULL /* isc_log_t */,
&zone->query_acl);
zone->query_acl = dns_c_ipmatchlist_attach(NULL /* isc_log_t */,
acl);
UNLOCK(&zone->lock);
}
void
dns_zone_setupdateacl(dns_zone_t *zone, dns_c_ipmatchlist_t *acl) {
REQUIRE(DNS_ZONE_VALID(zone));
LOCK(&zone->lock);
if (zone->update_acl != NULL)
dns_c_ipmatchlist_delete(NULL /* isc_log_t */,
&zone->update_acl);
zone->update_acl = dns_c_ipmatchlist_attach(NULL /* isc_log_t */,
acl);
UNLOCK(&zone->lock);
}
void
dns_zone_setxfracl(dns_zone_t *zone, dns_c_ipmatchlist_t *acl) {
REQUIRE(DNS_ZONE_VALID(zone));
LOCK(&zone->lock);
if (zone->xfr_acl != NULL)
dns_c_ipmatchlist_delete(NULL /* isc_log_t */,
&zone->xfr_acl);
zone->xfr_acl = dns_c_ipmatchlist_attach(NULL /* isc_log_t */,
acl);
UNLOCK(&zone->lock);
}
dns_c_ipmatchlist_t *
dns_zone_getqueryacl(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
return (zone->query_acl);
}
dns_c_ipmatchlist_t *
dns_zone_getupdateacl(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
return (zone->update_acl);
}
dns_c_ipmatchlist_t *
dns_zone_getxfracl(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
return (zone->xfr_acl);
}
void
dns_zone_clearupdateacl(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
LOCK(&zone->lock);
if (zone->update_acl != NULL)
dns_c_ipmatchlist_delete(NULL /* isc_log_t */,
&zone->update_acl);
UNLOCK(&zone->lock);
}
void
dns_zone_clearqueryacl(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
LOCK(&zone->lock);
if (zone->query_acl != NULL)
dns_c_ipmatchlist_delete(NULL /* isc_log_t */,
&zone->query_acl);
UNLOCK(&zone->lock);
}
void
dns_zone_clearxfracl(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
LOCK(&zone->lock);
if (zone->xfr_acl != NULL)
dns_c_ipmatchlist_delete(NULL /* isc_log_t */,
&zone->xfr_acl);
UNLOCK(&zone->lock);
}
void
dns_zone_setchecknames(dns_zone_t *zone, dns_c_severity_t severity) {
REQUIRE(DNS_ZONE_VALID(zone));
zone->check_names = severity;
}
dns_c_severity_t
dns_zone_getchecknames(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
return (zone->check_names);
}
void
dns_zone_setpubkey(dns_zone_t *zone, dns_c_pubkey_t *pubkey) {
REQUIRE(DNS_ZONE_VALID(zone));
zone->pubkey = pubkey; /* XXX should be an attach */
}
dns_c_pubkey_t *
dns_zone_getpubkey(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
return (zone->pubkey);
}
void
dns_zone_setixfrlogsize(dns_zone_t *zone, isc_int32_t size) {
REQUIRE(DNS_ZONE_VALID(zone));
zone->ixfrlogsize = size;
}
isc_int32_t
dns_zone_getixfrlogsize(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
return (zone->ixfrlogsize);
}
void
dns_zone_setmasterport(dns_zone_t *zone, in_port_t port) {
REQUIRE(DNS_ZONE_VALID(zone));
zone->masterport = port;
}
in_port_t
dns_zone_getmasterport(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
return (zone->masterport);
}
static void
dns_zone_logerror(dns_zone_t *zone, const char *fmt, ...) {
va_list ap;
char message[4096];
char namebuf[1024];
isc_buffer_t buffer;
int len;
dns_result_t result;
isc_buffer_init(&buffer, namebuf, sizeof namebuf, ISC_BUFFERTYPE_TEXT);
LOCK(&zone->lock);
result = dns_name_totext(&zone->origin, ISC_TRUE, &buffer);
UNLOCK(&zone->lock);
if (result == DNS_R_SUCCESS)
len = buffer.used;
else
len = 0;
va_start(ap, fmt);
vsnprintf(message, sizeof message, fmt, ap);
va_end(ap);
fprintf(stderr, "zone %.*s: %s\n", len, namebuf, message);
}
static int
message_count(dns_message_t *msg, dns_section_t section, dns_rdatatype_t type) {
dns_result_t result;
dns_name_t *name;
dns_rdataset_t *curr;
int res = 0;
result = dns_message_firstname(msg, section);
while (result == DNS_R_SUCCESS) {
name = NULL;
dns_message_currentname(msg, section, &name);
for (curr = ISC_LIST_TAIL(name->list); curr != NULL;
curr = ISC_LIST_PREV(curr, link)) {
if (curr->type == type)
res++;
}
result = dns_message_nextname(msg, section);
}
return (res);
}
void
dns_zone_setresolver(dns_zone_t *zone, dns_resolver_t *resolver) {
REQUIRE(DNS_ZONE_VALID(zone));
LOCK(&zone->lock);
if (zone->res != NULL)
dns_resolver_detach(&zone->res);
dns_resolver_attach(resolver, &zone->res);
UNLOCK(&zone->lock);
}
void
dns_zone_setxfrtime(dns_zone_t *zone, isc_uint32_t xfrtime) {
REQUIRE(DNS_ZONE_VALID(zone));
REQUIRE(xfrtime != 0);
zone->xfrtime = xfrtime;
}
isc_uint32_t
dns_zone_getxfrtime(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
return (zone->xfrtime);
}
void
dns_zone_transfer_in(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
fprintf(stdout, "dns_zone_transfer_in\n");
}
dns_zonetype_t dns_zone_gettype(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
return (zone->type);
}
dns_result_t
dns_zone_getorigin(dns_zone_t *zone, isc_mem_t *mctx, dns_name_t *name) {
REQUIRE(DNS_ZONE_VALID(zone));
return (dns_name_dup(&zone->origin, mctx, name));
}
isc_task_t *dns_zone_gettask(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
return (zone->task);
}
const char *dns_zone_getdatabase(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
return (zone->database);
}
const char *dns_zone_getixfrlog(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
return (zone->ixfrlog);
}
#if 0
/*
* XXX should become isc_sockaddr_fromaddr() once dns_c_addr_t -> isc
*/
static void
sockaddr_fromaddr(isc_sockaddr_t *sockaddr, dns_c_addr_t *a,
in_port_t port) {
switch (a->type.sa.sa_family) {
case AF_INET:
isc_sockaddr_fromin(sockaddr, &a->type.sin.sin_addr, port);
break;
case AF_INET6:
isc_sockaddr_fromin6(sockaddr, &a->type.sin6.sin6_addr, port);
break;
default:
INSIST(0);
}
}
#endif
static void
record_serial() {
}
static isc_boolean_t
dns_zone_equal(dns_zone_t *oldzone, dns_zone_t *newzone) {
unsigned int i;
REQUIRE(DNS_ZONE_VALID(oldzone));
REQUIRE(DNS_ZONE_VALID(newzone));
LOCK(&oldzone->lock);
LOCK(&newzone->lock);
if (oldzone->type != newzone->type ||
oldzone->xfrtime != newzone->xfrtime ||
oldzone->rdclass != newzone->rdclass ||
oldzone->db_argc != newzone->db_argc ||
oldzone->notifycnt != newzone->notifycnt ||
oldzone->masterscnt != newzone->masterscnt ||
oldzone->masterport != newzone->masterport ||
oldzone->check_names != newzone->check_names ||
oldzone->diff_on_reload != newzone->diff_on_reload ||
oldzone->ixfrlogsize != newzone->ixfrlogsize)
goto false;
if (!dns_name_equal(&oldzone->origin, &newzone->origin))
goto false;
if ((oldzone->updatelog == NULL && newzone->updatelog != NULL) ||
(oldzone->updatelog != NULL && newzone->updatelog == NULL) ||
(oldzone->updatelog != NULL &&
strcmp(oldzone->updatelog, newzone->updatelog) != 0))
goto false;
if ((oldzone->ixfrlog == NULL && newzone->ixfrlog != NULL) ||
(oldzone->ixfrlog != NULL && newzone->ixfrlog == NULL) ||
(oldzone->ixfrlog != NULL &&
strcmp(oldzone->ixfrlog, newzone->ixfrlog) != 0))
goto false;
if ((oldzone->options & oldzone->setoptions) !=
(newzone->options & newzone->setoptions))
goto false;
if ((oldzone->db_type == NULL && newzone->db_type != NULL) ||
(oldzone->db_type != NULL && newzone->db_type == NULL) ||
(oldzone->db_type != NULL &&
strcmp(oldzone->db_type, newzone->db_type) != 0))
goto false;
for (i = 0; i < oldzone->db_argc; i++)
if (strcmp(oldzone->db_argv[i], newzone->db_argv[i]) != 0)
goto false;
if (!isc_sockaddr_equal(&oldzone->xfrsource, &newzone->xfrsource))
goto false;
for (i = 0; i < oldzone->notifycnt; i++)
if (!isc_sockaddr_equal(&oldzone->notify[i],
&newzone->notify[i]))
goto false;
for (i = 0; i < oldzone->masterscnt; i++)
if (!isc_sockaddr_equal(&oldzone->masters[i],
&newzone->masters[i]))
goto false;
if (!dns_c_ipmatchlist_equal(oldzone->update_acl, newzone->update_acl))
goto false;
if (!dns_c_ipmatchlist_equal(oldzone->query_acl, newzone->query_acl))
goto false;
if (!dns_c_ipmatchlist_equal(oldzone->xfr_acl, newzone->xfr_acl))
goto false;
if (!dns_c_pubkey_equal(oldzone->pubkey, newzone->pubkey))
goto false;
UNLOCK(&newzone->lock);
UNLOCK(&oldzone->lock);
return(ISC_TRUE); /* XXX should be ISC_TRUE once acl/pubkey
checks are done. */
false:
UNLOCK(&newzone->lock);
UNLOCK(&oldzone->lock);
return (ISC_FALSE);
}
dns_result_t
dns_zone_replacedb(dns_zone_t *zone, dns_db_t *db, isc_boolean_t dump) {
dns_dbversion_t *ver;
isc_result_t result;
REQUIRE(DNS_ZONE_VALID(zone));
ver = NULL;
dns_db_currentversion(db, &ver);
/*
* The initial version of a slave zone is always dumped;
* subsequent versions may be journalled instead if this
* is enabled in the configuration.
*/
if (zone->top != NULL && zone->ixfrlog != NULL &&
zone->diff_on_reload) {
printf("generating diffs\n");
result = dns_db_diff(zone->mctx,
db, ver,
zone->top, NULL /* XXX */,
zone->ixfrlog);
if (result != DNS_R_SUCCESS)
goto fail;
} else {
if (dump) {
printf("dumping new version\n");
/* XXX should use temporary file and rename */
result = dns_db_dump(db, ver, zone->database);
if (result != DNS_R_SUCCESS)
goto fail;
}
printf("unlinking journal\n");
(void) unlink(zone->ixfrlog);
}
dns_db_closeversion(db, &ver, ISC_FALSE);
printf("replacing database...");
if (zone->top != NULL)
dns_db_detach(&zone->top);
dns_db_attach(db, &zone->top);
zone->flags |= DNS_ZONE_F_LOADED;
return (DNS_R_SUCCESS);
fail:
dns_db_closeversion(db, &ver, ISC_FALSE);
return (result);
}