From ac2ccb4e7d26e8942bec1ff9a8ca6c11861850d2 Mon Sep 17 00:00:00 2001 From: Chris Hofstaedtler Date: Tue, 20 Feb 2018 10:29:26 +0100 Subject: [PATCH] dnsdist: Move Lua(Response)Action operator() out of header file --- pdns/dnsdist-lua-actions.cc | 32 +++++++++++++++++++++++++++++ pdns/dnsdist-lua.hh | 40 ++----------------------------------- 2 files changed, 34 insertions(+), 38 deletions(-) diff --git a/pdns/dnsdist-lua-actions.cc b/pdns/dnsdist-lua-actions.cc index 8d25ae874..4be1d0302 100644 --- a/pdns/dnsdist-lua-actions.cc +++ b/pdns/dnsdist-lua-actions.cc @@ -306,6 +306,38 @@ public: } }; +DNSAction::Action LuaAction::operator()(DNSQuestion* dq, string* ruleresult) const +{ + std::lock_guard lock(g_luamutex); + try { + auto ret = d_func(dq); + if(ruleresult) + *ruleresult=std::get<1>(ret); + return (Action)std::get<0>(ret); + } catch (std::exception &e) { + warnlog("LuaAction failed inside lua, returning ServFail: %s", e.what()); + } catch (...) { + warnlog("LuaAction failed inside lua, returning ServFail: [unknown exception]"); + } + return DNSAction::Action::ServFail; +} + +DNSResponseAction::Action LuaResponseAction::operator()(DNSResponse* dr, string* ruleresult) const +{ + std::lock_guard lock(g_luamutex); + try { + auto ret = d_func(dr); + if(ruleresult) + *ruleresult=std::get<1>(ret); + return (Action)std::get<0>(ret); + } catch (std::exception &e) { + warnlog("LuaResponseAction failed inside lua, returning ServFail: %s", e.what()); + } catch (...) { + warnlog("LuaResponseAction failed inside lua, returning ServFail: [unknown exception]"); + } + return DNSResponseAction::Action::ServFail; +} + DNSAction::Action SpoofAction::operator()(DNSQuestion* dq, string* ruleresult) const { uint16_t qtype = dq->qtype; diff --git a/pdns/dnsdist-lua.hh b/pdns/dnsdist-lua.hh index 497519166..5c7d73c1d 100644 --- a/pdns/dnsdist-lua.hh +++ b/pdns/dnsdist-lua.hh @@ -21,36 +21,17 @@ */ #pragma once -#include "dolog.hh" - class LuaAction : public DNSAction { public: typedef std::function(DNSQuestion* dq)> func_t; LuaAction(LuaAction::func_t func) : d_func(func) {} - - Action operator()(DNSQuestion* dq, string* ruleresult) const override - { - std::lock_guard lock(g_luamutex); - try { - auto ret = d_func(dq); - if(ruleresult) - *ruleresult=std::get<1>(ret); - return (Action)std::get<0>(ret); - } catch (std::exception &e) { - warnlog("LuaAction failed inside lua, returning ServFail: %s", e.what()); - } catch (...) { - warnlog("LuaAction failed inside lua, returning ServFail: [unknown exception]"); - } - return DNSAction::Action::ServFail; - } - + Action operator()(DNSQuestion* dq, string* ruleresult) const override; string toString() const override { return "Lua script"; } - private: func_t d_func; }; @@ -61,28 +42,11 @@ public: typedef std::function(DNSResponse* dr)> func_t; LuaResponseAction(LuaResponseAction::func_t func) : d_func(func) {} - - Action operator()(DNSResponse* dr, string* ruleresult) const override - { - std::lock_guard lock(g_luamutex); - try { - auto ret = d_func(dr); - if(ruleresult) - *ruleresult=std::get<1>(ret); - return (Action)std::get<0>(ret); - } catch (std::exception &e) { - warnlog("LuaResponseAction failed inside lua, returning ServFail: %s", e.what()); - } catch (...) { - warnlog("LuaResponseAction failed inside lua, returning ServFail: [unknown exception]"); - } - return DNSResponseAction::Action::ServFail; - } - + Action operator()(DNSResponse* dr, string* ruleresult) const override; string toString() const override { return "Lua response script"; } - private: func_t d_func; }; -- 2.40.0