4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson/*
93ca8abdf86dfe69d40c0bc5389151e0672780afTinderbox User * Copyright (C) 1999-2018 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
f30785f506a522ed6a5e394af2bb13b6f883927eEvan Hunt/* $Id: update.c,v 1.199 2011/12/22 07:32:40 each Exp $ */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson#include <config.h>
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
92f60809e854ccf5f115883c6347e370da048848Mark Andrews#include <isc/netaddr.h>
a1cfa2a82dcde6906b3debef82f24527141cab2eAndreas Gustafsson#include <isc/print.h>
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews#include <isc/serial.h>
d9059b0c38bd630c367d81424d72b1308cd74b04Tatuya JINMEI 神明達哉#include <isc/stats.h>
8a47ea1dadd3b985f5266f198423e01e225e218dDavid Lawrence#include <isc/string.h>
999ae80184e3df1016ac74514124b0459ace4d01Andreas Gustafsson#include <isc/taskpool.h>
66c41c5b4ff384aae100772a3f2d722391202f63Andreas Gustafsson#include <isc/util.h>
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
d60f5b9bc8c1e1f7ddebc6c7834f7550a8e8be6fBob Halley#include <dns/db.h>
d60f5b9bc8c1e1f7ddebc6c7834f7550a8e8be6fBob Halley#include <dns/dbiterator.h>
911ed0d3bee586b3bec42cb6c376d5cc6c0e1e24Brian Wellington#include <dns/diff.h>
d60f5b9bc8c1e1f7ddebc6c7834f7550a8e8be6fBob Halley#include <dns/dnssec.h>
d60f5b9bc8c1e1f7ddebc6c7834f7550a8e8be6fBob Halley#include <dns/events.h>
4bf54f182d5ac0bde48800af9000801cbc39ee15Brian Wellington#include <dns/fixedname.h>
d60f5b9bc8c1e1f7ddebc6c7834f7550a8e8be6fBob Halley#include <dns/journal.h>
59d84d1b077678cb77f6cbcc53d8cfa60ff69cb7Mark Andrews#include <dns/keyvalues.h>
d60f5b9bc8c1e1f7ddebc6c7834f7550a8e8be6fBob Halley#include <dns/message.h>
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews#include <dns/nsec.h>
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews#include <dns/nsec3.h>
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews#include <dns/private.h>
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson#include <dns/rdataclass.h>
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson#include <dns/rdataset.h>
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson#include <dns/rdatasetiter.h>
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews#include <dns/rdatastruct.h>
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews#include <dns/rdatatype.h>
4f367742735b9578ce1b61ec8b01811f7baa5fd9David Lawrence#include <dns/soa.h>
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington#include <dns/ssu.h>
71bd858d8ed62672e7c23999dc7c02fd16a55089Evan Hunt#include <dns/tsig.h>
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews#include <dns/update.h>
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson#include <dns/view.h>
d60f5b9bc8c1e1f7ddebc6c7834f7550a8e8be6fBob Halley#include <dns/zone.h>
d60f5b9bc8c1e1f7ddebc6c7834f7550a8e8be6fBob Halley#include <dns/zt.h>
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson#include <named/client.h>
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson#include <named/log.h>
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews#include <named/server.h>
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafsson#include <named/update.h>
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*! \file
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \brief
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * This module implements dynamic update as in RFC2136.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson/*
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews * XXX TODO:
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews * - document strict minimality
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson/**************************************************************************/
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson * Log level for tracing dynamic update protocol requests.
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson */
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson#define LOGLEVEL_PROTOCOL ISC_LOG_INFO
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson * Log level for low-level debug tracing.
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson */
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews#define LOGLEVEL_DEBUG ISC_LOG_DEBUG(8)
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson * Check an operation for failure. These macros all assume that
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson * the function using them has a 'result' variable and a 'failure'
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson * label.
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson */
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson#define CHECK(op) \
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews do { result = (op); \
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews if (result != ISC_R_SUCCESS) goto failure; \
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson } while (0)
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson * Fail unconditionally with result 'code', which must not
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff * be ISC_R_SUCCESS. The reason for failure presumably has
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson * been logged already.
f2fdfe7c42f3b10f3653f851ce5a0a90ee5ac1f9David Lawrence *
f2fdfe7c42f3b10f3653f851ce5a0a90ee5ac1f9David Lawrence * The test against ISC_R_SUCCESS is there to keep the Solaris compiler
f2fdfe7c42f3b10f3653f851ce5a0a90ee5ac1f9David Lawrence * from complaining about "end-of-loop code not reached".
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson */
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson#define FAIL(code) \
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson do { \
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson result = (code); \
553727079c69cacf56aaa8fd2722d04bfbbc8ce1David Lawrence if (result != ISC_R_SUCCESS) goto failure; \
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson } while (0)
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson * Fail unconditionally and log as a client error.
f2fdfe7c42f3b10f3653f851ce5a0a90ee5ac1f9David Lawrence * The test against ISC_R_SUCCESS is there to keep the Solaris compiler
f2fdfe7c42f3b10f3653f851ce5a0a90ee5ac1f9David Lawrence * from complaining about "end-of-loop code not reached".
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson */
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson#define FAILC(code, msg) \
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson do { \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews const char *_what = "failed"; \
ea398d3eba82ec4d18a636e4e6e9e120e337dad2Andreas Gustafsson result = (code); \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews switch (result) { \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews case DNS_R_NXDOMAIN: \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews case DNS_R_YXDOMAIN: \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews case DNS_R_YXRRSET: \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews case DNS_R_NXRRSET: \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews _what = "unsuccessful"; \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews } \
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews update_log(client, zone, LOGLEVEL_PROTOCOL, \
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews "update %s: %s (%s)", _what, \
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews msg, isc_result_totext(result)); \
94296c8d5b9c3c1ed13cf91c1f7b1d76d7fa0607David Lawrence if (result != ISC_R_SUCCESS) goto failure; \
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson } while (0)
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews#define PREREQFAILC(code, msg) \
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews do { \
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(zone, dns_nsstatscounter_updatebadprereq); \
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews FAILC(code, msg); \
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews } while (0)
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews#define FAILN(code, name, msg) \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews do { \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews const char *_what = "failed"; \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews result = (code); \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews switch (result) { \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews case DNS_R_NXDOMAIN: \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews case DNS_R_YXDOMAIN: \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews case DNS_R_YXRRSET: \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews case DNS_R_NXRRSET: \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews _what = "unsuccessful"; \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews } \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews if (isc_log_wouldlog(ns_g_lctx, LOGLEVEL_PROTOCOL)) { \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews char _nbuf[DNS_NAME_FORMATSIZE]; \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews dns_name_format(name, _nbuf, sizeof(_nbuf)); \
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews update_log(client, zone, LOGLEVEL_PROTOCOL, \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews "update %s: %s: %s (%s)", _what, _nbuf, \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews msg, isc_result_totext(result)); \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews } \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews if (result != ISC_R_SUCCESS) goto failure; \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews } while (0)
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews#define PREREQFAILN(code, name, msg) \
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews do { \
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(zone, dns_nsstatscounter_updatebadprereq); \
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews FAILN(code, name, msg); \
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews } while (0)
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews#define FAILNT(code, name, type, msg) \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews do { \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews const char *_what = "failed"; \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews result = (code); \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews switch (result) { \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews case DNS_R_NXDOMAIN: \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews case DNS_R_YXDOMAIN: \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews case DNS_R_YXRRSET: \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews case DNS_R_NXRRSET: \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews _what = "unsuccessful"; \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews } \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews if (isc_log_wouldlog(ns_g_lctx, LOGLEVEL_PROTOCOL)) { \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews char _nbuf[DNS_NAME_FORMATSIZE]; \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews char _tbuf[DNS_RDATATYPE_FORMATSIZE]; \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews dns_name_format(name, _nbuf, sizeof(_nbuf)); \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews dns_rdatatype_format(type, _tbuf, sizeof(_tbuf)); \
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews update_log(client, zone, LOGLEVEL_PROTOCOL, \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews "update %s: %s/%s: %s (%s)", \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews _what, _nbuf, _tbuf, msg, \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews isc_result_totext(result)); \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews } \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews if (result != ISC_R_SUCCESS) goto failure; \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews } while (0)
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews#define PREREQFAILNT(code, name, type, msg) \
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews do { \
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(zone, dns_nsstatscounter_updatebadprereq); \
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews FAILNT(code, name, type, msg); \
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews } while (0)
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson * Fail unconditionally and log as a server error.
f2fdfe7c42f3b10f3653f851ce5a0a90ee5ac1f9David Lawrence * The test against ISC_R_SUCCESS is there to keep the Solaris compiler
f2fdfe7c42f3b10f3653f851ce5a0a90ee5ac1f9David Lawrence * from complaining about "end-of-loop code not reached".
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson */
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson#define FAILS(code, msg) \
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson do { \
ea398d3eba82ec4d18a636e4e6e9e120e337dad2Andreas Gustafsson result = (code); \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews update_log(client, zone, LOGLEVEL_PROTOCOL, \
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews "error: %s: %s", \
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews msg, isc_result_totext(result)); \
94296c8d5b9c3c1ed13cf91c1f7b1d76d7fa0607David Lawrence if (result != ISC_R_SUCCESS) goto failure; \
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson } while (0)
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson
92f60809e854ccf5f115883c6347e370da048848Mark Andrews/*
b9d48991211415094ed6ea92d2084422104c6787Francis Dupont * Return TRUE if NS_CLIENTATTR_TCP is set in the attributes other FALSE.
92f60809e854ccf5f115883c6347e370da048848Mark Andrews */
92f60809e854ccf5f115883c6347e370da048848Mark Andrews#define TCPCLIENT(client) (((client)->attributes & NS_CLIENTATTR_TCP) != 0)
92f60809e854ccf5f115883c6347e370da048848Mark Andrews
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson/**************************************************************************/
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssontypedef struct rr rr_t;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssonstruct rr {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /* dns_name_t name; */
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews isc_uint32_t ttl;
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews dns_rdata_t rdata;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson};
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafssontypedef struct update_event update_event_t;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafssonstruct update_event {
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson ISC_EVENT_COMMON(update_event_t);
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews dns_zone_t *zone;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_result_t result;
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews dns_message_t *answer;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson};
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews/*%
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews * Prepare an RR for the addition of the new RR 'ctx->update_rr',
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews * with TTL 'ctx->update_rr_ttl', to its rdataset, by deleting
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews * the RRs if it is replaced by the new RR or has a conflicting TTL.
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews * The necessary changes are appended to ctx->del_diff and ctx->add_diff;
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews * we need to do all deletions before any additions so that we don't run
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews * into transient states with conflicting TTLs.
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews */
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrewstypedef struct {
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews dns_db_t *db;
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews dns_dbversion_t *ver;
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews dns_diff_t *diff;
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews dns_name_t *name;
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews dns_name_t *oldname;
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews dns_rdata_t *update_rr;
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews dns_ttl_t update_rr_ttl;
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews isc_boolean_t ignore_add;
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews dns_diff_t del_diff;
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews dns_diff_t add_diff;
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews} add_rr_prepare_ctx_t;
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson/**************************************************************************/
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson/*
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson * Forward declarations.
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson */
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafssonstatic void update_action(isc_task_t *task, isc_event_t *event);
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafssonstatic void updatedone_action(isc_task_t *task, isc_event_t *event);
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrewsstatic isc_result_t send_forward_event(ns_client_t *client, dns_zone_t *zone);
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrewsstatic void forward_done(isc_task_t *task, isc_event_t *event);
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrewsstatic isc_result_t add_rr_prepare_action(void *data, rr_t *rr);
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson/**************************************************************************/
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson
ec52edeff21c45e1469c2a74d78632e7d6fb0b52Andreas Gustafssonstatic void
ec52edeff21c45e1469c2a74d78632e7d6fb0b52Andreas Gustafssonupdate_log(ns_client_t *client, dns_zone_t *zone,
ec52edeff21c45e1469c2a74d78632e7d6fb0b52Andreas Gustafsson int level, const char *fmt, ...) ISC_FORMAT_PRINTF(4, 5);
ec52edeff21c45e1469c2a74d78632e7d6fb0b52Andreas Gustafsson
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafssonstatic void
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafssonupdate_log(ns_client_t *client, dns_zone_t *zone,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson int level, const char *fmt, ...)
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson{
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson va_list ap;
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson char message[4096];
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson char namebuf[DNS_NAME_FORMATSIZE];
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson char classbuf[DNS_RDATACLASS_FORMATSIZE];
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson if (client == NULL || zone == NULL)
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson return;
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson if (isc_log_wouldlog(ns_g_lctx, level) == ISC_FALSE)
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson return;
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson dns_name_format(dns_zone_getorigin(zone), namebuf,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson sizeof(namebuf));
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson dns_rdataclass_format(dns_zone_getclass(zone), classbuf,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson sizeof(classbuf));
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson va_start(ap, fmt);
2f734e0a7e518c89c2b2b179714b8885b7626b3aAndreas Gustafsson vsnprintf(message, sizeof(message), fmt, ap);
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson va_end(ap);
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson ns_client_log(client, NS_LOGCATEGORY_UPDATE, NS_LOGMODULE_UPDATE,
55b62439233d930152690b9eba97b06d9dc13d23Mark Andrews level, "updating zone '%s/%s': %s",
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson namebuf, classbuf, message);
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson}
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrewsstatic void
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrewsupdate_log_cb(void *arg, dns_zone_t *zone, int level, const char *message) {
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews update_log(arg, zone, level, "%s", message);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews}
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews/*%
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews * Increment updated-related statistics counters.
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews */
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrewsstatic inline void
d9059b0c38bd630c367d81424d72b1308cd74b04Tatuya JINMEI 神明達哉inc_stats(dns_zone_t *zone, isc_statscounter_t counter) {
d9059b0c38bd630c367d81424d72b1308cd74b04Tatuya JINMEI 神明達哉 isc_stats_increment(ns_g_server->nsstats, counter);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews if (zone != NULL) {
d9059b0c38bd630c367d81424d72b1308cd74b04Tatuya JINMEI 神明達哉 isc_stats_t *zonestats = dns_zone_getrequeststats(zone);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews if (zonestats != NULL)
d9059b0c38bd630c367d81424d72b1308cd74b04Tatuya JINMEI 神明達哉 isc_stats_increment(zonestats, counter);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews }
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews}
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews/*%
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews * Check if we could have queried for the contents of this zone or
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews * if the zone is potentially updateable.
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews * If the zone can potentially be updated and the check failed then
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews * log a error otherwise we log a informational message.
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews */
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrewsstatic isc_result_t
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrewscheckqueryacl(ns_client_t *client, dns_acl_t *queryacl, dns_name_t *zonename,
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews dns_acl_t *updateacl, dns_ssutable_t *ssutable)
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews{
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews char namebuf[DNS_NAME_FORMATSIZE];
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews char classbuf[DNS_RDATACLASS_FORMATSIZE];
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews int level;
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews isc_result_t result;
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews result = ns_client_checkaclsilent(client, NULL, queryacl, ISC_TRUE);
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews if (result != ISC_R_SUCCESS) {
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews dns_name_format(zonename, namebuf, sizeof(namebuf));
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews dns_rdataclass_format(client->view->rdclass, classbuf,
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews sizeof(classbuf));
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews level = (updateacl == NULL && ssutable == NULL) ?
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews ISC_LOG_INFO : ISC_LOG_ERROR;
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews ns_client_log(client, NS_LOGCATEGORY_UPDATE_SECURITY,
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews NS_LOGMODULE_UPDATE, level,
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews "update '%s/%s' denied due to allow-query",
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews namebuf, classbuf);
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews } else if (updateacl == NULL && ssutable == NULL) {
e2facd7af296d90d0d1fef7994b6b8e795490a92Evan Hunt dns_name_format(zonename, namebuf, sizeof(namebuf));
e2facd7af296d90d0d1fef7994b6b8e795490a92Evan Hunt dns_rdataclass_format(client->view->rdclass, classbuf,
e2facd7af296d90d0d1fef7994b6b8e795490a92Evan Hunt sizeof(classbuf));
e2facd7af296d90d0d1fef7994b6b8e795490a92Evan Hunt
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews result = DNS_R_REFUSED;
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews ns_client_log(client, NS_LOGCATEGORY_UPDATE_SECURITY,
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews NS_LOGMODULE_UPDATE, ISC_LOG_INFO,
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews "update '%s/%s' denied", namebuf, classbuf);
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews }
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews return (result);
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews}
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews/*%
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews * Override the default acl logging when checking whether a client
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews * can update the zone or whether we can forward the request to the
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews * master based on IP address.
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews *
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews * 'message' contains the type of operation that is being attempted.
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews * 'slave' indicates if this is a slave zone. If 'acl' is NULL then
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews * log at debug=3.
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews * If the zone has no access controls configured ('acl' == NULL &&
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews * 'has_ssutable == ISC_FALS) log the attempt at info, otherwise
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews * at error.
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews *
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews * If the request was signed log that we received it.
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews */
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrewsstatic isc_result_t
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrewscheckupdateacl(ns_client_t *client, dns_acl_t *acl, const char *message,
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews dns_name_t *zonename, isc_boolean_t slave,
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews isc_boolean_t has_ssutable)
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews{
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews char namebuf[DNS_NAME_FORMATSIZE];
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews char classbuf[DNS_RDATACLASS_FORMATSIZE];
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews int level = ISC_LOG_ERROR;
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews const char *msg = "denied";
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews isc_result_t result;
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews
18afcb70285f2204b1586c351dd4af0a01d33f75Mark Andrews if (slave && acl == NULL) {
18afcb70285f2204b1586c351dd4af0a01d33f75Mark Andrews result = DNS_R_NOTIMP;
18afcb70285f2204b1586c351dd4af0a01d33f75Mark Andrews level = ISC_LOG_DEBUG(3);
18afcb70285f2204b1586c351dd4af0a01d33f75Mark Andrews msg = "disabled";
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews } else {
819b98479eff49ed93f57f4d65eb0ffe72136adcMark Andrews result = ns_client_checkaclsilent(client, NULL, acl, ISC_FALSE);
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews if (result == ISC_R_SUCCESS) {
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews level = ISC_LOG_DEBUG(3);
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews msg = "approved";
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews } else if (acl == NULL && !has_ssutable) {
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews level = ISC_LOG_INFO;
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews }
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews }
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews if (client->signer != NULL) {
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews dns_name_format(client->signer, namebuf, sizeof(namebuf));
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews ns_client_log(client, NS_LOGCATEGORY_UPDATE_SECURITY,
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews NS_LOGMODULE_UPDATE, ISC_LOG_INFO,
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews "signer \"%s\" %s", namebuf, msg);
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews }
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews dns_name_format(zonename, namebuf, sizeof(namebuf));
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews dns_rdataclass_format(client->view->rdclass, classbuf,
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews sizeof(classbuf));
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews ns_client_log(client, NS_LOGCATEGORY_UPDATE_SECURITY,
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews NS_LOGMODULE_UPDATE, level, "%s '%s/%s' %s",
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews message, namebuf, classbuf, msg);
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews return (result);
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews}
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Update a single RR in version 'ver' of 'db' and log the
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * update in 'diff'.
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson *
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Ensures:
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews * \li '*tuple' == NULL. Either the tuple is freed, or its
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews * ownership has been transferred to the diff.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrewsdo_one_tuple(dns_difftuple_t **tuple, dns_db_t *db, dns_dbversion_t *ver,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_diff_t *diff)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson{
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_diff_t temp_diff;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_result_t result;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence /*
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Create a singleton diff.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_diff_init(diff->mctx, &temp_diff);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson ISC_LIST_APPEND(temp_diff.tuples, *tuple, link);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence /*
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Apply it to the database.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_diff_apply(&temp_diff, db, ver);
cf573ce6fb91d8d514425849c73cdbc2096d97e1Mark Andrews ISC_LIST_UNLINK(temp_diff.tuples, *tuple, link);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_difftuple_free(tuple);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (result);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence /*
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Merge it into the current pending journal entry.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_diff_appendminimal(diff, tuple);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence /*
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Do not clear temp_diff.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson * Perform the updates in 'updates' in version 'ver' of 'db' and log the
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson * update in 'diff'.
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson *
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson * Ensures:
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews * \li 'updates' is empty.
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson */
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafssonstatic isc_result_t
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafssondo_diff(dns_diff_t *updates, dns_db_t *db, dns_dbversion_t *ver,
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson dns_diff_t *diff)
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson{
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson isc_result_t result;
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson while (! ISC_LIST_EMPTY(updates->tuples)) {
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson dns_difftuple_t *t = ISC_LIST_HEAD(updates->tuples);
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson ISC_LIST_UNLINK(updates->tuples, t, link);
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson CHECK(do_one_tuple(&t, db, ver, diff));
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson }
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson return (ISC_R_SUCCESS);
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson failure:
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson dns_diff_clear(diff);
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson return (result);
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson}
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssonupdate_one_rr(dns_db_t *db, dns_dbversion_t *ver, dns_diff_t *diff,
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews dns_diffop_t op, dns_name_t *name, dns_ttl_t ttl,
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews dns_rdata_t *rdata)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson{
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_difftuple_t *tuple = NULL;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_result_t result;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_difftuple_create(diff->mctx, op,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson name, ttl, rdata, &tuple);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (result);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (do_one_tuple(&tuple, db, ver, diff));
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson/**************************************************************************/
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson/*
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Callback-style iteration over rdatasets and rdatas.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * foreach_rrset() can be used to iterate over the RRsets
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * of a name and call a callback function with each
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * one. Similarly, foreach_rr() can be used to iterate
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * over the individual RRs at name, optionally restricted
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * to RRs of a given type.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson *
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * The callback functions are called "actions" and take
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * two arguments: a void pointer for passing arbitrary
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * context information, and a pointer to the current RRset
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * or RR. By convention, their names end in "_action".
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson/*
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * XXXRTH We might want to make this public somewhere in libdns.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Function type for foreach_rrset() iterator actions.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Grafftypedef isc_result_t rrset_func(void *data, dns_rdataset_t *rrset);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Function type for foreach_rr() iterator actions.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Grafftypedef isc_result_t rr_func(void *data, rr_t *rr);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Internal context struct for foreach_node_rr().
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssontypedef struct {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson rr_func * rr_action;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson void * rr_action_data;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson} foreach_node_rr_ctx_t;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Internal helper function for foreach_node_rr().
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrenceforeach_node_rr_action(void *data, dns_rdataset_t *rdataset) {
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_result_t result;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson foreach_node_rr_ctx_t *ctx = data;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson for (result = dns_rdataset_first(rdataset);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff result == ISC_R_SUCCESS;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_rdataset_next(rdataset))
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson {
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews rr_t rr = { 0, DNS_RDATA_INIT };
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdataset_current(rdataset, &rr.rdata);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson rr.ttl = rdataset->ttl;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = (*ctx->rr_action)(ctx->rr_action_data, &rr);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (result);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_NOMORE)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (result);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * For each rdataset of 'name' in 'ver' of 'db', call 'action'
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * with the rdataset and 'action_data' as arguments. If the name
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * does not exist, do nothing.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson *
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * If 'action' returns an error, abort iteration and return the error.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrewsforeach_rrset(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name,
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews rrset_func *action, void *action_data)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson{
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_result_t result;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_dbnode_t *node;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdatasetiter_t *iter;
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt dns_clientinfomethods_t cm;
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt dns_clientinfo_t ci;
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt dns_dbversion_t *oldver = NULL;
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt dns_clientinfomethods_init(&cm, ns_client_sourceip);
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt /*
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt * Only set the clientinfo 'versionp' if the new version is
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt * different from the current version
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt */
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt dns_db_currentversion(db, &oldver);
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt dns_clientinfo_init(&ci, NULL, (ver != oldver) ? ver : NULL);
f4f70bf596b10acbb7fb0bf0bdbe4d6637e23e36Mark Andrews dns_db_closeversion(db, &oldver, ISC_FALSE);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson node = NULL;
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt result = dns_db_findnodeext(db, name, ISC_FALSE, &cm, &ci, &node);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result == ISC_R_NOTFOUND)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (result);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson iter = NULL;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_db_allrdatasets(db, node, ver,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson (isc_stdtime_t) 0, &iter);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson goto cleanup_node;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson for (result = dns_rdatasetiter_first(iter);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff result == ISC_R_SUCCESS;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_rdatasetiter_next(iter))
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdataset_t rdataset;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdataset_init(&rdataset);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdatasetiter_current(iter, &rdataset);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = (*action)(action_data, &rdataset);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdataset_disassociate(&rdataset);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson goto cleanup_iterator;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result == ISC_R_NOMORE)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff result = ISC_R_SUCCESS;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson cleanup_iterator:
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdatasetiter_destroy(&iter);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson cleanup_node:
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_db_detachnode(db, &node);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (result);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * For each RR of 'name' in 'ver' of 'db', call 'action'
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * with the RR and 'action_data' as arguments. If the name
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * does not exist, do nothing.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson *
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * If 'action' returns an error, abort iteration
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * and return the error.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrewsforeach_node_rr(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name,
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews rr_func *rr_action, void *rr_action_data)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson{
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson foreach_node_rr_ctx_t ctx;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson ctx.rr_action = rr_action;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson ctx.rr_action_data = rr_action_data;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (foreach_rrset(db, ver, name,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson foreach_node_rr_action, &ctx));
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley * For each of the RRs specified by 'db', 'ver', 'name', 'type',
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley * (which can be dns_rdatatype_any to match any type), and 'covers', call
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * 'action' with the RR and 'action_data' as arguments. If the name
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * does not exist, or if no RRset of the given type exists at the name,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * do nothing.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * If 'action' returns an error, abort iteration and return the error.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrewsforeach_rr(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name,
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews dns_rdatatype_t type, dns_rdatatype_t covers, rr_func *rr_action,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson void *rr_action_data)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson{
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_result_t result;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_dbnode_t *node;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdataset_t rdataset;
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt dns_clientinfomethods_t cm;
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt dns_clientinfo_t ci;
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt dns_dbversion_t *oldver = NULL;
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews dns_fixedname_t fixed;
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt dns_clientinfomethods_init(&cm, ns_client_sourceip);
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt /*
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt * Only set the clientinfo 'versionp' if the new version is
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt * different from the current version
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt */
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt dns_db_currentversion(db, &oldver);
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt dns_clientinfo_init(&ci, NULL, (ver != oldver) ? ver : NULL);
f4f70bf596b10acbb7fb0bf0bdbe4d6637e23e36Mark Andrews dns_db_closeversion(db, &oldver, ISC_FALSE);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (type == dns_rdatatype_any)
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence return (foreach_node_rr(db, ver, name,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson rr_action, rr_action_data));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson node = NULL;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (type == dns_rdatatype_nsec3 ||
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews (type == dns_rdatatype_rrsig && covers == dns_rdatatype_nsec3))
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_db_findnsec3node(db, name, ISC_FALSE, &node);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews else
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt result = dns_db_findnodeext(db, name, ISC_FALSE,
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt &cm, &ci, &node);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result == ISC_R_NOTFOUND)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (result);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdataset_init(&rdataset);
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley result = dns_db_findrdataset(db, node, ver, type, covers,
9637357a7765cc63ae401e02c727b1202f20bc08Bob Halley (isc_stdtime_t) 0, &rdataset, NULL);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result == ISC_R_NOTFOUND) {
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff result = ISC_R_SUCCESS;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson goto cleanup_node;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson goto cleanup_node;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews if (rr_action == add_rr_prepare_action) {
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews add_rr_prepare_ctx_t *ctx = rr_action_data;
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews dns_fixedname_init(&fixed);
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews ctx->oldname = dns_fixedname_name(&fixed);
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews dns_name_copy(name, ctx->oldname, NULL);
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews dns_rdataset_getownercase(&rdataset, ctx->oldname);
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews }
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson for (result = dns_rdataset_first(&rdataset);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff result == ISC_R_SUCCESS;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_rdataset_next(&rdataset))
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson {
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews rr_t rr = { 0, DNS_RDATA_INIT };
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdataset_current(&rdataset, &rr.rdata);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson rr.ttl = rdataset.ttl;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = (*rr_action)(rr_action_data, &rr);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson goto cleanup_rdataset;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_NOMORE)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson goto cleanup_rdataset;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff result = ISC_R_SUCCESS;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson cleanup_rdataset:
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdataset_disassociate(&rdataset);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson cleanup_node:
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_db_detachnode(db, &node);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (result);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson/**************************************************************************/
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson/*
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Various tests on the database contents (for prerequisites, etc).
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Function type for predicate functions that compare a database RR 'db_rr'
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * against an update RR 'update_rr'.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssontypedef isc_boolean_t rr_predicate(dns_rdata_t *update_rr, dns_rdata_t *db_rr);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Helper function for rrset_exists().
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrencerrset_exists_action(void *data, rr_t *rr) {
66c41c5b4ff384aae100772a3f2d722391202f63Andreas Gustafsson UNUSED(data);
66c41c5b4ff384aae100772a3f2d722391202f63Andreas Gustafsson UNUSED(rr);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_EXISTS);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson * Utility macro for RR existence checking functions.
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson *
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff * If the variable 'result' has the value ISC_R_EXISTS or
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff * ISC_R_SUCCESS, set *exists to ISC_TRUE or ISC_FALSE,
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson * respectively, and return success.
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson *
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson * If 'result' has any other value, there was a failure.
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson * Return the failure result code and do not set *exists.
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson *
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson * This would be more readable as "do { if ... } while(0)",
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson * but that form generates tons of warnings on Solaris 2.6.
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson */
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews#define RETURN_EXISTENCE_FLAG \
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews return ((result == ISC_R_EXISTS) ? \
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews (*exists = ISC_TRUE, ISC_R_SUCCESS) : \
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff ((result == ISC_R_SUCCESS) ? \
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff (*exists = ISC_FALSE, ISC_R_SUCCESS) : \
046bd40fd1ce213a851cbbd6fb09be5dbaa3dcabAndreas Gustafsson result))
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Set '*exists' to true iff an rrset of the given type exists,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * to false otherwise.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrewsrrset_exists(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name,
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews dns_rdatatype_t type, dns_rdatatype_t covers,
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley isc_boolean_t *exists)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson{
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_result_t result;
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley result = foreach_rr(db, ver, name, type, covers,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson rrset_exists_action, NULL);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson RETURN_EXISTENCE_FLAG;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Helper function for cname_incompatible_rrset_exists.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrencecname_compatibility_action(void *data, dns_rdataset_t *rrset) {
66c41c5b4ff384aae100772a3f2d722391202f63Andreas Gustafsson UNUSED(data);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (rrset->type != dns_rdatatype_cname &&
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson ! dns_rdatatype_isdnssec(rrset->type))
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_EXISTS);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Check whether there is an rrset incompatible with adding a CNAME RR,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * i.e., anything but another CNAME (which can be replaced) or a
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * DNSSEC RR (which can coexist).
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson *
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * If such an incompatible rrset exists, set '*exists' to ISC_TRUE.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Otherwise, set it to ISC_FALSE.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssoncname_incompatible_rrset_exists(dns_db_t *db, dns_dbversion_t *ver,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_name_t *name, isc_boolean_t *exists) {
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence isc_result_t result;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence result = foreach_rrset(db, ver, name,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson cname_compatibility_action, NULL);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson RETURN_EXISTENCE_FLAG;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Helper function for rr_count().
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrencestatic isc_result_t
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrencecount_rr_action(void *data, rr_t *rr) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson int *countp = data;
66c41c5b4ff384aae100772a3f2d722391202f63Andreas Gustafsson UNUSED(rr);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson (*countp)++;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Count the number of RRs of 'type' belonging to 'name' in 'ver' of 'db'.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssonrr_count(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name,
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley dns_rdatatype_t type, dns_rdatatype_t covers, int *countp)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson{
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson *countp = 0;
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley return (foreach_rr(db, ver, name, type, covers,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson count_rr_action, countp));
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Context struct and helper function for name_exists().
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrencename_exists_action(void *data, dns_rdataset_t *rrset) {
66c41c5b4ff384aae100772a3f2d722391202f63Andreas Gustafsson UNUSED(data);
66c41c5b4ff384aae100772a3f2d722391202f63Andreas Gustafsson UNUSED(rrset);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_EXISTS);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Set '*exists' to true iff the given name exists, to false otherwise.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssonname_exists(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson isc_boolean_t *exists)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson{
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_result_t result;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = foreach_rrset(db, ver, name,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson name_exists_action, NULL);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson RETURN_EXISTENCE_FLAG;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
92f60809e854ccf5f115883c6347e370da048848Mark Andrews/*
b9d48991211415094ed6ea92d2084422104c6787Francis Dupont * 'ssu_check_t' is used to pass the arguments to
92f60809e854ccf5f115883c6347e370da048848Mark Andrews * dns_ssutable_checkrules() to the callback function
92f60809e854ccf5f115883c6347e370da048848Mark Andrews * ssu_checkrule().
92f60809e854ccf5f115883c6347e370da048848Mark Andrews */
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellingtontypedef struct {
92f60809e854ccf5f115883c6347e370da048848Mark Andrews /* The ownername of the record to be updated. */
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews dns_name_t *name;
92f60809e854ccf5f115883c6347e370da048848Mark Andrews
92f60809e854ccf5f115883c6347e370da048848Mark Andrews /* The signature's name if the request was signed. */
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews dns_name_t *signer;
92f60809e854ccf5f115883c6347e370da048848Mark Andrews
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt /* The address of the client. */
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt isc_netaddr_t *addr;
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt /* Whether the request was sent via TCP. */
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt isc_boolean_t tcp;
92f60809e854ccf5f115883c6347e370da048848Mark Andrews
92f60809e854ccf5f115883c6347e370da048848Mark Andrews /* The ssu table to check against. */
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington dns_ssutable_t *table;
71bd858d8ed62672e7c23999dc7c02fd16a55089Evan Hunt
71bd858d8ed62672e7c23999dc7c02fd16a55089Evan Hunt /* the key used for TKEY requests */
71bd858d8ed62672e7c23999dc7c02fd16a55089Evan Hunt dst_key_t *key;
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington} ssu_check_t;
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellingtonstatic isc_result_t
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrencessu_checkrule(void *data, dns_rdataset_t *rrset) {
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington ssu_check_t *ssuinfo = data;
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington isc_boolean_t result;
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington /*
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews * If we're deleting all records, it's ok to delete RRSIG and NSEC even
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington * if we're normally not allowed to.
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington */
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews if (rrset->type == dns_rdatatype_rrsig ||
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews rrset->type == dns_rdatatype_nsec)
6cdae8730d5a287c30987516c6f99962d4e8e6beMark Andrews return (ISC_R_SUCCESS);
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt result = dns_ssutable_checkrules2(ssuinfo->table, ssuinfo->signer,
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt ssuinfo->name, ssuinfo->addr,
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt ssuinfo->tcp, &ns_g_server->aclenv,
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt rrset->type, ssuinfo->key);
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington return (result == ISC_TRUE ? ISC_R_SUCCESS : ISC_R_FAILURE);
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington}
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellingtonstatic isc_boolean_t
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellingtonssu_checkall(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name,
92f60809e854ccf5f115883c6347e370da048848Mark Andrews dns_ssutable_t *ssutable, dns_name_t *signer,
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt isc_netaddr_t *addr, isc_boolean_t tcp, dst_key_t *key)
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington{
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington isc_result_t result;
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington ssu_check_t ssuinfo;
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington ssuinfo.name = name;
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington ssuinfo.table = ssutable;
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington ssuinfo.signer = signer;
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt ssuinfo.addr = addr;
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt ssuinfo.tcp = tcp;
71bd858d8ed62672e7c23999dc7c02fd16a55089Evan Hunt ssuinfo.key = key;
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington result = foreach_rrset(db, ver, name, ssu_checkrule, &ssuinfo);
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington return (ISC_TF(result == ISC_R_SUCCESS));
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington}
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson/**************************************************************************/
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson/*
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Checking of "RRset exists (value dependent)" prerequisites.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson *
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * In the RFC2136 section 3.2.5, this is the pseudocode involving
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * a variable called "temp", a mapping of <name, type> tuples to rrsets.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson *
b9d48991211415094ed6ea92d2084422104c6787Francis Dupont * Here, we represent the "temp" data structure as (non-minimal) "dns_diff_t"
b9d48991211415094ed6ea92d2084422104c6787Francis Dupont * where each tuple has op==DNS_DIFFOP_EXISTS.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Append a tuple asserting the existence of the RR with
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * 'name' and 'rdata' to 'diff'.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrencetemp_append(dns_diff_t *diff, dns_name_t *name, dns_rdata_t *rdata) {
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_result_t result;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_difftuple_t *tuple = NULL;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
297377a5029e71566d4158bae67f127a3e4f3fc3Bob Halley REQUIRE(DNS_DIFF_VALID(diff));
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson CHECK(dns_difftuple_create(diff->mctx, DNS_DIFFOP_EXISTS,
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews name, 0, rdata, &tuple));
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson ISC_LIST_APPEND(diff->tuples, tuple, link);
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson failure:
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson return (result);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Compare two rdatasets represented as sorted lists of tuples.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * All list elements must have the same owner name and type.
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff * Return ISC_R_SUCCESS if the rdatasets are equal, rcode(dns_rcode_nxrrset)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * if not.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrencestatic isc_result_t
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssontemp_check_rrset(dns_difftuple_t *a, dns_difftuple_t *b) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson for (;;) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (a == NULL || b == NULL)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson break;
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence INSIST(a->op == DNS_DIFFOP_EXISTS &&
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence b->op == DNS_DIFFOP_EXISTS);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson INSIST(a->rdata.type == b->rdata.type);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson INSIST(dns_name_equal(&a->name, &b->name));
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews if (dns_rdata_casecompare(&a->rdata, &b->rdata) != 0)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (DNS_R_NXRRSET);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson a = ISC_LIST_NEXT(a, link);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson b = ISC_LIST_NEXT(b, link);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (a != NULL || b != NULL)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (DNS_R_NXRRSET);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * A comparison function defining the sorting order for the entries
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * in the "temp" data structure. The major sort key is the owner name,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * followed by the type and rdata.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrencestatic int
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrencetemp_order(const void *av, const void *bv) {
efec85a561ff950be0de7aab4dab9e339f6ca4d3Brian Wellington dns_difftuple_t const * const *ap = av;
efec85a561ff950be0de7aab4dab9e339f6ca4d3Brian Wellington dns_difftuple_t const * const *bp = bv;
efec85a561ff950be0de7aab4dab9e339f6ca4d3Brian Wellington dns_difftuple_t const *a = *ap;
efec85a561ff950be0de7aab4dab9e339f6ca4d3Brian Wellington dns_difftuple_t const *b = *bp;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson int r;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson r = dns_name_compare(&a->name, &b->name);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (r != 0)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (r);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson r = (b->rdata.type - a->rdata.type);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (r != 0)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (r);
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews r = dns_rdata_casecompare(&a->rdata, &b->rdata);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (r);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Check the "RRset exists (value dependent)" prerequisite information
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * in 'temp' against the contents of the database 'db'.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson *
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff * Return ISC_R_SUCCESS if the prerequisites are satisfied,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * rcode(dns_rcode_nxrrset) if not.
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews *
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews * 'temp' must be pre-sorted.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssontemp_check(isc_mem_t *mctx, dns_diff_t *temp, dns_db_t *db,
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews dns_dbversion_t *ver, dns_name_t *tmpname, dns_rdatatype_t *typep)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson{
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_result_t result;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_name_t *name;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_dbnode_t *node;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_difftuple_t *t;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_diff_t trash;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_diff_init(mctx, &trash);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /*
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * For each name and type in the prerequisites,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * construct a sorted rdata list of the corresponding
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * database contents, and compare the lists.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson t = ISC_LIST_HEAD(temp->tuples);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson while (t != NULL) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson name = &t->name;
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews (void)dns_name_copy(name, tmpname, NULL);
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews *typep = t->rdata.type;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /* A new unique name begins here. */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson node = NULL;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_db_findnode(db, name, ISC_FALSE, &node);
dc0ecf08dbea81b6ebfcd3a18b52aa974472b1baMark Andrews if (result == ISC_R_NOTFOUND) {
dc0ecf08dbea81b6ebfcd3a18b52aa974472b1baMark Andrews dns_diff_clear(&trash);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (DNS_R_NXRRSET);
dc0ecf08dbea81b6ebfcd3a18b52aa974472b1baMark Andrews }
dc0ecf08dbea81b6ebfcd3a18b52aa974472b1baMark Andrews if (result != ISC_R_SUCCESS) {
dc0ecf08dbea81b6ebfcd3a18b52aa974472b1baMark Andrews dns_diff_clear(&trash);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (result);
dc0ecf08dbea81b6ebfcd3a18b52aa974472b1baMark Andrews }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence /* A new unique type begins here. */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson while (t != NULL && dns_name_equal(&t->name, name)) {
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley dns_rdatatype_t type, covers;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdataset_t rdataset;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_diff_t d_rrs; /* Database RRs with
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson this name and type */
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews dns_diff_t u_rrs; /* Update RRs with
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson this name and type */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews *typep = type = t->rdata.type;
38e8022ace865803bdd609c9763cd7d7ba2818dcMark Andrews if (type == dns_rdatatype_rrsig ||
38e8022ace865803bdd609c9763cd7d7ba2818dcMark Andrews type == dns_rdatatype_sig)
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley covers = dns_rdata_covers(&t->rdata);
bd190a40a85e5ed780c9c428c6261bc397059b4bMark Andrews else if (type == dns_rdatatype_any) {
bd190a40a85e5ed780c9c428c6261bc397059b4bMark Andrews dns_db_detachnode(db, &node);
bd190a40a85e5ed780c9c428c6261bc397059b4bMark Andrews dns_diff_clear(&trash);
bd190a40a85e5ed780c9c428c6261bc397059b4bMark Andrews return (DNS_R_NXRRSET);
bd190a40a85e5ed780c9c428c6261bc397059b4bMark Andrews } else
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley covers = 0;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /*
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Collect all database RRs for this name and type
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * onto d_rrs and sort them.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdataset_init(&rdataset);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_db_findrdataset(db, node, ver, type,
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley covers, (isc_stdtime_t) 0,
9637357a7765cc63ae401e02c727b1202f20bc08Bob Halley &rdataset, NULL);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_db_detachnode(db, &node);
dc0ecf08dbea81b6ebfcd3a18b52aa974472b1baMark Andrews dns_diff_clear(&trash);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (DNS_R_NXRRSET);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_diff_init(mctx, &d_rrs);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_diff_init(mctx, &u_rrs);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson for (result = dns_rdataset_first(&rdataset);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff result == ISC_R_SUCCESS;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_rdataset_next(&rdataset))
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson {
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews dns_rdata_t rdata = DNS_RDATA_INIT;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdataset_current(&rdataset, &rdata);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = temp_append(&d_rrs, name, &rdata);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson goto failure;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_NOMORE)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson goto failure;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_diff_sort(&d_rrs, temp_order);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence if (result != ISC_R_SUCCESS)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson goto failure;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /*
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Collect all update RRs for this name and type
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * onto u_rrs. No need to sort them here -
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * they are already sorted.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson while (t != NULL &&
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_name_equal(&t->name, name) &&
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson t->rdata.type == type)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_difftuple_t *next =
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson ISC_LIST_NEXT(t, link);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson ISC_LIST_UNLINK(temp->tuples, t, link);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson ISC_LIST_APPEND(u_rrs.tuples, t, link);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson t = next;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /* Compare the two sorted lists. */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = temp_check_rrset(ISC_LIST_HEAD(u_rrs.tuples),
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson ISC_LIST_HEAD(d_rrs.tuples));
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson goto failure;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /*
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * We are done with the tuples, but we can't free
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * them yet because "name" still points into one
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * of them. Move them on a temporary list.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson ISC_LIST_APPENDLIST(trash.tuples, u_rrs.tuples, link);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson ISC_LIST_APPENDLIST(trash.tuples, d_rrs.tuples, link);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdataset_disassociate(&rdataset);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson continue;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson failure:
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_diff_clear(&d_rrs);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_diff_clear(&u_rrs);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_diff_clear(&trash);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdataset_disassociate(&rdataset);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_db_detachnode(db, &node);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (result);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_db_detachnode(db, &node);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_diff_clear(&trash);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson/**************************************************************************/
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson/*
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Conditional deletion of RRs.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Context structure for delete_if().
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssontypedef struct {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson rr_predicate *predicate;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_db_t *db;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_dbversion_t *ver;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_diff_t *diff;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_name_t *name;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdata_t *update_rr;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson} conditional_delete_ctx_t;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Predicate functions for delete_if().
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
055597532db52233e80f617b8b015e8caadcb577Mark Andrews * Return true iff 'db_rr' is neither a SOA nor an NS RR nor
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * an RRSIG nor an NSEC3PARAM nor a NSEC.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssonstatic isc_boolean_t
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrencetype_not_soa_nor_ns_p(dns_rdata_t *update_rr, dns_rdata_t *db_rr) {
66c41c5b4ff384aae100772a3f2d722391202f63Andreas Gustafsson UNUSED(update_rr);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return ((db_rr->type != dns_rdatatype_soa &&
055597532db52233e80f617b8b015e8caadcb577Mark Andrews db_rr->type != dns_rdatatype_ns &&
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews db_rr->type != dns_rdatatype_nsec3param &&
055597532db52233e80f617b8b015e8caadcb577Mark Andrews db_rr->type != dns_rdatatype_rrsig &&
055597532db52233e80f617b8b015e8caadcb577Mark Andrews db_rr->type != dns_rdatatype_nsec) ?
055597532db52233e80f617b8b015e8caadcb577Mark Andrews ISC_TRUE : ISC_FALSE);
055597532db52233e80f617b8b015e8caadcb577Mark Andrews}
055597532db52233e80f617b8b015e8caadcb577Mark Andrews
fb827ed6df9a473770fb69a75a455b4ad0d14f52Mark Andrews/*%
055597532db52233e80f617b8b015e8caadcb577Mark Andrews * Return true iff 'db_rr' is neither a RRSIG nor a NSEC.
055597532db52233e80f617b8b015e8caadcb577Mark Andrews */
055597532db52233e80f617b8b015e8caadcb577Mark Andrewsstatic isc_boolean_t
055597532db52233e80f617b8b015e8caadcb577Mark Andrewstype_not_dnssec(dns_rdata_t *update_rr, dns_rdata_t *db_rr) {
055597532db52233e80f617b8b015e8caadcb577Mark Andrews UNUSED(update_rr);
055597532db52233e80f617b8b015e8caadcb577Mark Andrews return ((db_rr->type != dns_rdatatype_rrsig &&
055597532db52233e80f617b8b015e8caadcb577Mark Andrews db_rr->type != dns_rdatatype_nsec) ?
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson ISC_TRUE : ISC_FALSE);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Return true always.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssonstatic isc_boolean_t
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrencetrue_p(dns_rdata_t *update_rr, dns_rdata_t *db_rr) {
66c41c5b4ff384aae100772a3f2d722391202f63Andreas Gustafsson UNUSED(update_rr);
66c41c5b4ff384aae100772a3f2d722391202f63Andreas Gustafsson UNUSED(db_rr);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (ISC_TRUE);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Return true iff the two RRs have identical rdata.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssonstatic isc_boolean_t
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssonrr_equal_p(dns_rdata_t *update_rr, dns_rdata_t *db_rr) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /*
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * XXXRTH This is not a problem, but we should consider creating
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * dns_rdata_equal() (that used dns_name_equal()), since it
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * would be faster. Not a priority.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews return (dns_rdata_casecompare(update_rr, db_rr) == 0 ?
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson ISC_TRUE : ISC_FALSE);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Return true iff 'update_rr' should replace 'db_rr' according
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * to the special RFC2136 rules for CNAME, SOA, and WKS records.
35a1d7c80e14927d124d6ea6926cc29c64232c80Andreas Gustafsson *
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews * RFC2136 does not mention NSEC or DNAME, but multiple NSECs or DNAMEs
35a1d7c80e14927d124d6ea6926cc29c64232c80Andreas Gustafsson * make little sense, so we replace those, too.
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews *
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews * Additionally replace RRSIG that have been generated by the same key
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews * for the same type. This simplifies refreshing a offline KSK by not
b9d48991211415094ed6ea92d2084422104c6787Francis Dupont * requiring that the old RRSIG be deleted. It also simplifies key
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews * rollover by only requiring that the new RRSIG be added.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssonstatic isc_boolean_t
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssonreplaces_p(dns_rdata_t *update_rr, dns_rdata_t *db_rr) {
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews dns_rdata_rrsig_t updatesig, dbsig;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews isc_result_t result;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (db_rr->type != update_rr->type)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (ISC_FALSE);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (db_rr->type == dns_rdatatype_cname)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (ISC_TRUE);
35a1d7c80e14927d124d6ea6926cc29c64232c80Andreas Gustafsson if (db_rr->type == dns_rdatatype_dname)
35a1d7c80e14927d124d6ea6926cc29c64232c80Andreas Gustafsson return (ISC_TRUE);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (db_rr->type == dns_rdatatype_soa)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (ISC_TRUE);
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews if (db_rr->type == dns_rdatatype_nsec)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (ISC_TRUE);
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews if (db_rr->type == dns_rdatatype_rrsig) {
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews /*
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews * Replace existing RRSIG with the same keyid,
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews * covered and algorithm.
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews */
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews result = dns_rdata_tostruct(db_rr, &dbsig, NULL);
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews RUNTIME_CHECK(result == ISC_R_SUCCESS);
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews result = dns_rdata_tostruct(update_rr, &updatesig, NULL);
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews RUNTIME_CHECK(result == ISC_R_SUCCESS);
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews if (dbsig.keyid == updatesig.keyid &&
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews dbsig.covered == updatesig.covered &&
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews dbsig.algorithm == updatesig.algorithm)
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews return (ISC_TRUE);
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (db_rr->type == dns_rdatatype_wks) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /*
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Compare the address and protocol fields only. These
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * form the first five bytes of the RR data. Do a
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * raw binary comparison; unpacking the WKS RRs using
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * dns_rdata_tostruct() might be cleaner in some ways.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson INSIST(db_rr->length >= 5 && update_rr->length >= 5);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (memcmp(db_rr->data, update_rr->data, 5) == 0 ?
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson ISC_TRUE : ISC_FALSE);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (db_rr->type == dns_rdatatype_nsec3param) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (db_rr->length != update_rr->length)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return (ISC_FALSE);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews INSIST(db_rr->length >= 4 && update_rr->length >= 4);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews /*
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * Replace NSEC3PARAM records that only differ by the
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * flags field.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (db_rr->data[0] == update_rr->data[0] &&
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews memcmp(db_rr->data+2, update_rr->data+2,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews update_rr->length - 2) == 0)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return (ISC_TRUE);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (ISC_FALSE);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Internal helper function for delete_if().
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrencestatic isc_result_t
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssondelete_if_action(void *data, rr_t *rr) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson conditional_delete_ctx_t *ctx = data;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if ((*ctx->predicate)(ctx->update_rr, &rr->rdata)) {
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_result_t result;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = update_one_rr(ctx->db, ctx->ver, ctx->diff,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson DNS_DIFFOP_DEL, ctx->name,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson rr->ttl, &rr->rdata);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews return (result);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews } else {
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews return (ISC_R_SUCCESS);
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson }
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews}
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews/*%
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * Conditionally delete RRs. Apply 'predicate' to the RRs
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * specified by 'db', 'ver', 'name', and 'type' (which can
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * be dns_rdatatype_any to match any type). Delete those
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * RRs for which the predicate returns true, and log the
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * deletions in 'diff'.
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews */
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrewsstatic isc_result_t
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrewsdelete_if(rr_predicate *predicate, dns_db_t *db, dns_dbversion_t *ver,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_name_t *name, dns_rdatatype_t type, dns_rdatatype_t covers,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_rdata_t *update_rr, dns_diff_t *diff)
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews{
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews conditional_delete_ctx_t ctx;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews ctx.predicate = predicate;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews ctx.db = db;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews ctx.ver = ver;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews ctx.diff = diff;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews ctx.name = name;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews ctx.update_rr = update_rr;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews return (foreach_rr(db, ver, name, type, covers,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews delete_if_action, &ctx));
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews}
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews/**************************************************************************/
1f3e0508c2146b473838899429f44e72c52b32f4Mark Andrews
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrewsstatic isc_result_t
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrewsadd_rr_prepare_action(void *data, rr_t *rr) {
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews isc_result_t result = ISC_R_SUCCESS;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews add_rr_prepare_ctx_t *ctx = data;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_difftuple_t *tuple = NULL;
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews isc_boolean_t equal, case_equal, ttl_equal;
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews /*
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews * Are the new and old cases equal?
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews */
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews case_equal = dns_name_caseequal(ctx->name, ctx->oldname);
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews /*
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews * Are the ttl's equal?
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews */
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews ttl_equal = rr->ttl == ctx->update_rr_ttl;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson /*
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews * If the update RR is a "duplicate" of a existing RR,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * the update should be silently ignored.
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson */
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews equal = ISC_TF(dns_rdata_casecompare(&rr->rdata, ctx->update_rr) == 0);
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews if (equal && case_equal && ttl_equal) {
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews ctx->ignore_add = ISC_TRUE;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews return (ISC_R_SUCCESS);
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson }
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson /*
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * If this RR is "equal" to the update RR, it should
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * be deleted before the update RR is added.
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson */
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews if (replaces_p(ctx->update_rr, &rr->rdata)) {
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews CHECK(dns_difftuple_create(ctx->del_diff.mctx, DNS_DIFFOP_DEL,
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews ctx->oldname, rr->ttl, &rr->rdata,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews &tuple));
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_diff_append(&ctx->del_diff, &tuple);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews return (ISC_R_SUCCESS);
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson }
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews /*
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews * If this RR differs in TTL or case from the update RR,
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews * its TTL and case must be adjusted.
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews */
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews if (!ttl_equal || !case_equal) {
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews CHECK(dns_difftuple_create(ctx->del_diff.mctx, DNS_DIFFOP_DEL,
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews ctx->oldname, rr->ttl, &rr->rdata,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews &tuple));
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_diff_append(&ctx->del_diff, &tuple);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews if (!equal) {
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews CHECK(dns_difftuple_create(ctx->add_diff.mctx,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews DNS_DIFFOP_ADD, ctx->name,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews ctx->update_rr_ttl,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews &rr->rdata, &tuple));
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_diff_append(&ctx->add_diff, &tuple);
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson }
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson }
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews failure:
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews return (result);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews}
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews/**************************************************************************/
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews/*
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * Miscellaneous subroutines.
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews/*%
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * Extract a single update RR from 'section' of dynamic update message
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * 'msg', with consistency checking.
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews *
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * Stores the owner name, rdata, and TTL of the update RR at 'name',
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * 'rdata', and 'ttl', respectively.
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews */
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrewsstatic void
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrewsget_current_rr(dns_message_t *msg, dns_section_t section,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_rdataclass_t zoneclass, dns_name_t **name,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_rdata_t *rdata, dns_rdatatype_t *covers,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_ttl_t *ttl, dns_rdataclass_t *update_class)
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews{
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_rdataset_t *rdataset;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews isc_result_t result;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_message_currentname(msg, section, name);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews rdataset = ISC_LIST_HEAD((*name)->list);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews INSIST(rdataset != NULL);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews INSIST(ISC_LIST_NEXT(rdataset, link) == NULL);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews *covers = rdataset->covers;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews *ttl = rdataset->ttl;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews result = dns_rdataset_first(rdataset);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews INSIST(result == ISC_R_SUCCESS);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_rdataset_current(rdataset, rdata);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews INSIST(dns_rdataset_next(rdataset) == ISC_R_NOMORE);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews *update_class = rdata->rdclass;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews rdata->rdclass = zoneclass;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews}
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews/*%
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * Increment the SOA serial number of database 'db', version 'ver'.
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * Replace the SOA record in the database, and log the
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * change in 'diff'.
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews /*
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * XXXRTH Failures in this routine will be worth logging, when
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * we have a logging system. Failure to find the zonename
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * or the SOA rdataset warrant at least an UNEXPECTED_ERROR().
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrewsstatic isc_result_t
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrewsupdate_soa_serial(dns_db_t *db, dns_dbversion_t *ver, dns_diff_t *diff,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews isc_mem_t *mctx, dns_updatemethod_t method)
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews{
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_difftuple_t *deltuple = NULL;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_difftuple_t *addtuple = NULL;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews isc_uint32_t serial;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews isc_result_t result;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews CHECK(dns_db_createsoatuple(db, ver, mctx, DNS_DIFFOP_DEL, &deltuple));
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews CHECK(dns_difftuple_copy(deltuple, &addtuple));
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews addtuple->op = DNS_DIFFOP_ADD;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews serial = dns_soa_getserial(&addtuple->rdata);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews serial = dns_update_soaserial(serial, method);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_soa_setserial(serial, &addtuple->rdata);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews CHECK(do_one_tuple(&deltuple, db, ver, diff));
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews CHECK(do_one_tuple(&addtuple, db, ver, diff));
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews result = ISC_R_SUCCESS;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews failure:
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews if (addtuple != NULL)
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_difftuple_free(&addtuple);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews if (deltuple != NULL)
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_difftuple_free(&deltuple);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews return (result);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews}
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews/*%
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * Check that the new SOA record at 'update_rdata' does not
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * illegally cause the SOA serial number to decrease or stay
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * unchanged relative to the existing SOA in 'db'.
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews *
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * Sets '*ok' to ISC_TRUE if the update is legal, ISC_FALSE if not.
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews *
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * William King points out that RFC2136 is inconsistent about
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * the case where the serial number stays unchanged:
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews *
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * section 3.4.2.2 requires a server to ignore a SOA update request
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * if the serial number on the update SOA is less_than_or_equal to
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * the zone SOA serial.
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews *
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * section 3.6 requires a server to ignore a SOA update request if
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * the serial is less_than the zone SOA serial.
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews *
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * Paul says 3.4.2.2 is correct.
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews *
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews */
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrewsstatic isc_result_t
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrewscheck_soa_increment(dns_db_t *db, dns_dbversion_t *ver,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_rdata_t *update_rdata, isc_boolean_t *ok)
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews{
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews isc_uint32_t db_serial;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews isc_uint32_t update_serial;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews isc_result_t result;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews update_serial = dns_soa_getserial(update_rdata);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews result = dns_db_getsoaserial(db, ver, &db_serial);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews if (result != ISC_R_SUCCESS)
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews return (result);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews if (DNS_SERIAL_GE(db_serial, update_serial)) {
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews *ok = ISC_FALSE;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews } else {
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews *ok = ISC_TRUE;
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson }
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews return (ISC_R_SUCCESS);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence}
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson/**************************************************************************/
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * The actual update code in all its glory. We try to follow
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * the RFC2136 pseudocode as closely as possible.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafssonsend_update_event(ns_client_t *client, dns_zone_t *zone) {
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff isc_result_t result = ISC_R_SUCCESS;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson update_event_t *event = NULL;
999ae80184e3df1016ac74514124b0459ace4d01Andreas Gustafsson isc_task_t *zonetask = NULL;
3b14e4434a8828cfb9bbe6f17423be7524af39a0Andreas Gustafsson ns_client_t *evclient;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson event = (update_event_t *)
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson isc_event_allocate(client->mctx, client, DNS_EVENT_UPDATE,
3b14e4434a8828cfb9bbe6f17423be7524af39a0Andreas Gustafsson update_action, NULL, sizeof(*event));
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson if (event == NULL)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff FAIL(ISC_R_NOMEMORY);
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson event->zone = zone;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff event->result = ISC_R_SUCCESS;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson
3b14e4434a8828cfb9bbe6f17423be7524af39a0Andreas Gustafsson evclient = NULL;
3b14e4434a8828cfb9bbe6f17423be7524af39a0Andreas Gustafsson ns_client_attach(client, &evclient);
c426fddf168a3cdfc1c4c162365d440c89148ae4Mark Andrews INSIST(client->nupdates == 0);
c426fddf168a3cdfc1c4c162365d440c89148ae4Mark Andrews client->nupdates++;
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff event->ev_arg = evclient;
3b14e4434a8828cfb9bbe6f17423be7524af39a0Andreas Gustafsson
71a16ee1350bf1a37c0c9a56a7698c0d4e51fb12Andreas Gustafsson dns_zone_gettask(zone, &zonetask);
42b48d11ca7b296324d7a8a98cdbf0070b0deb1dMark Andrews isc_task_send(zonetask, ISC_EVENT_PTR(&event));
92450223cadcf1fe2efb0c88f09e5bba84f572b2Mark Andrews
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson failure:
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson if (event != NULL)
42b48d11ca7b296324d7a8a98cdbf0070b0deb1dMark Andrews isc_event_free(ISC_EVENT_PTR(&event));
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson return (result);
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson}
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafssonstatic void
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffrespond(ns_client_t *client, isc_result_t result) {
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_result_t msg_result;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff
26e1af486a8c56671aebda6d3f256364e49117b3Brian Wellington msg_result = dns_message_reply(client->message, ISC_TRUE);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (msg_result != ISC_R_SUCCESS)
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson goto msg_failure;
26e1af486a8c56671aebda6d3f256364e49117b3Brian Wellington client->message->rcode = dns_result_torcode(result);
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson ns_client_send(client);
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson return;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson msg_failure:
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson isc_log_write(ns_g_lctx, NS_LOGCATEGORY_UPDATE, NS_LOGMODULE_UPDATE,
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson ISC_LOG_ERROR,
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "could not create update response message: %s",
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson isc_result_totext(msg_result));
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson ns_client_next(client, msg_result);
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson}
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafssonvoid
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrewsns_update_start(ns_client_t *client, isc_result_t sigresult) {
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson dns_message_t *request = client->message;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_result_t result;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_name_t *zonename;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdataset_t *zone_rdataset;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_zone_t *zone = NULL, *raw = NULL;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /*
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Interpret the zone section.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_message_firstname(request, DNS_SECTION_ZONE);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS)
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews FAILC(DNS_R_FORMERR, "update zone section empty");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /*
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * The zone section must contain exactly one "question", and
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * it must be of type SOA.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson zonename = NULL;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_message_currentname(request, DNS_SECTION_ZONE, &zonename);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson zone_rdataset = ISC_LIST_HEAD(zonename->list);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (zone_rdataset->type != dns_rdatatype_soa)
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson FAILC(DNS_R_FORMERR,
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "update zone section contains non-SOA");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (ISC_LIST_NEXT(zone_rdataset, link) != NULL)
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson FAILC(DNS_R_FORMERR,
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "update zone section contains multiple RRs");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /* The zone section must have exactly one name. */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_message_nextname(request, DNS_SECTION_ZONE);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_NOMORE)
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson FAILC(DNS_R_FORMERR,
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "update zone section contains multiple RRs");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
e2fe0815b3c33c5c2c70b11329ac213f4deb18ebBob Halley result = dns_zt_find(client->view->zonetable, zonename, 0, NULL,
e2fe0815b3c33c5c2c70b11329ac213f4deb18ebBob Halley &zone);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS)
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews FAILC(DNS_R_NOTAUTH, "not authoritative for update zone");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews /*
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * If there is a raw (unsigned) zone associated with this
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * zone then it processes the UPDATE request.
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews */
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_zone_getraw(zone, &raw);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews if (raw != NULL) {
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_zone_detach(&zone);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_zone_attach(raw, &zone);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_zone_detach(&raw);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews }
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson switch(dns_zone_gettype(zone)) {
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson case dns_zone_master:
71bd858d8ed62672e7c23999dc7c02fd16a55089Evan Hunt case dns_zone_dlz:
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews /*
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews * We can now fail due to a bad signature as we now know
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews * that we are the master.
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews */
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews if (sigresult != ISC_R_SUCCESS)
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews FAIL(sigresult);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence CHECK(send_update_event(client, zone));
a3e41e3c03a32b00fc243fce538a39ddc7237885Andreas Gustafsson break;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson case dns_zone_slave:
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews CHECK(checkupdateacl(client, dns_zone_getforwardacl(zone),
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews "update forwarding", zonename, ISC_TRUE,
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews ISC_FALSE));
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews CHECK(send_forward_event(client, zone));
a3e41e3c03a32b00fc243fce538a39ddc7237885Andreas Gustafsson break;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson default:
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews FAILC(DNS_R_NOTAUTH, "not authoritative for update zone");
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson }
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson return;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson failure:
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews if (result == DNS_R_REFUSED) {
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews INSIST(dns_zone_gettype(zone) == dns_zone_slave);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(zone, dns_nsstatscounter_updaterej);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews }
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson /*
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson * We failed without having sent an update event to the zone.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * We are still in the client task context, so we can
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson * simply give an error response without switching tasks.
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson */
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson respond(client, result);
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews if (zone != NULL)
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews dns_zone_detach(&zone);
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
c314efc295ef357960fa446490561ddf342c1b36Mark Andrews * DS records are not allowed to exist without corresponding NS records,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * RFC 3658, 2.2 Protocol Change,
c314efc295ef357960fa446490561ddf342c1b36Mark Andrews * "DS RRsets MUST NOT appear at non-delegation points or at a zone's apex".
c314efc295ef357960fa446490561ddf342c1b36Mark Andrews */
c314efc295ef357960fa446490561ddf342c1b36Mark Andrews
4411b9b6e77df22df8f033dc60ebe7e65990ce15Michael Graffstatic isc_result_t
4411b9b6e77df22df8f033dc60ebe7e65990ce15Michael Graffremove_orphaned_ds(dns_db_t *db, dns_dbversion_t *newver, dns_diff_t *diff) {
4411b9b6e77df22df8f033dc60ebe7e65990ce15Michael Graff isc_result_t result;
1f3e0508c2146b473838899429f44e72c52b32f4Mark Andrews isc_boolean_t ns_exists;
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews dns_difftuple_t *tupple;
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews dns_diff_t temp_diff;
4411b9b6e77df22df8f033dc60ebe7e65990ce15Michael Graff
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews dns_diff_init(diff->mctx, &temp_diff);
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews for (tupple = ISC_LIST_HEAD(diff->tuples);
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews tupple != NULL;
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews tupple = ISC_LIST_NEXT(tupple, link)) {
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews if (!((tupple->op == DNS_DIFFOP_DEL &&
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews tupple->rdata.type == dns_rdatatype_ns) ||
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews (tupple->op == DNS_DIFFOP_ADD &&
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews tupple->rdata.type == dns_rdatatype_ds)))
4411b9b6e77df22df8f033dc60ebe7e65990ce15Michael Graff continue;
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews CHECK(rrset_exists(db, newver, &tupple->name,
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews dns_rdatatype_ns, 0, &ns_exists));
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews if (ns_exists &&
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews !dns_name_equal(&tupple->name, dns_db_origin(db)))
4411b9b6e77df22df8f033dc60ebe7e65990ce15Michael Graff continue;
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews CHECK(delete_if(true_p, db, newver, &tupple->name,
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews dns_rdatatype_ds, 0, NULL, &temp_diff));
4411b9b6e77df22df8f033dc60ebe7e65990ce15Michael Graff }
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews result = ISC_R_SUCCESS;
4411b9b6e77df22df8f033dc60ebe7e65990ce15Michael Graff
4411b9b6e77df22df8f033dc60ebe7e65990ce15Michael Graff failure:
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews for (tupple = ISC_LIST_HEAD(temp_diff.tuples);
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews tupple != NULL;
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews tupple = ISC_LIST_HEAD(temp_diff.tuples)) {
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews ISC_LIST_UNLINK(temp_diff.tuples, tupple, link);
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews dns_diff_appendminimal(diff, &tupple);
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews }
4411b9b6e77df22df8f033dc60ebe7e65990ce15Michael Graff return (result);
4411b9b6e77df22df8f033dc60ebe7e65990ce15Michael Graff}
4411b9b6e77df22df8f033dc60ebe7e65990ce15Michael Graff
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews/*
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews * This implements the post load integrity checks for mx records.
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews */
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewsstatic isc_result_t
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewscheck_mx(ns_client_t *client, dns_zone_t *zone,
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_db_t *db, dns_dbversion_t *newver, dns_diff_t *diff)
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews{
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews char tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:123.123.123.123.")];
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews char ownerbuf[DNS_NAME_FORMATSIZE];
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews char namebuf[DNS_NAME_FORMATSIZE];
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews char altbuf[DNS_NAME_FORMATSIZE];
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_difftuple_t *t;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_fixedname_t fixed;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_name_t *foundname;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_rdata_mx_t mx;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_rdata_t rdata;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews isc_boolean_t ok = ISC_TRUE;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews isc_boolean_t isaddress;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews isc_result_t result;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews struct in6_addr addr6;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews struct in_addr addr;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews unsigned int options;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_fixedname_init(&fixed);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews foundname = dns_fixedname_name(&fixed);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_rdata_init(&rdata);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews options = dns_zone_getoptions(zone);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews for (t = ISC_LIST_HEAD(diff->tuples);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews t != NULL;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews t = ISC_LIST_NEXT(t, link)) {
d91df50b670d92d0ab784b741e2ee9af7f2dc4a1Mark Andrews if (t->op != DNS_DIFFOP_ADD ||
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews t->rdata.type != dns_rdatatype_mx)
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews continue;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews result = dns_rdata_tostruct(&t->rdata, &mx, NULL);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews RUNTIME_CHECK(result == ISC_R_SUCCESS);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews /*
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews * Check if we will error out if we attempt to reload the
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews * zone.
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews */
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_name_format(&mx.mx, namebuf, sizeof(namebuf));
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_name_format(&t->name, ownerbuf, sizeof(ownerbuf));
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews isaddress = ISC_FALSE;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews if ((options & DNS_RDATA_CHECKMX) != 0 &&
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews strlcpy(tmp, namebuf, sizeof(tmp)) < sizeof(tmp)) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews if (tmp[strlen(tmp) - 1] == '.')
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews tmp[strlen(tmp) - 1] = '\0';
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews if (inet_aton(tmp, &addr) == 1 ||
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews inet_pton(AF_INET6, tmp, &addr6) == 1)
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews isaddress = ISC_TRUE;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews }
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews if (isaddress && (options & DNS_RDATA_CHECKMXFAIL) != 0) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews update_log(client, zone, ISC_LOG_ERROR,
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews "%s/MX: '%s': %s",
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews ownerbuf, namebuf,
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_result_totext(DNS_R_MXISADDRESS));
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews ok = ISC_FALSE;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews } else if (isaddress) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews update_log(client, zone, ISC_LOG_WARNING,
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews "%s/MX: warning: '%s': %s",
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews ownerbuf, namebuf,
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_result_totext(DNS_R_MXISADDRESS));
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews }
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews /*
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews * Check zone integrity checks.
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews */
2c15fcdeac4c2402258867fbac24d7475ef98259Mark Andrews if ((options & DNS_ZONEOPT_CHECKINTEGRITY) == 0)
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews continue;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews result = dns_db_find(db, &mx.mx, newver, dns_rdatatype_a,
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews 0, 0, NULL, foundname, NULL, NULL);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews if (result == ISC_R_SUCCESS)
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews continue;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews if (result == DNS_R_NXRRSET) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews result = dns_db_find(db, &mx.mx, newver,
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_rdatatype_aaaa,
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews 0, 0, NULL, foundname,
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews NULL, NULL);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews if (result == ISC_R_SUCCESS)
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews continue;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews }
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews if (result == DNS_R_NXRRSET || result == DNS_R_NXDOMAIN) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews update_log(client, zone, ISC_LOG_ERROR,
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews "%s/MX '%s' has no address records "
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews "(A or AAAA)", ownerbuf, namebuf);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews ok = ISC_FALSE;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews } else if (result == DNS_R_CNAME) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews update_log(client, zone, ISC_LOG_ERROR,
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews "%s/MX '%s' is a CNAME (illegal)",
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews ownerbuf, namebuf);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews ok = ISC_FALSE;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews } else if (result == DNS_R_DNAME) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_name_format(foundname, altbuf, sizeof altbuf);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews update_log(client, zone, ISC_LOG_ERROR,
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews "%s/MX '%s' is below a DNAME '%s' (illegal)",
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews ownerbuf, namebuf, altbuf);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews ok = ISC_FALSE;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews }
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews }
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews return (ok ? ISC_R_SUCCESS : DNS_R_REFUSED);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews}
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsstatic isc_result_t
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsrr_exists(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews const dns_rdata_t *rdata, isc_boolean_t *flag)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews{
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_rdataset_t rdataset;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_dbnode_t *node = NULL;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_result_t result;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_rdataset_init(&rdataset);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (rdata->type == dns_rdatatype_nsec3)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(dns_db_findnsec3node(db, name, ISC_FALSE, &node));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews else
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(dns_db_findnode(db, name, ISC_FALSE, &node));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_db_findrdataset(db, node, ver, rdata->type, 0,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews (isc_stdtime_t) 0, &rdataset, NULL);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (result == ISC_R_NOTFOUND) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews *flag = ISC_FALSE;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = ISC_R_SUCCESS;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews goto failure;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews for (result = dns_rdataset_first(&rdataset);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result == ISC_R_SUCCESS;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_rdataset_next(&rdataset)) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_rdata_t myrdata = DNS_RDATA_INIT;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_rdataset_current(&rdataset, &myrdata);
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews if (!dns_rdata_casecompare(&myrdata, rdata))
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews break;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_rdataset_disassociate(&rdataset);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (result == ISC_R_SUCCESS) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews *flag = ISC_TRUE;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews } else if (result == ISC_R_NOMORE) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews *flag = ISC_FALSE;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = ISC_R_SUCCESS;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews failure:
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (node != NULL)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_db_detachnode(db, &node);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return (result);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews}
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsstatic isc_result_t
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrewsget_iterations(dns_db_t *db, dns_dbversion_t *ver, dns_rdatatype_t privatetype,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews unsigned int *iterationsp)
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews{
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_dbnode_t *node = NULL;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_rdata_nsec3param_t nsec3param;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_rdataset_t rdataset;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_result_t result;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews unsigned int iterations = 0;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_rdataset_init(&rdataset);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_db_getoriginnode(db, &node);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (result != ISC_R_SUCCESS)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return (result);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_db_findrdataset(db, node, ver, dns_rdatatype_nsec3param,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews 0, (isc_stdtime_t) 0, &rdataset, NULL);
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if (result == ISC_R_NOTFOUND)
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews goto try_private;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if (result != ISC_R_SUCCESS)
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews goto failure;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews for (result = dns_rdataset_first(&rdataset);
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews result == ISC_R_SUCCESS;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews result = dns_rdataset_next(&rdataset)) {
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_rdata_t rdata = DNS_RDATA_INIT;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_rdataset_current(&rdataset, &rdata);
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews CHECK(dns_rdata_tostruct(&rdata, &nsec3param, NULL));
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if ((nsec3param.flags & DNS_NSEC3FLAG_REMOVE) != 0)
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews continue;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if (nsec3param.iterations > iterations)
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews iterations = nsec3param.iterations;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews }
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if (result != ISC_R_NOMORE)
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews goto failure;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_rdataset_disassociate(&rdataset);
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews try_private:
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if (privatetype == 0)
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews goto success;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews result = dns_db_findrdataset(db, node, ver, privatetype,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews 0, (isc_stdtime_t) 0, &rdataset, NULL);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (result == ISC_R_NOTFOUND)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews goto success;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (result != ISC_R_SUCCESS)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews goto failure;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews for (result = dns_rdataset_first(&rdataset);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result == ISC_R_SUCCESS;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_rdataset_next(&rdataset)) {
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews unsigned char buf[DNS_NSEC3PARAM_BUFFERSIZE];
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_rdata_t private = DNS_RDATA_INIT;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_rdata_t rdata = DNS_RDATA_INIT;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_rdataset_current(&rdataset, &rdata);
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if (!dns_nsec3param_fromprivate(&private, &rdata,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews buf, sizeof(buf)))
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews continue;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(dns_rdata_tostruct(&rdata, &nsec3param, NULL));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if ((nsec3param.flags & DNS_NSEC3FLAG_REMOVE) != 0)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews continue;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (nsec3param.iterations > iterations)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews iterations = nsec3param.iterations;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (result != ISC_R_NOMORE)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews goto failure;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews success:
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews *iterationsp = iterations;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = ISC_R_SUCCESS;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews failure:
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if (node != NULL)
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_db_detachnode(db, &node);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (dns_rdataset_isassociated(&rdataset))
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_rdataset_disassociate(&rdataset);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return (result);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews}
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews/*
b9d48991211415094ed6ea92d2084422104c6787Francis Dupont * Prevent the zone entering a inconsistent state where
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * NSEC only DNSKEYs are present with NSEC3 chains.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsstatic isc_result_t
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewscheck_dnssec(ns_client_t *client, dns_zone_t *zone, dns_db_t *db,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_dbversion_t *ver, dns_diff_t *diff)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews{
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt dns_difftuple_t *tuple;
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt isc_boolean_t nseconly = ISC_FALSE, nsec3 = ISC_FALSE;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_result_t result;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews unsigned int iterations = 0, max;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_rdatatype_t privatetype = dns_zone_getprivatetype(zone);
6e2871232f7ede047799480370aff444be1f5a13Automatic Updater
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt /* Scan the tuples for an NSEC-only DNSKEY or an NSEC3PARAM */
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt for (tuple = ISC_LIST_HEAD(diff->tuples);
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt tuple != NULL;
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt tuple = ISC_LIST_NEXT(tuple, link)) {
928e12ccdc36220075e01d7fa3b6fa79e9162385Automatic Updater if (tuple->op != DNS_DIFFOP_ADD)
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt continue;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt if (tuple->rdata.type == dns_rdatatype_dnskey) {
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt isc_uint8_t alg;
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt alg = tuple->rdata.data[3];
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt if (alg == DST_ALG_RSAMD5 || alg == DST_ALG_RSASHA1 ||
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt alg == DST_ALG_DSA || alg == DST_ALG_ECC) {
928e12ccdc36220075e01d7fa3b6fa79e9162385Automatic Updater nseconly = ISC_TRUE;
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt break;
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt }
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt } else if (tuple->rdata.type == dns_rdatatype_nsec3param) {
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt nsec3 = ISC_TRUE;
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt break;
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt }
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt }
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt /* Check existing DB for NSEC-only DNSKEY */
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt if (!nseconly) {
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt result = dns_nsec_nseconly(db, ver, &nseconly);
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt /*
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * An NSEC3PARAM update can proceed without a DNSKEY (it
0f467ed4d4a732003941247d26f05596e25f357bAutomatic Updater * will trigger a delayed change), so we can ignore
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * ISC_R_NOTFOUND here.
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt */
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt if (result == ISC_R_NOTFOUND)
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt result = ISC_R_SUCCESS;
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt CHECK(result);
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt /* Check existing DB for NSEC3 */
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt if (!nsec3)
cc3ed192b030ccf9a903a4a7c8667cda8ad23eebEvan Hunt CHECK(dns_nsec3_activex(db, ver, ISC_FALSE,
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt privatetype, &nsec3));
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt /* Refuse to allow NSEC3 with NSEC-only keys */
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt if (nseconly && nsec3) {
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt update_log(client, zone, ISC_LOG_ERROR,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews "NSEC only DNSKEYs and NSEC3 chains not allowed");
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt result = DNS_R_REFUSED;
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt goto failure;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt /* Verify NSEC3 params */
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt CHECK(get_iterations(db, ver, privatetype, &iterations));
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt CHECK(dns_nsec3_maxiterations(db, ver, client->mctx, &max));
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt if (max != 0 && iterations > max) {
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt update_log(client, zone, ISC_LOG_ERROR,
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt "too many NSEC3 iterations (%u) for "
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt "weakest DNSKEY (%u)", iterations, max);
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt result = DNS_R_REFUSED;
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt goto failure;
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews failure:
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return (result);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews}
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews/*
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Delay NSEC3PARAM changes as they need to be applied to the whole zone.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsstatic isc_result_t
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsadd_nsec3param_records(ns_client_t *client, dns_zone_t *zone, dns_db_t *db,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_dbversion_t *ver, dns_diff_t *diff)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews{
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_result_t result = ISC_R_SUCCESS;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_difftuple_t *tuple, *newtuple = NULL, *next;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_rdata_t rdata = DNS_RDATA_INIT;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews unsigned char buf[DNS_NSEC3PARAM_BUFFERSIZE + 1];
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_diff_t temp_diff;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_diffop_t op;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_boolean_t flag;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_name_t *name = dns_zone_getorigin(zone);
cf5770e7b13ee510b9201fa53b86649da23eca0eMark Andrews dns_rdatatype_t privatetype = dns_zone_getprivatetype(zone);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews isc_uint32_t ttl = 0;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews isc_boolean_t ttl_good = ISC_FALSE;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews update_log(client, zone, ISC_LOG_DEBUG(3),
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews "checking for NSEC3PARAM changes");
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_diff_init(diff->mctx, &temp_diff);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews /*
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Extract NSEC3PARAM tuples from list.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews for (tuple = ISC_LIST_HEAD(diff->tuples);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews tuple != NULL;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews tuple = next) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews next = ISC_LIST_NEXT(tuple, link);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (tuple->rdata.type != dns_rdatatype_nsec3param ||
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews !dns_name_equal(name, &tuple->name))
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews continue;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews ISC_LIST_UNLINK(diff->tuples, tuple, link);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews ISC_LIST_APPEND(temp_diff.tuples, tuple, link);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews /*
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * Extract TTL changes pairs, we don't need to convert these to
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * delayed changes.
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews for (tuple = ISC_LIST_HEAD(temp_diff.tuples);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews tuple != NULL; tuple = next) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (tuple->op == DNS_DIFFOP_ADD) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if (!ttl_good) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews /*
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * Any adds here will contain the final
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * NSEC3PARAM RRset TTL.
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews */
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews ttl = tuple->ttl;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews ttl_good = ISC_TRUE;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews }
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews /*
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * Walk the temp_diff list looking for the
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * corresponding delete.
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews */
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews next = ISC_LIST_HEAD(temp_diff.tuples);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews while (next != NULL) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews unsigned char *next_data = next->rdata.data;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews unsigned char *tuple_data = tuple->rdata.data;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if (next->op == DNS_DIFFOP_DEL &&
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews next->rdata.length == tuple->rdata.length &&
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews !memcmp(next_data, tuple_data,
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews next->rdata.length)) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews ISC_LIST_UNLINK(temp_diff.tuples, next,
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews link);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews ISC_LIST_APPEND(diff->tuples, next,
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews link);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews break;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews }
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews next = ISC_LIST_NEXT(next, link);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews }
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews /*
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * If we have not found a pair move onto the next
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * tuple.
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews */
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if (next == NULL) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews next = ISC_LIST_NEXT(tuple, link);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews continue;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews }
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews /*
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * Find the next tuple to be processed before
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * unlinking then complete moving the pair to 'diff'.
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews */
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews next = ISC_LIST_NEXT(tuple, link);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews ISC_LIST_UNLINK(temp_diff.tuples, tuple, link);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews ISC_LIST_APPEND(diff->tuples, tuple, link);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews } else
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews next = ISC_LIST_NEXT(tuple, link);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews }
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater /*
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater * Preserve any ongoing changes from a BIND 9.6.x upgrade.
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews *
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * Any NSEC3PARAM records with flags other than OPTOUT named
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * in managing and should not be touched so revert such changes
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * taking into account any TTL change of the NSEC3PARAM RRset.
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater */
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater for (tuple = ISC_LIST_HEAD(temp_diff.tuples);
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater tuple != NULL; tuple = next) {
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater next = ISC_LIST_NEXT(tuple, link);
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater if ((tuple->rdata.data[1] & ~DNS_NSEC3FLAG_OPTOUT) != 0) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews /*
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * If we havn't had any adds then the tuple->ttl must
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * be the original ttl and should be used for any
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * future changes.
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews */
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if (!ttl_good) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews ttl = tuple->ttl;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews ttl_good = ISC_TRUE;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews }
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater op = (tuple->op == DNS_DIFFOP_DEL) ?
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater DNS_DIFFOP_ADD : DNS_DIFFOP_DEL;
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater CHECK(dns_difftuple_create(diff->mctx, op, name,
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater ttl, &tuple->rdata,
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews &newtuple));
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater CHECK(do_one_tuple(&newtuple, db, ver, diff));
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater ISC_LIST_UNLINK(temp_diff.tuples, tuple, link);
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater dns_diff_appendminimal(diff, &tuple);
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater }
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater }
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews /*
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * We now have just the actual changes to the NSEC3PARAM RRset.
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * Convert the adds to delayed adds and the deletions into delayed
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * deletions.
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews */
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews for (tuple = ISC_LIST_HEAD(temp_diff.tuples);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews tuple != NULL; tuple = next) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews /*
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * If we havn't had any adds then the tuple->ttl must be the
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * original ttl and should be used for any future changes.
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews */
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if (!ttl_good) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews ttl = tuple->ttl;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews ttl_good = ISC_TRUE;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews }
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if (tuple->op == DNS_DIFFOP_ADD) {
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt isc_boolean_t nseconly = ISC_FALSE;
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews /*
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * Look for any deletes which match this ADD ignoring
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * flags. We don't need to explictly remove them as
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * they will be removed a side effect of processing
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * the add.
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews */
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews next = ISC_LIST_HEAD(temp_diff.tuples);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews while (next != NULL) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews unsigned char *next_data = next->rdata.data;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews unsigned char *tuple_data = tuple->rdata.data;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if (next->op != DNS_DIFFOP_DEL ||
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews next->rdata.length != tuple->rdata.length ||
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews next_data[0] != tuple_data[0] ||
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews next_data[2] != tuple_data[2] ||
6e2871232f7ede047799480370aff444be1f5a13Automatic Updater next_data[3] != tuple_data[3] ||
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews memcmp(next_data + 4, tuple_data + 4,
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews tuple->rdata.length - 4)) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews next = ISC_LIST_NEXT(next, link);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews continue;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews ISC_LIST_UNLINK(temp_diff.tuples, next, link);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews ISC_LIST_APPEND(diff->tuples, next, link);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews next = ISC_LIST_HEAD(temp_diff.tuples);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews /*
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * Create a private-type record to signal that
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * we want a delayed NSEC3 chain add/delete
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_nsec3param_toprivate(&tuple->rdata, &rdata,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews privatetype, buf, sizeof(buf));
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews buf[2] |= DNS_NSEC3FLAG_CREATE;
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt /*
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * If the zone is not currently capable of
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * supporting an NSEC3 chain, then we set the
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * INITIAL flag to indicate that these parameters
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * are to be used later.
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt */
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt result = dns_nsec_nseconly(db, ver, &nseconly);
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt if (result == ISC_R_NOTFOUND || nseconly)
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt buf[2] |= DNS_NSEC3FLAG_INITIAL;
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt /*
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * See if this CREATE request already exists.
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(rr_exists(db, ver, name, &rdata, &flag));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (!flag) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(dns_difftuple_create(diff->mctx,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews DNS_DIFFOP_ADD,
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews name, 0, &rdata,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews &newtuple));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(do_one_tuple(&newtuple, db, ver, diff));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
57fb4f7bbec88bc6431a39d4a10f82c265798b1fMark Andrews /*
57fb4f7bbec88bc6431a39d4a10f82c265798b1fMark Andrews * Remove any existing CREATE request to add an
57fb4f7bbec88bc6431a39d4a10f82c265798b1fMark Andrews * otherwise indentical chain with a reversed
57fb4f7bbec88bc6431a39d4a10f82c265798b1fMark Andrews * OPTOUT state.
57fb4f7bbec88bc6431a39d4a10f82c265798b1fMark Andrews */
57fb4f7bbec88bc6431a39d4a10f82c265798b1fMark Andrews buf[2] ^= DNS_NSEC3FLAG_OPTOUT;
57fb4f7bbec88bc6431a39d4a10f82c265798b1fMark Andrews CHECK(rr_exists(db, ver, name, &rdata, &flag));
57fb4f7bbec88bc6431a39d4a10f82c265798b1fMark Andrews
57fb4f7bbec88bc6431a39d4a10f82c265798b1fMark Andrews if (flag) {
57fb4f7bbec88bc6431a39d4a10f82c265798b1fMark Andrews CHECK(dns_difftuple_create(diff->mctx,
57fb4f7bbec88bc6431a39d4a10f82c265798b1fMark Andrews DNS_DIFFOP_DEL,
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews name, 0, &rdata,
57fb4f7bbec88bc6431a39d4a10f82c265798b1fMark Andrews &newtuple));
57fb4f7bbec88bc6431a39d4a10f82c265798b1fMark Andrews CHECK(do_one_tuple(&newtuple, db, ver, diff));
57fb4f7bbec88bc6431a39d4a10f82c265798b1fMark Andrews }
57fb4f7bbec88bc6431a39d4a10f82c265798b1fMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews /*
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * Find the next tuple to be processed and remove the
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * temporary add record.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews next = ISC_LIST_NEXT(tuple, link);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(dns_difftuple_create(diff->mctx, DNS_DIFFOP_DEL,
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews name, ttl, &tuple->rdata,
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews &newtuple));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(do_one_tuple(&newtuple, db, ver, diff));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews ISC_LIST_UNLINK(temp_diff.tuples, tuple, link);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_diff_appendminimal(diff, &tuple);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_rdata_reset(&rdata);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews } else
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews next = ISC_LIST_NEXT(tuple, link);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews for (tuple = ISC_LIST_HEAD(temp_diff.tuples);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews tuple != NULL; tuple = next) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews INSIST(ttl_good);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews next = ISC_LIST_NEXT(tuple, link);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews /*
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * See if we already have a REMOVE request in progress.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews dns_nsec3param_toprivate(&tuple->rdata, &rdata, privatetype,
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews buf, sizeof(buf));
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews buf[2] |= DNS_NSEC3FLAG_REMOVE | DNS_NSEC3FLAG_NONSEC;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(rr_exists(db, ver, name, &rdata, &flag));
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if (!flag) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews buf[2] &= ~DNS_NSEC3FLAG_NONSEC;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews CHECK(rr_exists(db, ver, name, &rdata, &flag));
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (!flag) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(dns_difftuple_create(diff->mctx, DNS_DIFFOP_ADD,
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews name, 0, &rdata, &newtuple));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(do_one_tuple(&newtuple, db, ver, diff));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(dns_difftuple_create(diff->mctx, DNS_DIFFOP_ADD, name,
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews ttl, &tuple->rdata, &newtuple));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(do_one_tuple(&newtuple, db, ver, diff));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews ISC_LIST_UNLINK(temp_diff.tuples, tuple, link);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_diff_appendminimal(diff, &tuple);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_rdata_reset(&rdata);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = ISC_R_SUCCESS;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews failure:
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_diff_clear(&temp_diff);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return (result);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews}
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrewsstatic isc_result_t
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrewsrollback_private(dns_db_t *db, dns_rdatatype_t privatetype,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_dbversion_t *ver, dns_diff_t *diff)
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews{
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_diff_t temp_diff;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_diffop_t op;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_difftuple_t *tuple, *newtuple = NULL, *next;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_name_t *name = dns_db_origin(db);
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews isc_mem_t *mctx = diff->mctx;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews isc_result_t result;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if (privatetype == 0)
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews return (ISC_R_SUCCESS);
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_diff_init(mctx, &temp_diff);
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews /*
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews * Extract the changes to be rolled back.
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews */
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews for (tuple = ISC_LIST_HEAD(diff->tuples);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews tuple != NULL; tuple = next) {
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews next = ISC_LIST_NEXT(tuple, link);
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if (tuple->rdata.type != privatetype ||
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews !dns_name_equal(name, &tuple->name))
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews continue;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews /*
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews * Allow records which indicate that a zone has been
931814de4ad11f20b85c3b50399e2e7dda2e7d47Francis Dupont * signed with a DNSKEY to be removed.
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews */
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if (tuple->op == DNS_DIFFOP_DEL &&
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews tuple->rdata.length == 5 &&
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews tuple->rdata.data[0] != 0 &&
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews tuple->rdata.data[4] != 0)
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews continue;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews ISC_LIST_UNLINK(diff->tuples, tuple, link);
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews ISC_LIST_PREPEND(temp_diff.tuples, tuple, link);
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews }
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews /*
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews * Rollback the changes.
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews */
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews while ((tuple = ISC_LIST_HEAD(temp_diff.tuples)) != NULL) {
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews op = (tuple->op == DNS_DIFFOP_DEL) ?
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews DNS_DIFFOP_ADD : DNS_DIFFOP_DEL;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews CHECK(dns_difftuple_create(mctx, op, name, tuple->ttl,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews &tuple->rdata, &newtuple));
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews CHECK(do_one_tuple(&newtuple, db, ver, &temp_diff));
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews }
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews result = ISC_R_SUCCESS;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews failure:
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_diff_clear(&temp_diff);
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews return (result);
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews}
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews/*
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Add records to cause the delayed signing of the zone by added DNSKEY
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * to remove the RRSIG records generated by a deleted DNSKEY.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrewsstatic isc_result_t
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrewsadd_signing_records(dns_db_t *db, dns_rdatatype_t privatetype,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_dbversion_t *ver, dns_diff_t *diff)
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews{
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews dns_difftuple_t *tuple, *newtuple = NULL, *next;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews dns_rdata_dnskey_t dnskey;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews dns_rdata_t rdata = DNS_RDATA_INIT;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_boolean_t flag;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews isc_region_t r;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_result_t result = ISC_R_SUCCESS;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews isc_uint16_t keyid;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews unsigned char buf[5];
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_name_t *name = dns_db_origin(db);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews dns_diff_t temp_diff;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews dns_diff_init(diff->mctx, &temp_diff);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews /*
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews * Extract the DNSKEY tuples from the list.
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews */
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews for (tuple = ISC_LIST_HEAD(diff->tuples);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews tuple != NULL; tuple = next) {
784a904bd06c7492361ed09a882d10c636b1291bAutomatic Updater
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews next = ISC_LIST_NEXT(tuple, link);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (tuple->rdata.type != dns_rdatatype_dnskey)
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews continue;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews ISC_LIST_UNLINK(diff->tuples, tuple, link);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews ISC_LIST_APPEND(temp_diff.tuples, tuple, link);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews }
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews /*
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews * Extract TTL changes pairs, we don't need signing records for these.
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews */
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews for (tuple = ISC_LIST_HEAD(temp_diff.tuples);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews tuple != NULL; tuple = next) {
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews if (tuple->op == DNS_DIFFOP_ADD) {
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews /*
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews * Walk the temp_diff list looking for the
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews * corresponding delete.
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews */
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews next = ISC_LIST_HEAD(temp_diff.tuples);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews while (next != NULL) {
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews unsigned char *next_data = next->rdata.data;
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews unsigned char *tuple_data = tuple->rdata.data;
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews if (next->op == DNS_DIFFOP_DEL &&
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews dns_name_equal(&tuple->name, &next->name) &&
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews next->rdata.length == tuple->rdata.length &&
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews !memcmp(next_data, tuple_data,
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews next->rdata.length)) {
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews ISC_LIST_UNLINK(temp_diff.tuples, next,
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews link);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews ISC_LIST_APPEND(diff->tuples, next,
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews link);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews break;
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews }
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews next = ISC_LIST_NEXT(next, link);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews }
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews /*
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews * If we have not found a pair move onto the next
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews * tuple.
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews */
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews if (next == NULL) {
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews next = ISC_LIST_NEXT(tuple, link);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews continue;
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews }
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews /*
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews * Find the next tuple to be processed before
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews * unlinking then complete moving the pair to 'diff'.
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews */
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews next = ISC_LIST_NEXT(tuple, link);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews ISC_LIST_UNLINK(temp_diff.tuples, tuple, link);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews ISC_LIST_APPEND(diff->tuples, tuple, link);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews } else
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews next = ISC_LIST_NEXT(tuple, link);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews }
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews /*
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews * Process the remaining DNSKEY entries.
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews */
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews for (tuple = ISC_LIST_HEAD(temp_diff.tuples);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews tuple != NULL;
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews tuple = ISC_LIST_HEAD(temp_diff.tuples)) {
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews ISC_LIST_UNLINK(temp_diff.tuples, tuple, link);
784a904bd06c7492361ed09a882d10c636b1291bAutomatic Updater ISC_LIST_APPEND(diff->tuples, tuple, link);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews result = dns_rdata_tostruct(&tuple->rdata, &dnskey, NULL);
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews RUNTIME_CHECK(result == ISC_R_SUCCESS);
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews if ((dnskey.flags &
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews (DNS_KEYFLAG_OWNERMASK|DNS_KEYTYPE_NOAUTH))
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews != DNS_KEYOWNER_ZONE)
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews continue;
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews dns_rdata_toregion(&tuple->rdata, &r);
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews keyid = dst_region_computeid(&r, dnskey.algorithm);
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews buf[0] = dnskey.algorithm;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews buf[1] = (keyid & 0xff00) >> 8;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews buf[2] = (keyid & 0xff);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews buf[3] = (tuple->op == DNS_DIFFOP_ADD) ? 0 : 1;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews buf[4] = 0;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews rdata.data = buf;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews rdata.length = sizeof(buf);
3f42cf2f3e4dc7e740b4609ba7d7430292348f2bMark Andrews rdata.type = privatetype;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews rdata.rdclass = tuple->rdata.rdclass;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(rr_exists(db, ver, name, &rdata, &flag));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (flag)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews continue;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(dns_difftuple_create(diff->mctx, DNS_DIFFOP_ADD,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews name, 0, &rdata, &newtuple));
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews CHECK(do_one_tuple(&newtuple, db, ver, diff));
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews INSIST(newtuple == NULL);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews /*
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Remove any record which says this operation has already
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * completed.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews buf[4] = 1;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(rr_exists(db, ver, name, &rdata, &flag));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (flag) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(dns_difftuple_create(diff->mctx, DNS_DIFFOP_DEL,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews name, 0, &rdata, &newtuple));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(do_one_tuple(&newtuple, db, ver, diff));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews INSIST(newtuple == NULL);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews failure:
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews dns_diff_clear(&temp_diff);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return (result);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews}
6e2871232f7ede047799480370aff444be1f5a13Automatic Updater
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrewsstatic isc_boolean_t
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrewsisdnssec(dns_db_t *db, dns_dbversion_t *ver, dns_rdatatype_t privatetype) {
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews isc_result_t result;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews isc_boolean_t build_nsec, build_nsec3;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if (dns_db_issecure(db))
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews return (ISC_TRUE);
15bbb8a1298a61e401ba16c944dc06049abb81bfAutomatic Updater
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews result = dns_private_chains(db, ver, privatetype,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews &build_nsec, &build_nsec3);
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews RUNTIME_CHECK(result == ISC_R_SUCCESS);
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews return (build_nsec || build_nsec3);
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews}
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafssonstatic void
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrenceupdate_action(isc_task_t *task, isc_event_t *event) {
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson update_event_t *uev = (update_event_t *) event;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson dns_zone_t *zone = uev->zone;
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff ns_client_t *client = (ns_client_t *)event->ev_arg;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_result_t result;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson dns_db_t *db = NULL;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson dns_dbversion_t *oldver = NULL;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson dns_dbversion_t *ver = NULL;
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews dns_diff_t diff; /* Pending updates. */
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews dns_diff_t temp; /* Pending RR existence assertions. */
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson isc_boolean_t soa_serial_changed = ISC_FALSE;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson isc_mem_t *mctx = client->mctx;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson dns_rdatatype_t covers;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson dns_message_t *request = client->message;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson dns_rdataclass_t zoneclass;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson dns_name_t *zonename;
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington dns_ssutable_t *ssutable = NULL;
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews dns_fixedname_t tmpnamefixed;
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews dns_name_t *tmpname = NULL;
35f6a21f5f8114542c050bfcb484b39ce513d4bdEvan Hunt unsigned int options, options2;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews dns_difftuple_t *tuple;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews dns_rdata_dnskey_t dnskey;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_boolean_t had_dnskey;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_rdatatype_t privatetype = dns_zone_getprivatetype(zone);
35f6a21f5f8114542c050bfcb484b39ce513d4bdEvan Hunt dns_ttl_t maxttl = 0;
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews isc_uint32_t maxrecords;
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews isc_uint64_t records;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff INSIST(event->ev_type == DNS_EVENT_UPDATE);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson dns_diff_init(mctx, &diff);
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson dns_diff_init(mctx, &temp);
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson CHECK(dns_zone_getdb(zone, &db));
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson zonename = dns_db_origin(db);
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson zoneclass = dns_db_class(db);
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington dns_zone_getssutable(zone, &ssutable);
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews /*
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews * Update message processing can leak record existance information
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews * so check that we are allowed to query this zone. Additionally
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews * if we would refuse all updates for this zone we bail out here.
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews */
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews CHECK(checkqueryacl(client, dns_zone_getqueryacl(zone), zonename,
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews dns_zone_getupdateacl(zone), ssutable));
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews /*
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews * Get old and new versions now that queryacl has been checked.
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews */
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson dns_db_currentversion(db, &oldver);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson CHECK(dns_db_newversion(db, &ver));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence /*
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Check prerequisites.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson for (result = dns_message_firstname(request, DNS_SECTION_PREREQUISITE);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff result == ISC_R_SUCCESS;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_message_nextname(request, DNS_SECTION_PREREQUISITE))
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_name_t *name = NULL;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews dns_rdata_t rdata = DNS_RDATA_INIT;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_ttl_t ttl;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdataclass_t update_class;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson isc_boolean_t flag;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson get_current_rr(request, DNS_SECTION_PREREQUISITE, zoneclass,
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley &name, &rdata, &covers, &ttl, &update_class);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (ttl != 0)
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews PREREQFAILC(DNS_R_FORMERR,
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "prerequisite TTL is not zero");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (! dns_name_issubdomain(name, zonename))
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews PREREQFAILN(DNS_R_NOTZONE, name,
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "prerequisite name is out of zone");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (update_class == dns_rdataclass_any) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (rdata.length != 0)
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews PREREQFAILC(DNS_R_FORMERR,
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "class ANY prerequisite "
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "RDATA is not empty");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (rdata.type == dns_rdatatype_any) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson CHECK(name_exists(db, ver, name, &flag));
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (! flag) {
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews PREREQFAILN(DNS_R_NXDOMAIN, name,
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "'name in use' "
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "prerequisite not "
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "satisfied");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson } else {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson CHECK(rrset_exists(db, ver, name,
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley rdata.type, covers, &flag));
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (! flag) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /* RRset does not exist. */
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews PREREQFAILNT(DNS_R_NXRRSET, name, rdata.type,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson "'rrset exists (value independent)' "
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "prerequisite not satisfied");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson } else if (update_class == dns_rdataclass_none) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (rdata.length != 0)
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews PREREQFAILC(DNS_R_FORMERR,
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "class NONE prerequisite "
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "RDATA is not empty");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (rdata.type == dns_rdatatype_any) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson CHECK(name_exists(db, ver, name, &flag));
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (flag) {
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews PREREQFAILN(DNS_R_YXDOMAIN, name,
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "'name not in use' "
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "prerequisite not "
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "satisfied");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson } else {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson CHECK(rrset_exists(db, ver, name,
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley rdata.type, covers, &flag));
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (flag) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /* RRset exists. */
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews PREREQFAILNT(DNS_R_YXRRSET, name,
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews rdata.type,
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "'rrset does not exist' "
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "prerequisite not "
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "satisfied");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson } else if (update_class == zoneclass) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /* "temp<rr.name, rr.type> += rr;" */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = temp_append(&temp, name, &rdata);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson UNEXPECTED_ERROR(__FILE__, __LINE__,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson "temp entry creation failed: %s",
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_result_totext(result));
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff FAIL(ISC_R_UNEXPECTED);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson } else {
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews PREREQFAILC(DNS_R_FORMERR, "malformed prerequisite");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_NOMORE)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson FAIL(result);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /*
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Perform the final check of the "rrset exists (value dependent)"
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * prerequisites.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews if (ISC_LIST_HEAD(temp.tuples) != NULL) {
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews dns_rdatatype_t type;
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews /*
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews * Sort the prerequisite records by owner name,
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews * type, and rdata.
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews */
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews result = dns_diff_sort(&temp, temp_order);
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews if (result != ISC_R_SUCCESS)
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews FAILC(result, "'RRset exists (value dependent)' "
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews "prerequisite not satisfied");
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews dns_fixedname_init(&tmpnamefixed);
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews tmpname = dns_fixedname_name(&tmpnamefixed);
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews result = temp_check(mctx, &temp, db, ver, tmpname, &type);
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews if (result != ISC_R_SUCCESS)
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews FAILNT(result, tmpname, type,
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews "'RRset exists (value dependent)' "
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews "prerequisite not satisfied");
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson update_log(client, zone, LOGLEVEL_DEBUG,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "prerequisites are OK");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
8e8c5f7081695f2952f2cd5be2360253e060f6e1Andreas Gustafsson /*
8e8c5f7081695f2952f2cd5be2360253e060f6e1Andreas Gustafsson * Check Requestor's Permissions. It seems a bit silly to do this
8e8c5f7081695f2952f2cd5be2360253e060f6e1Andreas Gustafsson * only after prerequisite testing, but that is what RFC2136 says.
8e8c5f7081695f2952f2cd5be2360253e060f6e1Andreas Gustafsson */
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews if (ssutable == NULL)
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews CHECK(checkupdateacl(client, dns_zone_getupdateacl(zone),
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews "update", zonename, ISC_FALSE, ISC_FALSE));
92f60809e854ccf5f115883c6347e370da048848Mark Andrews else if (client->signer == NULL && !TCPCLIENT(client))
392cd518b3aff35c0396f84884cd51680edd68a1Mark Andrews CHECK(checkupdateacl(client, NULL, "update", zonename,
c5adbd722da0908f91be4fb710c082b4b68ec782Mark Andrews ISC_FALSE, ISC_TRUE));
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater
cde7dfea4c1267a2b526114f4ea80fe9db1fc557Brian Wellington if (dns_zone_getupdatedisabled(zone))
6e5e27c38d86f2338688f5123d2ff84558956dd0Mark Andrews FAILC(DNS_R_REFUSED, "dynamic update temporarily disabled "
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater "because the zone is frozen. Use "
6e5e27c38d86f2338688f5123d2ff84558956dd0Mark Andrews "'rndc thaw' to re-enable updates.");
d8c70cbcd78b808c7eb23b39ef0c17f2e22def2eAndreas Gustafsson
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence /*
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Perform the Update Section Prescan.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson for (result = dns_message_firstname(request, DNS_SECTION_UPDATE);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff result == ISC_R_SUCCESS;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_message_nextname(request, DNS_SECTION_UPDATE))
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_name_t *name = NULL;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews dns_rdata_t rdata = DNS_RDATA_INIT;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_ttl_t ttl;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_rdataclass_t update_class;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson get_current_rr(request, DNS_SECTION_UPDATE, zoneclass,
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley &name, &rdata, &covers, &ttl, &update_class);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (! dns_name_issubdomain(name, zonename))
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson FAILC(DNS_R_NOTZONE,
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "update RR is outside zone");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (update_class == zoneclass) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /*
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Check for meta-RRs. The RFC2136 pseudocode says
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * check for ANY|AXFR|MAILA|MAILB, but the text adds
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * "or any other QUERY metatype"
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (dns_rdatatype_ismeta(rdata.type)) {
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson FAILC(DNS_R_FORMERR,
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "meta-RR in update");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews result = dns_zone_checknames(zone, name, &rdata);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews if (result != ISC_R_SUCCESS)
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews FAIL(DNS_R_REFUSED);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson } else if (update_class == dns_rdataclass_any) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (ttl != 0 || rdata.length != 0 ||
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson (dns_rdatatype_ismeta(rdata.type) &&
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson rdata.type != dns_rdatatype_any))
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence FAILC(DNS_R_FORMERR,
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "meta-RR in update");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson } else if (update_class == dns_rdataclass_none) {
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence if (ttl != 0 ||
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdatatype_ismeta(rdata.type))
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence FAILC(DNS_R_FORMERR,
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "meta-RR in update");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson } else {
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson update_log(client, zone, ISC_LOG_WARNING,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "update RR has incorrect class %d",
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson update_class);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson FAIL(DNS_R_FORMERR);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson /*
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson * draft-ietf-dnsind-simple-secure-update-01 says
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson * "Unlike traditional dynamic update, the client
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews * is forbidden from updating NSEC records."
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson */
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if (rdata.type == dns_rdatatype_nsec3) {
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews FAILC(DNS_R_REFUSED,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews "explicit NSEC3 updates are not allowed "
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews "in secure zones");
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews } else if (rdata.type == dns_rdatatype_nsec) {
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews FAILC(DNS_R_REFUSED,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews "explicit NSEC updates are not allowed "
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews "in secure zones");
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews } else if (rdata.type == dns_rdatatype_rrsig &&
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews !dns_name_equal(name, zonename)) {
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews FAILC(DNS_R_REFUSED,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews "explicit RRSIG updates are currently "
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews "not supported in secure zones except "
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews "at the apex");
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson }
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington
92f60809e854ccf5f115883c6347e370da048848Mark Andrews if (ssutable != NULL) {
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt isc_netaddr_t netaddr;
71bd858d8ed62672e7c23999dc7c02fd16a55089Evan Hunt dst_key_t *tsigkey = NULL;
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt isc_netaddr_fromsockaddr(&netaddr, &client->peeraddr);
71bd858d8ed62672e7c23999dc7c02fd16a55089Evan Hunt
71bd858d8ed62672e7c23999dc7c02fd16a55089Evan Hunt if (client->message->tsigkey != NULL)
71bd858d8ed62672e7c23999dc7c02fd16a55089Evan Hunt tsigkey = client->message->tsigkey->key;
71bd858d8ed62672e7c23999dc7c02fd16a55089Evan Hunt
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington if (rdata.type != dns_rdatatype_any) {
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt if (!dns_ssutable_checkrules2
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt (ssutable, client->signer, name, &netaddr,
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt ISC_TF(TCPCLIENT(client)),
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt &ns_g_server->aclenv,
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt rdata.type, tsigkey))
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt {
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington FAILC(DNS_R_REFUSED,
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington "rejected by secure update");
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt }
92f60809e854ccf5f115883c6347e370da048848Mark Andrews } else {
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington if (!ssu_checkall(db, ver, name, ssutable,
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt client->signer,
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt &netaddr,
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt ISC_TF(TCPCLIENT(client)),
71bd858d8ed62672e7c23999dc7c02fd16a55089Evan Hunt tsigkey))
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt {
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington FAILC(DNS_R_REFUSED,
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington "rejected by secure update");
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt }
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington }
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_NOMORE)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson FAIL(result);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson update_log(client, zone, LOGLEVEL_DEBUG,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "update section prescan OK");
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence /*
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Process the Update Section.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
508f61f8d699c46f962b682f388e54b446a7194dMark Andrews options = dns_zone_getoptions(zone);
35f6a21f5f8114542c050bfcb484b39ce513d4bdEvan Hunt options2 = dns_zone_getoptions2(zone);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson for (result = dns_message_firstname(request, DNS_SECTION_UPDATE);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff result == ISC_R_SUCCESS;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_message_nextname(request, DNS_SECTION_UPDATE))
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_name_t *name = NULL;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews dns_rdata_t rdata = DNS_RDATA_INIT;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_ttl_t ttl;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdataclass_t update_class;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson isc_boolean_t flag;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson get_current_rr(request, DNS_SECTION_UPDATE, zoneclass,
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley &name, &rdata, &covers, &ttl, &update_class);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (update_class == zoneclass) {
11dbb6dc6b32c6316cb40c767701a24cfbc18326Mark Andrews
11dbb6dc6b32c6316cb40c767701a24cfbc18326Mark Andrews /*
6fb3db01acad7f5c1f4e23789fb0f2ce56cc07deMukund Sivaraman * RFC1123 doesn't allow MF and MD in master zones.
6fb3db01acad7f5c1f4e23789fb0f2ce56cc07deMukund Sivaraman */
11dbb6dc6b32c6316cb40c767701a24cfbc18326Mark Andrews if (rdata.type == dns_rdatatype_md ||
11dbb6dc6b32c6316cb40c767701a24cfbc18326Mark Andrews rdata.type == dns_rdatatype_mf) {
11dbb6dc6b32c6316cb40c767701a24cfbc18326Mark Andrews char typebuf[DNS_RDATATYPE_FORMATSIZE];
11dbb6dc6b32c6316cb40c767701a24cfbc18326Mark Andrews
11dbb6dc6b32c6316cb40c767701a24cfbc18326Mark Andrews dns_rdatatype_format(rdata.type, typebuf,
11dbb6dc6b32c6316cb40c767701a24cfbc18326Mark Andrews sizeof(typebuf));
11dbb6dc6b32c6316cb40c767701a24cfbc18326Mark Andrews update_log(client, zone, LOGLEVEL_PROTOCOL,
11dbb6dc6b32c6316cb40c767701a24cfbc18326Mark Andrews "attempt to add %s ignored",
11dbb6dc6b32c6316cb40c767701a24cfbc18326Mark Andrews typebuf);
11dbb6dc6b32c6316cb40c767701a24cfbc18326Mark Andrews continue;
11dbb6dc6b32c6316cb40c767701a24cfbc18326Mark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if ((rdata.type == dns_rdatatype_ns ||
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews rdata.type == dns_rdatatype_dname) &&
59ab128c972622f5aeafe3229966dcba73b62243Mark Andrews dns_name_iswildcard(name)) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews char typebuf[DNS_RDATATYPE_FORMATSIZE];
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_rdatatype_format(rdata.type, typebuf,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews sizeof(typebuf));
59ab128c972622f5aeafe3229966dcba73b62243Mark Andrews update_log(client, zone,
59ab128c972622f5aeafe3229966dcba73b62243Mark Andrews LOGLEVEL_PROTOCOL,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews "attempt to add wildcard %s record "
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews "ignored", typebuf);
59ab128c972622f5aeafe3229966dcba73b62243Mark Andrews continue;
59ab128c972622f5aeafe3229966dcba73b62243Mark Andrews }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (rdata.type == dns_rdatatype_cname) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson CHECK(cname_incompatible_rrset_exists(db, ver,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson name,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson &flag));
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (flag) {
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson update_log(client, zone,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson LOGLEVEL_PROTOCOL,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "attempt to add CNAME "
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "alongside non-CNAME "
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "ignored");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson continue;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson } else {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson CHECK(rrset_exists(db, ver, name,
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley dns_rdatatype_cname, 0,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson &flag));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence if (flag &&
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson ! dns_rdatatype_isdnssec(rdata.type))
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson {
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson update_log(client, zone,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson LOGLEVEL_PROTOCOL,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "attempt to add non-CNAME "
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "alongside CNAME ignored");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson continue;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (rdata.type == dns_rdatatype_soa) {
c6e66777242752532a094561fc728233cab9bc2fAndreas Gustafsson isc_boolean_t ok;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence CHECK(rrset_exists(db, ver, name,
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley dns_rdatatype_soa, 0,
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley &flag));
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (! flag) {
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson update_log(client, zone,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson LOGLEVEL_PROTOCOL,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "attempt to create 2nd "
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "SOA ignored");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson continue;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson CHECK(check_soa_increment(db, ver, &rdata,
c6e66777242752532a094561fc728233cab9bc2fAndreas Gustafsson &ok));
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (! ok) {
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson update_log(client, zone,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson LOGLEVEL_PROTOCOL,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "SOA update failed to "
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "increment serial, "
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "ignoring it");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson continue;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
c6e66777242752532a094561fc728233cab9bc2fAndreas Gustafsson soa_serial_changed = ISC_TRUE;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if (rdata.type == privatetype) {
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews update_log(client, zone, LOGLEVEL_PROTOCOL,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews "attempt to add a private type "
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews "(%u) record rejected internal "
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews "use only", privatetype);
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews continue;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews }
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (rdata.type == dns_rdatatype_nsec3param) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews /*
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Ignore attempts to add NSEC3PARAM records
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * with any flags other than OPTOUT.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
6fb3db01acad7f5c1f4e23789fb0f2ce56cc07deMukund Sivaraman if ((rdata.data[1] &
6fb3db01acad7f5c1f4e23789fb0f2ce56cc07deMukund Sivaraman ~DNS_NSEC3FLAG_OPTOUT) != 0)
6fb3db01acad7f5c1f4e23789fb0f2ce56cc07deMukund Sivaraman {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews update_log(client, zone,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews LOGLEVEL_PROTOCOL,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews "attempt to add NSEC3PARAM "
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews "record with non OPTOUT "
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews "flag");
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews continue;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
508f61f8d699c46f962b682f388e54b446a7194dMark Andrews if ((options & DNS_ZONEOPT_CHECKWILDCARD) != 0 &&
508f61f8d699c46f962b682f388e54b446a7194dMark Andrews dns_name_internalwildcard(name)) {
508f61f8d699c46f962b682f388e54b446a7194dMark Andrews char namestr[DNS_NAME_FORMATSIZE];
508f61f8d699c46f962b682f388e54b446a7194dMark Andrews dns_name_format(name, namestr,
508f61f8d699c46f962b682f388e54b446a7194dMark Andrews sizeof(namestr));
508f61f8d699c46f962b682f388e54b446a7194dMark Andrews update_log(client, zone, LOGLEVEL_PROTOCOL,
508f61f8d699c46f962b682f388e54b446a7194dMark Andrews "warning: ownername '%s' contains "
508f61f8d699c46f962b682f388e54b446a7194dMark Andrews "a non-terminal wildcard", namestr);
508f61f8d699c46f962b682f388e54b446a7194dMark Andrews }
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington
35f6a21f5f8114542c050bfcb484b39ce513d4bdEvan Hunt if ((options2 & DNS_ZONEOPT2_CHECKTTL) != 0) {
35f6a21f5f8114542c050bfcb484b39ce513d4bdEvan Hunt maxttl = dns_zone_getmaxttl(zone);
35f6a21f5f8114542c050bfcb484b39ce513d4bdEvan Hunt if (ttl > maxttl) {
35f6a21f5f8114542c050bfcb484b39ce513d4bdEvan Hunt ttl = maxttl;
35f6a21f5f8114542c050bfcb484b39ce513d4bdEvan Hunt update_log(client, zone,
35f6a21f5f8114542c050bfcb484b39ce513d4bdEvan Hunt LOGLEVEL_PROTOCOL,
35f6a21f5f8114542c050bfcb484b39ce513d4bdEvan Hunt "reducing TTL to the "
35f6a21f5f8114542c050bfcb484b39ce513d4bdEvan Hunt "configured max-zone-ttl %d",
35f6a21f5f8114542c050bfcb484b39ce513d4bdEvan Hunt maxttl);
35f6a21f5f8114542c050bfcb484b39ce513d4bdEvan Hunt }
35f6a21f5f8114542c050bfcb484b39ce513d4bdEvan Hunt }
35f6a21f5f8114542c050bfcb484b39ce513d4bdEvan Hunt
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington if (isc_log_wouldlog(ns_g_lctx, LOGLEVEL_PROTOCOL)) {
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington char namestr[DNS_NAME_FORMATSIZE];
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington char typestr[DNS_RDATATYPE_FORMATSIZE];
2425d8bb7ccf5dc956ad12d64d97b5a42e022930Evan Hunt char rdstr[2048];
c91c439f80c555f016cce8e9fd910630f81bb5c9Curtis Blackburn isc_buffer_t buf;
c91c439f80c555f016cce8e9fd910630f81bb5c9Curtis Blackburn int len = 0;
2425d8bb7ccf5dc956ad12d64d97b5a42e022930Evan Hunt const char *truncated = "";
2425d8bb7ccf5dc956ad12d64d97b5a42e022930Evan Hunt
c91c439f80c555f016cce8e9fd910630f81bb5c9Curtis Blackburn dns_name_format(name, namestr, sizeof(namestr));
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington dns_rdatatype_format(rdata.type, typestr,
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington sizeof(typestr));
c91c439f80c555f016cce8e9fd910630f81bb5c9Curtis Blackburn isc_buffer_init(&buf, rdstr, sizeof(rdstr));
c91c439f80c555f016cce8e9fd910630f81bb5c9Curtis Blackburn result = dns_rdata_totext(&rdata, NULL, &buf);
2425d8bb7ccf5dc956ad12d64d97b5a42e022930Evan Hunt if (result == ISC_R_NOSPACE) {
2425d8bb7ccf5dc956ad12d64d97b5a42e022930Evan Hunt len = (int)isc_buffer_usedlength(&buf);
2425d8bb7ccf5dc956ad12d64d97b5a42e022930Evan Hunt truncated = " [TRUNCATED]";
2425d8bb7ccf5dc956ad12d64d97b5a42e022930Evan Hunt } else if (result != ISC_R_SUCCESS) {
2425d8bb7ccf5dc956ad12d64d97b5a42e022930Evan Hunt snprintf(rdstr, sizeof(rdstr), "[dns_"
2425d8bb7ccf5dc956ad12d64d97b5a42e022930Evan Hunt "rdata_totext failed: %s]",
2425d8bb7ccf5dc956ad12d64d97b5a42e022930Evan Hunt dns_result_totext(result));
2425d8bb7ccf5dc956ad12d64d97b5a42e022930Evan Hunt len = strlen(rdstr);
2425d8bb7ccf5dc956ad12d64d97b5a42e022930Evan Hunt } else
2425d8bb7ccf5dc956ad12d64d97b5a42e022930Evan Hunt len = (int)isc_buffer_usedlength(&buf);
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews update_log(client, zone, LOGLEVEL_PROTOCOL,
2425d8bb7ccf5dc956ad12d64d97b5a42e022930Evan Hunt "adding an RR at '%s' %s %.*s%s",
2425d8bb7ccf5dc956ad12d64d97b5a42e022930Evan Hunt namestr, typestr, len, rdstr,
2425d8bb7ccf5dc956ad12d64d97b5a42e022930Evan Hunt truncated);
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington }
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson /* Prepare the affected RRset for the addition. */
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson {
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson add_rr_prepare_ctx_t ctx;
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson ctx.db = db;
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson ctx.ver = ver;
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson ctx.diff = &diff;
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson ctx.name = name;
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews ctx.oldname = name;
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson ctx.update_rr = &rdata;
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson ctx.update_rr_ttl = ttl;
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson ctx.ignore_add = ISC_FALSE;
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson dns_diff_init(mctx, &ctx.del_diff);
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson dns_diff_init(mctx, &ctx.add_diff);
38e8022ace865803bdd609c9763cd7d7ba2818dcMark Andrews CHECK(foreach_rr(db, ver, name, rdata.type,
38e8022ace865803bdd609c9763cd7d7ba2818dcMark Andrews covers, add_rr_prepare_action,
38e8022ace865803bdd609c9763cd7d7ba2818dcMark Andrews &ctx));
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson if (ctx.ignore_add) {
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson dns_diff_clear(&ctx.del_diff);
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson dns_diff_clear(&ctx.add_diff);
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson } else {
f5bb5eb7f6640af4a94e666bf1d7f84a6a7f1f23Mark Andrews result = do_diff(&ctx.del_diff, db, ver,
f5bb5eb7f6640af4a94e666bf1d7f84a6a7f1f23Mark Andrews &diff);
f5bb5eb7f6640af4a94e666bf1d7f84a6a7f1f23Mark Andrews if (result == ISC_R_SUCCESS) {
f5bb5eb7f6640af4a94e666bf1d7f84a6a7f1f23Mark Andrews result = do_diff(&ctx.add_diff,
f5bb5eb7f6640af4a94e666bf1d7f84a6a7f1f23Mark Andrews db, ver,
f5bb5eb7f6640af4a94e666bf1d7f84a6a7f1f23Mark Andrews &diff);
f5bb5eb7f6640af4a94e666bf1d7f84a6a7f1f23Mark Andrews }
f5bb5eb7f6640af4a94e666bf1d7f84a6a7f1f23Mark Andrews if (result != ISC_R_SUCCESS) {
f5bb5eb7f6640af4a94e666bf1d7f84a6a7f1f23Mark Andrews dns_diff_clear(&ctx.del_diff);
f5bb5eb7f6640af4a94e666bf1d7f84a6a7f1f23Mark Andrews dns_diff_clear(&ctx.add_diff);
f5bb5eb7f6640af4a94e666bf1d7f84a6a7f1f23Mark Andrews goto failure;
f5bb5eb7f6640af4a94e666bf1d7f84a6a7f1f23Mark Andrews }
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson CHECK(update_one_rr(db, ver, &diff,
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson DNS_DIFFOP_ADD,
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson name, ttl, &rdata));
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson } else if (update_class == dns_rdataclass_any) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (rdata.type == dns_rdatatype_any) {
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington if (isc_log_wouldlog(ns_g_lctx,
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington LOGLEVEL_PROTOCOL))
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington {
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington char namestr[DNS_NAME_FORMATSIZE];
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington dns_name_format(name, namestr,
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington sizeof(namestr));
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington update_log(client, zone,
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington LOGLEVEL_PROTOCOL,
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington "delete all rrsets from "
ec52edeff21c45e1469c2a74d78632e7d6fb0b52Andreas Gustafsson "name '%s'", namestr);
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (dns_name_equal(name, zonename)) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson CHECK(delete_if(type_not_soa_nor_ns_p,
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence db, ver, name,
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley dns_rdatatype_any, 0,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson &rdata, &diff));
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson } else {
055597532db52233e80f617b8b015e8caadcb577Mark Andrews CHECK(delete_if(type_not_dnssec,
055597532db52233e80f617b8b015e8caadcb577Mark Andrews db, ver, name,
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley dns_rdatatype_any, 0,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson &rdata, &diff));
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson } else if (dns_name_equal(name, zonename) &&
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson (rdata.type == dns_rdatatype_soa ||
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson rdata.type == dns_rdatatype_ns)) {
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews update_log(client, zone, LOGLEVEL_PROTOCOL,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "attempt to delete all SOA "
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "or NS records ignored");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson continue;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson } else {
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington if (isc_log_wouldlog(ns_g_lctx,
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington LOGLEVEL_PROTOCOL))
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington {
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington char namestr[DNS_NAME_FORMATSIZE];
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington char typestr[DNS_RDATATYPE_FORMATSIZE];
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington dns_name_format(name, namestr,
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington sizeof(namestr));
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington dns_rdatatype_format(rdata.type,
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington typestr,
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington sizeof(typestr));
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington update_log(client, zone,
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington LOGLEVEL_PROTOCOL,
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington "deleting rrset at '%s' %s",
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington namestr, typestr);
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson CHECK(delete_if(true_p, db, ver, name,
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley rdata.type, covers, &rdata,
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley &diff));
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson } else if (update_class == dns_rdataclass_none) {
88471538d69a7c21b8b9fd13b489399ad6c26597Mark Andrews char namestr[DNS_NAME_FORMATSIZE];
88471538d69a7c21b8b9fd13b489399ad6c26597Mark Andrews char typestr[DNS_RDATATYPE_FORMATSIZE];
88471538d69a7c21b8b9fd13b489399ad6c26597Mark Andrews
1a3d6530f67d4f6a53fd91d76d10ff14f84d2198Andreas Gustafsson /*
1a3d6530f67d4f6a53fd91d76d10ff14f84d2198Andreas Gustafsson * The (name == zonename) condition appears in
1a3d6530f67d4f6a53fd91d76d10ff14f84d2198Andreas Gustafsson * RFC2136 3.4.2.4 but is missing from the pseudocode.
1a3d6530f67d4f6a53fd91d76d10ff14f84d2198Andreas Gustafsson */
1a3d6530f67d4f6a53fd91d76d10ff14f84d2198Andreas Gustafsson if (dns_name_equal(name, zonename)) {
1a3d6530f67d4f6a53fd91d76d10ff14f84d2198Andreas Gustafsson if (rdata.type == dns_rdatatype_soa) {
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson update_log(client, zone,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson LOGLEVEL_PROTOCOL,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "attempt to delete SOA "
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "ignored");
1a3d6530f67d4f6a53fd91d76d10ff14f84d2198Andreas Gustafsson continue;
1a3d6530f67d4f6a53fd91d76d10ff14f84d2198Andreas Gustafsson }
1a3d6530f67d4f6a53fd91d76d10ff14f84d2198Andreas Gustafsson if (rdata.type == dns_rdatatype_ns) {
1a3d6530f67d4f6a53fd91d76d10ff14f84d2198Andreas Gustafsson int count;
1a3d6530f67d4f6a53fd91d76d10ff14f84d2198Andreas Gustafsson CHECK(rr_count(db, ver, name,
1a3d6530f67d4f6a53fd91d76d10ff14f84d2198Andreas Gustafsson dns_rdatatype_ns,
1a3d6530f67d4f6a53fd91d76d10ff14f84d2198Andreas Gustafsson 0, &count));
1a3d6530f67d4f6a53fd91d76d10ff14f84d2198Andreas Gustafsson if (count == 1) {
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson update_log(client, zone,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson LOGLEVEL_PROTOCOL,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "attempt to "
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "delete last "
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "NS ignored");
1a3d6530f67d4f6a53fd91d76d10ff14f84d2198Andreas Gustafsson continue;
1a3d6530f67d4f6a53fd91d76d10ff14f84d2198Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
88471538d69a7c21b8b9fd13b489399ad6c26597Mark Andrews dns_name_format(name, namestr, sizeof(namestr));
88471538d69a7c21b8b9fd13b489399ad6c26597Mark Andrews dns_rdatatype_format(rdata.type, typestr,
88471538d69a7c21b8b9fd13b489399ad6c26597Mark Andrews sizeof(typestr));
88471538d69a7c21b8b9fd13b489399ad6c26597Mark Andrews update_log(client, zone, LOGLEVEL_PROTOCOL,
88471538d69a7c21b8b9fd13b489399ad6c26597Mark Andrews "deleting an RR at %s %s", namestr, typestr);
88471538d69a7c21b8b9fd13b489399ad6c26597Mark Andrews CHECK(delete_if(rr_equal_p, db, ver, name, rdata.type,
88471538d69a7c21b8b9fd13b489399ad6c26597Mark Andrews covers, &rdata, &diff));
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_NOMORE)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson FAIL(result);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews /*
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Check that any changes to DNSKEY/NSEC3PARAM records make sense.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * If they don't then back out all changes to DNSKEY/NSEC3PARAM
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * records.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (! ISC_LIST_EMPTY(diff.tuples))
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(check_dnssec(client, zone, db, ver, &diff));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
5d850024cb41fdcb0b85efd3f7997bc52e6b33e8Mark Andrews if (! ISC_LIST_EMPTY(diff.tuples)) {
5d850024cb41fdcb0b85efd3f7997bc52e6b33e8Mark Andrews unsigned int errors = 0;
5d850024cb41fdcb0b85efd3f7997bc52e6b33e8Mark Andrews CHECK(dns_zone_nscheck(zone, db, ver, &errors));
5d850024cb41fdcb0b85efd3f7997bc52e6b33e8Mark Andrews if (errors != 0) {
5d850024cb41fdcb0b85efd3f7997bc52e6b33e8Mark Andrews update_log(client, zone, LOGLEVEL_PROTOCOL,
5d850024cb41fdcb0b85efd3f7997bc52e6b33e8Mark Andrews "update rejected: post update name server "
5d850024cb41fdcb0b85efd3f7997bc52e6b33e8Mark Andrews "sanity check failed");
5d850024cb41fdcb0b85efd3f7997bc52e6b33e8Mark Andrews result = DNS_R_REFUSED;
5d850024cb41fdcb0b85efd3f7997bc52e6b33e8Mark Andrews goto failure;
5d850024cb41fdcb0b85efd3f7997bc52e6b33e8Mark Andrews }
5d850024cb41fdcb0b85efd3f7997bc52e6b33e8Mark Andrews }
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews if (! ISC_LIST_EMPTY(diff.tuples)) {
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews result = dns_zone_cdscheck(zone, db, ver);
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews if (result == DNS_R_BADCDS || result == DNS_R_BADCDNSKEY) {
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews update_log(client, zone, LOGLEVEL_PROTOCOL,
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews "update rejected: bad %s RRset",
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews result == DNS_R_BADCDS ? "CDS" : "CDNSKEY");
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews result = DNS_R_REFUSED;
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews goto failure;
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews }
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews if (result != ISC_R_SUCCESS)
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews goto failure;
3813d22587681c16ad3a85a6e684558182aeb9f9Tinderbox User
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews }
5d850024cb41fdcb0b85efd3f7997bc52e6b33e8Mark Andrews
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /*
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson * If any changes were made, increment the SOA serial number,
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews * update RRSIGs and NSECs (if zone is secure), and write the update
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson * to the journal.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (! ISC_LIST_EMPTY(diff.tuples)) {
ea544b0511a66bc5f3700d56a72dcd808fdf22e8Brian Wellington char *journalfile;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_journal_t *journal;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews isc_boolean_t has_dnskey;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /*
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Increment the SOA serial, but only if it was not
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson * changed as a result of an update operation.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (! soa_serial_changed) {
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews CHECK(update_soa_serial(db, ver, &diff, mctx,
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews dns_zone_getserialupdatemethod(zone)));
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews CHECK(check_mx(client, zone, db, ver, &diff));
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
4411b9b6e77df22df8f033dc60ebe7e65990ce15Michael Graff CHECK(remove_orphaned_ds(db, ver, &diff));
4411b9b6e77df22df8f033dc60ebe7e65990ce15Michael Graff
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(rrset_exists(db, ver, zonename, dns_rdatatype_dnskey,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews 0, &has_dnskey));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews#define ALLOW_SECURE_TO_INSECURE(zone) \
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews ((dns_zone_getoptions(zone) & DNS_ZONEOPT_SECURETOINSECURE) != 0)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
b16d99bac1d100735224ab3eaa84632537ff21b5Mark Andrews CHECK(rrset_exists(db, oldver, zonename, dns_rdatatype_dnskey,
b16d99bac1d100735224ab3eaa84632537ff21b5Mark Andrews 0, &had_dnskey));
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if (!ALLOW_SECURE_TO_INSECURE(zone)) {
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if (had_dnskey && !has_dnskey) {
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews update_log(client, zone, LOGLEVEL_PROTOCOL,
8e4f3f1cbceef520ba889270c993de0ac376a2a7Evan Hunt "update rejected: all DNSKEY "
63aeaafd975c96e68a35c9e5d58d822b35c0f9d1Automatic Updater "records removed and "
63aeaafd975c96e68a35c9e5d58d822b35c0f9d1Automatic Updater "'dnssec-secure-to-insecure' "
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews "not set");
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews result = DNS_R_REFUSED;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews goto failure;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews CHECK(rollback_private(db, privatetype, ver, &diff));
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews CHECK(add_signing_records(db, privatetype, ver, &diff));
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews CHECK(add_nsec3param_records(client, zone, db, ver, &diff));
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt if (had_dnskey && !has_dnskey) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews /*
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * We are transitioning from secure to insecure.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Cause all NSEC3 chains to be deleted. When the
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * the last signature for the DNSKEY records are
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * remove any NSEC chain present will also be removed.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
8d31dd9ab62d91b5f23ac687657c966d44074a3fMark Andrews CHECK(dns_nsec3param_deletechains(db, ver, zone,
9c03f13e18c1b0c32f62391a17300378605bbc7bEvan Hunt ISC_TRUE, &diff));
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews } else if (has_dnskey && isdnssec(db, ver, privatetype)) {
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews isc_uint32_t interval;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_update_log_t log;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews interval = dns_zone_getsigvalidityinterval(zone);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews log.func = update_log_cb;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews log.arg = client;
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews result = dns_update_signatures(&log, zone, db, oldver,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews ver, &diff, interval);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS) {
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson update_log(client, zone,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson ISC_LOG_ERROR,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews "RRSIG/NSEC/NSEC3 update failed: %s",
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson isc_result_totext(result));
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson goto failure;
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson }
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson }
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews maxrecords = dns_zone_getmaxrecords(zone);
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews if (maxrecords != 0U) {
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews result = dns_db_getsize(db, ver, &records, NULL);
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews if (result == ISC_R_SUCCESS && records > maxrecords) {
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews update_log(client, zone, ISC_LOG_ERROR,
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews "records in zone (%"
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews ISC_PRINT_QUADFORMAT
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews "u) exceeds max-records (%u)",
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews records, maxrecords);
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews result = DNS_R_TOOMANYRECORDS;
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews goto failure;
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews }
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews }
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews
ea544b0511a66bc5f3700d56a72dcd808fdf22e8Brian Wellington journalfile = dns_zone_getjournal(zone);
ea544b0511a66bc5f3700d56a72dcd808fdf22e8Brian Wellington if (journalfile != NULL) {
ea544b0511a66bc5f3700d56a72dcd808fdf22e8Brian Wellington update_log(client, zone, LOGLEVEL_DEBUG,
ea544b0511a66bc5f3700d56a72dcd808fdf22e8Brian Wellington "writing journal %s", journalfile);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
ea544b0511a66bc5f3700d56a72dcd808fdf22e8Brian Wellington journal = NULL;
ea544b0511a66bc5f3700d56a72dcd808fdf22e8Brian Wellington result = dns_journal_open(mctx, journalfile,
f30785f506a522ed6a5e394af2bb13b6f883927eEvan Hunt DNS_JOURNAL_CREATE, &journal);
ea544b0511a66bc5f3700d56a72dcd808fdf22e8Brian Wellington if (result != ISC_R_SUCCESS)
ea544b0511a66bc5f3700d56a72dcd808fdf22e8Brian Wellington FAILS(result, "journal open failed");
ea544b0511a66bc5f3700d56a72dcd808fdf22e8Brian Wellington
ea544b0511a66bc5f3700d56a72dcd808fdf22e8Brian Wellington result = dns_journal_write_transaction(journal, &diff);
ea544b0511a66bc5f3700d56a72dcd808fdf22e8Brian Wellington if (result != ISC_R_SUCCESS) {
ea544b0511a66bc5f3700d56a72dcd808fdf22e8Brian Wellington dns_journal_destroy(&journal);
ea544b0511a66bc5f3700d56a72dcd808fdf22e8Brian Wellington FAILS(result, "journal write failed");
ea544b0511a66bc5f3700d56a72dcd808fdf22e8Brian Wellington }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_journal_destroy(&journal);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews /*
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews * XXXRTH Just a note that this committing code will have
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews * to change to handle databases that need two-phase
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews * commit, but this isn't a priority.
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews */
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews update_log(client, zone, LOGLEVEL_DEBUG,
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews "committing update transaction");
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews dns_db_closeversion(db, &ver, ISC_TRUE);
224553741e5eb5b614e6057fefbc26cf6d18440fAndreas Gustafsson
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews /*
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews * Mark the zone as dirty so that it will be written to disk.
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews */
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews dns_zone_markdirty(zone);
224553741e5eb5b614e6057fefbc26cf6d18440fAndreas Gustafsson
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews /*
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews * Notify slaves of the change we just made.
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews */
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews dns_zone_notify(zone);
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews /*
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Cause the zone to be signed with the key that we
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * have just added or have the corresponding signatures
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * deleted.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews *
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Note: we are already committed to this course of action.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews for (tuple = ISC_LIST_HEAD(diff.tuples);
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews tuple != NULL;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews tuple = ISC_LIST_NEXT(tuple, link)) {
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews isc_region_t r;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews dns_secalg_t algorithm;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews isc_uint16_t keyid;
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (tuple->rdata.type != dns_rdatatype_dnskey)
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews continue;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews dns_rdata_tostruct(&tuple->rdata, &dnskey, NULL);
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews if ((dnskey.flags &
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews (DNS_KEYFLAG_OWNERMASK|DNS_KEYTYPE_NOAUTH))
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews != DNS_KEYOWNER_ZONE)
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews continue;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews dns_rdata_toregion(&tuple->rdata, &r);
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews algorithm = dnskey.algorithm;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews keyid = dst_region_computeid(&r, algorithm);
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_zone_signwithkey(zone, algorithm, keyid,
6e2871232f7ede047799480370aff444be1f5a13Automatic Updater ISC_TF(tuple->op == DNS_DIFFOP_DEL));
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews if (result != ISC_R_SUCCESS) {
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews update_log(client, zone, ISC_LOG_ERROR,
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews "dns_zone_signwithkey failed: %s",
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews dns_result_totext(result));
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews }
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews /*
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Cause the zone to add/delete NSEC3 chains for the
b9d48991211415094ed6ea92d2084422104c6787Francis Dupont * deferred NSEC3PARAM changes.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews *
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Note: we are already committed to this course of action.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews for (tuple = ISC_LIST_HEAD(diff.tuples);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews tuple != NULL;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews tuple = ISC_LIST_NEXT(tuple, link)) {
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews unsigned char buf[DNS_NSEC3PARAM_BUFFERSIZE];
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_rdata_t rdata = DNS_RDATA_INIT;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_rdata_nsec3param_t nsec3param;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if (tuple->rdata.type != privatetype ||
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews tuple->op != DNS_DIFFOP_ADD)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews continue;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if (!dns_nsec3param_fromprivate(&tuple->rdata, &rdata,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews buf, sizeof(buf)))
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews continue;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_rdata_tostruct(&rdata, &nsec3param, NULL);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (nsec3param.flags == 0)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews continue;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_zone_addnsec3chain(zone, &nsec3param);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (result != ISC_R_SUCCESS) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews update_log(client, zone, ISC_LOG_ERROR,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews "dns_zone_addnsec3chain failed: %s",
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_result_totext(result));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews } else {
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews update_log(client, zone, LOGLEVEL_DEBUG, "redundant request");
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews dns_db_closeversion(db, &ver, ISC_TRUE);
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews }
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff result = ISC_R_SUCCESS;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson goto common;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson failure:
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence /*
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * The reason for failure should have been logged at this point.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (ver != NULL) {
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater update_log(client, zone, LOGLEVEL_DEBUG,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "rolling back");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_db_closeversion(db, &ver, ISC_FALSE);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson }
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson common:
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_diff_clear(&temp);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_diff_clear(&diff);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson if (oldver != NULL)
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson dns_db_closeversion(db, &oldver, ISC_FALSE);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (db != NULL)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_db_detach(&db);
d60f5b9bc8c1e1f7ddebc6c7834f7550a8e8be6fBob Halley
54477d367bb80484ba8e9ca4eac43c0c317d4968Brian Wellington if (ssutable != NULL)
54477d367bb80484ba8e9ca4eac43c0c317d4968Brian Wellington dns_ssutable_detach(&ssutable);
54477d367bb80484ba8e9ca4eac43c0c317d4968Brian Wellington
999ae80184e3df1016ac74514124b0459ace4d01Andreas Gustafsson isc_task_detach(&task);
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson uev->result = result;
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews if (zone != NULL)
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews INSIST(uev->zone == zone); /* we use this later */
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff uev->ev_type = DNS_EVENT_UPDATEDONE;
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff uev->ev_action = updatedone_action;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson isc_task_send(client->task, &event);
9c0589bc8b1401e02c9b557737cb756e86b094ffMark Andrews
9c0589bc8b1401e02c9b557737cb756e86b094ffMark Andrews INSIST(ver == NULL);
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson INSIST(event == NULL);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafssonstatic void
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrenceupdatedone_action(isc_task_t *task, isc_event_t *event) {
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson update_event_t *uev = (update_event_t *) event;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence ns_client_t *client = (ns_client_t *) event->ev_arg;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson
82ca33427bdd4f3bc4ed3431e86bd810fe751674Andreas Gustafsson UNUSED(task);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff INSIST(event->ev_type == DNS_EVENT_UPDATEDONE);
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson INSIST(task == client->task);
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson
c426fddf168a3cdfc1c4c162365d440c89148ae4Mark Andrews INSIST(client->nupdates > 0);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews switch (uev->result) {
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews case ISC_R_SUCCESS:
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(uev->zone, dns_nsstatscounter_updatedone);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews break;
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews case DNS_R_REFUSED:
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(uev->zone, dns_nsstatscounter_updaterej);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews break;
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews default:
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(uev->zone, dns_nsstatscounter_updatefail);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews break;
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews }
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews if (uev->zone != NULL)
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews dns_zone_detach(&uev->zone);
c426fddf168a3cdfc1c4c162365d440c89148ae4Mark Andrews client->nupdates--;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson respond(client, uev->result);
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson isc_event_free(&event);
e23932d3c8c154cff3fea0ecff64e26c6ac6f5d8Mark Andrews ns_client_detach(&client);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson}
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews * Update forwarding support.
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews */
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrewsstatic void
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrewsforward_fail(isc_task_t *task, isc_event_t *event) {
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews ns_client_t *client = (ns_client_t *)event->ev_arg;
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews UNUSED(task);
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews
c426fddf168a3cdfc1c4c162365d440c89148ae4Mark Andrews INSIST(client->nupdates > 0);
c426fddf168a3cdfc1c4c162365d440c89148ae4Mark Andrews client->nupdates--;
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews respond(client, DNS_R_SERVFAIL);
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews isc_event_free(&event);
e23932d3c8c154cff3fea0ecff64e26c6ac6f5d8Mark Andrews ns_client_detach(&client);
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews}
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrewsstatic void
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrewsforward_callback(void *arg, isc_result_t result, dns_message_t *answer) {
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews update_event_t *uev = arg;
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews ns_client_t *client = uev->ev_arg;
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews dns_zone_t *zone = uev->zone;
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews if (result != ISC_R_SUCCESS) {
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews INSIST(answer == NULL);
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews uev->ev_type = DNS_EVENT_UPDATEDONE;
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews uev->ev_action = forward_fail;
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(zone, dns_nsstatscounter_updatefwdfail);
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews } else {
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews uev->ev_type = DNS_EVENT_UPDATEDONE;
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews uev->ev_action = forward_done;
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews uev->answer = answer;
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(zone, dns_nsstatscounter_updaterespfwd);
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews }
42b48d11ca7b296324d7a8a98cdbf0070b0deb1dMark Andrews isc_task_send(client->task, ISC_EVENT_PTR(&uev));
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews dns_zone_detach(&zone);
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews}
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrewsstatic void
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrewsforward_done(isc_task_t *task, isc_event_t *event) {
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews update_event_t *uev = (update_event_t *) event;
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews ns_client_t *client = (ns_client_t *)event->ev_arg;
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews UNUSED(task);
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews
c426fddf168a3cdfc1c4c162365d440c89148ae4Mark Andrews INSIST(client->nupdates > 0);
c426fddf168a3cdfc1c4c162365d440c89148ae4Mark Andrews client->nupdates--;
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews ns_client_sendraw(client, uev->answer);
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews dns_message_destroy(&uev->answer);
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews isc_event_free(&event);
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews ns_client_detach(&client);
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews}
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrewsstatic void
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrewsforward_action(isc_task_t *task, isc_event_t *event) {
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews update_event_t *uev = (update_event_t *) event;
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews dns_zone_t *zone = uev->zone;
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews ns_client_t *client = (ns_client_t *)event->ev_arg;
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews isc_result_t result;
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews result = dns_zone_forwardupdate(zone, client->message,
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews forward_callback, event);
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews if (result != ISC_R_SUCCESS) {
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews uev->ev_type = DNS_EVENT_UPDATEDONE;
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews uev->ev_action = forward_fail;
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrews isc_task_send(client->task, &event);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(zone, dns_nsstatscounter_updatefwdfail);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews dns_zone_detach(&zone);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews } else
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(zone, dns_nsstatscounter_updatereqfwd);
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews isc_task_detach(&task);
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews}
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrewsstatic isc_result_t
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrewssend_forward_event(ns_client_t *client, dns_zone_t *zone) {
34f3693b93f3ba16634f0c08368ef7f81182ef93Evan Hunt char namebuf[DNS_NAME_FORMATSIZE];
34f3693b93f3ba16634f0c08368ef7f81182ef93Evan Hunt char classbuf[DNS_RDATACLASS_FORMATSIZE];
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews isc_result_t result = ISC_R_SUCCESS;
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews update_event_t *event = NULL;
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews isc_task_t *zonetask = NULL;
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews ns_client_t *evclient;
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews
2c35c682362049f823248542e07e7dca4008b986Mark Andrews /*
2c35c682362049f823248542e07e7dca4008b986Mark Andrews * This may take some time so replace this client.
2c35c682362049f823248542e07e7dca4008b986Mark Andrews */
2c35c682362049f823248542e07e7dca4008b986Mark Andrews if (!client->mortal && (client->attributes & NS_CLIENTATTR_TCP) == 0)
2c35c682362049f823248542e07e7dca4008b986Mark Andrews CHECK(ns_client_replace(client));
2c35c682362049f823248542e07e7dca4008b986Mark Andrews
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews event = (update_event_t *)
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews isc_event_allocate(client->mctx, client, DNS_EVENT_UPDATE,
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews forward_action, NULL, sizeof(*event));
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews if (event == NULL)
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews FAIL(ISC_R_NOMEMORY);
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews event->zone = zone;
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews event->result = ISC_R_SUCCESS;
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews evclient = NULL;
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews ns_client_attach(client, &evclient);
c426fddf168a3cdfc1c4c162365d440c89148ae4Mark Andrews INSIST(client->nupdates == 0);
c426fddf168a3cdfc1c4c162365d440c89148ae4Mark Andrews client->nupdates++;
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews event->ev_arg = evclient;
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews
34f3693b93f3ba16634f0c08368ef7f81182ef93Evan Hunt dns_name_format(dns_zone_getorigin(zone), namebuf,
34f3693b93f3ba16634f0c08368ef7f81182ef93Evan Hunt sizeof(namebuf));
34f3693b93f3ba16634f0c08368ef7f81182ef93Evan Hunt dns_rdataclass_format(dns_zone_getclass(zone), classbuf,
34f3693b93f3ba16634f0c08368ef7f81182ef93Evan Hunt sizeof(classbuf));
34f3693b93f3ba16634f0c08368ef7f81182ef93Evan Hunt
34f3693b93f3ba16634f0c08368ef7f81182ef93Evan Hunt ns_client_log(client, NS_LOGCATEGORY_UPDATE, NS_LOGMODULE_UPDATE,
34f3693b93f3ba16634f0c08368ef7f81182ef93Evan Hunt LOGLEVEL_PROTOCOL, "forwarding update for zone '%s/%s'",
34f3693b93f3ba16634f0c08368ef7f81182ef93Evan Hunt namebuf, classbuf);
34f3693b93f3ba16634f0c08368ef7f81182ef93Evan Hunt
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews dns_zone_gettask(zone, &zonetask);
42b48d11ca7b296324d7a8a98cdbf0070b0deb1dMark Andrews isc_task_send(zonetask, ISC_EVENT_PTR(&event));
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews failure:
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews if (event != NULL)
42b48d11ca7b296324d7a8a98cdbf0070b0deb1dMark Andrews isc_event_free(ISC_EVENT_PTR(&event));
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews return (result);
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews}