Commit c97c2e0e authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[4497] Enable retrieved options copying for DHCPv4o6 case.

parent d11a96e3
......@@ -121,6 +121,9 @@ void Dhcp4to6Ipc::handler() {
// Delete previously set arguments
callout_handle->deleteAllArguments();
// Enable copying options from the packet within hook library.
ScopedEnableOptionsCopy<Pkt4> response4_options_copy(rsp);
// Pass incoming packet as argument
callout_handle->setArgument("response4", rsp);
......
......@@ -21,6 +21,7 @@
#include <gtest/gtest.h>
#include <stdint.h>
#include <utility>
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<Pkt4o6>(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<Pkt4o6>(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<bool, bool> callback_recv_pkt_options_copy_;
/// Flags indicating if copying retrieved options was enabled for
/// a sent packet during callout execution.
static std::pair<bool, bool> 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<bool, bool> Dhcp4to6IpcTest::callback_recv_pkt_options_copy_;
std::pair<bool, bool> 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());
......
......@@ -107,6 +107,9 @@ void Dhcp6to4Ipc::handler() {
// Delete previously set arguments
callout_handle->deleteAllArguments();
// Enable copying options from the packet within hook library.
ScopedEnableOptionsCopy<Pkt6> response6_options_copy(pkt);
// Pass incoming packet as argument
callout_handle->setArgument("response6", pkt);
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment