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

PowerDNS / pdns / 18743945403

23 Oct 2025 09:29AM UTC coverage: 65.845% (+0.02%) from 65.829%
18743945403

Pull #16356

github

web-flow
Merge 8a2027ef1 into efa3637e8
Pull Request #16356: auth 5.0: backport "pdnsutil: fix b2b-migrate to from sql to non-sql"

42073 of 92452 branches covered (45.51%)

Branch coverage included in aggregate %.

128008 of 165855 relevant lines covered (77.18%)

6379935.17 hits per line

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

85.27
/pdns/recursordist/rec-main.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

23
#pragma once
24

25
#ifdef HAVE_CONFIG_H
26
#include "config.h"
27
#endif
28

29
#include "logger.hh"
30
#include "logr.hh"
31
#include "lua-recursor4.hh"
32
#include "mplexer.hh"
33
#include "namespaces.hh"
34
#include "rec-lua-conf.hh"
35
#include "rec-protozero.hh"
36
#include "syncres.hh"
37
#include "rec-snmp.hh"
38
#include "rec_channel.hh"
39
#include "threadname.hh"
40
#include "recpacketcache.hh"
41
#include "ratelimitedlog.hh"
42
#include "protozero-trace.hh"
43

44
#ifdef NOD_ENABLED
45
#include "nod.hh"
46
#endif /* NOD_ENABLED */
47

48
#include <boost/container/flat_set.hpp>
49

50
extern std::shared_ptr<Logr::Logger> g_slogtcpin;
51
extern std::shared_ptr<Logr::Logger> g_slogudpin;
52

53
//! used to send information to a newborn mthread
54
struct DNSComboWriter
55
{
56
  DNSComboWriter(const std::string& query, const struct timeval& now, shared_ptr<RecursorLua4> luaContext) :
57
    d_mdp(true, query), d_now(now), d_query(query), d_luaContext(std::move(luaContext))
58
  {
852✔
59
  }
852✔
60

61
  DNSComboWriter(const std::string& query, const struct timeval& now, std::unordered_set<std::string>&& policyTags, shared_ptr<RecursorLua4> luaContext, LuaContext::LuaObject&& data, std::vector<DNSRecord>&& records) :
62
    d_mdp(true, query), d_now(now), d_query(query), d_policyTags(std::move(policyTags)), d_gettagPolicyTags(d_policyTags), d_records(std::move(records)), d_luaContext(std::move(luaContext)), d_data(std::move(data))
63
  {
2,370✔
64
  }
2,370✔
65

66
  // The address the query is coming from
67
  void setRemote(const ComboAddress& sa)
68
  {
3,222✔
69
    d_remote = sa;
3,222✔
70
  }
3,222✔
71

72
  // The address we assume the query is coming from, might be set by proxy protocol
73
  void setSource(const ComboAddress& sa)
74
  {
3,221✔
75
    d_source = sa;
3,221✔
76
  }
3,221✔
77

78
  void setMappedSource(const ComboAddress& sa)
79
  {
3,222✔
80
    d_mappedSource = sa;
3,222✔
81
  }
3,222✔
82

83
  void setLocal(const ComboAddress& sa)
84
  {
3,221✔
85
    d_local = sa;
3,221✔
86
  }
3,221✔
87

88
  // The address we assume the query is sent to, might be set by proxy protocol
89
  void setDestination(const ComboAddress& sa)
90
  {
3,221✔
91
    d_destination = sa;
3,221✔
92
  }
3,221✔
93

94
  void setSocket(int sock)
95
  {
3,223✔
96
    d_socket = sock;
3,223✔
97
  }
3,223✔
98

99
  // get a string repesentation of the client address, including proxy info if applicable
100
  string getRemote() const
101
  {
3,149✔
102
    if (d_source == d_remote) {
3,152✔
103
      return d_source.toStringWithPort();
3,122✔
104
    }
3,122✔
105
    return d_source.toStringWithPort() + " (proxied by " + d_remote.toStringWithPort() + ")";
2,147,483,676✔
106
  }
3,149✔
107

108
  std::vector<ProxyProtocolValue> d_proxyProtocolValues;
109
  MOADNSParser d_mdp;
110
  struct timeval d_now;
111

112
  ComboAddress d_remote; // the address the query is coming from
113
  ComboAddress d_source; // the address we assume the query is coming from, might be set by proxy protocol
114
  ComboAddress d_local; // the address we received the query on
115
  ComboAddress d_destination; // the address we assume the query is sent to, might be set by proxy protocol
116
  ComboAddress d_mappedSource; // the source address after being mapped by table based proxy mapping
117
  RecEventTrace d_eventTrace;
118
  pdns::trace::InitialSpanInfo d_otTrace;
119
  boost::uuids::uuid d_uuid;
120
  string d_requestorId;
121
  string d_deviceId;
122
  string d_deviceName;
123
  struct timeval d_kernelTimestamp{
124
    0, 0};
125
  std::string d_query;
126
  std::unordered_set<std::string> d_policyTags;
127
  std::unordered_set<std::string> d_gettagPolicyTags;
128
  std::string d_routingTag;
129
  std::vector<DNSRecord> d_records;
130

131
  // d_data is tied to this LuaContext so we need to keep it alive and use it, not a newer one, as long as d_data exists
132
  shared_ptr<RecursorLua4> d_luaContext;
133
  LuaContext::LuaObject d_data;
134

135
  EDNSSubnetOpts d_ednssubnet;
136
  shared_ptr<TCPConnection> d_tcpConnection;
137
  boost::optional<uint16_t> d_extendedErrorCode{boost::none};
138
  string d_extendedErrorExtra;
139
  boost::optional<int> d_rcode{boost::none};
140
  int d_socket{-1};
141
  unsigned int d_tag{0};
142
  uint32_t d_qhash{0};
143
  uint32_t d_ttlCap{std::numeric_limits<uint32_t>::max()};
144
  bool d_variable{false};
145
  bool d_ecsFound{false};
146
  bool d_ecsParsed{false};
147
  bool d_followCNAMERecords{false};
148
  bool d_logResponse{false};
149
  bool d_tcp{false};
150
  bool d_responsePaddingDisabled{false};
151
  std::map<std::string, RecursorLua4::MetaValue> d_meta;
152
};
153

154
extern thread_local unique_ptr<FDMultiplexer> t_fdm;
155
extern uint16_t g_minUdpSourcePort;
156
extern uint16_t g_maxUdpSourcePort;
157
extern bool g_regressionTestMode;
158
struct DoneRunning
159
{
160
  std::mutex mutex;
161
  std::condition_variable condVar;
162
  std::atomic<bool> done{false};
163
};
164
extern DoneRunning g_doneRunning;
165

166
// you can ask this class for a UDP socket to send a query from
167
// this socket is not yours, don't even think about deleting it
168
// but after you call 'returnSocket' on it, don't assume anything anymore
169
class UDPClientSocks
170
{
171
  unsigned int d_numsocks;
172

173
public:
174
  UDPClientSocks() :
175
    d_numsocks(0)
176
  {
913✔
177
  }
913✔
178

179
  LWResult::Result getSocket(const ComboAddress& toaddr, int* fileDesc);
180

181
  // return a socket to the pool, or simply erase it
182
  void returnSocket(int fileDesc);
183

184
private:
185
  // returns -1 for errors which might go away, throws for ones that won't
186
  static int makeClientSocket(int family);
187
};
188

189
enum class PaddingMode
190
{
191
  Always,
192
  PaddedQueries
193
};
194

195
typedef MTasker<std::shared_ptr<PacketID>, PacketBuffer, PacketIDCompare> MT_t;
196
extern thread_local std::unique_ptr<MT_t> g_multiTasker; // the big MTasker
197
extern std::unique_ptr<RecursorPacketCache> g_packetCache;
198

199
using RemoteLoggerStats_t = std::unordered_map<std::string, RemoteLoggerInterface::Stats>;
200

201
extern bool g_yamlSettings;
202
extern string g_yamlSettingsSuffix;
203
extern LockGuarded<pdns::rust::settings::rec::Recursorsettings> g_yamlStruct;
204
extern bool g_logCommonErrors;
205
extern size_t g_proxyProtocolMaximumSize;
206
extern std::atomic<bool> g_quiet;
207
extern thread_local std::shared_ptr<RecursorLua4> t_pdl;
208
extern bool g_gettagNeedsEDNSOptions;
209
extern NetmaskGroup g_paddingFrom;
210
extern unsigned int g_paddingTag;
211
extern PaddingMode g_paddingMode;
212
extern unsigned int g_maxMThreads;
213
extern bool g_reusePort;
214
extern bool g_anyToTcp;
215
extern size_t g_tcpMaxQueriesPerConn;
216
extern unsigned int g_maxTCPClients;
217
extern unsigned int g_maxTCPPerClient;
218
extern int g_tcpTimeout;
219
extern uint16_t g_udpTruncationThreshold;
220
extern double g_balancingFactor;
221
extern size_t g_maxUDPQueriesPerRound;
222
extern bool g_useKernelTimestamp;
223
extern bool g_allowNoRD;
224
extern unsigned int g_maxChainLength;
225
extern thread_local std::shared_ptr<NetmaskGroup> t_allowFrom;
226
extern thread_local std::shared_ptr<NetmaskGroup> t_allowNotifyFrom;
227
extern thread_local std::shared_ptr<notifyset_t> t_allowNotifyFor;
228
extern thread_local std::unique_ptr<UDPClientSocks> t_udpclientsocks;
229
extern thread_local std::shared_ptr<NetmaskGroup> t_proxyProtocolACL;
230
extern thread_local std::shared_ptr<std::set<ComboAddress>> t_proxyProtocolExceptions;
231
extern bool g_useIncomingECS;
232
extern boost::optional<ComboAddress> g_dns64Prefix;
233
extern DNSName g_dns64PrefixReverse;
234
extern uint64_t g_latencyStatSize;
235
extern std::atomic<bool> g_statsWanted;
236
extern uint32_t g_disthashseed;
237
extern int g_argc;
238
extern char** g_argv;
239
extern LockGuarded<std::shared_ptr<SyncRes::domainmap_t>> g_initialDomainMap; // new threads needs this to be setup
240
extern LockGuarded<std::shared_ptr<NetmaskGroup>> g_initialAllowFrom; // new thread needs to be setup with this
241
extern LockGuarded<std::shared_ptr<NetmaskGroup>> g_initialAllowNotifyFrom; // new threads need this to be setup
242
extern LockGuarded<std::shared_ptr<notifyset_t>> g_initialAllowNotifyFor; // new threads need this to be setup
243
extern thread_local std::shared_ptr<Regex> t_traceRegex;
244
extern thread_local FDWrapper t_tracefd;
245
extern string g_programname;
246
extern string g_pidfname;
247
extern RecursorControlChannel g_rcc; // only active in the handler thread
248

249
extern thread_local std::unique_ptr<ProxyMapping> t_proxyMapping;
250
using ProxyMappingStats_t = std::unordered_map<Netmask, ProxyMappingCounts>;
251
extern pdns::RateLimitedLog g_rateLimitedLogger;
252

253
#ifdef NOD_ENABLED
254
extern bool g_nodEnabled;
255
extern DNSName g_nodLookupDomain;
256
extern bool g_nodLog;
257
extern SuffixMatchNode g_nodDomainWL;
258
extern SuffixMatchNode g_udrDomainWL;
259
extern std::string g_nod_pbtag;
260
extern bool g_udrEnabled;
261
extern bool g_udrLog;
262
extern std::string g_udr_pbtag;
263
extern std::unique_ptr<nod::NODDB> g_nodDBp;
264
extern std::unique_ptr<nod::UniqueResponseDB> g_udrDBp;
265
#endif
266

267
struct ProtobufServersInfo
268
{
269
  std::shared_ptr<std::vector<std::unique_ptr<RemoteLogger>>> servers;
270
  uint64_t generation;
271
  ProtobufExportConfig config;
272
};
273
extern thread_local ProtobufServersInfo t_protobufServers;
274
extern thread_local ProtobufServersInfo t_outgoingProtobufServers;
275

276
#ifdef HAVE_FSTRM
277
struct FrameStreamServersInfo
278
{
279
  std::shared_ptr<std::vector<std::unique_ptr<FrameStreamLogger>>> servers;
280
  uint64_t generation;
281
  FrameStreamExportConfig config;
282
};
283

284
extern thread_local FrameStreamServersInfo t_frameStreamServersInfo;
285
extern thread_local FrameStreamServersInfo t_nodFrameStreamServersInfo;
286
#endif /* HAVE_FSTRM */
287

288
extern boost::container::flat_set<uint16_t> g_avoidUdpSourcePorts;
289

290
/* without reuseport, all listeners share the same sockets */
291
typedef vector<pair<int, std::function<void(int, boost::any&)>>> deferredAdd_t;
292

293
inline MT_t* getMT()
294
{
1,896✔
295
  return g_multiTasker ? g_multiTasker.get() : nullptr;
1,896!
296
}
1,896✔
297

298
/* this function is called with both a string and a vector<uint8_t> representing a packet */
299
template <class T>
300
static bool sendResponseOverTCP(const std::unique_ptr<DNSComboWriter>& dc, const T& packet)
301
{
844✔
302
  uint8_t buf[2];
844✔
303
  buf[0] = packet.size() / 256;
844✔
304
  buf[1] = packet.size() % 256;
844✔
305

306
  Utility::iovec iov[2];
844✔
307
  iov[0].iov_base = (void*)buf;
844✔
308
  iov[0].iov_len = 2;
844✔
309
  iov[1].iov_base = (void*)&*packet.begin();
844✔
310
  iov[1].iov_len = packet.size();
844✔
311

312
  int wret = Utility::writev(dc->d_socket, iov, 2);
844✔
313
  bool hadError = true;
844✔
314

315
  if (wret == 0) {
844!
316
    g_log << Logger::Warning << "EOF writing TCP answer to " << dc->getRemote() << endl;
×
317
  }
×
318
  else if (wret < 0) {
844!
319
    int err = errno;
×
320
    g_log << Logger::Warning << "Error writing TCP answer to " << dc->getRemote() << ": " << strerror(err) << endl;
×
321
  }
×
322
  else if ((unsigned int)wret != 2 + packet.size()) {
844!
323
    g_log << Logger::Warning << "Oops, partial answer sent to " << dc->getRemote() << " for " << dc->d_mdp.d_qname << " (size=" << (2 + packet.size()) << ", sent " << wret << ")" << endl;
×
324
  }
×
325
  else {
844✔
326
    hadError = false;
844✔
327
  }
844✔
328

329
  return hadError;
844✔
330
}
844✔
331

332
// For communicating with our threads effectively readonly after
333
// startup.
334
// First we have the handler thread, t_id == 0  then the
335
// distributor threads if any and finally the workers
336
struct RecThreadInfo
337
{
338
  struct ThreadPipeSet
339
  {
340
    int writeToThread{-1};
341
    int readToThread{-1};
342
    int writeFromThread{-1};
343
    int readFromThread{-1};
344
    int writeQueriesToThread{-1}; // this one is non-blocking
345
    int readQueriesToThread{-1};
346
  };
347

348
public:
349
  static RecThreadInfo& self()
350
  {
17,089✔
351
    auto& info = s_threadInfos.at(t_id);
17,089✔
352
    assert(info.d_myid == t_id); // internal consistency check
17,089✔
353
    return info;
×
354
  }
17,089✔
355

356
  static RecThreadInfo& info(unsigned int index)
357
  {
6,843✔
358
    auto& info = s_threadInfos.at(index);
6,843✔
359
    assert(info.d_myid == index);
6,843✔
360
    return info;
×
361
  }
6,843✔
362

363
  static vector<RecThreadInfo>& infos()
364
  {
2,272✔
365
    return s_threadInfos;
2,272✔
366
  }
2,272✔
367

368
  [[nodiscard]] bool isDistributor() const
369
  {
3,612✔
370
    return s_weDistributeQueries && listener;
3,612!
371
  }
3,612✔
372

373
  [[nodiscard]] bool isHandler() const
374
  {
56,339✔
375
    return handler;
56,339✔
376
  }
56,339✔
377

378
  [[nodiscard]] bool isWorker() const
379
  {
7,102✔
380
    return worker;
7,102✔
381
  }
7,102✔
382

383
  // UDP or TCP listener?
384
  [[nodiscard]] bool isListener() const
385
  {
1,102✔
386
    return listener;
1,102✔
387
  }
1,102✔
388

389
  // A TCP-only listener?
390
  [[nodiscard]] bool isTCPListener() const
391
  {
30✔
392
    return tcplistener;
30✔
393
  }
30✔
394

395
  [[nodiscard]] bool isTaskThread() const
396
  {
25,817✔
397
    return taskThread;
25,817✔
398
  }
25,817✔
399

400
  void setHandler()
401
  {
175✔
402
    handler = true;
175✔
403
  }
175✔
404

405
  void setWorker()
406
  {
549✔
407
    worker = true;
549✔
408
  }
549✔
409

410
  void setListener(bool flag = true)
411
  {
563✔
412
    listener = flag;
563✔
413
  }
563✔
414

415
  void setTCPListener(bool flag = true)
416
  {
175✔
417
    setListener(flag);
175✔
418
    tcplistener = flag;
175✔
419
  }
175✔
420

421
  void setTaskThread()
422
  {
175✔
423
    taskThread = true;
175✔
424
  }
175✔
425

426
  static unsigned int thread_local_id()
427
  {
13,984✔
428
    if (t_id == TID_NOT_INITED) {
13,984✔
429
      return 0; // backward compatibility
7,466✔
430
    }
7,466✔
431
    return t_id;
6,518✔
432
  }
13,984✔
433

434
  static bool is_thread_inited()
435
  {
542✔
436
    return t_id != TID_NOT_INITED;
542✔
437
  }
542✔
438

439
  [[nodiscard]] unsigned int id() const
440
  {
×
441
    return d_myid;
×
442
  }
×
443

444
  static void setThreadId(unsigned int arg)
445
  {
3✔
446
    t_id = arg;
3✔
447
  }
3✔
448

449
  [[nodiscard]] std::string getName() const
450
  {
303✔
451
    return name;
303✔
452
  }
303✔
453

454
  static unsigned int numHandlers()
455
  {
5,877✔
456
    return 1;
5,877✔
457
  }
5,877✔
458

459
  static unsigned int numTaskThreads()
460
  {
2,959✔
461
    return 1;
2,959✔
462
  }
2,959✔
463

464
  static unsigned int numUDPWorkers()
465
  {
13,641✔
466
    return s_numUDPWorkerThreads;
13,641✔
467
  }
13,641✔
468

469
  static unsigned int numTCPWorkers()
470
  {
4,326✔
471
    return s_numTCPWorkerThreads;
4,326✔
472
  }
4,326✔
473

474
  static unsigned int numDistributors()
475
  {
6,416✔
476
    return s_numDistributorThreads;
6,416✔
477
  }
6,416✔
478

479
  static bool weDistributeQueries()
480
  {
7,314✔
481
    return s_weDistributeQueries;
7,314✔
482
  }
7,314✔
483

484
  static void setWeDistributeQueries(bool flag)
485
  {
175✔
486
    s_weDistributeQueries = flag;
175✔
487
  }
175✔
488

489
  static void setNumUDPWorkerThreads(unsigned int n)
490
  {
175✔
491
    s_numUDPWorkerThreads = n;
175✔
492
  }
175✔
493

494
  static void setNumTCPWorkerThreads(unsigned int n)
495
  {
175✔
496
    s_numTCPWorkerThreads = n;
175✔
497
  }
175✔
498

499
  static void setNumDistributorThreads(unsigned int n)
500
  {
175✔
501
    s_numDistributorThreads = n;
175✔
502
  }
175✔
503

504
  static unsigned int numRecursorThreads()
505
  {
2,265✔
506
    return numHandlers() + numDistributors() + numUDPWorkers() + numTCPWorkers() + numTaskThreads();
2,265✔
507
  }
2,265✔
508

509
  static int runThreads(Logr::log_t);
510
  static void makeThreadPipes(Logr::log_t);
511

512
  void setExitCode(int n)
513
  {
×
514
    exitCode = n;
×
515
  }
×
516

517
  std::set<int>& getTCPSockets()
518
  {
160✔
519
    return tcpSockets;
160✔
520
  }
160✔
521

522
  void setTCPSockets(std::set<int>& socks)
523
  {
15✔
524
    tcpSockets = socks;
15✔
525
  }
15✔
526

527
  deferredAdd_t& getDeferredAdds()
528
  {
956✔
529
    return deferredAdds;
956✔
530
  }
956✔
531

532
  const ThreadPipeSet& getPipes() const
533
  {
14,091✔
534
    return pipes;
14,091✔
535
  }
14,091✔
536

537
  [[nodiscard]] uint64_t getNumberOfDistributedQueries() const
538
  {
207✔
539
    return numberOfDistributedQueries;
207✔
540
  }
207✔
541

542
  void incNumberOfDistributedQueries()
543
  {
6,184✔
544
    numberOfDistributedQueries++;
6,184✔
545
  }
6,184✔
546

547
  MT_t* getMT()
548
  {
×
549
    return mt;
×
550
  }
×
551

552
  void setMT(MT_t* theMT)
553
  {
913✔
554
    mt = theMT;
913✔
555
  }
913✔
556

557
  static void joinThread0()
558
  {
175✔
559
    info(0).thread.join();
175✔
560
  }
175✔
561

562
  static void resize(size_t size)
563
  {
175✔
564
    s_threadInfos.resize(size);
175✔
565
    for (unsigned int i = 0; i < size; i++) {
1,088✔
566
      s_threadInfos.at(i).d_myid = i;
913✔
567
    }
913✔
568
  }
175✔
569
  static constexpr unsigned int TID_NOT_INITED = std::numeric_limits<unsigned int>::max();
570

571
private:
572
  // FD corresponding to TCP sockets this thread is listening on.
573
  // These FDs are also in deferredAdds when we have one socket per
574
  // listener, and in g_deferredAdds instead.
575
  std::set<int> tcpSockets;
576
  // FD corresponding to listening sockets if we have one socket per
577
  // listener (with reuseport), otherwise all listeners share the
578
  // same FD and g_deferredAdds is then used instead
579
  deferredAdd_t deferredAdds;
580

581
  struct ThreadPipeSet pipes;
582
  MT_t* mt{nullptr};
583
  uint64_t numberOfDistributedQueries{0};
584

585
  void start(unsigned int tid, const string& tname, const std::map<unsigned int, std::set<int>>& cpusMap, Logr::log_t);
586

587
  std::string name;
588
  std::thread thread;
589
  int exitCode{0};
590
  unsigned int d_myid{TID_NOT_INITED}; // should always be equal to the thread_local tid;
591

592
  // handle the web server, carbon, statistics and the control channel
593
  bool handler{false};
594
  // accept incoming queries (and distributes them to the workers if pdns-distributes-queries is set)
595
  bool listener{false};
596
  // accept incoming TCP queries (and distributes them to the workers if pdns-distributes-queries is set)
597
  bool tcplistener{false};
598
  // process queries
599
  bool worker{false};
600
  // run async tasks: from TaskQueue and ZoneToCache
601
  bool taskThread{false};
602

603
  static thread_local unsigned int t_id;
604
  static std::vector<RecThreadInfo> s_threadInfos;
605
  static bool s_weDistributeQueries; // if true, 1 or more threads listen on the incoming query sockets and distribute them to workers
606
  static unsigned int s_numDistributorThreads;
607
  static unsigned int s_numUDPWorkerThreads;
608
  static unsigned int s_numTCPWorkerThreads;
609
};
610

611
struct ThreadMSG
612
{
613
  pipefunc_t func;
614
  bool wantAnswer;
615
};
616

617
void parseACLs();
618
PacketBuffer GenUDPQueryResponse(const ComboAddress& dest, const string& query);
619
bool checkProtobufExport(LocalStateHolder<LuaConfigItems>& luaconfsLocal);
620
bool checkOutgoingProtobufExport(LocalStateHolder<LuaConfigItems>& luaconfsLocal);
621
#ifdef HAVE_FSTRM
622
bool checkFrameStreamExport(LocalStateHolder<LuaConfigItems>& luaconfsLocal, const FrameStreamExportConfig& config, FrameStreamServersInfo& serverInfos);
623
#endif
624
void getQNameAndSubnet(const std::string& question, DNSName* dnsname, uint16_t* qtype, uint16_t* qclass,
625
                       bool& foundECS, EDNSSubnetOpts* ednssubnet, EDNSOptionViewMap* options, boost::optional<uint32_t>& ednsVersion);
626
void protobufLogQuery(LocalStateHolder<LuaConfigItems>& luaconfsLocal, const boost::uuids::uuid& uniqueId, const ComboAddress& remote, const ComboAddress& local, const ComboAddress& mappedSource, const Netmask& ednssubnet, bool tcp, size_t len, const DNSName& qname, uint16_t qtype, uint16_t qclass, const std::unordered_set<std::string>& policyTags, const std::string& requestorId, const std::string& deviceId, const std::string& deviceName, const std::map<std::string, RecursorLua4::MetaValue>& meta, const boost::optional<uint32_t>& ednsVersion, const dnsheader& header);
627
bool isAllowNotifyForZone(DNSName qname);
628
bool checkForCacheHit(bool qnameParsed, unsigned int tag, const string& data,
629
                      DNSName& qname, uint16_t& qtype, uint16_t& qclass,
630
                      const struct timeval& now,
631
                      string& response, uint32_t& qhash,
632
                      RecursorPacketCache::OptPBData& pbData, bool tcp, const ComboAddress& source, const ComboAddress& mappedSource);
633
void protobufLogResponse(pdns::ProtoZero::RecMessage& message);
634
void protobufLogResponse(const DNSName& qname, QType qtype, const struct dnsheader* header, LocalStateHolder<LuaConfigItems>& luaconfsLocal,
635
                         const RecursorPacketCache::OptPBData& pbData, const struct timeval& tv,
636
                         bool tcp, const ComboAddress& source, const ComboAddress& destination,
637
                         const ComboAddress& mappedSource, const EDNSSubnetOpts& ednssubnet,
638
                         const boost::uuids::uuid& uniqueId, const string& requestorId, const string& deviceId,
639
                         const string& deviceName, const std::map<std::string, RecursorLua4::MetaValue>& meta,
640
                         const RecEventTrace& eventTrace,
641
                         pdns::trace::InitialSpanInfo& otTrace,
642
                         const std::unordered_set<std::string>& policyTags);
643
void requestWipeCaches(const DNSName& canon);
644
void startDoResolve(void*);
645
bool expectProxyProtocol(const ComboAddress& from, const ComboAddress& listenAddress);
646
void finishTCPReply(std::unique_ptr<DNSComboWriter>&, bool hadError, bool updateInFlight);
647
void checkFastOpenSysctl(bool active, Logr::log_t);
648
void checkTFOconnect(Logr::log_t);
649
unsigned int makeTCPServerSockets(deferredAdd_t& deferredAdds, std::set<int>& tcpSockets, Logr::log_t, bool doLog, unsigned int instances);
650
void handleNewTCPQuestion(int fileDesc, FDMultiplexer::funcparam_t&);
651

652
unsigned int makeUDPServerSockets(deferredAdd_t& deferredAdds, Logr::log_t, bool doLog, unsigned int instances);
653
string doTraceRegex(FDWrapper file, vector<string>::const_iterator begin, vector<string>::const_iterator end);
654
extern bool g_luaSettingsInYAML;
655
void startLuaConfigDelayedThreads(const LuaConfigItems& luaConfig, uint64_t generation);
656
void activateLuaConfig(LuaConfigItems& lci);
657
unsigned int authWaitTimeMSec(const std::unique_ptr<MT_t>& mtasker);
658

659
#define LOCAL_NETS "127.0.0.0/8, 10.0.0.0/8, 100.64.0.0/10, 169.254.0.0/16, 192.168.0.0/16, 172.16.0.0/12, ::1/128, fc00::/7, fe80::/10"
1✔
660
#define LOCAL_NETS_INVERSE "!127.0.0.0/8, !10.0.0.0/8, !100.64.0.0/10, !169.254.0.0/16, !192.168.0.0/16, !172.16.0.0/12, !::1/128, !fc00::/7, !fe80::/10"
661
// Bad Nets taken from both:
662
// http://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
663
// and
664
// http://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml
665
// where such a network may not be considered a valid destination
666
#define BAD_NETS "0.0.0.0/8, 192.0.0.0/24, 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24, 240.0.0.0/4, ::/96, ::ffff:0:0/96, 100::/64, 2001:db8::/32"
667
#define DONT_QUERY LOCAL_NETS ", " BAD_NETS
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