[svn] commit: r802 - in /branches/each-ds/src/lib/auth/cpp: data_source.cc data_source.h data_source_sqlite3.cc data_source_sqlite3.h data_source_static.cc data_source_static.h query.h
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Feb 11 22:26:51 UTC 2010
Author: each
Date: Thu Feb 11 22:26:50 2010
New Revision: 802
Log:
checkpoint:
- remove extra versions of findRRset() and findAddrs();
just pass the Query in to indicate whether dnssec is wanted or not.
for now, we still pass in two RRsetLists for data and sigs, but it is
expected that these will be merged down into a single one for data
(which includes signatures) soon
- additional-section processing for NS and MX is now suppported
Modified:
branches/each-ds/src/lib/auth/cpp/data_source.cc
branches/each-ds/src/lib/auth/cpp/data_source.h
branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.cc
branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.h
branches/each-ds/src/lib/auth/cpp/data_source_static.cc
branches/each-ds/src/lib/auth/cpp/data_source_static.h
branches/each-ds/src/lib/auth/cpp/query.h
Modified: branches/each-ds/src/lib/auth/cpp/data_source.cc
==============================================================================
--- branches/each-ds/src/lib/auth/cpp/data_source.cc (original)
+++ branches/each-ds/src/lib/auth/cpp/data_source.cc Thu Feb 11 22:26:50 2010
@@ -12,6 +12,45 @@
namespace isc {
namespace dns {
+
+static void
+getAdditional(Query& q, RRsetPtr rrset) {
+ RdataIteratorPtr it = rrset->getRdataIterator();
+ for (it->first(); !it->isLast(); it->next()) {
+ const rdata::Rdata& rd(it->getCurrent());
+ if (rrset->getType() == RRType::NS()) {
+ const rdata::generic::NS& ns =
+ dynamic_cast<const rdata::generic::NS&>(rd);
+ const Name& nsname(ns.getNSName());
+ bool add = false;
+
+ // Don't bother with A/AAAA record in the additional section
+ // if they match the qname/qtype that we've already answered.
+ if (nsname != q.qname() || q.qtype() != RRType::A()) {
+ q.tasks().push(QueryTask(nsname, q.qclass(), RRType::A(),
+ Section::ADDITIONAL()));
+ add = true;
+ }
+ if (nsname != q.qname() || q.qtype() != RRType::AAAA()) {
+ q.tasks().push(QueryTask(nsname, q.qclass(), RRType::AAAA(),
+ Section::ADDITIONAL()));
+ add = true;
+ }
+ if (add) {
+ q.setStatus(QUERY_GETADDITIONAL);
+ }
+ } else if (rrset->getType() == RRType::MX()) {
+ const rdata::generic::MX& mx =
+ dynamic_cast<const rdata::generic::MX&>(rd);
+ const Name& mxname(mx.getMXName());
+ q.tasks().push(QueryTask(mxname, q.qclass(), RRType::A(),
+ Section::ADDITIONAL()));
+ q.tasks().push(QueryTask(mxname, q.qclass(), RRType::AAAA(),
+ Section::ADDITIONAL()));
+ q.setStatus(QUERY_GETADDITIONAL);
+ }
+ }
+}
DSResult
DataSrc::runQuery(Query q) {
@@ -30,21 +69,21 @@
if (ds == NULL) {
result = ZONE_NOT_FOUND;
- } else if (q.wantDnssec()) {
- result = ds->findRRset(task.qname, task.qclass, task.qtype,
+ } else {
+ result = ds->findRRset(q, task.qname, task.qclass, task.qtype,
data, sigs);
- // XXX validity check:
- // for now, there must only be exactly one RRset in data
- // and no more than one RRset in sigs. the rrtype of data
- // must match the sigtype of sigs, if any
- } else {
- result = ds->findRRset(task.qname, task.qclass, task.qtype,
- data);
+
+ // Check answer validity:
+ // For this version, there should only be one RRset in data,
+ // and no more than one RRset in sigs. We will address other
+ // cases (e.g. ANY queries) later.
+ if (result == SUCCESS && (data.size() != 1 || sigs.size() > 1)) {
+ result = ERROR;
+ }
}
switch (result) {
case SUCCESS:
- // XXX: what if 'data' contains more than one RRset?
m.addRRset(task.section, data[0]);
if (q.wantDnssec() && sigs.size() == 1) {
m.addRRset(task.section, sigs[0]);
@@ -52,28 +91,43 @@
switch (q.status()) {
case QUERY_GETANSWER:
- case QUERY_GETADDITIONAL:
- case QUERY_GETCNAME:
- // if no more work items, add authority section now
- if (q.tasks().empty() &&
- data[0]->getType() != RRType("NS")) {
- q.tasks().push(QueryTask(Name(*match.closestName()),
- task.qclass, RRType("NS"),
- Section::AUTHORITY()));
+ case QUERY_FOLLOWCNAME:
+ getAdditional(q, data[0]);
+ if (q.tasks().empty()) {
+ // No additional processing is needed;
+ // add authority section.
+ if (data[0]->getType() != RRType::NS()) {
+ QueryTask qt(Name(*match.closestName()),
+ task.qclass, RRType::NS(),
+ Section::AUTHORITY());
+ q.tasks().push(qt);
+ }
q.setStatus(QUERY_GETAUTHORITY);
}
continue;
+ case QUERY_GETADDITIONAL:
+ // If no more work items, add authority section now
+ if (q.tasks().empty()) {
+ q.setStatus(QUERY_SUCCESS);
+ return (SUCCESS);
+ }
+ continue;
+
case QUERY_GETAUTHORITY:
- q.setStatus(QUERY_SUCCESS);
- return (SUCCESS);
+ getAdditional(q, data[0]);
+ if (q.tasks().empty()) {
+ q.setStatus(QUERY_SUCCESS);
+ return (SUCCESS);
+ }
+ continue;
default:
dns_throw (Unexpected, "unexpected query status");
}
case CNAME:
- if (data[0]->getType() != RRType("CNAME")) {
+ if (data[0]->getType() != RRType::CNAME()) {
dns_throw (Unexpected, "unexpected query status");
}
@@ -88,9 +142,9 @@
const rdata::generic::CNAME& cname =
dynamic_cast<const rdata::generic::CNAME&>(rd);
const Name& target(cname.getCname());
- q.setStatus(QUERY_GETCNAME);
q.tasks().push(QueryTask(target, task.qclass, task.qtype,
Section::ANSWER()));
+ q.setStatus(QUERY_FOLLOWCNAME);
break;
}
continue;
@@ -101,42 +155,37 @@
if (result == NAME_NOT_FOUND) {
m.setRcode(Rcode::NXDOMAIN());
}
- }
- q.setStatus(QUERY_NODATA);
- if (q.wantDnssec()) {
- result = ds->findRRset(Name(*match.closestName()),
+ result = ds->findRRset(q, Name(*match.closestName()),
task.qclass, RRType::SOA(),
data, sigs);
- } else {
- result = ds->findRRset(Name(*match.closestName()),
- task.qclass, RRType::SOA(),
- data);
+ if (result != SUCCESS) {
+ m.setRcode(Rcode::SERVFAIL());
+ return (ERROR);
+ }
+
+ m.addRRset(Section::AUTHORITY(), data[0]);
+ if (q.wantDnssec() && sigs.size() == 1) {
+ m.addRRset(Section::AUTHORITY(), sigs[0]);
+ }
+
+ q.setStatus(QUERY_FAIL);
+ return (result);
}
-
- if (result != SUCCESS) {
- m.setRcode(Rcode::SERVFAIL());
- return (ERROR);
- }
-
- m.addRRset(Section::AUTHORITY(), data[0]);
- if (q.wantDnssec() && sigs.size() == 1) {
- m.addRRset(Section::AUTHORITY(), sigs[0]);
- }
-
- return (result);
+ continue;
case ZONE_NOT_FOUND:
if (q.status() == QUERY_GETANSWER) {
m.setRcode(Rcode::REFUSED());
+ q.setStatus(QUERY_FAIL);
+ return (result);
}
- q.setStatus(QUERY_NODATA);
- return (result);
+ continue;
case NOT_IMPLEMENTED:
case ERROR:
m.setRcode(Rcode::SERVFAIL());
- q.setStatus(QUERY_NODATA);
+ q.setStatus(QUERY_FAIL);
return (result);
}
}
Modified: branches/each-ds/src/lib/auth/cpp/data_source.h
==============================================================================
--- branches/each-ds/src/lib/auth/cpp/data_source.h (original)
+++ branches/each-ds/src/lib/auth/cpp/data_source.h Thu Feb 11 22:26:50 2010
@@ -51,17 +51,13 @@
// Mandatory 'low-level' methods: These will NOT be implemented by
// the general DataSrc class; subclasses MUST implement them.
- virtual DSResult findRRset(const Name& qname,
+ virtual DSResult findRRset(const Query& q,
+ const Name& qname,
const RRClass& qclass,
const RRType& qtype,
RRsetList& target,
RRsetList& sigs) const = 0;
- virtual DSResult findRRset(const Name& qname,
- const RRClass& qclass,
- const RRType& qtype,
- RRsetList& target) const = 0;
-
virtual void findClosestEnclosure(NameMatch& match) const = 0;
// Optional 'low-level' methods. These will have stub implementations
@@ -79,37 +75,25 @@
DSResult runQuery(Query q);
- virtual DSResult findRRset(const Name& qname,
+ virtual DSResult findRRset(const Query& q,
+ const Name& qname,
const RRClass& qclass,
const RRType& qtype,
RRsetList& target,
RRsetList& sigs) const = 0;
- virtual DSResult findRRset(const Name& qname,
- const RRClass& qclass,
- const RRType& qtype,
- RRsetList& target) const = 0;
-
- virtual DSResult findAddrs(const Name& qname,
+ virtual DSResult findAddrs(const Query& q,
+ const Name& qname,
const RRClass& qclass,
RRsetList& target,
RRsetList& sigs) const {
DSResult r;
- r = findRRset(qname, qclass, RRType::A(), target, sigs);
- if (r != SUCCESS)
+ r = findRRset(q, qname, qclass, RRType::A(), target, sigs);
+ if (r != SUCCESS) {
return (r);
- r = findRRset(qname, qclass, RRType::AAAA(), target, sigs);
- return (r);
- }
-
- virtual DSResult findAddrs(const Name& qname,
- const RRClass& qclass,
- RRsetList& target) const {
- DSResult r;
- r = findRRset(qname, qclass, RRType::A(), target);
- if (r != SUCCESS)
- return (r);
- r = findRRset(qname, qclass, RRType::AAAA(), target);
+ }
+
+ r = findRRset(q, qname, qclass, RRType::AAAA(), target, sigs);
return (r);
}
@@ -155,24 +139,15 @@
// Instead, use findClosestEnclosure() to get a pointer to the best
// concrete data source, then send all queries directly there.
- DSResult findRRset(const Name& qname, const RRClass& qclass,
- const RRType& qtype, RRsetList& target,
- RRsetList& sigs) const {
- return (NOT_IMPLEMENTED);
- }
-
- DSResult findRRset(const Name& qname, const RRClass& qclass,
- const RRType& qtype, RRsetList& target) const {
- return (NOT_IMPLEMENTED);
- }
-
- DSResult findAddrs(const Name& qname, const RRClass& qclass,
+ DSResult findRRset(const Query& q, const Name& qname,
+ const RRClass& qclass, const RRType& qtype,
RRsetList& target, RRsetList& sigs) const {
return (NOT_IMPLEMENTED);
}
- DSResult findAddrs(const Name& qname, const RRClass& qclass,
- RRsetList& target) const {
+ DSResult findAddrs(const Query& q,
+ const Name& qname, const RRClass& qclass,
+ RRsetList& target, RRsetList& sigs) const {
return (NOT_IMPLEMENTED);
}
Modified: branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.cc
==============================================================================
--- branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.cc (original)
+++ branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.cc Thu Feb 11 22:26:50 2010
@@ -335,10 +335,12 @@
}
DSResult
-Sqlite3DataSrc::findRRset(const Name& qname,
+Sqlite3DataSrc::findRRset(const Query& q,
+ const Name& qname,
const RRClass& qclass,
const RRType& qtype,
- RRsetList& target) const
+ RRsetList& target,
+ RRsetList& sigs) const
{
bool node_exists, found_cname;
int rows = findRecords(qname, qtype, target, node_exists, found_cname);
@@ -353,15 +355,6 @@
}
}
-DSResult
-Sqlite3DataSrc::findRRset(const Name& qname,
- const RRClass& qclass,
- const RRType& qtype,
- RRsetList& target, RRsetList& sigs) const
-{
- return (findRRset(qname, qclass, qtype, target));
-}
-
//
// Open the database.
//
Modified: branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.h
==============================================================================
--- branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.h (original)
+++ branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.h Thu Feb 11 22:26:50 2010
@@ -31,15 +31,11 @@
virtual void findClosestEnclosure(NameMatch& match) const;
- virtual DSResult findRRset(const Name& qname,
- const RRClass& qclass,
- const RRType& qtype,
- RRsetList& target, RRsetList& sigs) const;
-
- virtual DSResult findRRset(const Name& qname,
- const RRClass& qclass,
- const RRType& qtype,
- RRsetList& target) const;
+ virtual DSResult findRRset(const Query& q,
+ const Name& qname,
+ const RRClass& qclass,
+ const RRType& qtype,
+ RRsetList& target, RRsetList& sigs) const;
virtual DSResult init();
virtual DSResult close();
Modified: branches/each-ds/src/lib/auth/cpp/data_source_static.cc
==============================================================================
--- branches/each-ds/src/lib/auth/cpp/data_source_static.cc (original)
+++ branches/each-ds/src/lib/auth/cpp/data_source_static.cc Thu Feb 11 22:26:50 2010
@@ -68,10 +68,12 @@
}
DSResult
-StaticDataSrc::findRRset(const Name& qname,
+StaticDataSrc::findRRset(const Query& q,
+ const Name& qname,
const RRClass& qclass,
const RRType& qtype,
- RRsetList& target) const
+ RRsetList& target,
+ RRsetList& sigs) const
{
if (qname == version_name &&
qclass == version->getClass() && qtype == version->getType()) {
@@ -92,19 +94,11 @@
target.push_back(authors_ns);
return SUCCESS;
}
+
// XXX: this is not 100% correct.
// We should also support the nodata/noerror case.
return NAME_NOT_FOUND;
}
-DSResult
-StaticDataSrc::findRRset(const Name& qname,
- const RRClass& qclass,
- const RRType& qtype,
- RRsetList& target, RRsetList& sigs) const
-{
- return findRRset(qname, qclass, qtype, target);
-}
-
}
}
Modified: branches/each-ds/src/lib/auth/cpp/data_source_static.h
==============================================================================
--- branches/each-ds/src/lib/auth/cpp/data_source_static.h (original)
+++ branches/each-ds/src/lib/auth/cpp/data_source_static.h Thu Feb 11 22:26:50 2010
@@ -37,15 +37,12 @@
void findClosestEnclosure(NameMatch& match) const;
- DSResult findRRset(const Name& qname,
+ DSResult findRRset(const Query& q,
+ const Name& qname,
const RRClass& qclass,
const RRType& qtype,
- RRsetList& target, RRsetList& sigs) const;
-
- DSResult findRRset(const Name& qname,
- const RRClass& qclass,
- const RRType& qtype,
- RRsetList& target) const;
+ RRsetList& target,
+ RRsetList& sigs) const;
DSResult init() { return SUCCESS; };
DSResult close() { return SUCCESS; } ;
Modified: branches/each-ds/src/lib/auth/cpp/query.h
==============================================================================
--- branches/each-ds/src/lib/auth/cpp/query.h (original)
+++ branches/each-ds/src/lib/auth/cpp/query.h Thu Feb 11 22:26:50 2010
@@ -31,11 +31,11 @@
enum QueryStatus {
QUERY_GETANSWER,
- QUERY_GETCNAME,
QUERY_GETADDITIONAL,
QUERY_GETAUTHORITY,
+ QUERY_FOLLOWCNAME,
QUERY_SUCCESS,
- QUERY_NODATA
+ QUERY_FAIL
};
///
More information about the bind10-changes
mailing list