]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dnsdist-lua-vars.cc
Merge pull request #9229 from rgacogne/dnsdist-webserver-allow-from
[thirdparty/pdns.git] / pdns / dnsdist-lua-vars.cc
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 #include "dnsdist.hh"
23 #include "dnsdist-lua.hh"
24 #include "ednsoptions.hh"
25
26 #undef BADSIG // signal.h SIG_ERR
27
28 void setupLuaVars()
29 {
30 g_lua.writeVariable("DNSAction", std::unordered_map<string,int>{
31 {"Drop", (int)DNSAction::Action::Drop},
32 {"Nxdomain", (int)DNSAction::Action::Nxdomain},
33 {"Refused", (int)DNSAction::Action::Refused},
34 {"Spoof", (int)DNSAction::Action::Spoof},
35 {"SpoofRaw", (int)DNSAction::Action::SpoofRaw},
36 {"Allow", (int)DNSAction::Action::Allow},
37 {"HeaderModify", (int)DNSAction::Action::HeaderModify},
38 {"Pool", (int)DNSAction::Action::Pool},
39 {"None",(int)DNSAction::Action::None},
40 {"NoOp",(int)DNSAction::Action::NoOp},
41 {"Delay", (int)DNSAction::Action::Delay},
42 {"Truncate", (int)DNSAction::Action::Truncate},
43 {"ServFail", (int)DNSAction::Action::ServFail},
44 {"NoRecurse", (int)DNSAction::Action::NoRecurse}
45 });
46
47 g_lua.writeVariable("DNSResponseAction", std::unordered_map<string,int>{
48 {"Allow", (int)DNSResponseAction::Action::Allow },
49 {"Delay", (int)DNSResponseAction::Action::Delay },
50 {"Drop", (int)DNSResponseAction::Action::Drop },
51 {"HeaderModify", (int)DNSResponseAction::Action::HeaderModify },
52 {"ServFail", (int)DNSResponseAction::Action::ServFail },
53 {"None", (int)DNSResponseAction::Action::None }
54 });
55
56 g_lua.writeVariable("DNSClass", std::unordered_map<string,int>{
57 {"IN", QClass::IN },
58 {"CHAOS", QClass::CHAOS },
59 {"NONE", QClass::NONE },
60 {"ANY", QClass::ANY }
61 });
62
63 g_lua.writeVariable("DNSOpcode", std::unordered_map<string,int>{
64 {"Query", Opcode::Query },
65 {"IQuery", Opcode::IQuery },
66 {"Status", Opcode::Status },
67 {"Notify", Opcode::Notify },
68 {"Update", Opcode::Update }
69 });
70
71 g_lua.writeVariable("DNSSection", std::unordered_map<string,int>{
72 {"Question", 0 },
73 {"Answer", 1 },
74 {"Authority", 2 },
75 {"Additional",3 }
76 });
77
78 g_lua.writeVariable("EDNSOptionCode", std::unordered_map<string,int>{
79 {"NSID", EDNSOptionCode::NSID },
80 {"DAU", EDNSOptionCode::DAU },
81 {"DHU", EDNSOptionCode::DHU },
82 {"N3U", EDNSOptionCode::N3U },
83 {"ECS", EDNSOptionCode::ECS },
84 {"EXPIRE", EDNSOptionCode::EXPIRE },
85 {"COOKIE", EDNSOptionCode::COOKIE },
86 {"TCPKEEPALIVE", EDNSOptionCode::TCPKEEPALIVE },
87 {"PADDING", EDNSOptionCode::PADDING },
88 {"CHAIN", EDNSOptionCode::CHAIN },
89 {"KEYTAG", EDNSOptionCode::KEYTAG }
90 });
91
92 g_lua.writeVariable("DNSRCode", std::unordered_map<string, int>{
93 {"NOERROR", RCode::NoError },
94 {"FORMERR", RCode::FormErr },
95 {"SERVFAIL", RCode::ServFail },
96 {"NXDOMAIN", RCode::NXDomain },
97 {"NOTIMP", RCode::NotImp },
98 {"REFUSED", RCode::Refused },
99 {"YXDOMAIN", RCode::YXDomain },
100 {"YXRRSET", RCode::YXRRSet },
101 {"NXRRSET", RCode::NXRRSet },
102 {"NOTAUTH", RCode::NotAuth },
103 {"NOTZONE", RCode::NotZone },
104 {"BADVERS", ERCode::BADVERS },
105 {"BADSIG", ERCode::BADSIG },
106 {"BADKEY", ERCode::BADKEY },
107 {"BADTIME", ERCode::BADTIME },
108 {"BADMODE", ERCode::BADMODE },
109 {"BADNAME", ERCode::BADNAME },
110 {"BADALG", ERCode::BADALG },
111 {"BADTRUNC", ERCode::BADTRUNC },
112 {"BADCOOKIE",ERCode::BADCOOKIE }
113 });
114
115 vector<pair<string, int> > dd;
116 for(const auto& n : QType::names)
117 dd.push_back({n.first, n.second});
118 g_lua.writeVariable("DNSQType", dd);
119
120 g_lua.executeCode(R"LUA(
121 local tables = {
122 DNSQType = DNSQType,
123 DNSRCode = DNSRCode
124 }
125 local function index (table, key)
126 for tname,t in pairs(tables)
127 do
128 local val = t[key]
129 if val then
130 warnlog(string.format("access to dnsdist.%s is deprecated, please use %s.%s", key, tname, key))
131 return val
132 end
133 end
134 end
135
136 dnsdist = {}
137 setmetatable(dnsdist, { __index = index })
138 )LUA"
139 );
140
141 #ifdef HAVE_DNSCRYPT
142 g_lua.writeVariable("DNSCryptExchangeVersion", std::unordered_map<string,int>{
143 { "VERSION1", DNSCryptExchangeVersion::VERSION1 },
144 { "VERSION2", DNSCryptExchangeVersion::VERSION2 },
145 });
146 #endif
147 }