From c97c2e0e7cf3a34ad7e103563aba2b10ee978dfc Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Fri, 8 Jul 2016 10:51:21 +0200 Subject: [PATCH] [4497] Enable retrieved options copying for DHCPv4o6 case. --- src/bin/dhcp4/dhcp4to6_ipc.cc | 3 ++ src/bin/dhcp4/tests/dhcp4to6_ipc_unittest.cc | 49 ++++++++++++++++++-- src/bin/dhcp6/dhcp6to4_ipc.cc | 3 ++ src/bin/dhcp6/tests/dhcp6to4_ipc_unittest.cc | 15 ++++++ 4 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/bin/dhcp4/dhcp4to6_ipc.cc b/src/bin/dhcp4/dhcp4to6_ipc.cc index 72499c122a..573078cb3e 100644 --- a/src/bin/dhcp4/dhcp4to6_ipc.cc +++ b/src/bin/dhcp4/dhcp4to6_ipc.cc @@ -121,6 +121,9 @@ void Dhcp4to6Ipc::handler() { // Delete previously set arguments callout_handle->deleteAllArguments(); + // Enable copying options from the packet within hook library. + ScopedEnableOptionsCopy response4_options_copy(rsp); + // Pass incoming packet as argument callout_handle->setArgument("response4", rsp); diff --git a/src/bin/dhcp4/tests/dhcp4to6_ipc_unittest.cc b/src/bin/dhcp4/tests/dhcp4to6_ipc_unittest.cc index 412bcb498a..166b53ecb2 100644 --- a/src/bin/dhcp4/tests/dhcp4to6_ipc_unittest.cc +++ b/src/bin/dhcp4/tests/dhcp4to6_ipc_unittest.cc @@ -21,6 +21,7 @@ #include #include +#include using namespace isc; using namespace isc::asiolink; @@ -64,6 +65,10 @@ public: EXPECT_TRUE(srv); // Let's wipe all existing statistics. StatsMgr::instance().removeAll(); + + // Set the flags to false as we expect them to be set in callouts. + callback_recv_pkt_options_copy_ = std::make_pair(false, false); + callback_sent_pkt_options_copy_ = std::make_pair(false, false); } /// @brief Configure DHCP4o6 port. @@ -85,9 +90,17 @@ public: /// /// @param callout_handle handle passed by the hooks framework /// @return always 0 - static int - buffer4_receive_callout(CalloutHandle& callout_handle) { + static int buffer4_receive_callout(CalloutHandle& callout_handle) { callout_handle.getArgument("query4", callback_recv_pkt_); + Pkt4o6Ptr pkt4 = boost::dynamic_pointer_cast(callback_recv_pkt_); + if (pkt4) { + callback_recv_pkt_options_copy_.first = pkt4->isCopyRetrievedOptions(); + Pkt6Ptr pkt6 = pkt4->getPkt6(); + if (pkt6) { + callback_recv_pkt_options_copy_.second = + pkt6->isCopyRetrievedOptions(); + } + } return (0); } @@ -97,9 +110,17 @@ public: /// /// @param callout_handle handle passed by the hooks framework /// @return always 0 - static int - buffer4_send_callout(CalloutHandle& callout_handle) { + static int buffer4_send_callout(CalloutHandle& callout_handle) { callout_handle.getArgument("response4", callback_sent_pkt_); + Pkt4o6Ptr pkt4 = boost::dynamic_pointer_cast(callback_sent_pkt_); + if (pkt4) { + callback_sent_pkt_options_copy_.first = pkt4->isCopyRetrievedOptions(); + Pkt6Ptr pkt6 = pkt4->getPkt6(); + if (pkt6) { + callback_sent_pkt_options_copy_.second = + pkt6->isCopyRetrievedOptions(); + } + } return (0); } @@ -109,6 +130,14 @@ public: /// @brief Response Pkt4 shared pointer returned in the send callout static Pkt4Ptr callback_sent_pkt_; + /// Flags indicating if copying retrieved options was enabled for + /// a received packet during callout execution. + static std::pair callback_recv_pkt_options_copy_; + + /// Flags indicating if copying retrieved options was enabled for + /// a sent packet during callout execution. + static std::pair callback_sent_pkt_options_copy_; + /// @brief reference to a controlled server /// /// Dhcp4to6Ipc::handler() uses the instance of the controlled server @@ -124,6 +153,8 @@ private: Pkt4Ptr Dhcp4to6IpcTest::callback_recv_pkt_; Pkt4Ptr Dhcp4to6IpcTest::callback_sent_pkt_; +std::pair Dhcp4to6IpcTest::callback_recv_pkt_options_copy_; +std::pair Dhcp4to6IpcTest::callback_sent_pkt_options_copy_; void Dhcp4to6IpcTest::configurePort(uint16_t port) { @@ -192,6 +223,11 @@ TEST_F(Dhcp4to6IpcTest, receive) { ASSERT_TRUE(pkt6_received); EXPECT_EQ("eth0", pkt6_received->getIface()); EXPECT_EQ("2001:db8:1::123", pkt6_received->getRemoteAddr().toText()); + + // Both DHCP4o6 and encapsulated DHCPv6 packet should have the + // flag enabled. + EXPECT_TRUE(callback_recv_pkt_options_copy_.first); + EXPECT_TRUE(callback_recv_pkt_options_copy_.second); } // This test verifies that message with multiple DHCPv4 query options @@ -326,6 +362,11 @@ TEST_F(Dhcp4to6IpcTest, process) { EXPECT_EQ("eth0", pkt6_sent->getIface()); EXPECT_EQ("2001:db8:1::123", pkt6_sent->getRemoteAddr().toText()); + // Both DHCP4o6 and encapsulated DHCPv6 packet should have the + // flag enabled. + EXPECT_TRUE(callback_sent_pkt_options_copy_.first); + EXPECT_TRUE(callback_sent_pkt_options_copy_.second); + // Verify the 4o6 part OptionCollection sent_msgs = pkt6_sent->getOptions(D6O_DHCPV4_MSG); ASSERT_EQ(1, sent_msgs.size()); diff --git a/src/bin/dhcp6/dhcp6to4_ipc.cc b/src/bin/dhcp6/dhcp6to4_ipc.cc index 8bdeffcf02..72001a4f87 100644 --- a/src/bin/dhcp6/dhcp6to4_ipc.cc +++ b/src/bin/dhcp6/dhcp6to4_ipc.cc @@ -107,6 +107,9 @@ void Dhcp6to4Ipc::handler() { // Delete previously set arguments callout_handle->deleteAllArguments(); + // Enable copying options from the packet within hook library. + ScopedEnableOptionsCopy response6_options_copy(pkt); + // Pass incoming packet as argument callout_handle->setArgument("response6", pkt); diff --git a/src/bin/dhcp6/tests/dhcp6to4_ipc_unittest.cc b/src/bin/dhcp6/tests/dhcp6to4_ipc_unittest.cc index 8fada87cc5..2e1a708e02 100644 --- a/src/bin/dhcp6/tests/dhcp6to4_ipc_unittest.cc +++ b/src/bin/dhcp6/tests/dhcp6to4_ipc_unittest.cc @@ -55,6 +55,9 @@ public: registerCallout("buffer6_send", buffer6_send_callout)); // Let's wipe all existing statistics. StatsMgr::instance().removeAll(); + + // Reset the flag which we expect to be set in the callout. + callback_pkt_options_copy_ = false; } /// @brief Configure DHCP4o6 port. @@ -77,12 +80,19 @@ public: static int buffer6_send_callout(CalloutHandle& callout_handle) { callout_handle.getArgument("response6", callback_pkt_); + if (callback_pkt_) { + callback_pkt_options_copy_ = callback_pkt_->isCopyRetrievedOptions(); + } return (0); } /// @brief Response Pkt6 shared pointer returned in the callout static Pkt6Ptr callback_pkt_; + /// Flag indicating if copying retrieved options was enabled for + /// a received packet during callout execution. + static bool callback_pkt_options_copy_; + private: /// @brief Provides fake configuration of interfaces. @@ -90,6 +100,7 @@ private: }; Pkt6Ptr Dhcp6to4IpcTest::callback_pkt_; +bool Dhcp6to4IpcTest::callback_pkt_options_copy_; void Dhcp6to4IpcTest::configurePort(const uint16_t port) { @@ -153,6 +164,10 @@ TEST_F(Dhcp6to4IpcTest, receive) { ASSERT_NO_THROW(src_ipc.send(pkt)); ASSERT_NO_THROW(IfaceMgr::instance().receive6(1, 0)); + // Make sure that the received packet was configured to return copy of + // retrieved options within a callout. + EXPECT_TRUE(callback_pkt_options_copy_); + // Get the forwarded packet from the callout Pkt6Ptr forwarded = Dhcp6to4IpcTest::callback_pkt_; ASSERT_TRUE(forwarded); -- 2.47.2