summaryrefslogtreecommitdiffstats
path: root/src/lib/dns
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/dns')
-rw-r--r--src/lib/dns/rdata/generic/opt_41.cc22
-rw-r--r--src/lib/dns/tests/rdata_opt_unittest.cc39
2 files changed, 54 insertions, 7 deletions
diff --git a/src/lib/dns/rdata/generic/opt_41.cc b/src/lib/dns/rdata/generic/opt_41.cc
index 176fa3929b..6b292e9fa1 100644
--- a/src/lib/dns/rdata/generic/opt_41.cc
+++ b/src/lib/dns/rdata/generic/opt_41.cc
@@ -164,13 +164,27 @@ OPT::toText() const {
}
void
-OPT::toWire(OutputBuffer&) const {
- // nothing to do, as this simple version doesn't support any options.
+OPT::toWire(OutputBuffer& buffer) const {
+ BOOST_FOREACH(const PseudoRR& pseudo_rr, impl_->pseudo_rrs_) {
+ buffer.writeUint16(pseudo_rr.getCode());
+ const uint16_t length = pseudo_rr.getLength();
+ buffer.writeUint16(length);
+ if (length > 0) {
+ buffer.writeData(pseudo_rr.getData(), length);
+ }
+ }
}
void
-OPT::toWire(AbstractMessageRenderer&) const {
- // nothing to do, as this simple version doesn't support any options.
+OPT::toWire(AbstractMessageRenderer& renderer) const {
+ BOOST_FOREACH(const PseudoRR& pseudo_rr, impl_->pseudo_rrs_) {
+ renderer.writeUint16(pseudo_rr.getCode());
+ const uint16_t length = pseudo_rr.getLength();
+ renderer.writeUint16(length);
+ if (length > 0) {
+ renderer.writeData(pseudo_rr.getData(), length);
+ }
+ }
}
int
diff --git a/src/lib/dns/tests/rdata_opt_unittest.cc b/src/lib/dns/tests/rdata_opt_unittest.cc
index e5695ac328..756f8d3f0f 100644
--- a/src/lib/dns/tests/rdata_opt_unittest.cc
+++ b/src/lib/dns/tests/rdata_opt_unittest.cc
@@ -35,7 +35,14 @@ class Rdata_OPT_Test : public RdataTest {
// there's nothing to specialize
};
-const generic::OPT rdata_opt;
+const uint8_t rdata_opt_wiredata[] = {
+ // Option code
+ 0x00, 0x03,
+ // Option length
+ 0x00, 0x03,
+ // Option data
+ 0x00, 0x01, 0x02
+};
TEST_F(Rdata_OPT_Test, createFromText) {
// OPT RR cannot be created from text.
@@ -78,21 +85,47 @@ TEST_F(Rdata_OPT_Test, createFromLexer) {
}
TEST_F(Rdata_OPT_Test, toWireBuffer) {
+ const generic::OPT rdata_opt =
+ dynamic_cast<const generic::OPT&>
+ (*rdataFactoryFromFile(RRType("OPT"), RRClass("IN"),
+ "rdata_opt_fromWire1", 2));
+
+ obuffer.clear();
rdata_opt.toWire(obuffer);
- EXPECT_EQ(0, obuffer.getLength());
+
+ EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
+ obuffer.getData(),
+ obuffer.getLength(),
+ rdata_opt_wiredata, sizeof(rdata_opt_wiredata));
}
TEST_F(Rdata_OPT_Test, toWireRenderer) {
+ const generic::OPT rdata_opt =
+ dynamic_cast<const generic::OPT&>
+ (*rdataFactoryFromFile(RRType("OPT"), RRClass("IN"),
+ "rdata_opt_fromWire1", 2));
+
+ renderer.clear();
rdata_opt.toWire(renderer);
- EXPECT_EQ(0, obuffer.getLength());
+
+ EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
+ renderer.getData(),
+ renderer.getLength(),
+ rdata_opt_wiredata, sizeof(rdata_opt_wiredata));
}
TEST_F(Rdata_OPT_Test, toText) {
+ // empty OPT
+ const generic::OPT rdata_opt;
+
EXPECT_THROW(rdata_opt.toText(),
isc::InvalidOperation);
}
TEST_F(Rdata_OPT_Test, compare) {
+ // empty OPT
+ const generic::OPT rdata_opt;
+
EXPECT_THROW(rdata_opt.compare(
*rdataFactoryFromFile(RRType::OPT(), RRClass::CH(),
"rdata_opt_fromWire1", 2)),