Skip to content

Commit

Permalink
Enforce consistent use of reportAllTypes()
Browse files Browse the repository at this point in the history
  • Loading branch information
rgacogne committed Nov 28, 2024
1 parent 4af3f15 commit b6a8c99
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 126 deletions.
5 changes: 1 addition & 4 deletions modules/remotebackend/test-remotebackend-pipe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ struct RemotebackendSetup
::arg().set("remote-connection-string") = "pipe:command=unittest_pipe.py";
::arg().set("remote-dnssec") = "yes";
backendUnderTest = std::move(BackendMakers().all()[0]);
// load few record types to help out
SOARecordContent::report();
NSRecordContent::report();
ARecordContent::report();
reportAllTypes();
}
catch (PDNSException& ex) {
BOOST_TEST_MESSAGE("Cannot start remotebackend: " << ex.reason);
Expand Down
5 changes: 1 addition & 4 deletions modules/remotebackend/test-remotebackend-unix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ struct RemotebackendSetup
::arg().set("remote-connection-string") = "unix:path=/tmp/remotebackend.sock";
::arg().set("remote-dnssec") = "yes";
backendUnderTest = std::move(BackendMakers().all()[0]);
// load few record types to help out
SOARecordContent::report();
NSRecordContent::report();
ARecordContent::report();
reportAllTypes();
}
catch (PDNSException& ex) {
BOOST_TEST_MESSAGE("Cannot start remotebackend: " << ex.reason);
Expand Down
5 changes: 1 addition & 4 deletions modules/remotebackend/test-remotebackend-zeromq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ struct RemotebackendSetup
::arg().set("remote-connection-string") = "zeromq:endpoint=ipc:///tmp/remotebackend.0";
::arg().set("remote-dnssec") = "yes";
backendUnderTest = std::move(BackendMakers().all()[0]);
// load few record types to help out
SOARecordContent::report();
NSRecordContent::report();
ARecordContent::report();
reportAllTypes();
}
catch (PDNSException& ex) {
BOOST_TEST_MESSAGE("Cannot start remotebackend: " << ex.reason);
Expand Down
8 changes: 4 additions & 4 deletions pdns/dnsparser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "namespaces.hh"
#include "noinitvector.hh"

bool DNSRecordContent::d_locked{false};
std::atomic<bool> DNSRecordContent::d_locked{false};

UnknownRecordContent::UnknownRecordContent(const string& zone)
{
Expand Down Expand Up @@ -80,7 +80,7 @@ void UnknownRecordContent::toPacket(DNSPacketWriter& pw) const
pw.xfrBlob(string(d_record.begin(),d_record.end()));
}

shared_ptr<DNSRecordContent> DNSRecordContent::deserialize(const DNSName& qname, uint16_t qtype, const string& serialized)
shared_ptr<DNSRecordContent> DNSRecordContent::deserialize(const DNSName& qname, uint16_t qtype, const string& serialized, uint16_t qclass)
{
dnsheader dnsheader;
memset(&dnsheader, 0, sizeof(dnsheader));
Expand All @@ -102,7 +102,7 @@ shared_ptr<DNSRecordContent> DNSRecordContent::deserialize(const DNSName& qname,

struct dnsrecordheader drh;
drh.d_type=htons(qtype);
drh.d_class=htons(QClass::IN);
drh.d_class=htons(qclass);
drh.d_ttl=0;
drh.d_clen=htons(serialized.size());

Expand All @@ -114,7 +114,7 @@ shared_ptr<DNSRecordContent> DNSRecordContent::deserialize(const DNSName& qname,
}

DNSRecord dr;
dr.d_class = QClass::IN;
dr.d_class = qclass;
dr.d_type = qtype;
dr.d_name = qname;
dr.d_clen = serialized.size();
Expand Down
9 changes: 5 additions & 4 deletions pdns/dnsparser.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#pragma once
#include <atomic>
#include <map>
#include <sstream>
#include <stdexcept>
Expand Down Expand Up @@ -225,7 +226,7 @@ public:
}

// parse the content in wire format, possibly including compressed pointers pointing to the owner name
static shared_ptr<DNSRecordContent> deserialize(const DNSName& qname, uint16_t qtype, const string& serialized);
static shared_ptr<DNSRecordContent> deserialize(const DNSName& qname, uint16_t qtype, const string& serialized, uint16_t qclass=QClass::IN);

void doRecordCheck(const struct DNSRecord&){}

Expand All @@ -234,7 +235,7 @@ public:

static void regist(uint16_t cl, uint16_t ty, makerfunc_t* f, zmakerfunc_t* z, const char* name)
{
assert(!d_locked); // NOLINT: it's the API
assert(!d_locked.load()); // NOLINT: it's the API
if(f)
getTypemap()[pair(cl,ty)]=f;
if(z)
Expand Down Expand Up @@ -280,7 +281,7 @@ public:

static void lock()
{
d_locked = true;
d_locked.store(true);
}

protected:
Expand All @@ -292,7 +293,7 @@ protected:
static t2namemap_t& getT2Namemap();
static n2typemap_t& getN2Typemap();
static zmakermap_t& getZmakermap();
static bool d_locked;
static std::atomic<bool> d_locked;
};

struct DNSRecord
Expand Down
137 changes: 73 additions & 64 deletions pdns/dnsrecords.cc
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,9 @@ boilerplate_conv(LP,
conv.xfrName(d_fqdn, false);)

/* EUI48 start */
void EUI48RecordContent::report()
void EUI48RecordContent::report(const ReportIsOnlyCallableByReportAllTypes& guard)
{
(void)guard;
regist(1, QType::EUI48, &make, &make, "EUI48");
}
std::shared_ptr<DNSRecordContent> EUI48RecordContent::make(const DNSRecord &dr, PacketReader& pr)
Expand Down Expand Up @@ -502,8 +503,9 @@ string EUI48RecordContent::getZoneRepresentation(bool /* noDot */) const

/* EUI64 start */

void EUI64RecordContent::report()
void EUI64RecordContent::report(const ReportIsOnlyCallableByReportAllTypes& guard)
{
(void)guard;
regist(1, QType::EUI64, &make, &make, "EUI64");
}
std::shared_ptr<DNSRecordContent> EUI64RecordContent::make(const DNSRecord &dr, PacketReader& pr)
Expand Down Expand Up @@ -548,8 +550,9 @@ string EUI64RecordContent::getZoneRepresentation(bool /* noDot */) const

/* APL start */
/* https://tools.ietf.org/html/rfc3123 */
void APLRecordContent::report()
void APLRecordContent::report(const ReportIsOnlyCallableByReportAllTypes& guard)
{
(void)guard;
regist(1, QType::APL, &make, &make, "APL");
}

Expand Down Expand Up @@ -906,85 +909,91 @@ bool getEDNSOpts(const MOADNSParser& mdp, EDNSOpts* eo)
return false;
}

void reportBasicTypes()
static void reportBasicTypes(const ReportIsOnlyCallableByReportAllTypes& guard)
{
ARecordContent::report();
AAAARecordContent::report();
NSRecordContent::report();
CNAMERecordContent::report();
MXRecordContent::report();
SOARecordContent::report();
SRVRecordContent::report();
PTRRecordContent::report();
ARecordContent::report(guard);
AAAARecordContent::report(guard);
NSRecordContent::report(guard);
CNAMERecordContent::report(guard);
MXRecordContent::report(guard);
SOARecordContent::report(guard);
SRVRecordContent::report(guard);
PTRRecordContent::report(guard);
DNSRecordContent::regist(QClass::CHAOS, QType::TXT, &TXTRecordContent::make, &TXTRecordContent::make, "TXT");
TXTRecordContent::report();
TXTRecordContent::report(guard);
#ifdef HAVE_LUA_RECORDS
LUARecordContent::report();
LUARecordContent::report(guard);
#endif
DNSRecordContent::regist(QClass::IN, QType::ANY, nullptr, nullptr, "ANY");
DNSRecordContent::regist(QClass::IN, QType::AXFR, nullptr, nullptr, "AXFR");
DNSRecordContent::regist(QClass::IN, QType::IXFR, nullptr, nullptr, "IXFR");
}

void reportOtherTypes()
static void reportOtherTypes(const ReportIsOnlyCallableByReportAllTypes& guard)
{
MBRecordContent::report();
MGRecordContent::report();
MRRecordContent::report();
AFSDBRecordContent::report();
DNAMERecordContent::report();
MBRecordContent::report(guard);
MGRecordContent::report(guard);
MRRecordContent::report(guard);
AFSDBRecordContent::report(guard);
DNAMERecordContent::report(guard);
#if !defined(RECURSOR)
ALIASRecordContent::report();
ALIASRecordContent::report(guard);
#endif
SPFRecordContent::report();
NAPTRRecordContent::report();
KXRecordContent::report();
LOCRecordContent::report();
ENTRecordContent::report();
HINFORecordContent::report();
RPRecordContent::report();
KEYRecordContent::report();
DNSKEYRecordContent::report();
DHCIDRecordContent::report();
CDNSKEYRecordContent::report();
RKEYRecordContent::report();
RRSIGRecordContent::report();
DSRecordContent::report();
CDSRecordContent::report();
SSHFPRecordContent::report();
CERTRecordContent::report();
NSECRecordContent::report();
NSEC3RecordContent::report();
NSEC3PARAMRecordContent::report();
TLSARecordContent::report();
SMIMEARecordContent::report();
OPENPGPKEYRecordContent::report();
SVCBRecordContent::report();
HTTPSRecordContent::report();
DLVRecordContent::report();
SPFRecordContent::report(guard);
NAPTRRecordContent::report(guard);
KXRecordContent::report(guard);
LOCRecordContent::report(guard);
ENTRecordContent::report(guard);
HINFORecordContent::report(guard);
RPRecordContent::report(guard);
KEYRecordContent::report(guard);
DNSKEYRecordContent::report(guard);
DHCIDRecordContent::report(guard);
CDNSKEYRecordContent::report(guard);
RKEYRecordContent::report(guard);
RRSIGRecordContent::report(guard);
DSRecordContent::report(guard);
CDSRecordContent::report(guard);
SSHFPRecordContent::report(guard);
CERTRecordContent::report(guard);
NSECRecordContent::report(guard);
NSEC3RecordContent::report(guard);
NSEC3PARAMRecordContent::report(guard);
TLSARecordContent::report(guard);
SMIMEARecordContent::report(guard);
OPENPGPKEYRecordContent::report(guard);
SVCBRecordContent::report(guard);
HTTPSRecordContent::report(guard);
DLVRecordContent::report(guard);
DNSRecordContent::regist(QClass::ANY, QType::TSIG, &TSIGRecordContent::make, &TSIGRecordContent::make, "TSIG");
DNSRecordContent::regist(QClass::ANY, QType::TKEY, &TKEYRecordContent::make, &TKEYRecordContent::make, "TKEY");
//TSIGRecordContent::report();
OPTRecordContent::report();
EUI48RecordContent::report();
EUI64RecordContent::report();
MINFORecordContent::report();
URIRecordContent::report();
CAARecordContent::report();
APLRecordContent::report();
IPSECKEYRecordContent::report();
CSYNCRecordContent::report();
NIDRecordContent::report();
L32RecordContent::report();
L64RecordContent::report();
LPRecordContent::report();
ZONEMDRecordContent::report();
//TSIGRecordContent::report(guard);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
OPTRecordContent::report(guard);
EUI48RecordContent::report(guard);
EUI64RecordContent::report(guard);
MINFORecordContent::report(guard);
URIRecordContent::report(guard);
CAARecordContent::report(guard);
APLRecordContent::report(guard);
IPSECKEYRecordContent::report(guard);
CSYNCRecordContent::report(guard);
NIDRecordContent::report(guard);
L32RecordContent::report(guard);
L64RecordContent::report(guard);
LPRecordContent::report(guard);
ZONEMDRecordContent::report(guard);
}

struct ReportIsOnlyCallableByReportAllTypes
{
};

void reportAllTypes()
{
reportBasicTypes();
reportOtherTypes();
ReportIsOnlyCallableByReportAllTypes guard;
reportBasicTypes(guard);
reportOtherTypes(guard);
DNSRecordContent::lock();
}

ComboAddress getAddr(const DNSRecord& dr, uint16_t defport)
Expand Down
Loading

0 comments on commit b6a8c99

Please sign in to comment.