From d12c21abcf2daaed236b118c2fa7771fdc11559e Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 16 Mar 2020 11:23:11 +0100 Subject: [PATCH] dnsdist: Make FrameStream IO parameters configurable --- pdns/dnsdist-console.cc | 4 +-- .../dnsdist-lua-bindings-protobuf.cc | 31 ++++++++++++++--- pdns/dnsdistdist/docs/reference/dnstap.rst | 34 +++++++++++++++++-- 3 files changed, 61 insertions(+), 8 deletions(-) diff --git a/pdns/dnsdist-console.cc b/pdns/dnsdist-console.cc index 98841bac68..6fe525e2dd 100644 --- a/pdns/dnsdist-console.cc +++ b/pdns/dnsdist-console.cc @@ -452,8 +452,8 @@ const std::vector 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 diff --git a/pdns/dnsdistdist/dnsdist-lua-bindings-protobuf.cc b/pdns/dnsdistdist/dnsdist-lua-bindings-protobuf.cc index e8d6350eb9..1f96d7168a 100644 --- a/pdns/dnsdistdist/dnsdist-lua-bindings-protobuf.cc +++ b/pdns/dnsdistdist/dnsdist-lua-bindings-protobuf.cc @@ -32,6 +32,23 @@ #include "ipcipher.hh" #endif /* HAVE_LIBCRYPTO */ +#ifdef HAVE_FSTRM +static void parseFSTRMOptions(const boost::optional>& params, std::unordered_map& options) +{ + if (!params) { + return; + } + + static std::vector const potentialOptions = { "bufferHint", "flushTimeout", "inputQueueSize", "outputQueueSize", "queueNotifyThreshold", "reopenInterval" }; + + for (const auto& potentialOption : potentialOptions) { + if (params->count(potentialOption)) { + options[potentialOption] = boost::get(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(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> params) { #ifdef HAVE_FSTRM if (client || configCheck) { return std::shared_ptr(nullptr); } - return std::shared_ptr(new FrameStreamLogger(AF_UNIX, address, !client)); + + std::unordered_map options; + parseFSTRMOptions(params, options); + return std::shared_ptr(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> params) { #if defined(HAVE_FSTRM) && defined(HAVE_FSTRM_TCP_WRITER_INIT) if (client || configCheck) { return std::shared_ptr(nullptr); } - return std::shared_ptr(new FrameStreamLogger(AF_INET, address, !client)); + + std::unordered_map options; + parseFSTRMOptions(params, options); + return std::shared_ptr(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 */ diff --git a/pdns/dnsdistdist/docs/reference/dnstap.rst b/pdns/dnsdistdist/docs/reference/dnstap.rst index 48bd895841..9da5b96055 100644 --- a/pdns/dnsdistdist/docs/reference/dnstap.rst +++ b/pdns/dnsdistdist/docs/reference/dnstap.rst @@ -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 -- 2.47.2