]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix destination port extraction for client queries
authorMichał Kępień <michal@isc.org>
Wed, 22 Jun 2022 11:45:46 +0000 (13:45 +0200)
committerMichał Kępień <michal@isc.org>
Wed, 22 Jun 2022 11:52:08 +0000 (13:52 +0200)
The current logic for determining the address of the socket to which a
client sent its query is:

 1. Get the address:port tuple from the netmgr handle using
    isc_nmhandle_localaddr() or from the ns_interface_t structure.

 2. Convert the address:port tuple from step 1 into an isc_netaddr_t
    using isc_netaddr_fromsockaddr().

 3. Convert the address from step 2 back into a socket address with the
    port set to 0 using isc_sockaddr_fromnetaddr().

Note that the port number (readily available in the netmgr handle or in
the ns_interface_t structure) is needlessly lost in the process,
preventing it from being recorded in dnstap captures of client traffic
produced by named.

Fix by first storing the address:port tuple in client->destsockaddr and
then creating an isc_netaddr_t from that structure.  This allows the
port number to be retained in client->destsockaddr, which is what
subsequently gets passed to dns_dt_send().

Remove an outdated code comment.

(cherry picked from commit 2f945703f2c078db315653e6b57776e67939150e)

lib/ns/client.c

index 33734386c540bce57ec21abc618d195fd991943f..bf60746642db3387131e8886c268a23f8169871a 100644 (file)
@@ -1960,28 +1960,13 @@ ns__client_request(isc_nmhandle_t *handle, isc_result_t eresult,
                return;
        }
 
-       /*
-        * Determine the destination address.  If the receiving interface is
-        * bound to a specific address, we simply use it regardless of the
-        * address family.  All IPv4 queries should fall into this case.
-        * Otherwise, if this is a TCP query, get the address from the
-        * receiving socket (this needs a system call and can be heavy).
-        * For IPv6 UDP queries, we get this from the pktinfo structure (if
-        * supported).
-        *
-        * If all the attempts fail (this can happen due to memory shortage,
-        * etc), we regard this as an error for safety.
-        */
        if ((client->manager->interface->flags & NS_INTERFACEFLAG_ANYADDR) == 0)
        {
-               isc_netaddr_fromsockaddr(&client->destaddr,
-                                        &client->manager->interface->addr);
+               client->destsockaddr = client->manager->interface->addr;
        } else {
-               isc_sockaddr_t sockaddr = isc_nmhandle_localaddr(handle);
-               isc_netaddr_fromsockaddr(&client->destaddr, &sockaddr);
+               client->destsockaddr = isc_nmhandle_localaddr(handle);
        }
-
-       isc_sockaddr_fromnetaddr(&client->destsockaddr, &client->destaddr, 0);
+       isc_netaddr_fromsockaddr(&client->destaddr, &client->destsockaddr);
 
        result = client->sctx->matchingview(&netaddr, &client->destaddr,
                                            client->message, env, &sigresult,