2 * Copyright (C) 2004-2007 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.
18 /* $Id: notify.c,v 1.37 2007/06/19 23:46:59 tbox Exp $ */
23 #include <isc/print.h>
25 #include <dns/message.h>
26 #include <dns/rdataset.h>
27 #include <dns/result.h>
33 #include <named/log.h>
34 #include <named/notify.h>
38 * This module implements notify as in RFC1996.
42 notify_log(ns_client_t
*client
, int level
, const char *fmt
, ...) {
46 ns_client_logv(client
, DNS_LOGCATEGORY_NOTIFY
, NS_LOGMODULE_NOTIFY
,
52 respond(ns_client_t
*client
, isc_result_t result
) {
54 dns_message_t
*message
;
55 isc_result_t msg_result
;
57 message
= client
->message
;
58 rcode
= dns_result_torcode(result
);
60 msg_result
= dns_message_reply(message
, ISC_TRUE
);
61 if (msg_result
!= ISC_R_SUCCESS
)
62 msg_result
= dns_message_reply(message
, ISC_FALSE
);
63 if (msg_result
!= ISC_R_SUCCESS
) {
64 ns_client_next(client
, msg_result
);
67 message
->rcode
= rcode
;
68 if (rcode
== dns_rcode_noerror
)
69 message
->flags
|= DNS_MESSAGEFLAG_AA
;
71 message
->flags
&= ~DNS_MESSAGEFLAG_AA
;
72 ns_client_send(client
);
76 ns_notify_start(ns_client_t
*client
) {
77 dns_message_t
*request
= client
->message
;
80 dns_rdataset_t
*zone_rdataset
;
81 dns_zone_t
*zone
= NULL
;
82 char namebuf
[DNS_NAME_FORMATSIZE
];
83 char tsigbuf
[DNS_NAME_FORMATSIZE
+ sizeof(": TSIG ''")];
84 dns_tsigkey_t
*tsigkey
;
87 * Interpret the question section.
89 result
= dns_message_firstname(request
, DNS_SECTION_QUESTION
);
90 if (result
!= ISC_R_SUCCESS
) {
91 notify_log(client
, ISC_LOG_NOTICE
,
92 "notify question section empty");
97 * The question section must contain exactly one question.
100 dns_message_currentname(request
, DNS_SECTION_QUESTION
, &zonename
);
101 zone_rdataset
= ISC_LIST_HEAD(zonename
->list
);
102 if (ISC_LIST_NEXT(zone_rdataset
, link
) != NULL
) {
103 notify_log(client
, ISC_LOG_NOTICE
,
104 "notify question section contains multiple RRs");
108 /* The zone section must have exactly one name. */
109 result
= dns_message_nextname(request
, DNS_SECTION_ZONE
);
110 if (result
!= ISC_R_NOMORE
) {
111 notify_log(client
, ISC_LOG_NOTICE
,
112 "notify question section contains multiple RRs");
116 /* The one rdataset must be an SOA. */
117 if (zone_rdataset
->type
!= dns_rdatatype_soa
) {
118 notify_log(client
, ISC_LOG_NOTICE
,
119 "notify question section contains no SOA");
123 tsigkey
= dns_message_gettsigkey(request
);
124 if (tsigkey
!= NULL
) {
125 dns_name_format(&tsigkey
->name
, namebuf
, sizeof(namebuf
));
127 if (tsigkey
->generated
) {
128 char cnamebuf
[DNS_NAME_FORMATSIZE
];
129 dns_name_format(tsigkey
->creator
, cnamebuf
,
131 snprintf(tsigbuf
, sizeof(tsigbuf
), ": TSIG '%s' (%s)",
134 snprintf(tsigbuf
, sizeof(tsigbuf
), ": TSIG '%s'",
139 dns_name_format(zonename
, namebuf
, sizeof(namebuf
));
140 result
= dns_zt_find(client
->view
->zonetable
, zonename
, 0, NULL
,
142 if (result
!= ISC_R_SUCCESS
)
145 switch (dns_zone_gettype(zone
)) {
146 case dns_zone_master
:
148 case dns_zone_stub
: /* Allow dialup passive to work. */
149 notify_log(client
, ISC_LOG_INFO
,
150 "received notify for zone '%s'%s", namebuf
, tsigbuf
);
151 respond(client
, dns_zone_notifyreceive(zone
,
152 ns_client_getsockaddr(client
), request
));
157 dns_zone_detach(&zone
);
161 notify_log(client
, ISC_LOG_NOTICE
,
162 "received notify for zone '%s'%s: not authoritative",
164 result
= DNS_R_NOTAUTH
;
168 result
= DNS_R_FORMERR
;
172 dns_zone_detach(&zone
);
173 respond(client
, result
);