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

PowerDNS / pdns / 15920880335

26 Jun 2025 03:30PM UTC coverage: 61.923% (-3.7%) from 65.652%
15920880335

push

github

web-flow
Merge pull request #15669 from miodvallat/serial_keyer

Increase zone serial number after zone key operations

38311 of 91850 branches covered (41.71%)

Branch coverage included in aggregate %.

27 of 29 new or added lines in 1 file covered. (93.1%)

6308 existing lines in 78 files now uncovered.

120482 of 164587 relevant lines covered (73.2%)

5965233.22 hits per line

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

0.0
/pdns/recursordist/rec-xfr.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 "config.h"
25

26
#include <condition_variable>
27
#include <string>
28
#include <thread>
29
#include <vector>
30

31
#include "iputils.hh"
32
#include "lock.hh"
33
#include "logr.hh"
34
#include "dnsrecords.hh"
35
#include "rust/lib.rs.h"
36

37
class DNSName;
38
class SOARecordContent;
39
struct FWCatalogZone;
40

41
// All members of this struct must be copyable, as they are used as parameters in a thread constructor
42
struct ZoneXFRParams
43
{
44
  std::string name;
45
  std::vector<std::string> primaries;
46
  ComboAddress localAddress;
47
  std::shared_ptr<const SOARecordContent> soaRecordContent;
48
  TSIGTriplet tsigtriplet;
49
  size_t maxReceivedMBytes{0};
50
  size_t zoneSizeHint{0};
51
  size_t zoneIdx{0};
52
  uint32_t refreshFromConf{0};
53
  uint16_t xfrTimeout{20};
54
};
55

56
class CatalogZone
57
{
58
public:
59
  void setRefresh(uint32_t refresh)
UNCOV
60
  {
×
UNCOV
61
    d_refresh = refresh;
×
UNCOV
62
  }
×
63
  [[nodiscard]] auto getRefresh() const
64
  {
×
65
    return d_refresh;
×
66
  }
×
67
  void setSerial(uint32_t serial)
UNCOV
68
  {
×
UNCOV
69
    d_serial = serial;
×
UNCOV
70
  }
×
71
  void setName(const DNSName& name)
UNCOV
72
  {
×
UNCOV
73
    d_name = name;
×
UNCOV
74
  }
×
75
  [[nodiscard]] const DNSName& getName() const
UNCOV
76
  {
×
UNCOV
77
    return d_name;
×
UNCOV
78
  }
×
79
  void clear()
UNCOV
80
  {
×
UNCOV
81
    d_records.clear();
×
UNCOV
82
  }
×
83
  void add(const DNSRecord& record, Logr::log_t logger);
84
  void remove(const DNSRecord& record, Logr::log_t logger);
85
  void registerForwarders(const FWCatalogZone& params, Logr::log_t logger) const;
86
  [[nodiscard]] bool versionCheck() const;
87
  [[nodiscard]] bool dupsCheck() const;
88

89
private:
90
  std::multimap<std::pair<DNSName, QType>, DNSRecord> d_records;
91
  DNSName d_name;
92
  uint32_t d_refresh{0};
93
  uint32_t d_serial{0};
94
};
95

96
struct FWCatalogZone
97
{
98
  ZoneXFRParams d_params;
99
  std::map<std::string, pdns::rust::settings::rec::FCZDefault> d_defaults;
100
  std::shared_ptr<CatalogZone> d_catz;
101
};
102

103
class ZoneXFR
104
{
105
public:
106
  // A struct that holds the condition var and related stuff to allow notifies to be sent to the thread owning
107
  // the struct.
108
  struct ZoneWaiter
109
  {
110
    ZoneWaiter(std::thread::id arg) :
UNCOV
111
      id(arg) {}
×
112
    std::thread::id id;
113
    std::mutex mutex;
114
    std::condition_variable condVar;
115
    std::atomic<bool> stop{false};
116
  };
117

118
  static bool notifyZoneTracker(const DNSName& name);
119
  static void insertZoneTracker(const DNSName& zoneName, ZoneWaiter& waiter);
120
  static void clearZoneTracker(const DNSName& zoneName);
121

122
  // coverity[pass_by_value] clang-tidy and coverity do not agree here
123
  ZoneXFR(ZoneXFRParams params) :
124
    d_params(std::move(params))
UNCOV
125
  {}
×
126

127
  ZoneXFRParams d_params;
128

129
  // As there can be multiple threads doing updates (due to config reloads), we use a multimap.
130
  // The value contains the actual thread id that owns the struct.
131
  static LockGuarded<std::multimap<DNSName, ZoneXFR::ZoneWaiter&>> condVars;
132
};
133

134
class FWCatZoneXFR : ZoneXFR
135
{
136
public:
137
  // coverity[pass_by_value] clang-tidy and coverity do not agree here
138
  FWCatZoneXFR(ZoneXFRParams params) :
139
    ZoneXFR(std::move(params))
UNCOV
140
  {}
×
141

142
  static void zoneXFRTracker(ZoneXFRParams params, uint64_t configGeneration);
143

144
private:
145
  void preloadZoneFile(const DNSName& zoneName, const std::shared_ptr<const CatalogZone>& oldZone, uint32_t& refresh, uint64_t configGeneration, ZoneWaiter& waiter, Logr::log_t logger);
146
  bool zoneTrackerIteration(const DNSName& zoneName, std::shared_ptr<const CatalogZone>& oldZone, uint32_t& refresh, bool& skipRefreshDelay, uint64_t configGeneration, ZoneWaiter& waiter, Logr::log_t logger);
147
};
148

149
std::string reloadZoneConfiguration(bool yaml);
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