]>
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 | ||
77d574ac OM |
24 | #include <random> |
25 | ||
d545a872 RG |
26 | struct ResponseConfig |
27 | { | |
28 | boost::optional<bool> setAA{boost::none}; | |
29 | boost::optional<bool> setAD{boost::none}; | |
30 | boost::optional<bool> setRA{boost::none}; | |
202c4ab9 | 31 | uint32_t ttl{60}; |
d545a872 RG |
32 | }; |
33 | void setResponseHeadersFromConfig(dnsheader& dh, const ResponseConfig& config); | |
34 | ||
6bb38cd6 RG |
35 | class SpoofAction : public DNSAction |
36 | { | |
37 | public: | |
38 | SpoofAction(const vector<ComboAddress>& addrs): d_addrs(addrs) | |
39 | { | |
202c4ab9 RG |
40 | for (const auto& addr : d_addrs) { |
41 | if (addr.isIPv4()) { | |
42 | d_types.insert(QType::A); | |
43 | } | |
44 | else if (addr.isIPv6()) { | |
45 | d_types.insert(QType::AAAA); | |
46 | } | |
47 | } | |
48 | ||
49 | if (!d_addrs.empty()) { | |
50 | d_types.insert(QType::ANY); | |
51 | } | |
6bb38cd6 | 52 | } |
202c4ab9 RG |
53 | |
54 | SpoofAction(const DNSName& cname): d_cname(cname) | |
6bb38cd6 RG |
55 | { |
56 | } | |
202c4ab9 RG |
57 | |
58 | SpoofAction(const std::string& raw): d_rawResponse(raw) | |
59 | { | |
60 | } | |
61 | ||
6bb38cd6 | 62 | DNSAction::Action operator()(DNSQuestion* dq, string* ruleresult) const override; |
202c4ab9 | 63 | |
6bb38cd6 RG |
64 | string toString() const override |
65 | { | |
66 | string ret = "spoof in "; | |
202c4ab9 RG |
67 | if (!d_cname.empty()) { |
68 | ret += d_cname.toString() + " "; | |
69 | } | |
70 | else if (!d_rawResponse.empty()) { | |
71 | ret += "raw bytes "; | |
72 | } | |
73 | else { | |
6bb38cd6 RG |
74 | for(const auto& a : d_addrs) |
75 | ret += a.toString()+" "; | |
76 | } | |
77 | return ret; | |
78 | } | |
955b9377 | 79 | |
955b9377 | 80 | |
d545a872 | 81 | ResponseConfig d_responseConfig; |
6bb38cd6 | 82 | private: |
77d574ac | 83 | static thread_local std::default_random_engine t_randomEngine; |
6bb38cd6 | 84 | std::vector<ComboAddress> d_addrs; |
202c4ab9 RG |
85 | std::set<uint16_t> d_types; |
86 | std::string d_rawResponse; | |
6bb38cd6 RG |
87 | DNSName d_cname; |
88 | }; | |
efd35aa8 | 89 | |
f850b032 | 90 | typedef boost::variant<string, vector<pair<int, string>>, std::shared_ptr<DNSRule>, DNSName, vector<pair<int, DNSName> > > luadnsrule_t; |
cf48b0ce | 91 | std::shared_ptr<DNSRule> makeRule(const luadnsrule_t& var); |
4d5959e6 | 92 | typedef std::unordered_map<std::string, boost::variant<std::string> > luaruleparams_t; |
f8a222ac | 93 | void parseRuleParams(boost::optional<luaruleparams_t> params, boost::uuids::uuid& uuid, uint64_t& creationOrder); |
6bb38cd6 RG |
94 | |
95 | typedef NetmaskTree<DynBlock> nmts_t; | |
96 | ||
203b5348 | 97 | vector<std::function<void(void)>> setupLua(bool client, bool configCheck, const std::string& config); |
6bb38cd6 RG |
98 | void setupLuaActions(); |
99 | void setupLuaBindings(bool client); | |
4d4d5623 | 100 | void setupLuaBindingsDNSCrypt(); |
6bb38cd6 | 101 | void setupLuaBindingsDNSQuestion(); |
4d4d5623 RG |
102 | void setupLuaBindingsKVS(bool client); |
103 | void setupLuaBindingsPacketCache(); | |
203b5348 | 104 | void setupLuaBindingsProtoBuf(bool client, bool configCheck); |
6bb38cd6 RG |
105 | void setupLuaRules(); |
106 | void setupLuaInspection(); | |
107 | void setupLuaVars(); |