From 03c05963ccad3bdae5f4da9280f2432084f866a6 Mon Sep 17 00:00:00 2001 From: Charles-Henri Bruyand Date: Fri, 26 Oct 2018 17:21:28 +0200 Subject: [PATCH] dnsdist: add setConsoleOutputMaxMsgSize function to tune console output message maximum size --- pdns/dnsdist-console.cc | 29 ++++++++++++++++++++++ pdns/dnsdist-console.hh | 1 + pdns/dnsdist-lua.cc | 4 +++ pdns/dnsdist-tcp.cc | 27 -------------------- pdns/dnsdistdist/docs/reference/config.rst | 8 ++++++ 5 files changed, 42 insertions(+), 27 deletions(-) diff --git a/pdns/dnsdist-console.cc b/pdns/dnsdist-console.cc index 53210fe85..d0195c9ec 100644 --- a/pdns/dnsdist-console.cc +++ b/pdns/dnsdist-console.cc @@ -44,6 +44,7 @@ vector > g_confDelta; std::string g_consoleKey; bool g_logConsoleConnections{true}; bool g_consoleEnabled{false}; +uint32_t g_consoleOutputMsgMaxSize{10000000}; // MUST BE CALLED UNDER A LOCK - right now the LuaLock static void feedConfigDelta(const std::string& line) @@ -412,6 +413,7 @@ const std::vector g_consoleKeywords{ { "setAPIWritable", true, "bool, dir", "allow modifications via the API. if `dir` is set, it must be a valid directory where the configuration files will be written by the API" }, { "setConsoleACL", true, "{netmask, netmask}", "replace the console ACL set with these netmasks" }, { "setConsoleConnectionsLogging", true, "enabled", "whether to log the opening and closing of console connections" }, + { "setConsoleOutputMaxMsgSize", true, "messageSize", "set console message maximum size in bytes, default is 10 MB" }, { "setDNSSECPool", true, "pool name", "move queries requesting DNSSEC processing to this pool" }, { "setDynBlocksAction", true, "action", "set which action is performed when a query is blocked. Only DNSAction.Drop (the default) and DNSAction.Refused are supported" }, { "setECSOverride", true, "bool", "whether to override an existing EDNS Client Subnet value in the query" }, @@ -700,3 +702,30 @@ catch(const std::exception& e) close(fd); errlog("Control connection died: %s", e.what()); } + +bool getMsgLen32(int fd, uint32_t* len) +try +{ + uint32_t raw; + size_t ret = readn2(fd, &raw, sizeof raw); + if(ret != sizeof raw) + return false; + *len = ntohl(raw); + if(*len > g_consoleOutputMsgMaxSize) + return false; + return true; +} +catch(...) { + return false; +} + +bool putMsgLen32(int fd, uint32_t len) +try +{ + uint32_t raw = htonl(len); + size_t ret = writen2(fd, &raw, sizeof raw); + return ret==sizeof raw; +} +catch(...) { + return false; +} diff --git a/pdns/dnsdist-console.hh b/pdns/dnsdist-console.hh index 7de8b6845..1c3bb6e2f 100644 --- a/pdns/dnsdist-console.hh +++ b/pdns/dnsdist-console.hh @@ -43,6 +43,7 @@ extern const std::vector g_consoleKeywords; extern std::string g_consoleKey; // in theory needs locking extern bool g_logConsoleConnections; extern bool g_consoleEnabled; +extern uint32_t g_consoleOutputMsgMaxSize; void doClient(ComboAddress server, const std::string& command); void doConsole(); diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 00bb21651..40abb4bce 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -1469,6 +1469,10 @@ void setupLuaConfig(bool client) g_logConsoleConnections = enabled; }); + g_lua.writeFunction("setConsoleOutputMaxMsgSize", [](uint32_t size) { + g_consoleOutputMsgMaxSize = size; + }); + g_lua.writeFunction("setUDPMultipleMessagesVectorSize", [](size_t vSize) { if (g_configurationDone) { errlog("setUDPMultipleMessagesVectorSize() cannot be used at runtime!"); diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index 9eba86191..b918c7968 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -776,30 +776,3 @@ void* tcpAcceptorThread(void* p) return 0; } - -bool getMsgLen32(int fd, uint32_t* len) -try -{ - uint32_t raw; - size_t ret = readn2(fd, &raw, sizeof raw); - if(ret != sizeof raw) - return false; - *len = ntohl(raw); - if(*len > 10000000) // arbitrary 10MB limit - return false; - return true; -} -catch(...) { - return false; -} - -bool putMsgLen32(int fd, uint32_t len) -try -{ - uint32_t raw = htonl(len); - size_t ret = writen2(fd, &raw, sizeof raw); - return ret==sizeof raw; -} -catch(...) { - return false; -} diff --git a/pdns/dnsdistdist/docs/reference/config.rst b/pdns/dnsdistdist/docs/reference/config.rst index 90da2e703..345a25541 100644 --- a/pdns/dnsdistdist/docs/reference/config.rst +++ b/pdns/dnsdistdist/docs/reference/config.rst @@ -203,6 +203,14 @@ Control Socket, Console and Webserver Test the crypto code, will report errors when something is not ok. +.. function:: setConsoleOutputMaxMsgSize(size) + + .. versionadded:: 1.3.3 + + Set the maximum size in bytes of a single console message, default set to 10 MB. + + :param int size: The new maximum size. + Webserver ~~~~~~~~~ -- 2.40.0