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