]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/zonemd.hh
pkcs11signers: Use emplace_back for attributes
[thirdparty/pdns.git] / pdns / zonemd.hh
CommitLineData
e21df721
O
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
efe79e15 24#ifdef HAVE_CONFIG_H
e21df721 25#include "config.h"
efe79e15
OM
26#endif
27
28#include "dnsname.hh"
29#include "qtype.hh"
30#include "dnsrecords.hh"
95b66e0d 31#include "validate.hh"
e21df721 32
e21df721
O
33class ZoneParserTNG;
34
35namespace pdns
36{
efe79e15
OM
37class ZoneMD
38{
39public:
5ee5e1e6
OM
40 enum class Config : uint8_t
41 {
42 Ignore,
af5b15bc
OM
43 Validate,
44 Require
5ee5e1e6
OM
45 };
46 enum class Result : uint8_t
47 {
48 OK,
49 NoValidationDone,
50 ValidationFailure
51 };
5ecf9d92 52
7dcdce8c
OM
53 ZoneMD(DNSName zone) :
54 d_zone(std::move(zone))
efe79e15
OM
55 {}
56 void readRecords(ZoneParserTNG& zpt);
5ecf9d92 57 void readRecords(const std::vector<DNSRecord>& records);
1c3bc297 58 void readRecord(const DNSRecord& record);
7dcdce8c 59 void processRecord(const DNSRecord& record);
efe79e15
OM
60 void verify(bool& validationDone, bool& validationOK);
61
e5163239 62 // Return the zone's apex DNSKEYs
7dcdce8c 63 [[nodiscard]] const std::set<shared_ptr<const DNSKEYRecordContent>>& getDNSKEYs() const
e5163239
OM
64 {
65 return d_dnskeys;
66 }
67
68 // Return the zone's apex RRSIGs
7dcdce8c 69 [[nodiscard]] const std::vector<shared_ptr<const RRSIGRecordContent>>& getRRSIGs() const
e5163239
OM
70 {
71 return d_rrsigs;
72 }
73
74 // Return the zone's apex ZONEMDs
7dcdce8c 75 [[nodiscard]] std::vector<shared_ptr<const ZONEMDRecordContent>> getZONEMDs() const
e5163239 76 {
d06dcda4 77 std::vector<shared_ptr<const ZONEMDRecordContent>> ret;
7dcdce8c 78 ret.reserve(d_zonemdRecords.size());
e5163239
OM
79 for (const auto& zonemd : d_zonemdRecords) {
80 ret.emplace_back(zonemd.second.record);
81 }
82 return ret;
5e7dd5e9
OM
83 }
84
95b66e0d 85 // Return the zone's apex NSECs with signatures
7dcdce8c 86 [[nodiscard]] const ContentSigPair& getNSECs() const
95b66e0d
OM
87 {
88 return d_nsecs;
89 }
90
91 // Return the zone's apex NSEC3s with signatures
7dcdce8c 92 [[nodiscard]] const ContentSigPair& getNSEC3s() const
95b66e0d 93 {
7dcdce8c
OM
94 const auto item = d_nsec3s.find(d_nsec3label);
95 return item == d_nsec3s.end() ? empty : d_nsec3s.at(d_nsec3label);
95b66e0d
OM
96 }
97
7dcdce8c 98 [[nodiscard]] const DNSName& getNSEC3Label() const
2088c7b8 99 {
3cb47b35
OM
100 return d_nsec3label;
101 }
102
7dcdce8c 103 [[nodiscard]] const std::vector<shared_ptr<const NSEC3PARAMRecordContent>>& getNSEC3Params() const
2088c7b8
OM
104 {
105 return d_nsec3params;
106 }
107
efe79e15 108private:
d06dcda4
RG
109 using RRSetKey_t = std::pair<DNSName, QType>;
110 using RRVector_t = std::vector<std::shared_ptr<const DNSRecordContent>>;
efe79e15 111
5fca0ca2 112 struct CanonRRSetKeyCompare
efe79e15 113 {
7dcdce8c 114 bool operator()(const RRSetKey_t& lhs, const RRSetKey_t& rhs) const
efe79e15
OM
115 {
116 // FIXME surely we can be smarter here
7dcdce8c 117 if (lhs.first.canonCompare(rhs.first)) {
efe79e15
OM
118 return true;
119 }
7dcdce8c 120 if (rhs.first.canonCompare(lhs.first)) {
efe79e15
OM
121 return false;
122 }
7dcdce8c 123 return lhs.second < rhs.second;
efe79e15
OM
124 }
125 };
126
d06dcda4 127 using RRSetMap_t = std::map<RRSetKey_t, RRVector_t, CanonRRSetKeyCompare>;
efe79e15
OM
128
129 struct ZoneMDAndDuplicateFlag
130 {
d06dcda4 131 const std::shared_ptr<const ZONEMDRecordContent> record;
efe79e15
OM
132 bool duplicate;
133 };
134
135 // scheme,hashalgo -> zonemdrecord,duplicate
136 std::map<pair<uint8_t, uint8_t>, ZoneMDAndDuplicateFlag> d_zonemdRecords;
137
138 RRSetMap_t d_resourceRecordSets;
139 std::map<RRSetKey_t, uint32_t> d_resourceRecordSetTTLs;
140
d06dcda4
RG
141 std::shared_ptr<const SOARecordContent> d_soaRecordContent;
142 std::set<shared_ptr<const DNSKEYRecordContent>> d_dnskeys;
143 std::vector<shared_ptr<const RRSIGRecordContent>> d_rrsigs;
144 std::vector<shared_ptr<const NSEC3PARAMRecordContent>> d_nsec3params;
95b66e0d 145 ContentSigPair d_nsecs;
2088c7b8 146 map<DNSName, ContentSigPair> d_nsec3s;
3cb47b35 147 DNSName d_nsec3label;
efe79e15 148 const DNSName d_zone;
2088c7b8 149 const ContentSigPair empty;
efe79e15 150};
e21df721
O
151
152}