From 4e77daebb1cf1a1faf3bba33a2a0ead4ed06d00a Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Mon, 14 Sep 2015 16:36:42 +0200 Subject: [PATCH 01/11] [fd4o6] Added DHCPv4-over-DHCPv6 packet class --- src/lib/dhcp/Makefile.am | 3 ++- src/lib/dhcp/pkt4o6.cc | 50 ++++++++++++++++++++++++++++++++++ src/lib/dhcp/pkt4o6.h | 58 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 src/lib/dhcp/pkt4o6.cc create mode 100644 src/lib/dhcp/pkt4o6.h diff --git a/src/lib/dhcp/Makefile.am b/src/lib/dhcp/Makefile.am index 73f1b00590..349070ec0c 100644 --- a/src/lib/dhcp/Makefile.am +++ b/src/lib/dhcp/Makefile.am @@ -15,7 +15,7 @@ CLEANFILES = *.gcno *.gcda lib_LTLIBRARIES = libkea-dhcp++.la libkea_dhcp___la_SOURCES = libkea_dhcp___la_SOURCES += classify.cc classify.h -libkea_dhcp___la_SOURCES += dhcp6.h dhcp4.h +libkea_dhcp___la_SOURCES += dhcp6.h dhcp4.h dhcp4o6.h libkea_dhcp___la_SOURCES += duid.cc duid.h libkea_dhcp___la_SOURCES += hwaddr.cc hwaddr.h libkea_dhcp___la_SOURCES += iface_mgr.cc iface_mgr.h @@ -48,6 +48,7 @@ libkea_dhcp___la_SOURCES += protocol_util.cc protocol_util.h libkea_dhcp___la_SOURCES += pkt.cc pkt.h libkea_dhcp___la_SOURCES += pkt6.cc pkt6.h libkea_dhcp___la_SOURCES += pkt4.cc pkt4.h +libkea_dhcp___la_SOURCES += pkt4o6.cc pkt4o6.h libkea_dhcp___la_SOURCES += pkt_filter.h pkt_filter.cc libkea_dhcp___la_SOURCES += pkt_filter6.h pkt_filter6.cc libkea_dhcp___la_SOURCES += pkt_filter_inet.cc pkt_filter_inet.h diff --git a/src/lib/dhcp/pkt4o6.cc b/src/lib/dhcp/pkt4o6.cc new file mode 100644 index 0000000000..f328e82f7d --- /dev/null +++ b/src/lib/dhcp/pkt4o6.cc @@ -0,0 +1,50 @@ +// Copyright (C) 2015 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. + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +using namespace std; +using namespace isc::dhcp; +using namespace isc::asiolink; + +namespace { + +/// @brief Default address used in Pkt4 constructor +const IOAddress DEFAULT_ADDRESS("0.0.0.0"); +} + +namespace isc { +namespace dhcp { + +Pkt4o6::Pkt4o6(const uint8_t* data, size_t len, const Pkt6Ptr& pkt6) + :Pkt4(data, len), pkt6_(pkt6) +{ + setIface(pkt6->getIface()); + setIndex(pkt6->getIndex()); + setRemoteAddr(pkt6->getRemoteAddr()); +} + +} // end of namespace isc::dhcp + +} // end of namespace isc diff --git a/src/lib/dhcp/pkt4o6.h b/src/lib/dhcp/pkt4o6.h new file mode 100644 index 0000000000..7e6f1877d2 --- /dev/null +++ b/src/lib/dhcp/pkt4o6.h @@ -0,0 +1,58 @@ +// Copyright (C) 2015 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. + +#ifndef PKT4O6_H +#define PKT4O6_H + +#include +#include + +#include + +namespace isc { + +namespace dhcp { + +/// @brief Represents DHCPv4-over-DHCPv6 packet +/// +/// This class derives from @c Pkt4 in order to be handled by +/// the DHCPv4 server code. It includes a shared pointer to the +/// DHCPv6 message too. +class Pkt4o6 : public Pkt4 { +public: + + /// @brief Constructor, used in message reception. + /// + /// @param data pointer to received data + /// @param len size of buffer to be allocated for this packet + /// @param pkt6 encapsulating DHCPv6 message. + Pkt4o6(const uint8_t* data, size_t len, const Pkt6Ptr& pkt6); + + /// @brief Returns encapsulating DHCPv6 message + const Pkt6Ptr& getPkt6() { return (pkt6_); } + +protected: + /// Encapsulating DHCPv6 message + const Pkt6Ptr& pkt6_; + +}; // Pkt4o6 class + +/// @brief A pointer to Pkt4o6 object. +typedef boost::shared_ptr Pkt4o6Ptr; + +} // isc::dhcp namespace + +} // isc namespace + +#endif From 72ba32da5f6a946ca7f131a450663cb345dd51cc Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Sat, 31 Oct 2015 13:29:05 +0900 Subject: [PATCH 02/11] [4027] incorporated part of c0044e3 from fd4o6 branch (not cherry-picking it because the commit has other irrelevant changes) --- src/lib/dhcp/pkt4o6.cc | 36 ++++++++++++++++++++++++------------ src/lib/dhcp/pkt4o6.h | 31 ++++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/src/lib/dhcp/pkt4o6.cc b/src/lib/dhcp/pkt4o6.cc index f328e82f7d..7fb087a6e3 100644 --- a/src/lib/dhcp/pkt4o6.cc +++ b/src/lib/dhcp/pkt4o6.cc @@ -13,20 +13,17 @@ // PERFORMANCE OF THIS SOFTWARE. #include -#include -#include -#include -#include + +#include +#include #include #include +#include -#include -#include -#include - -using namespace std; -using namespace isc::dhcp; using namespace isc::asiolink; +using namespace isc::dhcp; +using namespace isc::util; +using namespace std; namespace { @@ -37,14 +34,29 @@ const IOAddress DEFAULT_ADDRESS("0.0.0.0"); namespace isc { namespace dhcp { -Pkt4o6::Pkt4o6(const uint8_t* data, size_t len, const Pkt6Ptr& pkt6) - :Pkt4(data, len), pkt6_(pkt6) +Pkt4o6::Pkt4o6(const OptionBuffer& pkt4, const Pkt6Ptr& pkt6) + :Pkt4(&pkt4[0], pkt4.size()), pkt6_(pkt6) { + static_cast(pkt6->delOption(D6O_DHCPV4_MSG)); setIface(pkt6->getIface()); setIndex(pkt6->getIndex()); setRemoteAddr(pkt6->getRemoteAddr()); } +Pkt4o6::Pkt4o6(const Pkt4Ptr& pkt4, const Pkt6Ptr& pkt6) + :Pkt4(*pkt4), pkt6_(pkt6) { +} + +void Pkt4o6::pack() { + Pkt4::pack(); + OutputBuffer& buf = getBuffer(); + const uint8_t* ptr = static_cast(buf.getData()); + OptionBuffer msg(ptr, ptr + buf.getLength()); + OptionPtr dhcp4_msg(new Option(Option::V6, D6O_DHCPV4_MSG, msg)); + pkt6_->addOption(dhcp4_msg); + pkt6_->pack(); +} + } // end of namespace isc::dhcp } // end of namespace isc diff --git a/src/lib/dhcp/pkt4o6.h b/src/lib/dhcp/pkt4o6.h index 7e6f1877d2..f90ae4eb61 100644 --- a/src/lib/dhcp/pkt4o6.h +++ b/src/lib/dhcp/pkt4o6.h @@ -34,13 +34,34 @@ public: /// @brief Constructor, used in message reception. /// - /// @param data pointer to received data - /// @param len size of buffer to be allocated for this packet - /// @param pkt6 encapsulating DHCPv6 message. - Pkt4o6(const uint8_t* data, size_t len, const Pkt6Ptr& pkt6); + /// @param pkt4 DHCPv4 message + /// @param pkt6 encapsulating unpacked DHCPv6 message + /// the DHCPv4 message option will be removed + Pkt4o6(const OptionBuffer& pkt4, const Pkt6Ptr& pkt6); + + /// @brief Constructor, used in replying to a message + /// + /// @param pkt4 DHCPv4 message + /// @param pkt6 DHCPv6 message + Pkt4o6(const Pkt4Ptr& pkt4, const Pkt6Ptr& pkt6); /// @brief Returns encapsulating DHCPv6 message - const Pkt6Ptr& getPkt6() { return (pkt6_); } + const Pkt6Ptr& getPkt6() const { return (pkt6_); } + + /// @brief Prepares on-wire format of DHCPv4-over-DHCPv6 packet. + /// + /// Calls pack() on both DHCPv4 and DHCPv6 parts + /// Inserts the DHCPv4-message option + /// @ref pkt4::pack and @ref pkt6::pack + virtual void pack(); + + /// @brief Checks if a DHCPv4 message has beeb transported over DHCPv6 + /// + /// @return Boolean value which indicates whether the message is + /// transported over DHCPv6 (true) or native DHCPv4 (false) + virtual bool isDhcp4o6() const { + return (true); + } protected: /// Encapsulating DHCPv6 message From 9d3df95a21a93ea6314b0fc142c8b89fc19f6468 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Thu, 8 Oct 2015 05:15:28 +0200 Subject: [PATCH 03/11] [fd4o6] Adjusted Pkt6 pointer type --- src/lib/dhcp/pkt4o6.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/dhcp/pkt4o6.h b/src/lib/dhcp/pkt4o6.h index f90ae4eb61..4608ee55bb 100644 --- a/src/lib/dhcp/pkt4o6.h +++ b/src/lib/dhcp/pkt4o6.h @@ -46,7 +46,7 @@ public: Pkt4o6(const Pkt4Ptr& pkt4, const Pkt6Ptr& pkt6); /// @brief Returns encapsulating DHCPv6 message - const Pkt6Ptr& getPkt6() const { return (pkt6_); } + Pkt6Ptr getPkt6() const { return (pkt6_); } /// @brief Prepares on-wire format of DHCPv4-over-DHCPv6 packet. /// @@ -65,7 +65,7 @@ public: protected: /// Encapsulating DHCPv6 message - const Pkt6Ptr& pkt6_; + Pkt6Ptr pkt6_; }; // Pkt4o6 class From 5fcb4e02c45d43d419bb0a165eb4d59be8ee8316 Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Sat, 31 Oct 2015 13:46:05 +0900 Subject: [PATCH 04/11] [4027] enable DHCP4o6 option macros --- src/lib/dhcp/dhcp6.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/dhcp/dhcp6.h b/src/lib/dhcp/dhcp6.h index 6e053f69b1..86df12f99a 100644 --- a/src/lib/dhcp/dhcp6.h +++ b/src/lib/dhcp/dhcp6.h @@ -110,8 +110,8 @@ //#define D6O_ADDRSEL 84 /* RFC7078 */ //#define D6O_ADDRSEL_TABLE 85 /* RFC7078 */ //#define D6O_V6_PCP_SERVER 86 /* RFC7291 */ -//#define D6O_DHCPV4_MSG 87 /* RFC7341 */ -//#define D6O_DHCPV4_O_DHCPV6_SERVER 88 /* RFC7341 */ +#define D6O_DHCPV4_MSG 87 /* RFC7341 */ +#define D6O_DHCPV4_O_DHCPV6_SERVER 88 /* RFC7341 */ //#define D6O_S46_RULE 89 /* RFC7598 */ //#define D6O_S46_BR 90 /* RFC7598 */ //#define D6O_S46_DMR 91 /* RFC7598 */ From 6b35611c3b06ecee3c2497472e6e6a2339ccc055 Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Sat, 31 Oct 2015 17:20:25 +0900 Subject: [PATCH 05/11] [4027] added unit tests for Pkt4o6Test (with other some small cleanups) --- src/lib/dhcp/pkt4o6.h | 2 +- src/lib/dhcp/pkt6.h | 2 +- src/lib/dhcp/tests/Makefile.am | 1 + src/lib/dhcp/tests/pkt4o6_unittest.cc | 98 +++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 src/lib/dhcp/tests/pkt4o6_unittest.cc diff --git a/src/lib/dhcp/pkt4o6.h b/src/lib/dhcp/pkt4o6.h index 4608ee55bb..70bf6496b2 100644 --- a/src/lib/dhcp/pkt4o6.h +++ b/src/lib/dhcp/pkt4o6.h @@ -63,7 +63,7 @@ public: return (true); } -protected: +private: /// Encapsulating DHCPv6 message Pkt6Ptr pkt6_; diff --git a/src/lib/dhcp/pkt6.h b/src/lib/dhcp/pkt6.h index 87dab71a67..e517c35eed 100644 --- a/src/lib/dhcp/pkt6.h +++ b/src/lib/dhcp/pkt6.h @@ -244,7 +244,7 @@ public: /// @param option_code code of the requested option /// @param nesting_level see description above /// - /// @return pointer to the option (or NULL if there is no such option) + /// @return pointer to the option (or NULL if there is no such option) OptionPtr getRelayOption(uint16_t option_code, uint8_t nesting_level); /// @brief Return first instance of a specified option diff --git a/src/lib/dhcp/tests/Makefile.am b/src/lib/dhcp/tests/Makefile.am index 2e21b53f41..8faf432b14 100644 --- a/src/lib/dhcp/tests/Makefile.am +++ b/src/lib/dhcp/tests/Makefile.am @@ -74,6 +74,7 @@ libdhcp___unittests_SOURCES += option_vendor_class_unittest.cc libdhcp___unittests_SOURCES += pkt_captures4.cc pkt_captures6.cc pkt_captures.h libdhcp___unittests_SOURCES += pkt4_unittest.cc libdhcp___unittests_SOURCES += pkt6_unittest.cc +libdhcp___unittests_SOURCES += pkt4o6_unittest.cc libdhcp___unittests_SOURCES += pkt_filter_unittest.cc libdhcp___unittests_SOURCES += pkt_filter_inet_unittest.cc libdhcp___unittests_SOURCES += pkt_filter_inet6_unittest.cc diff --git a/src/lib/dhcp/tests/pkt4o6_unittest.cc b/src/lib/dhcp/tests/pkt4o6_unittest.cc new file mode 100644 index 0000000000..d75c2c03af --- /dev/null +++ b/src/lib/dhcp/tests/pkt4o6_unittest.cc @@ -0,0 +1,98 @@ +// Copyright (C) 2015 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. + +#include + +#include +#include +#include +#include +#include + +#include + +#include + +using namespace isc::dhcp; + +namespace { +class Pkt4o6Test : public ::testing::Test { +protected: + Pkt4o6Test() : + data6_(6, 0), + pkt6_(new Pkt6(&data6_[0], data6_.size())), + pkt4_(new Pkt4(DHCPDISCOVER, 0x12345678)) + { + pkt4_->pack(); + const uint8_t* cp = static_cast( + pkt4_->getBuffer().getData()); + buffer4_.assign(cp, cp + pkt4_->getBuffer().getLength()); + } + +protected: + const std::vector data6_; + // commonly used test data + Pkt6Ptr pkt6_; + Pkt4Ptr pkt4_; + OptionBuffer buffer4_; +}; + +TEST_F(Pkt4o6Test, construct) { + // Construct 4o6 packet, unpack the data to examine it + boost::scoped_ptr pkt4o6(new Pkt4o6(buffer4_, pkt6_)); + pkt4o6->unpack(); + // Inspect its internal to confirm it's built as expected. We also test + // isDhcp4o6() here. + EXPECT_TRUE(pkt4o6->isDhcp4o6()); + EXPECT_EQ(pkt6_, pkt4o6->getPkt6()); + EXPECT_EQ(DHCPDISCOVER, pkt4o6->getType()); + + // Same check for the other constructor. It relies on the internal + // behavior of Pkt4's copy constructor, so we need to first unpack pkt4. + pkt4_.reset(new Pkt4(&buffer4_[0], buffer4_.size())); + pkt4_->unpack(); + pkt4o6.reset(new Pkt4o6(pkt4_, pkt6_)); + EXPECT_TRUE(pkt4o6->isDhcp4o6()); + EXPECT_EQ(pkt6_, pkt4o6->getPkt6()); + EXPECT_EQ(DHCPDISCOVER, pkt4o6->getType()); +} + +TEST_F(Pkt4o6Test, pack) { + // prepare unpacked DHCPv4 packet (see the note in constructor test) + pkt4_.reset(new Pkt4(&buffer4_[0], buffer4_.size())); + pkt4_->unpack(); + + // Construct 4o6 packet to be tested and pack the data. + Pkt4o6 pkt4o6(pkt4_, pkt6_); + pkt4o6.pack(); + + // The packed data should be: + // 4-byte DHCPv6 message header + // 4-byte header part of DHCPv4 message option + // Raw DHCPv4 message (data stored in buffer4_) + EXPECT_EQ(4 + 4 + buffer4_.size(), + pkt4o6.getPkt6()->getBuffer().getLength()); + + // Check the DHCPv4 message option content (Pkt4o6 class is not responsible + // for making it valid, so we won't examine it) + const u_int8_t* cp = static_cast( + pkt4o6.getPkt6()->getBuffer().getData()); + EXPECT_EQ(0, cp[4]); + EXPECT_EQ(D6O_DHCPV4_MSG, cp[5]); + EXPECT_EQ((buffer4_.size() >> 8) & 0xff, cp[6]); + EXPECT_EQ(buffer4_.size() & 0xff, cp[7]); + EXPECT_EQ(0, memcmp(&cp[8], &buffer4_[0], buffer4_.size())); +} + +} From 3435b6f64d03c8df5216d535356a5ab6f4ed8f31 Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Sat, 31 Oct 2015 17:22:49 +0900 Subject: [PATCH 06/11] [4027] added some more comments for tests --- src/lib/dhcp/tests/pkt4o6_unittest.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/dhcp/tests/pkt4o6_unittest.cc b/src/lib/dhcp/tests/pkt4o6_unittest.cc index d75c2c03af..4d178b1530 100644 --- a/src/lib/dhcp/tests/pkt4o6_unittest.cc +++ b/src/lib/dhcp/tests/pkt4o6_unittest.cc @@ -41,11 +41,11 @@ protected: } protected: - const std::vector data6_; // commonly used test data - Pkt6Ptr pkt6_; - Pkt4Ptr pkt4_; - OptionBuffer buffer4_; + const std::vector data6_; // data for Pkt6 (content unimportant) + Pkt6Ptr pkt6_; // DHCPv6 message for 4o6 + Pkt4Ptr pkt4_; // DHCPv4 message for 4o6 + OptionBuffer buffer4_; // wire-format data buffer of pkt4_ }; TEST_F(Pkt4o6Test, construct) { From 1084fad9535966a34ee5ae9982332850e7aa38e1 Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Sat, 31 Oct 2015 18:47:03 +0900 Subject: [PATCH 07/11] [4027] use a single underscore version of uint8_t for consistency (and perhaps the double-underscore version is non-standard) --- src/lib/dhcp/tests/pkt4o6_unittest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/dhcp/tests/pkt4o6_unittest.cc b/src/lib/dhcp/tests/pkt4o6_unittest.cc index 4d178b1530..b6897b9c01 100644 --- a/src/lib/dhcp/tests/pkt4o6_unittest.cc +++ b/src/lib/dhcp/tests/pkt4o6_unittest.cc @@ -86,7 +86,7 @@ TEST_F(Pkt4o6Test, pack) { // Check the DHCPv4 message option content (Pkt4o6 class is not responsible // for making it valid, so we won't examine it) - const u_int8_t* cp = static_cast( + const uint8_t* cp = static_cast( pkt4o6.getPkt6()->getBuffer().getData()); EXPECT_EQ(0, cp[4]); EXPECT_EQ(D6O_DHCPV4_MSG, cp[5]); From b8b57816c2a31d220ef23efde9b29244f1bca24d Mon Sep 17 00:00:00 2001 From: Tomek Mrugalski Date: Sat, 31 Oct 2015 18:49:07 +0900 Subject: [PATCH 08/11] [4027] Minor corrections. --- src/lib/dhcp/pkt4o6.h | 6 +++--- src/lib/dhcp/tests/pkt4o6_unittest.cc | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lib/dhcp/pkt4o6.h b/src/lib/dhcp/pkt4o6.h index 70bf6496b2..e767a69047 100644 --- a/src/lib/dhcp/pkt4o6.h +++ b/src/lib/dhcp/pkt4o6.h @@ -34,7 +34,7 @@ public: /// @brief Constructor, used in message reception. /// - /// @param pkt4 DHCPv4 message + /// @param pkt4 Content of the DHCPv4-message option /// @param pkt6 encapsulating unpacked DHCPv6 message /// the DHCPv4 message option will be removed Pkt4o6(const OptionBuffer& pkt4, const Pkt6Ptr& pkt6); @@ -52,10 +52,10 @@ public: /// /// Calls pack() on both DHCPv4 and DHCPv6 parts /// Inserts the DHCPv4-message option - /// @ref pkt4::pack and @ref pkt6::pack + /// @ref Pkt4::pack and @ref Pkt6::pack virtual void pack(); - /// @brief Checks if a DHCPv4 message has beeb transported over DHCPv6 + /// @brief Checks if a DHCPv4 message has been transported over DHCPv6 /// /// @return Boolean value which indicates whether the message is /// transported over DHCPv6 (true) or native DHCPv4 (false) diff --git a/src/lib/dhcp/tests/pkt4o6_unittest.cc b/src/lib/dhcp/tests/pkt4o6_unittest.cc index 4d178b1530..e25c6fa48d 100644 --- a/src/lib/dhcp/tests/pkt4o6_unittest.cc +++ b/src/lib/dhcp/tests/pkt4o6_unittest.cc @@ -27,6 +27,9 @@ using namespace isc::dhcp; namespace { + +/// @brief A Fixture class dedicated to testing of the Pkt4o6 class that +/// represents a DHCPv4-over-DHCPv6 packet. class Pkt4o6Test : public ::testing::Test { protected: Pkt4o6Test() : @@ -48,6 +51,7 @@ protected: OptionBuffer buffer4_; // wire-format data buffer of pkt4_ }; +// This test verifies that the constructors are working as expected. TEST_F(Pkt4o6Test, construct) { // Construct 4o6 packet, unpack the data to examine it boost::scoped_ptr pkt4o6(new Pkt4o6(buffer4_, pkt6_)); @@ -68,6 +72,8 @@ TEST_F(Pkt4o6Test, construct) { EXPECT_EQ(DHCPDISCOVER, pkt4o6->getType()); } +// This test verifies that the pack() method handles the building +// process correctly. TEST_F(Pkt4o6Test, pack) { // prepare unpacked DHCPv4 packet (see the note in constructor test) pkt4_.reset(new Pkt4(&buffer4_[0], buffer4_.size())); @@ -86,7 +92,7 @@ TEST_F(Pkt4o6Test, pack) { // Check the DHCPv4 message option content (Pkt4o6 class is not responsible // for making it valid, so we won't examine it) - const u_int8_t* cp = static_cast( + const uint8_t* cp = static_cast( pkt4o6.getPkt6()->getBuffer().getData()); EXPECT_EQ(0, cp[4]); EXPECT_EQ(D6O_DHCPV4_MSG, cp[5]); @@ -95,4 +101,6 @@ TEST_F(Pkt4o6Test, pack) { EXPECT_EQ(0, memcmp(&cp[8], &buffer4_[0], buffer4_.size())); } +/// @todo: Add a test that handles actual DHCP4o6 traffic capture +/// once we get it. We should add the capture to pkt_captures{4,6}.cc } From 0fe570f5f161a0053f95b7d2afad6a43a4c7cd8b Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Sat, 31 Oct 2015 18:57:59 +0900 Subject: [PATCH 09/11] [4027] added some references --- src/lib/dhcp/pkt4o6.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/dhcp/pkt4o6.h b/src/lib/dhcp/pkt4o6.h index e767a69047..0e87f8e112 100644 --- a/src/lib/dhcp/pkt4o6.h +++ b/src/lib/dhcp/pkt4o6.h @@ -29,6 +29,10 @@ namespace dhcp { /// This class derives from @c Pkt4 in order to be handled by /// the DHCPv4 server code. It includes a shared pointer to the /// DHCPv6 message too. +/// +/// This is an implementation of the DHCPv4-query/response DHCPv6 messages +/// defined in RFC 7341 (http://ietf.org/rfc/rfc7341.txt). +/// See also http://kea.isc.org/wiki/Dhcp4o6Design for design discussions. class Pkt4o6 : public Pkt4 { public: From 7709b1539364456173826e0f3acdc8e1c471f9c3 Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Sat, 31 Oct 2015 19:01:02 +0900 Subject: [PATCH 10/11] [4027] added some explanatory comments for Pkt4o6::pack(). --- src/lib/dhcp/pkt4o6.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/dhcp/pkt4o6.cc b/src/lib/dhcp/pkt4o6.cc index 7fb087a6e3..ca26cf98c1 100644 --- a/src/lib/dhcp/pkt4o6.cc +++ b/src/lib/dhcp/pkt4o6.cc @@ -48,10 +48,14 @@ Pkt4o6::Pkt4o6(const Pkt4Ptr& pkt4, const Pkt6Ptr& pkt6) } void Pkt4o6::pack() { + // Convert wire-format Pkt4 data in the form of OptionBuffer. Pkt4::pack(); OutputBuffer& buf = getBuffer(); const uint8_t* ptr = static_cast(buf.getData()); OptionBuffer msg(ptr, ptr + buf.getLength()); + + // Build the DHCPv4 Message option for the DHCPv6 message, and pack the + // entire stuff. OptionPtr dhcp4_msg(new Option(Option::V6, D6O_DHCPV4_MSG, msg)); pkt6_->addOption(dhcp4_msg); pkt6_->pack(); From 47a7a6d11f9a8567367e43ed180847e7b24b9848 Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Sat, 31 Oct 2015 19:02:23 +0900 Subject: [PATCH 11/11] [4027] removed an unused variable (besides, this type of file-static definition is dangerious - it can lead to static initialization fiasco). --- src/lib/dhcp/pkt4o6.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/lib/dhcp/pkt4o6.cc b/src/lib/dhcp/pkt4o6.cc index ca26cf98c1..2dd3d0ff25 100644 --- a/src/lib/dhcp/pkt4o6.cc +++ b/src/lib/dhcp/pkt4o6.cc @@ -25,12 +25,6 @@ using namespace isc::dhcp; using namespace isc::util; using namespace std; -namespace { - -/// @brief Default address used in Pkt4 constructor -const IOAddress DEFAULT_ADDRESS("0.0.0.0"); -} - namespace isc { namespace dhcp {