Commit 8a0c9ae6 authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[2893] Fixed failing ifacemgr unit test on BSD.

parent 67b078ed
......@@ -19,6 +19,7 @@
#include <dhcp/iface_mgr.h>
#include <dhcp/iface_mgr_error_handler.h>
#include <dhcp/pkt_filter_bpf.h>
#include <dhcp/pkt_filter_inet.h>
#include <exceptions/exceptions.h>
#include <sys/types.h>
......@@ -144,13 +145,21 @@ bool IfaceMgr::os_receive4(struct msghdr& /*m*/, Pkt4Ptr& /*pkt*/) {
}
void
IfaceMgr::setMatchingPacketFilter(const bool /* direct_response_desired */) {
// Ignore whether the direct response is desired or not. Even if the
// direct response is not desired we don't want to use PktFilterInet
// because the BSD doesn't support binding to the device and listening
// to broadcast traffic on individual interfaces. So, datagram socket
// supported by PktFilterInet is not really usable for DHCP.
setPacketFilter(PktFilterPtr(new PktFilterBPF()));
IfaceMgr::setMatchingPacketFilter(const bool direct_response_desired) {
// If direct response is desired we have to use BPF. If the direct
// response is not desired we use datagram socket supported by the
// PktFilterInet class. Note however that on BSD systems binding the
// datagram socket to the device is not supported and the server would
// have no means to determine on which interface the packet has been
// received. Hence, it is discouraged to use PktFilterInet for the
// server.
if (direct_response_desired) {
setPacketFilter(PktFilterPtr(new PktFilterBPF()));
} else {
setPacketFilter(PktFilterPtr(new PktFilterInet()));
}
}
bool
......
......@@ -1290,12 +1290,12 @@ TEST_F(IfaceMgrTest, setPacketFilter6) {
}
#if defined OS_LINUX
#if defined OS_LINUX || OS_BSD
// This Linux specific test checks whether it is possible to use
// IfaceMgr to figure out which Pakcket Filter object should be
// used when direct responses to hosts, having no address assigned
// are desired or not desired.
// This test is only supported on Linux and BSD systems. It checks
// if it is possible to use the IfaceMgr to select the packet filter
// object which can be used to send direct responses to the host
// which doesn't have an address yet.
TEST_F(IfaceMgrTest, setMatchingPacketFilter) {
// Create an instance of IfaceMgr.
......@@ -1304,23 +1304,22 @@ TEST_F(IfaceMgrTest, setMatchingPacketFilter) {
// Let IfaceMgr figure out which Packet Filter to use when
// direct response capability is not desired. It should pick
// PktFilterInet.
// PktFilterInet on Linux.
EXPECT_NO_THROW(iface_mgr->setMatchingPacketFilter(false));
// The PktFilterInet is supposed to report lack of direct
// response capability.
EXPECT_FALSE(iface_mgr->isDirectResponseSupported());
// There is working implementation of direct responses on Linux
// in PktFilterLPF. It uses Linux Packet Filtering as underlying
// mechanism. When direct responses are desired the object of
// this class should be set.
// and BSD (using PktFilterLPF and PktFilterBPF. When direct
// responses are desired the object of this class should be set.
EXPECT_NO_THROW(iface_mgr->setMatchingPacketFilter(true));
// This object should report that direct responses are supported.
EXPECT_TRUE(iface_mgr->isDirectResponseSupported());
}
// This test checks that it is not possible to open two sockets: IP/UDP
// and raw (LPF) socket and bind to the same address and port. The
// and raw socket and bind to the same address and port. The
// raw socket should be opened together with the fallback IP/UDP socket.
// The fallback socket should fail to open when there is another IP/UDP
// socket bound to the same address and port. Failing to open the fallback
......@@ -1376,8 +1375,8 @@ TEST_F(IfaceMgrTest, checkPacketFilterLPFSocket) {
// on systems other than Linux the function under test should always
// set object of PktFilterInet type as current Packet Filter. This
// object does not support direct responses. Once implementation is
// added on non-Linux systems the OS specific version of the test
// will be removed.
// added on systems other than BSD and Linux the OS specific version
// of the test will be removed.
TEST_F(IfaceMgrTest, setMatchingPacketFilter) {
// Create an instance of IfaceMgr.
......
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