]>
Commit | Line | Data |
---|---|---|
cf48b0ce RG |
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 | ||
6bb38cd6 RG |
24 | class LuaAction : public DNSAction |
25 | { | |
26 | public: | |
0b3789ef | 27 | typedef std::function<std::tuple<int, boost::optional<string> >(DNSQuestion* dq)> func_t; |
41a33fa7 | 28 | LuaAction(const LuaAction::func_t& func) : d_func(func) |
6bb38cd6 | 29 | {} |
ac2ccb4e | 30 | Action operator()(DNSQuestion* dq, string* ruleresult) const override; |
6bb38cd6 RG |
31 | string toString() const override |
32 | { | |
33 | return "Lua script"; | |
34 | } | |
6bb38cd6 RG |
35 | private: |
36 | func_t d_func; | |
37 | }; | |
38 | ||
39 | class LuaResponseAction : public DNSResponseAction | |
40 | { | |
41 | public: | |
c134cbaa | 42 | typedef std::function<std::tuple<int, boost::optional<string> >(DNSResponse* dr)> func_t; |
41a33fa7 | 43 | LuaResponseAction(const LuaResponseAction::func_t& func) : d_func(func) |
6bb38cd6 | 44 | {} |
ac2ccb4e | 45 | Action operator()(DNSResponse* dr, string* ruleresult) const override; |
6bb38cd6 RG |
46 | string toString() const override |
47 | { | |
48 | return "Lua response script"; | |
49 | } | |
6bb38cd6 RG |
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 | }; | |
efd35aa8 | 79 | |
f850b032 | 80 | typedef boost::variant<string, vector<pair<int, string>>, std::shared_ptr<DNSRule>, DNSName, vector<pair<int, DNSName> > > luadnsrule_t; |
cf48b0ce | 81 | std::shared_ptr<DNSRule> makeRule(const luadnsrule_t& var); |
4d5959e6 | 82 | typedef std::unordered_map<std::string, boost::variant<std::string> > luaruleparams_t; |
f8a222ac | 83 | void parseRuleParams(boost::optional<luaruleparams_t> params, boost::uuids::uuid& uuid, uint64_t& creationOrder); |
6bb38cd6 RG |
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(); |