From: Remi Gacogne Date: Thu, 2 Apr 2026 08:17:41 +0000 (+0200) Subject: dnsdist: Do not oversize the received buffer with `recvmmsg` X-Git-Tag: auth-5.1.0-beta1~84^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2025bb78fc98fb4cf44bfb9a3ca8e5bbb2415ecd;p=thirdparty%2Fpdns.git dnsdist: Do not oversize the received buffer with `recvmmsg` Passing `MSG_TRUNC` to `recvmmsg` causes the Linux kernel to report the real size of the datagram even if it was longer than the passed buffer, which is not what we want here as it would be wasteful to resize our internal buffer to this size. This was reported by komaku in #YWH-PGM6095-172, many thanks!. Signed-off-by: Remi Gacogne --- diff --git a/pdns/dnsdistdist/dnsdist.cc b/pdns/dnsdistdist/dnsdist.cc index cb93360573..1475553932 100644 --- a/pdns/dnsdistdist/dnsdist.cc +++ b/pdns/dnsdistdist/dnsdist.cc @@ -2287,7 +2287,7 @@ static void MultipleMessagesUDPClientThread(ClientState* clientState) /* block until we have at least one message ready, but return as many as possible to save the syscall costs */ - msgsGot = recvmmsg(clientState->udpFD, msgVec.data(), vectSize, MSG_WAITFORONE | MSG_TRUNC, nullptr); + msgsGot = recvmmsg(clientState->udpFD, msgVec.data(), vectSize, MSG_WAITFORONE, nullptr); if (msgsGot <= 0) { int savederrno = errno; VERBOSESLOG(infolog("Getting UDP messages via recvmmsg() failed with: %s", stringerror(savederrno)), @@ -2311,6 +2311,13 @@ static void MultipleMessagesUDPClientThread(ClientState* clientState) continue; } + if ((msgh->msg_flags & MSG_TRUNC) != 0) { + /* message was too large for our buffer */ + ++clientState->nonCompliantQueries; + ++dnsdist::metrics::g_stats.nonCompliantQueries; + continue; + } + auto& data = recvData[msgIdx]; data.packet.resize(got); dnsdist::configuration::refreshLocalRuntimeConfiguration();