2 * Copyright (C) 2004-2013 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
22 #include <isc/formatcheck.h>
24 #include <isc/timer.h>
25 #include <isc/print.h>
26 #include <isc/stats.h>
30 #include <dns/dbiterator.h>
32 #include <dns/fixedname.h>
33 #include <dns/journal.h>
34 #include <dns/message.h>
36 #include <dns/rdataclass.h>
37 #include <dns/rdatalist.h>
38 #include <dns/rdataset.h>
39 #include <dns/rdatasetiter.h>
40 #include <dns/result.h>
41 #include <dns/rriterator.h>
43 #include <dns/stats.h>
44 #include <dns/timer.h>
50 #include <named/client.h>
51 #include <named/log.h>
52 #include <named/server.h>
53 #include <named/xfrout.h>
57 * Outgoing AXFR and IXFR.
65 #define XFROUT_COMMON_LOGARGS \
66 ns_g_lctx, DNS_LOGCATEGORY_XFER_OUT, NS_LOGMODULE_XFER_OUT
68 #define XFROUT_PROTOCOL_LOGARGS \
69 XFROUT_COMMON_LOGARGS, ISC_LOG_INFO
71 #define XFROUT_DEBUG_LOGARGS(n) \
72 XFROUT_COMMON_LOGARGS, ISC_LOG_DEBUG(n)
74 #define XFROUT_RR_LOGARGS \
75 XFROUT_COMMON_LOGARGS, XFROUT_RR_LOGLEVEL
77 #define XFROUT_RR_LOGLEVEL ISC_LOG_DEBUG(8)
80 * Fail unconditionally and log as a client error.
81 * The test against ISC_R_SUCCESS is there to keep the Solaris compiler
82 * from complaining about "end-of-loop code not reached".
84 #define FAILC(code, msg) \
87 ns_client_log(client, DNS_LOGCATEGORY_XFER_OUT, \
88 NS_LOGMODULE_XFER_OUT, ISC_LOG_INFO, \
89 "bad zone transfer request: %s (%s)", \
90 msg, isc_result_totext(code)); \
91 if (result != ISC_R_SUCCESS) goto failure; \
94 #define FAILQ(code, msg, question, rdclass) \
96 char _buf1[DNS_NAME_FORMATSIZE]; \
97 char _buf2[DNS_RDATACLASS_FORMATSIZE]; \
99 dns_name_format(question, _buf1, sizeof(_buf1)); \
100 dns_rdataclass_format(rdclass, _buf2, sizeof(_buf2)); \
101 ns_client_log(client, DNS_LOGCATEGORY_XFER_OUT, \
102 NS_LOGMODULE_XFER_OUT, ISC_LOG_INFO, \
103 "bad zone transfer request: '%s/%s': %s (%s)", \
104 _buf1, _buf2, msg, isc_result_totext(code)); \
105 if (result != ISC_R_SUCCESS) goto failure; \
109 do { result = (op); \
110 if (result != ISC_R_SUCCESS) goto failure; \
113 /**************************************************************************/
116 inc_stats(dns_zone_t *zone, isc_statscounter_t counter) {
117 isc_stats_increment(ns_g_server->nsstats, counter);
119 isc_stats_t *zonestats = dns_zone_getrequeststats(zone);
120 if (zonestats != NULL)
121 isc_stats_increment(zonestats, counter);
125 /**************************************************************************/
127 /*% Log an RR (for debugging) */
130 log_rr(dns_name_t *name, dns_rdata_t *rdata, isc_uint32_t ttl) {
136 dns_rdata_t rd = DNS_RDATA_INIT;
138 rdl.type = rdata->type;
139 rdl.rdclass = rdata->rdclass;
141 if (rdata->type == dns_rdatatype_sig ||
142 rdata->type == dns_rdatatype_rrsig)
143 rdl.covers = dns_rdata_covers(rdata);
145 rdl.covers = dns_rdatatype_none;
146 ISC_LIST_INIT(rdl.rdata);
147 ISC_LINK_INIT(&rdl, link);
148 dns_rdataset_init(&rds);
150 dns_rdata_clone(rdata, &rd);
151 ISC_LIST_APPEND(rdl.rdata, &rd, link);
152 RUNTIME_CHECK(dns_rdatalist_tordataset(&rdl, &rds) == ISC_R_SUCCESS);
154 isc_buffer_init(&buf, mem, sizeof(mem));
155 result = dns_rdataset_totext(&rds, name,
156 ISC_FALSE, ISC_FALSE, &buf);
159 * We could use xfrout_log(), but that would produce
160 * very long lines with a repetitive prefix.
162 if (result == ISC_R_SUCCESS) {
164 * Get rid of final newline.
166 INSIST(buf.used >= 1 &&
167 ((char *) buf.base)[buf.used - 1] == '\n');
170 isc_log_write(XFROUT_RR_LOGARGS, "%.*s",
171 (int)isc_buffer_usedlength(&buf),
172 (char *)isc_buffer_base(&buf));
174 isc_log_write(XFROUT_RR_LOGARGS, "<RR too large to print>");
178 /**************************************************************************/
180 * An 'rrstream_t' is a polymorphic iterator that returns
181 * a stream of resource records. There are multiple implementations,
182 * e.g. for generating AXFR and IXFR records streams.
185 typedef struct rrstream_methods rrstream_methods_t;
187 typedef struct rrstream {
189 rrstream_methods_t *methods;
192 struct rrstream_methods {
193 isc_result_t (*first)(rrstream_t *);
194 isc_result_t (*next)(rrstream_t *);
195 void (*current)(rrstream_t *,
199 void (*pause)(rrstream_t *);
200 void (*destroy)(rrstream_t **);
204 rrstream_noop_pause(rrstream_t *rs) {
208 /**************************************************************************/
210 * An 'ixfr_rrstream_t' is an 'rrstream_t' that returns
211 * an IXFR-like RR stream from a journal file.
213 * The SOA at the beginning of each sequence of additions
214 * or deletions are included in the stream, but the extra
215 * SOAs at the beginning and end of the entire transfer are
219 typedef struct ixfr_rrstream {
221 dns_journal_t *journal;
224 /* Forward declarations. */
226 ixfr_rrstream_destroy(rrstream_t **sp);
228 static rrstream_methods_t ixfr_rrstream_methods;
231 * Returns: anything dns_journal_open() or dns_journal_iter_init()
236 ixfr_rrstream_create(isc_mem_t *mctx,
237 const char *journal_filename,
238 isc_uint32_t begin_serial,
239 isc_uint32_t end_serial,
245 INSIST(sp != NULL && *sp == NULL);
247 s = isc_mem_get(mctx, sizeof(*s));
249 return (ISC_R_NOMEMORY);
250 s->common.mctx = NULL;
251 isc_mem_attach(mctx, &s->common.mctx);
252 s->common.methods = &ixfr_rrstream_methods;
255 CHECK(dns_journal_open(mctx, journal_filename,
256 DNS_JOURNAL_READ, &s->journal));
257 CHECK(dns_journal_iter_init(s->journal, begin_serial, end_serial));
259 *sp = (rrstream_t *) s;
260 return (ISC_R_SUCCESS);
263 ixfr_rrstream_destroy((rrstream_t **) (void *)&s);
268 ixfr_rrstream_first(rrstream_t *rs) {
269 ixfr_rrstream_t *s = (ixfr_rrstream_t *) rs;
270 return (dns_journal_first_rr(s->journal));
274 ixfr_rrstream_next(rrstream_t *rs) {
275 ixfr_rrstream_t *s = (ixfr_rrstream_t *) rs;
276 return (dns_journal_next_rr(s->journal));
280 ixfr_rrstream_current(rrstream_t *rs,
281 dns_name_t **name, isc_uint32_t *ttl,
284 ixfr_rrstream_t *s = (ixfr_rrstream_t *) rs;
285 dns_journal_current_rr(s->journal, name, ttl, rdata);
289 ixfr_rrstream_destroy(rrstream_t **rsp) {
290 ixfr_rrstream_t *s = (ixfr_rrstream_t *) *rsp;
292 dns_journal_destroy(&s->journal);
293 isc_mem_putanddetach(&s->common.mctx, s, sizeof(*s));
296 static rrstream_methods_t ixfr_rrstream_methods = {
299 ixfr_rrstream_current,
301 ixfr_rrstream_destroy
304 /**************************************************************************/
306 * An 'axfr_rrstream_t' is an 'rrstream_t' that returns
307 * an AXFR-like RR stream from a database.
309 * The SOAs at the beginning and end of the transfer are
310 * not included in the stream.
313 typedef struct axfr_rrstream {
316 isc_boolean_t it_valid;
320 * Forward declarations.
323 axfr_rrstream_destroy(rrstream_t **rsp);
325 static rrstream_methods_t axfr_rrstream_methods;
328 axfr_rrstream_create(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *ver,
334 INSIST(sp != NULL && *sp == NULL);
336 s = isc_mem_get(mctx, sizeof(*s));
338 return (ISC_R_NOMEMORY);
339 s->common.mctx = NULL;
340 isc_mem_attach(mctx, &s->common.mctx);
341 s->common.methods = &axfr_rrstream_methods;
342 s->it_valid = ISC_FALSE;
344 CHECK(dns_rriterator_init(&s->it, db, ver, 0));
345 s->it_valid = ISC_TRUE;
347 *sp = (rrstream_t *) s;
348 return (ISC_R_SUCCESS);
351 axfr_rrstream_destroy((rrstream_t **) (void *)&s);
356 axfr_rrstream_first(rrstream_t *rs) {
357 axfr_rrstream_t *s = (axfr_rrstream_t *) rs;
359 result = dns_rriterator_first(&s->it);
360 if (result != ISC_R_SUCCESS)
362 /* Skip SOA records. */
364 dns_name_t *name_dummy = NULL;
365 isc_uint32_t ttl_dummy;
366 dns_rdata_t *rdata = NULL;
367 dns_rriterator_current(&s->it, &name_dummy,
368 &ttl_dummy, NULL, &rdata);
369 if (rdata->type != dns_rdatatype_soa)
371 result = dns_rriterator_next(&s->it);
372 if (result != ISC_R_SUCCESS)
379 axfr_rrstream_next(rrstream_t *rs) {
380 axfr_rrstream_t *s = (axfr_rrstream_t *) rs;
383 /* Skip SOA records. */
385 dns_name_t *name_dummy = NULL;
386 isc_uint32_t ttl_dummy;
387 dns_rdata_t *rdata = NULL;
388 result = dns_rriterator_next(&s->it);
389 if (result != ISC_R_SUCCESS)
391 dns_rriterator_current(&s->it, &name_dummy,
392 &ttl_dummy, NULL, &rdata);
393 if (rdata->type != dns_rdatatype_soa)
400 axfr_rrstream_current(rrstream_t *rs, dns_name_t **name, isc_uint32_t *ttl,
403 axfr_rrstream_t *s = (axfr_rrstream_t *) rs;
404 dns_rriterator_current(&s->it, name, ttl, NULL, rdata);
408 axfr_rrstream_pause(rrstream_t *rs) {
409 axfr_rrstream_t *s = (axfr_rrstream_t *) rs;
410 dns_rriterator_pause(&s->it);
414 axfr_rrstream_destroy(rrstream_t **rsp) {
415 axfr_rrstream_t *s = (axfr_rrstream_t *) *rsp;
417 dns_rriterator_destroy(&s->it);
418 isc_mem_putanddetach(&s->common.mctx, s, sizeof(*s));
421 static rrstream_methods_t axfr_rrstream_methods = {
424 axfr_rrstream_current,
426 axfr_rrstream_destroy
429 /**************************************************************************/
431 * An 'soa_rrstream_t' is a degenerate 'rrstream_t' that returns
432 * a single SOA record.
435 typedef struct soa_rrstream {
437 dns_difftuple_t *soa_tuple;
441 * Forward declarations.
444 soa_rrstream_destroy(rrstream_t **rsp);
446 static rrstream_methods_t soa_rrstream_methods;
449 soa_rrstream_create(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *ver,
455 INSIST(sp != NULL && *sp == NULL);
457 s = isc_mem_get(mctx, sizeof(*s));
459 return (ISC_R_NOMEMORY);
460 s->common.mctx = NULL;
461 isc_mem_attach(mctx, &s->common.mctx);
462 s->common.methods = &soa_rrstream_methods;
465 CHECK(dns_db_createsoatuple(db, ver, mctx, DNS_DIFFOP_EXISTS,
468 *sp = (rrstream_t *) s;
469 return (ISC_R_SUCCESS);
472 soa_rrstream_destroy((rrstream_t **) (void *)&s);
477 soa_rrstream_first(rrstream_t *rs) {
479 return (ISC_R_SUCCESS);
483 soa_rrstream_next(rrstream_t *rs) {
485 return (ISC_R_NOMORE);
489 soa_rrstream_current(rrstream_t *rs, dns_name_t **name, isc_uint32_t *ttl,
492 soa_rrstream_t *s = (soa_rrstream_t *) rs;
493 *name = &s->soa_tuple->name;
494 *ttl = s->soa_tuple->ttl;
495 *rdata = &s->soa_tuple->rdata;
499 soa_rrstream_destroy(rrstream_t **rsp) {
500 soa_rrstream_t *s = (soa_rrstream_t *) *rsp;
501 if (s->soa_tuple != NULL)
502 dns_difftuple_free(&s->soa_tuple);
503 isc_mem_putanddetach(&s->common.mctx, s, sizeof(*s));
506 static rrstream_methods_t soa_rrstream_methods = {
509 soa_rrstream_current,
514 /**************************************************************************/
516 * A 'compound_rrstream_t' objects owns a soa_rrstream
517 * and another rrstream, the "data stream". It returns
518 * a concatenated stream consisting of the soa_rrstream, then
519 * the data stream, then the soa_rrstream again.
521 * The component streams are owned by the compound_rrstream_t
522 * and are destroyed with it.
525 typedef struct compound_rrstream {
527 rrstream_t *components[3];
530 } compound_rrstream_t;
533 * Forward declarations.
536 compound_rrstream_destroy(rrstream_t **rsp);
539 compound_rrstream_next(rrstream_t *rs);
541 static rrstream_methods_t compound_rrstream_methods;
545 * soa_stream != NULL && *soa_stream != NULL
546 * data_stream != NULL && *data_stream != NULL
547 * sp != NULL && *sp == NULL
550 * *soa_stream == NULL
551 * *data_stream == NULL
552 * *sp points to a valid compound_rrstream_t
553 * The soa and data streams will be destroyed
554 * when the compound_rrstream_t is destroyed.
557 compound_rrstream_create(isc_mem_t *mctx, rrstream_t **soa_stream,
558 rrstream_t **data_stream, rrstream_t **sp)
560 compound_rrstream_t *s;
562 INSIST(sp != NULL && *sp == NULL);
564 s = isc_mem_get(mctx, sizeof(*s));
566 return (ISC_R_NOMEMORY);
567 s->common.mctx = NULL;
568 isc_mem_attach(mctx, &s->common.mctx);
569 s->common.methods = &compound_rrstream_methods;
570 s->components[0] = *soa_stream;
571 s->components[1] = *data_stream;
572 s->components[2] = *soa_stream;
574 s->result = ISC_R_FAILURE;
578 *sp = (rrstream_t *) s;
579 return (ISC_R_SUCCESS);
583 compound_rrstream_first(rrstream_t *rs) {
584 compound_rrstream_t *s = (compound_rrstream_t *) rs;
587 rrstream_t *curstream = s->components[s->state];
588 s->result = curstream->methods->first(curstream);
589 } while (s->result == ISC_R_NOMORE && s->state < 2);
594 compound_rrstream_next(rrstream_t *rs) {
595 compound_rrstream_t *s = (compound_rrstream_t *) rs;
596 rrstream_t *curstream = s->components[s->state];
597 s->result = curstream->methods->next(curstream);
598 while (s->result == ISC_R_NOMORE) {
600 * Make sure locks held by the current stream
601 * are released before we switch streams.
603 curstream->methods->pause(curstream);
605 return (ISC_R_NOMORE);
607 curstream = s->components[s->state];
608 s->result = curstream->methods->first(curstream);
614 compound_rrstream_current(rrstream_t *rs, dns_name_t **name, isc_uint32_t *ttl,
617 compound_rrstream_t *s = (compound_rrstream_t *) rs;
618 rrstream_t *curstream;
619 INSIST(0 <= s->state && s->state < 3);
620 INSIST(s->result == ISC_R_SUCCESS);
621 curstream = s->components[s->state];
622 curstream->methods->current(curstream, name, ttl, rdata);
626 compound_rrstream_pause(rrstream_t *rs)
628 compound_rrstream_t *s = (compound_rrstream_t *) rs;
629 rrstream_t *curstream;
630 INSIST(0 <= s->state && s->state < 3);
631 curstream = s->components[s->state];
632 curstream->methods->pause(curstream);
636 compound_rrstream_destroy(rrstream_t **rsp) {
637 compound_rrstream_t *s = (compound_rrstream_t *) *rsp;
638 s->components[0]->methods->destroy(&s->components[0]);
639 s->components[1]->methods->destroy(&s->components[1]);
640 s->components[2] = NULL; /* Copy of components[0]. */
641 isc_mem_putanddetach(&s->common.mctx, s, sizeof(*s));
644 static rrstream_methods_t compound_rrstream_methods = {
645 compound_rrstream_first,
646 compound_rrstream_next,
647 compound_rrstream_current,
648 compound_rrstream_pause,
649 compound_rrstream_destroy
652 /**************************************************************************/
654 * An 'xfrout_ctx_t' contains the state of an outgoing AXFR or IXFR
661 unsigned int id; /* ID of request */
662 dns_name_t *qname; /* Question name of request */
663 dns_rdatatype_t qtype; /* dns_rdatatype_{a,i}xfr */
664 dns_rdataclass_t qclass;
665 dns_zone_t *zone; /* (necessary for stats) */
667 dns_dbversion_t *ver;
669 rrstream_t *stream; /* The XFR RR stream */
670 isc_boolean_t end_of_stream; /* EOS has been reached */
671 isc_buffer_t buf; /* Buffer for message owner
673 isc_buffer_t txlenbuf; /* Transmit length buffer */
674 isc_buffer_t txbuf; /* Transmit message buffer */
676 unsigned int txmemlen;
677 unsigned int nmsg; /* Number of messages sent */
678 dns_tsigkey_t *tsigkey; /* Key used to create TSIG */
679 isc_buffer_t *lasttsig; /* the last TSIG */
680 isc_boolean_t many_answers;
681 int sends; /* Send in progress */
682 isc_boolean_t shuttingdown;
683 const char *mnemonic; /* Style of transfer */
687 xfrout_ctx_create(isc_mem_t *mctx, ns_client_t *client,
688 unsigned int id, dns_name_t *qname, dns_rdatatype_t qtype,
689 dns_rdataclass_t qclass, dns_zone_t *zone,
690 dns_db_t *db, dns_dbversion_t *ver, isc_quota_t *quota,
691 rrstream_t *stream, dns_tsigkey_t *tsigkey,
692 isc_buffer_t *lasttsig,
693 unsigned int maxtime,
694 unsigned int idletime,
695 isc_boolean_t many_answers,
696 xfrout_ctx_t **xfrp);
699 sendstream(xfrout_ctx_t *xfr);
702 xfrout_senddone(isc_task_t *task, isc_event_t *event);
705 xfrout_fail(xfrout_ctx_t *xfr, isc_result_t result, const char *msg);
708 xfrout_maybe_destroy(xfrout_ctx_t *xfr);
711 xfrout_ctx_destroy(xfrout_ctx_t **xfrp);
714 xfrout_client_shutdown(void *arg, isc_result_t result);
717 xfrout_log1(ns_client_t *client, dns_name_t *zonename,
718 dns_rdataclass_t rdclass, int level,
719 const char *fmt, ...) ISC_FORMAT_PRINTF(5, 6);
722 xfrout_log(xfrout_ctx_t *xfr, int level, const char *fmt, ...)
723 ISC_FORMAT_PRINTF(3, 4);
725 /**************************************************************************/
728 ns_xfr_start(ns_client_t *client, dns_rdatatype_t reqtype) {
730 dns_name_t *question_name;
731 dns_rdataset_t *question_rdataset;
732 dns_zone_t *zone = NULL;
734 dns_dbversion_t *ver = NULL;
735 dns_rdataclass_t question_class;
736 rrstream_t *soa_stream = NULL;
737 rrstream_t *data_stream = NULL;
738 rrstream_t *stream = NULL;
739 dns_difftuple_t *current_soa_tuple = NULL;
740 dns_name_t *soa_name;
741 dns_rdataset_t *soa_rdataset;
742 dns_rdata_t soa_rdata = DNS_RDATA_INIT;
743 isc_boolean_t have_soa = ISC_FALSE;
744 const char *mnemonic = NULL;
745 isc_mem_t *mctx = client->mctx;
746 dns_message_t *request = client->message;
747 xfrout_ctx_t *xfr = NULL;
748 isc_quota_t *quota = NULL;
749 dns_transfer_format_t format = client->view->transfer_format;
751 dns_peer_t *peer = NULL;
752 isc_buffer_t *tsigbuf = NULL;
754 char msg[NS_CLIENT_ACLMSGSIZE("zone transfer")];
755 char keyname[DNS_NAME_FORMATSIZE];
756 isc_boolean_t is_poll = ISC_FALSE;
757 isc_boolean_t is_dlz = ISC_FALSE;
760 case dns_rdatatype_axfr:
763 case dns_rdatatype_ixfr:
771 ns_client_log(client,
772 DNS_LOGCATEGORY_XFER_OUT, NS_LOGMODULE_XFER_OUT,
773 ISC_LOG_DEBUG(6), "%s request", mnemonic);
777 result = isc_quota_attach(&ns_g_server->xfroutquota, "a);
778 if (result != ISC_R_SUCCESS) {
779 isc_log_write(XFROUT_COMMON_LOGARGS, ISC_LOG_WARNING,
780 "%s request denied: %s", mnemonic,
781 isc_result_totext(result));
786 * Interpret the question section.
788 result = dns_message_firstname(request, DNS_SECTION_QUESTION);
789 INSIST(result == ISC_R_SUCCESS);
792 * The question section must contain exactly one question, and
793 * it must be for AXFR/IXFR as appropriate.
795 question_name = NULL;
796 dns_message_currentname(request, DNS_SECTION_QUESTION, &question_name);
797 question_rdataset = ISC_LIST_HEAD(question_name->list);
798 question_class = question_rdataset->rdclass;
799 INSIST(question_rdataset->type == reqtype);
800 if (ISC_LIST_NEXT(question_rdataset, link) != NULL)
801 FAILC(DNS_R_FORMERR, "multiple questions");
802 result = dns_message_nextname(request, DNS_SECTION_QUESTION);
803 if (result != ISC_R_NOMORE)
804 FAILC(DNS_R_FORMERR, "multiple questions");
806 result = dns_zt_find(client->view->zonetable, question_name, 0, NULL,
809 if (result != ISC_R_SUCCESS) {
811 * Normal zone table does not have a match.
812 * Try the DLZ database
814 if (client->view->dlzdatabase != NULL) {
815 result = dns_dlzallowzonexfr(client->view,
820 if (result == ISC_R_NOPERM) {
821 char _buf1[DNS_NAME_FORMATSIZE];
822 char _buf2[DNS_RDATACLASS_FORMATSIZE];
824 result = DNS_R_REFUSED;
825 dns_name_format(question_name, _buf1,
827 dns_rdataclass_format(question_class,
828 _buf2, sizeof(_buf2));
829 ns_client_log(client, DNS_LOGCATEGORY_SECURITY,
830 NS_LOGMODULE_XFER_OUT,
832 "zone transfer '%s/%s' denied",
836 if (result != ISC_R_SUCCESS)
837 FAILQ(DNS_R_NOTAUTH, "non-authoritative zone",
838 question_name, question_class);
842 * not DLZ and not in normal zone table, we are
845 FAILQ(DNS_R_NOTAUTH, "non-authoritative zone",
846 question_name, question_class);
849 /* zone table has a match */
850 switch(dns_zone_gettype(zone)) {
851 /* Master and slave zones are OK for transfer. */
852 case dns_zone_master:
857 FAILQ(DNS_R_NOTAUTH, "non-authoritative zone",
858 question_name, question_class);
860 CHECK(dns_zone_getdb(zone, &db));
861 dns_db_currentversion(db, &ver);
864 xfrout_log1(client, question_name, question_class, ISC_LOG_DEBUG(6),
865 "%s question section OK", mnemonic);
868 * Check the authority section. Look for a SOA record with
869 * the same name and class as the question.
871 for (result = dns_message_firstname(request, DNS_SECTION_AUTHORITY);
872 result == ISC_R_SUCCESS;
873 result = dns_message_nextname(request, DNS_SECTION_AUTHORITY))
876 dns_message_currentname(request, DNS_SECTION_AUTHORITY,
880 * Ignore data whose owner name is not the zone apex.
882 if (! dns_name_equal(soa_name, question_name))
885 for (soa_rdataset = ISC_LIST_HEAD(soa_name->list);
886 soa_rdataset != NULL;
887 soa_rdataset = ISC_LIST_NEXT(soa_rdataset, link))
890 * Ignore non-SOA data.
892 if (soa_rdataset->type != dns_rdatatype_soa)
894 if (soa_rdataset->rdclass != question_class)
897 CHECK(dns_rdataset_first(soa_rdataset));
898 dns_rdataset_current(soa_rdataset, &soa_rdata);
899 result = dns_rdataset_next(soa_rdataset);
900 if (result == ISC_R_SUCCESS)
902 "IXFR authority section "
903 "has multiple SOAs");
909 if (result != ISC_R_NOMORE)
912 xfrout_log1(client, question_name, question_class, ISC_LOG_DEBUG(6),
913 "%s authority section OK", mnemonic);
916 * If not a DLZ zone, decide whether to allow this transfer.
919 ns_client_aclmsg("zone transfer", question_name, reqtype,
920 client->view->rdclass, msg, sizeof(msg));
921 CHECK(ns_client_checkacl(client, NULL, msg,
922 dns_zone_getxfracl(zone),
923 ISC_TRUE, ISC_LOG_ERROR));
927 * AXFR over UDP is not possible.
929 if (reqtype == dns_rdatatype_axfr &&
930 (client->attributes & NS_CLIENTATTR_TCP) == 0)
931 FAILC(DNS_R_FORMERR, "attempted AXFR over UDP");
934 * Look up the requesting server in the peer table.
936 isc_netaddr_fromsockaddr(&na, &client->peeraddr);
937 (void)dns_peerlist_peerbyaddr(client->view->peers, &na, &peer);
940 * Decide on the transfer format (one-answer or many-answers).
943 (void)dns_peer_gettransferformat(peer, &format);
946 * Get a dynamically allocated copy of the current SOA.
949 dns_db_currentversion(db, &ver);
951 CHECK(dns_db_createsoatuple(db, ver, mctx, DNS_DIFFOP_EXISTS,
952 ¤t_soa_tuple));
954 if (reqtype == dns_rdatatype_ixfr) {
955 isc_uint32_t begin_serial, current_serial;
956 isc_boolean_t provide_ixfr;
959 * Outgoing IXFR may have been disabled for this peer
962 provide_ixfr = client->view->provideixfr;
964 (void) dns_peer_getprovideixfr(peer, &provide_ixfr);
965 if (provide_ixfr == ISC_FALSE)
970 "IXFR request missing SOA");
972 begin_serial = dns_soa_getserial(&soa_rdata);
973 current_serial = dns_soa_getserial(¤t_soa_tuple->rdata);
976 * RFC1995 says "If an IXFR query with the same or
977 * newer version number than that of the server
978 * is received, it is replied to with a single SOA
979 * record of the server's current version, just as
980 * in AXFR". The claim about AXFR is incorrect,
981 * but other than that, we do as the RFC says.
983 * Sending a single SOA record is also how we refuse
984 * IXFR over UDP (currently, we always do).
986 if (DNS_SERIAL_GE(begin_serial, current_serial) ||
987 (client->attributes & NS_CLIENTATTR_TCP) == 0)
989 CHECK(soa_rrstream_create(mctx, db, ver, &stream));
993 journalfile = is_dlz ? NULL : dns_zone_getjournal(zone);
994 if (journalfile != NULL)
995 result = ixfr_rrstream_create(mctx,
1001 result = ISC_R_NOTFOUND;
1002 if (result == ISC_R_NOTFOUND ||
1003 result == ISC_R_RANGE) {
1004 xfrout_log1(client, question_name, question_class,
1006 "IXFR version not in journal, "
1007 "falling back to AXFR");
1008 mnemonic = "AXFR-style IXFR";
1014 CHECK(axfr_rrstream_create(mctx, db, ver,
1019 * Bracket the data stream with SOAs.
1021 CHECK(soa_rrstream_create(mctx, db, ver, &soa_stream));
1022 CHECK(compound_rrstream_create(mctx, &soa_stream, &data_stream,
1028 CHECK(dns_message_getquerytsig(request, mctx, &tsigbuf));
1030 * Create the xfrout context object. This transfers the ownership
1031 * of "stream", "db", "ver", and "quota" to the xfrout context object.
1037 CHECK(xfrout_ctx_create(mctx, client, request->id,
1038 question_name, reqtype, question_class,
1039 zone, db, ver, quota, stream,
1040 dns_message_gettsigkey(request),
1044 (format == dns_many_answers) ?
1045 ISC_TRUE : ISC_FALSE,
1048 CHECK(xfrout_ctx_create(mctx, client, request->id,
1049 question_name, reqtype, question_class,
1050 zone, db, ver, quota, stream,
1051 dns_message_gettsigkey(request),
1053 dns_zone_getmaxxfrout(zone),
1054 dns_zone_getidleout(zone),
1055 (format == dns_many_answers) ?
1056 ISC_TRUE : ISC_FALSE,
1059 xfr->mnemonic = mnemonic;
1063 CHECK(xfr->stream->methods->first(xfr->stream));
1065 if (xfr->tsigkey != NULL)
1066 dns_name_format(&xfr->tsigkey->name, keyname, sizeof(keyname));
1070 xfrout_log1(client, question_name, question_class,
1071 ISC_LOG_DEBUG(1), "IXFR poll up to date%s%s",
1072 (xfr->tsigkey != NULL) ? ": TSIG " : "", keyname);
1074 xfrout_log1(client, question_name, question_class,
1075 ISC_LOG_INFO, "%s started%s%s", mnemonic,
1076 (xfr->tsigkey != NULL) ? ": TSIG " : "", keyname);
1079 * Hand the context over to sendstream(). Set xfr to NULL;
1080 * sendstream() is responsible for either passing the
1081 * context on to a later event handler or destroying it.
1086 result = ISC_R_SUCCESS;
1089 if (result == DNS_R_REFUSED)
1090 inc_stats(zone, dns_nsstatscounter_xfrrej);
1092 isc_quota_detach("a);
1093 if (current_soa_tuple != NULL)
1094 dns_difftuple_free(¤t_soa_tuple);
1096 stream->methods->destroy(&stream);
1097 if (soa_stream != NULL)
1098 soa_stream->methods->destroy(&soa_stream);
1099 if (data_stream != NULL)
1100 data_stream->methods->destroy(&data_stream);
1102 dns_db_closeversion(db, &ver, ISC_FALSE);
1106 dns_zone_detach(&zone);
1109 xfrout_fail(xfr, result, "setting up zone transfer");
1110 } else if (result != ISC_R_SUCCESS) {
1111 ns_client_log(client, DNS_LOGCATEGORY_XFER_OUT,
1112 NS_LOGMODULE_XFER_OUT,
1113 ISC_LOG_DEBUG(3), "zone transfer setup failed");
1114 ns_client_error(client, result);
1119 xfrout_ctx_create(isc_mem_t *mctx, ns_client_t *client, unsigned int id,
1120 dns_name_t *qname, dns_rdatatype_t qtype,
1121 dns_rdataclass_t qclass, dns_zone_t *zone,
1122 dns_db_t *db, dns_dbversion_t *ver, isc_quota_t *quota,
1123 rrstream_t *stream, dns_tsigkey_t *tsigkey,
1124 isc_buffer_t *lasttsig, unsigned int maxtime,
1125 unsigned int idletime, isc_boolean_t many_answers,
1126 xfrout_ctx_t **xfrp)
1129 isc_result_t result;
1133 INSIST(xfrp != NULL && *xfrp == NULL);
1134 xfr = isc_mem_get(mctx, sizeof(*xfr));
1136 return (ISC_R_NOMEMORY);
1138 isc_mem_attach(mctx, &xfr->mctx);
1140 ns_client_attach(client, &xfr->client);
1144 xfr->qclass = qclass;
1148 if (zone != NULL) /* zone will be NULL if it's DLZ */
1149 dns_zone_attach(zone, &xfr->zone);
1150 dns_db_attach(db, &xfr->db);
1151 dns_db_attachversion(db, ver, &xfr->ver);
1152 xfr->end_of_stream = ISC_FALSE;
1153 xfr->tsigkey = tsigkey;
1154 xfr->lasttsig = lasttsig;
1158 xfr->many_answers = many_answers,
1160 xfr->shuttingdown = ISC_FALSE;
1161 xfr->mnemonic = NULL;
1162 xfr->buf.base = NULL;
1163 xfr->buf.length = 0;
1170 * Allocate a temporary buffer for the uncompressed response
1171 * message data. The size should be no more than 65535 bytes
1172 * so that the compressed data will fit in a TCP message,
1173 * and no less than 65535 bytes so that an almost maximum-sized
1174 * RR will fit. Note that although 65535-byte RRs are allowed
1175 * in principle, they cannot be zone-transferred (at least not
1176 * if uncompressible), because the message and RR headers would
1177 * push the size of the TCP message over the 65536 byte limit.
1180 mem = isc_mem_get(mctx, len);
1182 result = ISC_R_NOMEMORY;
1185 isc_buffer_init(&xfr->buf, mem, len);
1188 * Allocate another temporary buffer for the compressed
1189 * response message and its TCP length prefix.
1192 mem = isc_mem_get(mctx, len);
1194 result = ISC_R_NOMEMORY;
1197 isc_buffer_init(&xfr->txlenbuf, mem, 2);
1198 isc_buffer_init(&xfr->txbuf, (char *) mem + 2, len - 2);
1200 xfr->txmemlen = len;
1202 CHECK(dns_timer_setidle(xfr->client->timer,
1203 maxtime, idletime, ISC_FALSE));
1206 * Register a shutdown callback with the client, so that we
1207 * can stop the transfer immediately when the client task
1208 * gets a shutdown event.
1210 xfr->client->shutdown = xfrout_client_shutdown;
1211 xfr->client->shutdown_arg = xfr;
1213 * These MUST be after the last "goto failure;" / CHECK to
1214 * prevent a double free by the caller.
1217 xfr->stream = stream;
1220 return (ISC_R_SUCCESS);
1223 xfrout_ctx_destroy(&xfr);
1229 * Arrange to send as much as we can of "stream" without blocking.
1232 * The stream iterator is initialized and points at an RR,
1233 * or possibly at the end of the stream (that is, the
1234 * _first method of the iterator has been called).
1237 sendstream(xfrout_ctx_t *xfr) {
1238 dns_message_t *tcpmsg = NULL;
1239 dns_message_t *msg = NULL; /* Client message if UDP, tcpmsg if TCP */
1240 isc_result_t result;
1242 isc_region_t region;
1243 dns_rdataset_t *qrdataset;
1244 dns_name_t *msgname = NULL;
1245 dns_rdata_t *msgrdata = NULL;
1246 dns_rdatalist_t *msgrdl = NULL;
1247 dns_rdataset_t *msgrds = NULL;
1248 dns_compress_t cctx;
1249 isc_boolean_t cleanup_cctx = ISC_FALSE;
1253 isc_buffer_clear(&xfr->buf);
1254 isc_buffer_clear(&xfr->txlenbuf);
1255 isc_buffer_clear(&xfr->txbuf);
1257 if ((xfr->client->attributes & NS_CLIENTATTR_TCP) == 0) {
1259 * In the UDP case, we put the response data directly into
1260 * the client message.
1262 msg = xfr->client->message;
1263 CHECK(dns_message_reply(msg, ISC_TRUE));
1266 * TCP. Build a response dns_message_t, temporarily storing
1267 * the raw, uncompressed owner names and RR data contiguously
1268 * in xfr->buf. We know that if the uncompressed data fits
1269 * in xfr->buf, the compressed data will surely fit in a TCP
1273 CHECK(dns_message_create(xfr->mctx,
1274 DNS_MESSAGE_INTENTRENDER, &tcpmsg));
1278 msg->rcode = dns_rcode_noerror;
1279 msg->flags = DNS_MESSAGEFLAG_QR | DNS_MESSAGEFLAG_AA;
1280 if ((xfr->client->attributes & NS_CLIENTATTR_RA) != 0)
1281 msg->flags |= DNS_MESSAGEFLAG_RA;
1282 CHECK(dns_message_settsigkey(msg, xfr->tsigkey));
1283 CHECK(dns_message_setquerytsig(msg, xfr->lasttsig));
1284 if (xfr->lasttsig != NULL)
1285 isc_buffer_free(&xfr->lasttsig);
1288 * Account for reserved space.
1290 if (xfr->tsigkey != NULL)
1291 INSIST(msg->reserved != 0U);
1292 isc_buffer_add(&xfr->buf, msg->reserved);
1295 * Include a question section in the first message only.
1296 * BIND 8.2.1 will not recognize an IXFR if it does not
1297 * have a question section.
1299 if (xfr->nmsg == 0) {
1300 dns_name_t *qname = NULL;
1304 * Reserve space for the 12-byte message header
1305 * and 4 bytes of question.
1307 isc_buffer_add(&xfr->buf, 12 + 4);
1310 result = dns_message_gettemprdataset(msg, &qrdataset);
1311 if (result != ISC_R_SUCCESS)
1313 dns_rdataset_init(qrdataset);
1314 dns_rdataset_makequestion(qrdataset,
1315 xfr->client->message->rdclass,
1318 result = dns_message_gettempname(msg, &qname);
1319 if (result != ISC_R_SUCCESS)
1321 dns_name_init(qname, NULL);
1322 isc_buffer_availableregion(&xfr->buf, &r);
1323 INSIST(r.length >= xfr->qname->length);
1324 r.length = xfr->qname->length;
1325 isc_buffer_putmem(&xfr->buf, xfr->qname->ndata,
1326 xfr->qname->length);
1327 dns_name_fromregion(qname, &r);
1328 ISC_LIST_INIT(qname->list);
1329 ISC_LIST_APPEND(qname->list, qrdataset, link);
1331 dns_message_addname(msg, qname, DNS_SECTION_QUESTION);
1334 * Reserve space for the 12-byte message header
1336 isc_buffer_add(&xfr->buf, 12);
1337 msg->tcp_continuation = 1;
1342 * Try to fit in as many RRs as possible, unless "one-answer"
1343 * format has been requested.
1345 for (n_rrs = 0; ; n_rrs++) {
1346 dns_name_t *name = NULL;
1348 dns_rdata_t *rdata = NULL;
1358 xfr->stream->methods->current(xfr->stream,
1359 &name, &ttl, &rdata);
1360 size = name->length + 10 + rdata->length;
1361 isc_buffer_availableregion(&xfr->buf, &r);
1362 if (size >= r.length) {
1364 * RR would not fit. If there are other RRs in the
1365 * buffer, send them now and leave this RR to the
1366 * next message. If this RR overflows the buffer
1367 * all by itself, fail.
1369 * In theory some RRs might fit in a TCP message
1370 * when compressed even if they do not fit when
1371 * uncompressed, but surely we don't want
1372 * to send such monstrosities to an unsuspecting
1376 xfrout_log(xfr, ISC_LOG_WARNING,
1377 "RR too large for zone transfer "
1378 "(%d bytes)", size);
1379 /* XXX DNS_R_RRTOOLARGE? */
1380 result = ISC_R_NOSPACE;
1386 if (isc_log_wouldlog(ns_g_lctx, XFROUT_RR_LOGLEVEL))
1387 log_rr(name, rdata, ttl); /* XXX */
1389 result = dns_message_gettempname(msg, &msgname);
1390 if (result != ISC_R_SUCCESS)
1392 dns_name_init(msgname, NULL);
1393 isc_buffer_availableregion(&xfr->buf, &r);
1394 INSIST(r.length >= name->length);
1395 r.length = name->length;
1396 isc_buffer_putmem(&xfr->buf, name->ndata, name->length);
1397 dns_name_fromregion(msgname, &r);
1399 /* Reserve space for RR header. */
1400 isc_buffer_add(&xfr->buf, 10);
1402 result = dns_message_gettemprdata(msg, &msgrdata);
1403 if (result != ISC_R_SUCCESS)
1405 isc_buffer_availableregion(&xfr->buf, &r);
1406 r.length = rdata->length;
1407 isc_buffer_putmem(&xfr->buf, rdata->data, rdata->length);
1408 dns_rdata_init(msgrdata);
1409 dns_rdata_fromregion(msgrdata,
1410 rdata->rdclass, rdata->type, &r);
1412 result = dns_message_gettemprdatalist(msg, &msgrdl);
1413 if (result != ISC_R_SUCCESS)
1415 msgrdl->type = rdata->type;
1416 msgrdl->rdclass = rdata->rdclass;
1418 if (rdata->type == dns_rdatatype_sig ||
1419 rdata->type == dns_rdatatype_rrsig)
1420 msgrdl->covers = dns_rdata_covers(rdata);
1422 msgrdl->covers = dns_rdatatype_none;
1423 ISC_LINK_INIT(msgrdl, link);
1424 ISC_LIST_INIT(msgrdl->rdata);
1425 ISC_LIST_APPEND(msgrdl->rdata, msgrdata, link);
1427 result = dns_message_gettemprdataset(msg, &msgrds);
1428 if (result != ISC_R_SUCCESS)
1430 dns_rdataset_init(msgrds);
1431 result = dns_rdatalist_tordataset(msgrdl, msgrds);
1432 INSIST(result == ISC_R_SUCCESS);
1434 ISC_LIST_APPEND(msgname->list, msgrds, link);
1436 dns_message_addname(msg, msgname, DNS_SECTION_ANSWER);
1439 result = xfr->stream->methods->next(xfr->stream);
1440 if (result == ISC_R_NOMORE) {
1441 xfr->end_of_stream = ISC_TRUE;
1446 if (! xfr->many_answers)
1450 if ((xfr->client->attributes & NS_CLIENTATTR_TCP) != 0) {
1451 CHECK(dns_compress_init(&cctx, -1, xfr->mctx));
1452 dns_compress_setsensitive(&cctx, ISC_TRUE);
1453 cleanup_cctx = ISC_TRUE;
1454 CHECK(dns_message_renderbegin(msg, &cctx, &xfr->txbuf));
1455 CHECK(dns_message_rendersection(msg, DNS_SECTION_QUESTION, 0));
1456 CHECK(dns_message_rendersection(msg, DNS_SECTION_ANSWER, 0));
1457 CHECK(dns_message_renderend(msg));
1458 dns_compress_invalidate(&cctx);
1459 cleanup_cctx = ISC_FALSE;
1461 isc_buffer_usedregion(&xfr->txbuf, &used);
1462 isc_buffer_putuint16(&xfr->txlenbuf,
1463 (isc_uint16_t)used.length);
1464 region.base = xfr->txlenbuf.base;
1465 region.length = 2 + used.length;
1466 xfrout_log(xfr, ISC_LOG_DEBUG(8),
1467 "sending TCP message of %d bytes",
1469 CHECK(isc_socket_send(xfr->client->tcpsocket, /* XXX */
1470 ®ion, xfr->client->task,
1475 xfrout_log(xfr, ISC_LOG_DEBUG(8), "sending IXFR UDP response");
1476 ns_client_send(xfr->client);
1477 xfr->stream->methods->pause(xfr->stream);
1478 xfrout_ctx_destroy(&xfr);
1482 /* Advance lasttsig to be the last TSIG generated */
1483 CHECK(dns_message_getquerytsig(msg, xfr->mctx, &xfr->lasttsig));
1488 if (msgname != NULL) {
1489 if (msgrds != NULL) {
1490 if (dns_rdataset_isassociated(msgrds))
1491 dns_rdataset_disassociate(msgrds);
1492 dns_message_puttemprdataset(msg, &msgrds);
1494 if (msgrdl != NULL) {
1495 ISC_LIST_UNLINK(msgrdl->rdata, msgrdata, link);
1496 dns_message_puttemprdatalist(msg, &msgrdl);
1498 if (msgrdata != NULL)
1499 dns_message_puttemprdata(msg, &msgrdata);
1500 dns_message_puttempname(msg, &msgname);
1504 dns_message_destroy(&tcpmsg);
1507 dns_compress_invalidate(&cctx);
1509 * Make sure to release any locks held by database
1510 * iterators before returning from the event handler.
1512 xfr->stream->methods->pause(xfr->stream);
1514 if (result == ISC_R_SUCCESS)
1517 xfrout_fail(xfr, result, "sending zone data");
1521 xfrout_ctx_destroy(xfrout_ctx_t **xfrp) {
1522 xfrout_ctx_t *xfr = *xfrp;
1523 ns_client_t *client = NULL;
1525 INSIST(xfr->sends == 0);
1527 xfr->client->shutdown = NULL;
1528 xfr->client->shutdown_arg = NULL;
1530 if (xfr->stream != NULL)
1531 xfr->stream->methods->destroy(&xfr->stream);
1532 if (xfr->buf.base != NULL)
1533 isc_mem_put(xfr->mctx, xfr->buf.base, xfr->buf.length);
1534 if (xfr->txmem != NULL)
1535 isc_mem_put(xfr->mctx, xfr->txmem, xfr->txmemlen);
1536 if (xfr->lasttsig != NULL)
1537 isc_buffer_free(&xfr->lasttsig);
1538 if (xfr->quota != NULL)
1539 isc_quota_detach(&xfr->quota);
1540 if (xfr->ver != NULL)
1541 dns_db_closeversion(xfr->db, &xfr->ver, ISC_FALSE);
1542 if (xfr->zone != NULL)
1543 dns_zone_detach(&xfr->zone);
1544 if (xfr->db != NULL)
1545 dns_db_detach(&xfr->db);
1548 * We want to detch the client after we have released the memory
1549 * context as ns_client_detach checks the memory reference count.
1551 ns_client_attach(xfr->client, &client);
1552 ns_client_detach(&xfr->client);
1553 isc_mem_putanddetach(&xfr->mctx, xfr, sizeof(*xfr));
1554 ns_client_detach(&client);
1560 xfrout_senddone(isc_task_t *task, isc_event_t *event) {
1561 isc_socketevent_t *sev = (isc_socketevent_t *)event;
1562 xfrout_ctx_t *xfr = (xfrout_ctx_t *)event->ev_arg;
1563 isc_result_t evresult = sev->result;
1567 INSIST(event->ev_type == ISC_SOCKEVENT_SENDDONE);
1569 isc_event_free(&event);
1571 INSIST(xfr->sends == 0);
1573 (void)isc_timer_touch(xfr->client->timer);
1574 if (xfr->shuttingdown == ISC_TRUE) {
1575 xfrout_maybe_destroy(xfr);
1576 } else if (evresult != ISC_R_SUCCESS) {
1577 xfrout_fail(xfr, evresult, "send");
1578 } else if (xfr->end_of_stream == ISC_FALSE) {
1581 /* End of zone transfer stream. */
1582 inc_stats(xfr->zone, dns_nsstatscounter_xfrdone);
1583 xfrout_log(xfr, ISC_LOG_INFO, "%s ended", xfr->mnemonic);
1584 ns_client_next(xfr->client, ISC_R_SUCCESS);
1585 xfrout_ctx_destroy(&xfr);
1590 xfrout_fail(xfrout_ctx_t *xfr, isc_result_t result, const char *msg) {
1591 xfr->shuttingdown = ISC_TRUE;
1592 xfrout_log(xfr, ISC_LOG_ERROR, "%s: %s",
1593 msg, isc_result_totext(result));
1594 xfrout_maybe_destroy(xfr);
1598 xfrout_maybe_destroy(xfrout_ctx_t *xfr) {
1599 INSIST(xfr->shuttingdown == ISC_TRUE);
1600 if (xfr->sends > 0) {
1602 * If we are currently sending, cancel it and wait for
1603 * cancel event before destroying the context.
1605 isc_socket_cancel(xfr->client->tcpsocket, xfr->client->task,
1606 ISC_SOCKCANCEL_SEND);
1608 ns_client_next(xfr->client, ISC_R_CANCELED);
1609 xfrout_ctx_destroy(&xfr);
1614 xfrout_client_shutdown(void *arg, isc_result_t result) {
1615 xfrout_ctx_t *xfr = (xfrout_ctx_t *) arg;
1616 xfrout_fail(xfr, result, "aborted");
1620 * Log outgoing zone transfer messages in a format like
1621 * <client>: transfer of <zone>: <message>
1625 xfrout_logv(ns_client_t *client, dns_name_t *zonename,
1626 dns_rdataclass_t rdclass, int level, const char *fmt, va_list ap)
1627 ISC_FORMAT_PRINTF(5, 0);
1630 xfrout_logv(ns_client_t *client, dns_name_t *zonename,
1631 dns_rdataclass_t rdclass, int level, const char *fmt, va_list ap)
1634 char namebuf[DNS_NAME_FORMATSIZE];
1635 char classbuf[DNS_RDATACLASS_FORMATSIZE];
1637 dns_name_format(zonename, namebuf, sizeof(namebuf));
1638 dns_rdataclass_format(rdclass, classbuf, sizeof(classbuf));
1639 vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap);
1640 ns_client_log(client, DNS_LOGCATEGORY_XFER_OUT,
1641 NS_LOGMODULE_XFER_OUT, level,
1642 "transfer of '%s/%s': %s", namebuf, classbuf, msgbuf);
1646 * Logging function for use when a xfrout_ctx_t has not yet been created.
1649 xfrout_log1(ns_client_t *client, dns_name_t *zonename,
1650 dns_rdataclass_t rdclass, int level, const char *fmt, ...) {
1653 xfrout_logv(client, zonename, rdclass, level, fmt, ap);
1658 * Logging function for use when there is a xfrout_ctx_t.
1661 xfrout_log(xfrout_ctx_t *xfr, int level, const char *fmt, ...) {
1664 xfrout_logv(xfr->client, xfr->qname, xfr->qclass, level, fmt, ap);