File: dnsdist-lua-vars.cc

package info (click to toggle)
dnsdist 1.3.3-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,268 kB
  • sloc: cpp: 32,375; sh: 4,338; makefile: 356
file content (134 lines) | stat: -rw-r--r-- 5,854 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * This file is part of PowerDNS or dnsdist.
 * Copyright -- PowerDNS.COM B.V. and its contributors
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * In addition, for the avoidance of any doubt, permission is granted to
 * link this program with OpenSSL and to (re)distribute the binaries
 * produced as the result of such linking.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
#include "dnsdist.hh"
#include "ednsoptions.hh"

void setupLuaVars()
{
  g_lua.writeVariable("DNSAction", std::unordered_map<string,int>{
      {"Drop", (int)DNSAction::Action::Drop},
      {"Nxdomain", (int)DNSAction::Action::Nxdomain},
      {"Refused", (int)DNSAction::Action::Refused},
      {"Spoof", (int)DNSAction::Action::Spoof},
      {"Allow", (int)DNSAction::Action::Allow},
      {"HeaderModify", (int)DNSAction::Action::HeaderModify},
      {"Pool", (int)DNSAction::Action::Pool},
      {"None",(int)DNSAction::Action::None},
      {"NoOp",(int)DNSAction::Action::NoOp},
      {"Delay", (int)DNSAction::Action::Delay},
      {"Truncate", (int)DNSAction::Action::Truncate},
      {"ServFail", (int)DNSAction::Action::ServFail}
    });

  g_lua.writeVariable("DNSResponseAction", std::unordered_map<string,int>{
      {"Allow",        (int)DNSResponseAction::Action::Allow        },
      {"Delay",        (int)DNSResponseAction::Action::Delay        },
      {"Drop",         (int)DNSResponseAction::Action::Drop         },
      {"HeaderModify", (int)DNSResponseAction::Action::HeaderModify },
      {"ServFail",     (int)DNSResponseAction::Action::ServFail     },
      {"None",         (int)DNSResponseAction::Action::None         }
    });

  g_lua.writeVariable("DNSClass", std::unordered_map<string,int>{
      {"IN",    QClass::IN    },
      {"CHAOS", QClass::CHAOS },
      {"NONE",  QClass::NONE  },
      {"ANY",   QClass::ANY   }
    });

  g_lua.writeVariable("DNSOpcode", std::unordered_map<string,int>{
      {"Query",  Opcode::Query  },
      {"IQuery", Opcode::IQuery },
      {"Status", Opcode::Status },
      {"Notify", Opcode::Notify },
      {"Update", Opcode::Update }
    });

  g_lua.writeVariable("DNSSection", std::unordered_map<string,int>{
      {"Question",  0 },
      {"Answer",    1 },
      {"Authority", 2 },
      {"Additional",3 }
    });

  g_lua.writeVariable("EDNSOptionCode", std::unordered_map<string,int>{
      {"NSID",         EDNSOptionCode::NSID },
      {"DAU",          EDNSOptionCode::DAU },
      {"DHU",          EDNSOptionCode::DHU },
      {"N3U",          EDNSOptionCode::N3U },
      {"ECS",          EDNSOptionCode::ECS },
      {"EXPIRE",       EDNSOptionCode::EXPIRE },
      {"COOKIE",       EDNSOptionCode::COOKIE },
      {"TCPKEEPALIVE", EDNSOptionCode::TCPKEEPALIVE },
      {"PADDING",      EDNSOptionCode::PADDING },
      {"CHAIN",        EDNSOptionCode::CHAIN },
      {"KEYTAG",       EDNSOptionCode::KEYTAG }
    });

  vector<pair<string, int> > rcodes = {{"NOERROR",  RCode::NoError  },
                                       {"FORMERR",  RCode::FormErr  },
                                       {"SERVFAIL", RCode::ServFail },
                                       {"NXDOMAIN", RCode::NXDomain },
                                       {"NOTIMP",   RCode::NotImp   },
                                       {"REFUSED",  RCode::Refused  },
                                       {"YXDOMAIN", RCode::YXDomain },
                                       {"YXRRSET",  RCode::YXRRSet  },
                                       {"NXRRSET",  RCode::NXRRSet  },
                                       {"NOTAUTH",  RCode::NotAuth  },
                                       {"NOTZONE",  RCode::NotZone  },
                                       {"BADVERS",  ERCode::BADVERS },
                                       {"BADSIG",   ERCode::BADSIG  },
                                       {"BADKEY",   ERCode::BADKEY  },
                                       {"BADTIME",  ERCode::BADTIME   },
                                       {"BADMODE",  ERCode::BADMODE   },
                                       {"BADNAME",  ERCode::BADNAME   },
                                       {"BADALG",   ERCode::BADALG    },
                                       {"BADTRUNC", ERCode::BADTRUNC  },
                                       {"BADCOOKIE",ERCode::BADCOOKIE },
  };
  vector<pair<string, int> > dd;
  for(const auto& n : QType::names)
    dd.push_back({n.first, n.second});
  for(const auto& n : rcodes)
    dd.push_back({n.first, n.second});
  g_lua.writeVariable("dnsdist", dd);

#ifdef HAVE_DNSCRYPT
    g_lua.writeVariable("DNSCryptExchangeVersion", std::unordered_map<string,int>{
        { "VERSION1", DNSCryptExchangeVersion::VERSION1 },
        { "VERSION2", DNSCryptExchangeVersion::VERSION2 },
    });
#endif

  g_lua.writeVariable("EDNSOptionCode", std::unordered_map<string, uint8_t>{
      { "NSID", EDNSOptionCode::NSID },
      { "DAU", EDNSOptionCode::DAU },
      { "DHU", EDNSOptionCode::DHU },
      { "N3U", EDNSOptionCode::N3U },
      { "ECS", EDNSOptionCode::ECS },
      { "EXPIRE", EDNSOptionCode::EXPIRE },
      { "COOKIE", EDNSOptionCode::COOKIE },
      { "TCPKEEPALIVE", EDNSOptionCode::TCPKEEPALIVE },
      { "PADDING", EDNSOptionCode::PADDING },
      { "CHAIN", EDNSOptionCode::CHAIN }
    });
}