]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Log the server socket receiving each query
authorMichał Kępień <michal@isc.org>
Fri, 13 Feb 2026 13:27:10 +0000 (14:27 +0100)
committerMichał Kępień (GitLab job 6866004) <michal@isc.org>
Fri, 13 Feb 2026 14:03:58 +0000 (14:03 +0000)
Extend AsyncDnsServer._log_query() and AsyncDnsServer._log_response() so
that they also log the <address, port> tuple for the socket on which a
given query was received on.  Minimize the signatures of those methods
by taking advantage of all the information contained in the QueryContext
instances passed to them.

(cherry picked from commit d3d9d166ede01a97058f2ea967b385bd0f5ca77d)

bin/tests/system/isctest/asyncserver.py

index 3e8e59080fa732bc02c4f5fc1fd5fe6b2ec3a55a..c894d16f00ac86ebb2aaee454c1cbd80a130a028 100644 (file)
@@ -1181,33 +1181,31 @@ class AsyncDnsServer(AsyncServer):
             writer.write(response)
             await writer.drain()
 
-    def _log_query(self, qctx: QueryContext, peer: Peer, protocol: DnsProtocol) -> None:
+    def _log_query(self, qctx: QueryContext) -> None:
         logging.info(
-            "Received %s/%s/%s (ID=%d) query from %s (%s)",
+            "Received %s/%s/%s (ID=%d) query from %s on %s (%s)",
             qctx.qname.to_text(omit_final_dot=True),
             dns.rdataclass.to_text(qctx.qclass),
             dns.rdatatype.to_text(qctx.qtype),
             qctx.query.id,
-            peer,
-            protocol.name,
+            qctx.peer,
+            qctx.socket,
+            qctx.protocol.name,
         )
         logging.debug(
             "\n".join([f"[IN] {l}" for l in [""] + str(qctx.query).splitlines()])
         )
 
     def _log_response(
-        self,
-        qctx: QueryContext,
-        response: Optional[Union[dns.message.Message, bytes]],
-        peer: Peer,
-        protocol: DnsProtocol,
+        self, qctx: QueryContext, response: Optional[Union[dns.message.Message, bytes]]
     ) -> None:
         if not response:
             logging.info(
-                "Not sending a response to query (ID=%d) from %s (%s)",
+                "Not sending a response to query (ID=%d) from %s on %s (%s)",
                 qctx.query.id,
-                peer,
-                protocol.name,
+                qctx.peer,
+                qctx.socket,
+                qctx.protocol.name,
             )
             return
 
@@ -1222,7 +1220,7 @@ class AsyncDnsServer(AsyncServer):
                 qtype = "-"
 
             logging.info(
-                "Sending %s/%s/%s (ID=%d) response (%d/%d/%d/%d) to a query (ID=%d) from %s (%s)",
+                "Sending %s/%s/%s (ID=%d) response (%d/%d/%d/%d) to a query (ID=%d) from %s on %s (%s)",
                 qname,
                 qclass,
                 qtype,
@@ -1232,8 +1230,9 @@ class AsyncDnsServer(AsyncServer):
                 len(response.authority),
                 len(response.additional),
                 qctx.query.id,
-                peer,
-                protocol.name,
+                qctx.peer,
+                qctx.socket,
+                qctx.protocol.name,
             )
             logging.debug(
                 "\n".join([f"[OUT] {l}" for l in [""] + str(response).splitlines()])
@@ -1241,11 +1240,12 @@ class AsyncDnsServer(AsyncServer):
             return
 
         logging.info(
-            "Sending response (%d bytes) to a query (ID=%d) from %s (%s)",
+            "Sending response (%d bytes) to a query (ID=%d) from %s on %s (%s)",
             len(response),
             qctx.query.id,
-            peer,
-            protocol.name,
+            qctx.peer,
+            qctx.socket,
+            qctx.protocol.name,
         )
         logging.debug("[OUT] %s", response.hex())
 
@@ -1262,10 +1262,10 @@ class AsyncDnsServer(AsyncServer):
             return
         response_stub = _make_asyncserver_response(query)
         qctx = QueryContext(query, response_stub, socket, peer, protocol)
-        self._log_query(qctx, peer, protocol)
+        self._log_query(qctx)
         responses = self._prepare_responses(qctx)
         async for response in responses:
-            self._log_response(qctx, response, peer, protocol)
+            self._log_response(qctx, response)
             if response:
                 if isinstance(response, dns.message.Message):
                     response = response.to_wire(max_size=65535)