mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 22:15:23 +00:00
[4497] Enable retrieved options copying for DHCPv4o6 case.
This commit is contained in:
@@ -121,6 +121,9 @@ void Dhcp4to6Ipc::handler() {
|
|||||||
// Delete previously set arguments
|
// Delete previously set arguments
|
||||||
callout_handle->deleteAllArguments();
|
callout_handle->deleteAllArguments();
|
||||||
|
|
||||||
|
// Enable copying options from the packet within hook library.
|
||||||
|
ScopedEnableOptionsCopy<Pkt4> response4_options_copy(rsp);
|
||||||
|
|
||||||
// Pass incoming packet as argument
|
// Pass incoming packet as argument
|
||||||
callout_handle->setArgument("response4", rsp);
|
callout_handle->setArgument("response4", rsp);
|
||||||
|
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
using namespace isc;
|
using namespace isc;
|
||||||
using namespace isc::asiolink;
|
using namespace isc::asiolink;
|
||||||
@@ -64,6 +65,10 @@ public:
|
|||||||
EXPECT_TRUE(srv);
|
EXPECT_TRUE(srv);
|
||||||
// Let's wipe all existing statistics.
|
// Let's wipe all existing statistics.
|
||||||
StatsMgr::instance().removeAll();
|
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.
|
/// @brief Configure DHCP4o6 port.
|
||||||
@@ -85,9 +90,17 @@ public:
|
|||||||
///
|
///
|
||||||
/// @param callout_handle handle passed by the hooks framework
|
/// @param callout_handle handle passed by the hooks framework
|
||||||
/// @return always 0
|
/// @return always 0
|
||||||
static int
|
static int buffer4_receive_callout(CalloutHandle& callout_handle) {
|
||||||
buffer4_receive_callout(CalloutHandle& callout_handle) {
|
|
||||||
callout_handle.getArgument("query4", callback_recv_pkt_);
|
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);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,9 +110,17 @@ public:
|
|||||||
///
|
///
|
||||||
/// @param callout_handle handle passed by the hooks framework
|
/// @param callout_handle handle passed by the hooks framework
|
||||||
/// @return always 0
|
/// @return always 0
|
||||||
static int
|
static int buffer4_send_callout(CalloutHandle& callout_handle) {
|
||||||
buffer4_send_callout(CalloutHandle& callout_handle) {
|
|
||||||
callout_handle.getArgument("response4", callback_sent_pkt_);
|
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);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,6 +130,14 @@ public:
|
|||||||
/// @brief Response Pkt4 shared pointer returned in the send callout
|
/// @brief Response Pkt4 shared pointer returned in the send callout
|
||||||
static Pkt4Ptr callback_sent_pkt_;
|
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
|
/// @brief reference to a controlled server
|
||||||
///
|
///
|
||||||
/// Dhcp4to6Ipc::handler() uses the instance of the controlled server
|
/// Dhcp4to6Ipc::handler() uses the instance of the controlled server
|
||||||
@@ -124,6 +153,8 @@ private:
|
|||||||
|
|
||||||
Pkt4Ptr Dhcp4to6IpcTest::callback_recv_pkt_;
|
Pkt4Ptr Dhcp4to6IpcTest::callback_recv_pkt_;
|
||||||
Pkt4Ptr Dhcp4to6IpcTest::callback_sent_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
|
void
|
||||||
Dhcp4to6IpcTest::configurePort(uint16_t port) {
|
Dhcp4to6IpcTest::configurePort(uint16_t port) {
|
||||||
@@ -192,6 +223,11 @@ TEST_F(Dhcp4to6IpcTest, receive) {
|
|||||||
ASSERT_TRUE(pkt6_received);
|
ASSERT_TRUE(pkt6_received);
|
||||||
EXPECT_EQ("eth0", pkt6_received->getIface());
|
EXPECT_EQ("eth0", pkt6_received->getIface());
|
||||||
EXPECT_EQ("2001:db8:1::123", pkt6_received->getRemoteAddr().toText());
|
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
|
// 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("eth0", pkt6_sent->getIface());
|
||||||
EXPECT_EQ("2001:db8:1::123", pkt6_sent->getRemoteAddr().toText());
|
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
|
// Verify the 4o6 part
|
||||||
OptionCollection sent_msgs = pkt6_sent->getOptions(D6O_DHCPV4_MSG);
|
OptionCollection sent_msgs = pkt6_sent->getOptions(D6O_DHCPV4_MSG);
|
||||||
ASSERT_EQ(1, sent_msgs.size());
|
ASSERT_EQ(1, sent_msgs.size());
|
||||||
|
@@ -107,6 +107,9 @@ void Dhcp6to4Ipc::handler() {
|
|||||||
// Delete previously set arguments
|
// Delete previously set arguments
|
||||||
callout_handle->deleteAllArguments();
|
callout_handle->deleteAllArguments();
|
||||||
|
|
||||||
|
// Enable copying options from the packet within hook library.
|
||||||
|
ScopedEnableOptionsCopy<Pkt6> response6_options_copy(pkt);
|
||||||
|
|
||||||
// Pass incoming packet as argument
|
// Pass incoming packet as argument
|
||||||
callout_handle->setArgument("response6", pkt);
|
callout_handle->setArgument("response6", pkt);
|
||||||
|
|
||||||
|
@@ -55,6 +55,9 @@ public:
|
|||||||
registerCallout("buffer6_send", buffer6_send_callout));
|
registerCallout("buffer6_send", buffer6_send_callout));
|
||||||
// Let's wipe all existing statistics.
|
// Let's wipe all existing statistics.
|
||||||
StatsMgr::instance().removeAll();
|
StatsMgr::instance().removeAll();
|
||||||
|
|
||||||
|
// Reset the flag which we expect to be set in the callout.
|
||||||
|
callback_pkt_options_copy_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Configure DHCP4o6 port.
|
/// @brief Configure DHCP4o6 port.
|
||||||
@@ -77,12 +80,19 @@ public:
|
|||||||
static int
|
static int
|
||||||
buffer6_send_callout(CalloutHandle& callout_handle) {
|
buffer6_send_callout(CalloutHandle& callout_handle) {
|
||||||
callout_handle.getArgument("response6", callback_pkt_);
|
callout_handle.getArgument("response6", callback_pkt_);
|
||||||
|
if (callback_pkt_) {
|
||||||
|
callback_pkt_options_copy_ = callback_pkt_->isCopyRetrievedOptions();
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Response Pkt6 shared pointer returned in the callout
|
/// @brief Response Pkt6 shared pointer returned in the callout
|
||||||
static Pkt6Ptr callback_pkt_;
|
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:
|
private:
|
||||||
|
|
||||||
/// @brief Provides fake configuration of interfaces.
|
/// @brief Provides fake configuration of interfaces.
|
||||||
@@ -90,6 +100,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Pkt6Ptr Dhcp6to4IpcTest::callback_pkt_;
|
Pkt6Ptr Dhcp6to4IpcTest::callback_pkt_;
|
||||||
|
bool Dhcp6to4IpcTest::callback_pkt_options_copy_;
|
||||||
|
|
||||||
void
|
void
|
||||||
Dhcp6to4IpcTest::configurePort(const uint16_t port) {
|
Dhcp6to4IpcTest::configurePort(const uint16_t port) {
|
||||||
@@ -153,6 +164,10 @@ TEST_F(Dhcp6to4IpcTest, receive) {
|
|||||||
ASSERT_NO_THROW(src_ipc.send(pkt));
|
ASSERT_NO_THROW(src_ipc.send(pkt));
|
||||||
ASSERT_NO_THROW(IfaceMgr::instance().receive6(1, 0));
|
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
|
// Get the forwarded packet from the callout
|
||||||
Pkt6Ptr forwarded = Dhcp6to4IpcTest::callback_pkt_;
|
Pkt6Ptr forwarded = Dhcp6to4IpcTest::callback_pkt_;
|
||||||
ASSERT_TRUE(forwarded);
|
ASSERT_TRUE(forwarded);
|
||||||
|
Reference in New Issue
Block a user