From: Marcin Siodelski Date: Fri, 8 Jul 2016 07:47:46 +0000 (+0200) Subject: [4497] Extended Pkt4o6 to support setCopyRetrievedOptions. X-Git-Tag: trac4551_base~23^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d11a96e30051e45348f46f0bb069f086ffe69f10;p=thirdparty%2Fkea.git [4497] Extended Pkt4o6 to support setCopyRetrievedOptions. --- diff --git a/src/lib/dhcp/pkt.h b/src/lib/dhcp/pkt.h index bc29af4683..a86d4ce437 100644 --- a/src/lib/dhcp/pkt.h +++ b/src/lib/dhcp/pkt.h @@ -33,6 +33,8 @@ namespace dhcp { /// should be disabled. The use of RAII object eliminates the need for /// explicitly re-disabling options copying and is safer in case of /// exceptions thrown by callouts and a presence of multiple exit points. +/// +/// @tparam PktType Type of the packet, e.g. Pkt4, Pkt6, Pkt4o6. template class ScopedEnableOptionsCopy { public: @@ -331,10 +333,6 @@ public: /// @return pointer to found option (or NULL) OptionPtr getOption(const uint16_t type); - OptionPtr getOption(const uint16_t type) const { - return (getNonCopiedOption(type)); - } - /// @brief Controls whether the option retrieved by the @ref Pkt::getOption /// should be copied before being returned. /// @@ -359,7 +357,7 @@ public: /// /// @param copy Indicates if the options should be copied when /// retrieved (if true), or not copied (if false). - void setCopyRetrievedOptions(const bool copy) { + virtual void setCopyRetrievedOptions(const bool copy) { copy_retrieved_options_ = copy; } diff --git a/src/lib/dhcp/pkt4o6.cc b/src/lib/dhcp/pkt4o6.cc index 6eba0dc6d4..b828b190b7 100644 --- a/src/lib/dhcp/pkt4o6.cc +++ b/src/lib/dhcp/pkt4o6.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -47,6 +47,14 @@ void Pkt4o6::pack() { pkt6_->pack(); } +void +Pkt4o6::setCopyRetrievedOptions(const bool copy) { + Pkt4::setCopyRetrievedOptions(copy); + // Copy the new setting to the encapsulated instance of Pkt6. + pkt6_->setCopyRetrievedOptions(isCopyRetrievedOptions()); +} + + } // end of namespace isc::dhcp } // end of namespace isc diff --git a/src/lib/dhcp/pkt4o6.h b/src/lib/dhcp/pkt4o6.h index 4dc178d582..e092c1fcdb 100644 --- a/src/lib/dhcp/pkt4o6.h +++ b/src/lib/dhcp/pkt4o6.h @@ -1,4 +1,4 @@ -// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -59,6 +59,17 @@ public: return (true); } + /// @brief Overrides the @ref Pkt::setCopyRetrievedOptions to also + /// set the flag for encapsulated @ref Pkt6 instance. + /// + /// When the flag is set for the instance of the @ref Pkt4o6 the + /// encapsulated Pkt6, retrieved with @ref Pkt4o6::getPkt6, will + /// inherit this setting. + /// + /// @param copy Indicates if the options should be copied when + /// retrieved (if true), or not copied (if false). + virtual void setCopyRetrievedOptions(const bool copy); + private: /// Encapsulating DHCPv6 message Pkt6Ptr pkt6_; diff --git a/src/lib/dhcp/tests/pkt4o6_unittest.cc b/src/lib/dhcp/tests/pkt4o6_unittest.cc index 73bacb2460..d22d0ddb0d 100644 --- a/src/lib/dhcp/tests/pkt4o6_unittest.cc +++ b/src/lib/dhcp/tests/pkt4o6_unittest.cc @@ -93,6 +93,31 @@ TEST_F(Pkt4o6Test, pack) { EXPECT_EQ(0, memcmp(&cp[8], &buffer4_[0], buffer4_.size())); } +// This test verifies that the flag indicating that the retrieved options +// should be copied is transferred between the DHCPv4 packet and the +// DHCPv6 packet being a member of Pkt4o6 class. +TEST_F(Pkt4o6Test, setCopyRetrievedOptions) { + // Create Pkt4o6 and initially expect taht the flag is set to false. + Pkt4o6 pkt4o6(pkt4_, pkt6_); + ASSERT_FALSE(pkt4o6.isCopyRetrievedOptions()); + Pkt6Ptr pkt6 = pkt4o6.getPkt6(); + ASSERT_TRUE(pkt6); + ASSERT_FALSE(pkt6->isCopyRetrievedOptions()); + + // Set the flag to true for Pkt4o6. + pkt4o6.setCopyRetrievedOptions(true); + pkt6 = pkt4o6.getPkt6(); + ASSERT_TRUE(pkt6); + EXPECT_TRUE(pkt6->isCopyRetrievedOptions()); + + // Repeat the same test but set the flag to false. + pkt4o6.setCopyRetrievedOptions(false); + EXPECT_FALSE(pkt4o6.isCopyRetrievedOptions()); + pkt6 = pkt4o6.getPkt6(); + ASSERT_TRUE(pkt6); + EXPECT_FALSE(pkt6->isCopyRetrievedOptions()); +} + /// @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 }