]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add a function to set the UDP recv/snd buffer sizes
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 18 Nov 2021 16:38:56 +0000 (17:38 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 18 Nov 2021 16:38:56 +0000 (17:38 +0100)
And raise them to 16777216 by default.

pdns/dnsdist-console.cc
pdns/dnsdist-lua.cc
pdns/dnsdist.cc
pdns/dnsdist.hh
pdns/dnsdistdist/docs/reference/tuning.rst

index 44e33cc027dc6ad5996f8ad01992c78f415ef39d..bcf605844a621fdbc19153e791aac0edb942d596 100644 (file)
@@ -633,6 +633,7 @@ const std::vector<ConsoleKeyword> g_consoleKeywords{
   { "setTCPRecvTimeout", true, "n", "set the read timeout on TCP connections from the client, in seconds" },
   { "setTCPSendTimeout", true, "n", "set the write timeout on TCP connections from the client, in seconds" },
   { "setUDPMultipleMessagesVectorSize", true, "n", "set the size of the vector passed to recvmmsg() to receive UDP messages. Default to 1 which means that the feature is disabled and recvmsg() is used instead" },
+  { "setUDPSocketBufferSizes", true, "recv, send", "Set the size of the receive (SO_RCVBUF) and send (SO_SNDBUF) buffers for incoming UDP sockets" },
   { "setUDPTimeout", true, "n", "set the maximum time dnsdist will wait for a response from a backend over UDP, in seconds" },
   { "setVerboseHealthChecks", true, "bool", "set whether health check errors will be logged" },
   { "setWebserverConfig", true, "[{password=string, apiKey=string, customHeaders, statsRequireAuthentication}]", "Updates webserver configuration" },
index fde21a9fccb47b5f95b6d308d060f91e487e40bb..a05454ef5fef1e8dccd8c54783dc406618af29be 100644 (file)
@@ -2780,6 +2780,23 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
       }
     }
   });
+
+  luaCtx.writeFunction("setUDPSocketBufferSizes", [client](uint64_t recv, uint64_t snd) {
+    if (client) {
+      return;
+    }
+    checkParameterBound("setUDPSocketBufferSizes", recv, std::numeric_limits<uint32_t>::max());
+    checkParameterBound("setUDPSocketBufferSizes", snd, std::numeric_limits<uint32_t>::max());
+    setLuaSideEffect();
+
+    if (g_configurationDone) {
+      g_outputBuffer = "setUDPSocketBufferSizes cannot be used at runtime!\n";
+      return;
+    }
+
+    g_socketUDPSendBuffer = snd;
+    g_socketUDPRecvBuffer = recv;
+  });
 }
 
 vector<std::function<void(void)>> setupLua(LuaContext& luaCtx, bool client, bool configCheck, const std::string& config)
index 4d43eadec2868f88e1c12b04525606fefd2fbf3a..e679d64b481e7c0fe15dd4748afbf8b9a23a42e7 100644 (file)
@@ -141,6 +141,8 @@ bool g_servFailOnNoPolicy{false};
 bool g_truncateTC{false};
 bool g_fixupCase{false};
 bool g_dropEmptyQueries{false};
+uint32_t g_socketUDPSendBuffer{16777216};
+uint32_t g_socketUDPRecvBuffer{16777216};
 
 std::set<std::string> g_capabilitiesToRetain;
 
@@ -2073,6 +2075,26 @@ static void setUpLocalBind(std::unique_ptr<ClientState>& cs)
     }
   }
 
+  if (!cs->tcp) {
+    if (g_socketUDPSendBuffer > 0) {
+      try {
+        setSocketSendBuffer(cs->udpFD, g_socketUDPSendBuffer);
+      }
+      catch (const std::exception& e) {
+        warnlog(e.what());
+      }
+    }
+
+    if (g_socketUDPRecvBuffer > 0) {
+      try {
+        setSocketReceiveBuffer(cs->udpFD, g_socketUDPRecvBuffer);
+      }
+      catch (const std::exception& e) {
+        warnlog(e.what());
+      }
+    }
+  }
+
   const std::string& itf = cs->interface;
   if (!itf.empty()) {
 #ifdef SO_BINDTODEVICE
index 4576f843593ad541ca34ca73f7c8ec256808f2ba..6ee0b3382861f43e02a6a04eca3489f7bfdb4d7e 100644 (file)
@@ -1016,6 +1016,8 @@ extern std::string g_apiConfigDirectory;
 extern bool g_servFailOnNoPolicy;
 extern size_t g_udpVectorSize;
 extern bool g_allowEmptyResponse;
+extern uint32_t g_socketUDPSendBuffer;
+extern uint32_t g_socketUDPRecvBuffer;
 
 extern shared_ptr<BPFFilter> g_defaultBPFFilter;
 extern std::vector<std::shared_ptr<DynBPFFilter> > g_dynBPFFilters;
index 90442f5b80c1bd3d6456cb2bbacf7d51c011332c..da70e97049af19be8ec9e2caf31cb215eeffc6f0 100644 (file)
@@ -160,6 +160,15 @@ Tuning related functions
 
   :param int num: maximum number of UDP queries to accept
 
+.. function:: setUDPSocketBufferSize(recv, send)
+
+  .. versionadded:: 1.7.0
+
+  Set the size of the receive (SO_RCVBUF) and send (SO_SNDBUF) buffers for incoming UDP sockets.
+
+  :param int recv: SO_RCVBUF value. Default is 16777216. 0 means the system value will be kept.
+  :param int send: SO_SNDBUF value. Default is 16777216. 0 means the system value will be kept.
+
 .. function:: setUDPTimeout(num)
 
   Set the maximum time dnsdist will wait for a response from a backend over UDP, in seconds. Defaults to 2