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

use simpler version of Name::split() for better readability (trac #200)


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@2159 e5f2f494-b856-4b98-b285-d166d9295462
parent e25a9be8
......@@ -202,18 +202,18 @@ refQuery(const Name& name, const RRClass& qclass, const DataSrc* ds,
}
// Match downward, from the zone apex to the query name, looking for
// referrals.
// referrals. Note that we exclude the apex name and query name themselves;
// they'll be handled in a normal lookup in the zone.
inline bool
hasDelegation(const DataSrc* ds, const Name* zonename, Query& q,
QueryTaskPtr task)
{
const int nlen = task->qname.getLabelCount();
const int diff = nlen - zonename->getLabelCount();
const int diff = task->qname.getLabelCount() - zonename->getLabelCount();
if (diff > 1) {
bool found = false;
RRsetList ref;
for (int i = diff; i > 1; --i) {
const Name sub(task->qname.split(i - 1, nlen - i));
for (int i = diff - 1; i > 0; --i) {
const Name sub(task->qname.split(i));
if (refQuery(sub, q.qclass(), ds, zonename, ref)) {
found = true;
break;
......@@ -360,11 +360,11 @@ proveNX(Query& q, QueryTaskPtr task, const DataSrc* ds,
// Find the closest provable enclosing name for QNAME
Name enclosure(zonename);
const int nlen = task->qname.getLabelCount();
const int diff = nlen - enclosure.getLabelCount();
const int diff = task->qname.getLabelCount() -
enclosure.getLabelCount();
string hash2;
for (int i = 1; i <= diff; ++i) {
enclosure = task->qname.split(i, nlen - i);
enclosure = task->qname.split(i);
string nodehash(nsec3->getHash(enclosure));
if (nodehash == hash1) {
break;
......@@ -434,8 +434,7 @@ tryWildcard(Query& q, QueryTaskPtr task, const DataSrc* ds,
return (DataSrc::SUCCESS);
}
const int nlen = task->qname.getLabelCount();
const int diff = nlen - zonename->getLabelCount();
const int diff = task->qname.getLabelCount() - zonename->getLabelCount();
if (diff < 1) {
return (DataSrc::SUCCESS);
}
......@@ -445,7 +444,7 @@ tryWildcard(Query& q, QueryTaskPtr task, const DataSrc* ds,
bool cname = false;
for (int i = 1; i <= diff; ++i) {
const Name& wname(star.concatenate(task->qname.split(i, nlen - i)));
const Name& wname(star.concatenate(task->qname.split(i)));
QueryTask newtask(wname, task->qclass, task->qtype, Section::ANSWER(),
QueryTask::AUTH_QUERY);
result = doQueryTask(ds, zonename, newtask, wild);
......@@ -541,8 +540,7 @@ DataSrc::doQuery(Query& q) {
// (Note that RRtype DS queries need to go to the parent.)
const int nlabels = task->qname.getLabelCount() - 1;
NameMatch match(nlabels != 0 && task->qtype == RRType::DS() ?
task->qname.split(1, task->qname.getLabelCount() - 1) :
task->qname);
task->qname.split(1) : task->qname);
findClosestEnclosure(match, task->qclass);
const DataSrc* datasource = match.bestDataSrc();
const Name* zonename = match.closestName();
......
......@@ -330,7 +330,7 @@ int
Sqlite3DataSrc::findClosest(const Name& name, unsigned int* position) const {
const unsigned int nlabels = name.getLabelCount();
for (unsigned int i = 0; i < nlabels; ++i) {
const Name matchname(name.split(i, nlabels - i));
const Name matchname(name.split(i));
const int rc = hasExactZone(matchname.toText().c_str());
if (rc >= 0) {
if (position != NULL) {
......@@ -356,9 +356,7 @@ Sqlite3DataSrc::findClosestEnclosure(NameMatch& match,
return;
}
match.update(*this, match.qname().split(position,
match.qname().getLabelCount() -
position));
match.update(*this, match.qname().split(position));
}
DataSrc::Result
......
......@@ -540,6 +540,15 @@ TEST_F(DataSrcTest, Dname) {
EXPECT_TRUE(it->isLast());
}
TEST_F(DataSrcTest, DnameExact) {
// The example.org test zone has a DNAME RR for dname2.foo.example.org.
// A query for that name with a different RR type than DNAME shouldn't
// confuse delegation processing.
createAndProcessQuery(Name("dname2.foo.example.org"), RRClass::IN(),
RRType::A());
headerCheck(msg, Rcode::NOERROR(), true, true, true, 0, 1, 0);
}
TEST_F(DataSrcTest, Cname) {
readAndProcessQuery("q_cname");
......
......@@ -11,3 +11,4 @@ mail.example.org. A 192.0.2.10
sub.example.org. NS ns.sub.example.org.
ns.sub.example.org. A 192.0.2.101
dname.example.org. DNAME dname.example.info.
dname2.foo.example.org. DNAME dname2.example.info.
Supports Markdown
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