From 4d2c96adac5e6af39cbe8fc6a9f4d9d38b8754e7 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 13 Sep 2017 11:33:19 +0200 Subject: [PATCH] dnsdist: Add missing QPSAction In 1.2.0 we deprecated the `addQPSLimit()` function, suggesting the use of `QPSAction()` as a replacement, but the Lua binding for `QPSAction()` was missing. In addition the documenration was referring to `QPSLimitAction()` instead of `QPSAction()`. (cherry picked from commit 8499caafb7eeedd63e0e7db6c79dbbcbe1def320) --- pdns/dnsdist-lua.cc | 4 ++++ pdns/dnsdistdist/docs/rules-actions.rst | 15 +++++++++++---- regression-tests.dnsdist/test_Advanced.py | 4 ++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 799c10eb1..9308cc55e 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -788,6 +788,10 @@ vector> setupLua(bool client, const std::string& confi return std::shared_ptr(new PoolAction(a)); }); + g_lua.writeFunction("QPSAction", [](int limit) { + return std::shared_ptr(new QPSAction(limit)); + }); + g_lua.writeFunction("QPSPoolAction", [](int limit, const string& a) { return std::shared_ptr(new QPSPoolAction(limit, a)); }); diff --git a/pdns/dnsdistdist/docs/rules-actions.rst b/pdns/dnsdistdist/docs/rules-actions.rst index 1e32776da..873570ef0 100644 --- a/pdns/dnsdistdist/docs/rules-actions.rst +++ b/pdns/dnsdistdist/docs/rules-actions.rst @@ -198,7 +198,7 @@ Rule Generators All queries over the limit are dropped. This function is deprecated as of 1.2.0 and will be removed in 1.3.0, please use: - addAction(DNSRule, QPSLimitAction(limit)) + addAction(DNSRule, QPSAction(limit)) :param DNSRule: match queries based on this rule :param int limit: QPS limit for this rule @@ -222,9 +222,9 @@ Managing Rules Active Rules can be shown with :func:`showRules` and removed with :func:`rmRule`:: - > addAction("h4xorbooter.xyz.", QPSLimitAction(10)) - > addAction({"130.161.0.0/16", "145.14.0.0/16"} , QPSLimitAction(20)) - > addAction({"nl.", "be."}, QPSLimitAction(1)) + > addAction("h4xorbooter.xyz.", QPSAction(10)) + > addAction({"130.161.0.0/16", "145.14.0.0/16"} , QPSAction(20)) + > addAction({"nl.", "be."}, QPSAction(1)) > showRules() # Matches Rule Action 0 0 h4xorbooter.xyz. qps limit to 10 @@ -659,6 +659,13 @@ The following actions exist. :param string poolname: The name of the pool +.. function:: QPSAction(maxqps) + + Drop a packet if it does exceed the ``maxqps`` queries per second limits. + Letting the subsequent rules apply otherwise. + + :param int maxqps: The QPS limit + .. function:: QPSPoolAction(maxqps, poolname) Send the packet into the specified pool only if it does not exceed the ``maxqps`` queries per second limits. diff --git a/regression-tests.dnsdist/test_Advanced.py b/regression-tests.dnsdist/test_Advanced.py index 7864d8d3c..9fbb1b877 100644 --- a/regression-tests.dnsdist/test_Advanced.py +++ b/regression-tests.dnsdist/test_Advanced.py @@ -921,7 +921,7 @@ class TestAdvancedRestoreFlagsOnSelfResponse(DNSDistTest): class TestAdvancedQPS(DNSDistTest): _config_template = """ - addQPSLimit("qps.advanced.tests.powerdns.com", 10) + addAction("qps.advanced.tests.powerdns.com", QPSAction(10)) newServer{address="127.0.0.1:%s"} """ @@ -969,7 +969,7 @@ class TestAdvancedQPS(DNSDistTest): class TestAdvancedQPSNone(DNSDistTest): _config_template = """ - addQPSLimit("qpsnone.advanced.tests.powerdns.com", 100) + addAction("qpsnone.advanced.tests.powerdns.com", QPSAction(100)) addAction(AllRule(), RCodeAction(dnsdist.REFUSED)) newServer{address="127.0.0.1:%s"} """ -- 2.40.0