BIND 10 trac2098, updated. 49aabed090bd58b4aa295af86f106adbe2d5492b [2098] one minor comment update reflecting recent code changes
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Aug 31 12:29:08 UTC 2012
The branch, trac2098 has been updated
via 49aabed090bd58b4aa295af86f106adbe2d5492b (commit)
via 740e0113d51fe26a7683477e7e0e19d1390119eb (commit)
via e0bdb21d3bc3e0c4c23df61fe204bb6e35fa4057 (commit)
via 19e4b209bd92898239781336796e9dd339dde415 (commit)
via a92987802f0f8106a6c1e2fbf41adb53d8ba67fa (commit)
via cb4c5b31b47ea1062cb74077ff5788f192d60eac (commit)
via 8440ca544d013e4081c4e0762cdb88c9888c0af5 (commit)
via 04c06cecc291057718100127c381c8385aaa9e92 (commit)
via e8ec4c911eb69b969df42a60fb28d5f727b8a937 (commit)
via b166b6061c760ccef7fd83ec354f6338d88162ee (commit)
via 8d2f900a8a8db49df9d7ad6fb26c02c3235b22b0 (commit)
from 36baee1d22c2527174ac34f2c144854f43e0c5f0 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 49aabed090bd58b4aa295af86f106adbe2d5492b
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Fri Aug 31 10:58:29 2012 +0900
[2098] one minor comment update reflecting recent code changes
commit 740e0113d51fe26a7683477e7e0e19d1390119eb
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Fri Aug 31 10:32:13 2012 +0900
[2098] a minor grammar fix in document
commit e0bdb21d3bc3e0c4c23df61fe204bb6e35fa4057
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Fri Aug 31 10:28:40 2012 +0900
[2098] explicitly confirm unexpected method calls result in exception.
commit 19e4b209bd92898239781336796e9dd339dde415
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Fri Aug 31 10:18:23 2012 +0900
[2098] cleanup: removed commented-out unused method parameter.
commit a92987802f0f8106a6c1e2fbf41adb53d8ba67fa
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Fri Aug 31 10:16:15 2012 +0900
[2098] use a real name object for real name instead of serialized labelseqs
It will simplify various parts of the code.
Name object is expensive, but either way it involves memory allocation
anyway, so performance impact wouldn't be much different.
commit cb4c5b31b47ea1062cb74077ff5788f192d60eac
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Fri Aug 31 09:57:53 2012 +0900
[2098] try to improve in-method comments for isSameKind()
commit 8440ca544d013e4081c4e0762cdb88c9888c0af5
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Fri Aug 31 09:43:15 2012 +0900
[2098] unified the normal and truncation toWire test cases.
commit 04c06cecc291057718100127c381c8385aaa9e92
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Thu Aug 30 17:01:08 2012 -0700
[2098] editorial cleanup: removed unnecessary postfix in variable names
commit e8ec4c911eb69b969df42a60fb28d5f727b8a937
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Thu Aug 30 16:58:34 2012 -0700
[2098] make sure unexpected method call doesn't happen by exception/assert
commit b166b6061c760ccef7fd83ec354f6338d88162ee
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Thu Aug 30 16:43:57 2012 -0700
[2098] silence cppcheck warnings
they are basically false positives, but addressing them is not difficult
so I modified the code rather than suppressing them.
commit 8d2f900a8a8db49df9d7ad6fb26c02c3235b22b0
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Wed Aug 29 12:20:44 2012 -0700
[2098] [master] add cppcheck suppression rule for an intentional self-equivalence test
okayed on jabber.
-----------------------------------------------------------------------
Summary of changes:
.../memory/benchmarks/rrset_render_bench.cc | 1 +
src/lib/datasrc/memory/rdata_serialization.cc | 1 +
.../memory/tests/treenode_rrset_unittest.cc | 202 ++++++++++++--------
src/lib/datasrc/memory/treenode_rrset.cc | 64 ++-----
src/lib/datasrc/memory/treenode_rrset.h | 23 ++-
src/lib/dns/benchmarks/message_renderer_bench.cc | 6 +-
src/lib/dns/benchmarks/oldmessagerenderer.cc | 4 +-
src/lib/dns/tests/labelsequence_unittest.cc | 1 +
8 files changed, 164 insertions(+), 138 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/memory/benchmarks/rrset_render_bench.cc b/src/lib/datasrc/memory/benchmarks/rrset_render_bench.cc
index c5cdef6..bc418e8 100644
--- a/src/lib/datasrc/memory/benchmarks/rrset_render_bench.cc
+++ b/src/lib/datasrc/memory/benchmarks/rrset_render_bench.cc
@@ -151,6 +151,7 @@ buildZone(isc::util::MemorySegmentLocal& mem_sgmt,
if ((it + 1) != rrsets.end() &&
(*(it + 1))->getType() == RRType::RRSIG()) {
sig_rrset = *(++it);
+ assert(it != rrsets.end()); // to be safe, and silence cppcheck
}
RdataSet* rdataset =
RdataSet::create(mem_sgmt, encoder, rrset, sig_rrset);
diff --git a/src/lib/datasrc/memory/rdata_serialization.cc b/src/lib/datasrc/memory/rdata_serialization.cc
index 6c3e06c..6ac18d0 100644
--- a/src/lib/datasrc/memory/rdata_serialization.cc
+++ b/src/lib/datasrc/memory/rdata_serialization.cc
@@ -250,6 +250,7 @@ public:
virtual void setCompressMode(CompressMode) {}
virtual void writeName(const LabelSequence&, bool) {
// We don't need this version of writeName
+ isc_throw(Unexpected, "unexpected version of writeName is called");
}
// Called for each domain name in the RDATA, from the RDATA's toWire()
diff --git a/src/lib/datasrc/memory/tests/treenode_rrset_unittest.cc b/src/lib/datasrc/memory/tests/treenode_rrset_unittest.cc
index cf486bf..b95e706 100644
--- a/src/lib/datasrc/memory/tests/treenode_rrset_unittest.cc
+++ b/src/lib/datasrc/memory/tests/treenode_rrset_unittest.cc
@@ -70,7 +70,10 @@ protected:
"match.example.com. 3600 IN RRSIG "
"A 5 2 3600 20120814220826 20120715220826 "
"1234 example.com. FAKE")),
- zone_data_(NULL)
+ zone_data_(NULL), origin_node_(NULL), www_node_(NULL),
+ wildcard_node_(NULL), ns_rdataset_(NULL), dname_rdataset_(NULL),
+ a_rdataset_(NULL), aaaa_rdataset_(NULL), rrsig_only_rdataset_(NULL),
+ wildcard_rdataset_(NULL)
{}
void SetUp() {
// We create some common test data here in SetUp() so it will be
@@ -177,34 +180,73 @@ TEST_F(TreeNodeRRsetTest, create) {
match_name_, rrclass_, RRType::A(), 2, 1);
}
-// Templated if and when we support OutputBuffer version of toWire().
-// Right now, we take a minimalist approach, only implementing testing the
-// renderer version.
+// The following two templated functions are helper to encapsulate the
+// concept truncation and handle MessageRenderer and OutputBuffer transparently
+// in templated test cases.
+template <typename OutputType>
+void
+setOutputLengthLimit(OutputType& output, size_t len_limit) {
+ output.setLengthLimit(len_limit);
+}
+template <>
+void
+setOutputLengthLimit<OutputBuffer>(OutputBuffer&, size_t) {
+}
+
+template <typename OutputType>
+bool
+isOutputTruncated(OutputType& output) {
+ return (output.isTruncated());
+}
+template <>
+bool
+isOutputTruncated<OutputBuffer>(OutputBuffer&) {
+ return (false);
+}
+
+// Templated so we so can support OutputBuffer version of toWire().
+// We use the above helper templated functions for some renderer only methods.
+// We test two sets of cases: normal rendering case and case when truncation
+// is expected. The latter is effectively for MessageRenderer only.
+// If len_limit == 0, we consider it the normal case; otherwise it's for
+// truncation. prepended_name isn't used for the truncation case.
template <typename OutputType>
void
checkToWireResult(OutputType& expected_output, OutputType& actual_output,
const AbstractRRset& actual_rrset,
const Name& prepended_name,
ConstRRsetPtr rrset, ConstRRsetPtr rrsig_rrset,
- bool dnssec_ok)
+ bool dnssec_ok,
+ size_t len_limit = 0,
+ size_t expected_result = 0)
{
expected_output.clear();
actual_output.clear();
- // Prepare "actual" rendered data. We prepend a name to confirm the
- // owner name should be compressed in both cases.
- prepended_name.toWire(actual_output);
- const size_t rdata_count = rrset ? rrset->getRdataCount() : 0;
- const int expected_ret = (dnssec_ok && rrsig_rrset) ?
- rdata_count + rrsig_rrset->getRdataCount() : rdata_count;
- EXPECT_EQ(expected_ret, actual_rrset.toWire(actual_output));
+ if (len_limit == 0) { // normal rendering
+ // Prepare "actual" rendered data. We prepend a name to confirm the
+ // owner name should be compressed in both cases.
+ prepended_name.toWire(actual_output);
+ const size_t rdata_count = rrset ? rrset->getRdataCount() : 0;
+ const int expected_ret = (dnssec_ok && rrsig_rrset) ?
+ rdata_count + rrsig_rrset->getRdataCount() : rdata_count;
+ EXPECT_EQ(expected_ret, actual_rrset.toWire(actual_output));
+ } else { // truncation
+ setOutputLengthLimit(actual_output, len_limit);
+ EXPECT_EQ(expected_result, actual_rrset.toWire(actual_output));
+ EXPECT_TRUE(isOutputTruncated(actual_output)); // always true here
+ }
// Prepare "expected" data.
- prepended_name.toWire(expected_output);
+ if (len_limit == 0) { // normal rendering
+ prepended_name.toWire(expected_output);
+ } else { // truncation
+ setOutputLengthLimit(expected_output, len_limit);
+ }
if (rrset) {
rrset->toWire(expected_output);
}
- if (dnssec_ok && rrsig_rrset) {
+ if (!isOutputTruncated(expected_output) && dnssec_ok && rrsig_rrset) {
rrsig_rrset->toWire(expected_output);
}
@@ -215,33 +257,39 @@ checkToWireResult(OutputType& expected_output, OutputType& actual_output,
TEST_F(TreeNodeRRsetTest, toWire) {
MessageRenderer expected_renderer, actual_renderer;
+ OutputBuffer expected_buffer(0), actual_buffer(0);
{
SCOPED_TRACE("with RRSIG, DNSSEC OK");
- const TreeNodeRRset rrset1(rrclass_, www_node_, a_rdataset_, true);
- checkToWireResult(expected_renderer, actual_renderer, rrset1,
+ const TreeNodeRRset rrset(rrclass_, www_node_, a_rdataset_, true);
+ checkToWireResult(expected_renderer, actual_renderer, rrset,
www_name_, a_rrset_, a_rrsig_rrset_, true);
+ // Currently the buffer version throws
+ EXPECT_THROW(
+ checkToWireResult(expected_buffer, actual_buffer, rrset,
+ www_name_, a_rrset_, a_rrsig_rrset_, true),
+ isc::Unexpected);
}
{
SCOPED_TRACE("with RRSIG, DNSSEC not OK");
- const TreeNodeRRset rrset2(rrclass_, www_node_, a_rdataset_, false);
- checkToWireResult(expected_renderer, actual_renderer, rrset2,
+ const TreeNodeRRset rrset(rrclass_, www_node_, a_rdataset_, false);
+ checkToWireResult(expected_renderer, actual_renderer, rrset,
www_name_, a_rrset_, a_rrsig_rrset_, false);
}
{
SCOPED_TRACE("without RRSIG, DNSSEC OK");
- const TreeNodeRRset rrset3(rrclass_, origin_node_, ns_rdataset_, true);
- checkToWireResult(expected_renderer, actual_renderer, rrset3,
+ const TreeNodeRRset rrset(rrclass_, origin_node_, ns_rdataset_, true);
+ checkToWireResult(expected_renderer, actual_renderer, rrset,
origin_name_, ns_rrset_, ConstRRsetPtr(), true);
}
{
SCOPED_TRACE("without RRSIG, DNSSEC not OK");
- const TreeNodeRRset rrset4(rrclass_, origin_node_, ns_rdataset_,
- false);
- checkToWireResult(expected_renderer, actual_renderer, rrset4,
+ const TreeNodeRRset rrset(rrclass_, origin_node_, ns_rdataset_,
+ false);
+ checkToWireResult(expected_renderer, actual_renderer, rrset,
origin_name_, ns_rrset_, ConstRRsetPtr(), false);
}
@@ -249,9 +297,9 @@ TEST_F(TreeNodeRRsetTest, toWire) {
// RDATA of DNAME DR shouldn't be compressed. Prepending "example.org"
// will check that.
SCOPED_TRACE("uncompressed RDATA");
- const TreeNodeRRset rrset5(rrclass_, origin_node_, dname_rdataset_,
- false);
- checkToWireResult(expected_renderer, actual_renderer, rrset5,
+ const TreeNodeRRset rrset(rrclass_, origin_node_, dname_rdataset_,
+ false);
+ checkToWireResult(expected_renderer, actual_renderer, rrset,
Name("example.org"), dname_rrset_, ConstRRsetPtr(),
false);
}
@@ -280,9 +328,9 @@ TEST_F(TreeNodeRRsetTest, toWire) {
// ANY or type-RRSIG queries, which are rare also). But can still
// happen.
SCOPED_TRACE("RRSIG only, DNSSEC OK");
- const TreeNodeRRset rrset6(rrclass_, www_node_, rrsig_only_rdataset_,
- true);
- checkToWireResult(expected_renderer, actual_renderer, rrset6,
+ const TreeNodeRRset rrset(rrclass_, www_node_, rrsig_only_rdataset_,
+ true);
+ checkToWireResult(expected_renderer, actual_renderer, rrset,
www_name_, ConstRRsetPtr(), txt_rrsig_rrset_,true);
}
@@ -291,60 +339,34 @@ TEST_F(TreeNodeRRsetTest, toWire) {
// In practice this case wouldn't happen, but API-wise possible, so
// we test it explicitly.
SCOPED_TRACE("RRSIG only, DNSSEC not OK");
- const TreeNodeRRset rrset7(rrclass_, www_node_, rrsig_only_rdataset_,
- false);
- checkToWireResult(expected_renderer, actual_renderer, rrset7,
+ const TreeNodeRRset rrset(rrclass_, www_node_, rrsig_only_rdataset_,
+ false);
+ checkToWireResult(expected_renderer, actual_renderer, rrset,
www_name_, ConstRRsetPtr(), txt_rrsig_rrset_,false);
}
}
-void
-checkTruncationResult(MessageRenderer& expected_renderer,
- MessageRenderer& actual_renderer,
- const AbstractRRset& actual_rrset,
- ConstRRsetPtr rrset, ConstRRsetPtr rrsig_rrset,
- bool dnssec_ok, size_t len_limit, size_t expected_result)
-{
- expected_renderer.clear();
- actual_renderer.clear();
-
- actual_renderer.setLengthLimit(len_limit);
- EXPECT_EQ(expected_result, actual_rrset.toWire(actual_renderer));
- EXPECT_TRUE(actual_renderer.isTruncated()); // always true in this test
-
- expected_renderer.setLengthLimit(len_limit);
- if (rrset) {
- rrset->toWire(expected_renderer);
- }
- if (!expected_renderer.isTruncated() && dnssec_ok && rrsig_rrset) {
- rrsig_rrset->toWire(expected_renderer);
- }
-
- matchWireData(expected_renderer.getData(), expected_renderer.getLength(),
- actual_renderer.getData(), actual_renderer.getLength());
-}
-
TEST_F(TreeNodeRRsetTest, toWireTruncated) {
MessageRenderer expected_renderer, actual_renderer;
+ // dummy parameter to checkToWireResult (unused for the this test case)
+ const Name& name = Name::ROOT_NAME();
// Set the truncation limit to name len + 14 bytes of fixed data for A RR
// (type, class, TTL, rdlen, and 4-byte IPv4 address). Then we can only
// render just one RR, without any garbage trailing data.
- checkTruncationResult(expected_renderer, actual_renderer,
- TreeNodeRRset(rrclass_, www_node_, a_rdataset_,
- true),
- a_rrset_, a_rrsig_rrset_, true,
- www_name_.getLength() + 14,
- 1); // 1 main RR, no RRSIG
+ checkToWireResult(expected_renderer, actual_renderer,
+ TreeNodeRRset(rrclass_, www_node_, a_rdataset_, true),
+ name, a_rrset_, a_rrsig_rrset_, true,
+ www_name_.getLength() + 14,
+ 1); // 1 main RR, no RRSIG
// The first main RRs should fit in the renderer (the name will be
// fully compressed, so its size is 2 bytes), but the RRSIG doesn't.
- checkTruncationResult(expected_renderer, actual_renderer,
- TreeNodeRRset(rrclass_, www_node_, a_rdataset_,
- true),
- a_rrset_, a_rrsig_rrset_, true,
- www_name_.getLength() + 14 + 2 + 14,
- 2); // 2 main RR, no RRSIG
+ checkToWireResult(expected_renderer, actual_renderer,
+ TreeNodeRRset(rrclass_, www_node_, a_rdataset_, true),
+ name, a_rrset_, a_rrsig_rrset_, true,
+ www_name_.getLength() + 14 + 2 + 14,
+ 2); // 2 main RR, no RRSIG
// This RRset has one main RR and two RRSIGs. Rendering the second RRSIG
// causes truncation.
@@ -356,19 +378,18 @@ TEST_F(TreeNodeRRsetTest, toWireTruncated) {
a_rrsig_rrset_->toWire(expected_renderer);
const size_t limit_len = expected_renderer.getLength();
// Then perform the test
- checkTruncationResult(expected_renderer, actual_renderer,
- TreeNodeRRset(rrclass_, www_node_, aaaa_rdataset_,
- true),
- aaaa_rrset_, aaaa_rrsig_rrset_, true, limit_len,
- 2); // 1 main RR, 1 RRSIG
+ checkToWireResult(expected_renderer, actual_renderer,
+ TreeNodeRRset(rrclass_, www_node_, aaaa_rdataset_, true),
+ name, aaaa_rrset_, aaaa_rrsig_rrset_, true, limit_len,
+ 2); // 1 main RR, 1 RRSIG
// RRSIG only case. Render length limit being 1, so it won't fit,
// and will cause truncation.
- checkTruncationResult(expected_renderer, actual_renderer,
- TreeNodeRRset(rrclass_, www_node_,
- rrsig_only_rdataset_, true),
- ConstRRsetPtr(), txt_rrsig_rrset_, true, 1,
- 0); // no RR
+ checkToWireResult(expected_renderer, actual_renderer,
+ TreeNodeRRset(rrclass_, www_node_, rrsig_only_rdataset_,
+ true),
+ name, ConstRRsetPtr(), txt_rrsig_rrset_, true, 1,
+ 0); // no RR
}
void
@@ -523,4 +544,25 @@ TEST_F(TreeNodeRRsetTest, isSameKind) {
// Different kind of different RRset class
EXPECT_FALSE(rrset.isSameKind(*aaaa_rrset_));
}
+
+TEST_F(TreeNodeRRsetTest, unexpectedMethods) {
+ // Note: buffer version of toWire() is checked in the toWire test.
+
+ TreeNodeRRset rrset(rrclass_, www_node_, a_rdataset_, true);
+
+ EXPECT_THROW(rrset.getTTL(), isc::Unexpected);
+ EXPECT_THROW(rrset.setTTL(RRTTL(0)), isc::Unexpected);
+ EXPECT_THROW(rrset.setName(Name("example")), isc::Unexpected);
+ EXPECT_THROW(rrset.addRdata(createRdata(RRType::A(), rrclass_, "0.0.0.0")),
+ isc::Unexpected);
+ EXPECT_THROW(rrset.getRRsig(), isc::Unexpected);
+ RdataPtr sig_rdata = createRdata(
+ RRType::RRSIG(), rrclass_,
+ "A 5 2 3600 20120814220826 20120715220826 5300 example.com. FAKE");
+ EXPECT_THROW(rrset.addRRsig(sig_rdata), isc::Unexpected);
+ EXPECT_THROW(rrset.addRRsig(*a_rrsig_rrset_), isc::Unexpected);
+ EXPECT_THROW(rrset.addRRsig(a_rrsig_rrset_), isc::Unexpected);
+ EXPECT_THROW(rrset.addRRsig(RRsetPtr()), isc::Unexpected);
+ EXPECT_THROW(rrset.removeRRsig(), isc::Unexpected);
+}
}
diff --git a/src/lib/datasrc/memory/treenode_rrset.cc b/src/lib/datasrc/memory/treenode_rrset.cc
index 6fc6b66..5c333ff 100644
--- a/src/lib/datasrc/memory/treenode_rrset.cc
+++ b/src/lib/datasrc/memory/treenode_rrset.cc
@@ -40,22 +40,11 @@ namespace isc {
namespace datasrc {
namespace memory {
-TreeNodeRRset::TreeNodeRRset(const dns::Name& realname,
- const dns::RRClass& rrclass,
- const ZoneNode* node, const RdataSet* rdataset,
- bool dnssec_ok) :
- node_(node), rdataset_(rdataset),
- rrsig_count_(rdataset_->getSigRdataCount()), rrclass_(rrclass),
- dnssec_ok_(dnssec_ok), name_(NULL)
-{
- const LabelSequence labels(realname);
- const size_t labels_storangelen = labels.getSerializedLength();
- realname_buf_ = new uint8_t[labels_storangelen];
- labels.serialize(realname_buf_, labels_storangelen);
-}
-
const Name&
TreeNodeRRset::getName() const {
+ if (realname_ != NULL) {
+ return (*realname_);
+ }
if (name_ == NULL) {
uint8_t labels_buf[LabelSequence::MAX_SERIALIZED_LENGTH];
const LabelSequence name_labels = getOwnerLabels(labels_buf);
@@ -206,7 +195,7 @@ TreeNodeRRset::toWire(AbstractMessageRenderer& renderer) const {
}
unsigned int
-TreeNodeRRset::toWire(isc::util::OutputBuffer& /*buffer*/) const {
+TreeNodeRRset::toWire(isc::util::OutputBuffer&) const {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
}
@@ -339,40 +328,27 @@ TreeNodeRRset::isSameKind(const AbstractRRset& abs_other) const {
if (rdataset_ != other->rdataset_) {
return (false);
}
- // Same for the owner name (note: in practice this method would be
- // called for rrsets at different nodes, so we check that condition
- // first). Note also that based on the basic assumption of the
- // ZoneTree, if the nodes are different their RR classes must be
- // different.
- if (node_ != other->node_ || !hasSameRealName(*other)) {
+ // Same for the owner name. Comparing the nodes also detect
+ // the case where RR classes are different (see the method description
+ // of the header for details).
+ if (node_ != other->node_ ) {
return (false);
}
- return (true);
- }
- return (AbstractRRset::isSameKind(abs_other));
-}
-
-bool
-TreeNodeRRset::hasSameRealName(const TreeNodeRRset& other) const {
- // If one is constructed with a "real name" and the other isn't
- // *we consider* them different.
- if ((realname_buf_ == NULL && other.realname_buf_ != NULL) ||
- (realname_buf_ != NULL && other.realname_buf_ == NULL)) {
- return (false);
- }
-
- // If both are constructed with a "real name", we compare their names
- // (as label sequences) explicitly.
- if (realname_buf_ != NULL && other.realname_buf_ != NULL) {
- uint8_t labels_buf[LabelSequence::MAX_SERIALIZED_LENGTH];
- uint8_t other_labels_buf[LabelSequence::MAX_SERIALIZED_LENGTH];
- if (!getOwnerLabels(labels_buf).equals(
- other.getOwnerLabels(other_labels_buf))) {
+ // If one is constructed with a "real name" and the other isn't
+ // *we consider* them different.
+ if ((realname_ == NULL && other->realname_ != NULL) ||
+ (realname_ != NULL && other->realname_ == NULL)) {
return (false);
}
+ // If both are constructed with a "real name", we compare their names
+ // explicitly.
+ if (realname_ != NULL && other->realname_ != NULL &&
+ realname_->nequals(*other->realname_)) {
+ return (false);
+ }
+ return (true);
}
-
- return (true);
+ return (AbstractRRset::isSameKind(abs_other));
}
} // namespace memory
diff --git a/src/lib/datasrc/memory/treenode_rrset.h b/src/lib/datasrc/memory/treenode_rrset.h
index 1f52124..2ad3a3c 100644
--- a/src/lib/datasrc/memory/treenode_rrset.h
+++ b/src/lib/datasrc/memory/treenode_rrset.h
@@ -75,7 +75,7 @@ public:
/// \brief Normal case constructor.
///
/// This class object is basically defined with a \c ZoneNode and
- /// \c RdataSet. The former determine the owner name of the RRset,
+ /// \c RdataSet. The former determines the owner name of the RRset,
/// and the latter provides the rest of the RRset parameters.
/// Since the RR class is maintained outside of the \c ZoneData,
/// it must be explicitly given as a constructor parameter.
@@ -105,7 +105,7 @@ public:
const RdataSet* rdataset, bool dnssec_ok) :
node_(node), rdataset_(rdataset),
rrsig_count_(rdataset_->getSigRdataCount()), rrclass_(rrclass),
- dnssec_ok_(dnssec_ok), name_(NULL), realname_buf_(NULL)
+ dnssec_ok_(dnssec_ok), name_(NULL), realname_(NULL)
{}
/// \brief Constructor for wildcard-expanded owner name.
@@ -122,10 +122,14 @@ public:
/// \throw std::bad_alloc Memory allocation fails
TreeNodeRRset(const dns::Name& realname, const dns::RRClass& rrclass,
const ZoneNode* node, const RdataSet* rdataset,
- bool dnssec_ok);
+ bool dnssec_ok) :
+ node_(node), rdataset_(rdataset),
+ rrsig_count_(rdataset_->getSigRdataCount()), rrclass_(rrclass),
+ dnssec_ok_(dnssec_ok), name_(NULL), realname_(new dns::Name(realname))
+ {}
virtual ~TreeNodeRRset() {
- delete[] realname_buf_;
+ delete realname_;
delete name_;
}
@@ -233,24 +237,19 @@ private:
dns::LabelSequence getOwnerLabels(
uint8_t labels_buf[dns::LabelSequence::MAX_SERIALIZED_LENGTH]) const
{
- if (realname_buf_ != NULL) {
- return (dns::LabelSequence(realname_buf_));
+ if (realname_ != NULL) {
+ return (dns::LabelSequence(*realname_));
}
return (node_->getAbsoluteLabels(labels_buf));
}
- // A helper for isSameKind() to check if 'this' and 'other' has
- // the same "real" name in case at least either is constructed with
- // a real name.
- bool hasSameRealName(const TreeNodeRRset& other) const;
-
const ZoneNode* node_;
const RdataSet* rdataset_;
const size_t rrsig_count_;
const dns::RRClass rrclass_;
const bool dnssec_ok_;
mutable dns::Name* name_;
- uint8_t* realname_buf_;
+ const dns::Name* const realname_;
};
} // namespace memory
diff --git a/src/lib/dns/benchmarks/message_renderer_bench.cc b/src/lib/dns/benchmarks/message_renderer_bench.cc
index 752b1f6..6376498 100644
--- a/src/lib/dns/benchmarks/message_renderer_bench.cc
+++ b/src/lib/dns/benchmarks/message_renderer_bench.cc
@@ -116,7 +116,11 @@ public:
virtual void writeName(const Name& name, const bool = false) {
name.toWire(getBuffer());
}
- virtual void writeName(const LabelSequence&, const bool) {} // unused
+ virtual void writeName(const LabelSequence&, const bool) {
+ // We shouldn't use this version of writeName (and we internally
+ // control it, so we simply assert it here)
+ assert(false);
+ }
};
void
diff --git a/src/lib/dns/benchmarks/oldmessagerenderer.cc b/src/lib/dns/benchmarks/oldmessagerenderer.cc
index a6c7990..ed575a0 100644
--- a/src/lib/dns/benchmarks/oldmessagerenderer.cc
+++ b/src/lib/dns/benchmarks/oldmessagerenderer.cc
@@ -277,7 +277,9 @@ OldMessageRenderer::writeName(const Name& name, const bool compress) {
void
OldMessageRenderer::writeName(const LabelSequence&, const bool) {
- // we don't use this mode for the benchmark
+ // We shouldn't use this version of writeName (and we internally
+ // control it, so we simply assert it here)
+ assert(false);
}
}
diff --git a/src/lib/dns/tests/labelsequence_unittest.cc b/src/lib/dns/tests/labelsequence_unittest.cc
index 5eb4941..28f624a 100644
--- a/src/lib/dns/tests/labelsequence_unittest.cc
+++ b/src/lib/dns/tests/labelsequence_unittest.cc
@@ -180,6 +180,7 @@ TEST_F(LabelSequenceTest, equals_insensitive) {
// operator==(). This is mostly trivial wrapper, so it should suffice to
// check some basic cases.
TEST_F(LabelSequenceTest, operatorEqual) {
+ // cppcheck-suppress duplicateExpression
EXPECT_TRUE(ls1 == ls1); // self equivalence
EXPECT_TRUE(ls1 == LabelSequence(n1)); // equivalent two different objects
EXPECT_FALSE(ls1 == ls2); // non equivalent objects
More information about the bind10-changes
mailing list