From c5555a5ca215bf971e27856f6a8f511d86074f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Tue, 31 Dec 2024 05:40:48 +0100 Subject: [PATCH] Log both "from" and "to" socket in debug messages Move dns_dispentry_getlocaladdress() calls around so that they are not only invoked when dnstap support is compiled in. This function calls isc_nmhandle_localaddr(), which may issue a system call, but only if the ISC_SOCKET_DETAILS preprocessor macro is set at compile time. Pass the value extracted by dns_dispentry_getlocaladdress() to dns_message_logpacketfromto() so that it gets logged, adding useful information to the relevant debug messages. --- lib/dns/resolver.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index 9339f5e4dc..17e24c3ef7 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -2340,8 +2340,8 @@ resquery_send(resquery_t *query) { dns_ednsopt_t ednsopts[DNS_EDNSOPTIONS]; unsigned int ednsopt = 0; uint16_t hint = 0, udpsize = 0; /* No EDNS */ -#ifdef HAVE_DNSTAP isc_sockaddr_t localaddr, *la = NULL; +#ifdef HAVE_DNSTAP unsigned char zone[DNS_NAME_MAXWIRE]; dns_transport_type_t transport_type; dns_dtmsgtype_t dtmsgtype; @@ -2709,8 +2709,13 @@ resquery_send(resquery_t *query) { /* * Log the outgoing packet. */ + result = dns_dispentry_getlocaladdress(query->dispentry, &localaddr); + if (result == ISC_R_SUCCESS) { + la = &localaddr; + } + dns_message_logpacketfromto( - fctx->qmessage, "sending packet to", NULL, &query->addrinfo->sockaddr, + fctx->qmessage, "sending packet to", la, &query->addrinfo->sockaddr, DNS_LOGCATEGORY_RESOLVER, DNS_LOGMODULE_PACKETS, ISC_LOG_DEBUG(11), fctx->mctx); @@ -2737,11 +2742,6 @@ resquery_send(resquery_t *query) { dtmsgtype = DNS_DTTYPE_RQ; } - result = dns_dispentry_getlocaladdress(query->dispentry, &localaddr); - if (result == ISC_R_SUCCESS) { - la = &localaddr; - } - if (query->addrinfo->transport != NULL) { transport_type = dns_transport_get_type(query->addrinfo->transport); @@ -9718,9 +9718,9 @@ detach: static void rctx_logpacket(respctx_t *rctx) { fetchctx_t *fctx = rctx->fctx; -#ifdef HAVE_DNSTAP isc_result_t result; isc_sockaddr_t localaddr, *la = NULL; +#ifdef HAVE_DNSTAP unsigned char zone[DNS_NAME_MAXWIRE]; dns_transport_type_t transport_type; dns_dtmsgtype_t dtmsgtype; @@ -9729,9 +9729,15 @@ rctx_logpacket(respctx_t *rctx) { isc_buffer_t zb; #endif /* HAVE_DNSTAP */ + result = dns_dispentry_getlocaladdress(rctx->query->dispentry, + &localaddr); + if (result == ISC_R_SUCCESS) { + la = &localaddr; + } + dns_message_logpacketfromto( rctx->query->rmessage, "received packet from", - &rctx->query->addrinfo->sockaddr, NULL, DNS_LOGCATEGORY_RESOLVER, + &rctx->query->addrinfo->sockaddr, la, DNS_LOGCATEGORY_RESOLVER, DNS_LOGMODULE_PACKETS, ISC_LOG_DEBUG(10), fctx->mctx); #ifdef HAVE_DNSTAP @@ -9754,12 +9760,6 @@ rctx_logpacket(respctx_t *rctx) { dtmsgtype = DNS_DTTYPE_RR; } - result = dns_dispentry_getlocaladdress(rctx->query->dispentry, - &localaddr); - if (result == ISC_R_SUCCESS) { - la = &localaddr; - } - if (rctx->query->addrinfo->transport != NULL) { transport_type = dns_transport_get_type( rctx->query->addrinfo->transport);