2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 class LuaAction : public DNSAction
27 typedef std::function<std::tuple<int, string>(DNSQuestion* dq)> func_t;
28 LuaAction(LuaAction::func_t func) : d_func(func)
31 Action operator()(DNSQuestion* dq, string* ruleresult) const override
33 std::lock_guard<std::mutex> lock(g_luamutex);
34 auto ret = d_func(dq);
36 *ruleresult=std::get<1>(ret);
37 return (Action)std::get<0>(ret);
40 string toString() const override
49 class LuaResponseAction : public DNSResponseAction
52 typedef std::function<std::tuple<int, string>(DNSResponse* dr)> func_t;
53 LuaResponseAction(LuaResponseAction::func_t func) : d_func(func)
56 Action operator()(DNSResponse* dr, string* ruleresult) const override
58 std::lock_guard<std::mutex> lock(g_luamutex);
59 auto ret = d_func(dr);
61 *ruleresult=std::get<1>(ret);
62 return (Action)std::get<0>(ret);
65 string toString() const override
67 return "Lua response script";
74 class SpoofAction : public DNSAction
77 SpoofAction(const vector<ComboAddress>& addrs): d_addrs(addrs)
80 SpoofAction(const string& cname): d_cname(cname)
83 DNSAction::Action operator()(DNSQuestion* dq, string* ruleresult) const override;
84 string toString() const override
86 string ret = "spoof in ";
87 if(!d_cname.empty()) {
88 ret+=d_cname.toString()+ " ";
90 for(const auto& a : d_addrs)
91 ret += a.toString()+" ";
96 std::vector<ComboAddress> d_addrs;
100 typedef boost::variant<string, vector<pair<int, string>>, std::shared_ptr<DNSRule>, DNSName, vector<pair<int, DNSName> > > luadnsrule_t;
101 std::shared_ptr<DNSRule> makeRule(const luadnsrule_t& var);
103 typedef NetmaskTree<DynBlock> nmts_t;
105 void setupLuaActions();
106 void setupLuaBindings(bool client);
107 void setupLuaBindingsDNSQuestion();
108 void setupLuaRules();
109 void setupLuaInspection();