2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001, 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.24.2.3 2004/03/09 06:09:19 marka Exp $ */
24 #include <dns/message.h>
25 #include <dns/rdataset.h>
26 #include <dns/result.h>
31 #include <named/log.h>
32 #include <named/notify.h>
35 * This module implements notify as in RFC 1996.
39 notify_log(int level
, const char *fmt
, ...) {
43 isc_log_vwrite(ns_g_lctx
, DNS_LOGCATEGORY_NOTIFY
, NS_LOGMODULE_NOTIFY
,
49 respond(ns_client_t
*client
, isc_result_t result
) {
51 dns_message_t
*message
;
52 isc_result_t msg_result
;
54 message
= client
->message
;
55 rcode
= dns_result_torcode(result
);
57 msg_result
= dns_message_reply(message
, ISC_TRUE
);
58 if (msg_result
!= ISC_R_SUCCESS
)
59 msg_result
= dns_message_reply(message
, ISC_FALSE
);
60 if (msg_result
!= ISC_R_SUCCESS
) {
61 ns_client_next(client
, msg_result
);
64 message
->rcode
= rcode
;
65 if (rcode
== dns_rcode_noerror
)
66 message
->flags
|= DNS_MESSAGEFLAG_AA
;
68 message
->flags
&= ~DNS_MESSAGEFLAG_AA
;
69 ns_client_send(client
);
73 ns_notify_start(ns_client_t
*client
) {
74 dns_message_t
*request
= client
->message
;
77 dns_rdataset_t
*zone_rdataset
;
78 dns_zone_t
*zone
= NULL
;
79 char str
[DNS_NAME_FORMATSIZE
];
82 * Interpret the question section.
84 result
= dns_message_firstname(request
, DNS_SECTION_QUESTION
);
85 if (result
!= ISC_R_SUCCESS
) {
86 notify_log(ISC_LOG_INFO
, "notify question section empty");
91 * The question section must contain exactly one question.
94 dns_message_currentname(request
, DNS_SECTION_QUESTION
, &zonename
);
95 zone_rdataset
= ISC_LIST_HEAD(zonename
->list
);
96 if (ISC_LIST_NEXT(zone_rdataset
, link
) != NULL
) {
97 notify_log(ISC_LOG_INFO
,
98 "notify question section contains multiple RRs");
102 /* The zone section must have exactly one name. */
103 result
= dns_message_nextname(request
, DNS_SECTION_ZONE
);
104 if (result
!= ISC_R_NOMORE
) {
105 notify_log(ISC_LOG_INFO
,
106 "notify question section contains multiple RRs");
110 /* The one rdataset must be an SOA. */
111 if (zone_rdataset
->type
!= dns_rdatatype_soa
) {
112 notify_log(ISC_LOG_INFO
,
113 "notify question section contains no SOA");
117 dns_name_format(zonename
, str
, sizeof(str
));
118 result
= dns_zt_find(client
->view
->zonetable
, zonename
, 0, NULL
,
120 if (result
!= ISC_R_SUCCESS
)
123 switch(dns_zone_gettype(zone
)) {
124 case dns_zone_master
:
126 case dns_zone_stub
: /* Allow dialup passive to work. */
127 notify_log(ISC_LOG_INFO
, "received notify for zone '%s'", str
);
128 respond(client
, dns_zone_notifyreceive(zone
,
129 ns_client_getsockaddr(client
), request
));
134 dns_zone_detach(&zone
);
138 notify_log(ISC_LOG_INFO
,
139 "received notify for zone '%s': not authoritative",
141 result
= DNS_R_NOTAUTH
;
145 result
= DNS_R_FORMERR
;
149 dns_zone_detach(&zone
);
150 respond(client
, result
);