]> git.ipfire.org Git - thirdparty/pdns.git/blobdiff - pdns/dnsdist-console.cc
Merge pull request #4815 from rgacogne/dnsdist-console-no-replay
[thirdparty/pdns.git] / pdns / dnsdist-console.cc
index ad9c4bb3c642d1424f65d10ae319393f6993959d..3c34191d7fddece54e295287722da69caff45aad 100644 (file)
@@ -21,6 +21,7 @@
  */
 #include "dnsdist.hh"
 #include "sodcrypto.hh"
+#include "pwd.h"
 
 #if defined (__OpenBSD__)
 #include <readline/readline.h>
@@ -45,6 +46,26 @@ void feedConfigDelta(const std::string& line)
   g_confDelta.push_back({now,line});
 }
 
+string historyFile(const bool &ignoreHOME = false)
+{
+  string ret;
+
+  struct passwd pwd;
+  struct passwd *result;
+  char buf[16384];
+  getpwuid_r(geteuid(), &pwd, buf, sizeof(buf), &result);
+
+  const char *homedir = getenv("HOME");
+  if (result)
+    ret = string(pwd.pw_dir);
+  if (homedir && !ignoreHOME) // $HOME overrides what the OS tells us
+    ret = string(homedir);
+  if (ret.empty())
+    ret = "."; // CWD if nothing works..
+  ret.append("/.dnsdist_history");
+  return ret;
+}
+
 void doClient(ComboAddress server, const std::string& command)
 {
   if(g_verbose)
@@ -87,14 +108,15 @@ void doClient(ComboAddress server, const std::string& command)
     return; 
   }
 
+  string histfile = historyFile();
   set<string> dupper;
   {
-    ifstream history(".dnsdist_history");
+    ifstream history(histfile);
     string line;
     while(getline(history, line))
       add_history(line.c_str());
   }
-  ofstream history(".dnsdist_history", std::ios_base::app);
+  ofstream history(histfile, std::ios_base::app);
   string lastline;
   for(;;) {
     char* sline = readline("> ");
@@ -144,14 +166,15 @@ void doClient(ComboAddress server, const std::string& command)
 
 void doConsole()
 {
+  string histfile = historyFile(true);
   set<string> dupper;
   {
-    ifstream history(".dnsdist_history");
+    ifstream history(histfile);
     string line;
     while(getline(history, line))
       add_history(line.c_str());
   }
-  ofstream history(".dnsdist_history", std::ios_base::app);
+  ofstream history(histfile, std::ios_base::app);
   string lastline;
   for(;;) {
     char* sline = readline("> ");
@@ -334,10 +357,14 @@ const std::vector<ConsoleKeyword> g_consoleKeywords{
   { "setKey", true, "key", "set access key to that key" },
   { "setLocal", true, "netmask, [true], [false], [TCP Fast Open queue size]", "reset list of addresses we listen on to this address. Second optional parameter sets TCP or not. Third optional parameter sets SO_REUSEPORT when available. Last parameter sets the TCP Fast Open queue size, enabling TCP Fast Open when available and the value is larger than 0." },
   { "setMaxTCPClientThreads", true, "n", "set the maximum of TCP client threads, handling TCP connections" },
+  { "setMaxTCPConnectionDuration", true, "n", "set the maximum duration of an incoming TCP connection, in seconds. 0 means unlimited" },
+  { "setMaxTCPConnectionsPerClient", true, "n", "set the maximum number of TCP connections per client. 0 means unlimited" },
+  { "setMaxTCPQueriesPerConnection", true, "n", "set the maximum number of queries in an incoming TCP connection. 0 means unlimited" },
   { "setMaxTCPQueuedConnections", true, "n", "set the maximum number of TCP connections queued (waiting to be picked up by a client thread)" },
   { "setMaxUDPOutstanding", true, "n", "set the maximum number of outstanding UDP queries to a given backend server. This can only be set at configuration time and defaults to 10240" },
   { "setQueryCount", true, "bool", "set whether queries should be counted" },
   { "setQueryCountFilter", true, "func", "filter queries that would be counted, where `func` is a function with parameter `dq` which decides whether a query should and how it should be counted" },
+  { "setRingBuffersSize", true, "n", "set the capacity of the ringbuffers used for live traffic inspection to `n`" },
   { "setRules", true, "list of rules", "replace the current rules with the supplied list of pairs of DNS Rules and DNS Actions (see `newRuleAction()`)" },
   { "setServerPolicy", true, "policy", "set server selection policy to that policy" },
   { "setServerPolicyLua", true, "name, function", "set server selection policy to one named 'name' and provided by 'function'" },