BIND 10 master, updated. 49ad6346f574d00cfbd1d12905915fd0dd6a0bac Merge branch 'master' into trac2087
BIND 10 source code commits
bind10-changes at lists.isc.org
Sun Jul 15 18:16:29 UTC 2012
The branch, master has been updated
via 49ad6346f574d00cfbd1d12905915fd0dd6a0bac (commit)
via a1068f5f1929a6fdd7ec2bfacd8e751a688a83f9 (commit)
via a16d2686dc4f3ed114b3c43bec1c940b013e4998 (commit)
via 5f6ead50e01a9e9775ed2eb4816d029bc580f511 (commit)
via 99f765ae8f5294490a939cc87d3811f4b3cb9516 (commit)
from 9726cd1627ba4c074f65e57799e8b77ec158a491 (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 49ad6346f574d00cfbd1d12905915fd0dd6a0bac
Merge: a1068f5 9726cd1
Author: Mukund Sivaraman <muks at isc.org>
Date: Sun Jul 15 23:17:36 2012 +0530
Merge branch 'master' into trac2087
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/labelsequence.cc | 9 +++
src/lib/dns/labelsequence.h | 27 ++++++++
src/lib/dns/messagerenderer.cc | 18 +++--
src/lib/dns/messagerenderer.h | 18 +++++
src/lib/dns/tests/labelsequence_unittest.cc | 87 +++++++++++++++++++++++++
src/lib/dns/tests/messagerenderer_unittest.cc | 63 ++++++++++++++++++
src/lib/dns/tests/testdata/Makefile.am | 1 +
src/lib/dns/tests/testdata/name_toWire3 | 2 +-
src/lib/dns/tests/testdata/name_toWire7 | 10 +++
src/lib/dns/tests/testdata/name_toWire8 | 7 ++
src/lib/dns/tests/testdata/name_toWire9 | 13 ++++
11 files changed, 249 insertions(+), 6 deletions(-)
create mode 100644 src/lib/dns/tests/testdata/name_toWire7
create mode 100644 src/lib/dns/tests/testdata/name_toWire8
create mode 100644 src/lib/dns/tests/testdata/name_toWire9
-----------------------------------------------------------------------
diff --git a/src/lib/dns/labelsequence.cc b/src/lib/dns/labelsequence.cc
index 98b13f0..7627571 100644
--- a/src/lib/dns/labelsequence.cc
+++ b/src/lib/dns/labelsequence.cc
@@ -57,6 +57,15 @@ LabelSequence::getData(size_t *len) const {
return (&data_[offsets_[first_label_]]);
}
+void
+LabelSequence::getOffsetData(size_t* len,
+ uint8_t placeholder[Name::MAX_LABELS]) const {
+ *len = last_label_ - first_label_;
+ for (size_t i = 0; i < *len; i++) {
+ placeholder[i] = offsets_[first_label_ + i] - offsets_[first_label_];
+ }
+}
+
size_t
LabelSequence::getDataLength() const {
// If the labelsequence is absolute, the current last_label_ falls
diff --git a/src/lib/dns/labelsequence.h b/src/lib/dns/labelsequence.h
index 65344e1..48f3241 100644
--- a/src/lib/dns/labelsequence.h
+++ b/src/lib/dns/labelsequence.h
@@ -46,6 +46,23 @@ class LabelSequence {
friend std::string Name::toText(bool) const;
public:
+ /// \brief Constructs a LabelSequence for the given label sequence
+ ///
+ /// \note The associated data MUST remain in scope during the lifetime
+ /// of this LabelSequence, since only the pointers are copied.
+ ///
+ /// \note No validation is done on the given data upon construction;
+ /// use with care.
+ ///
+ /// \param ls The LabelSequence to construct a LabelSequence from
+ explicit LabelSequence(const LabelSequence& ls):
+ data_(ls.data_),
+ offsets_(ls.offsets_),
+ offsets_size_(ls.offsets_size_),
+ first_label_(ls.first_label_),
+ last_label_(ls.last_label_)
+ {}
+
/// \brief Constructs a LabelSequence for the given name
///
/// \note The associated Name MUST remain in scope during the lifetime
@@ -96,6 +113,16 @@ public:
/// \return Pointer to the wire-format data of this label sequence
const uint8_t* getData(size_t* len) const;
+ /// \brief Return the offset data for this LabelSequence
+ ///
+ /// The offsets are returned in the <code>placeholder</code> array.
+ ///
+ /// \param len Pointer to a size_t where the number of offsets
+ /// will be stored
+ /// \param placeholder Array where the offset data will be returned
+ void getOffsetData(size_t* len,
+ uint8_t placeholder[Name::MAX_LABELS]) const;
+
/// \brief Return the length of the wire-format data of this LabelSequence
///
/// This method returns the number of octets for the data that would
diff --git a/src/lib/dns/messagerenderer.cc b/src/lib/dns/messagerenderer.cc
index ca4ea54..081a5aa 100644
--- a/src/lib/dns/messagerenderer.cc
+++ b/src/lib/dns/messagerenderer.cc
@@ -289,8 +289,8 @@ MessageRenderer::setCompressMode(const CompressMode mode) {
}
void
-MessageRenderer::writeName(const Name& name, const bool compress) {
- LabelSequence sequence(name);
+MessageRenderer::writeName(const LabelSequence& ls, const bool compress) {
+ LabelSequence sequence(ls);
const size_t nlabels = sequence.getLabelCount();
size_t data_len;
const uint8_t* data;
@@ -302,6 +302,10 @@ MessageRenderer::writeName(const Name& name, const bool compress) {
const bool case_sensitive = (impl_->compress_mode_ ==
MessageRenderer::CASE_SENSITIVE);
for (nlabels_uncomp = 0; nlabels_uncomp < nlabels; ++nlabels_uncomp) {
+ if (nlabels_uncomp > 0) {
+ sequence.stripLeft(1);
+ }
+
data = sequence.getData(&data_len);
if (data_len == 1) { // trailing dot.
++nlabels_uncomp;
@@ -317,14 +321,13 @@ MessageRenderer::writeName(const Name& name, const bool compress) {
if (ptr_offset != MessageRendererImpl::NO_OFFSET) {
break;
}
- sequence.stripLeft(1);
}
// Record the current offset before updating the offset table
size_t offset = getLength();
// Write uncompress part:
if (nlabels_uncomp > 0 || !compress) {
- LabelSequence uncomp_sequence(name);
+ LabelSequence uncomp_sequence(ls);
if (compress && nlabels > nlabels_uncomp) {
// If there's compressed part, strip off that part.
uncomp_sequence.stripRight(nlabels - nlabels_uncomp);
@@ -342,7 +345,7 @@ MessageRenderer::writeName(const Name& name, const bool compress) {
// in the hash table. The renderer's buffer has just stored the
// corresponding data, so we use the rendered data to get the length
// of each label of the names.
- size_t seqlen = name.getLength();
+ size_t seqlen = ls.getDataLength();
for (size_t i = 0; i < nlabels_uncomp; ++i) {
const uint8_t label_len = getBuffer()[offset];
if (label_len == 0) { // offset for root doesn't need to be stored.
@@ -359,6 +362,11 @@ MessageRenderer::writeName(const Name& name, const bool compress) {
}
}
+void
+MessageRenderer::writeName(const Name& name, const bool compress) {
+ writeName(LabelSequence(name), compress);
+}
+
AbstractMessageRenderer::AbstractMessageRenderer() :
local_buffer_(0), buffer_(&local_buffer_)
{
diff --git a/src/lib/dns/messagerenderer.h b/src/lib/dns/messagerenderer.h
index 4c1c92a..5a81eb2 100644
--- a/src/lib/dns/messagerenderer.h
+++ b/src/lib/dns/messagerenderer.h
@@ -22,6 +22,7 @@ namespace isc {
namespace dns {
// forward declarations
class Name;
+class LabelSequence;
/// \brief The \c AbstractMessageRenderer class is an abstract base class
/// that provides common interfaces for rendering a DNS message into a buffer
@@ -372,6 +373,23 @@ public:
virtual void clear();
virtual void writeName(const Name& name, bool compress = true);
+
+ /// \brief Write a \c LabelSequence object into the internal buffer
+ /// in wire format, with or without name compression.
+ ///
+ /// If the optional parameter \c compress is \c true, this method tries to
+ /// compress the \c ls if possible, searching the entire message that has
+ /// been rendered. Otherwise name compression is omitted. Its default
+ /// value is \c true.
+ ///
+ /// Note: even if \c compress is \c true, the position of the \c ls (and
+ /// possibly its ancestor names) in the message is recorded and may be used
+ /// for compressing subsequent names.
+ ///
+ /// \param ls A \c LabelSequence object to be written.
+ /// \param compress A boolean indicating whether to enable name compression.
+ void writeName(const LabelSequence& ls, bool compress = true);
+
private:
struct MessageRendererImpl;
MessageRendererImpl* impl_;
diff --git a/src/lib/dns/tests/labelsequence_unittest.cc b/src/lib/dns/tests/labelsequence_unittest.cc
index bbd52c9..dd41d5e 100644
--- a/src/lib/dns/tests/labelsequence_unittest.cc
+++ b/src/lib/dns/tests/labelsequence_unittest.cc
@@ -400,6 +400,93 @@ TEST_F(LabelSequenceTest, getData) {
getDataCheck("\000", 1, ls7);
};
+TEST_F(LabelSequenceTest, getOffsetData) {
+ size_t len;
+ uint8_t placeholder[Name::MAX_LABELS];
+
+ Name nx("x.isc.example.org");
+ LabelSequence lsx(nx);
+
+ // x.isc.example.org.
+ lsx.getOffsetData(&len, placeholder);
+ EXPECT_EQ(5, len);
+ EXPECT_EQ(0, placeholder[0]);
+ EXPECT_EQ(2, placeholder[1]);
+ EXPECT_EQ(6, placeholder[2]);
+ EXPECT_EQ(14, placeholder[3]);
+ EXPECT_EQ(18, placeholder[4]);
+
+ lsx.stripLeft(2);
+
+ // example.org.
+ lsx.getOffsetData(&len, placeholder);
+ EXPECT_EQ(3, len);
+ EXPECT_EQ(0, placeholder[0]);
+ EXPECT_EQ(8, placeholder[1]);
+ EXPECT_EQ(12, placeholder[2]);
+
+ lsx.stripLeft(1);
+
+ // org.
+ lsx.getOffsetData(&len, placeholder);
+ EXPECT_EQ(2, len);
+ EXPECT_EQ(0, placeholder[0]);
+ EXPECT_EQ(4, placeholder[1]);
+
+ lsx.stripLeft(1);
+
+ // .
+ lsx.getOffsetData(&len, placeholder);
+ EXPECT_EQ(1, len);
+ EXPECT_EQ(0, placeholder[0]);
+
+ Name ny("y.isc.example.org");
+ LabelSequence lsy(ny);
+
+ // y.isc.example.org.
+ lsy.getOffsetData(&len, placeholder);
+ EXPECT_EQ(5, len);
+ EXPECT_EQ(0, placeholder[0]);
+ EXPECT_EQ(2, placeholder[1]);
+ EXPECT_EQ(6, placeholder[2]);
+ EXPECT_EQ(14, placeholder[3]);
+ EXPECT_EQ(18, placeholder[4]);
+
+ lsy.stripRight(1);
+
+ // y.isc.example.org
+ lsy.getOffsetData(&len, placeholder);
+ EXPECT_EQ(4, len);
+ EXPECT_EQ(0, placeholder[0]);
+ EXPECT_EQ(2, placeholder[1]);
+ EXPECT_EQ(6, placeholder[2]);
+ EXPECT_EQ(14, placeholder[3]);
+
+ lsy.stripRight(1);
+
+ // y.isc.example
+ lsy.getOffsetData(&len, placeholder);
+ EXPECT_EQ(3, len);
+ EXPECT_EQ(0, placeholder[0]);
+ EXPECT_EQ(2, placeholder[1]);
+ EXPECT_EQ(6, placeholder[2]);
+
+ lsy.stripLeft(1);
+
+ // isc.example
+ lsy.getOffsetData(&len, placeholder);
+ EXPECT_EQ(2, len);
+ EXPECT_EQ(0, placeholder[0]);
+ EXPECT_EQ(4, placeholder[1]);
+
+ lsy.stripLeft(1);
+
+ // example
+ lsy.getOffsetData(&len, placeholder);
+ EXPECT_EQ(1, len);
+ EXPECT_EQ(0, placeholder[0]);
+};
+
TEST_F(LabelSequenceTest, stripLeft) {
EXPECT_TRUE(ls1.equals(ls3));
ls1.stripLeft(0);
diff --git a/src/lib/dns/tests/messagerenderer_unittest.cc b/src/lib/dns/tests/messagerenderer_unittest.cc
index bc526af..582c164 100644
--- a/src/lib/dns/tests/messagerenderer_unittest.cc
+++ b/src/lib/dns/tests/messagerenderer_unittest.cc
@@ -15,6 +15,7 @@
#include <exceptions/exceptions.h>
#include <util/buffer.h>
#include <dns/name.h>
+#include <dns/labelsequence.h>
#include <dns/messagerenderer.h>
#include <dns/tests/unittest_util.h>
@@ -28,6 +29,7 @@
using isc::UnitTestUtil;
using isc::dns::Name;
+using isc::dns::LabelSequence;
using isc::dns::MessageRenderer;
using isc::util::OutputBuffer;
using boost::lexical_cast;
@@ -176,6 +178,67 @@ TEST_F(MessageRendererTest, writeRootName) {
expected.getLength());
}
+TEST_F(MessageRendererTest, writeNameLabelSequence1) {
+ UnitTestUtil::readWireData("name_toWire7", data);
+
+ Name n1("a.example.com");
+ LabelSequence ls1(n1);
+
+ // a.example.com.
+ renderer.writeName(ls1);
+
+ ls1.stripLeft(1);
+
+ // example.com.
+ renderer.writeName(ls1);
+
+ EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData, renderer.getData(),
+ renderer.getLength(), &data[0], data.size());
+}
+
+TEST_F(MessageRendererTest, writeNameLabelSequence2) {
+ UnitTestUtil::readWireData("name_toWire8", data);
+
+ Name n1("a.example.com");
+ LabelSequence ls1(n1);
+
+ ls1.stripRight(1);
+
+ // a.example.com (without root .)
+ renderer.writeName(ls1);
+
+ EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData, renderer.getData(),
+ renderer.getLength(), &data[0], data.size());
+}
+
+TEST_F(MessageRendererTest, writeNameLabelSequence3) {
+ UnitTestUtil::readWireData("name_toWire9", data);
+
+ Name n1("a.example.com");
+ LabelSequence ls1(n1);
+
+ // a.example.com.
+ renderer.writeName(ls1);
+
+ ls1.stripRight(1);
+
+ // a.example.com (without root .)
+ renderer.writeName(ls1);
+
+ ls1.stripRight(1);
+
+ // a.example
+ renderer.writeName(ls1);
+
+ ls1.stripLeft(1);
+
+ // example
+ renderer.writeName(ls1);
+
+ EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData, renderer.getData(),
+ renderer.getLength(), &data[0], data.size());
+}
+
TEST_F(MessageRendererTest, setBuffer) {
OutputBuffer new_buffer(0);
renderer.setBuffer(&new_buffer);
diff --git a/src/lib/dns/tests/testdata/Makefile.am b/src/lib/dns/tests/testdata/Makefile.am
index fb1ec5b..043ea55 100644
--- a/src/lib/dns/tests/testdata/Makefile.am
+++ b/src/lib/dns/tests/testdata/Makefile.am
@@ -93,6 +93,7 @@ EXTRA_DIST += name_fromWire9 name_fromWire10 name_fromWire11 name_fromWire12
EXTRA_DIST += name_fromWire13 name_fromWire14
EXTRA_DIST += name_toWire1 name_toWire2 name_toWire3 name_toWire4
EXTRA_DIST += name_toWire5.spec name_toWire6.spec
+EXTRA_DIST += name_toWire7 name_toWire8 name_toWire9
EXTRA_DIST += question_fromWire question_toWire1 question_toWire2
EXTRA_DIST += rdatafields1.spec rdatafields2.spec rdatafields3.spec
EXTRA_DIST += rdatafields4.spec rdatafields5.spec rdatafields6.spec
diff --git a/src/lib/dns/tests/testdata/name_toWire3 b/src/lib/dns/tests/testdata/name_toWire3
index 643768e..08c1474 100644
--- a/src/lib/dns/tests/testdata/name_toWire3
+++ b/src/lib/dns/tests/testdata/name_toWire3
@@ -7,7 +7,7 @@
01 61 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00
#15 29 (bytes)
-#(1) b(7) e x a m p l e (3) c o m .; specified to be not compressed,
+#(1) b (7) e x a m p l e (3) c o m .; specified to be not compressed,
# but can be pointed to from others
01 62 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00
#[0f] referring to the second (uncompressed name)
diff --git a/src/lib/dns/tests/testdata/name_toWire7 b/src/lib/dns/tests/testdata/name_toWire7
new file mode 100644
index 0000000..bff599f
--- /dev/null
+++ b/src/lib/dns/tests/testdata/name_toWire7
@@ -0,0 +1,10 @@
+#
+# Rendering names including one explicitly uncompressed.
+# [x] means a compression pointer pointing to offset 'x'.
+#
+# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 (bytes)
+#(1) a (7) e x a m p l e (3) c o m .
+ 01 61 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00
+
+#[02] pointing to -> "example.com."
+ c0 02
diff --git a/src/lib/dns/tests/testdata/name_toWire8 b/src/lib/dns/tests/testdata/name_toWire8
new file mode 100644
index 0000000..d01093b
--- /dev/null
+++ b/src/lib/dns/tests/testdata/name_toWire8
@@ -0,0 +1,7 @@
+#
+# Rendering names.
+# [x] means a compression pointer pointing to offset 'x'.
+#
+# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 (bytes)
+#(1) a (7) e x a m p l e (3) c o m
+ 01 61 07 65 78 61 6d 70 6c 65 03 63 6f 6d
diff --git a/src/lib/dns/tests/testdata/name_toWire9 b/src/lib/dns/tests/testdata/name_toWire9
new file mode 100644
index 0000000..51a1987
--- /dev/null
+++ b/src/lib/dns/tests/testdata/name_toWire9
@@ -0,0 +1,13 @@
+#
+# Rendering names including one explicitly uncompressed.
+# [x] means a compression pointer pointing to offset 'x'.
+#
+# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 (bytes)
+#(1) a (7) e x a m p l e (3) c o m .
+ 01 61 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00
+#(1) a (7) e x a m p l e (3) c o m
+ 01 61 07 65 78 61 6d 70 6c 65 03 63 6f 6d
+#(1) a (7) e x a m p l e
+ 01 61 07 65 78 61 6d 70 6c 65
+#[1f] pointing to ^^ "example"
+ c0 1f
More information about the bind10-changes
mailing list