From: Chris Hofstaedtler Date: Fri, 19 Jan 2018 22:32:46 +0000 (+0100) Subject: add uuid= option to addLua*Action, mirroring add*Action X-Git-Tag: dnsdist-1.3.0~144^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e33e53fc97ad03d88ecd058e875fa2c1bc1a0c9f;p=pdns add uuid= option to addLua*Action, mirroring add*Action --- diff --git a/pdns/dnsdist-console.cc b/pdns/dnsdist-console.cc index bb765f579..b221f8d25 100644 --- a/pdns/dnsdist-console.cc +++ b/pdns/dnsdist-console.cc @@ -288,8 +288,8 @@ const std::vector g_consoleKeywords{ { "addDNSCryptBind", true, "\"127.0.0.1:8443\", \"provider name\", \"/path/to/resolver.cert\", \"/path/to/resolver.key\", {reusePort=false, tcpFastOpenSize=0, interface=\"\", cpus={}}", "listen to incoming DNSCrypt queries on 127.0.0.1 port 8443, with a provider name of `provider name`, using a resolver certificate and associated key stored respectively in the `resolver.cert` and `resolver.key` files. The fifth optional parameter is a table of parameters" }, { "addDynBlocks", true, "addresses, message[, seconds[, action]]", "block the set of addresses 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, tcpFastOpenSize=0, interface=\"\", cpus={}}]", "add `addr` to the list of addresses we listen on" }, - { "addLuaAction", true, "x, func", "where 'x' is all the combinations from `addAction`, and func is a function with the parameter `dq`, which returns an action to be taken on this packet. Good for rare packets but where you want to do a lot of processing" }, - { "addLuaResponseAction", true, "x, func", "where 'x' is all the combinations from `addAction`, and func is a function with the parameter `dr`, which returns an action to be taken on this response packet. Good for rare packets but where you want to do a lot of processing" }, + { "addLuaAction", true, "x, func [, {uuid=\"UUID\"}]", "where 'x' is all the combinations from `addAction`, and func is a function with the parameter `dq`, which returns an action to be taken on this packet. Good for rare packets but where you want to do a lot of processing" }, + { "addLuaResponseAction", true, "x, func [, {uuid=\"UUID\"}]", "where 'x' is all the combinations from `addAction`, and func is a function with the parameter `dr`, which returns an action to be taken on this response packet. Good for rare packets but where you want to do a lot of processing" }, { "addCacheHitResponseAction", true, "DNS rule, DNS response action [, {uuid=\"UUID\"}]", "add a cache hit response rule" }, { "addResponseAction", true, "DNS rule, DNS response action [, {uuid=\"UUID\"}]", "add a response rule" }, { "addTLSLocal", true, "addr, certFile, keyFile[,params]", "listen to incoming DNS over TLS queries on the specified address using the specified certificate and key. The last parameter is a table" }, diff --git a/pdns/dnsdist-lua-actions.cc b/pdns/dnsdist-lua-actions.cc index ed1cbea7e..abc618a8a 100644 --- a/pdns/dnsdist-lua-actions.cc +++ b/pdns/dnsdist-lua-actions.cc @@ -835,25 +835,27 @@ void setupLuaActions() }); }); - g_lua.writeFunction("addLuaAction", [](luadnsrule_t var, LuaAction::func_t func) { + g_lua.writeFunction("addLuaAction", [](luadnsrule_t var, LuaAction::func_t func, boost::optional params) { setLuaSideEffect(); + + boost::uuids::uuid uuid; + parseRuleParams(params, uuid); + auto rule=makeRule(var); - g_rulactions.modify([rule,func](decltype(g_rulactions)::value_type& rulactions){ - rulactions.push_back({ - rule, - std::make_shared(func), - t_uuidGenerator() }); + g_rulactions.modify([rule, func, uuid](decltype(g_rulactions)::value_type& rulactions){ + rulactions.push_back({rule, std::make_shared(func), uuid}); }); }); - g_lua.writeFunction("addLuaResponseAction", [](luadnsrule_t var, LuaResponseAction::func_t func) { + g_lua.writeFunction("addLuaResponseAction", [](luadnsrule_t var, LuaResponseAction::func_t func, boost::optional params) { setLuaSideEffect(); + + boost::uuids::uuid uuid; + parseRuleParams(params, uuid); + auto rule=makeRule(var); - g_resprulactions.modify([rule,func](decltype(g_resprulactions)::value_type& rulactions){ - rulactions.push_back({ - rule, - std::make_shared(func), - t_uuidGenerator() }); + g_resprulactions.modify([rule, func, uuid](decltype(g_resprulactions)::value_type& rulactions){ + rulactions.push_back({rule, std::make_shared(func), uuid}); }); }); diff --git a/pdns/dnsdistdist/docs/rules-actions.rst b/pdns/dnsdistdist/docs/rules-actions.rst index da0c31de2..3f4168b4a 100644 --- a/pdns/dnsdistdist/docs/rules-actions.rst +++ b/pdns/dnsdistdist/docs/rules-actions.rst @@ -143,17 +143,27 @@ Rule Generators :param string domain: Domain name to spoof for :param string cname: Domain name to add CNAME to -.. function:: addLuaAction(DNSrule, function) +.. function:: addLuaAction(DNSrule, function [, options]) + + .. versionchanged:: 1.3.0 + Added the optional parameter ``options``. Invoke a Lua function that accepts a :class:`DNSQuestion`. This function works similar to using :func:`LuaAction`. - The ``function`` should return a :ref:`DNSAction`. :param DNSRule: match queries based on this rule :param string function: the name of a Lua function + :param table options: A table with key: value pairs with options. + + Options: + + * ``uuid``: string - UUID to assign to the new rule. By default a random UUID is generated for each rule. -.. function:: addLuaResponseAction(DNSrule, function) +.. function:: addLuaResponseAction(DNSrule, function [, options]) + + .. versionchanged:: 1.3.0 + Added the optional parameter ``options``. Invoke a Lua function that accepts a :class:`DNSQuestion` on the response. This function works similar to using :func:`LuaAction`. @@ -162,6 +172,11 @@ Rule Generators :param DNSRule: match queries based on this rule :param string function: the name of a Lua function + :param table options: A table with key: value pairs with options. + + Options: + + * ``uuid``: string - UUID to assign to the new rule. By default a random UUID is generated for each rule. .. function:: addNoRecurseRule(DNSrule)