Browse Source

added very simple implementation of the EDNS OPT RR.
it doesn't support any EDNS options, but should be sufficient for the
year-1 deliverable.


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1035 e5f2f494-b856-4b98-b285-d166d9295462

JINMEI Tatuya 15 years ago
parent
commit
038bc68a9f

+ 78 - 0
src/lib/dns/cpp/rdata/generic/opt_41.cc

@@ -0,0 +1,78 @@
+// Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+// $Id$
+#include <string>
+
+#include "buffer.h"
+#include "messagerenderer.h"
+#include "rdata.h"
+#include "rdataclass.h"
+
+using namespace std;
+
+// BEGIN_ISC_NAMESPACE
+// BEGIN_RDATA_NAMESPACE
+
+OPT::OPT(const string& type_str)
+{
+    dns_throw(InvalidRdataText, "OPT RR cannot be constructed from text");
+}
+
+OPT::OPT(InputBuffer& buffer, size_t rdata_len)
+{
+    // setPosition() will throw against a short buffer anyway, but it's safer
+    // to check it explicitly here.
+    if (buffer.getLength() - buffer.getPosition() < rdata_len) {
+        dns_throw(InvalidRdataLength, "RDLEN of OPT is too large");
+    }
+
+    // This simple implementation ignores any options
+    buffer.setPosition(buffer.getPosition() + rdata_len);
+}
+
+OPT::OPT(const OPT& source)
+{
+    // there's nothing to copy in this simple implementation.
+}
+
+std::string
+OPT::toText() const
+{
+    return ("");
+}
+
+void
+OPT::toWire(OutputBuffer& buffer) const
+{
+    // nothing to do, as this simple version doesn't support any options.
+}
+
+void
+OPT::toWire(MessageRenderer& renderer) const
+{
+    // nothing to do, as this simple version doesn't support any options.
+}
+
+int
+OPT::compare(const Rdata& other) const
+{
+    //const OPT& other_opt = dynamic_cast<const OPT&>(other);
+    dynamic_cast<const OPT&>(other);
+
+    return (0);
+}
+
+// END_RDATA_NAMESPACE
+// END_ISC_NAMESPACE

+ 47 - 0
src/lib/dns/cpp/rdata/generic/opt_41.h

@@ -0,0 +1,47 @@
+// Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+// $Id$
+
+// BEGIN_HEADER_GUARD
+
+#include <string>
+
+#include "rdata.h"
+
+// BEGIN_ISC_NAMESPACE
+
+// BEGIN_COMMON_DECLARATIONS
+// END_COMMON_DECLARATIONS
+
+// BEGIN_RDATA_NAMESPACE
+
+class OPT : public Rdata {
+public:
+    // BEGIN_COMMON_MEMBERS
+    // END_COMMON_MEMBERS
+
+    // The default constructor makes sense for OPT as it can be empty.
+    OPT() {}
+private:
+    // RR-type specific members are here.
+};
+
+// END_RDATA_NAMESPACE
+// END_ISC_NAMESPACE
+// END_HEADER_GUARD
+
+// Local Variables: 
+// mode: c++
+// End: 

+ 1 - 0
src/lib/dns/cpp/tests/Makefile.am

@@ -17,6 +17,7 @@ run_unittests_SOURCES += rdata_ns_unittest.cc rdata_soa_unittest.cc
 run_unittests_SOURCES += rdata_txt_unittest.cc rdata_mx_unittest.cc
 run_unittests_SOURCES += rdata_cname_unittest.cc
 run_unittests_SOURCES += rdata_dname_unittest.cc
+run_unittests_SOURCES += rdata_opt_unittest.cc
 run_unittests_SOURCES += rdata_dnskey_unittest.cc
 run_unittests_SOURCES += rdata_ds_unittest.cc
 run_unittests_SOURCES += rdata_nsec_unittest.cc

+ 89 - 0
src/lib/dns/cpp/tests/rdata_opt_unittest.cc

@@ -0,0 +1,89 @@
+// Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+// $Id$
+
+#include <dns/buffer.h>
+#include <dns/messagerenderer.h>
+#include <dns/rdata.h>
+#include <dns/rdataclass.h>
+#include <dns/rrclass.h>
+#include <dns/rrtype.h>
+
+#include <gtest/gtest.h>
+
+#include "unittest_util.h"
+#include "rdata_unittest.h"
+
+using isc::UnitTestUtil;
+using namespace std;
+using namespace isc::dns;
+using namespace isc::dns::rdata;
+
+namespace {
+class Rdata_OPT_Test : public RdataTest {
+    // there's nothing to specialize
+};
+
+const generic::OPT rdata_opt;
+
+TEST_F(Rdata_OPT_Test, createFromText)
+{
+    // OPT RR cannot be created from text.
+    EXPECT_THROW(generic::OPT("this does not matter"), InvalidRdataText);
+}
+
+TEST_F(Rdata_OPT_Test, createFromWire)
+{
+    // Valid cases: in the simple implementation with no supported options,
+    // we can only check these don't throw.
+    EXPECT_NO_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass("CLASS4096"),
+                                         "testdata/rdata_opt_fromWire"));
+    EXPECT_NO_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass::CH(),
+                                         "testdata/rdata_opt_fromWire", 2));
+
+    // short buffer case.
+    EXPECT_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass::IN(),
+                                      "testdata/rdata_opt_fromWire", 11),
+                 InvalidRdataLength);
+}
+
+TEST_F(Rdata_OPT_Test, toWireBuffer)
+{
+    rdata_opt.toWire(obuffer);
+    EXPECT_EQ(0, obuffer.getLength());
+}
+
+TEST_F(Rdata_OPT_Test, toWireRenderer)
+{
+    rdata_opt.toWire(renderer);
+    EXPECT_EQ(0, obuffer.getLength());
+}
+
+TEST_F(Rdata_OPT_Test, toText)
+{
+    EXPECT_EQ("", rdata_opt.toText());
+}
+
+TEST_F(Rdata_OPT_Test, compare)
+{
+    // This simple implementation always returns "true"
+    EXPECT_EQ(0, rdata_opt.compare(
+                  *rdataFactoryFromFile(RRType::OPT(), RRClass::CH(),
+                                        "testdata/rdata_opt_fromWire", 2)));
+
+    // comparison attempt between incompatible RR types should be rejected
+    EXPECT_THROW(rdata_opt.compare(*RdataTest::rdata_nomatch), bad_cast); 
+}
+}