]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add an option to log as text. Display filename in showRules 3360/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 11 Feb 2016 14:43:43 +0000 (15:43 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 11 Feb 2016 14:43:43 +0000 (15:43 +0100)
LogAction() could log to the console in text mode or to a file in
binary mode. This commit adds an option to log to a file in text
mode.
When logging to a file, we now display the file name in
showRules().

pdns/README-dnsdist.md
pdns/dnsdist-lua.cc
pdns/dnsrulactions.hh

index 1ca6d6e2f4d5659f0b7242e8e82df782fac12e23..9e5570d404d36548bb133c3643c3100a2ba1e45e 100644 (file)
@@ -840,7 +840,7 @@ instantiate a server with additional parameters
     * `DelayAction()`: delay the response by the specified amount of milliseconds (UDP-only)
     * `DisableValidationAction()`: set the CD bit in the question, let it go through
     * `DropAction()`: drop these packets
-    * `LogAction()`: Log a line for each query, to the specified file if any, to the console (require verbose) otherwise
+    * `LogAction([filename], [binary])`: Log a line for each query, to the specified file if any, to the console (require verbose) otherwise. When logging to a file, the `binary` optional parameter specifies whether we log in binary form (default) or in textual form
     * `NoRecurseAction()`: strip RD bit from the question, let it go through
     * `PoolAction()`: set the packet into the specified pool
     * `QPSPoolAction()`: set the packet into the specified pool only if it does not exceed the specified QPS limits
index 9df0b5b6702c06218b9a04277037992d44cbf8f6..48625fb7bdbcd098a3461964994a389b4d66af60 100644 (file)
@@ -619,8 +619,8 @@ vector<std::function<void(void)>> setupLua(bool client, const std::string& confi
       return std::shared_ptr<DNSAction>(new DisableValidationAction);
     });
 
-  g_lua.writeFunction("LogAction", [](const std::string& fname) {
-      return std::shared_ptr<DNSAction>(new LogAction(fname));
+  g_lua.writeFunction("LogAction", [](const std::string& fname, boost::optional<bool> binary) {
+      return std::shared_ptr<DNSAction>(new LogAction(fname, binary ? *binary : true));
     });
 
   g_lua.writeFunction("RCodeAction", [](int rcode) {
index 86dc1a57c19ac210600a72f959096d3cb13b08c5..674423f8144daaf81ff74b4ddffb8cdb80588772 100644 (file)
@@ -589,7 +589,7 @@ public:
   LogAction() : d_fp(0)
   {
   }
-  LogAction(const std::string& str) : d_fname(str)
+  LogAction(const std::string& str, bool binary=true) : d_fname(str), d_binary(binary)
   {
     if(str.empty())
       return;
@@ -608,19 +608,28 @@ public:
       vinfolog("Packet from %s for %s %s with id %d", dq->remote->toStringWithPort(), dq->qname->toString(), QType(dq->qtype).getName(), dq->dh->id);
     }
     else {
-      string out = dq->qname->toDNSString();
-      fwrite(out.c_str(), 1, out.size(), d_fp);
-      fwrite((void*)&dq->qtype, 1, 2, d_fp);
+      if(d_binary) {
+        string out = dq->qname->toDNSString();
+        fwrite(out.c_str(), 1, out.size(), d_fp);
+        fwrite((void*)&dq->qtype, 1, 2, d_fp);
+      }
+      else {
+        fprintf(d_fp, "Packet from %s for %s %s with id %d\n", dq->remote->toStringWithPort().c_str(), dq->qname->toString().c_str(), QType(dq->qtype).getName().c_str(), dq->dh->id);
+      }
     }
     return Action::None;
   }
   string toString() const override
   {
+    if (!d_fname.empty()) {
+      return "log to " + d_fname;
+    }
     return "log";
   }
 private:
   string d_fname;
   FILE* d_fp{0};
+  bool d_binary{true};
 };