}
reset();
IfaceMgr::instance().setTestMode(false);
- IfaceMgr::instance().setDetectCallback(isc::dhcp::IfaceMgr::DetectCallback());
+ IfaceMgr::instance().setDetectCallback(std::bind(&IfaceMgr::checkDetectIfaces,
+ IfaceMgr::instancePtr().get(), ph::_1));
}
/// @brief Destructor
server_.reset();
IfaceMgr::instance().setTestMode(false);
- IfaceMgr::instance().setDetectCallback(isc::dhcp::IfaceMgr::DetectCallback());
+ IfaceMgr::instance().setDetectCallback(std::bind(&IfaceMgr::checkDetectIfaces,
+ IfaceMgr::instancePtr().get(), ph::_1));
IfaceMgr::instance().clearIfaces();
IfaceMgr::instance().closeSockets();
IfaceMgr::instance().detectIfaces();
// file is loaded correctly.
TEST_F(CtrlChannelDhcpv4SrvTest, configReloadDetectInterfaces) {
interfaces_ = "\"eth0\"";
- IfacePtr eth0 = IfaceMgrTestConfig::createIface("eth0", 0);
+ IfacePtr eth0 = IfaceMgrTestConfig::createIface("eth0", ETH0_INDEX,
+ "11:22:33:44:55:66");
auto detectIfaces = [&](bool update_only) {
if (!update_only) {
eth0->addAddress(IOAddress("10.0.0.1"));
f << cfg_txt;
f.close();
- IfacePtr eth1 = IfaceMgrTestConfig::createIface("eth1", 1);
+ IfacePtr eth1 = IfaceMgrTestConfig::createIface("eth1", ETH1_INDEX,
+ "AA:BB:CC:DD:EE:FF");
auto detectUpdateIfaces = [&](bool update_only) {
if (!update_only) {
eth1->addAddress(IOAddress("192.0.2.3"));
}
reset();
IfaceMgr::instance().setTestMode(false);
- IfaceMgr::instance().setDetectCallback(isc::dhcp::IfaceMgr::DetectCallback());
+ IfaceMgr::instance().setDetectCallback(std::bind(&IfaceMgr::checkDetectIfaces,
+ IfaceMgr::instancePtr().get(), ph::_1));
}
/// @brief Destructor
server_.reset();
reset();
IfaceMgr::instance().setTestMode(false);
- IfaceMgr::instance().setDetectCallback(isc::dhcp::IfaceMgr::DetectCallback());
+ IfaceMgr::instance().setDetectCallback(std::bind(&IfaceMgr::checkDetectIfaces,
+ IfaceMgr::instancePtr().get(), ph::_1));
IfaceMgr::instance().clearIfaces();
IfaceMgr::instance().closeSockets();
IfaceMgr::instance().detectIfaces();
// file is loaded correctly.
TEST_F(CtrlChannelDhcpv6SrvTest, configReloadDetectInterfaces) {
interfaces_ = "\"eth0\"";
- IfacePtr eth0 = IfaceMgrTestConfig::createIface("eth0", 0);
+ IfacePtr eth0 = IfaceMgrTestConfig::createIface("eth0", ETH0_INDEX,
+ "11:22:33:44:55:66");
auto detectIfaces = [&](bool update_only) {
if (!update_only) {
eth0->addAddress(IOAddress("10.0.0.1"));
f << cfg_txt;
f.close();
- IfacePtr eth1 = IfaceMgrTestConfig::createIface("eth1", ETH1_INDEX);
+ IfacePtr eth1 = IfaceMgrTestConfig::createIface("eth1", ETH1_INDEX,
+ "AA:BB:CC:DD:EE:FF");
auto detectUpdateIfaces = [&](bool update_only) {
if (!update_only) {
eth1->addAddress(IOAddress("192.0.2.3"));
using namespace isc::util;
using namespace isc::util::io;
using namespace isc::util::io::internal;
+namespace ph = std::placeholders;
namespace isc {
namespace dhcp {
IfaceMgr::IfaceMgr()
: packet_filter_(new PktFilterInet()),
packet_filter6_(new PktFilterInet6()),
- test_mode_(false),
- allow_loopback_(false) {
+ test_mode_(false), allow_loopback_(false) {
// Ensure that PQMs have been created to guarantee we have
// default packet queues in place.
isc_throw(Unexpected, "Failed to create PacketQueueManagers: " << ex.what());
}
+ detect_callback_ = std::bind(&IfaceMgr::checkDetectIfaces, this, ph::_1);
+
try {
// required for sending/receiving packets
return (getIfaceInternal(ifindex, MultiThreadingMgr::instance().getMode()));
}
-
IfacePtr
IfaceCollection::getIface(const std::string& ifname) {
return (getIfaceInternal(ifname, MultiThreadingMgr::instance().getMode()));
isc_throw(IfaceNotFound, "Tried to find socket for non-existent interface");
}
-
const Iface::SocketCollection& socket_collection = iface->getSockets();
Iface::SocketCollection::const_iterator candidate = socket_collection.end();
return errors_;
}
+bool
+IfaceMgr::checkDetectIfaces(bool update_only) {
+ if (test_mode_ && update_only) {
+ return (false);
+ }
+ return (true);
+}
+
} // end of namespace isc::dhcp
} // end of namespace isc
/// @param addr address to be removed.
///
/// @return true if removal was successful (address was in collection),
- /// false otherwise
+ /// false otherwise
bool delAddress(const isc::asiolink::IOAddress& addr);
/// @brief Adds socket descriptor to an interface.
///
class IfaceMgr : public boost::noncopyable {
public:
- /// Defines callback used when data is received over external sockets.
+ /// @brief Defines callback used when data is received over external sockets.
+ ///
/// @param fd socket descriptor of the ready socket
typedef std::function<void (int fd)> SocketCallback;
- /// Defines callback used when detecting interfaces.
+ /// @brief Defines callback used when detecting interfaces.
+ ///
/// @param update_only Only add interfaces that do not exist and update
/// existing interfaces.
///
detect_callback_ = cb;
}
+ /// @brief Check if the specific system calls used to detect interfaces
+ /// should be executed.
+ ///
+ /// @param update_only Only add interfaces that do not exist and update
+ /// existing interfaces.
+ ///
+ /// @return true if the specific system calls should be executed, false
+ /// otherwise causing the @ref detectIfaces to return immediately.
+ bool checkDetectIfaces(bool update_only);
+
/// @brief Detects network interfaces.
///
/// If the @ref detect_callback_ returns true, the specific system calls are
/// @brief Indicates if the IfaceMgr is in the test mode.
bool test_mode_;
- /// @brief Detect callback used to perform action before system dependent
- /// function calls. Currently this function is used in unittests only.
+ /// @brief Detect callback used to perform actions before system dependent
+ /// function calls.
///
/// If the @ref detect_callback_ returns true, the specific system calls are
/// executed, otherwise the @ref detectIfaces will return immediately.
}
}
- if (isTestMode() && update_only) {
- return;
- }
-
struct ifaddrs* iflist = 0;// The whole interface list
struct ifaddrs* ifptr = 0; // The interface we're processing now
}
}
- if (isTestMode() && update_only) {
- return;
- }
-
// Copies of netlink messages about links will be stored here.
Netlink::NetlinkMessages link_info;
}
}
- if (isTestMode() && update_only) {
- return;
- }
-
struct ifaddrs* iflist = 0;// The whole interface list
struct ifaddrs* ifptr = 0; // The interface we're processing now