1999-12-14 06:58:27 +00:00
|
|
|
/*
|
2000-02-03 22:29:57 +00:00
|
|
|
* Copyright (C) 1999, 2000 Internet Software Consortium.
|
1999-12-14 06:58:27 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
2000-07-27 09:55:03 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
|
|
|
|
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
|
|
|
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
|
|
|
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
1999-12-14 06:58:27 +00:00
|
|
|
*/
|
|
|
|
|
2000-07-27 09:55:03 +00:00
|
|
|
/* $Id: notify.c,v 1.19 2000/07/27 09:37:02 tale Exp $ */
|
2000-06-22 22:00:42 +00:00
|
|
|
|
1999-12-14 06:58:27 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <dns/message.h>
|
|
|
|
#include <dns/rdataset.h>
|
|
|
|
#include <dns/result.h>
|
|
|
|
#include <dns/view.h>
|
|
|
|
#include <dns/zone.h>
|
|
|
|
#include <dns/zt.h>
|
|
|
|
|
|
|
|
#include <named/log.h>
|
|
|
|
#include <named/notify.h>
|
|
|
|
|
|
|
|
/*
|
1999-12-16 01:23:17 +00:00
|
|
|
* This module implements notify as in RFC 1996.
|
1999-12-14 06:58:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convenience macro of common isc_log_write() arguments
|
|
|
|
* to use in reportings server errors.
|
|
|
|
*/
|
|
|
|
#define NOTIFY_ERROR_LOGARGS \
|
2000-03-23 00:55:12 +00:00
|
|
|
ns_g_lctx, DNS_LOGCATEGORY_NOTIFY, NS_LOGMODULE_NOTIFY, \
|
1999-12-14 06:58:27 +00:00
|
|
|
ISC_LOG_ERROR
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convenience macro of common isc_log_write() arguments
|
2000-02-02 21:03:12 +00:00
|
|
|
* to use in tracing notify protocol requests.
|
1999-12-14 06:58:27 +00:00
|
|
|
*/
|
|
|
|
#define NOTIFY_PROTOCOL_LOGARGS \
|
2000-03-23 00:55:12 +00:00
|
|
|
ns_g_lctx, DNS_LOGCATEGORY_NOTIFY, NS_LOGMODULE_NOTIFY, \
|
1999-12-14 06:58:27 +00:00
|
|
|
ISC_LOG_INFO
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convenience macro of common isc_log_write() arguments
|
|
|
|
* to use in low-level debug tracing.
|
|
|
|
*/
|
|
|
|
#define NOTIFY_DEBUG_LOGARGS \
|
2000-03-23 00:55:12 +00:00
|
|
|
ns_g_lctx, DNS_LOGCATEGORY_NOTIFY, NS_LOGMODULE_NOTIFY, \
|
1999-12-14 06:58:27 +00:00
|
|
|
ISC_LOG_DEBUG(8)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check an operation for failure. These macros all assume that
|
|
|
|
* the function using them has a 'result' variable and a 'failure'
|
|
|
|
* label.
|
|
|
|
*/
|
|
|
|
#define CHECK(op) \
|
|
|
|
do { result = (op); \
|
2000-04-06 22:03:35 +00:00
|
|
|
if (result != ISC_R_SUCCESS) goto failure; \
|
1999-12-14 06:58:27 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fail unconditionally with result 'code', which must not
|
2000-04-06 22:03:35 +00:00
|
|
|
* be ISC_R_SUCCESS. The reason for failure presumably has
|
1999-12-14 06:58:27 +00:00
|
|
|
* been logged already.
|
2000-05-10 03:33:57 +00:00
|
|
|
*
|
|
|
|
* The test is there to keep the Solaris compiler from complaining
|
|
|
|
* about "end-of-loop code not reached".
|
1999-12-14 06:58:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define FAIL(code) \
|
|
|
|
do { \
|
|
|
|
result = (code); \
|
2000-05-10 03:33:57 +00:00
|
|
|
if (code != ISC_R_SUCCESS) goto failure; \
|
1999-12-14 06:58:27 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fail unconditionally and log as a client error.
|
2000-05-10 03:33:57 +00:00
|
|
|
* The test against ISC_R_SUCCESS is there to keep the Solaris compiler
|
|
|
|
* from complaining about "end-of-loop code not reached".
|
1999-12-14 06:58:27 +00:00
|
|
|
*/
|
|
|
|
#define FAILC(code, msg) \
|
|
|
|
do { \
|
|
|
|
result = (code); \
|
|
|
|
isc_log_write(NOTIFY_PROTOCOL_LOGARGS, \
|
|
|
|
"notify failed: %s (%s)", \
|
|
|
|
msg, isc_result_totext(code)); \
|
2000-05-24 18:25:35 +00:00
|
|
|
if (result != ISC_R_SUCCESS) goto failure; \
|
1999-12-14 06:58:27 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fail unconditionally and log as a server error.
|
2000-05-10 03:33:57 +00:00
|
|
|
* The test against ISC_R_SUCCESS is there to keep the Solaris compiler
|
|
|
|
* from complaining about "end-of-loop code not reached".
|
1999-12-14 06:58:27 +00:00
|
|
|
*/
|
|
|
|
#define FAILS(code, msg) \
|
|
|
|
do { \
|
|
|
|
result = (code); \
|
|
|
|
isc_log_write(NOTIFY_PROTOCOL_LOGARGS, \
|
|
|
|
"notify error: %s: %s", \
|
|
|
|
msg, isc_result_totext(code)); \
|
2000-05-24 18:25:35 +00:00
|
|
|
if (result != ISC_R_SUCCESS) goto failure; \
|
1999-12-14 06:58:27 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
static void
|
1999-12-23 00:09:04 +00:00
|
|
|
respond(ns_client_t *client, isc_result_t result) {
|
1999-12-16 01:23:17 +00:00
|
|
|
dns_rcode_t rcode;
|
|
|
|
dns_message_t *message;
|
|
|
|
isc_result_t msg_result;
|
|
|
|
|
|
|
|
message = client->message;
|
1999-12-22 22:11:18 +00:00
|
|
|
rcode = dns_result_torcode(result);
|
1999-12-16 01:23:17 +00:00
|
|
|
|
|
|
|
msg_result = dns_message_reply(message, ISC_TRUE);
|
|
|
|
if (msg_result != ISC_R_SUCCESS)
|
|
|
|
msg_result = dns_message_reply(message, ISC_FALSE);
|
|
|
|
if (msg_result != ISC_R_SUCCESS) {
|
|
|
|
ns_client_next(client, msg_result);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
message->rcode = rcode;
|
2000-06-23 17:26:38 +00:00
|
|
|
if (rcode == dns_rcode_noerror)
|
|
|
|
message->flags |= DNS_MESSAGEFLAG_AA;
|
|
|
|
else
|
|
|
|
message->flags &= ~DNS_MESSAGEFLAG_AA;
|
1999-12-16 01:23:17 +00:00
|
|
|
ns_client_send(client);
|
1999-12-14 06:58:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-05-24 03:19:21 +00:00
|
|
|
ns_notify_start(ns_client_t *client) {
|
1999-12-14 06:58:27 +00:00
|
|
|
dns_message_t *request = client->message;
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t result;
|
1999-12-14 06:58:27 +00:00
|
|
|
dns_name_t *zonename;
|
|
|
|
dns_rdataset_t *zone_rdataset;
|
|
|
|
dns_zone_t *zone = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interpret the question section.
|
|
|
|
*/
|
|
|
|
result = dns_message_firstname(request, DNS_SECTION_QUESTION);
|
2000-04-06 22:03:35 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-12-14 06:58:27 +00:00
|
|
|
FAILC(DNS_R_FORMERR,
|
|
|
|
"notify question section empty");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The question section must contain exactly one question.
|
|
|
|
*/
|
|
|
|
zonename = NULL;
|
|
|
|
dns_message_currentname(request, DNS_SECTION_QUESTION, &zonename);
|
|
|
|
zone_rdataset = ISC_LIST_HEAD(zonename->list);
|
|
|
|
if (ISC_LIST_NEXT(zone_rdataset, link) != NULL)
|
|
|
|
FAILC(DNS_R_FORMERR,
|
|
|
|
"notify question section contains multiple RRs");
|
|
|
|
|
|
|
|
/* The zone section must have exactly one name. */
|
|
|
|
result = dns_message_nextname(request, DNS_SECTION_ZONE);
|
2000-04-06 22:03:35 +00:00
|
|
|
if (result != ISC_R_NOMORE)
|
1999-12-14 06:58:27 +00:00
|
|
|
FAILC(DNS_R_FORMERR,
|
|
|
|
"notify question section contains multiple RRs");
|
|
|
|
|
2000-04-19 18:27:42 +00:00
|
|
|
result = dns_zt_find(client->view->zonetable, zonename, 0, NULL,
|
|
|
|
&zone);
|
2000-04-06 22:03:35 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-12-14 06:58:27 +00:00
|
|
|
FAILC(DNS_R_REFUSED,
|
2000-02-02 21:03:12 +00:00
|
|
|
"not authoritative for notify zone");
|
1999-12-14 06:58:27 +00:00
|
|
|
|
|
|
|
switch(dns_zone_gettype(zone)) {
|
|
|
|
case dns_zone_master:
|
|
|
|
case dns_zone_slave:
|
|
|
|
respond(client, dns_zone_notifyreceive(zone,
|
|
|
|
ns_client_getsockaddr(client), request));
|
1999-12-16 01:23:17 +00:00
|
|
|
break;
|
1999-12-14 06:58:27 +00:00
|
|
|
default:
|
|
|
|
FAILC(DNS_R_REFUSED,
|
2000-02-02 21:03:12 +00:00
|
|
|
"not authoritative for notify zone");
|
1999-12-14 06:58:27 +00:00
|
|
|
}
|
2000-05-08 07:26:37 +00:00
|
|
|
dns_zone_detach(&zone);
|
1999-12-14 06:58:27 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
failure:
|
2000-05-08 07:26:37 +00:00
|
|
|
if (zone != NULL)
|
|
|
|
dns_zone_detach(&zone);
|
1999-12-14 06:58:27 +00:00
|
|
|
respond(client, result);
|
|
|
|
}
|