zone.c revision 2eeaed2812c732430b0a4a57d5d3f58f01cfeab7
1413616670fcb95b9ef236351502e4884ddca8bfTinderbox User * Copyright (C) 1999-2002 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * 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
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews/* $Id: zone.c,v 1.367 2002/04/02 08:04:42 marka Exp $ */
c46f10e4a1702191b003cf8f8fc5059c15d29c48Mark Andrews#define ZONE_MAGIC ISC_MAGIC('Z', 'O', 'N', 'E')
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews#define DNS_ZONE_VALID(zone) ISC_MAGIC_VALID(zone, ZONE_MAGIC)
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews#define NOTIFY_MAGIC ISC_MAGIC('N', 't', 'f', 'y')
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews#define DNS_NOTIFY_VALID(notify) ISC_MAGIC_VALID(notify, NOTIFY_MAGIC)
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews#define STUB_MAGIC ISC_MAGIC('S', 't', 'u', 'b')
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews#define DNS_STUB_VALID(stub) ISC_MAGIC_VALID(stub, STUB_MAGIC)
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews#define ZONEMGR_MAGIC ISC_MAGIC('Z', 'm', 'g', 'r')
c46f10e4a1702191b003cf8f8fc5059c15d29c48Mark Andrews#define DNS_ZONEMGR_VALID(stub) ISC_MAGIC_VALID(stub, ZONEMGR_MAGIC)
0b056755b2f423ba5f6adac8f7851d78f7d11437David Lawrence#define LOAD_MAGIC ISC_MAGIC('L', 'o', 'a', 'd')
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#define DNS_LOAD_VALID(load) ISC_MAGIC_VALID(load, LOAD_MAGIC)
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews#define FORWARD_MAGIC ISC_MAGIC('F', 'o', 'r', 'w')
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#define DNS_FORWARD_VALID(load) ISC_MAGIC_VALID(load, FORWARD_MAGIC)
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#define IO_MAGIC ISC_MAGIC('Z', 'm', 'I', 'O')
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#define DNS_IO_VALID(load) ISC_MAGIC_VALID(load, IO_MAGIC)
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews * Ensure 'a' is at least 'min' but not more than 'max'.
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence (((a) < (min)) ? (min) : ((a) < (max) ? (a) : (max)))
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence * Default values.
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#define MAX_XFER_TIME (2*3600) /* Documented default is 2 hours */
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#define DNS_MAX_EXPIRE 14515200 /* 24 weeks */
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson do { (z)->locked = ISC_FALSE; UNLOCK(&(z)->lock); } while (0)
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /* Unlocked */
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence unsigned int magic;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence ISC_LINK(dns_zone_t) link; /* Used by zmgr. */
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence unsigned int irefs;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence unsigned int flags;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /* Access Control Lists */
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Zones in certain states such as "waiting for zone transfer"
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson * or "zone transfer in progress" are kept on per-state linked lists
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews * in the zone manager using the 'statelink' field. The 'statelist'
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews * field points at the list the zone is currently on. It the zone
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews * is not on any such list, statelist is NULL.
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews * Optional per-zone statistics counters (NULL if not present).
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews#define DNS_ZONE_FLAG(z,f) (ISC_TF(((z)->flags & (f)) != 0))
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews#define DNS_ZONE_SETFLAG(z,f) do { \
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews (z)->flags |= (f); \
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define DNS_ZONE_CLRFLAG(z,f) do { \
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews (z)->flags &= ~(f); \
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews /* XXX MPA these may need to go back into zone.h */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define DNS_ZONEFLG_REFRESH 0x00000001U /* refresh check in progress */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define DNS_ZONEFLG_NEEDDUMP 0x00000002U /* zone need consolidation */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define DNS_ZONEFLG_USEVC 0x00000004U /* use tcp for refresh query */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define DNS_ZONEFLG_DUMPING 0x00000008U /* a dump is in progress */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define DNS_ZONEFLG_HASINCLUDE 0x00000010U /* $INCLUDE in zone file */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define DNS_ZONEFLG_LOADED 0x00000020U /* database has loaded */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define DNS_ZONEFLG_EXITING 0x00000040U /* zone is being destroyed */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define DNS_ZONEFLG_EXPIRED 0x00000080U /* zone has expired */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define DNS_ZONEFLG_NEEDREFRESH 0x00000100U /* refresh check needed */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define DNS_ZONEFLG_UPTODATE 0x00000200U /* zone contents are
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews * uptodate */
6a528eaa09b6eed63144250dc61062f3a84880abMark Andrews#define DNS_ZONEFLG_NEEDNOTIFY 0x00000400U /* need to send out notify
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews * messages */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define DNS_ZONEFLG_DIFFONRELOAD 0x00000800U /* generate a journal diff on
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define DNS_ZONEFLG_NOMASTERS 0x00001000U /* an attempt to refresh a
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews * zone with no masters
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews * occured */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define DNS_ZONEFLG_LOADING 0x00002000U /* load from disk in progress*/
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define DNS_ZONEFLG_HAVETIMERS 0x00004000U /* timer values have been set
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews * from SOA (if not set, we
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews * are still using
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews * default timer values) */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define DNS_ZONEFLG_FORCEXFER 0x00008000U /* Force a zone xfer */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define DNS_ZONEFLAG_NOIXFR 0x00100000U /* IXFR failed, force AXFR */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define DNS_ZONE_OPTION(z,o) (((z)->options & (o)) != 0)
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews/* Flags for zone_load() */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define DNS_ZONELOADFLAG_NOSTAT 0x00000001U /* Do not stat() master files */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews unsigned int magic;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews /* Locked by rwlock. */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews /* Configuration data. */
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews /* Locked by iolock */
b6a0341bcb113e93bd0bc41a9f9a1fc117444da6Mark Andrews * Hold notify state.
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews unsigned int magic;
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews unsigned int flags;
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews * dns_stub holds state while performing a 'stub' transfer.
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews * 'db' is the zone's 'db' or a new one if this is the initial
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews unsigned int magic;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * Hold load state.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int magic;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Hold forward state.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int magic;
368b37b616234fce3d23099eb180f1dd38e1fb62Mark Andrews * Hold IO request state.
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrewsstatic void zone_settimer(dns_zone_t *, isc_time_t *);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrewsstatic void zone_debuglog(dns_zone_t *zone, const char *, int debuglevel,
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrewsstatic void notify_log(dns_zone_t *zone, int level, const char *fmt, ...)
cabaeca9ae5b98c80586b91e89cf552e17a75a9bBrian Wellingtonstatic void zone_iattach(dns_zone_t *source, dns_zone_t **target);
cabaeca9ae5b98c80586b91e89cf552e17a75a9bBrian Wellingtonstatic void zone_idetach(dns_zone_t **zonep);
f1cae4bcb7ee3060d893f5ab3ba55c1820bf3e4aBrian Wellingtonstatic isc_result_t zone_replacedb(dns_zone_t *zone, dns_db_t *db,
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrewsstatic isc_result_t default_journal(dns_zone_t *zone);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrewsstatic void zone_xfrdone(dns_zone_t *zone, isc_result_t result);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrewsstatic isc_result_t zone_postload(dns_zone_t *zone, dns_db_t *db,
29c818c7d40fc8898b062903ec703851328a4deaMark Andrewsstatic void zone_needdump(dns_zone_t *zone, unsigned int delay);
29c818c7d40fc8898b062903ec703851328a4deaMark Andrewsstatic void zone_shutdown(isc_task_t *, isc_event_t *);
29c818c7d40fc8898b062903ec703851328a4deaMark Andrewsstatic void zone_loaddone(void *arg, isc_result_t result);
29c818c7d40fc8898b062903ec703851328a4deaMark Andrewsstatic isc_result_t zone_startload(dns_db_t *db, dns_zone_t *zone,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews/* ondestroy example */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic void dns_zonemgr_dbdestroyed(isc_task_t *task, isc_event_t *event);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic void refresh_callback(isc_task_t *, isc_event_t *);
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencestatic void stub_callback(isc_task_t *, isc_event_t *);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrewsstatic void soa_query(isc_task_t *, isc_event_t *);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic void ns_query(dns_zone_t *zone, dns_rdataset_t *soardataset,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic int message_count(dns_message_t *msg, dns_section_t section,
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrewsstatic void notify_find_address(dns_notify_t *notify);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic isc_result_t notify_createmessage(dns_zone_t *zone,
d981ca645597116d227a48bf37cc5edc061c854dBob Halley unsigned int flags,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic void notify_done(isc_task_t *task, isc_event_t *event);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic void notify_send_toaddr(isc_task_t *task, isc_event_t *event);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic isc_result_t zone_dump(dns_zone_t *, isc_boolean_t);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic void got_transfer_quota(isc_task_t *task, isc_event_t *event);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic isc_result_t zmgr_start_xfrin_ifquota(dns_zonemgr_t *zmgr,
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrewsstatic void zmgr_resume_xfrs(dns_zonemgr_t *zmgr);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrewsstatic isc_result_t zonemgr_getio(dns_zonemgr_t *zmgr, isc_boolean_t high,
90e303b114e56db5809fdd19805243457fa43cd9Olafur Gudmundssonstatic void zonemgr_cancelio(dns_io_t *io);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewszone_get_from_db(dns_db_t *db, dns_name_t *origin, unsigned int *nscount,
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrewsstatic void forward_callback(isc_task_t *task, isc_event_t *event);
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrewsstatic void zone_saveunique(dns_zone_t *zone, const char *path,
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews const char *templat);
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrewsstatic void dump_done(void *arg, isc_result_t result);
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews#define ENTER zone_debuglog(zone, me, 1, "enter")
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrewsstatic const char *dbargv_default[] = { "rbt" };
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews#define DNS_ZONE_JITTER_ADD(a, b, c) \
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews if (isc_time_add((a), &_i, (c)) != ISC_R_SUCCESS) { \
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews "epoch approaching: upgrade required: " \
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews "now + %s failed", #b); \
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#define DNS_ZONE_TIME_ADD(a, b, c) \
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (isc_time_add((a), &_i, (c)) != ISC_R_SUCCESS) { \
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews "epoch approaching: upgrade required: " \
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews "now + %s failed", #b); \
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews *** Public functions.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsdns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx) {
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff "isc_mutex_init() failed: %s",
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews /* XXX MPA check that all elements are initialised */
19d365e4448f1782611280b020987988b7ac3210Mark Andrews isc_refcount_init(&zone->erefs, 1); /* Implicit attach. */
19d365e4448f1782611280b020987988b7ac3210Mark Andrews /* Must be after magic is set. */
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews result = dns_zone_setdbtype(zone, dbargc_default, dbargv_default);
693ddf84daa745a0ea8ca311a8154dfa03eabc43Andreas Gustafsson ISC_EVENT_INIT(&zone->ctlevent, sizeof(zone->ctlevent), 0, NULL,
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews DNS_EVENT_ZONECONTROL, zone_shutdown, zone, zone,
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Free a zone. Because we require that there be no more
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff * outstanding events or references, no locking is necessary.
7c0378745269fe49a05904935afc42b85528f53aDavid Lawrence REQUIRE(isc_refcount_current(&zone->erefs) == 0);
7e4cda9965e2edf2ec43c57967eec8eff7061ab0Andreas Gustafsson * Managed objects. Order is important.
7e4cda9965e2edf2ec43c57967eec8eff7061ab0Andreas Gustafsson dns_request_destroy(&zone->request); /* XXXMPA */
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington /* Unmanaged objects */
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington isc_mem_free(zone->mctx, zone->masterfile);
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington dns_stats_freecounters(zone->mctx, &zone->counters);
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington RUNTIME_CHECK(dns_zone_setmasterswithkeys(zone, NULL, NULL, 0)
1cc4695f0da63f0190e3514adccf6a96f3dc1519Mark Andrews RUNTIME_CHECK(dns_zone_setalsonotify(zone, NULL, 0)
7e4cda9965e2edf2ec43c57967eec8eff7061ab0Andreas Gustafsson /* last stuff */
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington * Single shot.
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellingtondns_zone_setclass(dns_zone_t *zone, dns_rdataclass_t rdclass) {
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews * Test and set.
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews REQUIRE(zone->rdclass == dns_rdataclass_none ||
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrencedns_zone_setnotifytype(dns_zone_t *zone, dns_notifytype_t notifytype) {
19d365e4448f1782611280b020987988b7ac3210Mark Andrews * Single shot.
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrewsdns_zone_settype(dns_zone_t *zone, dns_zonetype_t type) {
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington * Test and set.
228c679d7a269423019f7c528db92e855f08240bMark Andrews REQUIRE(zone->type == dns_zone_none || zone->type == type);
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews unsigned int i;
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews /* Free the old database argument list. */
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews unsigned int dbargc, const char * const *dbargv) {
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews unsigned int i;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews /* Set up a new database argument list. */
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews new = isc_mem_get(zone->mctx, dbargc * sizeof(*new));
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews for (i = 0; i < dbargc; i++)
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews for (i = 0; i < dbargc; i++) {
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews new[i] = isc_mem_strdup(zone->mctx, dbargv[i]);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews /* Free the old list. */
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews for (i = 0; i < dbargc; i++) {
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrewsdns_zone_setview(dns_zone_t *zone, dns_view_t *view) {
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrewsdns_zone_setorigin(dns_zone_t *zone, dns_name_t *origin) {
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews result = dns_name_dup(origin, zone->mctx, &zone->origin);
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrewsdns_zone_setstring(dns_zone_t *zone, char **field, const char *value) {
ae70d32b67cf30e06553c01479e71c87b21d984cBob Halleydns_zone_setfile(dns_zone_t *zone, const char *file) {
19d365e4448f1782611280b020987988b7ac3210Mark Andrews result = dns_zone_setstring(zone, &zone->masterfile, file);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews /* Calculate string length including '\0'. */
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews int len = strlen(zone->masterfile) + sizeof(".jnl");
ae70d32b67cf30e06553c01479e71c87b21d984cBob Halley result = dns_zone_setstring(zone, &zone->journal, journal);
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Huntdns_zone_setjournal(dns_zone_t *zone, const char *journal) {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence result = dns_zone_setstring(zone, &zone->journal, journal);
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt * Return true iff the zone is "dynamic", in the sense that the zone's
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson * master file (if any) is written by the server, rather than being
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson * updated manually and read by the server.
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson * This is true for slave zones, stub zones, and zones that allow
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson * dynamic updates either by having an update policy ("ssutable")
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff * or an "allow-update" ACL with a value other than exactly "{ none; }".
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews (!zone->update_disabled && zone->ssutable != NULL) ||
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews (!zone->update_disabled && zone->update_acl != NULL &&
19d365e4448f1782611280b020987988b7ac3210Mark Andrews zone->update_acl->elements[0].negative == ISC_TRUE
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewszone_load(dns_zone_t *zone, unsigned int flags) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_LOADING)) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (zone->db != NULL && zone->masterfile == NULL) {
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews * The zone has no master file configured, but it already
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff * has a database. It could be the built-in
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews * version.bind. CH zone, a zone with a persistent
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * database being reloaded, or maybe a zone that
19d365e4448f1782611280b020987988b7ac3210Mark Andrews * used to have a master file but whose configuration
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews * was changed so that it no longer has one. Do nothing.
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (zone->db != NULL && zone_isdynamic(zone)) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * This is a slave, stub, or dynamically updated
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * zone being reloaded. Do nothing - the database
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews * we already have is guaranteed to be up-to-date.
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews * Don't do the load if the file that stores the zone is older
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff * than the last time the zone was loaded. If the zone has not
d981ca645597116d227a48bf37cc5edc061c854dBob Halley * been loaded yet, zone->loadtime will be the epoch.
d981ca645597116d227a48bf37cc5edc061c854dBob Halley if (zone->masterfile != NULL && ! isc_time_isepoch(&zone->loadtime)) {
d981ca645597116d227a48bf37cc5edc061c854dBob Halley * The file is already loaded. If we are just doing a
d981ca645597116d227a48bf37cc5edc061c854dBob Halley * "rndc reconfig", we are done.
d981ca645597116d227a48bf37cc5edc061c854dBob Halley if (! DNS_ZONE_FLAG(zone, DNS_ZONEFLG_HASINCLUDE)) {
d981ca645597116d227a48bf37cc5edc061c854dBob Halley isc_time_compare(&filetime, &zone->loadtime) < 0) {
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews "skipping load: master file older "
d981ca645597116d227a48bf37cc5edc061c854dBob Halley "than last load");
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley dns_zone_log(zone, ISC_LOG_DEBUG(1), "starting load");
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews * Store the current time before the zone is loaded, so that if the
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley * file changes between the time of the load and the time that
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley * zone->loadtime is set, then the file will still be reloaded
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley * the next time dns_zone_load is called.
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews result = dns_db_create(zone->mctx, zone->db_argv[0],
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley "loading zone: creating database: %s",
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews "loading zone: "
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews "no master file configured");
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews dns_zone_log(zone, ISC_LOG_INFO, "loading zone: "
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews "no master file configured: continuing");
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff result = zone_postload(zone, db, loadtime, result);
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff return (zone_load(zone, DNS_ZONELOADFLAG_NOSTAT));
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graffzone_gotreadhandle(isc_task_t *task, isc_event_t *event) {
8695d7b357789bedff63e5b19c5ab25cd58fcd4bMark Andrews unsigned int options;
8695d7b357789bedff63e5b19c5ab25cd58fcd4bMark Andrews if ((event->ev_attributes & ISC_EVENTATTR_CANCELED) != 0)
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington result = dns_master_loadfileinc(load->zone->masterfile,
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if (result != ISC_R_SUCCESS && result != DNS_R_CONTINUE &&
8c962eba3d6faebc008806ebb6bb9d08089118e9Andreas Gustafssonzone_gotwritehandle(isc_task_t *task, isc_event_t *event) {
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson if ((event->ev_attributes & ISC_EVENTATTR_CANCELED) != 0)
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson dns_db_currentversion(zone->db, &version);
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson result = dns_master_dumpinc(zone->mctx, zone->db, version,
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson dns_db_closeversion(zone->db, &version, ISC_FALSE);
2383eb527269d333df4222da20e4b422c3662daaEvan Huntzone_startload(dns_db_t *db, dns_zone_t *zone, isc_time_t loadtime) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (zone->zmgr != NULL && zone->db != NULL && zone->task != NULL) {
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt result = dns_db_beginload(db, &load->callbacks.add,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = zonemgr_getio(zone->zmgr, ISC_TRUE, zone->task,
c2b217ea1135f070da3856d3276895b3026e932aMark Andrews } else if (DNS_ZONE_OPTION(zone, DNS_ZONEOPT_MANYERRORS)) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int options;
9a36fb86f5019f25705d25ea729d03fcf8ecaa95Mark Andrews options = DNS_MASTER_MANYERRORS|DNS_MASTER_ZONE;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff result = dns_master_loadfile(zone->masterfile, &zone->origin,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews tresult = dns_db_endload(db, &callbacks.add_private);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewszone_postload(dns_zone_t *zone, dns_db_t *db, isc_time_t loadtime,
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews unsigned int soacount = 0;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews unsigned int nscount = 0;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews isc_uint32_t serial, refresh, retry, expire, minimum;
f0ff273b530afa730025e1c5ad311950f7ff4328Mark Andrews * Initiate zone transfer? We may need a error code that
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews * indicates that the "permanent" form does not exist.
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews * XXX better error feedback to log.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if (result != ISC_R_SUCCESS && result != DNS_R_SEENINCLUDE) {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "no master file");
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews "loading master file %s: %s",
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews "loading master file %s: %s",
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews "number of nodes in database: %u",
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews dns_zone_log(zone, ISC_LOG_DEBUG(1), "loaded");
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_HASINCLUDE);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_HASINCLUDE);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews * Apply update log, if any, on initial load.
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews ! DNS_ZONE_OPTION(zone, DNS_ZONEOPT_NOMERGE) &&
a5a30ae7c0636a57d8575acb98fdf906c0ea818fMark Andrews result = dns_journal_rollforward(zone->mctx, db,
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND &&
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews result != DNS_R_UPTODATE && result != DNS_R_NOJOURNAL &&
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews "journal rollforward failed: %s",
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (result == ISC_R_NOTFOUND || result == ISC_R_RANGE) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews "journal rollforward failed: "
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews "journal out of sync with zone");
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence "journal rollforward completed "
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews "successfully: %s",
bfb2a81b65579882a80855c279cedc45aebd62e8Mark Andrews * Obtain ns and soa counts for top of zone.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = zone_get_from_db(db, &zone->origin, &nscount,
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt "could not find NS and/or SOA records");
7712d1660a308ec3de17f1ddbbf801eb0d663f3eEvan Hunt * Master / Slave / Stub zones require both NS and SOA records at
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont * the top of the zone.
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont "has no NS records");
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont "zone serial has gone backwards");
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont zone->expire = RANGE(expire, zone->refresh + zone->retry,
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_HAVETIMERS);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont result = isc_file_getmodtime(zone->journal, &t);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont result = isc_file_getmodtime(zone->masterfile,
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont /* destroy notification example. */
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont isc_event_t *e = isc_event_allocate(zone->mctx, NULL,
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont dns_zone_log(zone, ISC_LOG_INFO, "loaded serial %u", zone->serial);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont zone_saveunique(zone, zone->journal, "jn-XXXXXXXX");
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont zone_saveunique(zone, zone->masterfile, "db-XXXXXXXX");
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont /* Mark the zone for immediate refresh. */
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_SHUTDOWN) &&
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * DNS_ZONEFLG_SHUTDOWN can only be set if erefs == 0.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews INSIST(isc_refcount_current(&zone->erefs) == 0);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewszone_count_ns_rr(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int *nscount)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int count;
38b84a1fcfdbda4d1d0fdca409004ae83be2ace8Mark Andrews result = dns_db_findrdataset(db, node, version, dns_rdatatype_ns,
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellingtonzone_load_soa_rr(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington unsigned int *soacount,
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington isc_uint32_t *serial, isc_uint32_t *refresh,
26b0f58b6c4d65bc8b131debf40b8c376c2978bfBob Halley result = dns_db_findrdataset(db, node, version, dns_rdatatype_soa,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = dns_rdata_tostruct(&rdata, &soa, NULL);
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson * zone must be locked.
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafssonzone_get_from_db(dns_db_t *db, dns_name_t *origin, unsigned int *nscount,
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafsson unsigned int *soacount, isc_uint32_t *serial,
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafsson isc_uint32_t *refresh, isc_uint32_t *retry,
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafsson isc_uint32_t *expire, isc_uint32_t *minimum)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_db_findnode(db, origin, ISC_FALSE, &node);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = zone_count_ns_rr(db, node, version, nscount);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (soacount != NULL || serial != NULL || refresh != NULL
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews || retry != NULL || expire != NULL || minimum != NULL) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = zone_load_soa_rr(db, node, version, soacount,
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson dns_db_closeversion(db, &version, ISC_FALSE);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsdns_zone_attach(dns_zone_t *source, dns_zone_t **target) {
7e9d637131516486630290d36c4c0db544cb700eMark Andrews unsigned int refs;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff REQUIRE(zonep != NULL && DNS_ZONE_VALID(*zonep));
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence * We just detached the last external reference.
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence * This zone is being managed. Post
cbef026164ceabccb2e85403434b722d77f7b5eeMark Andrews * its control event and let it clean
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * up synchronously in the context of
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence * This zone is not being managed; it has
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence * no task and can have no outstanding
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence * events. Free it immediately.
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence * Unmanaged zones should not have non-null views;
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrews * we have no way of detaching from the view here
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrews * without causing deadlock because this code is called
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrews * with the view already locked.
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrewsdns_zone_iattach(dns_zone_t *source, dns_zone_t **target) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrewszone_iattach(dns_zone_t *source, dns_zone_t **target) {
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrews * 'source' locked by caller.
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews INSIST(source->irefs + isc_refcount_current(&source->erefs) > 0);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff * 'zone' locked by caller.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence REQUIRE(zonep != NULL && DNS_ZONE_VALID(*zonep));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews INSIST(zone->irefs + isc_refcount_current(&zone->erefs) > 0);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews REQUIRE(zonep != NULL && DNS_ZONE_VALID(*zonep));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrewsdns_zone_setflag(dns_zone_t *zone, unsigned int flags, isc_boolean_t value) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrewsdns_zone_setoption(dns_zone_t *zone, unsigned int option, isc_boolean_t value)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrewsdns_zone_setxfrsource4(dns_zone_t *zone, isc_sockaddr_t *xfrsource) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrewsdns_zone_setxfrsource6(dns_zone_t *zone, isc_sockaddr_t *xfrsource) {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencedns_zone_setnotifysrc4(dns_zone_t *zone, isc_sockaddr_t *notifysrc) {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencedns_zone_setnotifysrc6(dns_zone_t *zone, isc_sockaddr_t *notifysrc) {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencedns_zone_setalsonotify(dns_zone_t *zone, isc_sockaddr_t *notify,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews new = isc_mem_get(zone->mctx, count * sizeof *new);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencedns_zone_setmasters(dns_zone_t *zone, isc_sockaddr_t *masters,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews result = dns_zone_setmasterswithkeys(zone, masters, NULL, count);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrewsdns_zone_setmasterswithkeys(dns_zone_t *zone, isc_sockaddr_t *masters,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews unsigned int i;
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson isc_mem_put(zone->mctx, zone->masterkeynames,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * If count == 0, don't allocate any space for masters or keynames
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * so internally, those pointers are NULL if count == 0
806c235ecf533b98d068b3f8df9d7abbe1e30cf9Mark Andrews * masters must countain count elements!
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_NOMASTERS);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews * if keynames is non-NULL, it must contain count elements!
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews for (i = 0; i < count; i++)
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews for (i = 0; i < count; i++) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews for (i = 0; i < count; i++)
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updaterdns_zone_getdb(dns_zone_t *zone, dns_db_t **dpb) {
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews * Co-ordinates the starting of routine jobs.
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews dumping = DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DUMPING);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Configuring the view of this zone may have
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff * failed, for example because the config file
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff * had a syntax error. In that case, the view
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff * adb or resolver, and we had better not try
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff * to do maintenance on it.
ebd68da027cfa8da0fb536c3db11bb88292f41c7Andreas Gustafsson if (zone->view == NULL || zone->view->adb == NULL)
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff * Expire check.
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff if (isc_time_compare(&now, &zone->expiretime) >= 0 &&
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews * Up to date check.
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews if (!DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DIALREFRESH) &&
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews isc_time_compare(&now, &zone->refreshtime) >= 0)
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff * Do we need to consolidate the backing store?
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff isc_time_compare(&now, &zone->dumptime) >= 0 &&
b469f0321d2bcea3914c57d26fd43319e506c313Andreas Gustafsson DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NEEDDUMP)) {
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff result = zone_dump(zone, ISC_TRUE); /* task locked */
b469f0321d2bcea3914c57d26fd43319e506c313Andreas Gustafsson "dump failed: %s",
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * Do we need to send out notify messages?
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NEEDNOTIFY))
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * 'zone' locked by caller.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 dns_zone_log(zone, ISC_LOG_WARNING, "expired");
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_EXPIRED);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_HAVETIMERS);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_NEEDDUMP);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_EXITING))
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * Set DNS_ZONEFLG_REFRESH so that there is only one refresh operation
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * in progress at a time.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_NOMASTERS);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 if ((oldflags & DNS_ZONEFLG_NOMASTERS) == 0)
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 "cannot refresh: no masters");
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_REFRESH);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_NOEDNS);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 if ((oldflags & (DNS_ZONEFLG_REFRESH|DNS_ZONEFLG_LOADING)) != 0)
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * Set the next refresh time as if refresh check has failed.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * Setting this to the retry time will do that. XXXMLG
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * If we are successful it will be reset using zone->refresh.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 isc_interval_set(&i, isc_random_jitter(zone->retry, zone->retry / 4),
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 isc_time_nowplusinterval(&zone->refreshtime, &i);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * When lacking user-specified timer values from the SOA,
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * do exponential backoff of the retry time up to a
if (!dumping)
return (result);
if (!dumping)
return (result);
switch (tresult) {
case ISC_R_SUCCESS:
case ISC_R_NOSPACE:
case ISC_R_NOTFOUND:
if (again)
static isc_result_t
redo:
goto fail;
goto fail;
if (compact) {
fail:
if (again)
goto redo;
return (result);
return (DNS_R_NOTLOADED);
return (result);
static isc_boolean_t
return (ISC_TRUE);
return (ISC_TRUE);
return (ISC_FALSE);
if (!locked)
if (!locked)
if (locked)
static isc_result_t
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
unsigned int options;
goto destroy;
goto destroy;
static isc_result_t
isc_event_t *e;
if (e == NULL)
return (ISC_R_NOMEMORY);
isc_event_free(&e);
return (result);
int timeout;
goto cleanup;
goto cleanup;
addrbuf);
goto cleanup;
goto cleanup;
addrbuf);
case PF_INET:
case PF_INET6:
goto cleanup_key;
&new);
goto cleanup;
goto cleanup;
unsigned int flags = 0;
goto cleanup1;
goto cleanup2;
goto cleanup3;
goto cleanup3;
if (!loggednotify) {
serial);
if (isqueued) {
static inline isc_result_t
goto fail;
goto fail;
goto fail;
&rdataset);
goto fail;
goto fail;
&rdataset);
goto fail;
goto fail;
&rdataset);
goto fail;
goto fail;
goto fail;
return (ISC_R_SUCCESS);
fail:
return (result);
goto next_master;
goto same_master;
goto next_master;
goto next_master;
goto next_master;
goto same_master;
goto next_master;
master);
goto next_master;
goto same_master;
master);
goto next_master;
if (cnamecnt != 0) {
goto next_master;
if (nscnt == 0) {
goto next_master;
goto next_master;
goto free_stub;
goto free_stub;
goto free_stub;
goto done;
done:
goto same_master;
master);
goto next_master;
goto next_master;
goto next_master;
master);
goto same_master;
goto next_master;
master);
goto tcp_transfer;
master);
goto next_master;
goto same_master;
goto next_master;
if (cnamecnt != 0) {
goto next_master;
goto next_master;
goto next_master;
goto next_master;
goto next_master;
goto next_master;
goto next_master;
goto next_master;
goto detach;
goto detach;
goto detach;
isc_event_t *e;
if (e == NULL) {
isc_event_free(&e);
static inline isc_result_t
&message);
goto cleanup;
goto cleanup;
goto cleanup;
return (ISC_R_SUCCESS);
return (result);
static isc_result_t
goto cleanup;
goto cleanup;
goto cleanup;
== ISC_R_SUCCESS);
return (result);
int timeout;
goto cleanup;
goto cleanup;
DNS_REQUESTOPT_TCP : 0;
case PF_INET:
case PF_INET6:
goto cleanup;
goto cleanup;
if (cancel)
int timeout;
goto cleanup;
goto cleanup;
&node);
goto cleanup;
goto cleanup;
case PF_INET:
case PF_INET6:
goto cleanup;
goto cleanup;
goto unlock;
if (free_needed)
case dns_zone_master:
case dns_zone_slave:
case dns_zone_stub:
static isc_result_t
isc_region_t r;
&message);
return (result);
goto cleanup;
goto cleanup;
goto done;
goto soa_cleanup;
goto soa_cleanup;
goto soa_cleanup;
goto soa_cleanup;
goto soa_cleanup;
NULL);
goto soa_cleanup;
goto soa_cleanup;
goto soa_cleanup;
isc_buffer_usedregion(b, &r);
goto soa_cleanup;
goto soa_cleanup;
done:
return (ISC_R_SUCCESS);
return (result);
int match = 0;
return (DNS_R_FORMERR);
return (DNS_R_NOTIMP);
return (ISC_R_SUCCESS);
match > 0)
return (DNS_R_REFUSED);
&rdataset);
fromtext);
return (ISC_R_SUCCESS);
fromtext);
return (ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
const char *fmt, ...)
int count = 0;
count++;
return (count);
if (idlein == 0)
return (result);
static isc_result_t
goto fail;
if (dump)
goto fail;
return (ISC_R_SUCCESS);
fail:
return (result);
unsigned int soacount;
unsigned int nscount;
switch (result) {
case ISC_R_SUCCESS:
case DNS_R_UPTODATE:
goto same_master;
&now);
nscount = 0;
soacount = 0;
if (nscount == 0)
case DNS_R_BADIXFR:
goto same_master;
goto cleanup;
static isc_result_t
return (ISC_R_NOMORE);
case PF_INET:
case PF_INET6:
goto unlock;
return (result);
goto next_master;
goto next_master;
goto next_master;
case dns_rcode_noerror:
case dns_rcode_yxdomain:
case dns_rcode_yxrrset:
case dns_rcode_nxrrset:
case dns_rcode_refused:
case dns_rcode_nxdomain:
case dns_rcode_notzone:
case dns_rcode_notauth: {
goto next_master;
case dns_rcode_formerr:
case dns_rcode_servfail:
case dns_rcode_notimp:
case dns_rcode_badvers:
goto next_master;
return (ISC_R_NOMEMORY);
goto cleanup;
goto cleanup;
goto cleanup;
return (result);
return (ISC_R_NOMORE);
return (ISC_R_SUCCESS);
return (ISC_R_NOMORE);
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
goto free_mem;
goto free_rwlock;
goto free_taskpool;
goto free_task;
goto free_rl;
return (ISC_R_SUCCESS);
return (result);
goto cleanup_task;
goto unlock;
return (result);
if (free_now)
if (free_now)
dns_zone_t *p;
p != NULL;
return (ISC_R_SUCCESS);
static isc_result_t
dns_zone_t *x;
isc_event_t *e;
x != NULL;
nxfrsin++;
nxfrsperns++;
return (ISC_R_QUOTA);
return (ISC_R_QUOTA);
sizeof(isc_event_t));
if (e == NULL)
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
static isc_result_t
return (ISC_R_NOMEMORY);
return (ISC_R_NOMEMORY);
if (queue) {
if (!queue) {
return (ISC_R_SUCCESS);
if (send_event) {
char *buf;
int buflen;
goto cleanup;
goto cleanup;
if (value == 0)
ns = 0;
if (on) {
goto done;
goto done;
done:
return (result);
switch (dialup) {
case dns_dialuptype_no:
case dns_dialuptype_yes:
case dns_dialuptype_notify:
case dns_dialuptype_refresh:
case dns_dialuptype_passive:
INSIST(0);
return (result);
unsigned int count = 0;
switch (state) {
count++;
count++;
case DNS_ZONESTATE_SOAQUERY:
count++;
case DNS_ZONESTATE_ANY:
count++;
INSIST(0);
return (count);