]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Log both "from" and "to" socket in debug messages
authorMichał Kępień <michal@isc.org>
Tue, 31 Dec 2024 04:40:48 +0000 (05:40 +0100)
committerMichał Kępień <michal@isc.org>
Tue, 31 Dec 2024 04:40:48 +0000 (05:40 +0100)
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

index 9339f5e4dce926f440d9ab7c9d01b4747f1fdd45..17e24c3ef703ea4cd1b96c4e8943b2f9c088a74f 100644 (file)
@@ -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);