00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include <isc/log.h>
00023 #include <isc/print.h>
00024
00025 #include <dns/message.h>
00026 #include <dns/rdataset.h>
00027 #include <dns/result.h>
00028 #include <dns/tsig.h>
00029 #include <dns/view.h>
00030 #include <dns/zone.h>
00031 #include <dns/zt.h>
00032
00033 #include <named/log.h>
00034 #include <named/notify.h>
00035
00036
00037
00038
00039
00040
00041 static void
00042 notify_log(ns_client_t *client, int level, const char *fmt, ...) {
00043 va_list ap;
00044
00045 va_start(ap, fmt);
00046 ns_client_logv(client, DNS_LOGCATEGORY_NOTIFY, NS_LOGMODULE_NOTIFY,
00047 level, fmt, ap);
00048 va_end(ap);
00049 }
00050
00051 static void
00052 respond(ns_client_t *client, isc_result_t result) {
00053 dns_rcode_t rcode;
00054 dns_message_t *message;
00055 isc_result_t msg_result;
00056
00057 message = client->message;
00058 rcode = dns_result_torcode(result);
00059
00060 msg_result = dns_message_reply(message, ISC_TRUE);
00061 if (msg_result != ISC_R_SUCCESS)
00062 msg_result = dns_message_reply(message, ISC_FALSE);
00063 if (msg_result != ISC_R_SUCCESS) {
00064 ns_client_next(client, msg_result);
00065 return;
00066 }
00067 message->rcode = rcode;
00068 if (rcode == dns_rcode_noerror)
00069 message->flags |= DNS_MESSAGEFLAG_AA;
00070 else
00071 message->flags &= ~DNS_MESSAGEFLAG_AA;
00072 ns_client_send(client);
00073 }
00074
00075 void
00076 ns_notify_start(ns_client_t *client) {
00077 dns_message_t *request = client->message;
00078 isc_result_t result;
00079 dns_name_t *zonename;
00080 dns_rdataset_t *zone_rdataset;
00081 dns_zone_t *zone = NULL;
00082 char namebuf[DNS_NAME_FORMATSIZE];
00083 char tsigbuf[DNS_NAME_FORMATSIZE + sizeof(": TSIG ''")];
00084 dns_tsigkey_t *tsigkey;
00085
00086
00087
00088
00089 result = dns_message_firstname(request, DNS_SECTION_QUESTION);
00090 if (result != ISC_R_SUCCESS) {
00091 notify_log(client, ISC_LOG_NOTICE,
00092 "notify question section empty");
00093 goto formerr;
00094 }
00095
00096
00097
00098
00099 zonename = NULL;
00100 dns_message_currentname(request, DNS_SECTION_QUESTION, &zonename);
00101 zone_rdataset = ISC_LIST_HEAD(zonename->list);
00102 if (ISC_LIST_NEXT(zone_rdataset, link) != NULL) {
00103 notify_log(client, ISC_LOG_NOTICE,
00104 "notify question section contains multiple RRs");
00105 goto formerr;
00106 }
00107
00108
00109 result = dns_message_nextname(request, DNS_SECTION_ZONE);
00110 if (result != ISC_R_NOMORE) {
00111 notify_log(client, ISC_LOG_NOTICE,
00112 "notify question section contains multiple RRs");
00113 goto formerr;
00114 }
00115
00116
00117 if (zone_rdataset->type != dns_rdatatype_soa) {
00118 notify_log(client, ISC_LOG_NOTICE,
00119 "notify question section contains no SOA");
00120 goto formerr;
00121 }
00122
00123 tsigkey = dns_message_gettsigkey(request);
00124 if (tsigkey != NULL) {
00125 dns_name_format(&tsigkey->name, namebuf, sizeof(namebuf));
00126
00127 if (tsigkey->generated) {
00128 char cnamebuf[DNS_NAME_FORMATSIZE];
00129 dns_name_format(tsigkey->creator, cnamebuf,
00130 sizeof(cnamebuf));
00131 snprintf(tsigbuf, sizeof(tsigbuf), ": TSIG '%s' (%s)",
00132 namebuf, cnamebuf);
00133 } else {
00134 snprintf(tsigbuf, sizeof(tsigbuf), ": TSIG '%s'",
00135 namebuf);
00136 }
00137 } else
00138 tsigbuf[0] = '\0';
00139 dns_name_format(zonename, namebuf, sizeof(namebuf));
00140 result = dns_zt_find(client->view->zonetable, zonename, 0, NULL,
00141 &zone);
00142 if (result != ISC_R_SUCCESS)
00143 goto notauth;
00144
00145 switch (dns_zone_gettype(zone)) {
00146 case dns_zone_master:
00147 case dns_zone_slave:
00148 case dns_zone_stub:
00149 notify_log(client, ISC_LOG_INFO,
00150 "received notify for zone '%s'%s", namebuf, tsigbuf);
00151 respond(client, dns_zone_notifyreceive(zone,
00152 ns_client_getsockaddr(client), request));
00153 break;
00154 default:
00155 goto notauth;
00156 }
00157 dns_zone_detach(&zone);
00158 return;
00159
00160 notauth:
00161 notify_log(client, ISC_LOG_NOTICE,
00162 "received notify for zone '%s'%s: not authoritative",
00163 namebuf, tsigbuf);
00164 result = DNS_R_NOTAUTH;
00165 goto failure;
00166
00167 formerr:
00168 result = DNS_R_FORMERR;
00169
00170 failure:
00171 if (zone != NULL)
00172 dns_zone_detach(&zone);
00173 respond(client, result);
00174 }