1 /* $NetBSD: notify.c,v 1.4 2014/12/10 04:37:51 christos Exp $ */
4 * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2003 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: notify.c,v 1.37 2007/06/19 23:46:59 tbox Exp */
25 #include <isc/print.h>
27 #include <dns/message.h>
28 #include <dns/rdataset.h>
29 #include <dns/result.h>
35 #include <named/log.h>
36 #include <named/notify.h>
40 * This module implements notify as in RFC1996.
44 notify_log(ns_client_t
*client
, int level
, const char *fmt
, ...) {
48 ns_client_logv(client
, DNS_LOGCATEGORY_NOTIFY
, NS_LOGMODULE_NOTIFY
,
54 respond(ns_client_t
*client
, isc_result_t result
) {
56 dns_message_t
*message
;
57 isc_result_t msg_result
;
59 message
= client
->message
;
60 rcode
= dns_result_torcode(result
);
62 msg_result
= dns_message_reply(message
, ISC_TRUE
);
63 if (msg_result
!= ISC_R_SUCCESS
)
64 msg_result
= dns_message_reply(message
, ISC_FALSE
);
65 if (msg_result
!= ISC_R_SUCCESS
) {
66 ns_client_next(client
, msg_result
);
69 message
->rcode
= rcode
;
70 if (rcode
== dns_rcode_noerror
)
71 message
->flags
|= DNS_MESSAGEFLAG_AA
;
73 message
->flags
&= ~DNS_MESSAGEFLAG_AA
;
74 ns_client_send(client
);
78 ns_notify_start(ns_client_t
*client
) {
79 dns_message_t
*request
= client
->message
;
82 dns_rdataset_t
*zone_rdataset
;
83 dns_zone_t
*zone
= NULL
;
84 char namebuf
[DNS_NAME_FORMATSIZE
];
85 char tsigbuf
[DNS_NAME_FORMATSIZE
+ sizeof(": TSIG ''")];
86 dns_tsigkey_t
*tsigkey
;
89 * Interpret the question section.
91 result
= dns_message_firstname(request
, DNS_SECTION_QUESTION
);
92 if (result
!= ISC_R_SUCCESS
) {
93 notify_log(client
, ISC_LOG_NOTICE
,
94 "notify question section empty");
99 * The question section must contain exactly one question.
102 dns_message_currentname(request
, DNS_SECTION_QUESTION
, &zonename
);
103 zone_rdataset
= ISC_LIST_HEAD(zonename
->list
);
104 if (ISC_LIST_NEXT(zone_rdataset
, link
) != NULL
) {
105 notify_log(client
, ISC_LOG_NOTICE
,
106 "notify question section contains multiple RRs");
110 /* The zone section must have exactly one name. */
111 result
= dns_message_nextname(request
, DNS_SECTION_ZONE
);
112 if (result
!= ISC_R_NOMORE
) {
113 notify_log(client
, ISC_LOG_NOTICE
,
114 "notify question section contains multiple RRs");
118 /* The one rdataset must be an SOA. */
119 if (zone_rdataset
->type
!= dns_rdatatype_soa
) {
120 notify_log(client
, ISC_LOG_NOTICE
,
121 "notify question section contains no SOA");
125 tsigkey
= dns_message_gettsigkey(request
);
126 if (tsigkey
!= NULL
) {
127 dns_name_format(&tsigkey
->name
, namebuf
, sizeof(namebuf
));
129 if (tsigkey
->generated
) {
130 char cnamebuf
[DNS_NAME_FORMATSIZE
];
131 dns_name_format(tsigkey
->creator
, cnamebuf
,
133 snprintf(tsigbuf
, sizeof(tsigbuf
), ": TSIG '%s' (%s)",
136 snprintf(tsigbuf
, sizeof(tsigbuf
), ": TSIG '%s'",
141 dns_name_format(zonename
, namebuf
, sizeof(namebuf
));
142 result
= dns_zt_find(client
->view
->zonetable
, zonename
, 0, NULL
,
144 if (result
!= ISC_R_SUCCESS
)
147 switch (dns_zone_gettype(zone
)) {
148 case dns_zone_master
:
150 case dns_zone_stub
: /* Allow dialup passive to work. */
151 notify_log(client
, ISC_LOG_INFO
,
152 "received notify for zone '%s'%s", namebuf
, tsigbuf
);
153 respond(client
, dns_zone_notifyreceive(zone
,
154 ns_client_getsockaddr(client
), request
));
159 dns_zone_detach(&zone
);
163 notify_log(client
, ISC_LOG_NOTICE
,
164 "received notify for zone '%s'%s: not authoritative",
166 result
= DNS_R_NOTAUTH
;
170 result
= DNS_R_FORMERR
;
174 dns_zone_detach(&zone
);
175 respond(client
, result
);