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

PowerDNS / pdns / 18776176249

24 Oct 2025 09:51AM UTC coverage: 73.028% (+15.6%) from 57.383%
18776176249

Pull #16370

github

web-flow
Merge 0f309894e into 39f7f1b27
Pull Request #16370: auth: xfr churning

38273 of 63104 branches covered (60.65%)

Branch coverage included in aggregate %.

186 of 264 new or added lines in 1 file covered. (70.45%)

14471 existing lines in 217 files now uncovered.

127487 of 163878 relevant lines covered (77.79%)

5632363.83 hits per line

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

93.33
/pdns/auth-zonecache.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
#include <string>
24
#include <unordered_map>
25
#include <vector>
26
#include "dnsname.hh"
27
#include "lock.hh"
28
#include "misc.hh"
29
#include "iputils.hh"
30
#include "dnspacket.hh"
31

32
class AuthZoneCache : public boost::noncopyable
33
{
34
public:
35
  AuthZoneCache(size_t mapsCount = 1024);
36

37
  using ViewsMap = std::map<std::string, std::map<DNSName, std::string>>;
38

39
  // Zone maintainance
40
  void replace(const vector<std::tuple<ZoneName, domainid_t>>& zone);
41
  void replace(NetmaskTree<string> nettree);
42
  void replace(ViewsMap viewsmap);
43
  void add(const ZoneName& zone, const domainid_t zoneId);
44
  void remove(const ZoneName& zone);
45
  void setReplacePending(); //!< call this when data collection for the subsequent replace() call starts.
46

47
  // Views maintainance
48
  void addToView(const std::string& view, const ZoneName& zone);
49
  bool removeFromView(const std::string& view, const ZoneName& zone);
50

51
  // Network maintainance
52
  void updateNetwork(const Netmask& network, const std::string& view);
53

54
  // Zone lookup
55
  bool getEntry(const ZoneName& zone, domainid_t& zoneId);
56

57
  // View lookup
58
  std::string getViewFromNetwork(Netmask* net);
59

60
  // Variant lookup
61
  std::string getVariantFromView(const ZoneName& zone, const std::string& view);
62
  void setZoneVariant(DNSPacket& packet);
63

UNCOV
64
  size_t size() { return *d_statnumentries; } //!< number of entries in the cache
×
65

66
  uint32_t getRefreshInterval() const
67
  {
386✔
68
    // coverity[store_truncates_time_t]
69
    return d_refreshinterval;
386✔
70
  }
386✔
71

72
  void setRefreshInterval(uint32_t interval)
73
  {
203✔
74
    d_refreshinterval = interval;
203✔
75
  }
203✔
76

77
  bool isEnabled() const;
78

79
  void clear();
80

81
private:
82
  SharedLockGuarded<NetmaskTree<string>> d_nets;
83
  SharedLockGuarded<ViewsMap> d_views;
84

85
  struct CacheValue
86
  {
87
    domainid_t zoneId{UnknownDomainID};
88
  };
89

90
  typedef std::unordered_map<ZoneName, CacheValue, std::hash<ZoneName>> cmap_t;
91

92
  struct MapCombo
93
  {
94
    MapCombo() = default;
6,402,048✔
95
    ~MapCombo() = default;
6,144✔
96
    MapCombo(const MapCombo&) = delete;
97
    MapCombo& operator=(const MapCombo&) = delete;
98

99
    SharedLockGuarded<cmap_t> d_map;
100
  };
101

102
  vector<MapCombo> d_maps;
103
  size_t getMapIndex(const ZoneName& zone)
104
  {
212,453✔
105
    return zone.hash() % d_maps.size();
212,453✔
106
  }
212,453✔
107
  MapCombo& getMap(const ZoneName& qname)
108
  {
210,354✔
109
    return d_maps[getMapIndex(qname)];
210,354✔
110
  }
210,354✔
111

112
  AtomicCounter* d_statnumhit;
113
  AtomicCounter* d_statnummiss;
114
  AtomicCounter* d_statnumentries;
115

116
  time_t d_refreshinterval{0};
117

118
  struct PendingData
119
  {
120
    std::vector<std::tuple<ZoneName, domainid_t, bool>> d_pendingUpdates;
121
    bool d_replacePending{false};
122
  };
123
  LockGuarded<PendingData> d_pending;
124
};
125

126
extern AuthZoneCache g_zoneCache;
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