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

PowerDNS / pdns / 19741624072

27 Nov 2025 03:45PM UTC coverage: 73.086% (+0.02%) from 73.065%
19741624072

Pull #16570

github

web-flow
Merge 08a2cdb1d into f94a3f63f
Pull Request #16570: rec: rewrite all unwrap calls in web.rs

38523 of 63408 branches covered (60.75%)

Branch coverage included in aggregate %.

128044 of 164496 relevant lines covered (77.84%)

6531485.83 hits per line

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

73.83
/pdns/dnsdistdist/dnsdist-rules.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-rules-factory.hh"
23

24
std::atomic<uint64_t> LuaFFIPerThreadRule::s_functionsCounter = 0;
25
thread_local std::map<uint64_t, LuaFFIPerThreadRule::PerThreadState> LuaFFIPerThreadRule::t_perThreadStates;
26

27
HTTPHeaderRule::HTTPHeaderRule(const std::string& header, const std::string& regex) :
28
  d_header(toLower(header)), d_visual("http[" + header + "] ~ " + regex)
10✔
29
{
10✔
30
#if !defined(HAVE_DNS_OVER_HTTPS) && !defined(HAVE_DNS_OVER_HTTP3)
31
  throw std::runtime_error("Using HTTPHeaderRule while DoH support is not enabled");
32
#else
33
  try {
10✔
34
    d_regex = Regex(regex);
10✔
35
  }
10✔
36
  catch (const PDNSException& exp) {
10✔
37
    throw std::runtime_error("Error compiling expression in HTTPHeaderRule: " + exp.reason);
38
  }
39
#endif /* HAVE_DNS_OVER_HTTPS || HAVE_DNS_OVER_HTTP3 */
10✔
40
}
10✔
41

42
bool HTTPHeaderRule::matches([[maybe_unused]] const DNSQuestion* dnsQuestion) const
43
{
63✔
44
#if defined(HAVE_DNS_OVER_HTTPS)
63✔
45
  if (dnsQuestion->ids.du) {
63✔
46
    const auto& headers = dnsQuestion->ids.du->getHTTPHeaders();
50✔
47
    for (const auto& header : headers) {
266✔
48
      if (header.first == d_header) {
266✔
49
        return d_regex->match(header.second);
6✔
50
      }
6✔
51
    }
266✔
52
    return false;
44✔
53
  }
50✔
54
#endif /* HAVE_DNS_OVER_HTTPS */
13✔
55
#if defined(HAVE_DNS_OVER_HTTP3)
13✔
56
  if (dnsQuestion->ids.doh3u) {
13!
57
    const auto& headers = dnsQuestion->ids.doh3u->getHTTPHeaders();
13✔
58
    for (const auto& header : headers) {
52✔
59
      if (header.first == d_header) {
52✔
60
        return d_regex->match(header.second);
2✔
61
      }
2✔
62
    }
52✔
63
    return false;
11✔
64
  }
13✔
65
#endif /* defined(HAVE_DNS_OVER_HTTP3) */
66
  return false;
×
67
}
13✔
68

69
string HTTPHeaderRule::toString() const
70
{
×
71
  return d_visual;
×
72
}
×
73

74
HTTPPathRule::HTTPPathRule(std::string path) :
75
  d_path(std::move(path))
10✔
76
{
10✔
77
#if !defined(HAVE_DNS_OVER_HTTPS) && !defined(HAVE_DNS_OVER_HTTP3)
78
  throw std::runtime_error("Using HTTPPathRule while DoH support is not enabled");
79
#endif /* HAVE_DNS_OVER_HTTPS || HAVE_DNS_OVER_HTTP3 */
80
}
10✔
81

82
bool HTTPPathRule::matches([[maybe_unused]] const DNSQuestion* dnsQuestion) const
83
{
59✔
84
#if defined(HAVE_DNS_OVER_HTTPS)
59✔
85
  if (dnsQuestion->ids.du) {
59✔
86
    const auto path = dnsQuestion->ids.du->getHTTPPath();
47✔
87
    return d_path == path;
47✔
88
  }
47✔
89
#endif /* HAVE_DNS_OVER_HTTPS */
12✔
90
#if defined(HAVE_DNS_OVER_HTTP3)
12✔
91
  if (dnsQuestion->ids.doh3u) {
12!
92
    return dnsQuestion->ids.doh3u->getHTTPPath() == d_path;
12✔
93
  }
12✔
94
#endif /* defined(HAVE_DNS_OVER_HTTP3) */
95
  return false;
×
96
}
12✔
97

98
string HTTPPathRule::toString() const
99
{
×
100
  return "url path == " + d_path;
×
101
}
×
102

103
HTTPPathRegexRule::HTTPPathRegexRule(const std::string& regex) :
104
  d_visual("http path ~ " + regex)
10✔
105
{
10✔
106
#if !defined(HAVE_DNS_OVER_HTTPS) && !defined(HAVE_DNS_OVER_HTTP3)
107
  throw std::runtime_error("Using HTTPRegexRule while DoH support is not enabled");
108
#else
109
  try {
10✔
110
    d_regex = Regex(regex);
10✔
111
  }
10✔
112
  catch (const PDNSException& exp) {
10✔
113
    throw std::runtime_error("Error compiling expression in HTTPPathRegexRule: " + exp.reason);
114
  }
115
#endif /* HAVE_DNS_OVER_HTTPS || HAVE_DNS_OVER_HTTP3 */
10✔
116
}
10✔
117

118
bool HTTPPathRegexRule::matches([[maybe_unused]] const DNSQuestion* dnsQuestion) const
119
{
55✔
120
#if defined(HAVE_DNS_OVER_HTTPS)
55✔
121
  if (dnsQuestion->ids.du) {
55✔
122
    const auto path = dnsQuestion->ids.du->getHTTPPath();
44✔
123
    return d_regex->match(path);
44✔
124
  }
44✔
125
#endif /* HAVE_DNS_OVER_HTTPS */
11✔
126
#if defined(HAVE_DNS_OVER_HTTP3)
11✔
127
  if (dnsQuestion->ids.doh3u) {
11!
128
    return d_regex->match(dnsQuestion->ids.doh3u->getHTTPPath());
11✔
129
  }
11✔
130
  return false;
131
#endif /* HAVE_DNS_OVER_HTTP3 */
132
  return false;
×
133
}
11✔
134

135
string HTTPPathRegexRule::toString() const
136
{
×
137
  return d_visual;
×
138
}
×
139

140
namespace dnsdist::selectors
141
{
142
std::shared_ptr<QClassRule> getQClassSelector(const std::string& qclassStr, uint16_t qclassCode)
143
{
×
144
  QClass qclass(qclassCode);
×
145
  if (!qclassStr.empty()) {
×
146
    qclass = QClass(std::string(qclassStr));
×
147
  }
×
148

149
  return std::make_shared<QClassRule>(qclass);
×
150
}
×
151

152
std::shared_ptr<QTypeRule> getQTypeSelector(const std::string& qtypeStr, uint16_t qtypeCode)
153
{
×
154
  QType qtype(qtypeCode);
×
155
  if (!qtypeStr.empty()) {
×
156
    qtype = std::string(qtypeStr);
×
157
  }
×
158

159
  return std::make_shared<QTypeRule>(qtype);
×
160
}
×
161

162
std::shared_ptr<SuffixMatchNodeRule> getQNameSuffixSelector(const SuffixMatchNode& suffixes, bool quiet)
163
{
2✔
164
  return std::make_shared<SuffixMatchNodeRule>(suffixes, quiet);
2✔
165
}
2✔
166

167
std::shared_ptr<QNameSetRule> getQNameSetSelector(const DNSNameSet& qnames)
168
{
10✔
169
  return std::make_shared<QNameSetRule>(qnames);
10✔
170
}
10✔
171

172
std::shared_ptr<QNameRule> getQNameSelector(const DNSName& qname)
173
{
60✔
174
  return std::make_shared<QNameRule>(qname);
60✔
175
}
60✔
176

177
std::shared_ptr<NetmaskGroupRule> getNetmaskGroupSelector(const NetmaskGroup& nmg, bool source, bool quiet)
178
{
6✔
179
  return std::make_shared<NetmaskGroupRule>(nmg, source, quiet);
6✔
180
}
6✔
181

182
std::shared_ptr<KeyValueStoreLookupRule> getKeyValueStoreLookupSelector(const std::shared_ptr<KeyValueStore>& kvs, const std::shared_ptr<KeyValueLookupKey>& lookupKey)
183
{
2✔
184
  return std::make_shared<KeyValueStoreLookupRule>(kvs, lookupKey);
2✔
185
}
2✔
186

187
std::shared_ptr<KeyValueStoreRangeLookupRule> getKeyValueStoreRangeLookupSelector(const std::shared_ptr<KeyValueStore>& kvs, const std::shared_ptr<KeyValueLookupKey>& lookupKey)
188
{
×
189
  return std::make_shared<KeyValueStoreRangeLookupRule>(kvs, lookupKey);
×
190
}
×
191

192
std::shared_ptr<AndRule> getAndSelector(const std::vector<std::shared_ptr<DNSRule>>& rules)
193
{
8✔
194
  return std::make_shared<AndRule>(rules);
8✔
195
}
8✔
196

197
std::shared_ptr<OrRule> getOrSelector(const std::vector<std::shared_ptr<DNSRule>>& rules)
198
{
×
199
  return std::make_shared<OrRule>(rules);
×
200
}
×
201

202
std::shared_ptr<NotRule> getNotSelector(const std::shared_ptr<DNSRule>& rule)
203
{
8✔
204
  return std::make_shared<NotRule>(rule);
8✔
205
}
8✔
206

207
std::shared_ptr<LuaRule> getLuaSelector(const dnsdist::selectors::LuaSelectorFunction& func)
208
{
10✔
209
  return std::make_shared<LuaRule>(func);
10✔
210
}
10✔
211

212
std::shared_ptr<LuaFFIRule> getLuaFFISelector(const dnsdist::selectors::LuaSelectorFFIFunction& func)
213
{
2✔
214
  return std::make_shared<LuaFFIRule>(func);
2✔
215
}
2✔
216

217
#include "dnsdist-selectors-factory-generated-body.hh"
218

219
}
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