From a2c4a33981b6cbd3f7c54b8736c8e30e997f88f5 Mon Sep 17 00:00:00 2001 From: Chris Hofstaedtler Date: Sat, 6 Jan 2018 01:15:50 +0100 Subject: [PATCH] dnsdist: add docs, test for TempFailureCacheTTLAction --- pdns/dnsdist-console.cc | 2 ++ pdns/dnsdistdist/docs/rules-actions.rst | 4 +++ regression-tests.dnsdist/test_Caching.py | 46 ++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/pdns/dnsdist-console.cc b/pdns/dnsdist-console.cc index 40aa405ea..ea3b6ea9b 100644 --- a/pdns/dnsdist-console.cc +++ b/pdns/dnsdist-console.cc @@ -419,6 +419,8 @@ const std::vector 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" }, diff --git a/pdns/dnsdistdist/docs/rules-actions.rst b/pdns/dnsdistdist/docs/rules-actions.rst index 9b904f874..e97cfa6f7 100644 --- a/pdns/dnsdistdist/docs/rules-actions.rst +++ b/pdns/dnsdistdist/docs/rules-actions.rst @@ -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 diff --git a/regression-tests.dnsdist/test_Caching.py b/regression-tests.dnsdist/test_Caching.py index 175d4166c..50d8bc66d 100644 --- a/regression-tests.dnsdist/test_Caching.py +++ b/regression-tests.dnsdist/test_Caching.py @@ -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 = """ -- 2.40.0