xfrin.c revision 97a2a26cd93e153dcf8fb1ea6bf2311426496251
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * Copyright (C) 2004-2008, 2011-2013 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 1999-2003 Internet Software Consortium.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and/or distribute this software for any
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * purpose with or without fee is hereby granted, provided that the above
f41f183f628a148860a6d1f0070208cddd45b0c6Bob Halley * copyright notice and this permission notice appear in all copies.
f41f183f628a148860a6d1f0070208cddd45b0c6Bob Halley * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
f41f183f628a148860a6d1f0070208cddd45b0c6Bob Halley * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
c2bc56dc65b4b103a5600565680eb5f33fa4c90bMark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
51917258dbb23cfe6069ae1cf2b7fc5aefc1e0c2Bob Halley * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
6d5dcd0dc9bdbd679282b1ffc47987d24c3a1346Bob Halley * PERFORMANCE OF THIS SOFTWARE.
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley#include <isc/string.h> /* Required for HP/UX (and others?) */
f4cbe536b11da614fe05aeaeff41e324854cda7bMark Andrews * Incoming AXFR and IXFR.
f4cbe536b11da614fe05aeaeff41e324854cda7bMark Andrews * It would be non-sensical (or at least obtuse) to use FAIL() with an
f4cbe536b11da614fe05aeaeff41e324854cda7bMark Andrews * ISC_R_SUCCESS code, but the test is there to keep the Solaris compiler
f4cbe536b11da614fe05aeaeff41e324854cda7bMark Andrews * from complaining about "end-of-loop code not reached".
f4cbe536b11da614fe05aeaeff41e324854cda7bMark Andrews * The states of the *XFR state machine. We handle both IXFR and AXFR
f4cbe536b11da614fe05aeaeff41e324854cda7bMark Andrews * with a single integrated state machine because they cannot be distinguished
f4cbe536b11da614fe05aeaeff41e324854cda7bMark Andrews * immediately - an AXFR response to an IXFR request can only be detected
f4cbe536b11da614fe05aeaeff41e324854cda7bMark Andrews * when the first two (2) response RRs have already been received.
f4cbe536b11da614fe05aeaeff41e324854cda7bMark Andrewstypedef enum {
fc80027fb54b501cdd88461bf879d078259e0226David Lawrence * Incoming zone transfer context.
f40036cbd6ba047c954dcea8705a0b9392d403d9Mark Andrews unsigned int magic;
fc80027fb54b501cdd88461bf879d078259e0226David Lawrence dns_name_t name; /*%< Name of zone to transfer */
56b40c0185bcbd4a04422acc1211b5e2d2ba8a3eBob Halley * Requested transfer type (dns_rdatatype_axfr or
56b40c0185bcbd4a04422acc1211b5e2d2ba8a3eBob Halley * dns_rdatatype_ixfr). The actual transfer type
56b40c0185bcbd4a04422acc1211b5e2d2ba8a3eBob Halley * may differ due to IXFR->AXFR fallback.
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉 /*% Buffer for IXFR/AXFR request message */
9f7d51ee3290e2a064d71016a6bd555b47134a7cMark Andrews /*% Incoming reply TCP message */
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉 dns_diff_t diff; /*%< Pending database changes */
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉 unsigned int nmsg; /*%< Number of messages recvd */
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉 unsigned int nrecs; /*%< Number of records recvd */
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉 isc_uint64_t nbytes; /*%< Number of bytes received */
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉 isc_time_t start; /*%< Start time of the transfer */
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉 isc_time_t end; /*%< End time of the transfer */
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉 dns_tsigkey_t *tsigkey; /*%< Key used to create TSIG */
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉 isc_buffer_t *lasttsig; /*%< The last TSIG */
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉 dst_context_t *tsigctx; /*%< TSIG verification context */
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉 unsigned int sincetsig; /*%< recvd since the last TSIG */
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉 * AXFR- and IXFR-specific data. Only one is used at a time
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉 * according to the is_ixfr flag, so this could be a union,
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt * but keeping them separate makes it a bit simpler to clean
9f7d51ee3290e2a064d71016a6bd555b47134a7cMark Andrews * things up when destroying the context.
9f7d51ee3290e2a064d71016a6bd555b47134a7cMark Andrews#define XFRIN_MAGIC ISC_MAGIC('X', 'f', 'r', 'I')
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt#define VALID_XFRIN(x) ISC_MAGIC_VALID(x, XFRIN_MAGIC)
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt/**************************************************************************/
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt * Forward declarations.
9f7d51ee3290e2a064d71016a6bd555b47134a7cMark Andrewsstatic isc_result_t axfr_init(dns_xfrin_ctx_t *xfr);
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Huntstatic isc_result_t axfr_makedb(dns_xfrin_ctx_t *xfr, dns_db_t **dbp);
96e79f7ede9fd09c79ac6452ab09e4e48b288e4dMichael Graffstatic isc_result_t axfr_putdata(dns_xfrin_ctx_t *xfr, dns_diffop_t op,
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Huntstatic isc_result_t axfr_apply(dns_xfrin_ctx_t *xfr);
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleystatic isc_result_t axfr_commit(dns_xfrin_ctx_t *xfr);
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Huntstatic isc_result_t axfr_finalize(dns_xfrin_ctx_t *xfr);
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Huntstatic isc_result_t ixfr_init(dns_xfrin_ctx_t *xfr);
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleystatic isc_result_t ixfr_apply(dns_xfrin_ctx_t *xfr);
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Huntstatic isc_result_t ixfr_putdata(dns_xfrin_ctx_t *xfr, dns_diffop_t op,
c9f9dd2dd2344e45cf7b95d064338d97f08f1fb8Bob Halleystatic isc_result_t ixfr_commit(dns_xfrin_ctx_t *xfr);
9f7d51ee3290e2a064d71016a6bd555b47134a7cMark Andrewsstatic isc_result_t xfr_rr(dns_xfrin_ctx_t *xfr, dns_name_t *name,
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Huntstatic isc_result_t xfrin_start(dns_xfrin_ctx_t *xfr);
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Huntstatic void xfrin_connect_done(isc_task_t *task, isc_event_t *event);
9a2eda6f8e435ecf0d84502c84b1e75e2f5e9220Bob Halleystatic isc_result_t xfrin_send_request(dns_xfrin_ctx_t *xfr);
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Huntstatic void xfrin_send_done(isc_task_t *task, isc_event_t *event);
9f7d51ee3290e2a064d71016a6bd555b47134a7cMark Andrewsstatic void xfrin_sendlen_done(isc_task_t *task, isc_event_t *event);
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Huntstatic void xfrin_recv_done(isc_task_t *task, isc_event_t *event);
53c24d27c83084d93f591d2d5eeb40a127b514c6Andreas Gustafssonstatic void xfrin_timeout(isc_task_t *task, isc_event_t *event);
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Huntxfrin_fail(dns_xfrin_ctx_t *xfr, isc_result_t result, const char *msg);
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Huntrender(dns_message_t *msg, isc_mem_t *mctx, isc_buffer_t *buf);
9f7d51ee3290e2a064d71016a6bd555b47134a7cMark Andrewsxfrin_logv(int level, const char *zonetext, isc_sockaddr_t *masteraddr,
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Huntxfrin_log1(int level, const char *zonetext, isc_sockaddr_t *masteraddr,
9e4292a2b46bc30568bd1eb204761f7134609405David Lawrence const char *fmt, ...)
9e4292a2b46bc30568bd1eb204761f7134609405David Lawrencexfrin_log(dns_xfrin_ctx_t *xfr, int level, const char *fmt, ...)
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt/**************************************************************************/
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt * AXFR handling
9f7d51ee3290e2a064d71016a6bd555b47134a7cMark Andrewsaxfr_makedb(dns_xfrin_ctx_t *xfr, dns_db_t **dbp) {
9f7d51ee3290e2a064d71016a6bd555b47134a7cMark Andrewsaxfr_putdata(dns_xfrin_ctx_t *xfr, dns_diffop_t op,
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt dns_name_t *name, dns_ttl_t ttl, dns_rdata_t *rdata)
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt CHECK(dns_zone_checknames(xfr->zone, name, rdata));
fd088dc8c8e63f495c4d0257f21849542a582c1eDavid Lawrence * Store a set of AXFR RRs in the database.
37aab7fc211828df0358628f119ef91140c6f2c9William King CHECK(dns_diff_load(&xfr->diff, xfr->axfr.add, xfr->axfr.add_private));
return (result);
static isc_result_t
return (result);
static isc_result_t
return (result);
static isc_result_t
char *journalfile;
return (DNS_R_FORMERR);
return (result);
static isc_result_t
return (result);
static isc_result_t
goto failure;
return (result);
static isc_result_t
return (result);
static isc_result_t
redo:
case XFRST_SOAQUERY:
case XFRST_GOTSOA:
case XFRST_INITIALSOA:
case XFRST_FIRSTDATA:
goto redo;
case XFRST_IXFR_DELSOA:
case XFRST_IXFR_DEL:
goto redo;
case XFRST_IXFR_ADDSOA:
case XFRST_IXFR_ADD:
goto redo;
case XFRST_AXFR:
case XFRST_AXFR_END:
case XFRST_IXFR_END:
INSIST(0);
return (result);
case PF_INET:
case PF_INET6:
INSIST(0);
return (result);
static isc_result_t
return (ISC_R_NOMEMORY);
/* ixfr.current_serial */
ISC_FALSE));
return (ISC_R_SUCCESS);
return (result);
static isc_result_t
#ifndef BROKEN_TCP_BIND_BEFORE_CONNECT
return (ISC_R_SUCCESS);
return (result);
static isc_result_t
if (cleanup_cctx)
return (result);
goto failure;
static isc_result_t
return (ISC_R_SUCCESS);
return (result);
static isc_result_t
return (result);
goto failure;
goto try_axfr;
goto failure;
goto failure;
goto failure;
case XFRST_GOTSOA:
case XFRST_AXFR_END:
case XFRST_IXFR_END:
if (msecs == 0)
(unsigned int) persec);
const char *fmt, ...)