From 7d29457330af6bacf19a60529a05b923c888b650 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 8 Apr 2019 16:10:41 +0200 Subject: [PATCH] dnsdist: Switch to the new 'newPacketCache()' syntax for 1.4.0 --- pdns/dnsdist-lua-bindings.cc | 14 ++++- pdns/dnsdistdist/docs/reference/config.rst | 21 ++++--- pdns/dnsdistdist/docs/rules-actions.rst | 4 +- .../test_CacheHitResponses.py | 2 +- regression-tests.dnsdist/test_Caching.py | 58 +++++++------------ regression-tests.dnsdist/test_DNSCrypt.py | 2 +- regression-tests.dnsdist/test_TCPKeepAlive.py | 2 +- 7 files changed, 49 insertions(+), 54 deletions(-) diff --git a/pdns/dnsdist-lua-bindings.cc b/pdns/dnsdist-lua-bindings.cc index 6a8d64156d..b29fc3edf3 100644 --- a/pdns/dnsdist-lua-bindings.cc +++ b/pdns/dnsdist-lua-bindings.cc @@ -248,9 +248,18 @@ void setupLuaBindings(bool client) #endif /* HAVE_EBPF */ /* PacketCache */ - g_lua.writeFunction("newPacketCache", [](size_t maxEntries, boost::optional maxTTL, boost::optional minTTL, boost::optional tempFailTTL, boost::optional staleTTL, boost::optional dontAge, boost::optional numberOfShards, boost::optional deferrableInsertLock, boost::optional maxNegativeTTL, boost::optional ecsParsing, boost::optional>> vars) { + g_lua.writeFunction("newPacketCache", [](size_t maxEntries, boost::optional>> 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((*vars)["temporaryFailureTTL"]); } - } - auto res = std::make_shared(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(maxEntries, maxTTL, minTTL, tempFailTTL, maxNegativeTTL, staleTTL, dontAge, numberOfShards, deferrableInsertLock, ecsParsing); res->setKeepStaleData(keepStaleData); diff --git a/pdns/dnsdistdist/docs/reference/config.rst b/pdns/dnsdistdist/docs/reference/config.rst index 62604d792d..90bba6d37a 100644 --- a/pdns/dnsdistdist/docs/reference/config.rst +++ b/pdns/dnsdistdist/docs/reference/config.rst @@ -310,7 +310,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:: @@ -537,7 +537,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. @@ -545,11 +545,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 @@ -561,7 +559,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: @@ -608,7 +613,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. @@ -718,7 +723,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. diff --git a/pdns/dnsdistdist/docs/rules-actions.rst b/pdns/dnsdistdist/docs/rules-actions.rst index 1ed837dea2..ec23c155e3 100644 --- a/pdns/dnsdistdist/docs/rules-actions.rst +++ b/pdns/dnsdistdist/docs/rules-actions.rst @@ -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. diff --git a/regression-tests.dnsdist/test_CacheHitResponses.py b/regression-tests.dnsdist/test_CacheHitResponses.py index a6b8aafa6d..589372b3e9 100644 --- a/regression-tests.dnsdist/test_CacheHitResponses.py +++ b/regression-tests.dnsdist/test_CacheHitResponses.py @@ -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"} diff --git a/regression-tests.dnsdist/test_Caching.py b/regression-tests.dnsdist/test_Caching.py index aff1d2b6ee..60a898b65b 100644 --- a/regression-tests.dnsdist/test_Caching.py +++ b/regression-tests.dnsdist/test_Caching.py @@ -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, diff --git a/regression-tests.dnsdist/test_DNSCrypt.py b/regression-tests.dnsdist/test_DNSCrypt.py index 08a021029f..c1d59a4d5c 100644 --- a/regression-tests.dnsdist/test_DNSCrypt.py +++ b/regression-tests.dnsdist/test_DNSCrypt.py @@ -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"} """ diff --git a/regression-tests.dnsdist/test_TCPKeepAlive.py b/regression-tests.dnsdist/test_TCPKeepAlive.py index 984c7d1e08..87aa54bf1f 100644 --- a/regression-tests.dnsdist/test_TCPKeepAlive.py +++ b/regression-tests.dnsdist/test_TCPKeepAlive.py @@ -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)) -- 2.47.2