xfrout.c revision df925e6c66d45d960fbac0383169763967d2111c
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * Copyright (C) 2004-2012 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
2bef3713093349af52ba61eaab07adf3207da873Mark Andrews * purpose with or without fee is hereby granted, provided that the above
2bef3713093349af52ba61eaab07adf3207da873Mark Andrews * copyright notice and this permission notice appear in all copies.
2bef3713093349af52ba61eaab07adf3207da873Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
2bef3713093349af52ba61eaab07adf3207da873Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
43e2c588ba773f471a7a2459b10a67a800c576c6Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
2bef3713093349af52ba61eaab07adf3207da873Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
43e2c588ba773f471a7a2459b10a67a800c576c6Mark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
43e2c588ba773f471a7a2459b10a67a800c576c6Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2bef3713093349af52ba61eaab07adf3207da873Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
8f25faf9720a0c2730c4ac80ea4c12ca1f25599fMukund Sivaraman * Outgoing AXFR and IXFR.
8f25faf9720a0c2730c4ac80ea4c12ca1f25599fMukund Sivaraman * - IXFR over UDP
d1f1f13c7fc1f1515930053508f1645cfafaa478Mark Andrews ns_g_lctx, DNS_LOGCATEGORY_XFER_OUT, NS_LOGMODULE_XFER_OUT
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt * Fail unconditionally and log as a client error.
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt * The test against ISC_R_SUCCESS is there to keep the Solaris compiler
e45d0508c3460db87afb1f743bc5210522721bb3Evan Hunt * from complaining about "end-of-loop code not reached".
43e2c588ba773f471a7a2459b10a67a800c576c6Mark Andrews ns_client_log(client, DNS_LOGCATEGORY_XFER_OUT, \
de7df3e56fe99c33a415674b018aae93eee94750Evan Hunt "bad zone transfer request: %s (%s)", \
43e2c588ba773f471a7a2459b10a67a800c576c6Mark Andrews dns_name_format(question, _buf1, sizeof(_buf1)); \
820fdd61dd35e359a8e616031209d074a7140d97Evan Hunt dns_rdataclass_format(rdclass, _buf2, sizeof(_buf2)); \
820fdd61dd35e359a8e616031209d074a7140d97Evan Hunt "bad zone transfer request: '%s/%s': %s (%s)", \
820fdd61dd35e359a8e616031209d074a7140d97Evan Hunt/**************************************************************************/
820fdd61dd35e359a8e616031209d074a7140d97Evan Huntstatic inline void
820fdd61dd35e359a8e616031209d074a7140d97Evan Huntinc_stats(dns_zone_t *zone, isc_statscounter_t counter) {
076bda8c2e2b2f41775bd7b1694dd2cab287aeebMark Andrews isc_stats_increment(ns_g_server->nsstats, counter);
076bda8c2e2b2f41775bd7b1694dd2cab287aeebMark Andrews isc_stats_t *zonestats = dns_zone_getrequeststats(zone);
076bda8c2e2b2f41775bd7b1694dd2cab287aeebMark Andrews/**************************************************************************/
820fdd61dd35e359a8e616031209d074a7140d97Evan Hunt/*% Log an RR (for debugging) */
820fdd61dd35e359a8e616031209d074a7140d97Evan Huntlog_rr(dns_name_t *name, dns_rdata_t *rdata, isc_uint32_t ttl) {
43e2c588ba773f471a7a2459b10a67a800c576c6Mark Andrews RUNTIME_CHECK(dns_rdatalist_tordataset(&rdl, &rds) == ISC_R_SUCCESS);
1e34fe9044874422104e84373988d07876f716b6Mark Andrews * We could use xfrout_log(), but that would produce
2b8bed6681d1541474f022586cbe728dfce36880Evan Hunt * very long lines with a repetitive prefix.
2b8bed6681d1541474f022586cbe728dfce36880Evan Hunt * Get rid of final newline.
c14ba7107063650e7f4329e8c54adca57913381bEvan Hunt isc_log_write(XFROUT_RR_LOGARGS, "<RR too large to print>");
c14ba7107063650e7f4329e8c54adca57913381bEvan Hunt/**************************************************************************/
43e2c588ba773f471a7a2459b10a67a800c576c6Mark Andrews * An 'rrstream_t' is a polymorphic iterator that returns
c14ba7107063650e7f4329e8c54adca57913381bEvan Hunt * a stream of resource records. There are multiple implementations,
c14ba7107063650e7f4329e8c54adca57913381bEvan Hunt * e.g. for generating AXFR and IXFR records streams.
43e2c588ba773f471a7a2459b10a67a800c576c6Mark Andrewstypedef struct rrstream_methods rrstream_methods_t;
35f6a21f5f8114542c050bfcb484b39ce513d4bdEvan Hunttypedef struct rrstream {
43e2c588ba773f471a7a2459b10a67a800c576c6Mark Andrews/**************************************************************************/
baad8d9fd8dd054ce1edf350ff0c0f2038a1519eEvan Hunt * An 'ixfr_rrstream_t' is an 'rrstream_t' that returns
baad8d9fd8dd054ce1edf350ff0c0f2038a1519eEvan Hunt * an IXFR-like RR stream from a journal file.
baad8d9fd8dd054ce1edf350ff0c0f2038a1519eEvan Hunt * The SOA at the beginning of each sequence of additions
baad8d9fd8dd054ce1edf350ff0c0f2038a1519eEvan Hunt * or deletions are included in the stream, but the extra
43e2c588ba773f471a7a2459b10a67a800c576c6Mark Andrews * SOAs at the beginning and end of the entire transfer are
43e2c588ba773f471a7a2459b10a67a800c576c6Mark Andrews * not included.
0c29904b27c9ab3b85ecbde159b22ae1323bdbcdMukund Sivaraman/* Forward declarations. */
0c29904b27c9ab3b85ecbde159b22ae1323bdbcdMukund Sivaramanstatic rrstream_methods_t ixfr_rrstream_methods;
0c29904b27c9ab3b85ecbde159b22ae1323bdbcdMukund Sivaraman * Returns: anything dns_journal_open() or dns_journal_iter_init()
0c29904b27c9ab3b85ecbde159b22ae1323bdbcdMukund Sivaraman * may return.
43e2c588ba773f471a7a2459b10a67a800c576c6Mark Andrews CHECK(dns_journal_iter_init(s->journal, begin_serial, end_serial));
0c2313eb367de3b58801d643d52c0fd9bc0e5df7Evan Hunt ixfr_rrstream_destroy((rrstream_t **) (void *)&s);
0c2313eb367de3b58801d643d52c0fd9bc0e5df7Evan Hunt dns_journal_current_rr(s->journal, name, ttl, rdata);
43e2c588ba773f471a7a2459b10a67a800c576c6Mark Andrews isc_mem_putanddetach(&s->common.mctx, s, sizeof(*s));
0c2313eb367de3b58801d643d52c0fd9bc0e5df7Evan Huntstatic rrstream_methods_t ixfr_rrstream_methods = {
fbd9aaa58c32abaeab1bd3ca6943b18ce19ea023Mark Andrews/**************************************************************************/
43e2c588ba773f471a7a2459b10a67a800c576c6Mark Andrews * An 'axfr_rrstream_t' is an 'rrstream_t' that returns
075a3d60c23140f05db10d70126ff271ef6469c9Mark Andrews * an AXFR-like RR stream from a database.
075a3d60c23140f05db10d70126ff271ef6469c9Mark Andrews * The SOAs at the beginning and end of the transfer are
075a3d60c23140f05db10d70126ff271ef6469c9Mark Andrews * not included in the stream.
9052766cc5ae39b9341253f863360ae679133a35Mark Andrewstypedef struct axfr_rrstream {
e6d0a391f5f9b18f5bd497aefff269e474ee560cWitold Krecicki * Forward declarations.
7382f5160274938d143d82bda1941b32822dac53Mark Andrewsstatic rrstream_methods_t axfr_rrstream_methods;
7382f5160274938d143d82bda1941b32822dac53Mark Andrewsaxfr_rrstream_create(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *ver,
7382f5160274938d143d82bda1941b32822dac53Mark Andrews CHECK(dns_rriterator_init(&s->it, db, ver, 0));
return (ISC_R_SUCCESS);
return (result);
static isc_result_t
return (result);
return (result);
static isc_result_t
return (result);
if (s->it_valid)
typedef struct soa_rrstream {
static isc_result_t
soa_rrstream_t *s;
if (s == NULL)
return (ISC_R_NOMEMORY);
&s->soa_tuple));
return (ISC_R_SUCCESS);
return (result);
static isc_result_t
return (ISC_R_SUCCESS);
static isc_result_t
return (ISC_R_NOMORE);
typedef struct compound_rrstream {
int state;
static isc_result_t
static isc_result_t
if (s == NULL)
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
static isc_result_t
s->state = 0;
return (s->result);
static isc_result_t
return (ISC_R_NOMORE);
s->state++;
return (s->result);
void *txmem;
unsigned int txmemlen;
} xfrout_ctx_t;
static isc_result_t
unsigned int maxtime,
unsigned int idletime,
char *journalfile;
switch (reqtype) {
case dns_rdatatype_axfr:
case dns_rdatatype_ixfr:
INSIST(0);
goto failure;
&zone);
&db);
sizeof(_buf1));
goto failure;
case dns_zone_master:
case dns_zone_slave:
case dns_zone_dlz:
&soa_name);
goto got_soa;
if (!is_dlz) {
if (is_dlz)
goto axfr_fallback;
if (! have_soa)
goto have_stream;
&data_stream);
goto axfr_fallback;
&data_stream));
&stream));
if (is_dlz)
&xfr));
&xfr));
if (is_poll)
static isc_result_t
unsigned int len;
void *mem;
return (ISC_R_NOMEMORY);
goto failure;
goto failure;
return (ISC_R_SUCCESS);
return (result);
int n_rrs;
isc_region_t r;
goto failure;
goto failure;
unsigned int size;
isc_region_t r;
if (n_rrs == 0) {
goto failure;
goto failure;
goto failure;
goto failure;
goto failure;
xfr));
if (cleanup_cctx)