Also use UnknownDomainID instead of -1.
Update all users, remove casts and lint conversion annotations.
{
public:
virtual unsigned int getCapabilities()=0;
- virtual void lookup(const QType &qtype, const string &qdomain, int zoneId=-1, DNSPacket *pkt_p=nullptr)=0;
- virtual bool list(const string &target, int domain_id)=0;
+ virtual void lookup(const QType &qtype, const string &qdomain, domainid_t zoneId=UnknownDomainID, DNSPacket *pkt_p=nullptr)=0;
+ virtual bool list(const string &target, domainid_t domain_id)=0;
virtual bool get(DNSResourceRecord &r)=0;
virtual bool getSOA(const string &name, SOAData &soadata);
};
public:
unsigned int getCapabilities() override { return 0; }
- bool list(const string &target, int id)
+ bool list(const string &target, domainid_t id)
{
return false; // we don't support pdnsutil list-zone or AXFR
}
- void lookup(const QType &type, const string &qdomain, int zoneId, DNSPacket *p)
+ void lookup(const QType &type, const string &qdomain, domainid_t zoneId, DNSPacket *p)
{
if(type.getCode()!=QType::A || qdomain!="random.powerdns.com") // we only know about random.powerdns.com A
d_answer=""; // no answer
Time To Live of this record
-.. cpp:member:: int DNSResourceRecord::domain_id
+.. cpp:member:: domainid_t DNSResourceRecord::domain_id
ID of the domain this record belongs to
Minimum acceptable value for TTL
-.. cpp:member:: int SOAData::domain_id
+.. cpp:member:: domainid_t SOAData::domain_id
The ID of the domain within this backend. Must be filled!
* `CAP_DNSSEC` Backend implements :ref:`backend-dnssec`.
* `CAP_LIST` Backend implements `list`, for AXFR or `pdnsutil list-zone`
-.. cpp:function:: void DNSBackend::lookup(const QType &qtype, const string &qdomain, int zoneId=-1, DNSPacket *pkt=nullptr)
+.. cpp:function:: void DNSBackend::lookup(const QType &qtype, const string &qdomain, domainid_t zoneId=UnknownDomainID, DNSPacket *pkt=nullptr)
This function is used to initiate a straight lookup for a record of name
'qdomain' and type 'qtype'. A QType can be converted into an integer by
It is legal to return here, and have the first call to ``get()`` return
false. This is interpreted as 'no data'.
-.. cpp:function:: bool DNSBackend::list(int domain_id, bool include_disabled=false)
+.. cpp:function:: bool DNSBackend::list(domainid_t domain_id, bool include_disabled=false)
Initiates a list of the indicated domain. Records should then be made
available via the ``get()`` method. Need not include the SOA record. If
/* ... */
virtual bool getDomainInfo(const string &domain, DomainInfo &di, bool getSerial = true);
virtual bool isPrimary(const ComboAddress& ipAddress);
- virtual bool startTransaction(const string &qname, int id);
+ virtual bool startTransaction(const string &qname, domainid_t id);
virtual bool commitTransaction();
virtual bool abortTransaction();
virtual bool feedRecord(const DNSResourceRecord &rr, const DNSName &ordername, bool ordernameIsNSEC3 = false);
virtual void getUnfreshSecondaryInfos(vector<DomainInfo>* domains);
- virtual void setFresh(uint32_t id);
+ virtual void setFresh(domainid_t id);
/* ... */
}
.. cpp:struct:: DomainInfo
-.. cpp:member:: uint32_t DomainInfo::id
+.. cpp:member:: domainid_t DomainInfo::id
ID of this zone within this backend
backend considers itself authoritative for the named zone, ``di`` should
be filled out, and 'true' be returned. Otherwise return false.
-.. cpp:function:: bool DomainInfo::startTransaction(const string &qname, int id)
+.. cpp:function:: bool DomainInfo::startTransaction(const string &qname, domainid_t id)
When called, the backend should start a transaction that can be
committed or rolled back atomically later on. In SQL terms, this
- function should **BEGIN** a transaction and **DELETE** all records.
+ function should **BEGIN** a transaction, and **DELETE** all records for
+ the domain matching the given ``id``, unless its value is
+ ``UnknownDomainID``.
.. cpp:function:: bool DomainInfo::feedRecord(const DNSResourceRecord &rr, const DNSName &ordername, bool ordernameIsNSEC3)
Abort changes. In SQL terms, execute **ABORT**.
-.. cpp:function:: bool DomainInfo::setFresh()
+.. cpp:function:: bool DomainInfo::setFresh(domainid_t id)
Indicate that a domain has either been updated or refreshed without the
need for a retransfer. This causes the domain to vanish from the vector
public:
/* ... */
virtual void getUpdatedPrimaries(vector<DomainInfo>* domains, std::unordered_set<DNSName> &catalogs, CatalogHashMap &catalogHashes);
- virtual void setNotified(uint32_t id, uint32_t serial);
+ virtual void setNotified(domainid_t id, uint32_t serial);
/* ... */
}
When called, the backend should examine its list of primary domains and
add any changed ones to the :cpp:class:`DomainInfo` vector.
-.. cpp:function:: void DNSBackend::setNotified(uint32_t domain_id, uint32_t serial)
+.. cpp:function:: void DNSBackend::setNotified(domainid_t domain_id, uint32_t serial)
Indicate that notifications have been queued for this domain and that it
need not be considered 'updated' anymore.
class DNSBackend {
public:
/* ... */
- virtual bool startTransaction(const DNSName &qname, int id);
+ virtual bool startTransaction(const DNSName &qname, domainid_t id);
virtual bool commitTransaction();
virtual bool abortTransaction();
virtual bool feedRecord(const DNSResourceRecord &rr, DNSName &ordername, bool ordernameIsNSEC3);
- virtual bool replaceRRSet(uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset)
- virtual bool listSubZone(const DNSName &zone, int domain_id);
+ virtual bool replaceRRSet(domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset)
+ virtual bool listSubZone(const DNSName &zone, domainid_t domain_id);
/* ... */
}
-.. cpp:function:: virtual bool DNSBackend::startTransaction(const DNSName &qname, int id)
+.. cpp:function:: virtual bool DNSBackend::startTransaction(const DNSName &qname, domainid_t id)
See :cpp:func:`above <DNSBackend::beginTransaction>`. Please
- note that this function now receives a negative number (-1), which
- indicates that the current zone data should NOT be deleted.
+ note that if this function receives ``UnknownDomainID`` as the ``id``,
+ the current zone data should NOT be deleted.
.. cpp:function:: virtual bool DNSBackend::commitTransaction()
Please keep in mind that the zone is not empty because
``startTransaction()`` was called differently.
-.. cpp:function:: virtual bool DNSBackend::listSubZone(const DNSName &name, int domain_id)
+.. cpp:function:: virtual bool DNSBackend::listSubZone(const DNSName &name, domainid_t domain_id)
This method is needed for rectification of a zone after NS-records have
been added. For DNSSEC, we need to know which records are below the
ENT-records in PowerDNS. Make sure it returns every record in the tree
below the given record.
-.. cpp:function:: virtual bool DNSBackend::replaceRRSet(uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset)
+.. cpp:function:: virtual bool DNSBackend::replaceRRSet(domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset)
This method should remove all the records with ``qname`` of type ``qt``.
``qt`` might also be ANY, which means all the records with that
virtual unsigned int getCapabilities();
/* ... */
- virtual bool getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after);
+ virtual bool getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after);
/* update operations */
- virtual bool updateDNSSECOrderNameAndAuth(uint32_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype=QType::ANY);
- virtual bool updateEmptyNonTerminals(uint32_t domain_id, set<DNSName>& insert, set<DNSName>& erase, bool remove);
- virtual bool feedEnts(int domain_id, map<DNSName,bool> &nonterm);
- virtual bool feedEnts3(int domain_id, const DNSName &domain, map<DNSName,bool> &nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow);
+ virtual bool updateDNSSECOrderNameAndAuth(domainid_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype=QType::ANY);
+ virtual bool updateEmptyNonTerminals(domainid_t domain_id, set<DNSName>& insert, set<DNSName>& erase, bool remove);
+ virtual bool feedEnts(domainid_t domain_id, map<DNSName,bool> &nonterm);
+ virtual bool feedEnts3(domainid_t domain_id, const DNSName &domain, map<DNSName,bool> &nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow);
/* keys management */
virtual bool getDomainKeys(const DNSName& name, std::vector<KeyData>& keys);
In addition to these methods, the return value of `getCapabilities` must
contain `CAP_DNSSEC` if that backend supports DNSSEC.
-.. cpp:function:: virtual bool getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
+.. cpp:function:: virtual bool getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
Asks the names before and after qname for NSEC and NSEC3. The qname will be hashed when using NSEC3. Care must be taken to handle wrap-around when qname is the first or last in the ordered list of zone names.
Please note that in case the requested name is present in the zone, it should be returned as the "before" name.
-.. cpp:function:: virtual bool updateDNSSECOrderNameAndAuth(uint32_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype=QType::ANY)
+.. cpp:function:: virtual bool updateDNSSECOrderNameAndAuth(domainid_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype=QType::ANY)
Updates the ordername and auth fields.
-.. cpp:function:: virtual bool updateEmptyNonTerminals(uint32_t domain_id, set<DNSName>& insert, set<DNSName>& erase, bool remove)
+.. cpp:function:: virtual bool updateEmptyNonTerminals(domainid_t domain_id, set<DNSName>& insert, set<DNSName>& erase, bool remove)
Updates ENT after a zone has been rectified. If 'remove' is false, 'erase' contains a list of ENTs to remove from the zone before adding any. Otherwise all ENTs should be removed from the zone before adding any. 'insert' contains the list of ENTs to add to the zone after the removals have been done.
-.. cpp:function:: virtual bool feedEnts(int domain_id, map<DNSName,bool> &nonterm)
+.. cpp:function:: virtual bool feedEnts(domainid_t domain_id, map<DNSName,bool> &nonterm)
This method is used by ``pdnsutil rectify-zone`` to populate missing non-terminals. This is used when you have, say, record like _sip._upd.example.com, but no _udp.example.com. PowerDNS requires that there exists a non-terminal in between, and this instructs you to add one.
-.. cpp:function:: virtual bool feedEnts3(int domain_id, const DNSName &domain, map<DNSName,bool> &nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow)
+.. cpp:function:: virtual bool feedEnts3(domainid_t domain_id, const DNSName &domain, map<DNSName,bool> &nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow)
Same as feedEnts, but provides NSEC3 hashing parameters.
struct DNSZoneRecord
{
- int domain_id{-1};
+ domainid_t domain_id{UnknownDomainID};
uint8_t scopeMask{0};
int signttl{0};
DNSName wildcardname;
class DNSResourceRecord
{
public:
- DNSResourceRecord() : last_modified(0), ttl(0), signttl(0), domain_id(-1), qclass(1), scopeMask(0), auth(true), disabled(false) {};
+ DNSResourceRecord() : last_modified(0), ttl(0), signttl(0), domain_id(UnknownDomainID), qclass(1), scopeMask(0), auth(true), disabled(false) {};
static DNSResourceRecord fromWire(const DNSRecord& d);
void setContent(const string& content);
uint32_t ttl; //!< Time To Live of this record
uint32_t signttl; //!< If non-zero, use this TTL as original TTL in the RRSIG
- int domain_id; //!< If a backend implements this, the domain_id of the zone this record is in
+ domainid_t domain_id; //!< If a backend implements this, the domain_id of the zone this record is in
QType qtype; //!< qtype of this record, ie A, CNAME, MX etc
uint16_t qclass; //!< class of this record
d_ctime = buf.st_ctime;
}
-bool Bind2Backend::safeGetBBDomainInfo(int id, BB2DomainInfo* bbd)
+// NOLINTNEXTLINE(readability-identifier-length)
+bool Bind2Backend::safeGetBBDomainInfo(domainid_t id, BB2DomainInfo* bbd)
{
auto state = s_state.read_lock();
state_t::const_iterator iter = state->find(id);
replacing_insert(*state, bbd);
}
-void Bind2Backend::setNotified(uint32_t id, uint32_t serial)
+// NOLINTNEXTLINE(readability-identifier-length)
+void Bind2Backend::setNotified(domainid_t id, uint32_t serial)
{
BB2DomainInfo bbd;
if (!safeGetBBDomainInfo(id, &bbd))
safePutBBDomainInfo(bbd);
}
-void Bind2Backend::setLastCheck(uint32_t domain_id, time_t lastcheck)
+// NOLINTNEXTLINE(readability-identifier-length)
+void Bind2Backend::setLastCheck(domainid_t domain_id, time_t lastcheck)
{
BB2DomainInfo bbd;
if (safeGetBBDomainInfo(domain_id, &bbd)) {
}
}
-void Bind2Backend::setStale(uint32_t domain_id)
+void Bind2Backend::setStale(domainid_t domain_id)
{
- setLastCheck(domain_id, 0);
+ Bind2Backend::setLastCheck(domain_id, 0);
}
-void Bind2Backend::setFresh(uint32_t domain_id)
+void Bind2Backend::setFresh(domainid_t domain_id)
{
- setLastCheck(domain_id, time(nullptr));
+ Bind2Backend::setLastCheck(domain_id, time(nullptr));
}
-bool Bind2Backend::startTransaction(const ZoneName& qname, int domainId)
+bool Bind2Backend::startTransaction(const ZoneName& qname, domainid_t domainId)
{
- if (domainId < 0) {
+ if (domainId == UnknownDomainID) {
d_transaction_tmpname.clear();
- d_transaction_id = domainId;
+ d_transaction_id = UnknownDomainID;
+ // No support for domain contents deletion
return false;
}
if (domainId == 0) {
bool Bind2Backend::commitTransaction()
{
- if (d_transaction_id < 0)
+ if (d_transaction_id == UnknownDomainID) {
return false;
+ }
d_of.reset();
BB2DomainInfo bbd;
queueReloadAndStore(bbd.d_id);
}
- d_transaction_id = 0;
+ d_transaction_id = UnknownDomainID;
return true;
}
// -1 = dnssec speciality
// 0 = invalid transact
// >0 = actual transaction
- if (d_transaction_id > 0) {
+ if (d_transaction_id != UnknownDomainID) {
unlink(d_transaction_tmpname.c_str());
d_of.reset();
- d_transaction_id = 0;
+ d_transaction_id = UnknownDomainID;
}
return true;
bool Bind2Backend::feedRecord(const DNSResourceRecord& rr, const DNSName& /* ordername */, bool /* ordernameIsNSEC3 */)
{
- if (d_transaction_id < 1) {
+ if (d_transaction_id == UnknownDomainID) {
throw DBException("Bind2Backend::feedRecord() called outside of transaction");
}
throw PDNSException("bind-hybrid and the zone cache currently interoperate badly. Please disable the zone cache or stop using bind-hybrid");
}
- d_transaction_id = 0;
+ d_transaction_id = UnknownDomainID;
s_ignore_broken_records = mustDo("ignore-broken-records");
d_upgradeContent = ::arg().mustDo("upgrade-unknown-types");
}
}
-void Bind2Backend::queueReloadAndStore(unsigned int id)
+// NOLINTNEXTLINE(readability-identifier-length)
+void Bind2Backend::queueReloadAndStore(domainid_t id)
{
BB2DomainInfo bbold;
try {
return true;
}
-bool Bind2Backend::getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
+// NOLINTNEXTLINE(readability-identifier-length)
+bool Bind2Backend::getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
{
BB2DomainInfo bbd;
if (!safeGetBBDomainInfo(id, &bbd))
}
}
-void Bind2Backend::lookup(const QType& qtype, const DNSName& qname, int zoneId, DNSPacket* /* pkt_p */)
+void Bind2Backend::lookup(const QType& qtype, const DNSName& qname, domainid_t zoneId, DNSPacket* /* pkt_p */)
{
d_handle.reset();
if (mustlog)
g_log << Logger::Warning << "Lookup for '" << qtype.toString() << "' of '" << qname << "' within zoneID " << zoneId << endl;
- if (zoneId >= 0) {
+ if (zoneId != UnknownDomainID) {
if ((found = (safeGetBBDomainInfo(zoneId, &bbd) && qname.isPartOf(bbd.d_name)))) {
domain = std::move(bbd.d_name);
}
return true;
}
-bool Bind2Backend::list(const ZoneName& /* target */, int domainId, bool /* include_disabled */)
+bool Bind2Backend::list(const ZoneName& /* target */, domainid_t domainId, bool /* include_disabled */)
{
BB2DomainInfo bbd;
BB2DomainInfo Bind2Backend::createDomainEntry(const ZoneName& domain, const string& filename)
{
- int newid = 1;
+ domainid_t newid = 1;
{ // Find a free zone id nr.
auto state = s_state.read_lock();
if (!state->empty()) {
bool getDomainInfo(const ZoneName& domain, DomainInfo& info, bool getSerial = true) override;
time_t getCtime(const string& fname);
// DNSSEC
- bool getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override;
- void lookup(const QType&, const DNSName& qdomain, int zoneId, DNSPacket* p = nullptr) override;
- bool list(const ZoneName& target, int domainId, bool include_disabled = false) override;
+ bool getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override;
+ void lookup(const QType& qtype, const DNSName& qname, domainid_t zoneId, DNSPacket* p = nullptr) override;
+ bool list(const ZoneName& target, domainid_t domainId, bool include_disabled = false) override;
bool get(DNSResourceRecord&) override;
void getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled = false) override;
static DNSBackend* maker();
static std::mutex s_startup_lock;
- void setStale(uint32_t domain_id) override;
- void setFresh(uint32_t domain_id) override;
- void setNotified(uint32_t id, uint32_t serial) override;
- bool startTransaction(const ZoneName& qname, int domainId) override;
+ void setStale(domainid_t domain_id) override;
+ void setFresh(domainid_t domain_id) override;
+ void setNotified(domainid_t id, uint32_t serial) override;
+ bool startTransaction(const ZoneName& qname, domainid_t domainId) override;
bool feedRecord(const DNSResourceRecord& rr, const DNSName& ordername, bool ordernameIsNSEC3 = false) override;
bool commitTransaction() override;
bool abortTransaction() override;
void setupDNSSEC();
void setupStatements();
void freeStatements();
- static bool safeGetBBDomainInfo(int id, BB2DomainInfo* bbd);
+ static bool safeGetBBDomainInfo(domainid_t id, BB2DomainInfo* bbd);
static void safePutBBDomainInfo(const BB2DomainInfo& bbd);
static bool safeGetBBDomainInfo(const ZoneName& name, BB2DomainInfo* bbd);
static bool safeRemoveBBDomainInfo(const ZoneName& name);
shared_ptr<SSQLite3> d_dnssecdb;
bool getNSEC3PARAM(const ZoneName& name, NSEC3PARAMRecordContent* ns3p);
- void setLastCheck(uint32_t domain_id, time_t lastcheck);
+ static void setLastCheck(domainid_t domain_id, time_t lastcheck);
bool getNSEC3PARAMuncached(const ZoneName& name, NSEC3PARAMRecordContent* ns3p);
class handle
{
DNSName qname;
ZoneName domain;
- int id{-1};
+ domainid_t id{UnknownDomainID};
QType qtype;
bool d_list{false};
bool mustlog{false};
handle d_handle;
static string s_binddirectory; //!< this is used to store the 'directory' setting of the bind configuration
static int s_first; //!< this is raised on construction to prevent multiple instances of us being generated
- int d_transaction_id;
+ domainid_t d_transaction_id;
static bool s_ignore_broken_records;
bool d_hybrid;
bool d_upgradeContent;
BB2DomainInfo createDomainEntry(const ZoneName& domain, const string& filename); //!< does not insert in s_state
- void queueReloadAndStore(unsigned int id);
+ void queueReloadAndStore(domainid_t id);
static bool findBeforeAndAfterUnhashed(std::shared_ptr<const recordstorage_t>& records, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after);
static void insertRecord(std::shared_ptr<recordstorage_t>& records, const ZoneName& zoneName, const DNSName& qname, const QType& qtype, const string& content, int ttl, const std::string& hashed = string(), const bool* auth = nullptr);
void reload() override;
struct GeoIPDomain
{
- std::uint32_t id{};
+ domainid_t id{};
ZoneName domain;
int ttl{};
map<DNSName, GeoIPService> services;
static vector<GeoIPDNSResourceRecord> makeDNSResourceRecord(GeoIPDomain& dom, DNSName name)
{
GeoIPDNSResourceRecord resourceRecord;
- resourceRecord.domain_id = static_cast<int>(dom.id);
+ resourceRecord.domain_id = dom.id;
resourceRecord.ttl = dom.ttl;
resourceRecord.qname = std::move(name);
resourceRecord.qtype = QType(0); // empty non terminal
}
}
-bool GeoIPBackend::loadDomain(const YAML::Node& domain, std::uint32_t domainID, GeoIPDomain& dom)
+bool GeoIPBackend::loadDomain(const YAML::Node& domain, domainid_t domainID, GeoIPDomain& dom)
{
try {
dom.id = domainID;
for (auto item = recs->second.begin(); item != recs->second.end(); item++) {
auto rec = item->begin();
GeoIPDNSResourceRecord rr;
- rr.domain_id = static_cast<int>(dom.id);
+ rr.domain_id = dom.id;
rr.ttl = dom.ttl;
rr.qname = qname.operator const DNSName&();
if (rec->first.IsNull()) {
return false;
};
-void GeoIPBackend::lookup(const QType& qtype, const DNSName& qdomain, int zoneId, DNSPacket* pkt_p)
+void GeoIPBackend::lookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId, DNSPacket* pkt_p)
{
ReadLock rl(&s_state_lock);
const GeoIPDomain* dom;
d_result.clear();
- if (zoneId > -1 && zoneId < static_cast<int>(s_domains.size()))
+ if (zoneId >= 0 && zoneId < static_cast<domainid_t>(s_domains.size())) {
dom = &(s_domains[zoneId]);
+ }
else {
for (const GeoIPDomain& i : s_domains) { // this is arguably wrong, we should probably find the most specific match
if (qdomain.isPartOf(i.domain)) {
return caps;
}
- void lookup(const QType& qtype, const DNSName& qdomain, int zoneId, DNSPacket* pkt_p = nullptr) override;
- bool list(const ZoneName& /* target */, int /* domain_id */, bool /* include_disabled */ = false) override { return false; } // not supported
+ void lookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId, DNSPacket* pkt_p = nullptr) override;
+ bool list(const ZoneName& /* target */, domainid_t /* domain_id */, bool /* include_disabled */ = false) override { return false; } // not supported
bool get(DNSResourceRecord& r) override;
void reload() override;
void rediscover(string* status = nullptr) override;
bool hasDNSSECkey(const ZoneName& name);
bool lookup_static(const GeoIPDomain& dom, const DNSName& search, const QType& qtype, const DNSName& qdomain, const Netmask& addr, GeoIPNetmask& gl);
void setupNetmasks(const YAML::Node& domain, GeoIPDomain& dom);
- bool loadDomain(const YAML::Node& domain, std::uint32_t domainID, GeoIPDomain& dom);
+ bool loadDomain(const YAML::Node& domain, domainid_t domainID, GeoIPDomain& dom);
void loadDomainsFromDirectory(const std::string& dir, vector<GeoIPDomain>& domains);
vector<DNSResourceRecord> d_result;
vector<GeoIPInterface> d_files;
PowerLDAP* d_pldap;
LdapAuthenticator* d_authenticator;
- bool (LdapBackend::*d_list_fcnt)(const ZoneName&, int);
- void (LdapBackend::*d_lookup_fcnt)(const QType&, const DNSName&, DNSPacket*, int);
+ bool (LdapBackend::*d_list_fcnt)(const ZoneName&, domainid_t);
+ void (LdapBackend::*d_lookup_fcnt)(const QType&, const DNSName&, DNSPacket*, domainid_t);
- bool list_simple(const ZoneName& target, int domain_id);
- bool list_strict(const ZoneName& target, int domain_id);
+ bool list_simple(const ZoneName& target, domainid_t domain_id);
+ bool list_strict(const ZoneName& target, domainid_t domain_id);
- void lookup_simple(const QType& qtype, const DNSName& qdomain, DNSPacket* p, int zoneid);
- void lookup_strict(const QType& qtype, const DNSName& qdomain, DNSPacket* p, int zoneid);
- void lookup_tree(const QType& qtype, const DNSName& qdomain, DNSPacket* p, int zoneid);
+ void lookup_simple(const QType& qtype, const DNSName& qname, DNSPacket* p, domainid_t zoneid);
+ void lookup_strict(const QType& qtype, const DNSName& qname, DNSPacket* p, domainid_t zoneid);
+ void lookup_tree(const QType& qtype, const DNSName& qname, DNSPacket* p, domainid_t zoneid);
bool reconnect();
// Native backend
unsigned int getCapabilities() override { return CAP_LIST; }
- bool list(const ZoneName& target, int domain_id, bool include_disabled = false) override;
- void lookup(const QType& qtype, const DNSName& qdomain, int zoneid, DNSPacket* p = nullptr) override;
+ bool list(const ZoneName& target, domainid_t domain_id, bool include_disabled = false) override;
+ void lookup(const QType& qtype, const DNSName& qname, domainid_t zoneid, DNSPacket* dnspkt = nullptr) override;
bool get(DNSResourceRecord& rr) override;
bool getDomainInfo(const ZoneName& domain, DomainInfo& info, bool getSerial = true) override;
// Primary backend
void getUpdatedPrimaries(vector<DomainInfo>& domains, std::unordered_set<DNSName>& catalogs, CatalogHashMap& catalogHashes) override;
- void setNotified(uint32_t id, uint32_t serial) override;
+ void setNotified(domainid_t id, uint32_t serial) override;
};
"PdnsRecordOrdername",
nullptr};
-bool LdapBackend::list(const ZoneName& target, int domain_id, bool /* include_disabled */)
+bool LdapBackend::list(const ZoneName& target, domainid_t domain_id, bool /* include_disabled */)
{
try {
d_in_list = true;
return false;
}
-bool LdapBackend::list_simple(const ZoneName& target, int /* domain_id */)
+bool LdapBackend::list_simple(const ZoneName& target, domainid_t /* domain_id */)
{
string dn;
string filter;
return true;
}
-bool LdapBackend::list_strict(const ZoneName& target, int domain_id)
+bool LdapBackend::list_strict(const ZoneName& target, domainid_t domain_id)
{
if (target.isPartOf(DNSName("in-addr.arpa")) || target.isPartOf(DNSName("ip6.arpa"))) {
g_log << Logger::Warning << d_myname << " Request for reverse zone AXFR, but this is not supported in strict mode" << endl;
return list_simple(target, domain_id);
}
-void LdapBackend::lookup(const QType& qtype, const DNSName& qname, int zoneid, DNSPacket* dnspkt)
+void LdapBackend::lookup(const QType& qtype, const DNSName& qname, domainid_t zoneid, DNSPacket* dnspkt)
{
try {
d_in_list = false;
}
}
-void LdapBackend::lookup_simple(const QType& qtype, const DNSName& qname, DNSPacket* /* dnspkt */, int /* zoneid */)
+void LdapBackend::lookup_simple(const QType& qtype, const DNSName& qname, DNSPacket* /* dnspkt */, domainid_t /* zoneid */)
{
string filter, attr, qesc;
const char** attributes = ldap_attrany + 1; // skip associatedDomain
d_search = d_pldap->search(getArg("basedn"), LDAP_SCOPE_SUBTREE, filter, attributes);
}
-void LdapBackend::lookup_strict(const QType& qtype, const DNSName& qname, DNSPacket* /* dnspkt */, int /* zoneid */)
+void LdapBackend::lookup_strict(const QType& qtype, const DNSName& qname, DNSPacket* /* dnspkt */, domainid_t /* zoneid */)
{
int len;
vector<string> parts;
d_search = d_pldap->search(getArg("basedn"), LDAP_SCOPE_SUBTREE, filter, attributes);
}
-void LdapBackend::lookup_tree(const QType& qtype, const DNSName& qname, DNSPacket* /* dnspkt */, int /* zoneid */)
+void LdapBackend::lookup_tree(const QType& qtype, const DNSName& qname, DNSPacket* /* dnspkt */, domainid_t /* zoneid */)
{
string filter, attr, qesc, dn;
const char** attributes = ldap_attrany + 1; // skip associatedDomain
fillSOAData(result["sOARecord"][0], sd);
if (result.count("PdnsDomainId") && !result["PdnsDomainId"].empty())
- info.id = std::stoi(result["PdnsDomainId"][0]);
+ info.id = static_cast<domainid_t>(std::stoll(result["PdnsDomainId"][0]));
else
info.id = 0;
}
}
-void LdapBackend::setNotified(uint32_t id, uint32_t serial)
+// NOLINTNEXTLINE(readability-identifier-length)
+void LdapBackend::setNotified(domainid_t id, uint32_t serial)
{
string filter;
PowerLDAP::SearchResult::Ptr search;
ar & g.last_check;
ar & g.account;
ar & g.primaries;
- ar & g.id;
+ ar& static_cast<uint32_t>(g.id);
ar & g.notified_serial;
ar & g.kind;
ar & g.options;
ar & g.last_check;
ar & g.account;
ar & g.primaries;
- ar & g.id;
+ uint32_t domainId{0};
+ ar & domainId;
+ g.id = static_cast<domainid_t>(domainId);
ar & g.notified_serial;
ar & g.kind;
if (version >= 1) {
#define StringView string
#endif
-void LMDBBackend::deleteDomainRecords(RecordsRWTransaction& txn, uint32_t domain_id, uint16_t qtype)
+void LMDBBackend::deleteDomainRecords(RecordsRWTransaction& txn, domainid_t domain_id, uint16_t qtype)
{
compoundOrdername co;
string match = co(domain_id);
*/
-bool LMDBBackend::startTransaction(const ZoneName& domain, int domain_id)
+bool LMDBBackend::startTransaction(const ZoneName& domain, domainid_t domain_id)
{
// cout <<"startTransaction("<<domain<<", "<<domain_id<<")"<<endl;
- int real_id = domain_id;
- if (real_id < 0) {
+ domainid_t real_id = domain_id;
+ if (real_id == UnknownDomainID) {
auto rotxn = d_tdomains->getROTransaction();
DomainInfo di;
real_id = rotxn.get<0>(domain, di);
d_transactiondomain = domain;
d_transactiondomainid = real_id;
- if (domain_id >= 0) {
- deleteDomainRecords(*d_rwtxn, domain_id);
+ if (domain_id != UnknownDomainID) {
+ LMDBBackend::deleteDomainRecords(*d_rwtxn, domain_id);
}
return true;
return true;
}
-bool LMDBBackend::feedEnts(int domain_id, map<DNSName, bool>& nonterm)
+bool LMDBBackend::feedEnts(domainid_t domain_id, map<DNSName, bool>& nonterm)
{
LMDBResourceRecord lrr;
lrr.ttl = 0;
return true;
}
-bool LMDBBackend::feedEnts3(int domain_id, const DNSName& domain, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow)
+bool LMDBBackend::feedEnts3(domainid_t domain_id, const DNSName& domain, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow)
{
string ser;
DNSName ordername;
}
// might be called within a transaction, might also be called alone
-bool LMDBBackend::replaceRRSet(uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset)
+// NOLINTNEXTLINE(readability-identifier-length)
+bool LMDBBackend::replaceRRSet(domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset)
{
// zonk qname/qtype within domain_id (go through qname, check domain_id && qtype)
shared_ptr<RecordsRWTransaction> txn;
return true;
}
-bool LMDBBackend::replaceComments([[maybe_unused]] const uint32_t domain_id, [[maybe_unused]] const DNSName& qname, [[maybe_unused]] const QType& qt, const vector<Comment>& comments)
+// NOLINTNEXTLINE(readability-identifier-length)
+bool LMDBBackend::replaceComments([[maybe_unused]] domainid_t domain_id, [[maybe_unused]] const DNSName& qname, [[maybe_unused]] const QType& qt, const vector<Comment>& comments)
{
// if the vector is empty, good, that's what we do here (LMDB does not store comments)
// if it's not, report failure
}
// tempting to templatize these two functions but the pain is not worth it
-std::shared_ptr<LMDBBackend::RecordsRWTransaction> LMDBBackend::getRecordsRWTransaction(uint32_t id)
+// NOLINTNEXTLINE(readability-identifier-length)
+std::shared_ptr<LMDBBackend::RecordsRWTransaction> LMDBBackend::getRecordsRWTransaction(domainid_t id)
{
auto& shard = d_trecords[id % s_shards];
if (!shard.env) {
return ret;
}
-std::shared_ptr<LMDBBackend::RecordsROTransaction> LMDBBackend::getRecordsROTransaction(uint32_t id, const std::shared_ptr<LMDBBackend::RecordsRWTransaction>& rwtxn)
+// NOLINTNEXTLINE(readability-identifier-length)
+std::shared_ptr<LMDBBackend::RecordsROTransaction> LMDBBackend::getRecordsROTransaction(domainid_t id, const std::shared_ptr<LMDBBackend::RecordsRWTransaction>& rwtxn)
{
auto& shard = d_trecords[id % s_shards];
if (!shard.env) {
return true;
}
-bool LMDBBackend::list(const ZoneName& target, int /* id */, bool include_disabled)
+bool LMDBBackend::list(const ZoneName& target, domainid_t /* id */, bool include_disabled)
{
d_includedisabled = include_disabled;
return true;
}
-void LMDBBackend::lookupInternal(const QType& type, const DNSName& qdomain, int zoneId, DNSPacket* /* p */, bool include_disabled)
+void LMDBBackend::lookupInternal(const QType& type, const DNSName& qdomain, domainid_t zoneId, DNSPacket* /* p */, bool include_disabled)
{
if (d_dolog) {
g_log << Logger::Warning << "Got lookup for " << qdomain << "|" << type.toString() << " in zone " << zoneId << endl;
ZoneName hunt(qdomain);
DomainInfo di;
- if (zoneId < 0) {
+ if (zoneId == UnknownDomainID) {
auto rotxn = d_tdomains->getROTransaction();
do {
zoneId = rotxn.get<0>(hunt, di);
- } while (!zoneId && type != QType::SOA && hunt.chopOff());
- if (zoneId <= 0) {
+ } while (zoneId == 0 && type != QType::SOA && hunt.chopOff());
+ if (zoneId == 0) {
// cout << "Did not find zone for "<< qdomain<<endl;
d_getcursor.reset();
return;
return true;
}
-int LMDBBackend::genChangeDomain(uint32_t id, const std::function<void(DomainInfo&)>& func)
+// NOLINTNEXTLINE(readability-identifier-length)
+int LMDBBackend::genChangeDomain(domainid_t id, const std::function<void(DomainInfo&)>& func)
{
DomainInfo di;
});
}
-void LMDBBackend::setStale(uint32_t domain_id)
+void LMDBBackend::setStale(domainid_t domain_id)
{
genChangeDomain(domain_id, [](DomainInfo& di) {
di.last_check = 0;
});
}
-void LMDBBackend::setFresh(uint32_t domain_id)
+void LMDBBackend::setFresh(domainid_t domain_id)
{
genChangeDomain(domain_id, [](DomainInfo& di) {
di.last_check = time(nullptr);
});
}
-void LMDBBackend::setNotified(uint32_t domain_id, uint32_t serial)
+void LMDBBackend::setNotified(domainid_t domain_id, uint32_t serial)
{
genChangeDomain(domain_id, [serial](DomainInfo& di) {
di.notified_serial = serial;
return true;
}
-bool LMDBBackend::getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
+// NOLINTNEXTLINE(readability-function-cognitive-complexity,readability-identifier-length)
+bool LMDBBackend::getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
{
// cout << __PRETTY_FUNCTION__<< ": "<<id <<", "<<qname << " " << unhashed<<endl;
return true;
}
-bool LMDBBackend::getBeforeAndAfterNames(uint32_t domainId, const ZoneName& zonenameU, const DNSName& qname, DNSName& before, DNSName& after)
+bool LMDBBackend::getBeforeAndAfterNames(domainid_t domainId, const ZoneName& zonenameU, const DNSName& qname, DNSName& before, DNSName& after)
{
ZoneName zonename = zonenameU.makeLowerCase();
// cout << __PRETTY_FUNCTION__<< ": "<<domainId <<", "<<zonename << ", '"<<qname<<"'"<<endl;
return true;
}
-bool LMDBBackend::updateDNSSECOrderNameAndAuth(uint32_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype)
+bool LMDBBackend::updateDNSSECOrderNameAndAuth(domainid_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype)
{
// cout << __PRETTY_FUNCTION__<< ": "<< domain_id <<", '"<<qname <<"', '"<<ordername<<"', "<<auth<< ", " << qtype << endl;
shared_ptr<RecordsRWTransaction> txn;
return false;
}
-bool LMDBBackend::updateEmptyNonTerminals(uint32_t domain_id, set<DNSName>& insert, set<DNSName>& erase, bool remove)
+bool LMDBBackend::updateEmptyNonTerminals(domainid_t domain_id, set<DNSName>& insert, set<DNSName>& erase, bool remove)
{
// cout << __PRETTY_FUNCTION__<< ": "<< domain_id << ", insert.size() "<<insert.size()<<", "<<erase.size()<<", " <<remove<<endl;
// if remove is set, all ENTs should be removed & nothing else should be done
if (remove) {
- deleteDomainRecords(*txn, domain_id, 0);
+ LMDBBackend::deleteDomainRecords(*txn, domain_id, 0);
}
else {
DomainInfo di;
return "can only refresh in the domains index\n";
}
- uint32_t id = 0;
+ domainid_t id = 0; // NOLINT(readability-identifier-length)
try {
- id = pdns::checked_stoi<uint32_t>(argv[3]);
+ pdns::checked_stoi_into(id, argv[3]);
}
catch (const std::out_of_range& e) {
return "ID out of range\n";
~LMDBBackend();
unsigned int getCapabilities() override { return CAP_DNSSEC | CAP_DIRECT | CAP_LIST | CAP_CREATE; }
- bool list(const ZoneName& target, int domainId, bool include_disabled) override;
+ bool list(const ZoneName& target, domainid_t domainId, bool include_disabled) override;
bool getDomainInfo(const ZoneName& domain, DomainInfo& info, bool getserial = true) override;
bool createDomain(const ZoneName& domain, const DomainInfo::DomainKind kind, const vector<ComboAddress>& primaries, const string& account) override;
- bool startTransaction(const ZoneName& domain, int domain_id = -1) override;
+ bool startTransaction(const ZoneName& domain, domainid_t domain_id = UnknownDomainID) override;
bool commitTransaction() override;
bool abortTransaction() override;
bool feedRecord(const DNSResourceRecord& r, const DNSName& ordername, bool ordernameIsNSEC3 = false) override;
- bool feedEnts(int domain_id, map<DNSName, bool>& nonterm) override;
- bool feedEnts3(int domain_id, const DNSName& domain, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow) override;
- bool replaceRRSet(uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset) override;
- bool replaceComments(uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<Comment>& comments) override;
+ bool feedEnts(domainid_t domain_id, map<DNSName, bool>& nonterm) override;
+ bool feedEnts3(domainid_t domain_id, const DNSName& domain, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow) override;
+ bool replaceRRSet(domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset) override;
+ bool replaceComments(domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<Comment>& comments) override;
void getAllDomains(vector<DomainInfo>* domains, bool doSerial, bool include_disabled) override;
- void lookup(const QType& type, const DNSName& qdomain, int zoneId, DNSPacket* p = nullptr) override { lookupInternal(type, qdomain, zoneId, p, false); }
- void APILookup(const QType& type, const DNSName& qdomain, int zoneId, bool include_disabled = false) override { lookupInternal(type, qdomain, zoneId, nullptr, include_disabled); }
+ void lookup(const QType& type, const DNSName& qdomain, domainid_t zoneId, DNSPacket* p = nullptr) override { lookupInternal(type, qdomain, zoneId, p, false); }
+ void APILookup(const QType& type, const DNSName& qdomain, domainid_t zoneId, bool include_disabled = false) override { lookupInternal(type, qdomain, zoneId, nullptr, include_disabled); }
bool get(DNSResourceRecord& rr) override;
bool get(DNSZoneRecord& dzr) override;
// secondary support
void getUnfreshSecondaryInfos(vector<DomainInfo>* domains) override;
- void setStale(uint32_t domain_id) override;
- void setFresh(uint32_t domain_id) override;
+ void setStale(domainid_t domain_id) override;
+ void setFresh(domainid_t domain_id) override;
// primary support
void getUpdatedPrimaries(vector<DomainInfo>& updatedDomains, std::unordered_set<DNSName>& catalogs, CatalogHashMap& catalogHashes) override;
- void setNotified(uint32_t id, uint32_t serial) override;
+ void setNotified(domainid_t id, uint32_t serial) override;
// catalog zones
bool getCatalogMembers(const ZoneName& catalog, vector<CatalogInfo>& members, CatalogInfo::CatalogType type) override;
// DNSSEC
- bool getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override;
+ bool getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override;
- bool getBeforeAndAfterNames(uint32_t domainId, const ZoneName& zonename, const DNSName& qname, DNSName& before, DNSName& after) override;
+ bool getBeforeAndAfterNames(domainid_t domainId, const ZoneName& zonename, const DNSName& qname, DNSName& before, DNSName& after) override;
- bool updateDNSSECOrderNameAndAuth(uint32_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype = QType::ANY) override;
+ bool updateDNSSECOrderNameAndAuth(domainid_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype = QType::ANY) override;
- bool updateEmptyNonTerminals(uint32_t domain_id, set<DNSName>& insert, set<DNSName>& erase, bool remove) override;
+ bool updateEmptyNonTerminals(domainid_t domain_id, set<DNSName>& insert, set<DNSName>& erase, bool remove) override;
// other
string directBackendCmd(const string& query) override;
return operator()(rr.domain_id, rr.qname, rr.qtype.getCode());
}
- static uint32_t getDomainID(const string_view& key)
+ static domainid_t getDomainID(const string_view& key)
{
uint32_t ret;
memcpy(&ret, &key[0], sizeof(ret));
- return ntohl(ret);
+ return static_cast<domainid_t>(ntohl(ret));
}
static DNSName getQName(const string_view& key)
shared_ptr<RecordsROTransaction> d_rotxn; // for lookup and list
shared_ptr<RecordsRWTransaction> d_rwtxn; // for feedrecord within begin/aborttransaction
bool d_txnorder{false}; // whether d_rotxn is more recent than d_rwtxn
- std::shared_ptr<RecordsRWTransaction> getRecordsRWTransaction(uint32_t id);
- std::shared_ptr<RecordsROTransaction> getRecordsROTransaction(uint32_t id, const std::shared_ptr<LMDBBackend::RecordsRWTransaction>& rwtxn = nullptr);
+ std::shared_ptr<RecordsRWTransaction> getRecordsRWTransaction(domainid_t id);
+ std::shared_ptr<RecordsROTransaction> getRecordsROTransaction(domainid_t id, const std::shared_ptr<LMDBBackend::RecordsRWTransaction>& rwtxn = nullptr);
int genChangeDomain(const ZoneName& domain, const std::function<void(DomainInfo&)>& func);
- int genChangeDomain(uint32_t id, const std::function<void(DomainInfo&)>& func);
- void deleteDomainRecords(RecordsRWTransaction& txn, uint32_t domain_id, uint16_t qtype = QType::ANY);
+ int genChangeDomain(domainid_t id, const std::function<void(DomainInfo&)>& func);
+ static void deleteDomainRecords(RecordsRWTransaction& txn, domainid_t domain_id, uint16_t qtype = QType::ANY);
void getAllDomainsFiltered(vector<DomainInfo>* domains, const std::function<bool(DomainInfo&)>& allow);
- void lookupInternal(const QType& type, const DNSName& qdomain, int zoneId, DNSPacket* p, bool include_disabled);
+ void lookupInternal(const QType& type, const DNSName& qdomain, domainid_t zoneId, DNSPacket* p, bool include_disabled);
bool getSerial(DomainInfo& di);
bool get_list(DNSZoneRecord& rr);
bool d_includedisabled;
ZoneName d_transactiondomain;
- uint32_t d_transactiondomainid;
+ domainid_t d_transactiondomainid;
bool d_dolog;
bool d_random_ids;
bool d_handle_dups;
typedef std::vector<std::pair<string, string>> lookup_context_t;
typedef std::vector<std::pair<int, std::vector<std::pair<string, boost::variant<bool, int, DNSName, string, QType>>>>> lookup_result_t;
- typedef std::function<lookup_result_t(const QType& qtype, const DNSName& qname, int domain_id, const lookup_context_t& ctx)> lookup_call_t;
+ typedef std::function<lookup_result_t(const QType& qtype, const DNSName& qname, domainid_t domain_id, const lookup_context_t& ctx)> lookup_call_t;
typedef boost::variant<bool, lookup_result_t> list_result_t;
- typedef std::function<list_result_t(const DNSName& qname, int domain_id)> list_call_t;
+ typedef std::function<list_result_t(const DNSName& qname, domainid_t domain_id)> list_call_t;
typedef vector<pair<string, boost::variant<bool, long, string, vector<string>>>> domaininfo_result_t;
typedef boost::variant<bool, domaininfo_result_t> get_domaininfo_result_t;
typedef std::vector<std::pair<string, boost::variant<string, DNSName>>> before_and_after_names_result_t;
typedef boost::variant<bool, before_and_after_names_result_t> get_before_and_after_names_absolute_result_t;
- typedef std::function<get_before_and_after_names_absolute_result_t(int id, const DNSName& qname)> get_before_and_after_names_absolute_call_t;
+ typedef std::function<get_before_and_after_names_absolute_result_t(domainid_t id, const DNSName& qname)> get_before_and_after_names_absolute_call_t;
- typedef std::function<void(int, long)> set_notified_call_t;
+ typedef std::function<void(domainid_t, long)> set_notified_call_t;
typedef std::function<string(const string& cmd)> direct_backend_cmd_call_t;
g_log << Logger::Debug << "[" << getPrefix() << "] Got empty result" << endl;
}
- bool list(const ZoneName& target, int domain_id, bool /* include_disabled */ = false) override
+ bool list(const ZoneName& target, domainid_t domain_id, bool /* include_disabled */ = false) override
{
if (f_list == nullptr) {
g_log << Logger::Error << "[" << getPrefix() << "] dns_list missing - cannot do AXFR" << endl;
return true;
}
- void lookup(const QType& qtype, const DNSName& qname, int domain_id, DNSPacket* p = nullptr) override
+ void lookup(const QType& qtype, const DNSName& qname, domainid_t domain_id, DNSPacket* p = nullptr) override
{
if (d_result.size() != 0)
throw PDNSException("lookup attempted while another was running");
return f(par);
}
- void setNotified(uint32_t id, uint32_t serial) override
+ void setNotified(domainid_t id, uint32_t serial) override
{
if (f_set_notified == NULL)
return;
- logCall("dns_set_notified", "id=" << static_cast<int>(id) << ",serial=" << serial);
- f_set_notified(static_cast<int>(id), serial);
+ logCall("dns_set_notified", "id=" << id << ",serial=" << serial);
+ f_set_notified(id, serial);
}
void parseDomainInfo(const domaininfo_result_t& row, DomainInfo& di)
for (const auto& primary : boost::get<vector<string>>(item.second))
di.primaries.push_back(ComboAddress(primary, 53));
else if (item.first == "id")
- di.id = static_cast<int>(boost::get<long>(item.second));
+ di.id = static_cast<domainid_t>(boost::get<long>(item.second));
else if (item.first == "notified_serial")
di.notified_serial = static_cast<unsigned int>(boost::get<long>(item.second));
else if (item.first == "serial")
return true;
}
- bool getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override
+ bool getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override
{
if (f_get_before_and_after_names_absolute == nullptr)
return false;
#include <arpa/inet.h>
#include "pipebackend.hh"
+// The following requirement guarantees UnknownDomainID will get output as "-1"
+// for compatibility.
+static_assert(std::is_signed<domainid_t>::value);
+
static const char* kBackendId = "[PIPEBackend]";
CoWrapper::CoWrapper(const string& command, int timeout, int abiVersion)
d_abiVersion = 0;
}
-void PipeBackend::lookup(const QType& qtype, const DNSName& qname, int zoneId, DNSPacket* pkt_p)
+void PipeBackend::lookup(const QType& qtype, const DNSName& qname, domainid_t zoneId, DNSPacket* pkt_p)
{
try {
launch();
d_qname = qname;
}
-bool PipeBackend::list(const ZoneName& target, int domain_id, bool /* include_disabled */)
+bool PipeBackend::list(const ZoneName& target, domainid_t domain_id, bool /* include_disabled */)
{
try {
launch();
~PipeBackend() override;
unsigned int getCapabilities() override { return CAP_DIRECT | CAP_LIST; }
- void lookup(const QType&, const DNSName& qdomain, int zoneId, DNSPacket* p = nullptr) override;
- bool list(const ZoneName& target, int domain_id, bool include_disabled = false) override;
+ void lookup(const QType& qtype, const DNSName& qname, domainid_t zoneId, DNSPacket* pkt_p = nullptr) override;
+ bool list(const ZoneName& target, domainid_t domain_id, bool include_disabled = false) override;
bool get(DNSResourceRecord& r) override;
string directBackendCmd(const string& query) override;
static DNSBackend* maker();
#endif
#include "remotebackend.hh"
+// The following requirement guarantees UnknownDomainID will get output as "-1"
+// in the Json data for compatibility.
+static_assert(std::is_signed<domainid_t>::value);
+
+// The following requirement is a consequency of JsonInt not able to store
+// anything larger than "int".
+static_assert(sizeof(domainid_t) <= sizeof(int));
+
static const char* kBackendId = "[RemoteBackend]";
/**
* The functions here are just remote json stubs that send and receive the method call
* data is mainly left alone, some defaults are assumed.
*/
-void RemoteBackend::lookup(const QType& qtype, const DNSName& qdomain, int zoneId, DNSPacket* pkt_p)
+void RemoteBackend::lookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId, DNSPacket* pkt_p)
{
if (d_index != -1) {
throw PDNSException("Attempt to lookup while one running");
}
// Similar to lookup above, but passes an extra include_disabled parameter.
-void RemoteBackend::APILookup(const QType& qtype, const DNSName& qdomain, int zoneId, bool include_disabled)
+void RemoteBackend::APILookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId, bool include_disabled)
{
if (d_index != -1) {
throw PDNSException("Attempt to lookup while one running");
d_index = 0;
}
-bool RemoteBackend::list(const ZoneName& target, int domain_id, bool include_disabled)
+bool RemoteBackend::list(const ZoneName& target, domainid_t domain_id, bool include_disabled)
{
if (d_index != -1) {
throw PDNSException("Attempt to lookup while one running");
rr.qclass = QClass::IN;
rr.content = stringFromJson(d_result["result"][d_index], "content");
rr.ttl = d_result["result"][d_index]["ttl"].int_value();
- rr.domain_id = intFromJson(d_result["result"][d_index], "domain_id", -1);
+ rr.domain_id = static_cast<domainid_t>(intFromJson(d_result["result"][d_index], "domain_id", UnknownDomainID));
if (d_dnssec) {
rr.auth = (intFromJson(d_result["result"][d_index], "auth", 1) != 0);
}
return true;
}
-bool RemoteBackend::getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
+// NOLINTNEXTLINE(readability-identifier-length)
+bool RemoteBackend::getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
{
// no point doing dnssec if it's not supported
if (!d_dnssec) {
Json query = Json::object{
{"method", "getBeforeAndAfterNamesAbsolute"},
- {"parameters", Json::object{{"id", Json(static_cast<double>(id))}, {"qname", qname.toString()}}}};
+ {"parameters", Json::object{{"id", Json(id)}, {"qname", qname.toString()}}}};
Json answer;
if (!this->send(query) || !this->recv(answer)) {
void RemoteBackend::parseDomainInfo(const Json& obj, DomainInfo& di)
{
- di.id = intFromJson(obj, "id", -1);
+ di.id = static_cast<domainid_t>(intFromJson(obj, "id", UnknownDomainID));
di.zone = ZoneName(stringFromJson(obj, "zone"));
for (const auto& primary : obj["masters"].array_items()) {
di.primaries.emplace_back(primary.string_value(), 53);
return true;
}
-void RemoteBackend::setNotified(uint32_t id, uint32_t serial)
+// NOLINTNEXTLINE(readability-identifier-length)
+void RemoteBackend::setNotified(domainid_t id, uint32_t serial)
{
Json query = Json::object{
{"method", "setNotified"},
- {"parameters", Json::object{{"id", static_cast<double>(id)}, {"serial", static_cast<double>(serial)}}}};
+ {"parameters", Json::object{{"id", id}, {"serial", static_cast<double>(serial)}}}};
Json answer;
if (!this->send(query) || !this->recv(answer)) {
return this->send(query) && this->recv(answer);
}
-bool RemoteBackend::replaceRRSet(uint32_t domain_id, const DNSName& qname, const QType& qtype, const vector<DNSResourceRecord>& rrset)
+bool RemoteBackend::replaceRRSet(domainid_t domain_id, const DNSName& qname, const QType& qtype, const vector<DNSResourceRecord>& rrset)
{
Json::array json_rrset;
for (const auto& rr : rrset) {
Json query = Json::object{
{"method", "replaceRRSet"},
- {"parameters", Json::object{{"domain_id", static_cast<double>(domain_id)}, {"qname", qname.toString()}, {"qtype", qtype.toString()}, {"trxid", static_cast<double>(d_trxid)}, {"rrset", json_rrset}}}};
+ {"parameters", Json::object{{"domain_id", domain_id}, {"qname", qname.toString()}, {"qtype", qtype.toString()}, {"trxid", static_cast<double>(d_trxid)}, {"rrset", json_rrset}}}};
Json answer;
return this->send(query) && this->recv(answer);
return this->send(query) && this->recv(answer); // XXX FIXME this API should not return 'true' I think -ahu
}
-bool RemoteBackend::feedEnts(int domain_id, map<DNSName, bool>& nonterm)
+bool RemoteBackend::feedEnts(domainid_t domain_id, map<DNSName, bool>& nonterm)
{
Json::array nts;
return this->send(query) && this->recv(answer);
}
-bool RemoteBackend::feedEnts3(int domain_id, const DNSName& domain, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow)
+bool RemoteBackend::feedEnts3(domainid_t domain_id, const DNSName& domain, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow)
{
Json::array nts;
return this->send(query) && this->recv(answer);
}
-bool RemoteBackend::startTransaction(const ZoneName& domain, int domain_id)
+bool RemoteBackend::startTransaction(const ZoneName& domain, domainid_t domain_id)
{
this->d_trxid = time((time_t*)nullptr);
rr.qclass = QClass::IN;
rr.content = stringFromJson(row, "content");
rr.ttl = row["ttl"].int_value();
- rr.domain_id = intFromJson(row, "domain_id", -1);
+ rr.domain_id = static_cast<domainid_t>(intFromJson(row, "domain_id", UnknownDomainID));
if (d_dnssec) {
rr.auth = (intFromJson(row, "auth", 1) != 0);
}
}
}
-void RemoteBackend::setStale(uint32_t domain_id)
+void RemoteBackend::setStale(domainid_t domain_id)
{
Json query = Json::object{
{"method", "setStale"},
- {"parameters", Json::object{{"id", static_cast<double>(domain_id)}}}};
+ {"parameters", Json::object{{"id", domain_id}}}};
Json answer;
if (!this->send(query) || !this->recv(answer)) {
}
}
-void RemoteBackend::setFresh(uint32_t domain_id)
+void RemoteBackend::setFresh(domainid_t domain_id)
{
Json query = Json::object{
{"method", "setFresh"},
- {"parameters", Json::object{{"id", static_cast<double>(domain_id)}}}};
+ {"parameters", Json::object{{"id", domain_id}}}};
Json answer;
if (!this->send(query) || !this->recv(answer)) {
~RemoteBackend() override;
unsigned int getCapabilities() override;
- void lookup(const QType& qtype, const DNSName& qdomain, int zoneId = -1, DNSPacket* pkt_p = nullptr) override;
- void APILookup(const QType& qtype, const DNSName& qdomain, int zoneId = -1, bool include_disabled = false) override;
+ void lookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId = UnknownDomainID, DNSPacket* pkt_p = nullptr) override;
+ void APILookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId = UnknownDomainID, bool include_disabled = false) override;
bool get(DNSResourceRecord& rr) override;
- bool list(const ZoneName& target, int domain_id, bool include_disabled = false) override;
+ bool list(const ZoneName& target, domainid_t domain_id, bool include_disabled = false) override;
bool getAllDomainMetadata(const ZoneName& name, std::map<std::string, std::vector<std::string>>& meta) override;
bool getDomainMetadata(const ZoneName& name, const std::string& kind, std::vector<std::string>& meta) override;
bool getDomainKeys(const ZoneName& name, std::vector<DNSBackend::KeyData>& keys) override;
bool getTSIGKey(const DNSName& name, DNSName& algorithm, std::string& content) override;
- bool getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override;
+ bool getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override;
bool setDomainMetadata(const ZoneName& name, const string& kind, const std::vector<std::basic_string<char>>& meta) override;
bool removeDomainKey(const ZoneName& name, unsigned int keyId) override;
bool addDomainKey(const ZoneName& name, const KeyData& key, int64_t& keyId) override;
bool publishDomainKey(const ZoneName& name, unsigned int keyId) override;
bool unpublishDomainKey(const ZoneName& name, unsigned int keyId) override;
bool getDomainInfo(const ZoneName& domain, DomainInfo& info, bool getSerial = true) override;
- void setNotified(uint32_t id, uint32_t serial) override;
+ void setNotified(domainid_t id, uint32_t serial) override;
bool autoPrimaryBackend(const string& ipAddress, const ZoneName& domain, const vector<DNSResourceRecord>& nsset, string* nameserver, string* account, DNSBackend** ddb) override;
bool createSecondaryDomain(const string& ipAddress, const ZoneName& domain, const string& nameserver, const string& account) override;
- bool replaceRRSet(uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset) override;
+ bool replaceRRSet(domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset) override;
bool feedRecord(const DNSResourceRecord& r, const DNSName& ordername, bool ordernameIsNSEC3 = false) override;
- bool feedEnts(int domain_id, map<DNSName, bool>& nonterm) override;
- bool feedEnts3(int domain_id, const DNSName& domain, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow) override;
- bool startTransaction(const ZoneName& domain, int domain_id) override;
+ bool feedEnts(domainid_t domain_id, map<DNSName, bool>& nonterm) override;
+ bool feedEnts3(domainid_t domain_id, const DNSName& domain, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow) override;
+ bool startTransaction(const ZoneName& domain, domainid_t domain_id) override;
bool commitTransaction() override;
bool abortTransaction() override;
bool setTSIGKey(const DNSName& name, const DNSName& algorithm, const string& content) override;
void getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled) override;
void getUpdatedPrimaries(vector<DomainInfo>& domains, std::unordered_set<DNSName>& catalogs, CatalogHashMap& catalogHashes) override;
void getUnfreshSecondaryInfos(vector<DomainInfo>* domains) override;
- void setStale(uint32_t domain_id) override;
- void setFresh(uint32_t domain_id) override;
+ void setStale(domainid_t domain_id) override;
+ void setFresh(domainid_t domain_id) override;
static DNSBackend* maker();
#include <utility>
static string backendname = "[TinyDNSBackend] ";
-uint32_t TinyDNSBackend::s_lastId;
+domainid_t TinyDNSBackend::s_lastId;
LockGuarded<TinyDNSBackend::TDI_suffix_t> TinyDNSBackend::s_domainInfo;
vector<string> TinyDNSBackend::getLocations()
}
}
-void TinyDNSBackend::setNotified(uint32_t id, uint32_t serial)
+// NOLINTNEXTLINE(readability-identifier-length)
+void TinyDNSBackend::setNotified(domainid_t id, uint32_t serial)
{
auto domainInfo = s_domainInfo.lock();
if (!domainInfo->count(d_suffix)) {
while (get(rr)) {
if (rr.qtype.getCode() == QType::SOA && dupcheck.insert(rr.qname).second) {
DomainInfo di;
- di.id = -1; // Will be overridden by caller
+ di.id = UnknownDomainID; // Will be overridden by caller
di.backend = this;
di.zone = ZoneName(rr.qname);
di.kind = DomainInfo::Primary;
return found;
}
-bool TinyDNSBackend::list(const ZoneName& target, int /* domain_id */, bool /* include_disabled */)
+bool TinyDNSBackend::list(const ZoneName& target, domainid_t /* domain_id */, bool /* include_disabled */)
{
d_isAxfr = true;
d_isGetDomains = false;
return d_cdbReader->searchSuffix(key);
}
-void TinyDNSBackend::lookup(const QType& qtype, const DNSName& qdomain, int /* zoneId */, DNSPacket* pkt_p)
+void TinyDNSBackend::lookup(const QType& qtype, const DNSName& qdomain, domainid_t /* zoneId */, DNSPacket* pkt_p)
{
d_isAxfr = false;
d_isGetDomains = false;
struct TinyDomainInfo
{
- uint32_t id;
+ domainid_t id;
uint32_t notified_serial;
ZoneName zone;
TinyDNSBackend(const string& suffix);
unsigned int getCapabilities() override { return CAP_LIST; }
- void lookup(const QType& qtype, const DNSName& qdomain, int zoneId, DNSPacket* pkt_p = nullptr) override;
- bool list(const ZoneName& target, int domain_id, bool include_disabled = false) override;
+ void lookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId, DNSPacket* pkt_p = nullptr) override;
+ bool list(const ZoneName& target, domainid_t domain_id, bool include_disabled = false) override;
bool get(DNSResourceRecord& rr) override;
bool getDomainInfo(const ZoneName& domain, DomainInfo& di, bool getSerial = true) override;
void getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled) override;
// Primary mode operation
void getUpdatedPrimaries(vector<DomainInfo>& domains, std::unordered_set<DNSName>& catalogs, CatalogHashMap& catalogHashes) override;
- void setNotified(uint32_t id, uint32_t serial) override;
+ void setNotified(domainid_t id, uint32_t serial) override;
private:
//TypeDefs
TinyDomainInfo,
indexed_by<
hashed_unique<tag<tag_zone>, member<TinyDomainInfo, ZoneName, &TinyDomainInfo::zone>>,
- hashed_unique<tag<tag_domainid>, member<TinyDomainInfo, uint32_t, &TinyDomainInfo::id>>>>
+ hashed_unique<tag<tag_domainid>, member<TinyDomainInfo, domainid_t, &TinyDomainInfo::id>>>>
TDI_t;
typedef map<string, TDI_t> TDI_suffix_t;
typedef TDI_t::index<tag_zone>::type TDIByZone_t;
// Statics
static LockGuarded<TDI_suffix_t> s_domainInfo;
- static uint32_t s_lastId; // used to give a domain an id.
+ static domainid_t s_lastId; // used to give a domain an id.
};
try {
if (d_onlyNotify.size()) {
- // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
B->lookup(QType(QType::NS), di.zone.operator const DNSName&(), di.id);
while (B->get(rr))
nsset.insert(getRR<NSRecordContent>(rr.dr)->getNS());
DNSResourceRecord rr;
makeIncreasedSOARecord(sd, "EPOCH", "", rr);
- di.backend->startTransaction(ZoneName(sd.qname), -1);
+ di.backend->startTransaction(ZoneName(sd.qname), UnknownDomainID);
if (!di.backend->replaceRRSet(di.id, rr.qname, rr.qtype, vector<DNSResourceRecord>(1, rr))) {
di.backend->abortTransaction();
throw PDNSException("backend hosting producer zone '" + sd.qname.toLogString() + "' does not support editing records");
for (const auto& x : add)
grouped[{ZoneName(x.d_name), x.d_type}].second.push_back(x);
- di.backend->startTransaction(domain, -1);
+ di.backend->startTransaction(domain, UnknownDomainID);
for (const auto& g : grouped) {
vector<DNSRecord> rrset;
{
DNSZoneRecord zrr;
- // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
di.backend->lookup(QType(g.first.second), g.first.first.operator const DNSName&() + domain.operator const DNSName&(), di.id);
while (di.backend->get(zrr)) {
zrr.dr.d_name.makeUsRelative(domain);
// Insert empty non-terminals
if (doent && !nonterm.empty()) {
if (zs.isNSEC3) {
- // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
di.backend->feedEnts3(zs.domain_id, domain.operator const DNSName&(), nonterm, zs.ns3pr, zs.isNarrow);
}
else
SOAData sd;
try {
// Use UeberBackend cache for SOA. Cache gets cleared after AXFR/IXFR.
- // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
B->lookup(QType(QType::SOA), di.zone.operator const DNSName&(), di.id, nullptr);
DNSZoneRecord zr;
hasSOA = B->get(zr);
else if (hasSOA && theirserial == ourserial) {
uint32_t maxExpire = 0, maxInception = 0;
if (checkSignatures && dk.isPresigned(di.zone)) {
- // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
B->lookup(QType(QType::RRSIG), di.zone.operator const DNSName&(), di.id); // can't use DK before we are done with this lookup!
DNSZoneRecord zr;
while (B->get(zr)) {
d_SearchCommentsQuery_stmt = nullptr;
}
-void GSQLBackend::setNotified(uint32_t domain_id, uint32_t serial)
+void GSQLBackend::setNotified(domainid_t domain_id, uint32_t serial)
{
try {
reconnectIfNeeded();
}
}
-void GSQLBackend::setLastCheck(uint32_t domain_id, time_t lastcheck)
+void GSQLBackend::setLastCheck(domainid_t domain_id, time_t lastcheck)
{
try {
reconnectIfNeeded();
}
}
-void GSQLBackend::setStale(uint32_t domain_id)
+void GSQLBackend::setStale(domainid_t domain_id)
{
setLastCheck(domain_id, 0);
}
-void GSQLBackend::setFresh(uint32_t domain_id)
+void GSQLBackend::setFresh(domainid_t domain_id)
{
setLastCheck(domain_id, time(nullptr));
}
return true;
}
-bool GSQLBackend::updateDNSSECOrderNameAndAuth(uint32_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype)
+bool GSQLBackend::updateDNSSECOrderNameAndAuth(domainid_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype)
{
if(!d_dnssecQueries)
return false;
return true;
}
-bool GSQLBackend::updateEmptyNonTerminals(uint32_t domain_id, set<DNSName>& insert, set<DNSName>& erase, bool remove)
+bool GSQLBackend::updateEmptyNonTerminals(domainid_t domain_id, set<DNSName>& insert, set<DNSName>& erase, bool remove)
{
if(remove) {
try {
return caps;
}
-bool GSQLBackend::getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
+// NOLINTNEXTLINE(readability-identifier-length)
+bool GSQLBackend::getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
{
if(!d_dnssecQueries)
return false;
return true;
}
-void GSQLBackend::lookup(const QType& qtype, const DNSName& qname, int domain_id, DNSPacket* /* pkt_p */)
+void GSQLBackend::lookup(const QType& qtype, const DNSName& qname, domainid_t domain_id, DNSPacket* /* pkt_p */)
{
try {
reconnectIfNeeded();
if(qtype.getCode()!=QType::ANY) {
- if(domain_id < 0) {
+ if(domain_id == UnknownDomainID) {
d_query_name = "basic-query";
d_query_stmt = &d_NoIdQuery_stmt;
// clang-format off
}
} else {
// qtype==ANY
- if(domain_id < 0) {
+ if(domain_id == UnknownDomainID) {
d_query_name = "any-query";
d_query_stmt = &d_ANYNoIdQuery_stmt;
// clang-format off
d_qname=qname;
}
-void GSQLBackend::APILookup(const QType& qtype, const DNSName& qname, int domain_id, bool include_disabled)
+void GSQLBackend::APILookup(const QType& qtype, const DNSName& qname, domainid_t domain_id, bool include_disabled)
{
try {
reconnectIfNeeded();
d_qname=qname;
}
-bool GSQLBackend::list(const ZoneName &target, int domain_id, bool include_disabled)
+bool GSQLBackend::list(const ZoneName &target, domainid_t domain_id, bool include_disabled)
{
DLOG(g_log<<"GSQLBackend constructing handle for list of domain id '"<<domain_id<<"'"<<endl);
return true;
}
-bool GSQLBackend::listSubZone(const ZoneName &zone, int domain_id) {
+bool GSQLBackend::listSubZone(const ZoneName &zone, domainid_t domain_id) {
string wildzone = "%." + zone.makeLowerCase().toStringNoDot();
}
}
-bool GSQLBackend::replaceRRSet(uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset)
+// NOLINTNEXTLINE(readability-identifier-length)
+bool GSQLBackend::replaceRRSet(domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset)
{
try {
reconnectIfNeeded();
return true; // XXX FIXME this API should not return 'true' I think -ahu
}
-bool GSQLBackend::feedEnts(int domain_id, map<DNSName,bool>& nonterm)
+bool GSQLBackend::feedEnts(domainid_t domain_id, map<DNSName,bool>& nonterm)
{
for(const auto& nt: nonterm) {
try {
return true;
}
-bool GSQLBackend::feedEnts3(int domain_id, const DNSName& /* domain */, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow)
+bool GSQLBackend::feedEnts3(domainid_t domain_id, const DNSName& /* domain */, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow)
{
if(!d_dnssecQueries)
return false;
return true;
}
-bool GSQLBackend::startTransaction(const ZoneName &domain, int domain_id)
+bool GSQLBackend::startTransaction(const ZoneName &domain, domainid_t domain_id)
{
try {
reconnectIfNeeded();
}
d_db->startTransaction();
d_inTransaction = true;
- if(domain_id >= 0) {
+ if(domain_id != UnknownDomainID) {
// clang-format off
d_DeleteZoneQuery_stmt->
bind("domain_id", domain_id)->
return true;
}
-bool GSQLBackend::listComments(const uint32_t domain_id)
+bool GSQLBackend::listComments(const domainid_t domain_id)
{
try {
reconnectIfNeeded();
return true;
}
-bool GSQLBackend::replaceComments(const uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<Comment>& comments)
+// NOLINTNEXTLINE(readability-identifier-length)
+bool GSQLBackend::replaceComments(const domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<Comment>& comments)
{
try {
reconnectIfNeeded();
public:
unsigned int getCapabilities() override;
- void lookup(const QType &, const DNSName &qdomain, int zoneId, DNSPacket *p=nullptr) override;
- void APILookup(const QType &qtype, const DNSName &qname, int domain_id, bool include_disabled = false) override;
- bool list(const ZoneName &target, int domain_id, bool include_disabled=false) override;
+ void lookup(const QType& qtype, const DNSName& qname, domainid_t domain_id, DNSPacket *p=nullptr) override;
+ void APILookup(const QType &qtype, const DNSName &qname, domainid_t domain_id, bool include_disabled = false) override;
+ bool list(const ZoneName &target, domainid_t domain_id, bool include_disabled=false) override;
bool get(DNSResourceRecord &r) override;
void getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled) override;
- bool startTransaction(const ZoneName &domain, int domain_id=-1) override;
+ bool startTransaction(const ZoneName &domain, domainid_t domain_id=UnknownDomainID) override;
bool commitTransaction() override;
bool abortTransaction() override;
bool feedRecord(const DNSResourceRecord &r, const DNSName &ordername, bool ordernameIsNSEC3=false) override;
- bool feedEnts(int domain_id, map<DNSName,bool>& nonterm) override;
- bool feedEnts3(int domain_id, const DNSName &domain, map<DNSName,bool> &nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow) override;
+ bool feedEnts(domainid_t domain_id, map<DNSName,bool>& nonterm) override;
+ bool feedEnts3(domainid_t domain_id, const DNSName &domain, map<DNSName,bool> &nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow) override;
bool createDomain(const ZoneName& domain, const DomainInfo::DomainKind kind, const vector<ComboAddress>& primaries, const string& account) override;
bool createSecondaryDomain(const string& ipAddress, const ZoneName& domain, const string& nameserver, const string& account) override;
bool deleteDomain(const ZoneName &domain) override;
bool autoPrimaryRemove(const AutoPrimary& primary) override;
bool autoPrimariesList(std::vector<AutoPrimary>& primaries) override;
bool autoPrimaryBackend(const string& ipAddress, const ZoneName& domain, const vector<DNSResourceRecord>& nsset, string* nameserver, string* account, DNSBackend** db) override;
- void setStale(uint32_t domain_id) override;
- void setFresh(uint32_t domain_id) override;
+ void setStale(domainid_t domain_id) override;
+ void setFresh(domainid_t domain_id) override;
void getUnfreshSecondaryInfos(vector<DomainInfo>* domains) override;
void getUpdatedPrimaries(vector<DomainInfo>& updatedDomains, std::unordered_set<DNSName>& catalogs, CatalogHashMap& catalogHashes) override;
bool getCatalogMembers(const ZoneName& catalog, vector<CatalogInfo>& members, CatalogInfo::CatalogType type) override;
bool getDomainInfo(const ZoneName &domain, DomainInfo &info, bool getSerial=true) override;
- void setNotified(uint32_t domain_id, uint32_t serial) override;
+ void setNotified(domainid_t domain_id, uint32_t serial) override;
bool setPrimaries(const ZoneName& domain, const vector<ComboAddress>& primaries) override;
bool setKind(const ZoneName &domain, const DomainInfo::DomainKind kind) override;
bool setOptions(const ZoneName& domain, const string& options) override;
bool setCatalog(const ZoneName& domain, const ZoneName& catalog) override;
bool setAccount(const ZoneName &domain, const string &account) override;
- bool getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override;
- bool updateDNSSECOrderNameAndAuth(uint32_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t=QType::ANY) override;
+ bool getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override;
+ bool updateDNSSECOrderNameAndAuth(domainid_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t=QType::ANY) override;
- bool updateEmptyNonTerminals(uint32_t domain_id, set<DNSName>& insert ,set<DNSName>& erase, bool remove) override;
+ bool updateEmptyNonTerminals(domainid_t domain_id, set<DNSName>& insert ,set<DNSName>& erase, bool remove) override;
- bool replaceRRSet(uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset) override;
- bool listSubZone(const ZoneName &zone, int domain_id) override;
+ bool replaceRRSet(domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset) override;
+ bool listSubZone(const ZoneName &zone, domainid_t domain_id) override;
bool addDomainKey(const ZoneName& name, const KeyData& key, int64_t& id) override;
bool getDomainKeys(const ZoneName& name, std::vector<KeyData>& keys) override;
bool getAllDomainMetadata(const ZoneName& name, std::map<std::string, std::vector<std::string> >& meta) override;
bool deleteTSIGKey(const DNSName& name) override;
bool getTSIGKeys(std::vector< struct TSIGKey > &keys) override;
- bool listComments(const uint32_t domain_id) override;
+ bool listComments(const domainid_t domain_id) override;
bool getComment(Comment& comment) override;
bool feedComment(const Comment& comment) override;
- bool replaceComments(const uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<Comment>& comments) override;
+ bool replaceComments(const domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<Comment>& comments) override;
string directBackendCmd(const string &query) override;
bool searchRecords(const string &pattern, size_t maxResults, vector<DNSResourceRecord>& result) override;
bool searchComments(const string &pattern, size_t maxResults, vector<Comment>& result) override;
string pattern2SQLPattern(const string& pattern);
void extractRecord(SSqlStatement::row_t& row, DNSResourceRecord& rr);
void extractComment(SSqlStatement::row_t& row, Comment& c);
- void setLastCheck(uint32_t domain_id, time_t lastcheck);
+ void setLastCheck(domainid_t domain_id, time_t lastcheck);
bool isConnectionUsable() {
if (d_db) {
return d_db->isConnectionUsable();
string account; //!< account last updating this comment
string content; //!< The actual comment. Example: blah blah
- int domain_id{0};
+ domainid_t domain_id{0};
QType qtype; //!< qtype of the associated RRset, ie A, CNAME, MX etc
};
}
if (doTransaction)
- sd.db->startTransaction(zone, -1);
+ sd.db->startTransaction(zone, UnknownDomainID);
bool realrr=true;
bool doent=true;
static std::string to_s(uint8_t opcode);
};
+// This needs to be a signed type, so that serialization of UnknownDomainID
+// as text is "-1", for compatibility with the remote and pipe backends.
+// See static_assert there for details.
+using domainid_t = int32_t;
+
+constexpr domainid_t UnknownDomainID{-1};
+
//! This class represents a resource record
class DNSResourceRecord
{
uint32_t ttl{}; //!< Time To Live of this record
uint32_t signttl{}; //!< If non-zero, use this TTL as original TTL in the RRSIG
- int domain_id{-1}; //!< If a backend implements this, the domain_id of the zone this record is in
+ domainid_t domain_id{UnknownDomainID}; //!< If a backend implements this, the domain_id of the zone this record is in
QType qtype; //!< qtype of this record, ie A, CNAME, MX etc
uint16_t qclass{1}; //!< class of this record
}
// Default API lookup has no support for disabled records and simply wraps lookup()
-void DNSBackend::APILookup(const QType& qtype, const DNSName& qdomain, int zoneId, bool /* include_disabled */)
+void DNSBackend::APILookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId, bool /* include_disabled */)
{
lookup(qtype, qdomain, zoneId, nullptr);
}
return true;
}
-bool DNSBackend::getBeforeAndAfterNames(uint32_t domainId, const ZoneName& zonename, const DNSName& qname, DNSName& before, DNSName& after)
+bool DNSBackend::getBeforeAndAfterNames(domainid_t domainId, const ZoneName& zonename, const DNSName& qname, DNSName& before, DNSName& after)
{
DNSName unhashed;
bool ret = this->getBeforeAndAfterNamesAbsolute(domainId, qname.makeRelative(zonename).makeLowerCase(), unhashed, before, after);
vector<ComboAddress> primaries;
DNSBackend* backend{};
- uint32_t id{};
+ domainid_t id{};
uint32_t notified_serial{};
bool receivedNotify{};
virtual unsigned int getCapabilities() = 0;
//! lookup() initiates a lookup. A lookup without results should not throw!
- virtual void lookup(const QType& qtype, const DNSName& qdomain, int zoneId = -1, DNSPacket* pkt_p = nullptr) = 0;
- virtual void APILookup(const QType& qtype, const DNSName& qdomain, int zoneId = -1, bool include_disabled = false);
+ virtual void lookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId = UnknownDomainID, DNSPacket* pkt_p = nullptr) = 0;
+ virtual void APILookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId = UnknownDomainID, bool include_disabled = false);
virtual bool get(DNSResourceRecord&) = 0; //!< retrieves one DNSResource record, returns false if no more were available
virtual bool get(DNSZoneRecord& zoneRecord);
if the backend does not consider itself responsible for the id passed.
\param domain_id ID of which a list is requested
*/
- virtual bool list(const ZoneName& target, int domain_id, bool include_disabled = false) = 0;
+ virtual bool list(const ZoneName& target, domainid_t domain_id, bool include_disabled = false) = 0;
virtual ~DNSBackend() = default;
//! fills the soadata struct with the SOA details. Returns false if there is no SOA.
virtual bool getSOA(const ZoneName& domain, SOAData& soaData);
- virtual bool replaceRRSet(uint32_t /* domain_id */, const DNSName& /* qname */, const QType& /* qt */, const vector<DNSResourceRecord>& /* rrset */)
+ virtual bool replaceRRSet(domainid_t /* domain_id */, const DNSName& /* qname */, const QType& /* qt */, const vector<DNSResourceRecord>& /* rrset */)
{
return false;
}
- virtual bool listSubZone(const ZoneName& /* zone */, int /* domain_id */)
+ virtual bool listSubZone(const ZoneName& /* zone */, domainid_t /* domain_id */)
{
return false;
}
virtual bool getTSIGKeys(std::vector<struct TSIGKey>& /* keys */) { return false; }
virtual bool deleteTSIGKey(const DNSName& /* name */) { return false; }
- virtual bool getBeforeAndAfterNamesAbsolute(uint32_t /* id */, const DNSName& qname, DNSName& /* unhashed */, DNSName& /* before */, DNSName& /* after */)
+ virtual bool getBeforeAndAfterNamesAbsolute(domainid_t /* id */, const DNSName& qname, DNSName& /* unhashed */, DNSName& /* before */, DNSName& /* after */)
{
throw PDNSException("DNSSEC operation invoked on non-DNSSEC capable backend, qname: '" + qname.toLogString() + "'");
}
- virtual bool getBeforeAndAfterNames(uint32_t /* id */, const ZoneName& zonename, const DNSName& qname, DNSName& before, DNSName& after);
+ virtual bool getBeforeAndAfterNames(domainid_t /* id */, const ZoneName& zonename, const DNSName& qname, DNSName& before, DNSName& after);
- virtual bool updateDNSSECOrderNameAndAuth(uint32_t /* domain_id */, const DNSName& /* qname */, const DNSName& /* ordername */, bool /* auth */, const uint16_t /* qtype */ = QType::ANY)
+ virtual bool updateDNSSECOrderNameAndAuth(domainid_t /* domain_id */, const DNSName& /* qname */, const DNSName& /* ordername */, bool /* auth */, const uint16_t /* qtype */ = QType::ANY)
{
return false;
}
- virtual bool updateEmptyNonTerminals(uint32_t /* domain_id */, set<DNSName>& /* insert */, set<DNSName>& /* erase */, bool /* remove */)
+ virtual bool updateEmptyNonTerminals(domainid_t /* domain_id */, set<DNSName>& /* insert */, set<DNSName>& /* erase */, bool /* remove */)
{
return false;
}
// end DNSSEC
// comments support
- virtual bool listComments(uint32_t /* domain_id */)
+ virtual bool listComments(domainid_t /* domain_id */)
{
return false; // unsupported by this backend
}
return false;
}
- virtual bool replaceComments(const uint32_t /* domain_id */, const DNSName& /* qname */, const QType& /* qt */, const vector<Comment>& /* comments */)
+ virtual bool replaceComments(const domainid_t /* domain_id */, const DNSName& /* qname */, const QType& /* qt */, const vector<Comment>& /* comments */)
{
return false;
}
//! returns true if primary ip is primary for domain name.
//! starts the transaction for updating domain qname, destroying all
- //! existing data for that domain if id is >= 0. In this case, the id MUST
- //! match the DomainInfo information for qname, or very bad things will
- //! happen.
+ //! existing data for that domain if id is != UnknownDomainID. In this case,
+ //! the id MUST match the DomainInfo information for qname, or very bad things
+ //! will happen.
//! FIXME: replace this with a bool to make this a less error-prone interface.
- virtual bool startTransaction(const ZoneName& /* qname */, int /* id */ = -1)
+ virtual bool startTransaction(const ZoneName& /* qname */, domainid_t /* id */ = UnknownDomainID)
{
return false;
}
{
return false; // no problem!
}
- virtual bool feedEnts(int /* domain_id */, map<DNSName, bool>& /* nonterm */)
+ virtual bool feedEnts(domainid_t /* domain_id */, map<DNSName, bool>& /* nonterm */)
{
return false;
}
- virtual bool feedEnts3(int /* domain_id */, const DNSName& /* domain */, map<DNSName, bool>& /* nonterm */, const NSEC3PARAMRecordContent& /* ns3prc */, bool /* narrow */)
+ virtual bool feedEnts3(domainid_t /* domain_id */, const DNSName& /* domain */, map<DNSName, bool>& /* nonterm */, const NSEC3PARAMRecordContent& /* ns3prc */, bool /* narrow */)
{
return false;
}
}
//! Called by PowerDNS to inform a backend that a domain need to be checked for freshness
- virtual void setStale(uint32_t /* domain_id */)
+ virtual void setStale(domainid_t /* domain_id */)
{
}
//! Called by PowerDNS to inform a backend that a domain has been checked for freshness
- virtual void setFresh(uint32_t /* domain_id */)
+ virtual void setFresh(domainid_t /* domain_id */)
{
}
//! Called by PowerDNS to inform a backend that the changes in the domain have been reported to secondaries
- virtual void setNotified(uint32_t /* id */, uint32_t /* serial */)
+ virtual void setNotified(domainid_t /* id */, uint32_t /* serial */)
{
}
struct SOAData
{
SOAData() :
- domain_id(-1) {};
+ domain_id(UnknownDomainID) {};
DNSName qname;
DNSName nameserver;
uint32_t expire{};
uint32_t minimum{};
DNSBackend* db{};
- int domain_id{};
+ domainid_t domain_id{};
[[nodiscard]] uint32_t getNegativeTTL() const { return min(ttl, minimum); }
};
struct DNSZoneRecord
{
- int domain_id{-1};
+ domainid_t domain_id{UnknownDomainID};
uint8_t scopeMask{0};
int signttl{0};
DNSName wildcardname;
bool TSIGGrantsAccess(const ZoneName& zone, const DNSName& keyname);
bool getTSIGForAccess(const ZoneName& zone, const ComboAddress& primary, DNSName* keyname);
- void startTransaction(const ZoneName& zone, int zone_id)
+ void startTransaction(const ZoneName& zone, domainid_t zone_id)
{
(*d_keymetadb->backends.begin())->startTransaction(zone, zone_id);
}
g_log << Logger::Error << "Failed to create " << zonename << " for potential autoprimary " << remote << endl;
return RCode::ServFail;
}
- // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
g_zoneCache.add(zonename, di.id);
if (tsigkeyname.empty() == false) {
vector<string> meta;
DomainInfo,
indexed_by<
ordered_non_unique< member<DomainInfo,ZoneName,&DomainInfo::zone>, CanonZoneNameCompare >,
- ordered_non_unique< member<DomainInfo,uint32_t,&DomainInfo::id> >
+ ordered_non_unique< member<DomainInfo,domainid_t,&DomainInfo::id> >
>
> seenInfos;
auto& seenNames = seenInfos.get<0>();
DNSResourceRecord rr;
makeIncreasedSOARecord(sd, "SOA-EDIT-INCREASE", soaEditKind, rr);
- sd.db->startTransaction(zone, -1);
+ sd.db->startTransaction(zone, UnknownDomainID);
auto rrs = vector<DNSResourceRecord>{rr};
if (!sd.db->replaceRRSet(sd.domain_id, zone.operator const DNSName&(), rr.qtype, rrs)) {
return EXIT_FAILURE;
}
- di.backend->startTransaction(zone, -1);
+ di.backend->startTransaction(zone, UnknownDomainID);
try {
if(di.backend->deleteDomain(zone)) {
di.backend->commitTransaction();
else if(changed.empty() || c!='a')
goto reAsk2;
- di.backend->startTransaction(zone, -1);
+ di.backend->startTransaction(zone, UnknownDomainID);
for(const auto& change : changed) {
vector<DNSResourceRecord> vrr;
for(const DNSRecord& rr : grouped[change.first]) {
}
}
- di.backend->startTransaction(zone, -1);
+ di.backend->startTransaction(zone, UnknownDomainID);
// Enforce that CNAME records can not be mixed with any other.
// If we add a CNAME: there should be no existing records except for one
name=DNSName(name_)+zone.operator const DNSName&();
QType qt(QType::chartocode(type_.c_str()));
- di.backend->startTransaction(zone, -1);
+ di.backend->startTransaction(zone, UnknownDomainID);
di.backend->replaceRRSet(di.id, name, qt, vector<DNSResourceRecord>());
di.backend->commitTransaction();
return EXIT_SUCCESS;
vector<DNSKEYRecordContent> keys;
DNSZoneRecord zr;
- // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
di.backend->lookup(QType(QType::DNSKEY), zone.operator const DNSName&(), di.id );
while(di.backend->get(zr)) {
keys.push_back(*getRR<DNSKEYRecordContent>(zr.dr));
cout<<"Committing"<<endl;
db->commitTransaction();
cout<<"Querying TXT"<<endl;
- // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
db->lookup(QType(QType::TXT), zone.operator const DNSName&(), di.id);
if(db->get(rrget))
{
unsigned int zoneErrors=0;
for(unsigned int n = 1; n < cmds.size(); ++n) { // NOLINT(readability-identifier-length)
ZoneName zone(cmds.at(n));
- dk.startTransaction(zone, -1);
+ dk.startTransaction(zone, UnknownDomainID);
if(secureZone(dk, zone)) {
mustRectify.push_back(std::move(zone));
} else {
throw PDNSException("Failed to create zone");
}
// move records
- // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
if (!src->list(di.zone, di.id, true)) {
throw PDNSException("Failed to list records");
}
nr=0;
- // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
tgt->startTransaction(di.zone, di_new.id);
while(src->get(rr)) {
- // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
rr.domain_id = di_new.id;
if (!tgt->feedRecord(rr, DNSName())) {
throw PDNSException("Failed to feed record");
}
Comment c; // NOLINT(readability-identifier-length)
while(src->getComment(c)) {
- // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
c.domain_id = di_new.id;
if (!tgt->feedComment(c)) {
throw PDNSException("Failed to feed zone comments");
break;
bool foundShorter = false;
- // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
di->backend->lookup(QType(QType::ANY), shorter.operator const DNSName&(), di->id);
while (di->backend->get(rec)) {
if (rec.qname == rr->d_name && rec.qtype == QType::DS)
DLOG(g_log<<msgPrefix<<"Going to fix auth flags below "<<rr->d_name<<endl);
insnonterm.clear(); // No ENT's are needed below delegates (auth=0)
vector<DNSName> qnames;
- // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
di->backend->listSubZone(ZoneName(rr->d_name), di->id);
while(di->backend->get(rec)) {
if (rec.qtype.getCode() && rec.qtype.getCode() != QType::DS && rr->d_name != rec.qname) // Skip ENT, DS and our already corrected record.
// If we've removed a delegate, we need to reset ordername/auth for some records.
if (rrType == QType::NS && rr->d_name != di->zone.operator const DNSName&()) {
vector<DNSName> belowOldDelegate, nsRecs, updateAuthFlag;
- // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
di->backend->listSubZone(ZoneName(rr->d_name), di->id);
while (di->backend->get(rec)) {
if (rec.qtype.getCode()) // skip ENT records, they are always auth=false
// on that level. If so, we must insert an ENT record.
// We take extra care here to not 'include' the record that we just deleted. Some backends will still return it as they only reload on a commit.
bool foundDeeper = false, foundOtherWithSameName = false;
- // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
di->backend->listSubZone(ZoneName(rr->d_name), di->id);
while (di->backend->get(rec)) {
if (rec.qname == rr->d_name && !count(recordsToDelete.begin(), recordsToDelete.end(), rec))
std::lock_guard<std::mutex> l(s_rfc2136lock); //TODO: i think this lock can be per zone, not for everything
g_log<<Logger::Info<<msgPrefix<<"starting transaction."<<endl;
- if (!di.backend->startTransaction(zonename, -1)) { // Not giving the domain_id means that we do not delete the existing records.
+ if (!di.backend->startTransaction(zonename, UnknownDomainID)) { // Not giving the domain_id means that we do not delete the existing records.
g_log<<Logger::Error<<msgPrefix<<"Backend for domain "<<zonename<<" does not support transaction. Can't do Update packet."<<endl;
return RCode::NotImp;
}
if (nsRRtoDelete.size()) {
vector<DNSResourceRecord> nsRRInZone;
DNSResourceRecord rec;
- // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
di.backend->lookup(QType(QType::NS), di.zone.operator const DNSName&(), di.id);
while (di.backend->get(rec)) {
nsRRInZone.push_back(rec);
struct SimpleDNSZone
{
- SimpleDNSZone(ZoneName name, uint64_t domainId): d_records(std::make_shared<RecordStorage>()), d_name(std::move(name)), d_id(domainId)
+ SimpleDNSZone(ZoneName name, domainid_t domainId): d_records(std::make_shared<RecordStorage>()), d_name(std::move(name)), d_id(domainId)
{
}
std::shared_ptr<RecordStorage> d_records;
ZoneName d_name;
- uint64_t d_id;
+ domainid_t d_id;
};
struct HashedNameTag {};
typedef multi_index_container<
SimpleDNSZone,
indexed_by <
- ordered_unique<tag<IDTag>, member<SimpleDNSZone, uint64_t, &SimpleDNSZone::d_id> >,
+ ordered_unique<tag<IDTag>, member<SimpleDNSZone, domainid_t, &SimpleDNSZone::d_id> >,
hashed_unique<tag<HashedNameTag>, member<SimpleDNSZone, ZoneName, &SimpleDNSZone::d_name> >
>
> ZoneStorage;
// Initialize our backend ID from the suffix, skipping the '-' that DNSBackend adds there
SimpleBackend(const std::string& suffix) :
- d_suffix(suffix), d_backendId(pdns::checked_stoi<decltype(d_backendId)>(suffix.substr(1)))
+ d_suffix(suffix), d_backendId(pdns::checked_stoi<domainid_t>(suffix.substr(1)))
{
}
unsigned int getCapabilities() override { return CAP_LIST; }
- bool findZone(const ZoneName& qdomain, int zoneId, std::shared_ptr<RecordStorage>& records, uint64_t& currentZoneId) const
+ bool findZone(const ZoneName& qdomain, domainid_t zoneId, std::shared_ptr<RecordStorage>& records, domainid_t& currentZoneId) const
{
- currentZoneId = -1;
+ currentZoneId = UnknownDomainID;
records.reset();
- if (zoneId != -1) {
+ if (zoneId != UnknownDomainID) {
const auto& idx = boost::multi_index::get<IDTag>(s_zones.at(d_backendId));
auto it = idx.find(zoneId);
if (it == idx.end()) {
return true;
}
- void lookup(const QType& qtype, const DNSName& qdomain, int zoneId = -1, DNSPacket *pkt_p = nullptr) override
+ void lookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId, DNSPacket *pkt_p) override
{
d_currentScopeMask = 0;
findZone(ZoneName(qdomain), zoneId, d_records, d_currentZone);
return true;
}
- bool list(const ZoneName& target, int zoneId, bool /* include_disabled */ = false) override
+ bool list(const ZoneName& target, domainid_t zoneId, bool /* include_disabled */) override
{
findZone(target, zoneId, d_records, d_currentZone);
}
/* this is not thread-safe */
- static std::unordered_map<uint64_t, ZoneStorage> s_zones;
- static std::unordered_map<uint64_t, MetaDataStorage> s_metadata;
+ static std::unordered_map<domainid_t, ZoneStorage> s_zones;
+ static std::unordered_map<domainid_t, MetaDataStorage> s_metadata;
protected:
std::string d_suffix;
std::shared_ptr<RecordStorage> d_records{nullptr};
RecordStorage::index<OrderedNameTypeTag>::type::const_iterator d_iter;
RecordStorage::index<OrderedNameTypeTag>::type::const_iterator d_end;
- const uint64_t d_backendId;
- uint64_t d_currentZone{0};
+ const domainid_t d_backendId; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes)
+ domainid_t d_currentZone{0}; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes)
uint8_t d_currentScopeMask{0};
};
if (target.isPartOf(best)) {
/* return the best SOA right away */
std::shared_ptr<RecordStorage> records;
- uint64_t zoneId;
- if (!findZone(best, -1, records, zoneId)) {
+ domainid_t zoneId{0};
+ if (!findZone(best, UnknownDomainID, records, zoneId)) {
return false;
}
}
};
-std::unordered_map<uint64_t, SimpleBackend::ZoneStorage> SimpleBackend::s_zones;
-std::unordered_map<uint64_t, SimpleBackend::MetaDataStorage> SimpleBackend::s_metadata;
+std::unordered_map<domainid_t, SimpleBackend::ZoneStorage> SimpleBackend::s_zones;
+std::unordered_map<domainid_t, SimpleBackend::MetaDataStorage> SimpleBackend::s_metadata;
class SimpleBackendFactory : public BackendFactory
{
BOOST_FIXTURE_TEST_SUITE(test_ueberbackend_cc, UeberBackendSetupArgFixture)
-static std::vector<DNSZoneRecord> getRecords(UeberBackend& ub, const DNSName& name, uint16_t qtype, int zoneId, const DNSPacket* pkt)
+// NOLINTNEXTLINE(readability-identifier-length)
+static std::vector<DNSZoneRecord> getRecords(UeberBackend& ub, const DNSName& name, uint16_t qtype, domainid_t zoneId, const DNSPacket* pkt)
{
std::vector<DNSZoneRecord> result;
return result;
}
-static void checkRecordExists(const std::vector<DNSZoneRecord>& records, const DNSName& name, uint16_t type, int zoneId, uint8_t scopeMask, bool auth)
+static void checkRecordExists(const std::vector<DNSZoneRecord>& records, const DNSName& name, uint16_t type, domainid_t zoneId, uint8_t scopeMask, bool auth)
{
BOOST_REQUIRE_GE(records.size(), 1U);
for (const auto& record : records) {
auto testFunction = [](UeberBackend& ub) -> void {
{
- // test SOA with unknown zone id == -1
- auto records = getRecords(ub, DNSName("powerdns.com."), QType::SOA, -1, nullptr);
+ // test SOA with unknown zone id
+ auto records = getRecords(ub, DNSName("powerdns.com."), QType::SOA, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 1U);
checkRecordExists(records, DNSName("powerdns.com."), QType::SOA, 1, 0, true);
}
{
- // test ANY with zone id == -1
- auto records = getRecords(ub, DNSName("powerdns.com."), QType::ANY, -1, nullptr);
+ // test ANY with unknown zone id
+ auto records = getRecords(ub, DNSName("powerdns.com."), QType::ANY, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 2U);
checkRecordExists(records, DNSName("powerdns.com."), QType::SOA, 1, 0, true);
checkRecordExists(records, DNSName("powerdns.com."), QType::AAAA, 1, 0, true);
}
{
- // test AAAA with zone id == -1
- auto records = getRecords(ub, DNSName("powerdns.com."), QType::AAAA, -1, nullptr);
+ // test AAAA with unknown zone id
+ auto records = getRecords(ub, DNSName("powerdns.com."), QType::AAAA, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 1U);
checkRecordExists(records, DNSName("powerdns.com."), QType::AAAA, 1, 0, true);
}
{
- // test NODATA with zone id == -1
- auto records = getRecords(ub, DNSName("powerdns.com."), QType::PTR, -1, nullptr);
+ // test NODATA with unknown zone id
+ auto records = getRecords(ub, DNSName("powerdns.com."), QType::PTR, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 0U);
}
auto testFunction = [](UeberBackend& ub) -> void {
{
- // test SOA with unknown zone id == -1
- auto records = getRecords(ub, DNSName("powerdns.com."), QType::SOA, -1, nullptr);
+ // test SOA with unknown zone id
+ auto records = getRecords(ub, DNSName("powerdns.com."), QType::SOA, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 1U);
checkRecordExists(records, DNSName("powerdns.com."), QType::SOA, 1, 0, true);
- records = getRecords(ub, DNSName("powerdns.org."), QType::SOA, -1, nullptr);
+ records = getRecords(ub, DNSName("powerdns.org."), QType::SOA, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 1U);
checkRecordExists(records, DNSName("powerdns.org."), QType::SOA, 2, 0, true);
}
{
- // test ANY with zone id == -1
- auto records = getRecords(ub, DNSName("powerdns.com."), QType::ANY, -1, nullptr);
+ // test ANY with unknown zone id
+ auto records = getRecords(ub, DNSName("powerdns.com."), QType::ANY, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 2U);
checkRecordExists(records, DNSName("powerdns.com."), QType::SOA, 1, 0, true);
checkRecordExists(records, DNSName("powerdns.com."), QType::AAAA, 1, 0, true);
- records = getRecords(ub, DNSName("powerdns.org."), QType::ANY, -1, nullptr);
+ records = getRecords(ub, DNSName("powerdns.org."), QType::ANY, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 2U);
checkRecordExists(records, DNSName("powerdns.org."), QType::SOA, 2, 0, true);
checkRecordExists(records, DNSName("powerdns.org."), QType::AAAA, 2, 0, true);
}
{
- // test AAAA with zone id == -1
- auto records = getRecords(ub, DNSName("powerdns.com."), QType::AAAA, -1, nullptr);
+ // test AAAA with unknown zone id
+ auto records = getRecords(ub, DNSName("powerdns.com."), QType::AAAA, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 1U);
checkRecordExists(records, DNSName("powerdns.com."), QType::AAAA, 1, 0, true);
- records = getRecords(ub, DNSName("powerdns.org."), QType::AAAA, -1, nullptr);
+ records = getRecords(ub, DNSName("powerdns.org."), QType::AAAA, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 1U);
checkRecordExists(records, DNSName("powerdns.org."), QType::AAAA, 2, 0, true);
}
{
- // test NODATA with zone id == -1
- auto records = getRecords(ub, DNSName("powerdns.com."), QType::PTR, -1, nullptr);
+ // test NODATA with unknown zone id
+ auto records = getRecords(ub, DNSName("powerdns.com."), QType::PTR, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 0U);
- records = getRecords(ub, DNSName("powerdns.org."), QType::PTR, -1, nullptr);
+ records = getRecords(ub, DNSName("powerdns.org."), QType::PTR, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 0U);
}
auto testFunction = [](UeberBackend& ub) -> void {
{
- // test SOA with unknown zone id == -1
- auto records = getRecords(ub, DNSName("powerdns.com."), QType::SOA, -1, nullptr);
+ // test SOA with unknown zone id
+ auto records = getRecords(ub, DNSName("powerdns.com."), QType::SOA, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 1U);
checkRecordExists(records, DNSName("powerdns.com."), QType::SOA, 1, 0, true);
}
{
- // test ANY with zone id == -1
- auto records = getRecords(ub, DNSName("powerdns.com."), QType::ANY, -1, nullptr);
+ // test ANY with unknown zone id
+ auto records = getRecords(ub, DNSName("powerdns.com."), QType::ANY, UnknownDomainID, nullptr);
// /!\ only 3 records are returned since we don't allow spreading the same name over several backends
BOOST_REQUIRE_EQUAL(records.size(), 3U);
checkRecordExists(records, DNSName("powerdns.com."), QType::SOA, 1, 0, true);
}
{
- // test AAAA with zone id == -1
- auto records = getRecords(ub, DNSName("powerdns.com."), QType::AAAA, -1, nullptr);
+ // test AAAA with unknown zone id
+ auto records = getRecords(ub, DNSName("powerdns.com."), QType::AAAA, UnknownDomainID, nullptr);
// /!\ the AAAA will be found on an exact search, but not on an ANY one
BOOST_REQUIRE_EQUAL(records.size(), 1U);
checkRecordExists(records, DNSName("powerdns.com."), QType::AAAA, 1, 0, true);
}
{
- // test NODATA with zone id == -1
- auto records = getRecords(ub, DNSName("powerdns.com."), QType::PTR, -1, nullptr);
+ // test NODATA with unknown zone id
+ auto records = getRecords(ub, DNSName("powerdns.com."), QType::PTR, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 0U);
}
auto testFunction = [](UeberBackend& ub) -> void {
{
- // test SOA with unknown zone id == -1
- auto records = getRecords(ub, DNSName("powerdns.com."), QType::SOA, -1, nullptr);
+ // test SOA with unknown zone id
+ auto records = getRecords(ub, DNSName("powerdns.com."), QType::SOA, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 1U);
checkRecordExists(records, DNSName("powerdns.com."), QType::SOA, 1, 0, true);
}
{
- // test ANY with zone id == -1
- auto records = getRecords(ub, DNSName("powerdns.com."), QType::ANY, -1, nullptr);
+ // test ANY with unknown zone id
+ auto records = getRecords(ub, DNSName("powerdns.com."), QType::ANY, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 5U);
checkRecordExists(records, DNSName("powerdns.com."), QType::SOA, 1, 0, true);
checkRecordExists(records, DNSName("powerdns.com."), QType::NS, 1, 0, true);
}
{
- // test AAAA with zone id == -1
- auto records = getRecords(ub, DNSName("powerdns.com."), QType::AAAA, -1, nullptr);
+ // test AAAA with unknown zone id
+ auto records = getRecords(ub, DNSName("powerdns.com."), QType::AAAA, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 1U);
checkRecordExists(records, DNSName("powerdns.com."), QType::AAAA, 1, 0, true);
}
{
- // test NODATA with zone id == -1
- auto records = getRecords(ub, DNSName("powerdns.com."), QType::PTR, -1, nullptr);
+ // test NODATA with unknown zone id
+ auto records = getRecords(ub, DNSName("powerdns.com."), QType::PTR, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 0U);
}
auto testFunction = [](UeberBackend& ub) -> void {
{
- // test SOA with unknown zone id == -1
- auto records = getRecords(ub, DNSName("com."), QType::SOA, -1, nullptr);
+ // test SOA with unknown zone id
+ auto records = getRecords(ub, DNSName("com."), QType::SOA, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 1U);
checkRecordExists(records, DNSName("com."), QType::SOA, 1, 0, true);
- records = getRecords(ub, DNSName("powerdns.com."), QType::SOA, -1, nullptr);
+ records = getRecords(ub, DNSName("powerdns.com."), QType::SOA, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 1U);
checkRecordExists(records, DNSName("powerdns.com."), QType::SOA, 2, 0, true);
}
{
- // test ANY with zone id == -1
- auto records = getRecords(ub, DNSName("powerdns.com."), QType::ANY, -1, nullptr);
+ // test ANY with unknown zone id
+ auto records = getRecords(ub, DNSName("powerdns.com."), QType::ANY, UnknownDomainID, nullptr);
BOOST_REQUIRE_EQUAL(records.size(), 3U);
checkRecordExists(records, DNSName("powerdns.com."), QType::SOA, 2, 0, true);
checkRecordExists(records, DNSName("powerdns.com."), QType::NS, 2, 0, true);
throw ApiException("Creating domain '" + zonename.toString() + "' failed: lookup of domain ID failed");
}
- domainInfo.backend->startTransaction(zonename, static_cast<int>(domainInfo.id));
+ domainInfo.backend->startTransaction(zonename, domainInfo.id);
// will be overridden by updateDomainSettingsFromDocument, if given in document.
domainInfo.backend->setDomainMetadataOne(zonename, "SOA-EDIT-API", "DEFAULT");
checkNewRecords(new_records, zoneData.zoneName);
- zoneData.domainInfo.backend->startTransaction(zoneData.zoneName, static_cast<int>(zoneData.domainInfo.id));
+ zoneData.domainInfo.backend->startTransaction(zoneData.zoneName, zoneData.domainInfo.id);
for (auto& resourceRecord : new_records) {
resourceRecord.domain_id = static_cast<int>(zoneData.domainInfo.id);
zoneData.domainInfo.backend->feedRecord(resourceRecord, DNSName());
}
else {
// avoid deleting current zone contents
- zoneData.domainInfo.backend->startTransaction(zoneData.zoneName, -1);
+ zoneData.domainInfo.backend->startTransaction(zoneData.zoneName, UnknownDomainID);
}
// updateDomainSettingsFromDocument will rectify the zone and update SOA serial.
// delete domain
- zoneData.domainInfo.backend->startTransaction(zoneData.zoneName, -1);
+ zoneData.domainInfo.backend->startTransaction(zoneData.zoneName, UnknownDomainID);
try {
if (!zoneData.domainInfo.backend->deleteDomain(zoneData.zoneName)) {
throw ApiException("Deleting domain '" + zoneData.zoneName.toString() + "' failed: backend delete failed/unsupported");