BIND 10 trac3316, updated. 2027fa4cd4d38923038e04a3c766097eaa0da5fb [3316] Use the OptionVendorClass in DHCPv6 server code.
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Feb 13 13:50:19 UTC 2014
The branch, trac3316 has been updated
via 2027fa4cd4d38923038e04a3c766097eaa0da5fb (commit)
via a0eb24bea3138ebb0d3d1543d7fa5e8c3a1ee676 (commit)
via 20784067f58bff3e1019d842ee8fb7f9d9119842 (commit)
from ce6bedc169294934b93edb9d646e7c5e2edf12a2 (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 2027fa4cd4d38923038e04a3c766097eaa0da5fb
Author: Marcin Siodelski <marcin at isc.org>
Date: Thu Feb 13 14:50:07 2014 +0100
[3316] Use the OptionVendorClass in DHCPv6 server code.
commit a0eb24bea3138ebb0d3d1543d7fa5e8c3a1ee676
Author: Marcin Siodelski <marcin at isc.org>
Date: Thu Feb 13 14:33:02 2014 +0100
[3316] Implemented function to check if specified tuple is in VC option.
commit 20784067f58bff3e1019d842ee8fb7f9d9119842
Author: Marcin Siodelski <marcin at isc.org>
Date: Thu Feb 13 14:17:03 2014 +0100
[3316] Use OptionVendorClass to encapsulate DHCPv6 option 16.
-----------------------------------------------------------------------
Summary of changes:
src/bin/dhcp6/dhcp6_srv.cc | 38 ++++++++++----------
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc | 4 +--
src/lib/dhcp/opaque_data_tuple.cc | 2 +-
src/lib/dhcp/opaque_data_tuple.h | 2 +-
src/lib/dhcp/option_definition.cc | 12 +++++++
src/lib/dhcp/option_definition.h | 5 +++
src/lib/dhcp/option_vendor_class.cc | 14 ++++++++
src/lib/dhcp/option_vendor_class.h | 7 ++++
src/lib/dhcp/std_option_defs.h | 3 +-
src/lib/dhcp/tests/libdhcp++_unittest.cc | 32 ++++++++++-------
src/lib/dhcp/tests/option_vendor_class_unittest.cc | 5 +++
11 files changed, 85 insertions(+), 39 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc
index 391bff6..432527f 100644
--- a/src/bin/dhcp6/dhcp6_srv.cc
+++ b/src/bin/dhcp6/dhcp6_srv.cc
@@ -28,6 +28,7 @@
#include <dhcp/option6_iaprefix.h>
#include <dhcp/option_custom.h>
#include <dhcp/option_vendor.h>
+#include <dhcp/option_vendor_class.h>
#include <dhcp/option_int_array.h>
#include <dhcp/pkt6.h>
#include <dhcp6/dhcp6_log.h>
@@ -54,6 +55,7 @@
#include <time.h>
#include <iomanip>
#include <fstream>
+#include <sstream>
using namespace isc;
using namespace isc::asiolink;
@@ -2436,36 +2438,32 @@ Dhcpv6Srv::ifaceMgrSocket6ErrorHandler(const std::string& errmsg) {
}
void Dhcpv6Srv::classifyPacket(const Pkt6Ptr& pkt) {
+ OptionVendorClassPtr vclass = boost::dynamic_pointer_cast<
+ OptionVendorClass>(pkt->getOption(D6O_VENDOR_CLASS));
- boost::shared_ptr<OptionCustom> vclass =
- boost::dynamic_pointer_cast<OptionCustom>(pkt->getOption(D6O_VENDOR_CLASS));
-
- if (!vclass) {
+ if (!vclass || vclass->getTuplesNum() == 0) {
return;
}
- string classes = "";
+ std::ostringstream classes;
- // DOCSIS specific section
- if (vclass->readString(VENDOR_CLASS_STRING_INDEX)
- .find(DOCSIS3_CLASS_MODEM) != std::string::npos) {
+ if (vclass->hasTuple(DOCSIS3_CLASS_MODEM)) {
pkt->addClass(DOCSIS3_CLASS_MODEM);
- classes += string(DOCSIS3_CLASS_MODEM) + " ";
- } else
- if (vclass->readString(VENDOR_CLASS_STRING_INDEX)
- .find(DOCSIS3_CLASS_EROUTER) != std::string::npos) {
+ classes << DOCSIS3_CLASS_MODEM;
+
+ } else if (vclass->hasTuple(DOCSIS3_CLASS_EROUTER)) {
pkt->addClass(DOCSIS3_CLASS_EROUTER);
- classes += string(DOCSIS3_CLASS_EROUTER) + " ";
- }else
- {
- // Otherwise use the string as is
- classes += vclass->readString(VENDOR_CLASS_STRING_INDEX);
- pkt->addClass(vclass->readString(VENDOR_CLASS_STRING_INDEX));
+ classes << DOCSIS3_CLASS_EROUTER;
+
+ } else {
+ pkt->addClass(vclass->getTuple(0).getText());
+ classes << vclass->getTuple(0);
+
}
- if (!classes.empty()) {
+ if (!classes.str().empty()) {
LOG_DEBUG(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_CLASS_ASSIGNED)
- .arg(classes);
+ .arg(classes.str());
}
}
diff --git a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
index f799186..205df2f 100644
--- a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
+++ b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
@@ -1759,8 +1759,8 @@ TEST_F(Dhcpv6SrvTest, cableLabsShortVendorClass) {
Pkt6Ptr adv = srv.fake_sent_.front();
ASSERT_TRUE(adv);
- // This is sent back to relay, so port is 547
- EXPECT_EQ(DHCP6_SERVER_PORT, adv->getRemotePort());
+ // This is sent back to client, so port is 546
+ EXPECT_EQ(DHCP6_CLIENT_PORT, adv->getRemotePort());
}
diff --git a/src/lib/dhcp/opaque_data_tuple.cc b/src/lib/dhcp/opaque_data_tuple.cc
index 42c04eb..f35721a 100644
--- a/src/lib/dhcp/opaque_data_tuple.cc
+++ b/src/lib/dhcp/opaque_data_tuple.cc
@@ -89,7 +89,7 @@ OpaqueDataTuple::operator=(const std::string& other) {
}
bool
-OpaqueDataTuple::operator==(const std::string& other) {
+OpaqueDataTuple::operator==(const std::string& other) const {
return (equals(other));
}
diff --git a/src/lib/dhcp/opaque_data_tuple.h b/src/lib/dhcp/opaque_data_tuple.h
index ed1b25c..82ea1ad 100644
--- a/src/lib/dhcp/opaque_data_tuple.h
+++ b/src/lib/dhcp/opaque_data_tuple.h
@@ -261,7 +261,7 @@ public:
///
/// @param other String to compare the tuple against.
/// @return true if data carried in the tuple is equal to the string.
- bool operator==(const std::string& other);
+ bool operator==(const std::string& other) const;
/// @brief Inequality operator.
///
diff --git a/src/lib/dhcp/option_definition.cc b/src/lib/dhcp/option_definition.cc
index 98765e6..c8c836f 100644
--- a/src/lib/dhcp/option_definition.cc
+++ b/src/lib/dhcp/option_definition.cc
@@ -28,6 +28,7 @@
#include <dhcp/option_space.h>
#include <dhcp/option_string.h>
#include <dhcp/option_vendor.h>
+#include <dhcp/option_vendor_class.h>
#include <util/encode/hex.h>
#include <util/strutil.h>
#include <boost/algorithm/string/classification.hpp>
@@ -400,6 +401,14 @@ OptionDefinition::haveVendor6Format() const {
}
bool
+OptionDefinition::haveVendorClass6Format() const {
+ return (haveType(OPT_RECORD_TYPE) &&
+ (record_fields_.size() == 2) &&
+ (record_fields_[0] == OPT_UINT32_TYPE) &&
+ (record_fields_[1] == OPT_BINARY_TYPE));
+}
+
+bool
OptionDefinition::convertToBool(const std::string& value_str) const {
// Case insensitve check that the input is one of: "true" or "false".
if (boost::iequals(value_str, "true")) {
@@ -653,6 +662,9 @@ OptionDefinition::factorySpecialFormatOption(Option::Universe u,
} else if (getCode() == D6O_VENDOR_OPTS && haveVendor6Format()) {
// Vendor-Specific Information.
return (OptionPtr(new OptionVendor(Option::V6, begin, end)));
+ } else if (getCode() == D6O_VENDOR_CLASS && haveVendorClass6Format()) {
+ // Vendor Class.
+ return (OptionPtr(new OptionVendorClass(Option::V6, begin, end)));
}
} else {
if ((getCode() == DHO_FQDN) && haveFqdn4Format()) {
diff --git a/src/lib/dhcp/option_definition.h b/src/lib/dhcp/option_definition.h
index 73c0cdf..68f4036 100644
--- a/src/lib/dhcp/option_definition.h
+++ b/src/lib/dhcp/option_definition.h
@@ -324,6 +324,11 @@ public:
/// Vendor-Specific Information %Option.
bool haveVendor6Format() const;
+ /// @brief Check if the option has format of DHCPv6 Vendor Class option.
+ ///
+ /// @return true if option has the format of DHCPv6 Vendor Class option.
+ bool haveVendorClass6Format() const;
+
/// @brief Option factory.
///
/// This function creates an instance of DHCP option using
diff --git a/src/lib/dhcp/option_vendor_class.cc b/src/lib/dhcp/option_vendor_class.cc
index 6f05d52..c211b2f 100644
--- a/src/lib/dhcp/option_vendor_class.cc
+++ b/src/lib/dhcp/option_vendor_class.cc
@@ -130,6 +130,20 @@ OptionVendorClass::getTuple(const size_t at) const {
return (tuples_[at]);
}
+bool
+OptionVendorClass::hasTuple(const std::string& tuple_str) const {
+ // Iterate over existing tuples (there shouldn't be many of them),
+ // and try to match the searched one.
+ for (TuplesCollection::const_iterator it = tuples_.begin();
+ it != tuples_.end(); ++it) {
+ if (*it == tuple_str) {
+ return (true);
+ }
+ }
+ return (false);
+}
+
+
uint16_t
OptionVendorClass::len() {
// The option starts with the header and enterprise id.
diff --git a/src/lib/dhcp/option_vendor_class.h b/src/lib/dhcp/option_vendor_class.h
index 35daff3..1d43078 100644
--- a/src/lib/dhcp/option_vendor_class.h
+++ b/src/lib/dhcp/option_vendor_class.h
@@ -128,6 +128,13 @@ public:
return (tuples_);
}
+ /// @brief Checks if the Vendor Class holds the opaque data tuple with the
+ /// specified string.
+ ///
+ /// @param tuple_str String representation of the tuple being searched.
+ /// @return true if the specified tuple exists for this option.
+ bool hasTuple(const std::string& tuple_str) const;
+
/// @brief Returns the full length of the option, including option header.
virtual uint16_t len();
diff --git a/src/lib/dhcp/std_option_defs.h b/src/lib/dhcp/std_option_defs.h
index 6611f19..865407e 100644
--- a/src/lib/dhcp/std_option_defs.h
+++ b/src/lib/dhcp/std_option_defs.h
@@ -230,8 +230,7 @@ RECORD_DECL(REMOTE_ID_RECORDS, OPT_UINT32_TYPE, OPT_BINARY_TYPE);
// status-code
RECORD_DECL(STATUS_CODE_RECORDS, OPT_UINT16_TYPE, OPT_STRING_TYPE);
// vendor-class
-RECORD_DECL(VENDOR_CLASS_RECORDS, OPT_UINT32_TYPE, OPT_UINT16_TYPE,
- OPT_STRING_TYPE);
+RECORD_DECL(VENDOR_CLASS_RECORDS, OPT_UINT32_TYPE, OPT_BINARY_TYPE);
/// Standard DHCPv6 option definitions.
///
diff --git a/src/lib/dhcp/tests/libdhcp++_unittest.cc b/src/lib/dhcp/tests/libdhcp++_unittest.cc
index 4d645a4..f0bd282 100644
--- a/src/lib/dhcp/tests/libdhcp++_unittest.cc
+++ b/src/lib/dhcp/tests/libdhcp++_unittest.cc
@@ -29,6 +29,7 @@
#include <dhcp/option_int_array.h>
#include <dhcp/option_string.h>
#include <dhcp/option_vendor.h>
+#include <dhcp/option_vendor_class.h>
#include <util/buffer.h>
#include <util/encode/hex.h>
@@ -981,6 +982,14 @@ TEST_F(LibDhcpTest, stdOptionDefs6) {
client_fqdn_buf.insert(client_fqdn_buf.end(), fqdn_buf.begin(),
fqdn_buf.end());
+ // Initialize test buffer for Vendor Class option.
+ const char vclass_data[] = {
+ 0x00, 0x01, 0x02, 0x03,
+ 0x00, 0x01, 0x02
+ };
+ std::vector<uint8_t> vclass_buf(vclass_data,
+ vclass_data + sizeof(vclass_data));;
+
// The actual test starts here for all supported option codes.
LibDhcpTest::testStdOptionDefs6(D6O_CLIENTID, begin, end,
typeid(Option));
@@ -1018,8 +1027,9 @@ TEST_F(LibDhcpTest, stdOptionDefs6) {
LibDhcpTest::testStdOptionDefs6(D6O_USER_CLASS, begin, end,
typeid(Option));
- LibDhcpTest::testStdOptionDefs6(D6O_VENDOR_CLASS, begin, end,
- typeid(OptionCustom));
+ LibDhcpTest::testStdOptionDefs6(D6O_VENDOR_CLASS, vclass_buf.begin(),
+ vclass_buf.end(),
+ typeid(OptionVendorClass));
LibDhcpTest::testStdOptionDefs6(D6O_VENDOR_OPTS, begin, end,
typeid(OptionVendor),
@@ -1148,22 +1158,18 @@ TEST_F(LibDhcpTest, vendorClass6) {
// Option vendor-class should be there
ASSERT_FALSE(options.find(D6O_VENDOR_CLASS) == options.end());
- // It should be of type OptionCustom
- boost::shared_ptr<OptionCustom> vclass =
- boost::dynamic_pointer_cast<OptionCustom> (options.begin()->second);
+ // It should be of type OptionVendorClass
+ boost::shared_ptr<OptionVendorClass> vclass =
+ boost::dynamic_pointer_cast<OptionVendorClass>(options.begin()->second);
ASSERT_TRUE(vclass);
// Let's investigate if the option content is correct
// 3 fields expected: vendor-id, data-len and data
- ASSERT_EQ(3, vclass->getDataFieldsNum());
-
- EXPECT_EQ(4491, vclass->readInteger<uint32_t>
- (VENDOR_CLASS_ENTERPRISE_ID_INDEX)); // vendor-id=4491
- EXPECT_EQ(10, vclass->readInteger<uint16_t>
- (VENDOR_CLASS_DATA_LEN_INDEX)); // data len = 10
- EXPECT_EQ("eRouter1.0", vclass->readString
- (VENDOR_CLASS_STRING_INDEX)); // data="eRouter1.0"
+ EXPECT_EQ(4491, vclass->getVendorId());
+ EXPECT_EQ(20, vclass->len());
+ ASSERT_EQ(1, vclass->getTuplesNum());
+ EXPECT_EQ("eRouter1.0", vclass->getTuple(0).getText());
}
} // end of anonymous space
diff --git a/src/lib/dhcp/tests/option_vendor_class_unittest.cc b/src/lib/dhcp/tests/option_vendor_class_unittest.cc
index 4028710..2315e1e 100644
--- a/src/lib/dhcp/tests/option_vendor_class_unittest.cc
+++ b/src/lib/dhcp/tests/option_vendor_class_unittest.cc
@@ -74,6 +74,11 @@ TEST(OptionVendorClass, addTuple) {
EXPECT_EQ("xyz", vendor_class.getTuple(0).getText());
EXPECT_EQ("abc", vendor_class.getTuple(1).getText());
+ // Check that hasTuple correctly identifies existing tuples.
+ EXPECT_TRUE(vendor_class.hasTuple("xyz"));
+ EXPECT_TRUE(vendor_class.hasTuple("abc"));
+ EXPECT_FALSE(vendor_class.hasTuple("other"));
+
// Attempt to add the tuple with 1 byte long length field should fail
// for DHCPv6 option.
OpaqueDataTuple tuple2(OpaqueDataTuple::LENGTH_1_BYTE);
More information about the bind10-changes
mailing list