2 * Copyright (C) 2004 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.24.2.2.2.7 2004/08/28 06:25:30 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>
36 * This module implements notify as in RFC 1996.
40 notify_log(ns_client_t *client, int level, const char *fmt, ...) {
44 ns_client_logv(client, DNS_LOGCATEGORY_NOTIFY, NS_LOGMODULE_NOTIFY,
50 respond(ns_client_t *client, isc_result_t result) {
52 dns_message_t *message;
53 isc_result_t msg_result;
55 message = client->message;
56 rcode = dns_result_torcode(result);
58 msg_result = dns_message_reply(message, ISC_TRUE);
59 if (msg_result != ISC_R_SUCCESS)
60 msg_result = dns_message_reply(message, ISC_FALSE);
61 if (msg_result != ISC_R_SUCCESS) {
62 ns_client_next(client, msg_result);
65 message->rcode = rcode;
66 if (rcode == dns_rcode_noerror)
67 message->flags |= DNS_MESSAGEFLAG_AA;
69 message->flags &= ~DNS_MESSAGEFLAG_AA;
70 ns_client_send(client);
74 ns_notify_start(ns_client_t *client) {
75 dns_message_t *request = client->message;
78 dns_rdataset_t *zone_rdataset;
79 dns_zone_t *zone = NULL;
80 char namebuf[DNS_NAME_FORMATSIZE];
81 char tsigbuf[DNS_NAME_FORMATSIZE + sizeof(": TSIG ''")];
85 * Interpret the question section.
87 result = dns_message_firstname(request, DNS_SECTION_QUESTION);
88 if (result != ISC_R_SUCCESS) {
89 notify_log(client, ISC_LOG_NOTICE,
90 "notify question section empty");
95 * The question section must contain exactly one question.
98 dns_message_currentname(request, DNS_SECTION_QUESTION, &zonename);
99 zone_rdataset = ISC_LIST_HEAD(zonename->list);
100 if (ISC_LIST_NEXT(zone_rdataset, link) != NULL) {
101 notify_log(client, ISC_LOG_NOTICE,
102 "notify question section contains multiple RRs");
106 /* The zone section must have exactly one name. */
107 result = dns_message_nextname(request, DNS_SECTION_ZONE);
108 if (result != ISC_R_NOMORE) {
109 notify_log(client, ISC_LOG_NOTICE,
110 "notify question section contains multiple RRs");
114 /* The one rdataset must be an SOA. */
115 if (zone_rdataset->type != dns_rdatatype_soa) {
116 notify_log(client, ISC_LOG_NOTICE,
117 "notify question section contains no SOA");
122 if (dns_message_gettsig(request, &tsigname) != NULL) {
123 dns_name_format(tsigname, namebuf, sizeof(namebuf));
124 snprintf(tsigbuf, sizeof(tsigbuf), ": TSIG '%s'", namebuf);
127 dns_name_format(zonename, namebuf, sizeof(namebuf));
128 result = dns_zt_find(client->view->zonetable, zonename, 0, NULL,
130 if (result != ISC_R_SUCCESS)
133 switch (dns_zone_gettype(zone)) {
134 case dns_zone_master:
136 case dns_zone_stub: /* Allow dialup passive to work. */
137 notify_log(client, ISC_LOG_INFO,
138 "received notify for zone '%s'%s", namebuf, tsigbuf);
139 respond(client, dns_zone_notifyreceive(zone,
140 ns_client_getsockaddr(client), request));
145 dns_zone_detach(&zone);
149 notify_log(client, ISC_LOG_NOTICE,
150 "received notify for zone '%s'%s: not authoritative",
152 result = DNS_R_NOTAUTH;
156 result = DNS_R_FORMERR;
160 dns_zone_detach(&zone);
161 respond(client, result);