]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Merge pull request #7689 from rgacogne/dnsdist-14-packetcache
authorRemi Gacogne <rgacogne@users.noreply.github.com>
Wed, 10 Apr 2019 08:02:43 +0000 (10:02 +0200)
committerGitHub <noreply@github.com>
Wed, 10 Apr 2019 08:02:43 +0000 (10:02 +0200)
dnsdist: Switch to the new 'newPacketCache()' syntax for 1.4.0

pdns/dnsdist-lua-bindings.cc
pdns/dnsdistdist/docs/reference/config.rst
pdns/dnsdistdist/docs/rules-actions.rst
regression-tests.dnsdist/test_CacheHitResponses.py
regression-tests.dnsdist/test_Caching.py
regression-tests.dnsdist/test_DNSCrypt.py
regression-tests.dnsdist/test_TCPKeepAlive.py

index 6a8d64156de8cde7eb8534ae88112b08bbfa9fc0..b29fc3edf3b4eaa20c5b95d1e3d0d21d69d8eee5 100644 (file)
@@ -248,9 +248,18 @@ void setupLuaBindings(bool client)
 #endif /* HAVE_EBPF */
 
   /* PacketCache */
-  g_lua.writeFunction("newPacketCache", [](size_t maxEntries, boost::optional<uint32_t> maxTTL, boost::optional<uint32_t> minTTL, boost::optional<uint32_t> tempFailTTL, boost::optional<uint32_t> staleTTL, boost::optional<bool> dontAge, boost::optional<size_t> numberOfShards, boost::optional<bool> deferrableInsertLock, boost::optional<uint32_t> maxNegativeTTL, boost::optional<bool> ecsParsing, boost::optional<std::unordered_map<std::string, boost::variant<bool, size_t>>> vars) {
+  g_lua.writeFunction("newPacketCache", [](size_t maxEntries, boost::optional<std::unordered_map<std::string, boost::variant<bool, size_t>>> vars) {
 
       bool keepStaleData = false;
+      size_t maxTTL = 86400;
+      size_t minTTL = 0;
+      size_t tempFailTTL = 60;
+      size_t maxNegativeTTL = 3600;
+      size_t staleTTL = 60;
+      size_t numberOfShards = 1;
+      bool dontAge = false;
+      bool deferrableInsertLock = true;
+      bool ecsParsing = false;
 
       if (vars) {
 
@@ -297,10 +306,9 @@ void setupLuaBindings(bool client)
         if (vars->count("temporaryFailureTTL")) {
           tempFailTTL = boost::get<size_t>((*vars)["temporaryFailureTTL"]);
         }
-
       }
 
-      auto res = std::make_shared<DNSDistPacketCache>(maxEntries, maxTTL ? *maxTTL : 86400, minTTL ? *minTTL : 0, tempFailTTL ? *tempFailTTL : 60, maxNegativeTTL ? *maxNegativeTTL : 3600, staleTTL ? *staleTTL : 60, dontAge ? *dontAge : false, numberOfShards ? *numberOfShards : 1, deferrableInsertLock ? *deferrableInsertLock : true, ecsParsing ? *ecsParsing : false);
+      auto res = std::make_shared<DNSDistPacketCache>(maxEntries, maxTTL, minTTL, tempFailTTL, maxNegativeTTL, staleTTL, dontAge, numberOfShards, deferrableInsertLock, ecsParsing);
 
       res->setKeepStaleData(keepStaleData);
 
index ef1f68b4b1ccb89766b216ff96a2dab34975bc44..1f78d14b623a38791fb9a83edec0adbeacd5e165 100644 (file)
@@ -318,7 +318,7 @@ Servers
   .. versionchanged:: 1.3.0
     Added ``checkClass``, ``sockets`` and ``checkFunction`` to server_table.
 
-  .. versionchanged:: 1.3.4
+  .. versionchanged:: 1.4.0
     Added ``checkTimeout`` and ``rise`` to server_table.
 
   Add a new backend server. Call this function with either a string::
@@ -545,7 +545,7 @@ PacketCache
 A Pool can have a packet cache to answer queries directly in stead of going to the backend.
 See :doc:`../guides/cache` for a how to.
 
-.. function:: newPacketCache(maxEntries[, maxTTL=86400[, minTTL=0[, temporaryFailureTTL=60[, staleTTL=60[, dontAge=false[, numberOfShards=1[, deferrableInsertLock=true[, maxNegativeTTL=3600[, parseECS=false [,options]]]]]]]]) -> PacketCache
+.. function:: newPacketCache(maxEntries[, maxTTL=86400[, minTTL=0[, temporaryFailureTTL=60[, staleTTL=60[, dontAge=false[, numberOfShards=1[, deferrableInsertLock=true[, maxNegativeTTL=3600[, parseECS=false]]]]]]]) -> PacketCache
 
   .. versionchanged:: 1.3.0
     ``numberOfShards`` and ``deferrableInsertLock`` parameters added.
@@ -553,11 +553,9 @@ See :doc:`../guides/cache` for a how to.
   .. versionchanged:: 1.3.1
     ``maxNegativeTTL`` and ``parseECS`` parameters added.
 
-  .. versionchanged:: 1.3.4
-    ``options`` parameter added.
+  .. deprecated:: 1.4.0
 
   Creates a new :class:`PacketCache` with the settings specified.
-  Starting with 1.3.4, all parameters can be specified in the ``options`` table, overriding the value from the existing parameters if any.
 
   :param int maxEntries: The maximum number of entries in this cache
   :param int maxTTL: Cap the TTL for records to his number
@@ -569,7 +567,14 @@ See :doc:`../guides/cache` for a how to.
   :param bool deferrableInsertLock: Whether the cache should give up insertion if the lock is held by another thread, or simply wait to get the lock
   :param int maxNegativeTTL: Cache a NXDomain or NoData answer from the backend for at most this amount of seconds, even if the TTL of the SOA record is higher
   :param bool parseECS: Whether any EDNS Client Subnet option present in the query should be extracted and stored to be able to detect hash collisions involving queries with the same qname, qtype and qclass but a different incoming ECS value. Enabling this option adds a parsing cost and only makes sense if at least one backend might send different responses based on the ECS value, so it's disabled by default
-  :param table options: A table with key: value pairs with the options listed below:
+
+.. function:: newPacketCache(maxEntries, [options]) -> PacketCache
+
+  .. versionadded:: 1.4.0
+
+  Creates a new :class:`PacketCache` with the settings specified.
+
+  :param int maxEntries: The maximum number of entries in this cache
 
   Options:
 
@@ -616,7 +621,7 @@ See :doc:`../guides/cache` for a how to.
 
   .. method:: PacketCache:getStats()
 
-    .. versionadded:: 1.3.4
+    .. versionadded:: 1.4.0
 
     Return the cache stats (number of entries, hits, misses, deferred lookups, deferred inserts, lookup collisions, insert collisions and TTL too shorts) as a Lua table.
 
@@ -726,7 +731,7 @@ Status, Statistics and More
 
 .. function:: showServers([options])
 
-  .. versionchanged:: 1.3.4
+  .. versionchanged:: 1.4.0
     ``options`` optional parameter added
 
   This function shows all backend servers currently configured and some statistics.
index 1ed837dea24f83cb38cdaf85863c0d9b8aff6eb5..ec23c155e3b4eb7800725826f484ca7aa25fcc57 100644 (file)
@@ -969,7 +969,7 @@ The following actions exist.
   .. versionchanged:: 1.3.0
     ``options`` optional parameter added.
 
-  .. versionchanged:: 1.3.4
+  .. versionchanged:: 1.4.0
     ``ipEncryptKey`` optional key added to the options table.
 
   Send the content of this query to a remote logger via Protocol Buffer.
@@ -989,7 +989,7 @@ The following actions exist.
   .. versionchanged:: 1.3.0
     ``options`` optional parameter added.
 
-  .. versionchanged:: 1.3.4
+  .. versionchanged:: 1.4.0
     ``ipEncryptKey`` optional key added to the options table.
 
   Send the content of this response to a remote logger via Protocol Buffer.
index a6b8aafa6dcec8f2c6962ede39f0f5b47354e0d9..589372b3e986245804a573a97d3c493ad990011f 100644 (file)
@@ -7,7 +7,7 @@ from dnsdisttests import DNSDistTest
 class TestCacheHitResponses(DNSDistTest):
 
     _config_template = """
-    pc = newPacketCache(100, 86400, 1)
+    pc = newPacketCache(100, {maxTTL=86400, minTTL=1})
     getPool(""):setCache(pc)
     addCacheHitResponseAction(makeRule("dropwhencached.cachehitresponses.tests.powerdns.com."), DropResponseAction())
     newServer{address="127.0.0.1:%s"}
index aff1d2b6ee60069aed9b336522351f4125e26553..60a898b65b294190f6b5a47acf9cf0321c2d9e0d 100644 (file)
@@ -8,8 +8,7 @@ from dnsdisttests import DNSDistTest
 class TestCaching(DNSDistTest):
 
     _config_template = """
-    -- maxTTL=86400, minTTL=1
-    pc = newPacketCache(100, 86400, 1)
+    pc = newPacketCache(100, {maxTTL=86400, minTTL=1})
     getPool(""):setCache(pc)
     addAction(makeRule("nocache.cache.tests.powerdns.com."), SkipCacheAction())
     function skipViaLua(dq)
@@ -407,8 +406,7 @@ class TestCaching(DNSDistTest):
 class TestTempFailureCacheTTLAction(DNSDistTest):
 
     _config_template = """
-    -- maxTTL=86400, minTTL=1
-    pc = newPacketCache(100, 86400, 1)
+    pc = newPacketCache(100, {maxTTL=86400, minTTL=1})
     getPool(""):setCache(pc)
     addAction("servfail.cache.tests.powerdns.com.", TempFailureCacheTTLAction(1))
     newServer{address="127.0.0.1:%d"}
@@ -454,8 +452,7 @@ class TestTempFailureCacheTTLAction(DNSDistTest):
 class TestCachingWithExistingEDNS(DNSDistTest):
 
     _config_template = """
-    -- maxTTL=86400, minTTL=1
-    pc = newPacketCache(5, 86400, 1)
+    pc = newPacketCache(5, {maxTTL=86400, minTTL=1})
     getPool(""):setCache(pc)
     newServer{address="127.0.0.1:%d"}
     """
@@ -512,8 +509,7 @@ class TestCachingWithExistingEDNS(DNSDistTest):
 class TestCachingCacheFull(DNSDistTest):
 
     _config_template = """
-    -- maxTTL=86400, minTTL=1
-    pc = newPacketCache(1, 86400, 1)
+    pc = newPacketCache(1, {maxTTL=86400, minTTL=1})
     getPool(""):setCache(pc)
     newServer{address="127.0.0.1:%d"}
     """
@@ -587,8 +583,7 @@ class TestCachingNoStale(DNSDistTest):
     _consoleKeyB64 = base64.b64encode(_consoleKey).decode('ascii')
     _config_params = ['_consoleKeyB64', '_consolePort', '_testServerPort']
     _config_template = """
-    -- maxTTL=86400, minTTL=1
-    pc = newPacketCache(100, 86400, 1)
+    pc = newPacketCache(100, {maxTTL=86400, minTTL=1})
     getPool(""):setCache(pc)
     setKey("%s")
     controlSocket("127.0.0.1:%d")
@@ -639,8 +634,7 @@ class TestCachingStale(DNSDistTest):
     _staleCacheTTL = 60
     _config_params = ['_staleCacheTTL', '_consoleKeyB64', '_consolePort', '_testServerPort']
     _config_template = """
-    -- maxTTL=86400, minTTL=1, temporaryFailureTTL=0, staleTTL=XX
-    pc = newPacketCache(100, 86400, 1, 0, %d)
+    pc = newPacketCache(100, {maxTTL=86400, minTTL=1, temporaryFailureTTL=0, staleTTL=%d})
     getPool(""):setCache(pc)
     setStaleCacheEntriesTTL(600)
     setKey("%s")
@@ -701,8 +695,7 @@ class TestCachingStaleExpunged(DNSDistTest):
     _staleCacheTTL = 60
     _config_params = ['_staleCacheTTL', '_consoleKeyB64', '_consolePort', '_testServerPort']
     _config_template = """
-    -- maxTTL=86400, minTTL=1, temporaryFailureTTL=0, staleTTL=XX
-    pc = newPacketCache(100, 86400, 1, 0, %d)
+    pc = newPacketCache(100, {maxTTL=86400, minTTL=1, temporaryFailureTTL=0, staleTTL=%d})
     getPool(""):setCache(pc)
     setStaleCacheEntriesTTL(600)
     -- try to remove all expired entries
@@ -776,8 +769,7 @@ class TestCachingStaleExpungePrevented(DNSDistTest):
     _consoleKeyB64 = base64.b64encode(_consoleKey).decode('ascii')
     _config_params = ['_consoleKeyB64', '_consolePort', '_testServerPort']
     _config_template = """
-    -- maxTTL=86400, minTTL=1, temporaryFailureTTL=0, staleTTL=60, dontAge=false, numberOfShards=1, deferrableInsertLock=true, maxNegativeTTL=3600, ecsParsing=false, keepStaleData=true
-    pc = newPacketCache(100, 86400, 1, 0, 60, false, 1, true, 3600, false, { keepStaleData=true})
+    pc = newPacketCache(100, {maxTTL=86400, minTTL=1, temporaryFailureTTL=0, staleTTL=60, dontAge=false, numberOfShards=1, deferrableInsertLock=true, maxNegativeTTL=3600, ecsParsing=false, keepStaleData=true})
     getPool(""):setCache(pc)
     setStaleCacheEntriesTTL(600)
     -- try to remove all expired entries
@@ -850,8 +842,7 @@ class TestCacheManagement(DNSDistTest):
     _consoleKeyB64 = base64.b64encode(_consoleKey).decode('ascii')
     _config_params = ['_consoleKeyB64', '_consolePort', '_testServerPort']
     _config_template = """
-    -- maxTTL=86400, minTTL=1
-    pc = newPacketCache(100, 86400, 1)
+    pc = newPacketCache(100, {maxTTL=86400, minTTL=1})
     getPool(""):setCache(pc)
     setKey("%s")
     controlSocket("127.0.0.1:%d")
@@ -1239,8 +1230,7 @@ class TestCachingTTL(DNSDistTest):
     _minCacheTTL = 600
     _config_params = ['_maxCacheTTL', '_minCacheTTL', '_testServerPort']
     _config_template = """
-    -- maxTTL=XX, minTTL=XX
-    pc = newPacketCache(1000, %d, %d)
+    pc = newPacketCache(1000, {maxTTL=%d, minTTL=%d})
     getPool(""):setCache(pc)
     newServer{address="127.0.0.1:%d"}
     """
@@ -1329,8 +1319,7 @@ class TestCachingLongTTL(DNSDistTest):
     _maxCacheTTL = 2
     _config_params = ['_maxCacheTTL', '_testServerPort']
     _config_template = """
-    -- maxTTL=XX
-    pc = newPacketCache(1000, %d)
+    pc = newPacketCache(1000, {maxTTL=%d})
     getPool(""):setCache(pc)
     newServer{address="127.0.0.1:%d"}
     """
@@ -1393,8 +1382,7 @@ class TestCachingFailureTTL(DNSDistTest):
     _failureCacheTTL = 2
     _config_params = ['_failureCacheTTL', '_testServerPort']
     _config_template = """
-    -- maxTTL=86400, minTTL=0, temporaryFailureTTL=XX, staleTTL=60
-    pc = newPacketCache(1000, 86400, 0, %d, 60)
+    pc = newPacketCache(1000, {maxTTL=86400, minTTL=0, temporaryFailureTTL=%d, staleTTL=60})
     getPool(""):setCache(pc)
     newServer{address="127.0.0.1:%d"}
     """
@@ -1530,8 +1518,7 @@ class TestCachingNegativeTTL(DNSDistTest):
     _negCacheTTL = 1
     _config_params = ['_negCacheTTL', '_testServerPort']
     _config_template = """
-    -- maxTTL=86400, minTTL=0, temporaryFailureTTL=60, staleTTL=60, dontAge=false, numberOfShards=1, deferrableInsertLock=true, maxNegativeTTL=XX
-    pc = newPacketCache(1000, 86400, 0, 60, 60, false, 1, true, %d)
+    pc = newPacketCache(1000, {maxTTL=86400, minTTL=0, temporaryFailureTTL=60, staleTTL=60, dontAge=false, numberOfShards=1, deferrableInsertLock=true, maxNegativeTTL=%d})
     getPool(""):setCache(pc)
     newServer{address="127.0.0.1:%d"}
     """
@@ -1635,8 +1622,7 @@ class TestCachingNegativeTTL(DNSDistTest):
 class TestCachingDontAge(DNSDistTest):
 
     _config_template = """
-    -- maxTTL=86400, minTTL=0, temporaryFailureTTL=60, staleTTL=60, dontAge=true
-    pc = newPacketCache(100, 86400, 0, 60, 60, true)
+    pc = newPacketCache(100, {maxTTL=86400, minTTL=0, temporaryFailureTTL=60, staleTTL=60, dontAge=true})
     getPool(""):setCache(pc)
     newServer{address="127.0.0.1:%d"}
     """
@@ -1696,8 +1682,7 @@ class TestCachingECSWithoutPoolECS(DNSDistTest):
     _consoleKeyB64 = base64.b64encode(_consoleKey).decode('ascii')
     _config_params = ['_consoleKeyB64', '_consolePort', '_testServerPort']
     _config_template = """
-    -- maxTTL=86400, minTTL=1
-    pc = newPacketCache(100, 86400, 1)
+    pc = newPacketCache(100, {maxTTL=86400, minTTL=1})
     getPool(""):setCache(pc)
     setKey("%s")
     controlSocket("127.0.0.1:%d")
@@ -1751,8 +1736,7 @@ class TestCachingECSWithPoolECS(DNSDistTest):
     _consoleKeyB64 = base64.b64encode(_consoleKey).decode('ascii')
     _config_params = ['_consoleKeyB64', '_consolePort', '_testServerPort']
     _config_template = """
-    -- maxTTL=86400, minTTL=1
-    pc = newPacketCache(100, 86400, 1)
+    pc = newPacketCache(100, {maxTTL=86400, minTTL=1})
     getPool(""):setCache(pc)
     getPool(""):setECS(true)
     setKey("%s")
@@ -1804,8 +1788,7 @@ class TestCachingECSWithPoolECS(DNSDistTest):
 class TestCachingCollisionNoECSParsing(DNSDistTest):
 
     _config_template = """
-    -- maxTTL=86400, minTTL=1
-    pc = newPacketCache(100, 86400, 1)
+    pc = newPacketCache(100, {maxTTL=86400, minTTL=1})
     getPool(""):setCache(pc)
     newServer{address="127.0.0.1:%d"}
     """
@@ -1847,8 +1830,7 @@ class TestCachingCollisionNoECSParsing(DNSDistTest):
 class TestCachingCollisionWithECSParsing(DNSDistTest):
 
     _config_template = """
-    -- maxTTL=86400, minTTL=1, temporaryFailureTTL=60, staleTTL=60, dontAge=false, numberOfShards=1, deferrableInsertLock=true, maxNegativeTTL=3600, parseECS=true
-    pc = newPacketCache(100, 86400, 1, 60, 60, false, 1, true, 3600, true)
+    pc = newPacketCache(100, {maxTTL=86400, minTTL=1, temporaryFailureTTL=60, staleTTL=60, dontAge=false, numberOfShards=1, deferrableInsertLock=true, maxNegativeTTL=3600, parseECS=true})
     getPool(""):setCache(pc)
     newServer{address="127.0.0.1:%d"}
     """
@@ -1897,7 +1879,7 @@ class TestCachingScopeZero(DNSDistTest):
 
     _config_template = """
     -- Be careful to enable ECS parsing in the packet cache, otherwise scope zero is disabled
-    pc = newPacketCache(100, 86400, 1, 60, 60, false, 1, true, 3600, true)
+    pc = newPacketCache(100, {maxTTL=86400, minTTL=1, temporaryFailureTTL=60, staleTTL=60, dontAge=false, numberOfShards=1, deferrableInsertLock=true, maxNegativeTTL=3600, parseECS=true})
     getPool(""):setCache(pc)
     newServer{address="127.0.0.1:%d", useClientSubnet=true}
     -- to simulate a second client coming from a different IP address,
@@ -2085,7 +2067,7 @@ class TestCachingScopeZeroButNoSubnetcheck(DNSDistTest):
 
     _config_template = """
     -- We disable ECS parsing in the packet cache, meaning scope zero is disabled
-    pc = newPacketCache(100, 86400, 1, 60, 60, false, 1, true, 3600, false)
+    pc = newPacketCache(100, {maxTTL=86400, minTTL=1, temporaryFailureTTL=60, staleTTL=60, dontAge=false, numberOfShards=1, deferrableInsertLock=true, maxNegativeTTL=3600, parseECS=false})
     getPool(""):setCache(pc)
     newServer{address="127.0.0.1:%d", useClientSubnet=true}
     -- to simulate a second client coming from a different IP address,
index 08a021029fa3f654c488ff11d1d1ad6ac86e3c41..c1d59a4d5c812e5b4823ea78ca69887ae63dcdd0 100644 (file)
@@ -235,7 +235,7 @@ class TestDNSCryptWithCache(DNSCryptTest):
     _config_template = """
     generateDNSCryptCertificate("DNSCryptProviderPrivate.key", "DNSCryptResolver.cert", "DNSCryptResolver.key", %d, %d, %d)
     addDNSCryptBind("127.0.0.1:%d", "%s", "DNSCryptResolver.cert", "DNSCryptResolver.key")
-    pc = newPacketCache(5, 86400, 1)
+    pc = newPacketCache(5, {maxTTL=86400, minTTL=1})
     getPool(""):setCache(pc)
     newServer{address="127.0.0.1:%s"}
     """
index 984c7d1e0856b79f9957e1a06c6f7a71dcff7343..87aa54bf1f5adf4d5a060ec562a9845faeab455f 100644 (file)
@@ -26,7 +26,7 @@ class TestTCPKeepAlive(DNSDistTest):
     setMaxTCPQueriesPerConnection(%s)
     setMaxTCPConnectionsPerClient(%s)
     setMaxTCPConnectionDuration(%s)
-    pc = newPacketCache(100, 86400, 1)
+    pc = newPacketCache(100, {maxTTL=86400, minTTL=1})
     getPool(""):setCache(pc)
     addAction("largernumberofconnections.tcpka.tests.powerdns.com.", SkipCacheAction())
     addAction("refused.tcpka.tests.powerdns.com.", RCodeAction(dnsdist.REFUSED))