Commit bb4cc992 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[1607] initial refactoring: change FindResult to Finder::Context and use

shared poitners to it instead of real objects.
no functional change yet, so the conversion is basically only about the
syntax.
parent e5d53f4b
......@@ -69,21 +69,21 @@ Query::addAdditionalAddrs(ZoneFinder& zone, const Name& qname,
// Find A rrset
if (qname_ != qname || qtype_ != RRType::A()) {
ZoneFinder::FindResult a_result = zone.find(qname, RRType::A(),
options | dnssec_opt_);
if (a_result.code == ZoneFinder::SUCCESS) {
ZoneFinderContextPtr a_ctx = zone.find(qname, RRType::A(),
options | dnssec_opt_);
if (a_ctx->code == ZoneFinder::SUCCESS) {
response_.addRRset(Message::SECTION_ADDITIONAL,
boost::const_pointer_cast<AbstractRRset>(a_result.rrset), dnssec_);
boost::const_pointer_cast<AbstractRRset>(a_ctx->rrset), dnssec_);
}
}
// Find AAAA rrset
if (qname_ != qname || qtype_ != RRType::AAAA()) {
ZoneFinder::FindResult aaaa_result = zone.find(qname, RRType::AAAA(),
options | dnssec_opt_);
if (aaaa_result.code == ZoneFinder::SUCCESS) {
ZoneFinderContextPtr aaaa_ctx = zone.find(qname, RRType::AAAA(),
options | dnssec_opt_);
if (aaaa_ctx->code == ZoneFinder::SUCCESS) {
response_.addRRset(Message::SECTION_ADDITIONAL,
boost::const_pointer_cast<AbstractRRset>(aaaa_result.rrset),
boost::const_pointer_cast<AbstractRRset>(aaaa_ctx->rrset),
dnssec_);
}
}
......@@ -91,10 +91,9 @@ Query::addAdditionalAddrs(ZoneFinder& zone, const Name& qname,
void
Query::addSOA(ZoneFinder& finder) {
ZoneFinder::FindResult soa_result = finder.find(finder.getOrigin(),
RRType::SOA(),
dnssec_opt_);
if (soa_result.code != ZoneFinder::SUCCESS) {
ZoneFinderContextPtr soa_ctx = finder.find(finder.getOrigin(),
RRType::SOA(), dnssec_opt_);
if (soa_ctx->code != ZoneFinder::SUCCESS) {
isc_throw(NoSOA, "There's no SOA record in zone " <<
finder.getOrigin().toText());
} else {
......@@ -104,7 +103,7 @@ Query::addSOA(ZoneFinder& finder) {
* to insist.
*/
response_.addRRset(Message::SECTION_AUTHORITY,
boost::const_pointer_cast<AbstractRRset>(soa_result.rrset), dnssec_);
boost::const_pointer_cast<AbstractRRset>(soa_ctx->rrset), dnssec_);
}
}
......@@ -148,10 +147,10 @@ Query::addNXDOMAINProofByNSEC(ZoneFinder& finder, ConstRRsetPtr nsec) {
// Confirm the wildcard doesn't exist (this should result in NXDOMAIN;
// otherwise we shouldn't have got NXDOMAIN for the original query in
// the first place).
const ZoneFinder::FindResult fresult =
ConstZoneFinderContextPtr fcontext =
finder.find(wildname, RRType::NSEC(), dnssec_opt_);
if (fresult.code != ZoneFinder::NXDOMAIN || !fresult.rrset ||
fresult.rrset->getRdataCount() == 0) {
if (fcontext->code != ZoneFinder::NXDOMAIN || !fcontext->rrset ||
fcontext->rrset->getRdataCount() == 0) {
isc_throw(BadNSEC, "Unexpected result for wildcard NXDOMAIN proof");
}
......@@ -160,9 +159,9 @@ Query::addNXDOMAINProofByNSEC(ZoneFinder& finder, ConstRRsetPtr nsec) {
// Note: name comparison is relatively expensive. When we are at the
// stage of performance optimization, we should consider optimizing this
// for some optimized data source implementations.
if (nsec->getName() != fresult.rrset->getName()) {
if (nsec->getName() != fcontext->rrset->getName()) {
response_.addRRset(Message::SECTION_AUTHORITY,
boost::const_pointer_cast<AbstractRRset>(fresult.rrset),
boost::const_pointer_cast<AbstractRRset>(fcontext->rrset),
dnssec_);
}
}
......@@ -230,27 +229,27 @@ Query::addNXDOMAINProofByNSEC3(ZoneFinder& finder) {
void
Query::addWildcardProof(ZoneFinder& finder,
const ZoneFinder::FindResult& db_result)
const ZoneFinder::Context& db_context)
{
if (db_result.isNSECSigned()) {
if (db_context.isNSECSigned()) {
// Case for RFC4035 Section 3.1.3.3.
//
// The query name shouldn't exist in the zone if there were no wildcard
// substitution. Confirm that by specifying NO_WILDCARD. It should
// result in NXDOMAIN and an NSEC RR that proves it should be returned.
const ZoneFinder::FindResult fresult =
ConstZoneFinderContextPtr fcontext =
finder.find(qname_, RRType::NSEC(),
dnssec_opt_ | ZoneFinder::NO_WILDCARD);
if (fresult.code != ZoneFinder::NXDOMAIN || !fresult.rrset ||
fresult.rrset->getRdataCount() == 0) {
if (fcontext->code != ZoneFinder::NXDOMAIN || !fcontext->rrset ||
fcontext->rrset->getRdataCount() == 0) {
isc_throw(BadNSEC,
"Unexpected NSEC result for wildcard proof");
}
response_.addRRset(Message::SECTION_AUTHORITY,
boost::const_pointer_cast<AbstractRRset>(
fresult.rrset),
fcontext->rrset),
dnssec_);
} else if (db_result.isNSEC3Signed()) {
} else if (db_context.isNSEC3Signed()) {
// Case for RFC 5155 Section 7.2.6.
//
// Note that the closest encloser must be the immediate ancestor
......@@ -269,36 +268,36 @@ Query::addWildcardNXRRSETProof(ZoneFinder& finder, ConstRRsetPtr nsec) {
isc_throw(BadNSEC, "NSEC for WILDCARD_NXRRSET is empty");
}
const ZoneFinder::FindResult fresult =
ConstZoneFinderContextPtr fcontext =
finder.find(qname_, RRType::NSEC(),
dnssec_opt_ | ZoneFinder::NO_WILDCARD);
if (fresult.code != ZoneFinder::NXDOMAIN || !fresult.rrset ||
fresult.rrset->getRdataCount() == 0) {
if (fcontext->code != ZoneFinder::NXDOMAIN || !fcontext->rrset ||
fcontext->rrset->getRdataCount() == 0) {
isc_throw(BadNSEC, "Unexpected result for no match QNAME proof");
}
if (nsec->getName() != fresult.rrset->getName()) {
if (nsec->getName() != fcontext->rrset->getName()) {
// one NSEC RR proves wildcard_nxrrset that no matched QNAME.
response_.addRRset(Message::SECTION_AUTHORITY,
boost::const_pointer_cast<AbstractRRset>(fresult.rrset),
boost::const_pointer_cast<AbstractRRset>(fcontext->rrset),
dnssec_);
}
}
void
Query::addDS(ZoneFinder& finder, const Name& dname) {
ZoneFinder::FindResult ds_result =
ConstZoneFinderContextPtr ds_context =
finder.find(dname, RRType::DS(), dnssec_opt_);
if (ds_result.code == ZoneFinder::SUCCESS) {
if (ds_context->code == ZoneFinder::SUCCESS) {
response_.addRRset(Message::SECTION_AUTHORITY,
boost::const_pointer_cast<AbstractRRset>(
ds_result.rrset),
ds_context->rrset),
dnssec_);
} else if (ds_result.code == ZoneFinder::NXRRSET &&
ds_result.isNSECSigned()) {
addNXRRsetProof(finder, ds_result);
} else if (ds_result.code == ZoneFinder::NXRRSET &&
ds_result.isNSEC3Signed()) {
} else if (ds_context->code == ZoneFinder::NXRRSET &&
ds_context->isNSECSigned()) {
addNXRRsetProof(finder, *ds_context);
} else if (ds_context->code == ZoneFinder::NXRRSET &&
ds_context->isNSEC3Signed()) {
// Add no DS proof with NSEC3 as specified in RFC 5155 Section 7.2.7.
addClosestEncloserProof(finder, dname, true);
} else {
......@@ -309,17 +308,17 @@ Query::addDS(ZoneFinder& finder, const Name& dname) {
void
Query::addNXRRsetProof(ZoneFinder& finder,
const ZoneFinder::FindResult& db_result)
const ZoneFinder::Context& db_context)
{
if (db_result.isNSECSigned() && db_result.rrset) {
if (db_context.isNSECSigned() && db_context.rrset) {
response_.addRRset(Message::SECTION_AUTHORITY,
boost::const_pointer_cast<AbstractRRset>(
db_result.rrset),
db_context.rrset),
dnssec_);
if (db_result.isWildcard()) {
addWildcardNXRRSETProof(finder, db_result.rrset);
if (db_context.isWildcard()) {
addWildcardNXRRSETProof(finder, db_context.rrset);
}
} else if (db_result.isNSEC3Signed() && !db_result.isWildcard()) {
} else if (db_context.isNSEC3Signed() && !db_context.isWildcard()) {
if (qtype_ == RRType::DS()) {
// RFC 5155, Section 7.2.4. Add either NSEC3 for the qname or
// closest (provable) encloser proof in case of optout.
......@@ -328,7 +327,7 @@ Query::addNXRRsetProof(ZoneFinder& finder,
// RFC 5155, Section 7.2.3. Just add NSEC3 for the qname.
addNSEC3ForName(finder, qname_, true);
}
} else if (db_result.isNSEC3Signed() && db_result.isWildcard()) {
} else if (db_context.isNSEC3Signed() && db_context.isWildcard()) {
// Case for RFC 5155 Section 7.2.5: add closest encloser proof for the
// qname, construct the matched wildcard name and add NSEC3 for it.
const uint8_t closest_labels =
......@@ -342,18 +341,18 @@ Query::addNXRRsetProof(ZoneFinder& finder,
void
Query::addAuthAdditional(ZoneFinder& finder) {
// Fill in authority and addtional sections.
ZoneFinder::FindResult ns_result =
ConstZoneFinderContextPtr ns_context =
finder.find(finder.getOrigin(), RRType::NS(), dnssec_opt_);
// zone origin name should have NS records
if (ns_result.code != ZoneFinder::SUCCESS) {
if (ns_context->code != ZoneFinder::SUCCESS) {
isc_throw(NoApexNS, "There's no apex NS records in zone " <<
finder.getOrigin().toText());
} else {
response_.addRRset(Message::SECTION_AUTHORITY,
boost::const_pointer_cast<AbstractRRset>(ns_result.rrset), dnssec_);
boost::const_pointer_cast<AbstractRRset>(ns_context->rrset), dnssec_);
// Handle additional for authority section
addAdditional(finder, *ns_result.rrset);
addAdditional(finder, *ns_context->rrset);
}
}
......@@ -404,7 +403,7 @@ Query::process() {
response_.setHeaderFlag(Message::HEADERFLAG_AA);
response_.setRcode(Rcode::NOERROR());
std::vector<ConstRRsetPtr> target;
boost::function0<ZoneFinder::FindResult> find;
boost::function0<ZoneFinderContextPtr> find;
const bool qtype_is_any = (qtype_ == RRType::ANY());
if (qtype_is_any) {
find = boost::bind(&ZoneFinder::findAll, &zfinder, qname_,
......@@ -413,12 +412,12 @@ Query::process() {
find = boost::bind(&ZoneFinder::find, &zfinder, qname_, qtype_,
dnssec_opt_);
}
ZoneFinder::FindResult db_result(find());
switch (db_result.code) {
ZoneFinderContextPtr db_context(find());
switch (db_context->code) {
case ZoneFinder::DNAME: {
// First, put the dname into the answer
response_.addRRset(Message::SECTION_ANSWER,
boost::const_pointer_cast<AbstractRRset>(db_result.rrset),
boost::const_pointer_cast<AbstractRRset>(db_context->rrset),
dnssec_);
/*
* Empty DNAME should never get in, as it is impossible to
......@@ -426,14 +425,14 @@ Query::process() {
*
* FIXME: Other way to prevent this should be done
*/
assert(db_result.rrset->getRdataCount() > 0);
assert(db_context->rrset->getRdataCount() > 0);
// Get the data of DNAME
const rdata::generic::DNAME& dname(
dynamic_cast<const rdata::generic::DNAME&>(
db_result.rrset->getRdataIterator()->getCurrent()));
db_context->rrset->getRdataIterator()->getCurrent()));
// The yet unmatched prefix dname
const Name prefix(qname_.split(0, qname_.getLabelCount() -
db_result.rrset->getName().getLabelCount()));
db_context->rrset->getName().getLabelCount()));
// If we put it together, will it be too long?
// (The prefix contains trailing ., which will be removed
if (prefix.getLength() - Name::ROOT_NAME().getLength() +
......@@ -448,12 +447,12 @@ Query::process() {
// The new CNAME we are creating (it will be unsigned even
// with DNSSEC, the DNAME is signed and it can be validated
// by that)
RRsetPtr cname(new RRset(qname_, db_result.rrset->getClass(),
RRType::CNAME(), db_result.rrset->getTTL()));
RRsetPtr cname(new RRset(qname_, db_context->rrset->getClass(),
RRType::CNAME(), db_context->rrset->getTTL()));
// Construct the new target by replacing the end
cname->addRdata(rdata::generic::CNAME(qname_.split(0,
qname_.getLabelCount() -
db_result.rrset->getName().getLabelCount()).
db_context->rrset->getName().getLabelCount()).
concatenate(dname.getDname())));
response_.addRRset(Message::SECTION_ANSWER, cname, dnssec_);
break;
......@@ -469,13 +468,13 @@ Query::process() {
* So, just put it there.
*/
response_.addRRset(Message::SECTION_ANSWER,
boost::const_pointer_cast<AbstractRRset>(db_result.rrset),
boost::const_pointer_cast<AbstractRRset>(db_context->rrset),
dnssec_);
// If the answer is a result of wildcard substitution,
// add a proof that there's no closer name.
if (dnssec_ && db_result.isWildcard()) {
addWildcardProof(*result.zone_finder,db_result);
if (dnssec_ && db_context->isWildcard()) {
addWildcardProof(*result.zone_finder, *db_context);
}
break;
case ZoneFinder::SUCCESS:
......@@ -490,17 +489,17 @@ Query::process() {
}
} else {
response_.addRRset(Message::SECTION_ANSWER,
boost::const_pointer_cast<AbstractRRset>(db_result.rrset),
boost::const_pointer_cast<AbstractRRset>(db_context->rrset),
dnssec_);
// Handle additional for answer section
addAdditional(*result.zone_finder, *db_result.rrset);
addAdditional(*result.zone_finder, *db_context->rrset);
}
// If apex NS records haven't been provided in the answer
// section, insert apex NS records into the authority section
// and AAAA/A RRS of each of the NS RDATA into the additional
// section.
if (qname_ != result.zone_finder->getOrigin() ||
db_result.code != ZoneFinder::SUCCESS ||
db_context->code != ZoneFinder::SUCCESS ||
(qtype_ != RRType::NS() && !qtype_is_any))
{
addAuthAdditional(*result.zone_finder);
......@@ -508,8 +507,8 @@ Query::process() {
// If the answer is a result of wildcard substitution,
// add a proof that there's no closer name.
if (dnssec_ && db_result.isWildcard()) {
addWildcardProof(*result.zone_finder,db_result);
if (dnssec_ && db_context->isWildcard()) {
addWildcardProof(*result.zone_finder, *db_context);
}
break;
case ZoneFinder::DELEGATION:
......@@ -523,22 +522,22 @@ Query::process() {
response_.setHeaderFlag(Message::HEADERFLAG_AA, false);
response_.addRRset(Message::SECTION_AUTHORITY,
boost::const_pointer_cast<AbstractRRset>(db_result.rrset),
boost::const_pointer_cast<AbstractRRset>(db_context->rrset),
dnssec_);
// If DNSSEC is requested, see whether there is a DS
// record for this delegation.
if (dnssec_) {
addDS(*result.zone_finder, db_result.rrset->getName());
addDS(*result.zone_finder, db_context->rrset->getName());
}
addAdditional(*result.zone_finder, *db_result.rrset);
addAdditional(*result.zone_finder, *db_context->rrset);
break;
case ZoneFinder::NXDOMAIN:
response_.setRcode(Rcode::NXDOMAIN());
addSOA(*result.zone_finder);
if (dnssec_) {
if (db_result.isNSECSigned() && db_result.rrset) {
addNXDOMAINProofByNSEC(zfinder, db_result.rrset);
} else if (db_result.isNSEC3Signed()) {
if (db_context->isNSECSigned() && db_context->rrset) {
addNXDOMAINProofByNSEC(zfinder, db_context->rrset);
} else if (db_context->isNSEC3Signed()) {
addNXDOMAINProofByNSEC3(zfinder);
}
}
......@@ -546,7 +545,7 @@ Query::process() {
case ZoneFinder::NXRRSET:
addSOA(*result.zone_finder);
if (dnssec_) {
addNXRRsetProof(zfinder, db_result);
addNXRRsetProof(zfinder, *db_context);
}
break;
default:
......@@ -579,11 +578,11 @@ Query::processDSAtChild() {
response_.setHeaderFlag(Message::HEADERFLAG_AA);
response_.setRcode(Rcode::NOERROR());
addSOA(*zresult.zone_finder);
const ZoneFinder::FindResult ds_result =
ConstZoneFinderContextPtr ds_context =
zresult.zone_finder->find(qname_, RRType::DS(), dnssec_opt_);
if (ds_result.code == ZoneFinder::NXRRSET) {
if (ds_context->code == ZoneFinder::NXRRSET) {
if (dnssec_) {
addNXRRsetProof(*zresult.zone_finder, ds_result);
addNXRRsetProof(*zresult.zone_finder, *ds_context);
}
}
......
......@@ -96,7 +96,7 @@ private:
/// data
/// \param db_result The ZoneFinder::FindResult returned by find()
void addNXRRsetProof(isc::datasrc::ZoneFinder& finder,
const isc::datasrc::ZoneFinder::FindResult& db_result);
const isc::datasrc::ZoneFinder::Context& db_context);
/// Add NSEC RRs that prove an NXDOMAIN result.
///
......@@ -115,7 +115,7 @@ private:
/// of RFC5155.
void addWildcardProof(
isc::datasrc::ZoneFinder& finder,
const isc::datasrc::ZoneFinder::FindResult& dbResult);
const isc::datasrc::ZoneFinder::Context& db_context);
/// \brief Adds one NSEC RR proved no matched QNAME,one NSEC RR proved no
/// matched <QNAME,QTYPE> through wildcard extension.
......
......@@ -176,16 +176,16 @@ zoneChecks(AuthSrv& server) {
EXPECT_TRUE(server.getInMemoryClient(RRClass::IN()));
EXPECT_EQ(ZoneFinder::SUCCESS, server.getInMemoryClient(RRClass::IN())->
findZone(Name("ns.test1.example")).zone_finder->
find(Name("ns.test1.example"), RRType::A()).code);
find(Name("ns.test1.example"), RRType::A())->code);
EXPECT_EQ(ZoneFinder::NXRRSET, server.getInMemoryClient(RRClass::IN())->
findZone(Name("ns.test1.example")).zone_finder->
find(Name("ns.test1.example"), RRType::AAAA()).code);
find(Name("ns.test1.example"), RRType::AAAA())->code);
EXPECT_EQ(ZoneFinder::SUCCESS, server.getInMemoryClient(RRClass::IN())->
findZone(Name("ns.test2.example")).zone_finder->
find(Name("ns.test2.example"), RRType::A()).code);
find(Name("ns.test2.example"), RRType::A())->code);
EXPECT_EQ(ZoneFinder::NXRRSET, server.getInMemoryClient(RRClass::IN())->
findZone(Name("ns.test2.example")).zone_finder->
find(Name("ns.test2.example"), RRType::AAAA()).code);
find(Name("ns.test2.example"), RRType::AAAA())->code);
}
void
......@@ -213,19 +213,19 @@ newZoneChecks(AuthSrv& server) {
EXPECT_TRUE(server.getInMemoryClient(RRClass::IN()));
EXPECT_EQ(ZoneFinder::SUCCESS, server.getInMemoryClient(RRClass::IN())->
findZone(Name("ns.test1.example")).zone_finder->
find(Name("ns.test1.example"), RRType::A()).code);
find(Name("ns.test1.example"), RRType::A())->code);
// now test1.example should have ns/AAAA
EXPECT_EQ(ZoneFinder::SUCCESS, server.getInMemoryClient(RRClass::IN())->
findZone(Name("ns.test1.example")).zone_finder->
find(Name("ns.test1.example"), RRType::AAAA()).code);
find(Name("ns.test1.example"), RRType::AAAA())->code);
// test2.example shouldn't change
EXPECT_EQ(ZoneFinder::SUCCESS, server.getInMemoryClient(RRClass::IN())->
findZone(Name("ns.test2.example")).zone_finder->
find(Name("ns.test2.example"), RRType::A()).code);
find(Name("ns.test2.example"), RRType::A())->code);
EXPECT_EQ(ZoneFinder::NXRRSET, server.getInMemoryClient(RRClass::IN())->
findZone(Name("ns.test2.example")).zone_finder->
find(Name("ns.test2.example"), RRType::AAAA()).code);
find(Name("ns.test2.example"), RRType::AAAA())->code);
}
TEST_F(AuthCommandTest, loadZone) {
......
......@@ -191,7 +191,7 @@ TEST_F(MemoryDatasrcConfigTest, addOneZone) {
// Check it actually loaded something
EXPECT_EQ(ZoneFinder::SUCCESS, server.getInMemoryClient(rrclass)->findZone(
Name("ns.example.com.")).zone_finder->find(Name("ns.example.com."),
RRType::A()).code);
RRType::A())->code);
}
TEST_F(MemoryDatasrcConfigTest, addMultiZones) {
......
......@@ -370,12 +370,14 @@ public:
}
virtual isc::dns::Name getOrigin() const { return (origin_); }
virtual isc::dns::RRClass getClass() const { return (rrclass_); }
virtual FindResult find(const isc::dns::Name& name,
const isc::dns::RRType& type,
const FindOptions options = FIND_DEFAULT);
virtual FindResult findAll(const isc::dns::Name& name,
std::vector<ConstRRsetPtr>& target,
const FindOptions options = FIND_DEFAULT);
virtual ZoneFinderContextPtr find(const isc::dns::Name& name,
const isc::dns::RRType& type,
const FindOptions options =
FIND_DEFAULT);
virtual ZoneFinderContextPtr findAll(const isc::dns::Name& name,
std::vector<ConstRRsetPtr>& target,
const FindOptions options =
FIND_DEFAULT);
virtual ZoneFinder::FindNSEC3Result
findNSEC3(const Name& name, bool recursive);
......@@ -397,8 +399,7 @@ public:
ConstRRsetPtr rrset)
{
nsec_name_ = nsec_name;
nsec_result_.reset(new ZoneFinder::FindResult(code, rrset,
RESULT_NSEC_SIGNED));
nsec_context_.reset(new Context(code, rrset, RESULT_NSEC_SIGNED));
}
// Once called, the findNSEC3 will return the provided result for the next
......@@ -505,7 +506,7 @@ private:
bool use_nsec3_;
// The following two will be used for faked NSEC cases
Name nsec_name_;
boost::scoped_ptr<ZoneFinder::FindResult> nsec_result_;
ZoneFinderContextPtr nsec_context_;
// The following two are for faking bad NSEC3 responses
// Enabled when not NULL
const FindNSEC3Result* nsec3_fake_;
......@@ -533,12 +534,12 @@ substituteWild(const AbstractRRset& wild_rrset, const Name& real_name) {
return (rrset);
}
ZoneFinder::FindResult
ZoneFinderContextPtr
MockZoneFinder::findAll(const Name& name, std::vector<ConstRRsetPtr>& target,
const FindOptions options)
{
ZoneFinder::FindResult result(find(name, RRType::ANY(), options));
if (result.code == NXRRSET) {
ZoneFinderContextPtr result(find(name, RRType::ANY(), options));
if (result->code == NXRRSET) {
const Domains::const_iterator found_domain = domains_.find(name);
if (!found_domain->second.empty()) {
for (RRsetStore::const_iterator found_rrset =
......@@ -547,7 +548,7 @@ MockZoneFinder::findAll(const Name& name, std::vector<ConstRRsetPtr>& target,
// Insert RRs under the domain name into target
target.push_back(found_rrset->second);
}
return (FindResult(SUCCESS, RRsetPtr()));
return (ZoneFinderContextPtr(new Context(SUCCESS, RRsetPtr())));
}
}
......@@ -610,16 +611,16 @@ MockZoneFinder::findNSEC3(const Name& name, bool recursive) {
isc_throw(isc::Unexpected, "findNSEC3() isn't expected to fail");
}
ZoneFinder::FindResult
ZoneFinderContextPtr
MockZoneFinder::find(const Name& name, const RRType& type,
const FindOptions options)
{
// Emulating a broken zone: mandatory apex RRs are missing if specifically
// configured so (which are rare cases).
if (name == origin_ && type == RRType::SOA() && !has_SOA_) {
return (FindResult(NXDOMAIN, RRsetPtr()));
return (ZoneFinderContextPtr(new Context(NXDOMAIN, RRsetPtr())));
} else if (name == origin_ && type == RRType::NS() && !has_apex_NS_) {
return (FindResult(NXDOMAIN, RRsetPtr()));
return (ZoneFinderContextPtr(new Context(NXDOMAIN, RRsetPtr())));
}
// Special case for names on or under a zone cut and under DNAME
......@@ -634,11 +635,12 @@ MockZoneFinder::find(const Name& name, const RRType& type,
// handled just like an in-zone case below. Others result in
// DELEGATION.
if (type != RRType::DS() || it->first != name) {
return (FindResult(DELEGATION, delegation_ns));
return (ZoneFinderContextPtr(new Context(DELEGATION,
delegation_ns)));
}
} else if (name.compare(dname_name_).getRelation() ==
NameComparisonResult::SUBDOMAIN) {
return (FindResult(DNAME, dname_rrset_));
return (ZoneFinderContextPtr(new Context(DNAME, dname_rrset_)));
}
// normal cases. names are searched for only per exact-match basis
......@@ -668,33 +670,37 @@ MockZoneFinder::find(const Name& name, const RRType& type,
}
rrset = noconst;
}
return (FindResult(SUCCESS, rrset));
return (ZoneFinderContextPtr(new Context(SUCCESS, rrset)));
}
// Otherwise, if this domain name has CNAME, return it.
found_rrset = found_domain->second.find(RRType::CNAME());
if (found_rrset != found_domain->second.end()) {
return (FindResult(CNAME, found_rrset->second));
return (ZoneFinderContextPtr(new Context(CNAME,
found_rrset->second)));
}
// Otherwise it's NXRRSET case...
// ...but a special pathological case first:
if (found_domain->first == bad_signed_delegation_name_ &&
type == RRType::DS()) {
return (FindResult(NXDOMAIN, RRsetPtr()));
return (ZoneFinderContextPtr(new Context(NXDOMAIN, RRsetPtr())));
}
// normal cases follow.
if ((options & FIND_DNSSEC) != 0) {
if (use_nsec3_) {
return (FindResult(NXRRSET, RRsetPtr(), RESULT_NSEC3_SIGNED));
return (ZoneFinderContextPtr(new Context(NXRRSET, RRsetPtr(),
RESULT_NSEC3_SIGNED)));
}
found_rrset = found_domain->second.find(RRType::NSEC());
if (found_rrset != found_domain->second.end()) {
return (FindResult(NXRRSET, found_rrset->second,
RESULT_NSEC_SIGNED));
return (ZoneFinderContextPtr(new Context(NXRRSET,
found_rrset->second,
RESULT_NSEC_SIGNED)));
}
}
return (FindResult(NXRRSET, RRsetPtr(), RESULT_NSEC_SIGNED));
return (ZoneFinderContextPtr(new Context(NXRRSET, RRsetPtr(),
RESULT_NSEC_SIGNED)));
}
// query name isn't found in our domains.
......@@ -714,16 +720,18 @@ MockZoneFinder::find(const Name& name, const RRType& type,
--domain; // reset domain to the "previous name"
if ((options & FIND_DNSSEC) != 0) {
if (use_nsec3_) {
return (FindResult(NXRRSET, RRsetPtr(), RESULT_NSEC3_SIGNED));
return (ZoneFinderContextPtr(new Context(NXRRSET, RRsetPtr(),
RESULT_NSEC3_SIGNED)));
}