Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dnsdist: add setConsoleOutputMaxMsgSize function #7109

Merged
merged 1 commit into from Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions pdns/dnsdist-console.cc
Expand Up @@ -44,6 +44,7 @@ vector<pair<struct timeval, string> > 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)
Expand Down Expand Up @@ -412,6 +413,7 @@ const std::vector<ConsoleKeyword> 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" },
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions pdns/dnsdist-console.hh
Expand Up @@ -43,6 +43,7 @@ extern const std::vector<ConsoleKeyword> 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();
Expand Down
4 changes: 4 additions & 0 deletions pdns/dnsdist-lua.cc
Expand Up @@ -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!");
Expand Down
27 changes: 0 additions & 27 deletions pdns/dnsdist-tcp.cc
Expand Up @@ -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;
}
8 changes: 8 additions & 0 deletions pdns/dnsdistdist/docs/reference/config.rst
Expand Up @@ -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
~~~~~~~~~

Expand Down