93ca8abdf86dfe69d40c0bc5389151e0672780afTinderbox User * Copyright (C) 1999-2018 Internet Systems Consortium, Inc. ("ISC")
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/.
f30785f506a522ed6a5e394af2bb13b6f883927eEvan Hunt/* $Id: update.c,v 1.199 2011/12/22 07:32:40 each Exp $ */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * This module implements dynamic update as in RFC2136.
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews * - document strict minimality
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson/**************************************************************************/
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson * Log level for tracing dynamic update protocol requests.
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson * Log level for low-level debug tracing.
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 * 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 * 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 * 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".
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(zone, dns_nsstatscounter_updatebadprereq); \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews if (isc_log_wouldlog(ns_g_lctx, LOGLEVEL_PROTOCOL)) { \
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(zone, dns_nsstatscounter_updatebadprereq); \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews if (isc_log_wouldlog(ns_g_lctx, LOGLEVEL_PROTOCOL)) { \
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews dns_rdatatype_format(type, _tbuf, sizeof(_tbuf)); \
64cc9c8818db2552cbdd77f1050e890ffa5a17d8Mark Andrews "update %s: %s/%s: %s (%s)", \
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(zone, dns_nsstatscounter_updatebadprereq); \
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".
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews "error: %s: %s", \
b9d48991211415094ed6ea92d2084422104c6787Francis Dupont * Return TRUE if NS_CLIENTATTR_TCP is set in the attributes other FALSE.
92f60809e854ccf5f115883c6347e370da048848Mark Andrews#define TCPCLIENT(client) (((client)->attributes & NS_CLIENTATTR_TCP) != 0)
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson/**************************************************************************/
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /* dns_name_t name; */
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafssontypedef struct update_event update_event_t;
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 Andrewstypedef struct {
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson/**************************************************************************/
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson * Forward declarations.
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);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson/**************************************************************************/
ec52edeff21c45e1469c2a74d78632e7d6fb0b52Andreas Gustafssonupdate_log(ns_client_t *client, dns_zone_t *zone,
ec52edeff21c45e1469c2a74d78632e7d6fb0b52Andreas Gustafsson int level, const char *fmt, ...) ISC_FORMAT_PRINTF(4, 5);
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafssonupdate_log(ns_client_t *client, dns_zone_t *zone,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson char classbuf[DNS_RDATACLASS_FORMATSIZE];
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson if (isc_log_wouldlog(ns_g_lctx, level) == ISC_FALSE)
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson dns_name_format(dns_zone_getorigin(zone), namebuf,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson dns_rdataclass_format(dns_zone_getclass(zone), classbuf,
2f734e0a7e518c89c2b2b179714b8885b7626b3aAndreas Gustafsson vsnprintf(message, sizeof(message), fmt, ap);
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson ns_client_log(client, NS_LOGCATEGORY_UPDATE, NS_LOGMODULE_UPDATE,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrewsupdate_log_cb(void *arg, dns_zone_t *zone, int level, const char *message) {
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews * Increment updated-related statistics counters.
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);
d9059b0c38bd630c367d81424d72b1308cd74b04Tatuya JINMEI 神明達哉 isc_stats_t *zonestats = dns_zone_getrequeststats(zone);
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 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 result = ns_client_checkaclsilent(client, NULL, queryacl, ISC_TRUE);
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews dns_name_format(zonename, namebuf, sizeof(namebuf));
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews dns_rdataclass_format(client->view->rdclass, classbuf,
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews level = (updateacl == NULL && ssutable == NULL) ?
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews ns_client_log(client, NS_LOGCATEGORY_UPDATE_SECURITY,
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews "update '%s/%s' denied due to allow-query",
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,
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews ns_client_log(client, NS_LOGCATEGORY_UPDATE_SECURITY,
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 * '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 * If the request was signed log that we received it.
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrewscheckupdateacl(ns_client_t *client, dns_acl_t *acl, const char *message,
819b98479eff49ed93f57f4d65eb0ffe72136adcMark Andrews result = ns_client_checkaclsilent(client, NULL, acl, ISC_FALSE);
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews dns_name_format(client->signer, namebuf, sizeof(namebuf));
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews ns_client_log(client, NS_LOGCATEGORY_UPDATE_SECURITY,
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews dns_name_format(zonename, namebuf, sizeof(namebuf));
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews dns_rdataclass_format(client->view->rdclass, classbuf,
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews ns_client_log(client, NS_LOGCATEGORY_UPDATE_SECURITY,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Update a single RR in version 'ver' of 'db' and log the
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * update in 'diff'.
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews * \li '*tuple' == NULL. Either the tuple is freed, or its
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews * ownership has been transferred to the diff.
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrewsdo_one_tuple(dns_difftuple_t **tuple, dns_db_t *db, dns_dbversion_t *ver,
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Create a singleton diff.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson ISC_LIST_APPEND(temp_diff.tuples, *tuple, link);
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Apply it to the database.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_diff_apply(&temp_diff, db, ver);
cf573ce6fb91d8d514425849c73cdbc2096d97e1Mark Andrews ISC_LIST_UNLINK(temp_diff.tuples, *tuple, link);
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Merge it into the current pending journal entry.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Do not clear temp_diff.
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson * Perform the updates in 'updates' in version 'ver' of 'db' and log the
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson * update in 'diff'.
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews * \li 'updates' is empty.
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafssondo_diff(dns_diff_t *updates, dns_db_t *db, dns_dbversion_t *ver,
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);
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,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_difftuple_create(diff->mctx, op,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (do_one_tuple(&tuple, db, ver, diff));
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson/**************************************************************************/
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Callback-style iteration over rdatasets and rdatas.
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 * 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 * XXXRTH We might want to make this public somewhere in libdns.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Function type for foreach_rrset() iterator actions.
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Grafftypedef isc_result_t rrset_func(void *data, dns_rdataset_t *rrset);
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Function type for foreach_rr() iterator actions.
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Grafftypedef isc_result_t rr_func(void *data, rr_t *rr);
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Internal context struct for foreach_node_rr().
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssontypedef struct {
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Internal helper function for foreach_node_rr().
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrenceforeach_node_rr_action(void *data, dns_rdataset_t *rdataset) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson for (result = dns_rdataset_first(rdataset);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdataset_current(rdataset, &rr.rdata);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = (*ctx->rr_action)(ctx->rr_action_data, &rr);
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 * If 'action' returns an error, abort iteration and return the error.
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrewsforeach_rrset(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name,
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt dns_clientinfomethods_init(&cm, ns_client_sourceip);
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt * Only set the clientinfo 'versionp' if the new version is
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt * different from the current version
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt dns_clientinfo_init(&ci, NULL, (ver != oldver) ? ver : NULL);
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt result = dns_db_findnodeext(db, name, ISC_FALSE, &cm, &ci, &node);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_db_allrdatasets(db, node, ver,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson for (result = dns_rdatasetiter_first(iter);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdatasetiter_current(iter, &rdataset);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = (*action)(action_data, &rdataset);
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 * If 'action' returns an error, abort iteration
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * and return the error.
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrewsforeach_node_rr(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name,
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 * If 'action' returns an error, abort iteration and return the error.
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,
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt dns_clientinfomethods_init(&cm, ns_client_sourceip);
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt * Only set the clientinfo 'versionp' if the new version is
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt * different from the current version
aefb3e308ba01ad47a3d3aaadf77a5edd4261cb9Evan Hunt dns_clientinfo_init(&ci, NULL, (ver != oldver) ? ver : NULL);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews (type == dns_rdatatype_rrsig && covers == dns_rdatatype_nsec3))
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_db_findnsec3node(db, name, ISC_FALSE, &node);
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley result = dns_db_findrdataset(db, node, ver, type, covers,
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews dns_rdataset_getownercase(&rdataset, ctx->oldname);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson for (result = dns_rdataset_first(&rdataset);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_rdataset_current(&rdataset, &rr.rdata);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = (*rr_action)(rr_action_data, &rr);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson/**************************************************************************/
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Various tests on the database contents (for prerequisites, etc).
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Function type for predicate functions that compare a database RR 'db_rr'
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * against an update RR 'update_rr'.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssontypedef isc_boolean_t rr_predicate(dns_rdata_t *update_rr, dns_rdata_t *db_rr);
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Helper function for rrset_exists().
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson * Utility macro for RR existence checking functions.
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 * If 'result' has any other value, there was a failure.
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson * Return the failure result code and do not set *exists.
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.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Set '*exists' to true iff an rrset of the given type exists,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * to false otherwise.
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrewsrrset_exists(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name,
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Helper function for cname_incompatible_rrset_exists.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrencecname_compatibility_action(void *data, dns_rdataset_t *rrset) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (rrset->type != dns_rdatatype_cname &&
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 * If such an incompatible rrset exists, set '*exists' to ISC_TRUE.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Otherwise, set it to ISC_FALSE.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssoncname_incompatible_rrset_exists(dns_db_t *db, dns_dbversion_t *ver,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_name_t *name, isc_boolean_t *exists) {
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Helper function for rr_count().
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Count the number of RRs of 'type' belonging to 'name' in 'ver' of 'db'.
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)
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Context struct and helper function for name_exists().
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrencename_exists_action(void *data, dns_rdataset_t *rrset) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Set '*exists' to true iff the given name exists, to false otherwise.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssonname_exists(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name,
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().
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellingtontypedef struct {
92f60809e854ccf5f115883c6347e370da048848Mark Andrews /* The ownername of the record to be updated. */
92f60809e854ccf5f115883c6347e370da048848Mark Andrews /* The signature's name if the request was signed. */
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt /* The address of the client. */
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt /* Whether the request was sent via TCP. */
92f60809e854ccf5f115883c6347e370da048848Mark Andrews /* The ssu table to check against. */
71bd858d8ed62672e7c23999dc7c02fd16a55089Evan Hunt /* the key used for TKEY requests */
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrencessu_checkrule(void *data, dns_rdataset_t *rrset) {
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.
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt result = dns_ssutable_checkrules2(ssuinfo->table, ssuinfo->signer,
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington return (result == ISC_TRUE ? ISC_R_SUCCESS : ISC_R_FAILURE);
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellingtonssu_checkall(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name,
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt isc_netaddr_t *addr, isc_boolean_t tcp, dst_key_t *key)
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington result = foreach_rrset(db, ver, name, ssu_checkrule, &ssuinfo);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson/**************************************************************************/
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Checking of "RRset exists (value dependent)" prerequisites.
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.
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 * Append a tuple asserting the existence of the RR with
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * 'name' and 'rdata' to 'diff'.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrencetemp_append(dns_diff_t *diff, dns_name_t *name, dns_rdata_t *rdata) {
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson CHECK(dns_difftuple_create(diff->mctx, DNS_DIFFOP_EXISTS,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson ISC_LIST_APPEND(diff->tuples, tuple, link);
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 Gustafssontemp_check_rrset(dns_difftuple_t *a, dns_difftuple_t *b) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson INSIST(dns_name_equal(&a->name, &b->name));
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews if (dns_rdata_casecompare(&a->rdata, &b->rdata) != 0)
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 r = dns_name_compare(&a->name, &b->name);
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews r = dns_rdata_casecompare(&a->rdata, &b->rdata);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Check the "RRset exists (value dependent)" prerequisite information
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * in 'temp' against the contents of the database 'db'.
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff * Return ISC_R_SUCCESS if the prerequisites are satisfied,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * rcode(dns_rcode_nxrrset) if not.
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews * 'temp' must be pre-sorted.
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 * 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 while (t != NULL) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /* A new unique name begins here. */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_db_findnode(db, name, ISC_FALSE, &node);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence /* A new unique type begins here. */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson while (t != NULL && dns_name_equal(&t->name, name)) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson this name and type */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson this name and type */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Collect all database RRs for this name and type
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * onto d_rrs and sort them.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_db_findrdataset(db, node, ver, type,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson for (result = dns_rdataset_first(&rdataset);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = temp_append(&d_rrs, name, &rdata);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_diff_sort(&d_rrs, temp_order);
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 while (t != NULL &&
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /* Compare the two sorted lists. */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = temp_check_rrset(ISC_LIST_HEAD(u_rrs.tuples),
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 ISC_LIST_APPENDLIST(trash.tuples, u_rrs.tuples, link);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson ISC_LIST_APPENDLIST(trash.tuples, d_rrs.tuples, link);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson/**************************************************************************/
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Conditional deletion of RRs.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Context structure for delete_if().
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssontypedef struct {
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Predicate functions for delete_if().
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 Lawrencetype_not_soa_nor_ns_p(dns_rdata_t *update_rr, dns_rdata_t *db_rr) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return ((db_rr->type != dns_rdatatype_soa &&
055597532db52233e80f617b8b015e8caadcb577Mark Andrews * Return true iff 'db_rr' is neither a RRSIG nor a NSEC.
055597532db52233e80f617b8b015e8caadcb577Mark Andrewstype_not_dnssec(dns_rdata_t *update_rr, dns_rdata_t *db_rr) {
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Return true always.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrencetrue_p(dns_rdata_t *update_rr, dns_rdata_t *db_rr) {
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Return true iff the two RRs have identical rdata.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssonrr_equal_p(dns_rdata_t *update_rr, dns_rdata_t *db_rr) {
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.
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews return (dns_rdata_casecompare(update_rr, db_rr) == 0 ?
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.
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 * 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 Gustafssonreplaces_p(dns_rdata_t *update_rr, dns_rdata_t *db_rr) {
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews * Replace existing RRSIG with the same keyid,
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews * covered and algorithm.
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews result = dns_rdata_tostruct(db_rr, &dbsig, NULL);
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews result = dns_rdata_tostruct(update_rr, &updatesig, NULL);
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 INSIST(db_rr->length >= 5 && update_rr->length >= 5);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (memcmp(db_rr->data, update_rr->data, 5) == 0 ?
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews INSIST(db_rr->length >= 4 && update_rr->length >= 4);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * Replace NSEC3PARAM records that only differ by the
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * flags field.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Internal helper function for delete_if().
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if ((*ctx->predicate)(ctx->update_rr, &rr->rdata)) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = update_one_rr(ctx->db, ctx->ver, ctx->diff,
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 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 return (foreach_rr(db, ver, name, type, covers,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews/**************************************************************************/
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews * Are the new and old cases equal?
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews case_equal = dns_name_caseequal(ctx->name, ctx->oldname);
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews * Are the ttl's equal?
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews * If the update RR is a "duplicate" of a existing RR,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * the update should be silently ignored.
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews equal = ISC_TF(dns_rdata_casecompare(&rr->rdata, ctx->update_rr) == 0);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * If this RR is "equal" to the update RR, it should
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * be deleted before the update RR is added.
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews CHECK(dns_difftuple_create(ctx->del_diff.mctx, DNS_DIFFOP_DEL,
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 CHECK(dns_difftuple_create(ctx->del_diff.mctx, DNS_DIFFOP_DEL,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews/**************************************************************************/
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * Miscellaneous subroutines.
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * Extract a single update RR from 'section' of dynamic update message
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * 'msg', with consistency checking.
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * Stores the owner name, rdata, and TTL of the update RR at 'name',
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * 'rdata', and 'ttl', respectively.
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrewsget_current_rr(dns_message_t *msg, dns_section_t section,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews dns_ttl_t *ttl, dns_rdataclass_t *update_class)
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews INSIST(dns_rdataset_next(rdataset) == ISC_R_NOMORE);
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 * 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().
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrewsupdate_soa_serial(dns_db_t *db, dns_dbversion_t *ver, dns_diff_t *diff,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews CHECK(dns_db_createsoatuple(db, ver, mctx, DNS_DIFFOP_DEL, &deltuple));
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews CHECK(dns_difftuple_copy(deltuple, &addtuple));
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 * Sets '*ok' to ISC_TRUE if the update is legal, ISC_FALSE if not.
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * William King points out that RFC2136 is inconsistent about
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * the case where the serial number stays unchanged:
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 * 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 * Paul says 3.4.2.2 is correct.
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrewscheck_soa_increment(dns_db_t *db, dns_dbversion_t *ver,
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews update_serial = dns_soa_getserial(update_rdata);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews result = dns_db_getsoaserial(db, ver, &db_serial);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson/**************************************************************************/
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * The actual update code in all its glory. We try to follow
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * the RFC2136 pseudocode as closely as possible.
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafssonsend_update_event(ns_client_t *client, dns_zone_t *zone) {
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson isc_event_allocate(client->mctx, client, DNS_EVENT_UPDATE,
42b48d11ca7b296324d7a8a98cdbf0070b0deb1dMark Andrews isc_task_send(zonetask, ISC_EVENT_PTR(&event));
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffrespond(ns_client_t *client, isc_result_t result) {
26e1af486a8c56671aebda6d3f256364e49117b3Brian Wellington msg_result = dns_message_reply(client->message, ISC_TRUE);
26e1af486a8c56671aebda6d3f256364e49117b3Brian Wellington client->message->rcode = dns_result_torcode(result);
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson isc_log_write(ns_g_lctx, NS_LOGCATEGORY_UPDATE, NS_LOGMODULE_UPDATE,
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "could not create update response message: %s",
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrewsns_update_start(ns_client_t *client, isc_result_t sigresult) {
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson dns_message_t *request = client->message;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Interpret the zone section.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_message_firstname(request, DNS_SECTION_ZONE);
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews FAILC(DNS_R_FORMERR, "update zone section empty");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * The zone section must contain exactly one "question", and
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * it must be of type SOA.
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 "update zone section contains non-SOA");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (ISC_LIST_NEXT(zone_rdataset, link) != NULL)
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "update zone section contains multiple RRs");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /* The zone section must have exactly one name. */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_message_nextname(request, DNS_SECTION_ZONE);
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "update zone section contains multiple RRs");
e2fe0815b3c33c5c2c70b11329ac213f4deb18ebBob Halley result = dns_zt_find(client->view->zonetable, zonename, 0, NULL,
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews FAILC(DNS_R_NOTAUTH, "not authoritative for update zone");
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * If there is a raw (unsigned) zone associated with this
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews * zone then it processes the UPDATE request.
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews * We can now fail due to a bad signature as we now know
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews * that we are the master.
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews CHECK(checkupdateacl(client, dns_zone_getforwardacl(zone),
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews FAILC(DNS_R_NOTAUTH, "not authoritative for update zone");
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews INSIST(dns_zone_gettype(zone) == dns_zone_slave);
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.
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".
4411b9b6e77df22df8f033dc60ebe7e65990ce15Michael Graffremove_orphaned_ds(dns_db_t *db, dns_dbversion_t *newver, dns_diff_t *diff) {
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews !dns_name_equal(&tupple->name, dns_db_origin(db)))
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews CHECK(delete_if(true_p, db, newver, &tupple->name,
47323be2afd461c2b0d44400907f3ac020488080Mark Andrews ISC_LIST_UNLINK(temp_diff.tuples, tupple, link);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews * This implements the post load integrity checks for mx records.
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_db_t *db, dns_dbversion_t *newver, dns_diff_t *diff)
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews char tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:123.123.123.123.")];
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews result = dns_rdata_tostruct(&t->rdata, &mx, NULL);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews * Check if we will error out if we attempt to reload the
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_name_format(&mx.mx, namebuf, sizeof(namebuf));
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_name_format(&t->name, ownerbuf, sizeof(ownerbuf));
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews strlcpy(tmp, namebuf, sizeof(tmp)) < sizeof(tmp)) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews if (isaddress && (options & DNS_RDATA_CHECKMXFAIL) != 0) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews "%s/MX: '%s': %s",
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews "%s/MX: warning: '%s': %s",
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews * Check zone integrity checks.
2c15fcdeac4c2402258867fbac24d7475ef98259Mark Andrews if ((options & DNS_ZONEOPT_CHECKINTEGRITY) == 0)
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews result = dns_db_find(db, &mx.mx, newver, dns_rdatatype_a,
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews if (result == DNS_R_NXRRSET || result == DNS_R_NXDOMAIN) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews "%s/MX '%s' has no address records "
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews "%s/MX '%s' is a CNAME (illegal)",
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_name_format(foundname, altbuf, sizeof altbuf);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews "%s/MX '%s' is below a DNAME '%s' (illegal)",
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsrr_exists(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(dns_db_findnsec3node(db, name, ISC_FALSE, &node));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(dns_db_findnode(db, name, ISC_FALSE, &node));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_db_findrdataset(db, node, ver, rdata->type, 0,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrewsget_iterations(dns_db_t *db, dns_dbversion_t *ver, dns_rdatatype_t privatetype,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews unsigned int *iterationsp)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_db_findrdataset(db, node, ver, dns_rdatatype_nsec3param,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews CHECK(dns_rdata_tostruct(&rdata, &nsec3param, NULL));
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if ((nsec3param.flags & DNS_NSEC3FLAG_REMOVE) != 0)
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews result = dns_db_findrdataset(db, node, ver, privatetype,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if (!dns_nsec3param_fromprivate(&private, &rdata,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(dns_rdata_tostruct(&rdata, &nsec3param, NULL));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if ((nsec3param.flags & DNS_NSEC3FLAG_REMOVE) != 0)
b9d48991211415094ed6ea92d2084422104c6787Francis Dupont * Prevent the zone entering a inconsistent state where
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * NSEC only DNSKEYs are present with NSEC3 chains.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewscheck_dnssec(ns_client_t *client, dns_zone_t *zone, dns_db_t *db,
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt isc_boolean_t nseconly = ISC_FALSE, nsec3 = ISC_FALSE;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_rdatatype_t privatetype = dns_zone_getprivatetype(zone);
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt /* Scan the tuples for an NSEC-only DNSKEY or an NSEC3PARAM */
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt if (alg == DST_ALG_RSAMD5 || alg == DST_ALG_RSASHA1 ||
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt } else if (tuple->rdata.type == dns_rdatatype_nsec3param) {
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt /* Check existing DB for NSEC-only DNSKEY */
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.
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt /* Check existing DB for NSEC3 */
4e55893d307162770fbd7e0967043f0aef9d7583Evan Hunt /* Refuse to allow NSEC3 with NSEC-only keys */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews "NSEC only DNSKEYs and NSEC3 chains not allowed");
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 "too many NSEC3 iterations (%u) for "
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Delay NSEC3PARAM changes as they need to be applied to the whole zone.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsadd_nsec3param_records(ns_client_t *client, dns_zone_t *zone, dns_db_t *db,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_difftuple_t *tuple, *newtuple = NULL, *next;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews unsigned char buf[DNS_NSEC3PARAM_BUFFERSIZE + 1];
cf5770e7b13ee510b9201fa53b86649da23eca0eMark Andrews dns_rdatatype_t privatetype = dns_zone_getprivatetype(zone);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews "checking for NSEC3PARAM changes");
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Extract NSEC3PARAM tuples from list.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (tuple->rdata.type != dns_rdatatype_nsec3param ||
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews ISC_LIST_APPEND(temp_diff.tuples, tuple, link);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * Extract TTL changes pairs, we don't need to convert these to
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * delayed changes.
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * Any adds here will contain the final
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * NSEC3PARAM RRset TTL.
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * Walk the temp_diff list looking for the
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * corresponding delete.
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * If we have not found a pair move onto the next
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * Find the next tuple to be processed before
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * unlinking then complete moving the pair to 'diff'.
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews ISC_LIST_UNLINK(temp_diff.tuples, tuple, link);
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater * Preserve any ongoing changes from a BIND 9.6.x upgrade.
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 for (tuple = ISC_LIST_HEAD(temp_diff.tuples);
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater if ((tuple->rdata.data[1] & ~DNS_NSEC3FLAG_OPTOUT) != 0) {
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.
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater CHECK(dns_difftuple_create(diff->mctx, op, name,
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater CHECK(do_one_tuple(&newtuple, db, ver, diff));
a4b8846651354cb55e700124bb4b0b83c29a7d1aAutomatic Updater ISC_LIST_UNLINK(temp_diff.tuples, tuple, link);
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 * 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 * 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
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * Create a private-type record to signal that
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * we want a delayed NSEC3 chain add/delete
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_nsec3param_toprivate(&tuple->rdata, &rdata,
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 * See if this CREATE request already exists.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(rr_exists(db, ver, name, &rdata, &flag));
57fb4f7bbec88bc6431a39d4a10f82c265798b1fMark Andrews * Remove any existing CREATE request to add an
57fb4f7bbec88bc6431a39d4a10f82c265798b1fMark Andrews * otherwise indentical chain with a reversed
57fb4f7bbec88bc6431a39d4a10f82c265798b1fMark Andrews * OPTOUT state.
57fb4f7bbec88bc6431a39d4a10f82c265798b1fMark Andrews CHECK(rr_exists(db, ver, name, &rdata, &flag));
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * Find the next tuple to be processed and remove the
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews * temporary add record.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(dns_difftuple_create(diff->mctx, DNS_DIFFOP_DEL,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews ISC_LIST_UNLINK(temp_diff.tuples, tuple, link);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * See if we already have a REMOVE request in progress.
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews dns_nsec3param_toprivate(&tuple->rdata, &rdata, privatetype,
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews buf[2] |= DNS_NSEC3FLAG_REMOVE | DNS_NSEC3FLAG_NONSEC;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(rr_exists(db, ver, name, &rdata, &flag));
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews CHECK(rr_exists(db, ver, name, &rdata, &flag));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(dns_difftuple_create(diff->mctx, DNS_DIFFOP_ADD,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(dns_difftuple_create(diff->mctx, DNS_DIFFOP_ADD, name,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews ISC_LIST_UNLINK(temp_diff.tuples, tuple, link);
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrewsrollback_private(dns_db_t *db, dns_rdatatype_t privatetype,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_difftuple_t *tuple, *newtuple = NULL, *next;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews * Extract the changes to be rolled back.
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews * Allow records which indicate that a zone has been
931814de4ad11f20b85c3b50399e2e7dda2e7d47Francis Dupont * signed with a DNSKEY to be removed.
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews ISC_LIST_PREPEND(temp_diff.tuples, tuple, link);
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews * Rollback the changes.
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews while ((tuple = ISC_LIST_HEAD(temp_diff.tuples)) != NULL) {
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews CHECK(dns_difftuple_create(mctx, op, name, tuple->ttl,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews CHECK(do_one_tuple(&newtuple, db, ver, &temp_diff));
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.
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrewsadd_signing_records(dns_db_t *db, dns_rdatatype_t privatetype,
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews dns_difftuple_t *tuple, *newtuple = NULL, *next;
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews * Extract the DNSKEY tuples from the list.
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews ISC_LIST_APPEND(temp_diff.tuples, tuple, link);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews * Extract TTL changes pairs, we don't need signing records for these.
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews * Walk the temp_diff list looking for the
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews * corresponding delete.
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews * If we have not found a pair move onto the next
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews * Find the next tuple to be processed before
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews * unlinking then complete moving the pair to 'diff'.
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews ISC_LIST_UNLINK(temp_diff.tuples, tuple, link);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews * Process the remaining DNSKEY entries.
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews ISC_LIST_UNLINK(temp_diff.tuples, tuple, link);
784a904bd06c7492361ed09a882d10c636b1291bAutomatic Updater ISC_LIST_APPEND(diff->tuples, tuple, link);
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews result = dns_rdata_tostruct(&tuple->rdata, &dnskey, NULL);
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews keyid = dst_region_computeid(&r, dnskey.algorithm);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews buf[3] = (tuple->op == DNS_DIFFOP_ADD) ? 0 : 1;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(rr_exists(db, ver, name, &rdata, &flag));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(dns_difftuple_create(diff->mctx, DNS_DIFFOP_ADD,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Remove any record which says this operation has already
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * completed.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(rr_exists(db, ver, name, &rdata, &flag));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(dns_difftuple_create(diff->mctx, DNS_DIFFOP_DEL,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrewsisdnssec(dns_db_t *db, dns_dbversion_t *ver, dns_rdatatype_t privatetype) {
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews result = dns_private_chains(db, ver, privatetype,
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrenceupdate_action(isc_task_t *task, isc_event_t *event) {
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson update_event_t *uev = (update_event_t *) event;
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff ns_client_t *client = (ns_client_t *)event->ev_arg;
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews dns_diff_t temp; /* Pending RR existence assertions. */
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson isc_boolean_t soa_serial_changed = ISC_FALSE;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson dns_message_t *request = client->message;
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_rdatatype_t privatetype = dns_zone_getprivatetype(zone);
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 CHECK(checkqueryacl(client, dns_zone_getqueryacl(zone), zonename,
9e9e7112f9d712fe9e1740162f88a82ef1aa4711Mark Andrews * Get old and new versions now that queryacl has been checked.
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Check prerequisites.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson for (result = dns_message_firstname(request, DNS_SECTION_PREREQUISITE);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_message_nextname(request, DNS_SECTION_PREREQUISITE))
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson get_current_rr(request, DNS_SECTION_PREREQUISITE, zoneclass,
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "prerequisite TTL is not zero");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (! dns_name_issubdomain(name, zonename))
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "prerequisite name is out of zone");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (update_class == dns_rdataclass_any) {
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "class ANY prerequisite "
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "RDATA is not empty");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson CHECK(name_exists(db, ver, name, &flag));
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "'name in use' "
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "prerequisite not "
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "satisfied");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /* RRset does not exist. */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson "'rrset exists (value independent)' "
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "prerequisite not satisfied");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson } else if (update_class == dns_rdataclass_none) {
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "class NONE prerequisite "
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "RDATA is not empty");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson CHECK(name_exists(db, ver, name, &flag));
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "'name not in use' "
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "prerequisite not "
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "satisfied");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /* RRset exists. */
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "'rrset does not exist' "
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "prerequisite not "
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "satisfied");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson /* "temp<rr.name, rr.type> += rr;" */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = temp_append(&temp, name, &rdata);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson "temp entry creation failed: %s",
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews PREREQFAILC(DNS_R_FORMERR, "malformed prerequisite");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Perform the final check of the "rrset exists (value dependent)"
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * prerequisites.
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews * Sort the prerequisite records by owner name,
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews * type, and rdata.
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews FAILC(result, "'RRset exists (value dependent)' "
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews "prerequisite not satisfied");
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews result = temp_check(mctx, &temp, db, ver, tmpname, &type);
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews "'RRset exists (value dependent)' "
4072dfb9b865c82c24a72e734d54da51a20dfc1eMark Andrews "prerequisite not satisfied");
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "prerequisites are OK");
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.
cc4928ec7116a064223f60639ca1a80f25ba350fMark Andrews CHECK(checkupdateacl(client, dns_zone_getupdateacl(zone),
92f60809e854ccf5f115883c6347e370da048848Mark Andrews else if (client->signer == NULL && !TCPCLIENT(client))
392cd518b3aff35c0396f84884cd51680edd68a1Mark Andrews CHECK(checkupdateacl(client, NULL, "update", zonename,
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.");
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Perform the Update Section Prescan.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson for (result = dns_message_firstname(request, DNS_SECTION_UPDATE);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_message_nextname(request, DNS_SECTION_UPDATE))
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson get_current_rr(request, DNS_SECTION_UPDATE, zoneclass,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (! dns_name_issubdomain(name, zonename))
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "update RR is outside zone");
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"
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "meta-RR in update");
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews result = dns_zone_checknames(zone, name, &rdata);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson } else if (update_class == dns_rdataclass_any) {
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "meta-RR in update");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson } else if (update_class == dns_rdataclass_none) {
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson "meta-RR in update");
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson update_log(client, zone, ISC_LOG_WARNING,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "update RR has incorrect class %d",
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."
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews "explicit NSEC3 updates are not allowed "
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews "in secure zones");
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews "explicit NSEC updates are not allowed "
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews "in secure zones");
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews } else if (rdata.type == dns_rdatatype_rrsig &&
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews "explicit RRSIG updates are currently "
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews "not supported in secure zones except "
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews "at the apex");
f592d2f76cac7115038124c510d2ba3050334b4dEvan Hunt isc_netaddr_fromsockaddr(&netaddr, &client->peeraddr);
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington "rejected by secure update");
84feab0fad8ce53c5d26dff9bde89c4cae285908Brian Wellington "rejected by secure update");
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "update section prescan OK");
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * Process the Update Section.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson for (result = dns_message_firstname(request, DNS_SECTION_UPDATE);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_message_nextname(request, DNS_SECTION_UPDATE))
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson get_current_rr(request, DNS_SECTION_UPDATE, zoneclass,
6fb3db01acad7f5c1f4e23789fb0f2ce56cc07deMukund Sivaraman * RFC1123 doesn't allow MF and MD in master zones.
11dbb6dc6b32c6316cb40c767701a24cfbc18326Mark Andrews "attempt to add %s ignored",
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews "attempt to add wildcard %s record "
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson CHECK(cname_incompatible_rrset_exists(db, ver,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "attempt to add CNAME "
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "alongside non-CNAME "
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "attempt to add non-CNAME "
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "alongside CNAME ignored");
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "attempt to create 2nd "
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "SOA ignored");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson CHECK(check_soa_increment(db, ver, &rdata,
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "SOA update failed to "
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "increment serial, "
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "ignoring it");
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews "attempt to add a private type "
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews "(%u) record rejected internal "
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Ignore attempts to add NSEC3PARAM records
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * with any flags other than OPTOUT.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews "attempt to add NSEC3PARAM "
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews "record with non OPTOUT "
508f61f8d699c46f962b682f388e54b446a7194dMark Andrews if ((options & DNS_ZONEOPT_CHECKWILDCARD) != 0 &&
508f61f8d699c46f962b682f388e54b446a7194dMark Andrews "warning: ownername '%s' contains "
35f6a21f5f8114542c050bfcb484b39ce513d4bdEvan Hunt "reducing TTL to the "
35f6a21f5f8114542c050bfcb484b39ce513d4bdEvan Hunt "configured max-zone-ttl %d",
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington if (isc_log_wouldlog(ns_g_lctx, LOGLEVEL_PROTOCOL)) {
c91c439f80c555f016cce8e9fd910630f81bb5c9Curtis Blackburn dns_name_format(name, namestr, sizeof(namestr));
c91c439f80c555f016cce8e9fd910630f81bb5c9Curtis Blackburn isc_buffer_init(&buf, rdstr, sizeof(rdstr));
c91c439f80c555f016cce8e9fd910630f81bb5c9Curtis Blackburn result = dns_rdata_totext(&rdata, NULL, &buf);
2425d8bb7ccf5dc956ad12d64d97b5a42e022930Evan Hunt "rdata_totext failed: %s]",
2425d8bb7ccf5dc956ad12d64d97b5a42e022930Evan Hunt "adding an RR at '%s' %s %.*s%s",
f19771c55d7e7d5bb38160e710185e6e61749d16Andreas Gustafsson /* Prepare the affected RRset for the addition. */
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson } else if (update_class == dns_rdataclass_any) {
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington "delete all rrsets from "
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson } else if (dns_name_equal(name, zonename) &&
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "attempt to delete all SOA "
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "or NS records ignored");
15033eed4da51bb031465e59a47681f8dc8dd551Brian Wellington "deleting rrset at '%s' %s",
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson } else if (update_class == dns_rdataclass_none) {
1a3d6530f67d4f6a53fd91d76d10ff14f84d2198Andreas Gustafsson * The (name == zonename) condition appears in
1a3d6530f67d4f6a53fd91d76d10ff14f84d2198Andreas Gustafsson * RFC2136 3.4.2.4 but is missing from the pseudocode.
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "attempt to delete SOA "
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "delete last "
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "NS ignored");
88471538d69a7c21b8b9fd13b489399ad6c26597Mark Andrews dns_name_format(name, namestr, sizeof(namestr));
88471538d69a7c21b8b9fd13b489399ad6c26597Mark Andrews CHECK(delete_if(rr_equal_p, db, ver, name, rdata.type,
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 CHECK(check_dnssec(client, zone, db, ver, &diff));
5d850024cb41fdcb0b85efd3f7997bc52e6b33e8Mark Andrews CHECK(dns_zone_nscheck(zone, db, ver, &errors));
5d850024cb41fdcb0b85efd3f7997bc52e6b33e8Mark Andrews "update rejected: post update name server "
5d850024cb41fdcb0b85efd3f7997bc52e6b33e8Mark Andrews "sanity check failed");
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews if (result == DNS_R_BADCDS || result == DNS_R_BADCDNSKEY) {
598b502695802c3d4e23316b85368e54f39f5cabMark Andrews "update rejected: bad %s RRset",
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.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Increment the SOA serial, but only if it was not
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson * changed as a result of an update operation.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(rrset_exists(db, ver, zonename, dns_rdatatype_dnskey,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews ((dns_zone_getoptions(zone) & DNS_ZONEOPT_SECURETOINSECURE) != 0)
b16d99bac1d100735224ab3eaa84632537ff21b5Mark Andrews CHECK(rrset_exists(db, oldver, zonename, dns_rdatatype_dnskey,
8e4f3f1cbceef520ba889270c993de0ac376a2a7Evan Hunt "update rejected: all DNSKEY "
63aeaafd975c96e68a35c9e5d58d822b35c0f9d1Automatic Updater "records removed and "
63aeaafd975c96e68a35c9e5d58d822b35c0f9d1Automatic Updater "'dnssec-secure-to-insecure' "
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews CHECK(rollback_private(db, privatetype, ver, &diff));
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews CHECK(add_signing_records(db, privatetype, ver, &diff));
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews CHECK(add_nsec3param_records(client, zone, db, ver, &diff));
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.
8d31dd9ab62d91b5f23ac687657c966d44074a3fMark Andrews CHECK(dns_nsec3param_deletechains(db, ver, zone,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews } else if (has_dnskey && isdnssec(db, ver, privatetype)) {
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews interval = dns_zone_getsigvalidityinterval(zone);
9198ab377b1cbf07d6d0c6eec25296c135bd66bdMark Andrews result = dns_update_signatures(&log, zone, db, oldver,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews "RRSIG/NSEC/NSEC3 update failed: %s",
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews result = dns_db_getsize(db, ver, &records, NULL);
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews if (result == ISC_R_SUCCESS && records > maxrecords) {
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews "records in zone (%"
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews "u) exceeds max-records (%u)",
ea544b0511a66bc5f3700d56a72dcd808fdf22e8Brian Wellington result = dns_journal_open(mctx, journalfile,
ea544b0511a66bc5f3700d56a72dcd808fdf22e8Brian Wellington result = dns_journal_write_transaction(journal, &diff);
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 "committing update transaction");
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews * Mark the zone as dirty so that it will be written to disk.
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews * Notify slaves of the change we just made.
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 * Note: we are already committed to this course of action.
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews dns_rdata_tostruct(&tuple->rdata, &dnskey, NULL);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_zone_signwithkey(zone, algorithm, keyid,
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews "dns_zone_signwithkey failed: %s",
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Cause the zone to add/delete NSEC3 chains for the
b9d48991211415094ed6ea92d2084422104c6787Francis Dupont * deferred NSEC3PARAM changes.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Note: we are already committed to this course of action.
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews if (!dns_nsec3param_fromprivate(&tuple->rdata, &rdata,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_zone_addnsec3chain(zone, &nsec3param);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews "dns_zone_addnsec3chain failed: %s",
8bcfe7952124a7aab5ae9fbb9420417b5be12721Mark Andrews update_log(client, zone, LOGLEVEL_DEBUG, "redundant request");
cfefc47443d2035d13c827837e286f12c23e6eb4David Lawrence * The reason for failure should have been logged at this point.
6259fcd6f721f4919bd63e81619b820e40ef6d43Andreas Gustafsson "rolling back");
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson dns_db_closeversion(db, &ver, ISC_FALSE);
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson dns_db_closeversion(db, &oldver, ISC_FALSE);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews INSIST(uev->zone == zone); /* we use this later */
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;
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff INSIST(event->ev_type == DNS_EVENT_UPDATEDONE);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(uev->zone, dns_nsstatscounter_updatedone);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(uev->zone, dns_nsstatscounter_updaterej);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(uev->zone, dns_nsstatscounter_updatefail);
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews * Update forwarding support.
de154f65f63a9762078eb7f990e270b9f1476282Mark Andrewsforward_fail(isc_task_t *task, isc_event_t *event) {
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews ns_client_t *client = (ns_client_t *)event->ev_arg;
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrewsforward_callback(void *arg, isc_result_t result, dns_message_t *answer) {
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(zone, dns_nsstatscounter_updatefwdfail);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(zone, dns_nsstatscounter_updaterespfwd);
42b48d11ca7b296324d7a8a98cdbf0070b0deb1dMark Andrews isc_task_send(client->task, ISC_EVENT_PTR(&uev));
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;
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrewsforward_action(isc_task_t *task, isc_event_t *event) {
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews update_event_t *uev = (update_event_t *) event;
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews ns_client_t *client = (ns_client_t *)event->ev_arg;
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews result = dns_zone_forwardupdate(zone, client->message,
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(zone, dns_nsstatscounter_updatefwdfail);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews inc_stats(zone, dns_nsstatscounter_updatereqfwd);
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrewssend_forward_event(ns_client_t *client, dns_zone_t *zone) {
2c35c682362049f823248542e07e7dca4008b986Mark Andrews * This may take some time so replace this client.
2c35c682362049f823248542e07e7dca4008b986Mark Andrews if (!client->mortal && (client->attributes & NS_CLIENTATTR_TCP) == 0)
459e901f905e09a2e98f3ff70cb19fb2061aef83Mark Andrews isc_event_allocate(client->mctx, client, DNS_EVENT_UPDATE,
34f3693b93f3ba16634f0c08368ef7f81182ef93Evan Hunt dns_name_format(dns_zone_getorigin(zone), namebuf,
34f3693b93f3ba16634f0c08368ef7f81182ef93Evan Hunt dns_rdataclass_format(dns_zone_getclass(zone), classbuf,
34f3693b93f3ba16634f0c08368ef7f81182ef93Evan Hunt ns_client_log(client, NS_LOGCATEGORY_UPDATE, NS_LOGMODULE_UPDATE,
34f3693b93f3ba16634f0c08368ef7f81182ef93Evan Hunt LOGLEVEL_PROTOCOL, "forwarding update for zone '%s/%s'",