]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dnsdist-lua.hh
Add some notes explaining why some validations are not relevant in the dnstap case.
[thirdparty/pdns.git] / pdns / dnsdist-lua.hh
1 /*
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
4 *
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.
8 *
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.
12 *
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.
17 *
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.
21 */
22 #pragma once
23
24 class LuaAction : public DNSAction
25 {
26 public:
27 typedef std::function<std::tuple<int, boost::optional<string> >(DNSQuestion* dq)> func_t;
28 LuaAction(const LuaAction::func_t& func) : d_func(func)
29 {}
30 Action operator()(DNSQuestion* dq, string* ruleresult) const override;
31 string toString() const override
32 {
33 return "Lua script";
34 }
35 private:
36 func_t d_func;
37 };
38
39 class LuaResponseAction : public DNSResponseAction
40 {
41 public:
42 typedef std::function<std::tuple<int, boost::optional<string> >(DNSResponse* dr)> func_t;
43 LuaResponseAction(const LuaResponseAction::func_t& func) : d_func(func)
44 {}
45 Action operator()(DNSResponse* dr, string* ruleresult) const override;
46 string toString() const override
47 {
48 return "Lua response script";
49 }
50 private:
51 func_t d_func;
52 };
53
54 class SpoofAction : public DNSAction
55 {
56 public:
57 SpoofAction(const vector<ComboAddress>& addrs): d_addrs(addrs)
58 {
59 }
60 SpoofAction(const string& cname): d_cname(cname)
61 {
62 }
63 DNSAction::Action operator()(DNSQuestion* dq, string* ruleresult) const override;
64 string toString() const override
65 {
66 string ret = "spoof in ";
67 if(!d_cname.empty()) {
68 ret+=d_cname.toString()+ " ";
69 } else {
70 for(const auto& a : d_addrs)
71 ret += a.toString()+" ";
72 }
73 return ret;
74 }
75 private:
76 std::vector<ComboAddress> d_addrs;
77 DNSName d_cname;
78 };
79
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);
84
85 typedef NetmaskTree<DynBlock> nmts_t;
86
87 void setupLuaActions();
88 void setupLuaBindings(bool client);
89 void setupLuaBindingsDNSQuestion();
90 void setupLuaRules();
91 void setupLuaInspection();
92 void setupLuaVars();