• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PowerDNS / pdns / 18837422702

27 Oct 2025 10:15AM UTC coverage: 73.025% (+0.02%) from 73.004%
18837422702

Pull #16375

github

web-flow
Merge 2f23fc90d into 82ea647b4
Pull Request #16375: dnsdist: Include a Date: response header for rejected HTTP1 requests

38279 of 63122 branches covered (60.64%)

Branch coverage included in aggregate %.

0 of 11 new or added lines in 1 file covered. (0.0%)

10680 existing lines in 98 files now uncovered.

127481 of 163870 relevant lines covered (77.79%)

5384548.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.16
/pdns/dnsdistdist/dnsdist-lua.hh
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

24
#include "dolog.hh"
25
#include "dnsdist.hh"
26

27
#include "ext/luawrapper/include/LuaContext.hpp"
28

29
extern RecursiveLockGuarded<LuaContext> g_lua;
30
extern std::string g_outputBuffer; // locking for this is ok, as locked by g_luamutex
31

32
template <class T>
33
using LuaArray = std::vector<std::pair<int, T>>;
34
template <class T>
35
using LuaAssociativeTable = std::unordered_map<std::string, T>;
36
template <class T>
37
using LuaTypeOrArrayOf = boost::variant<T, LuaArray<T>>;
38

39
using luaruleparams_t = LuaAssociativeTable<std::string>;
40

41
using luadnsrule_t = boost::variant<string, LuaArray<std::string>, std::shared_ptr<DNSRule>, DNSName, LuaArray<DNSName>>;
42
std::shared_ptr<DNSRule> makeRule(const luadnsrule_t& var, const std::string& calledFrom);
43

44
void parseRuleParams(boost::optional<luaruleparams_t>& params, boost::uuids::uuid& uuid, std::string& name, uint64_t& creationOrder);
45
void checkParameterBound(const std::string& parameter, uint64_t value, uint64_t max = std::numeric_limits<uint16_t>::max());
46

47
void setupLua(LuaContext& luaCtx, bool client, bool configCheck, const std::string& config);
48
void setupLuaActions(LuaContext& luaCtx);
49
void setupLuaBindings(LuaContext& luaCtx, bool client, bool configCheck);
50
void setupLuaBindingsDNSCrypt(LuaContext& luaCtx, bool client);
51
void setupLuaBindingsDNSParser(LuaContext& luaCtx);
52
void setupLuaBindingsDNSQuestion(LuaContext& luaCtx);
53
void setupLuaBindingsKVS(LuaContext& luaCtx, bool client);
54
void setupLuaBindingsLogging(LuaContext& luaCtx);
55
void setupLuaBindingsNetwork(LuaContext& luaCtx, bool client);
56
void setupLuaBindingsPacketCache(LuaContext& luaCtx, bool client);
57
void setupLuaBindingsProtoBuf(LuaContext& luaCtx, bool client, bool configCheck);
58
void setupLuaBindingsRings(LuaContext& luaCtx, bool client);
59
void setupLuaRules(LuaContext& luaCtx);
60
void setupLuaInspection(LuaContext& luaCtx);
61
void setupLuaVars(LuaContext& luaCtx);
62
void setupLuaWeb(LuaContext& luaCtx);
63
void setupLuaLoadBalancingContext(LuaContext& luaCtx);
64

65
namespace dnsdist::lua
66
{
67
void setupLua(LuaContext& luaCtx, bool client, bool configCheck);
68
void setupLuaBindingsOnly(LuaContext& luaCtx, bool client, bool configCheck);
69
void setupLuaConfigurationOptions(LuaContext& luaCtx, bool client, bool configCheck);
70
void setupConfigurationItems(LuaContext& luaCtx);
71

72
template <class FunctionType>
73
std::optional<FunctionType> getFunctionFromLuaCode(const std::string& code, const std::string& context)
74
{
10✔
75
  try {
10✔
76
    auto function = g_lua.lock()->executeCode<FunctionType>(code);
10✔
77
    if (!function) {
10!
78
      return std::nullopt;
79
    }
80
    return function;
10✔
81
  }
10✔
82
  catch (const std::exception& exp) {
10✔
83
    warnlog("Parsing Lua code '%s' in context '%s' failed: %s", code, context, exp.what());
84
  }
85

86
  return std::nullopt;
87
}
10✔
88

89
struct LuaServerPoolObject
90
{
91
  LuaServerPoolObject(std::string name) :
92
    poolName(std::move(name))
177✔
UNCOV
93
  {
177✔
UNCOV
94
  }
177✔
95

96
  std::string poolName;
97
};
98
}
99

100
namespace dnsdist::configuration::lua
101
{
102
void loadLuaConfigurationFile(LuaContext& luaCtx, const std::string& config, bool configCheck);
103
}
104

105
/**
106
 * getOptionalValue(vars, key, value)
107
 *
108
 * Attempts to extract value for key in vars.
109
 * Erases the key from vars.
110
 *
111
 * returns: -1 if type wasn't compatible, 0 if not found or number of element(s) found
112
 */
113
template <class G, class T, class V>
114
static inline int getOptionalValue(boost::optional<V>& vars, const std::string& key, T& value, bool warnOnWrongType = true)
115
{
61,867✔
116
  /* nothing found, nothing to return */
117
  if (!vars) {
61,867!
118
    return 0;
3,365✔
119
  }
3,365✔
120

121
  if (vars->count(key)) {
58,502!
122
    try {
2,343✔
123
      value = boost::get<G>((*vars)[key]);
2,343✔
124
    }
2,343✔
125
    catch (const boost::bad_get& e) {
2,343✔
126
      /* key is there but isn't compatible */
127
      if (warnOnWrongType) {
36!
128
        warnlog("Invalid type for key '%s' - ignored", key);
129
        vars->erase(key);
130
      }
131
      return -1;
36✔
132
    }
36✔
133
  }
2,343✔
134
  return vars->erase(key);
58,466✔
135
}
58,502✔
136

137
template <class T, class V>
138
static inline int getOptionalIntegerValue(const std::string& func, boost::optional<V>& vars, const std::string& key, T& value)
139
{
12,672✔
140
  std::string valueStr;
12,672✔
141
  auto ret = getOptionalValue<std::string>(vars, key, valueStr, true);
12,672✔
142
  if (ret == 1) {
12,672✔
143
    try {
84✔
144
      value = std::stoi(valueStr);
84✔
145
    }
84✔
146
    catch (const std::exception& e) {
84✔
147
      warnlog("Parameter '%s' of '%s' must be integer, not '%s' - ignoring", func, key, valueStr);
148
      return -1;
149
    }
150
  }
84✔
151
  return ret;
12,672✔
152
}
12,672✔
153

154
template <class V>
155
static inline void checkAllParametersConsumed(const std::string& func, const boost::optional<V>& vars)
156
{
2,451✔
157
  /* no vars */
158
  if (!vars) {
2,451!
159
    return;
1,254✔
160
  }
1,254✔
161
  for (const auto& [key, value] : *vars) {
1,197!
162
    warnlog("%s: Unknown key '%s' given - ignored", func, key);
163
  }
164
}
1,197✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc