MEDIUM: dns: don't call connect to dest socket for AF_INET*
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Wed, 13 Aug 2025 13:48:47 +0000 (15:48 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 26 Aug 2025 06:54:07 +0000 (08:54 +0200)
commit2b0da3f5da9b12771d1f32e465b5b1f6788bb41c
tree6124df9a79b7577960db9f1768ff75be07740d4f
parent50a5aa77a1811fde4787fed552126f329eb1e744
MEDIUM: dns: don't call connect to dest socket for AF_INET*

When we perform connect call for a datagram socket, used to send DNS requests,
we set for it the default destination address to some given nameserver. Then we
simply use send(), as the destination address is already set. In some usecases
described in GitHub issues #3001 and #2654, this approach becames inefficient,
nameservers change its IP addresses dynamically, this triggers DNS resolution
errors.

To fix this, let's perform the bind() on the wildcard address for the datagram
AF_INET* client socket. Like this we will allocate a port for it. Then let's
use sendto() instead of send().

If the nameserver is local and is listening on the UNIX domain socket, we
continue to use the existed approach (connect() and then send()).

This fixes issues #3001 and #2654.
This may be backported in all stable versions.

(cherry picked from commit 2c7e05f80e3b4bacad84eb213b9db3bc5d8963dc)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit bfcaf34de91339de70ec9556d3c10abb426336e0)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
src/dns.c