]> granicus.if.org Git - pdns/commitdiff
dnsdist: add docs, test for TempFailureCacheTTLAction
authorChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Sat, 6 Jan 2018 00:15:50 +0000 (01:15 +0100)
committerChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Sat, 6 Jan 2018 00:15:50 +0000 (01:15 +0100)
pdns/dnsdist-console.cc
pdns/dnsdistdist/docs/rules-actions.rst
regression-tests.dnsdist/test_Caching.py

index 40aa405eaf3894b63598247af3d4fcf4c601c651..ea3b6ea9bea1c57f4bb943a8af7b742d039ee3f6 100644 (file)
@@ -419,6 +419,8 @@ const std::vector<ConsoleKeyword> g_consoleKeywords{
   { "TagResponseAction", true, "name, value", "set the tag named 'name' to the given value" },
   { "TagRule", true, "name [, value]", "matches if the tag named 'name' is present, with the given 'value' matching if any" },
   { "TCAction", true, "", "create answer to query with TC and RD bits set, to move to TCP" },
+  { "TeeAction", true, "remote [, addECS]", "send copy of query to remote, optionally adding ECS info" },
+  { "TempFailureCacheTTLAction", true, "ttl", "set packetcache TTL for temporary failure replies" },
   { "testCrypto", true, "", "test of the crypto all works" },
   { "TimedIPSetRule", true, "", "Create a rule which matches a set of IP addresses which expire"}, 
   { "topBandwidth", true, "top", "show top-`top` clients that consume the most bandwidth over length of ringbuffer" },
index 9b904f874bc2e22ba837df9a26bc98c6ed645687..e97cfa6f77ea098b4cf0b33cf058ae619530682c 100644 (file)
@@ -791,4 +791,8 @@ The following actions exist.
   :param string remote: An IP:PORT conbination to send the copied queries to
   :param bool addECS: Whether or not to add ECS information. Default false
 
+.. function:: TempFailureCacheTTLAction(ttl)
 
+  Set the cache TTL to use for ServFail and Refused replies. TTL is not applied for successful replies.
+
+  :param int ttl: Cache TTL for temporary failure replies
index 175d4166c0ea64362241f01cbb7c906cdbe978d0..50d8bc66dfd8823b5c74ea5fcad0da48dbed4620 100644 (file)
@@ -354,6 +354,52 @@ class TestCaching(DNSDistTest):
         self.assertEquals(receivedResponse, differentCaseResponse)
 
 
+class TestTempFailureCacheTTLAction(DNSDistTest):
+
+    _config_template = """
+    pc = newPacketCache(100, 86400, 1)
+    getPool(""):setCache(pc)
+    addAction("servfail.cache.tests.powerdns.com.", TempFailureCacheTTLAction(1))
+    newServer{address="127.0.0.1:%s"}
+    """
+
+    def testTempFailureCacheTTLAction(self):
+        """
+        Cache: When a TempFailure TTL is set, it should be honored
+
+        dnsdist is configured to cache packets, plus a specific qname is
+        set up with a lower TempFailure Cache TTL. we are sending one request
+        (cache miss) and verify that the cache is hit for the following query,
+        but the TTL then expires before the larger "good" packetcache TTL.
+        """
+        name = 'servfail.cache.tests.powerdns.com.'
+        query = dns.message.make_query(name, 'AAAA', 'IN')
+        response = dns.message.make_response(query)
+        response.set_rcode(dns.rcode.SERVFAIL)
+
+        (receivedQuery, receivedResponse) = self.sendUDPQuery(query, response)
+        self.assertTrue(receivedQuery)
+        self.assertTrue(receivedResponse)
+        receivedQuery.id = query.id
+        self.assertEquals(query, receivedQuery)
+        self.assertEquals(receivedResponse, response)
+
+        # next query should hit the cache
+        (receivedQuery, receivedResponse) = self.sendUDPQuery(query, response)
+        self.assertFalse(receivedQuery)
+        self.assertTrue(receivedResponse)
+        self.assertEquals(receivedResponse, response)
+
+        # now we wait a bit for the Failure-Cache TTL to expire
+        time.sleep(2)
+
+        # next query should NOT hit the cache
+        (receivedQuery, receivedResponse) = self.sendUDPQuery(query, response)
+        self.assertTrue(receivedQuery)
+        self.assertTrue(receivedResponse)
+        self.assertEquals(receivedResponse, response)
+
+
 class TestCachingWithExistingEDNS(DNSDistTest):
 
     _config_template = """