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, boost::optional<string> >(DNSQuestion* dq)> func_t;
28 LuaAction(const LuaAction::func_t& func) : d_func(func)
30 Action operator()(DNSQuestion* dq, string* ruleresult) const override;
31 string toString() const override
39 class LuaResponseAction : public DNSResponseAction
42 typedef std::function<std::tuple<int, boost::optional<string> >(DNSResponse* dr)> func_t;
43 LuaResponseAction(const LuaResponseAction::func_t& func) : d_func(func)
45 Action operator()(DNSResponse* dr, string* ruleresult) const override;
46 string toString() const override
48 return "Lua response script";
54 class SpoofAction : public DNSAction
57 SpoofAction(const vector<ComboAddress>& addrs): d_addrs(addrs)
60 SpoofAction(const string& cname): d_cname(cname)
63 DNSAction::Action operator()(DNSQuestion* dq, string* ruleresult) const override;
64 string toString() const override
66 string ret = "spoof in ";
67 if(!d_cname.empty()) {
68 ret+=d_cname.toString()+ " ";
70 for(const auto& a : d_addrs)
71 ret += a.toString()+" ";
76 std::vector<ComboAddress> d_addrs;
80 typedef boost::variant<string, vector<pair<int, string>>, std::shared_ptr<DNSRule>, DNSName, vector<pair<int, DNSName> > > luadnsrule_t;
81 std::shared_ptr<DNSRule> makeRule(const luadnsrule_t& var);
82 typedef std::unordered_map<std::string, boost::variant<std::string> > luaruleparams_t;
83 void parseRuleParams(boost::optional<luaruleparams_t> params, boost::uuids::uuid& uuid, uint64_t& creationOrder);
85 typedef NetmaskTree<DynBlock> nmts_t;
87 void setupLuaActions();
88 void setupLuaBindings(bool client);
89 void setupLuaBindingsDNSQuestion();
91 void setupLuaInspection();