2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-03 08:05:21 +00:00

839. [func] Dump packets for which there was no view or that the

class could not be determined to file, (-e filename).
This commit is contained in:
Mark Andrews
2001-05-25 07:39:48 +00:00
parent 3b3a726ae4
commit 2ae4dd0dbd
4 changed files with 81 additions and 14 deletions

View File

@@ -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 838. [port] UnixWare 7.x.x is now suported by
bin/tests/system/ifconfig.sh. bin/tests/system/ifconfig.sh.

View File

@@ -15,12 +15,14 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * 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 <config.h> #include <config.h>
#include <isc/mutex.h> #include <isc/mutex.h>
#include <isc/once.h>
#include <isc/print.h> #include <isc/print.h>
#include <isc/stdio.h>
#include <isc/string.h> #include <isc/string.h>
#include <isc/task.h> #include <isc/task.h>
#include <isc/timer.h> #include <isc/timer.h>
@@ -172,6 +174,7 @@ static void ns_client_endrequest(ns_client_t *client);
static void ns_client_checkactive(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_start(isc_task_t *task, isc_event_t *event);
static void client_request(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. * 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_client_log(client, NS_LOGCATEGORY_CLIENT,
NS_LOGMODULE_CLIENT, ISC_LOG_ERROR, NS_LOGMODULE_CLIENT, ISC_LOG_ERROR,
"message class could not be determined"); "message class could not be determined");
ns_client_dumpmessage(client,
"message class could not be determined");
ns_client_error(client, DNS_R_FORMERR); ns_client_error(client, DNS_R_FORMERR);
goto cleanup; goto cleanup;
} }
@@ -1464,6 +1469,7 @@ client_request(isc_task_t *task, isc_event_t *event) {
ns_client_log(client, NS_LOGCATEGORY_CLIENT, ns_client_log(client, NS_LOGCATEGORY_CLIENT,
NS_LOGMODULE_CLIENT, ISC_LOG_ERROR, NS_LOGMODULE_CLIENT, ISC_LOG_ERROR,
"no matching view in class '%s'", classname); "no matching view in class '%s'", classname);
ns_client_dumpmessage(client, "no matching view in class");
ns_client_error(client, DNS_R_REFUSED); ns_client_error(client, DNS_R_REFUSED);
goto cleanup; goto cleanup;
} }
@@ -1528,7 +1534,7 @@ client_request(isc_task_t *task, isc_event_t *event) {
if (client->view->resolver != NULL && if (client->view->resolver != NULL &&
client->view->recursion == ISC_TRUE && client->view->recursion == ISC_TRUE &&
/* XXX this will log too much too early */ /* XXX this will log too much too early */
ns_client_checkacl(client, "recursion", ns_client_checkacl(client, "recursion available:",
client->view->recursionacl, client->view->recursionacl,
ISC_TRUE, ISC_LOG_DEBUG(1)) == ISC_R_SUCCESS) ISC_TRUE, ISC_LOG_DEBUG(1)) == ISC_R_SUCCESS)
ra = ISC_TRUE; ra = ISC_TRUE;
@@ -2204,6 +2210,14 @@ ns_client_checkacl(ns_client_t *client,
return (DNS_R_REFUSED); 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 static void
ns_client_logv(ns_client_t *client, isc_logcategory_t *category, ns_client_logv(ns_client_t *client, isc_logcategory_t *category,
isc_logmodule_t *module, int level, const char *fmt, va_list ap) 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]; char peerbuf[ISC_SOCKADDR_FORMATSIZE];
vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap); 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, isc_log_write(ns_g_lctx, category, module, level,
"client %s: %s", peerbuf, msgbuf); "client %s: %s", peerbuf, msgbuf);
} else {
isc_log_write(ns_g_lctx, category, module, level,
"client @%p: %s", client, msgbuf);
}
} }
void 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)); dns_rdataclass_format(rdclass, classbuf, sizeof(classbuf));
(void)snprintf(buf, len, "%s '%s/%s'", msg, namebuf, 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);
}

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * 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 #ifndef NAMED_GLOBALS_H
#define NAMED_GLOBALS_H 1 #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 EXTERN const char * lwresd_g_defaultpidfile INIT(NS_LOCALSTATEDIR
"/run/lwresd.pid"); "/run/lwresd.pid");
EXTERN const char * ns_g_username INIT(NULL); EXTERN const char * ns_g_username INIT(NULL);
EXTERN const char * ns_g_examinelog INIT(NULL);
#undef EXTERN #undef EXTERN
#undef INIT #undef INIT

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * 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 <config.h> #include <config.h>
@@ -270,7 +270,7 @@ parse_command_line(int argc, char *argv[]) {
isc_commandline_errprint = ISC_FALSE; isc_commandline_errprint = ISC_FALSE;
while ((ch = isc_commandline_parse(argc, argv, 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) { -1) {
switch (ch) { switch (ch) {
case 'c': case 'c':
@@ -290,6 +290,9 @@ parse_command_line(int argc, char *argv[]) {
ns_g_debuglevel = parse_int(isc_commandline_argument, ns_g_debuglevel = parse_int(isc_commandline_argument,
"debug level"); "debug level");
break; break;
case 'e':
ns_g_examinelog = isc_commandline_argument;
break;
case 'f': case 'f':
ns_g_foreground = ISC_TRUE; ns_g_foreground = ISC_TRUE;
break; break;