Enable logging both "from" and "to" socket

Change the function prototype for dns_message_logfmtpacket() so that it
takes two isc_sockaddr_t parameters: one for the sending side and
another one for the receiving side.  This enables debug messages to be
more precise.

Also adjust the function prototype for logfmtpacket() accordingly.
Unlike dns_message_logfmtpacket(), this function must not require both
'from' and 'to' parameters to be non-NULL as it is still going to be
used by dns_message_logpacket(), which only provides a single socket
address.  Adjust its log format to handle both of these cases properly.

Adjust both dns_message_logfmtpacket() call sites accordingly, without
actually providing the second socket address yet.  (This causes the
revised REQUIRE() assertion in dns_message_logfmtpacket() to fail; the
issue will be addressed in a separate commit.)
This commit is contained in:
Michał Kępień 2024-12-31 05:40:48 +01:00
parent 05d69bd7a4
commit bafa5d3c2e
No known key found for this signature in database
3 changed files with 25 additions and 18 deletions

View file

@ -1402,7 +1402,7 @@ dns_message_logpacket(dns_message_t *message, const char *description,
void
dns_message_logfmtpacket(dns_message_t *message, const char *description,
const isc_sockaddr_t *address,
const isc_sockaddr_t *from, const isc_sockaddr_t *to,
isc_logcategory_t category, isc_logmodule_t module,
int level, isc_mem_t *mctx);
/*%<
@ -1419,6 +1419,7 @@ dns_message_logfmtpacket(dns_message_t *message, const char *description,
* \li message be a valid.
* \li description to be non NULL.
* \li address to be non NULL.
* \li from and to to be non NULL.
* \li category to be valid.
* \li module to be valid.
* \li mctx to be a valid.

View file

@ -216,9 +216,9 @@ msgblock_free(isc_mem_t *, dns_msgblock_t *, unsigned int);
static void
logfmtpacket(dns_message_t *message, const char *description,
const isc_sockaddr_t *address, isc_logcategory_t category,
isc_logmodule_t module, const dns_master_style_t *style, int level,
isc_mem_t *mctx);
const isc_sockaddr_t *from, const isc_sockaddr_t *to,
isc_logcategory_t category, isc_logmodule_t module,
const dns_master_style_t *style, int level, isc_mem_t *mctx);
/*
* Allocate a new dns_msgblock_t, and return a pointer to it. If no memory
@ -4733,27 +4733,28 @@ dns_message_logpacket(dns_message_t *message, const char *description,
isc_logmodule_t module, int level, isc_mem_t *mctx) {
REQUIRE(address != NULL);
logfmtpacket(message, description, address, category, module,
logfmtpacket(message, description, address, NULL, category, module,
&dns_master_style_debug, level, mctx);
}
void
dns_message_logfmtpacket(dns_message_t *message, const char *description,
const isc_sockaddr_t *address,
const isc_sockaddr_t *from, const isc_sockaddr_t *to,
isc_logcategory_t category, isc_logmodule_t module,
int level, isc_mem_t *mctx) {
REQUIRE(address != NULL);
REQUIRE(from != NULL && to != NULL);
logfmtpacket(message, description, address, category, module,
logfmtpacket(message, description, from, to, category, module,
&dns_master_style_comment, level, mctx);
}
static void
logfmtpacket(dns_message_t *message, const char *description,
const isc_sockaddr_t *address, isc_logcategory_t category,
isc_logmodule_t module, const dns_master_style_t *style, int level,
isc_mem_t *mctx) {
char addrbuf[ISC_SOCKADDR_FORMATSIZE] = { 0 };
const isc_sockaddr_t *from, const isc_sockaddr_t *to,
isc_logcategory_t category, isc_logmodule_t module,
const dns_master_style_t *style, int level, isc_mem_t *mctx) {
char frombuf[ISC_SOCKADDR_FORMATSIZE] = { 0 };
char tobuf[ISC_SOCKADDR_FORMATSIZE] = { 0 };
isc_buffer_t buffer;
char *buf = NULL;
int len = 1024;
@ -4768,8 +4769,11 @@ logfmtpacket(dns_message_t *message, const char *description,
* to appear in the log after each message.
*/
if (address != NULL) {
isc_sockaddr_format(address, addrbuf, sizeof(addrbuf));
if (from != NULL) {
isc_sockaddr_format(from, frombuf, sizeof(frombuf));
}
if (to != NULL) {
isc_sockaddr_format(to, tobuf, sizeof(tobuf));
}
do {
@ -4780,8 +4784,10 @@ logfmtpacket(dns_message_t *message, const char *description,
isc_mem_put(mctx, buf, len);
len += 1024;
} else if (result == ISC_R_SUCCESS) {
isc_log_write(category, module, level, "%s %s\n%.*s",
description, addrbuf,
isc_log_write(category, module, level,
"%s%s%s%s%s\n%.*s", description,
(from != NULL ? " from " : ""), frombuf,
(to != NULL ? " to " : ""), tobuf,
(int)isc_buffer_usedlength(&buffer), buf);
}
} while (result == ISC_R_NOSPACE);

View file

@ -2710,7 +2710,7 @@ resquery_send(resquery_t *query) {
* Log the outgoing packet.
*/
dns_message_logfmtpacket(
fctx->qmessage, "sending packet to", &query->addrinfo->sockaddr,
fctx->qmessage, "sending packet to", NULL, &query->addrinfo->sockaddr,
DNS_LOGCATEGORY_RESOLVER, DNS_LOGMODULE_PACKETS,
ISC_LOG_DEBUG(11), fctx->mctx);
@ -9731,7 +9731,7 @@ rctx_logpacket(respctx_t *rctx) {
dns_message_logfmtpacket(
rctx->query->rmessage, "received packet from",
&rctx->query->addrinfo->sockaddr, DNS_LOGCATEGORY_RESOLVER,
&rctx->query->addrinfo->sockaddr, NULL, DNS_LOGCATEGORY_RESOLVER,
DNS_LOGMODULE_PACKETS, ISC_LOG_DEBUG(10), fctx->mctx);
#ifdef HAVE_DNSTAP