From f186603d78cf475a410655a6065b7dadc8fc1526 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 24 May 2017 09:10:45 +0100 Subject: [PATCH] dnsdist: Print useful messages when query and response actions are mixed --- pdns/dnsdist-lua.cc | 7 ++++++- pdns/dnsdist-lua2.cc | 20 +++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 47510a362..3f494f825 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -991,8 +991,13 @@ vector> setupLua(bool client, const std::string& confi return std::shared_ptr(new RCodeRule(rcode)); }); - g_lua.writeFunction("addAction", [](luadnsrule_t var, std::shared_ptr ea) + g_lua.writeFunction("addAction", [](luadnsrule_t var, boost::variant, std::shared_ptr > era) { + if (era.type() == typeid(std::shared_ptr)) { + throw std::runtime_error("addAction() can only be called with query-related actions, not response-related ones. Are you looking for addResponseAction()?"); + } + + auto ea = *boost::get>(&era); setLuaSideEffect(); auto rule=makeRule(var); g_rulactions.modify([rule, ea](decltype(g_rulactions)::value_type& rulactions){ diff --git a/pdns/dnsdist-lua2.cc b/pdns/dnsdist-lua2.cc index 89276ec9b..cd3cf50a9 100644 --- a/pdns/dnsdist-lua2.cc +++ b/pdns/dnsdist-lua2.cc @@ -826,13 +826,19 @@ void moreLua(bool client) g_lua.registerFunction("getStats", &DNSAction::getStats); - g_lua.writeFunction("addResponseAction", [](luadnsrule_t var, std::shared_ptr ea) { - setLuaSideEffect(); - auto rule=makeRule(var); - g_resprulactions.modify([rule, ea](decltype(g_resprulactions)::value_type& rulactions){ - rulactions.push_back({rule, ea}); - }); - }); + g_lua.writeFunction("addResponseAction", [](luadnsrule_t var, boost::variant, std::shared_ptr > era) { + if (era.type() == typeid(std::shared_ptr)) { + throw std::runtime_error("addResponseAction() can only be called with response-related actions, not query-related ones. Are you looking for addAction()?"); + } + + auto ea = *boost::get>(&era); + + setLuaSideEffect(); + auto rule=makeRule(var); + g_resprulactions.modify([rule, ea](decltype(g_resprulactions)::value_type& rulactions){ + rulactions.push_back({rule, ea}); + }); + }); g_lua.writeFunction("showResponseRules", []() { setLuaNoSideEffect(); -- 2.40.0