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.
26 boost::optional<bool> setAA{boost::none};
27 boost::optional<bool> setAD{boost::none};
28 boost::optional<bool> setRA{boost::none};
31 void setResponseHeadersFromConfig(dnsheader& dh, const ResponseConfig& config);
33 class LuaAction : public DNSAction
36 typedef std::function<std::tuple<int, boost::optional<string> >(DNSQuestion* dq)> func_t;
37 LuaAction(const LuaAction::func_t& func) : d_func(func)
39 Action operator()(DNSQuestion* dq, string* ruleresult) const override;
40 string toString() const override
48 class LuaResponseAction : public DNSResponseAction
51 typedef std::function<std::tuple<int, boost::optional<string> >(DNSResponse* dr)> func_t;
52 LuaResponseAction(const LuaResponseAction::func_t& func) : d_func(func)
54 Action operator()(DNSResponse* dr, string* ruleresult) const override;
55 string toString() const override
57 return "Lua response script";
63 class SpoofAction : public DNSAction
66 SpoofAction(const vector<ComboAddress>& addrs): d_addrs(addrs)
68 for (const auto& addr : d_addrs) {
70 d_types.insert(QType::A);
72 else if (addr.isIPv6()) {
73 d_types.insert(QType::AAAA);
77 if (!d_addrs.empty()) {
78 d_types.insert(QType::ANY);
82 SpoofAction(const DNSName& cname): d_cname(cname)
86 SpoofAction(const std::string& raw): d_rawResponse(raw)
90 DNSAction::Action operator()(DNSQuestion* dq, string* ruleresult) const override;
92 string toString() const override
94 string ret = "spoof in ";
95 if (!d_cname.empty()) {
96 ret += d_cname.toString() + " ";
98 else if (!d_rawResponse.empty()) {
102 for(const auto& a : d_addrs)
103 ret += a.toString()+" ";
109 ResponseConfig d_responseConfig;
111 std::vector<ComboAddress> d_addrs;
112 std::set<uint16_t> d_types;
113 std::string d_rawResponse;
117 typedef boost::variant<string, vector<pair<int, string>>, std::shared_ptr<DNSRule>, DNSName, vector<pair<int, DNSName> > > luadnsrule_t;
118 std::shared_ptr<DNSRule> makeRule(const luadnsrule_t& var);
119 typedef std::unordered_map<std::string, boost::variant<std::string> > luaruleparams_t;
120 void parseRuleParams(boost::optional<luaruleparams_t> params, boost::uuids::uuid& uuid, uint64_t& creationOrder);
122 typedef NetmaskTree<DynBlock> nmts_t;
124 vector<std::function<void(void)>> setupLua(bool client, bool configCheck, const std::string& config);
125 void setupLuaActions();
126 void setupLuaBindings(bool client);
127 void setupLuaBindingsDNSCrypt();
128 void setupLuaBindingsDNSQuestion();
129 void setupLuaBindingsKVS(bool client);
130 void setupLuaBindingsPacketCache();
131 void setupLuaBindingsProtoBuf(bool client, bool configCheck);
132 void setupLuaRules();
133 void setupLuaInspection();