]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add the ability to set flags in SetNegativeAndSOAAction() 8171/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 7 Feb 2020 11:06:07 +0000 (12:06 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 7 Feb 2020 11:06:07 +0000 (12:06 +0100)
pdns/dnsdist-console.cc
pdns/dnsdist-lua-actions.cc
pdns/dnsdistdist/docs/rules-actions.rst
regression-tests.dnsdist/test_Advanced.py

index d3a8b06e240ea8e872a977688f0b3bc302476784..6551f3a8341839f04b92d2303957a58912627d4c 100644 (file)
@@ -515,7 +515,7 @@ const std::vector<ConsoleKeyword> g_consoleKeywords{
   { "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 65535" },
-  { "SetNegativeAndSOAAction", "true", "nxd, zone, ttl, mname, rname, serial, refresh, retry, expire, minimum", "Turn a query into a NXDomain or NoData answer and sets a SOA record in the additional section" },
+  { "SetNegativeAndSOAAction", "true", "nxd, zone, ttl, mname, rname, serial, refresh, retry, expire, minimum [, options]", "Turn a query into a NXDomain or NoData answer and sets a SOA record in the additional section" },
   { "setPayloadSizeOnSelfGeneratedAnswers", true, "payloadSize", "set the UDP payload size advertised via EDNS on self-generated responses" },
   { "setPoolServerPolicy", true, "policy, pool", "set the server selection policy for this pool to that policy" },
   { "setPoolServerPolicyLua", true, "name, func, pool", "set the server selection policy for this pool to one named 'name' and provided by 'function'" },
index 69c6c1a175f82ab597991f52557fc544a8b67dd9..9134ddb7134d0ad0dd91d83861cbe552e49793ea 100644 (file)
@@ -1273,6 +1273,8 @@ public:
       return Action::None;
     }
 
+    setResponseHeadersFromConfig(*dq->dh, d_responseConfig);
+
     return Action::Allow;
   }
 
@@ -1281,6 +1283,8 @@ public:
     return std::string(d_nxd ? "NXD " : "NODATA") + " with SOA";
   }
 
+  ResponseConfig d_responseConfig;
+
 private:
   DNSName d_zone;
   DNSName d_mname;
@@ -1439,7 +1443,7 @@ void setupLuaActions()
       return std::shared_ptr<DNSAction>(new QPSPoolAction(limit, a));
     });
 
-  g_lua.writeFunction("SpoofAction", [](boost::variant<std::string,vector<pair<int, std::string>>> inp, boost::optional<std::string> b, boost::optional<responseParams_t> vars ) {
+  g_lua.writeFunction("SpoofAction", [](boost::variant<std::string,vector<pair<int, std::string>>> inp, boost::optional<std::string> b, boost::optional<responseParams_t> vars) {
       vector<ComboAddress> addrs;
       if(auto s = boost::get<std::string>(&inp))
         addrs.push_back(ComboAddress(*s));
@@ -1679,7 +1683,10 @@ void setupLuaActions()
       return std::shared_ptr<DNSAction>(new KeyValueStoreLookupAction(kvs, lookupKey, destinationTag));
     });
 
-  g_lua.writeFunction("SetNegativeAndSOAAction", [](bool nxd, const std::string& zone, uint32_t ttl, const std::string& mname, const std::string& rname, uint32_t serial, uint32_t refresh, uint32_t retry, uint32_t expire, uint32_t minimum) {
-      return std::shared_ptr<DNSAction>(new SetNegativeAndSOAAction(nxd, DNSName(zone), ttl, DNSName(mname), DNSName(rname), serial, refresh, retry, expire, minimum));
+  g_lua.writeFunction("SetNegativeAndSOAAction", [](bool nxd, const std::string& zone, uint32_t ttl, const std::string& mname, const std::string& rname, uint32_t serial, uint32_t refresh, uint32_t retry, uint32_t expire, uint32_t minimum, boost::optional<responseParams_t> vars) {
+      auto ret = std::shared_ptr<DNSAction>(new SetNegativeAndSOAAction(nxd, DNSName(zone), ttl, DNSName(mname), DNSName(rname), serial, refresh, retry, expire, minimum));
+      auto action = std::dynamic_pointer_cast<SetNegativeAndSOAAction>(ret);
+      parseResponseConfig(vars, action->d_responseConfig);
+      return ret;
     });
 }
index 4197e89efeedd787b735149c3fa2fcdfc67b3127..4e9af366f6a46df17beec9daef036a624e5ce3da 100644 (file)
@@ -1187,7 +1187,7 @@ The following actions exist.
   :param string v4: The IPv4 netmask, for example "192.0.2.1/32"
   :param string v6: The IPv6 netmask, if any
 
-.. function:: SetNegativeAndSOAAction(nxd, zone, ttl, mname, rname, serial, refresh, retry, expire, minimum)
+.. function:: SetNegativeAndSOAAction(nxd, zone, ttl, mname, rname, serial, refresh, retry, expire, minimum [, options])
 
   .. versionadded:: 1.5.0
 
@@ -1203,6 +1203,13 @@ The following actions exist.
   :param int retry: The value of the retry field in the SOA record
   :param int expire: The value of the expire field in the SOA record
   :param int minimum: The value of the minimum field in the SOA record
+  :param table options: A table with key: value pairs with options
+
+  Options:
+
+  * ``aa``: bool - Set the AA bit to this value (true means the bit is set, false means it's cleared). Default is to clear it.
+  * ``ad``: bool - Set the AD bit to this value (true means the bit is set, false means it's cleared). Default is to clear it.
+  * ``ra``: bool - Set the RA bit to this value (true means the bit is set, false means it's cleared). Default is to copy the value of the RD bit from the incoming query.
 
 .. function:: SkipCacheAction()
 
index e4d4c636dd73f21c44a17c5b7eada7c028ea8973..ba1a67ac09a17ee83145236c3f30e15ce8afc775 100644 (file)
@@ -1857,6 +1857,7 @@ class TestAdvancedSetNegativeAndSOA(DNSDistTest):
         """
         name = 'nxd.setnegativeandsoa.advanced.tests.powerdns.com.'
         query = dns.message.make_query(name, 'A', 'IN')
+        query.flags &= ~dns.flags.RD
         expectedResponse = dns.message.make_response(query)
         expectedResponse.set_rcode(dns.rcode.NXDOMAIN)
         soa = dns.rrset.from_text("auth",
@@ -1877,6 +1878,7 @@ class TestAdvancedSetNegativeAndSOA(DNSDistTest):
         """
         name = 'nodata.setnegativeandsoa.advanced.tests.powerdns.com.'
         query = dns.message.make_query(name, 'A', 'IN')
+        query.flags &= ~dns.flags.RD
         expectedResponse = dns.message.make_response(query)
         expectedResponse.set_rcode(dns.rcode.NOERROR)
         soa = dns.rrset.from_text("another-auth",