diff --git a/CHANGES b/CHANGES index b0ba12afcb..258a3c87a0 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ + 839. [func] Dump packets for which there was no view or that the + class could not be determined to file, (-e filename). + 838. [port] UnixWare 7.x.x is now suported by bin/tests/system/ifconfig.sh. diff --git a/bin/named/client.c b/bin/named/client.c index 34eaf7ac79..f4211c6fed 100644 --- a/bin/named/client.c +++ b/bin/named/client.c @@ -15,12 +15,14 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: client.c,v 1.167 2001/05/14 21:33:45 gson Exp $ */ +/* $Id: client.c,v 1.168 2001/05/25 07:39:45 marka Exp $ */ #include #include +#include #include +#include #include #include #include @@ -172,6 +174,7 @@ static void ns_client_endrequest(ns_client_t *client); static void ns_client_checkactive(ns_client_t *client); static void client_start(isc_task_t *task, isc_event_t *event); static void client_request(isc_task_t *task, isc_event_t *event); +static void ns_client_dumpmessage(ns_client_t *client, const char *reason); /* * Enter the inactive state. @@ -1419,6 +1422,8 @@ client_request(isc_task_t *task, isc_event_t *event) { ns_client_log(client, NS_LOGCATEGORY_CLIENT, NS_LOGMODULE_CLIENT, ISC_LOG_ERROR, "message class could not be determined"); + ns_client_dumpmessage(client, + "message class could not be determined"); ns_client_error(client, DNS_R_FORMERR); goto cleanup; } @@ -1464,6 +1469,7 @@ client_request(isc_task_t *task, isc_event_t *event) { ns_client_log(client, NS_LOGCATEGORY_CLIENT, NS_LOGMODULE_CLIENT, ISC_LOG_ERROR, "no matching view in class '%s'", classname); + ns_client_dumpmessage(client, "no matching view in class"); ns_client_error(client, DNS_R_REFUSED); goto cleanup; } @@ -1528,7 +1534,7 @@ client_request(isc_task_t *task, isc_event_t *event) { if (client->view->resolver != NULL && client->view->recursion == ISC_TRUE && /* XXX this will log too much too early */ - ns_client_checkacl(client, "recursion", + ns_client_checkacl(client, "recursion available:", client->view->recursionacl, ISC_TRUE, ISC_LOG_DEBUG(1)) == ISC_R_SUCCESS) ra = ISC_TRUE; @@ -2204,6 +2210,14 @@ ns_client_checkacl(ns_client_t *client, return (DNS_R_REFUSED); } +static void +ns_client_name(ns_client_t *client, char *peerbuf, size_t len) { + if (client->peeraddr_valid) + isc_sockaddr_format(&client->peeraddr, peerbuf, len); + else + snprintf(peerbuf, len, "@%p", client); +} + static void ns_client_logv(ns_client_t *client, isc_logcategory_t *category, isc_logmodule_t *module, int level, const char *fmt, va_list ap) @@ -2212,16 +2226,10 @@ ns_client_logv(ns_client_t *client, isc_logcategory_t *category, char peerbuf[ISC_SOCKADDR_FORMATSIZE]; vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap); + ns_client_name(client, peerbuf, sizeof peerbuf); - if (client->peeraddr_valid) { - isc_sockaddr_format(&client->peeraddr, - peerbuf, sizeof peerbuf); - isc_log_write(ns_g_lctx, category, module, level, - "client %s: %s", peerbuf, msgbuf); - } else { - isc_log_write(ns_g_lctx, category, module, level, - "client @%p: %s", client, msgbuf); - } + isc_log_write(ns_g_lctx, category, module, level, + "client %s: %s", peerbuf, msgbuf); } void @@ -2249,3 +2257,55 @@ ns_client_aclmsg(const char *msg, dns_name_t *name, dns_rdataclass_t rdclass, dns_rdataclass_format(rdclass, classbuf, sizeof(classbuf)); (void)snprintf(buf, len, "%s '%s/%s'", msg, namebuf, classbuf); } + +static isc_mutex_t dumpmessagemutex; + +static void dumpmessagemutex_init(void) { + (void)isc_mutex_init(&dumpmessagemutex); +} + +static void +ns_client_dumpmessage(ns_client_t *client, const char *reason) { + static isc_once_t once = ISC_ONCE_INIT; + char peerbuf[ISC_SOCKADDR_FORMATSIZE]; + isc_buffer_t buffer; + char *buf = NULL; + int len = 1024; + isc_result_t result; + FILE *fd = NULL; + + if (ns_g_examinelog == NULL) + return; + + ns_client_name(client, peerbuf, sizeof(peerbuf)); + + isc_once_do(&once, dumpmessagemutex_init); + + LOCK(&dumpmessagemutex); + + result = isc_stdio_open(ns_g_examinelog, "a", &fd); + if (result != ISC_R_SUCCESS) + goto unlock; + + do { + buf = isc_mem_get(client->mctx, len); + if (buf == NULL) + break; + isc_buffer_init(&buffer, buf, len); + result = dns_message_totext(client->message, + &dns_master_style_debug, + 0, &buffer); + if (result == ISC_R_NOSPACE) { + isc_mem_put(client->mctx, buf, len); + len += 1024; + } else if (result == ISC_R_SUCCESS) + fprintf(fd, "\nclient %s: %s\n%.*s\n", peerbuf, reason, + (int)isc_buffer_usedlength(&buffer), buf); + } while (result == ISC_R_NOSPACE); + + if (buf != NULL) + isc_mem_put(client->mctx, buf, len); + (void)isc_stdio_close(fd); + unlock: + UNLOCK(&dumpmessagemutex); +} diff --git a/bin/named/include/named/globals.h b/bin/named/include/named/globals.h index 5d34fddce8..0c40680f50 100644 --- a/bin/named/include/named/globals.h +++ b/bin/named/include/named/globals.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: globals.h,v 1.54 2001/03/27 00:44:36 bwelling Exp $ */ +/* $Id: globals.h,v 1.55 2001/05/25 07:39:48 marka Exp $ */ #ifndef NAMED_GLOBALS_H #define NAMED_GLOBALS_H 1 @@ -104,6 +104,7 @@ EXTERN const char * ns_g_defaultpidfile INIT(NS_LOCALSTATEDIR EXTERN const char * lwresd_g_defaultpidfile INIT(NS_LOCALSTATEDIR "/run/lwresd.pid"); EXTERN const char * ns_g_username INIT(NULL); +EXTERN const char * ns_g_examinelog INIT(NULL); #undef EXTERN #undef INIT diff --git a/bin/named/main.c b/bin/named/main.c index e77a415dc8..fc2698a1fb 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: main.c,v 1.109 2001/05/08 19:47:53 gson Exp $ */ +/* $Id: main.c,v 1.110 2001/05/25 07:39:46 marka Exp $ */ #include @@ -270,7 +270,7 @@ parse_command_line(int argc, char *argv[]) { isc_commandline_errprint = ISC_FALSE; while ((ch = isc_commandline_parse(argc, argv, - "c:C:d:fgi:ln:N:p:P:st:u:vx:")) != + "c:C:d:e:fgi:ln:N:p:P:st:u:vx:")) != -1) { switch (ch) { case 'c': @@ -290,6 +290,9 @@ parse_command_line(int argc, char *argv[]) { ns_g_debuglevel = parse_int(isc_commandline_argument, "debug level"); break; + case 'e': + ns_g_examinelog = isc_commandline_argument; + break; case 'f': ns_g_foreground = ISC_TRUE; break;