From: Remi Gacogne Date: Thu, 8 Dec 2022 08:43:42 +0000 (+0100) Subject: dnsdist: Add a few missing bindings and docs for the cache-inserted rules X-Git-Tag: dnsdist-1.8.0-rc1~171^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F12280%2Fhead;p=thirdparty%2Fpdns.git dnsdist: Add a few missing bindings and docs for the cache-inserted rules --- diff --git a/pdns/dnsdist-console.cc b/pdns/dnsdist-console.cc index 0dc0a94d47..472195d010 100644 --- a/pdns/dnsdist-console.cc +++ b/pdns/dnsdist-console.cc @@ -474,6 +474,7 @@ const std::vector g_consoleKeywords{ { "addDynBlockSMT", true, "names, message[, seconds [, action]]", "block the set of names with message `msg`, for `seconds` seconds (10 by default), applying `action` (default to the one set with `setDynBlocksAction()`)" }, { "addLocal", true, "addr [, {doTCP=true, reusePort=false, tcpFastOpenQueueSize=0, interface=\"\", cpus={}}]", "add `addr` to the list of addresses we listen on" }, { "addCacheHitResponseAction", true, "DNS rule, DNS response action [, {uuid=\"UUID\", name=\"name\"}}]", "add a cache hit response rule" }, + { "addCacheInsertedResponseAction", true, "DNS rule, DNS response action [, {uuid=\"UUID\", name=\"name\"}}]", "add a cache inserted response rule" }, { "addResponseAction", true, "DNS rule, DNS response action [, {uuid=\"UUID\", name=\"name\"}}]", "add a response rule" }, { "addSelfAnsweredResponseAction", true, "DNS rule, DNS response action [, {uuid=\"UUID\", name=\"name\"}}]", "add a self-answered response rule" }, { "addTLSLocal", true, "addr, certFile(s), keyFile(s) [,params]", "listen to incoming DNS over TLS queries on the specified address using the specified certificate (or list of) and key (or list of). The last parameter is a table" }, @@ -535,6 +536,7 @@ const std::vector g_consoleKeywords{ { "getServers", true, "", "returns a table with all defined servers" }, { "getStatisticsCounters", true, "", "returns a map of statistic counters" }, { "getTopCacheHitResponseRules", true, "[top]", "return the `top` cache-hit response rules" }, + { "getTopCacheInsertedResponseRules", true, "[top]", "return the `top` cache-inserted response rules" }, { "getTopResponseRules", true, "[top]", "return the `top` response rules" }, { "getTopRules", true, "[top]", "return the `top` rules" }, { "getTopSelfAnsweredResponseRules", true, "[top]", "return the `top` self-answered response rules" }, @@ -579,6 +581,8 @@ const std::vector g_consoleKeywords{ { "MaxQPSRule", true, "qps", "matches traffic **not** exceeding this qps limit" }, { "mvCacheHitResponseRule", true, "from, to", "move cache hit response rule 'from' to a position where it is in front of 'to'. 'to' can be one larger than the largest rule" }, { "mvCacheHitResponseRuleToTop", true, "", "move the last cache hit response rule to the first position" }, + { "mvCacheInsertedResponseRule", true, "from, to", "move cache inserted response rule 'from' to a position where it is in front of 'to'. 'to' can be one larger than the largest rule" }, + { "mvCacheInsertedResponseRuleToTop", true, "", "move the last cache inserted response rule to the first position" }, { "mvResponseRule", true, "from, to", "move response rule 'from' to a position where it is in front of 'to'. 'to' can be one larger than the largest rule" }, { "mvResponseRuleToTop", true, "", "move the last response rule to the first position" }, { "mvRule", true, "from, to", "move rule 'from' to a position where it is in front of 'to'. 'to' can be one larger than the largest rule, in which case the rule will be moved to the last position" }, @@ -640,6 +644,7 @@ const std::vector g_consoleKeywords{ { "requestTCPStatesDump", true, "", "Request a dump of the TCP states (incoming connections, outgoing connections) during the next scan. Useful for debugging purposes only" }, { "rmACL", true, "netmask", "remove netmask from ACL" }, { "rmCacheHitResponseRule", true, "id", "remove cache hit response rule in position 'id', or whose uuid matches if 'id' is an UUID string, or finally whose name matches if 'id' is a string but not a valid UUID" }, + { "rmCacheInsertedResponseRule", true, "id", "remove cache inserted response rule in position 'id', or whose uuid matches if 'id' is an UUID string, or finally whose name matches if 'id' is a string but not a valid UUID" }, { "rmResponseRule", true, "id", "remove response rule in position 'id', or whose uuid matches if 'id' is an UUID string, or finally whose name matches if 'id' is a string but not a valid UUID" }, { "rmRule", true, "id", "remove rule in position 'id', or whose uuid matches if 'id' is an UUID string, or finally whose name matches if 'id' is a string but not a valid UUID" }, { "rmSelfAnsweredResponseRule", true, "id", "remove self-answered response rule in position 'id', or whose uuid matches if 'id' is an UUID string, or finally whose name matches if 'id' is a string but not a valid UUID" }, @@ -773,6 +778,7 @@ const std::vector g_consoleKeywords{ { "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" }, { "topCacheHitResponseRules", true, "[top][, vars]", "show `top` cache-hit response rules" }, + { "topCacheInsertedResponseRules", true, "[top][, vars]", "show `top` cache-inserted response rules" }, { "topClients", true, "n", "show top-`n` clients sending the most queries over length of ringbuffer" }, { "topQueries", true, "n[, labels]", "show top 'n' queries, as grouped when optionally cut down to 'labels' labels" }, { "topResponses", true, "n, kind[, labels]", "show top 'n' responses with RCODE=kind (0=NO Error, 2=ServFail, 3=NXDomain), as grouped when optionally cut down to 'labels' labels" }, diff --git a/pdns/dnsdist-lua-rules.cc b/pdns/dnsdist-lua-rules.cc index 60ec310dd5..a234a3fd61 100644 --- a/pdns/dnsdist-lua-rules.cc +++ b/pdns/dnsdist-lua-rules.cc @@ -349,18 +349,30 @@ void setupLuaRules(LuaContext& luaCtx) return rulesToString(getTopRules(*rules, top.get_value_or(10)), vars); }); - luaCtx.writeFunction("getCacheHitResponseRules", [](boost::optional top) { + luaCtx.writeFunction("getTopCacheHitResponseRules", [](boost::optional top) { setLuaNoSideEffect(); auto rules = g_cachehitrespruleactions.getLocal(); return getTopRules(*rules, top.get_value_or(10)); }); - luaCtx.writeFunction("topCacheHitRules", [](boost::optional top, boost::optional vars) { + luaCtx.writeFunction("topCacheHitResponseRules", [](boost::optional top, boost::optional vars) { setLuaNoSideEffect(); auto rules = g_cachehitrespruleactions.getLocal(); return rulesToString(getTopRules(*rules, top.get_value_or(10)), vars); }); + luaCtx.writeFunction("getTopCacheInsertedResponseRules", [](boost::optional top) { + setLuaNoSideEffect(); + auto rules = g_cacheInsertedRespRuleActions.getLocal(); + return getTopRules(*rules, top.get_value_or(10)); + }); + + luaCtx.writeFunction("topCacheInsertedResponseRules", [](boost::optional top, boost::optional vars) { + setLuaNoSideEffect(); + auto rules = g_cacheInsertedRespRuleActions.getLocal(); + return rulesToString(getTopRules(*rules, top.get_value_or(10)), vars); + }); + luaCtx.writeFunction("getTopResponseRules", [](boost::optional top) { setLuaNoSideEffect(); auto rules = g_respruleactions.getLocal(); diff --git a/pdns/dnsdistdist/docs/reference/config.rst b/pdns/dnsdistdist/docs/reference/config.rst index 4cf1e7a1c6..828b83e230 100644 --- a/pdns/dnsdistdist/docs/reference/config.rst +++ b/pdns/dnsdistdist/docs/reference/config.rst @@ -1103,6 +1103,14 @@ Status, Statistics and More :param int top: How many response rules to return. +.. function:: getTopCacheInsertedResponseRules([top]) + + .. versionadded:: 1.8.0 + + Return the cache-inserted response rules that matched the most. + + :param int top: How many response rules to return. + .. function:: getTopResponseRules([top]) .. versionadded:: 1.6.0 @@ -1260,6 +1268,19 @@ Status, Statistics and More * ``showUUIDs=false``: bool - Whether to display the UUIDs, defaults to false. +.. function:: topCacheInsertedResponseRules([top [, options]]) + + .. versionadded:: 1.8.0 + + This function shows the cache-inserted response rules that matched the most. + + :param int top: How many rules to show. + :param table options: A table with key: value pairs with display options. + + Options: + + * ``showUUIDs=false``: bool - Whether to display the UUIDs, defaults to false. + .. function:: topClients([num]) Print the top ``num`` clients sending the most queries over length of ringbuffer