]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Make FrameStream IO parameters configurable
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 16 Mar 2020 10:23:11 +0000 (11:23 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 16 Mar 2020 10:23:11 +0000 (11:23 +0100)
pdns/dnsdist-console.cc
pdns/dnsdistdist/dnsdist-lua-bindings-protobuf.cc
pdns/dnsdistdist/docs/reference/dnstap.rst

index 98841bac685690d531f9142e33b92b7ac11a7fb1..6fe525e2ddc4f71acc77fd576a2729a31180e443 100644 (file)
@@ -452,8 +452,8 @@ const std::vector<ConsoleKeyword> g_consoleKeywords{
   { "newDNSName", true, "name", "make a DNSName based on this .-terminated name" },
   { "newDNSNameSet", true, "", "returns a new DNSNameSet" },
   { "newDynBPFFilter", true, "bpf", "Return a new dynamic eBPF filter associated to a given BPF Filter" },
-  { "newFrameStreamTcpLogger", true, "addr", "create a FrameStream logger object writing to a TCP address (addr should be ip:port), to use with `DnstapLogAction()` and `DnstapLogResponseAction()`" },
-  { "newFrameStreamUnixLogger", true, "socket", "create a FrameStream logger object writing to a local unix socket, to use with `DnstapLogAction()` and `DnstapLogResponseAction()`" },
+  { "newFrameStreamTcpLogger", true, "addr [, options]", "create a FrameStream logger object writing to a TCP address (addr should be ip:port), to use with `DnstapLogAction()` and `DnstapLogResponseAction()`" },
+  { "newFrameStreamUnixLogger", true, "socket [, options]", "create a FrameStream logger object writing to a local unix socket, to use with `DnstapLogAction()` and `DnstapLogResponseAction()`" },
 #ifdef HAVE_LMDB
   { "newLMDBKVStore", true, "fname, dbName", "Return a new KeyValueStore object associated to the corresponding LMDB database" },
 #endif
index e8d6350eb9629aad3f68b23b6b311aecea73e4cd..1f96d7168ae55437866721c695bf662ad9f12754 100644 (file)
 #include "ipcipher.hh"
 #endif /* HAVE_LIBCRYPTO */
 
+#ifdef HAVE_FSTRM
+static void parseFSTRMOptions(const boost::optional<std::unordered_map<std::string, unsigned int>>& params, std::unordered_map<string, unsigned int>& options)
+{
+  if (!params) {
+    return;
+  }
+
+  static std::vector<std::string> const potentialOptions = { "bufferHint", "flushTimeout", "inputQueueSize", "outputQueueSize", "queueNotifyThreshold", "reopenInterval" };
+
+  for (const auto& potentialOption : potentialOptions) {
+    if (params->count(potentialOption)) {
+      options[potentialOption] = boost::get<unsigned int>(params->at(potentialOption));
+    }
+  }
+}
+#endif /* HAVE_FSTRM */
+
 void setupLuaBindingsProtoBuf(bool client, bool configCheck)
 {
 #ifdef HAVE_LIBCRYPTO
@@ -113,23 +130,29 @@ void setupLuaBindingsProtoBuf(bool client, bool configCheck)
       return std::shared_ptr<RemoteLoggerInterface>(new RemoteLogger(ComboAddress(remote), timeout ? *timeout : 2, maxQueuedEntries ? (*maxQueuedEntries*100) : 10000, reconnectWaitTime ? *reconnectWaitTime : 1, client));
     });
 
-  g_lua.writeFunction("newFrameStreamUnixLogger", [client,configCheck](const std::string& address) {
+  g_lua.writeFunction("newFrameStreamUnixLogger", [client,configCheck](const std::string& address, boost::optional<std::unordered_map<std::string, unsigned int>> params) {
 #ifdef HAVE_FSTRM
       if (client || configCheck) {
         return std::shared_ptr<RemoteLoggerInterface>(nullptr);
       }
-      return std::shared_ptr<RemoteLoggerInterface>(new FrameStreamLogger(AF_UNIX, address, !client));
+
+      std::unordered_map<string, unsigned int> options;
+      parseFSTRMOptions(params, options);
+      return std::shared_ptr<RemoteLoggerInterface>(new FrameStreamLogger(AF_UNIX, address, !client, options));
 #else
       throw std::runtime_error("fstrm support is required to build an AF_UNIX FrameStreamLogger");
 #endif /* HAVE_FSTRM */
     });
 
-  g_lua.writeFunction("newFrameStreamTcpLogger", [client,configCheck](const std::string& address) {
+  g_lua.writeFunction("newFrameStreamTcpLogger", [client,configCheck](const std::string& address, boost::optional<std::unordered_map<std::string, unsigned int>> params) {
 #if defined(HAVE_FSTRM) && defined(HAVE_FSTRM_TCP_WRITER_INIT)
       if (client || configCheck) {
         return std::shared_ptr<RemoteLoggerInterface>(nullptr);
       }
-      return std::shared_ptr<RemoteLoggerInterface>(new FrameStreamLogger(AF_INET, address, !client));
+
+      std::unordered_map<string, unsigned int> options;
+      parseFSTRMOptions(params, options);
+      return std::shared_ptr<RemoteLoggerInterface>(new FrameStreamLogger(AF_INET, address, !client, options));
 #else
       throw std::runtime_error("fstrm with TCP support is required to build an AF_INET FrameStreamLogger");
 #endif /* HAVE_FSTRM */
index 48bd895841663a6d6ac7096a5774c06231b005ae..9da5b96055725357b2af1f03f4c5a67f613c2cd0 100644 (file)
@@ -11,20 +11,50 @@ As an extension, :program:`dnsdist` can send raw dnstap protobuf messages over a
 
 To use FrameStream transport, :program:`dnsdist` must have been built with `libfstrm`.
 
-.. function:: newFrameStreamUnixLogger(path)
+.. function:: newFrameStreamUnixLogger(path [, options])
+
+  .. versionchanged:: 1.5.0
+    Added the optional parameter ``options``.
 
   Create a Frame Stream Logger object, to use with :func:`DnstapLogAction` and :func:`DnstapLogResponseAction`.
   This version will log to a local AF_UNIX socket.
 
   :param string path: A local AF_UNIX socket path. Note that most platforms have a rather short limit on the length.
+  :param table options: A table with key: value pairs with options.
+
+  The following options apply to the settings of the framestream library. Refer to the documentation of that
+  library for the default and allowed values for these options, as well as their exact descriptions.
+  For all these options, absence or a zero value has the effect of using the library-provided default value.
+
+  * ``bufferHint=0``: unsigned
+  * ``flushTimeout=0``: unsigned
+  * ``inputQueueSize=0``: unsigned
+  * ``outputQueueSize=0``: unsigned
+  * ``queueNotifyThreshold=0``: unsigned
+  * ``reopenInterval=0``: unsigned
+
+.. function:: newFrameStreamTcpLogger(address [, options])
 
-.. function:: newFrameStreamTcpLogger(address)
+  .. versionchanged:: 1.5.0
+    Added the optional parameter ``options``.
 
   Create a Frame Stream Logger object, to use with :func:`DnstapLogAction` and :func:`DnstapLogResponseAction`.
   This version will log to a possibly remote TCP socket.
   Needs tcp_writer support in libfstrm.
 
   :param string address: An IP:PORT combination where the logger will connect to.
+  :param table options: A table with key: value pairs with options.
+
+  The following options apply to the settings of the framestream library. Refer to the documentation of that
+  library for the default and allowed values for these options, as well as their exact descriptions.
+  For all these options, absence or a zero value has the effect of using the library-provided default value.
+
+  * ``bufferHint=0``: unsigned
+  * ``flushTimeout=0``: unsigned
+  * ``inputQueueSize=0``: unsigned
+  * ``outputQueueSize=0``: unsigned
+  * ``queueNotifyThreshold=0``: unsigned
+  * ``reopenInterval=0``: unsigned
 
 .. class:: DnstapMessage