2 * Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and 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.30.18.3 2005/04/29 00:15:26 marka Exp $ */
23 #include <isc/print.h>
25 #include <dns/message.h>
26 #include <dns/rdataset.h>
27 #include <dns/result.h>
32 #include <named/log.h>
33 #include <named/notify.h>
37 * This module implements notify as in RFC1996.
41 notify_log(ns_client_t
*client
, int level
, const char *fmt
, ...) {
45 ns_client_logv(client
, DNS_LOGCATEGORY_NOTIFY
, NS_LOGMODULE_NOTIFY
,
51 respond(ns_client_t
*client
, isc_result_t result
) {
53 dns_message_t
*message
;
54 isc_result_t msg_result
;
56 message
= client
->message
;
57 rcode
= dns_result_torcode(result
);
59 msg_result
= dns_message_reply(message
, ISC_TRUE
);
60 if (msg_result
!= ISC_R_SUCCESS
)
61 msg_result
= dns_message_reply(message
, ISC_FALSE
);
62 if (msg_result
!= ISC_R_SUCCESS
) {
63 ns_client_next(client
, msg_result
);
66 message
->rcode
= rcode
;
67 if (rcode
== dns_rcode_noerror
)
68 message
->flags
|= DNS_MESSAGEFLAG_AA
;
70 message
->flags
&= ~DNS_MESSAGEFLAG_AA
;
71 ns_client_send(client
);
75 ns_notify_start(ns_client_t
*client
) {
76 dns_message_t
*request
= client
->message
;
79 dns_rdataset_t
*zone_rdataset
;
80 dns_zone_t
*zone
= NULL
;
81 char namebuf
[DNS_NAME_FORMATSIZE
];
82 char tsigbuf
[DNS_NAME_FORMATSIZE
+ sizeof(": TSIG ''")];
86 * Interpret the question section.
88 result
= dns_message_firstname(request
, DNS_SECTION_QUESTION
);
89 if (result
!= ISC_R_SUCCESS
) {
90 notify_log(client
, ISC_LOG_NOTICE
,
91 "notify question section empty");
96 * The question section must contain exactly one question.
99 dns_message_currentname(request
, DNS_SECTION_QUESTION
, &zonename
);
100 zone_rdataset
= ISC_LIST_HEAD(zonename
->list
);
101 if (ISC_LIST_NEXT(zone_rdataset
, link
) != NULL
) {
102 notify_log(client
, ISC_LOG_NOTICE
,
103 "notify question section contains multiple RRs");
107 /* The zone section must have exactly one name. */
108 result
= dns_message_nextname(request
, DNS_SECTION_ZONE
);
109 if (result
!= ISC_R_NOMORE
) {
110 notify_log(client
, ISC_LOG_NOTICE
,
111 "notify question section contains multiple RRs");
115 /* The one rdataset must be an SOA. */
116 if (zone_rdataset
->type
!= dns_rdatatype_soa
) {
117 notify_log(client
, ISC_LOG_NOTICE
,
118 "notify question section contains no SOA");
123 if (dns_message_gettsig(request
, &tsigname
) != NULL
) {
124 dns_name_format(tsigname
, namebuf
, sizeof(namebuf
));
125 snprintf(tsigbuf
, sizeof(tsigbuf
), ": TSIG '%s'", namebuf
);
128 dns_name_format(zonename
, namebuf
, sizeof(namebuf
));
129 result
= dns_zt_find(client
->view
->zonetable
, zonename
, 0, NULL
,
131 if (result
!= ISC_R_SUCCESS
)
134 switch (dns_zone_gettype(zone
)) {
135 case dns_zone_master
:
137 case dns_zone_stub
: /* Allow dialup passive to work. */
138 notify_log(client
, ISC_LOG_INFO
,
139 "received notify for zone '%s'%s", namebuf
, tsigbuf
);
140 respond(client
, dns_zone_notifyreceive(zone
,
141 ns_client_getsockaddr(client
), request
));
146 dns_zone_detach(&zone
);
150 notify_log(client
, ISC_LOG_NOTICE
,
151 "received notify for zone '%s'%s: not authoritative",
153 result
= DNS_R_NOTAUTH
;
157 result
= DNS_R_FORMERR
;
161 dns_zone_detach(&zone
);
162 respond(client
, result
);