]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add an optional `addECS` option to `TeeAction()` 4019/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 20 Jun 2016 11:58:27 +0000 (13:58 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 20 Jun 2016 11:58:27 +0000 (13:58 +0200)
pdns/README-dnsdist.md
pdns/dnsdist-lua2.cc
pdns/dnsdistdist/dnsrulactions.cc
pdns/dnsrulactions.hh

index 958ff16265028504380aa07a2d0cc9bc6f1b0eb0..71db623d432d489dccc24dcb2cccb405f88e74dd 100644 (file)
@@ -1159,7 +1159,7 @@ instantiate a server with additional parameters
     * `SpoofAction(ip[, ip])` or `SpoofAction({ip, ip, ..}): forge a response with the specified IPv4 (for an A query) or IPv6 (for an AAAA). If you specify multiple addresses, all that match the query type (A, AAAA or ANY) will get spoofed in
     * `SpoofCNAMEAction(cname)`: forge a response with the specified CNAME value
     * `TCAction()`: create answer to query with TC and RD bits set, to move to TCP/IP
-    * `TeeAction(remote)`: send copy of query to remote, keep stats on responses
+    * `TeeAction(remote[, addECS])`: send copy of query to remote, keep stats on responses. If `addECS` is set to `true`, EDNS Client Subnet information will be added to the query
  * Specialist rule generators
     * `addAnyTCRule()`: generate TC=1 answers to ANY queries received over UDP, moving them to TCP
     * `addDomainSpoof(domain, ip[, ip6])` or `addDomainSpoof(domain, {IP, IP, IP..})`: generate answers for A/AAAA/ANY queries using the ip parameters
index 17be04bacd7bd78ae034a6219e28998e20ac1382..6b0f95e9bf3050d5eeb22b2e08b09e2349af623d 100644 (file)
@@ -579,9 +579,8 @@ void moreLua(bool client)
         return std::make_shared<RemoteLogger>(ComboAddress(remote), timeout ? *timeout : 2, maxQueuedEntries ? *maxQueuedEntries : 100, reconnectWaitTime ? *reconnectWaitTime : 1);
       });
 
-    g_lua.writeFunction("TeeAction", [](const std::string& remote) {
-        setLuaNoSideEffect();
-        return std::shared_ptr<DNSAction>(new TeeAction(ComboAddress(remote, 53)));
+    g_lua.writeFunction("TeeAction", [](const std::string& remote, boost::optional<bool> addECS) {
+        return std::shared_ptr<DNSAction>(new TeeAction(ComboAddress(remote, 53), addECS ? *addECS : false));
       });
 
     g_lua.registerFunction<void(DNSAction::*)()>("printStats", [](const DNSAction& ta) {
index aa40c5a381efca4b59f6bc3ddbdf9b83759fc20e..88e76c295a1c6b8fd01d9cbe34759c432fac6adb 100644 (file)
@@ -3,7 +3,7 @@
 
 using namespace std;
 
-TeeAction::TeeAction(const ComboAddress& ca) : d_remote(ca)
+TeeAction::TeeAction(const ComboAddress& ca, bool addECS) : d_remote(ca), d_addECS(addECS)
 {
   d_fd=SSocket(d_remote.sin4.sin_family, SOCK_DGRAM, 0);
   SConnect(d_fd, d_remote);
@@ -23,8 +23,32 @@ DNSAction::Action TeeAction::operator()(DNSQuestion* dq, string* ruleresult) con
   if(dq->tcp) 
     d_tcpdrops++;
   else {
+    ssize_t res;
     d_queries++;
-    if(send(d_fd, (char*)dq->dh, dq->len, 0) <= 0) 
+
+    if(d_addECS) {
+      std::string query;
+      std::string larger;
+      uint16_t len = dq->len;
+      bool ednsAdded = false;
+      bool ecsAdded = false;
+      query.reserve(dq->size);
+      query.assign((char*) dq->dh, len);
+
+      handleEDNSClientSubnet((char*) query.c_str(), query.size(), dq->qname->wirelength(), &len, larger, &ednsAdded, &ecsAdded, *dq->remote);
+
+      if (larger.empty()) {
+        res = send(d_fd, query.c_str(), len, 0);
+      }
+      else {
+        res = send(d_fd, larger.c_str(), larger.length(), 0);
+      }
+    }
+    else {
+      res = send(d_fd, (char*)dq->dh, dq->len, 0);
+    }
+
+    if (res <= 0)
       d_senderrors++;
   }
   return DNSAction::Action::None;
index 899e7d64b474b9f12f3738a9d9f7cd126e31cbf8..9d47c4dd52720f51d9e77baf6054cd0205873761 100644 (file)
@@ -557,7 +557,7 @@ private:
 class TeeAction : public DNSAction
 {
 public:
-  TeeAction(const ComboAddress& ca);
+  TeeAction(const ComboAddress& ca, bool addECS=false);
   ~TeeAction();
   DNSAction::Action operator()(DNSQuestion* dq, string* ruleresult) const override;
   string toString() const override;
@@ -581,6 +581,7 @@ private:
   mutable unsigned long d_tcpdrops{0};
   unsigned long d_otherrcode{0};
   std::atomic<bool> d_pleaseQuit{false};
+  bool d_addECS{false};
 };