Commit 84d0d090 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[1198] proposed further refactor 4: moved the "no name"

(NXDOMAIN/empty name/wildcard) case to a separate method to make the main
method even more concise.
parent 35015af5
......@@ -578,6 +578,40 @@ DatabaseClient::Finder::findWildcardMatch(
return (ZoneFinder::FindResult(result_status, result_rrset));
}
ZoneFinder::FindResult
DatabaseClient::Finder::findNoNameResult(const Name& name, const RRType& type,
FindOptions options,
const DelegationSearchResult& dresult)
{
const bool dnssec_data((options & FIND_DNSSEC) != 0);
// We know the database doesn't have any record for the given name.
// But check if something lives below this domain and if so,
// pretend something is here as well.
if (hasSubdomains(name.toText())) {
LOG_DEBUG(logger, DBG_TRACE_DETAILED,
DATASRC_DATABASE_FOUND_EMPTY_NONTERMINAL).
arg(accessor_->getDBName()).arg(name);
return (FindResult(NXRRSET, dnssec_data ? findNSECCover(name) :
ConstRRsetPtr()));
} else if ((options & NO_WILDCARD) != 0) {
// If wildcard check is disabled, the search should terminate
// with NXDOMAIN.
return (FindResult(NXDOMAIN, dnssec_data ? findNSECCover(name) :
ConstRRsetPtr()));
} else {
// It's not an empty non-terminal so check for wildcards.
const ZoneFinder::FindResult wresult =
findWildcardMatch(name, type, options, dresult);
if (wresult.code == NXDOMAIN && dnssec_data) {
// If the result is NXDOMAIN case and the caller wanted
// DNSSEC data, try getting the NSEC record.
return (FindResult(NXDOMAIN, findNSECCover(name)));
}
return (FindResult(wresult.code, wresult.rrset));
}
}
ZoneFinder::FindResult
DatabaseClient::Finder::find(const isc::dns::Name& name,
const isc::dns::RRType& type,
......@@ -618,45 +652,17 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
DATASRC_DATABASE_FOUND_DELEGATION_EXACT).
arg(accessor_->getDBName()).arg(name);
return (FindResult(DELEGATION, nsi->second));
} else if (type != RRType::CNAME() && cni != found.second.end()) {
// A CNAME here
} else if (type != RRType::CNAME() && cni != found.second.end()) { // CNAME
if (cni->second->getRdataCount() != 1) {
isc_throw(DataSourceError, "CNAME with " <<
cni->second->getRdataCount() <<
" rdata at " << name << ", expected 1");
}
return (FindResult(CNAME, cni->second));
} else if (wti != found.second.end()) {
// Just get the answer
} else if (wti != found.second.end()) { // normal answer
return (FindResult(SUCCESS, wti->second));
} else if (!records_found) {
// Nothing lives here.
// But check if something lives below this domain and if so,
// pretend something is here as well.
if (hasSubdomains(name.toText())) {
LOG_DEBUG(logger, DBG_TRACE_DETAILED,
DATASRC_DATABASE_FOUND_EMPTY_NONTERMINAL).
arg(accessor_->getDBName()).arg(name);
return (FindResult(NXRRSET, dnssec_data ? findNSECCover(name) :
ConstRRsetPtr()));
} else if ((options & NO_WILDCARD) != 0) {
// If wildcard check is disabled, the search should terminate
// with NXDOMAIN.
return (FindResult(NXDOMAIN, dnssec_data ? findNSECCover(name) :
ConstRRsetPtr()));
} else {
// It's not an empty non-terminal so check for wildcards.
// We remove labels one by one and look for the wildcard there.
// Go up to first non-empty domain.
const ZoneFinder::FindResult wresult =
findWildcardMatch(name, type, options, dresult);
if (wresult.code == NXDOMAIN && dnssec_data) {
// If the result is NXDOMAIN case and the caller wanted
// DNSSEC data, try getting the NSEC record.
return (FindResult(NXDOMAIN, findNSECCover(name)));
}
return (FindResult(wresult.code, wresult.rrset));
}
} else if (!records_found) { // NXDOMAIN, empty name, wildcard
return (findNoNameResult(name, type, options, dresult));
} else {
// This is the "usual" NXRRSET case. So in case they want DNSSEC,
// provide the NSEC (which should be available already here)
......
......@@ -976,6 +976,11 @@ public:
const isc::dns::RRType& type, const FindOptions options,
const DelegationSearchResult& dresult);
/// To be documented.
FindResult findNoNameResult(const isc::dns::Name& name,
const isc::dns::RRType& type,
FindOptions options,
const DelegationSearchResult& dresult);
/**
* \brief Checks if something lives below this domain.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment