|
@@ -22,6 +22,8 @@
|
|
|
#include <dhcp/option4_addrlst.h>
|
|
|
#include <dhcp/option_custom.h>
|
|
|
#include <dhcp/option_int_array.h>
|
|
|
+#include <dhcp/pkt_filter.h>
|
|
|
+#include <dhcp/pkt_filter_inet.h>
|
|
|
#include <dhcp4/dhcp4_srv.h>
|
|
|
#include <dhcp4/dhcp4_log.h>
|
|
|
#include <dhcpsrv/cfgmgr.h>
|
|
@@ -50,14 +52,34 @@ public:
|
|
|
|
|
|
/// @brief Constructor.
|
|
|
///
|
|
|
- /// It disables configuration of broadcast options on
|
|
|
- /// sockets that are opened by the Dhcpv4Srv constructor.
|
|
|
- /// Setting broadcast options requires root privileges
|
|
|
- /// which is not the case when running unit tests.
|
|
|
+ /// This constructor disables default modes of operation used by the
|
|
|
+ /// Dhcpv4Srv class:
|
|
|
+ /// - Send/receive broadcast messages through sockets on interfaces
|
|
|
+ /// which support broadcast traffic.
|
|
|
+ /// - Direct DHCPv4 traffic - communication with clients which do not
|
|
|
+ /// have IP address assigned yet.
|
|
|
+ ///
|
|
|
+ /// Enabling these modes requires root privilges so they must be
|
|
|
+ /// disabled for unit testing.
|
|
|
+ ///
|
|
|
+ /// Note, that disabling broadcast options on sockets does not impact
|
|
|
+ /// the operation of these tests because they use local loopback
|
|
|
+ /// interface which doesn't have broadcast capability anyway. It rather
|
|
|
+ /// prevents setting broadcast options on other (broadcast capable)
|
|
|
+ /// sockets which are opened on other interfaces in Dhcpv4Srv constructor.
|
|
|
+ ///
|
|
|
+ /// The Direct DHCPv4 Traffic capability can be disabled here because
|
|
|
+ /// it is tested with PktFilterLPFTest unittest. The tests which belong
|
|
|
+ /// to PktFilterLPFTest can be enabled on demand when root privileges can
|
|
|
+ /// be guaranteed.
|
|
|
+ ///
|
|
|
+ /// @param port port number to listen on; the default value 0 indicates
|
|
|
+ /// that sockets should not be opened.
|
|
|
NakedDhcpv4Srv(uint16_t port = 0)
|
|
|
- : Dhcpv4Srv(port, "type=memfile", false) {
|
|
|
+ : Dhcpv4Srv(port, "type=memfile", false, false) {
|
|
|
}
|
|
|
|
|
|
+ using Dhcpv4Srv::adjustRemoteAddr;
|
|
|
using Dhcpv4Srv::processDiscover;
|
|
|
using Dhcpv4Srv::processRequest;
|
|
|
using Dhcpv4Srv::processRelease;
|
|
@@ -73,6 +95,41 @@ public:
|
|
|
|
|
|
static const char* SRVID_FILE = "server-id-test.txt";
|
|
|
|
|
|
+/// @brief Dummy Packet Filtering class.
|
|
|
+///
|
|
|
+/// This class reports capability to respond directly to the
|
|
|
+/// client which doesn't have address configured yet.
|
|
|
+///
|
|
|
+/// All packet and socket handling functions do nothing because
|
|
|
+/// they are not used in unit tests.
|
|
|
+class PktFilterTest : public PktFilter {
|
|
|
+public:
|
|
|
+
|
|
|
+ /// @brief Reports 'direct response' capability.
|
|
|
+ ///
|
|
|
+ /// @return always true.
|
|
|
+ virtual bool isDirectResponseSupported() const {
|
|
|
+ return (true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Does nothing.
|
|
|
+ virtual int openSocket(const Iface&, const IOAddress&, const uint16_t,
|
|
|
+ const bool, const bool) {
|
|
|
+ return (0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Does nothing.
|
|
|
+ virtual Pkt4Ptr receive(const Iface&, const SocketInfo&) {
|
|
|
+ return Pkt4Ptr();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Does nothing.
|
|
|
+ virtual int send(const Iface&, uint16_t, const Pkt4Ptr&) {
|
|
|
+ return (0);
|
|
|
+ }
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
class Dhcpv4SrvTest : public ::testing::Test {
|
|
|
public:
|
|
|
|
|
@@ -171,6 +228,11 @@ public:
|
|
|
EXPECT_EQ(q->getIface(), a->getIface());
|
|
|
EXPECT_EQ(q->getIndex(), a->getIndex());
|
|
|
EXPECT_EQ(q->getGiaddr(), a->getGiaddr());
|
|
|
+ // When processing an incoming packet the remote address
|
|
|
+ // is copied as a src address, and the source address is
|
|
|
+ // copied as a remote address to the response.
|
|
|
+ EXPECT_TRUE(q->getLocalHWAddr() == a->getLocalHWAddr());
|
|
|
+ EXPECT_TRUE(q->getRemoteHWAddr() == a->getRemoteHWAddr());
|
|
|
|
|
|
// Check that bare minimum of required options are there.
|
|
|
// We don't check options requested by a client. Those
|
|
@@ -360,26 +422,43 @@ public:
|
|
|
/// @brief Tests if Discover or Request message is processed correctly
|
|
|
///
|
|
|
/// @param msg_type DHCPDISCOVER or DHCPREQUEST
|
|
|
- /// @param client_addr client address
|
|
|
- /// @param relay_addr relay address
|
|
|
- void testDiscoverRequest(const uint8_t msg_type,
|
|
|
- const IOAddress& client_addr,
|
|
|
- const IOAddress& relay_addr) {
|
|
|
-
|
|
|
+ void testDiscoverRequest(const uint8_t msg_type) {
|
|
|
+ // Create an instance of the tested class.
|
|
|
boost::scoped_ptr<NakedDhcpv4Srv> srv(new NakedDhcpv4Srv(0));
|
|
|
+
|
|
|
+ // Initialize the source HW address.
|
|
|
vector<uint8_t> mac(6);
|
|
|
- for (int i = 0; i < 6; i++) {
|
|
|
- mac[i] = i*10;
|
|
|
+ for (int i = 0; i < 6; ++i) {
|
|
|
+ mac[i] = i * 10;
|
|
|
}
|
|
|
-
|
|
|
+ // Initialized the destination HW address.
|
|
|
+ vector<uint8_t> dst_mac(6);
|
|
|
+ for (int i = 0; i < 6; ++i) {
|
|
|
+ dst_mac[i] = i * 20;
|
|
|
+ }
|
|
|
+ // Create a DHCP message. It will be used to simulate the
|
|
|
+ // incoming message.
|
|
|
boost::shared_ptr<Pkt4> req(new Pkt4(msg_type, 1234));
|
|
|
+ // Create a response message. It will hold a reponse packet.
|
|
|
+ // Initially, set it to NULL.
|
|
|
boost::shared_ptr<Pkt4> rsp;
|
|
|
-
|
|
|
+ // Set the name of the interface on which packet is received.
|
|
|
req->setIface("eth0");
|
|
|
+ // Set the interface index. It is just a dummy value and will
|
|
|
+ // not be interpreted.
|
|
|
req->setIndex(17);
|
|
|
+ // Set the target HW address. This value is normally used to
|
|
|
+ // construct the data link layer header.
|
|
|
+ req->setRemoteHWAddr(1, 6, dst_mac);
|
|
|
+ // Set the HW address. This value is set on DHCP level (in chaddr).
|
|
|
req->setHWAddr(1, 6, mac);
|
|
|
- req->setRemoteAddr(IOAddress(client_addr));
|
|
|
- req->setGiaddr(relay_addr);
|
|
|
+ // Set local HW address. It is used to construct the data link layer
|
|
|
+ // header.
|
|
|
+ req->setLocalHWAddr(1, 6, mac);
|
|
|
+ // Set target IP address.
|
|
|
+ req->setRemoteAddr(IOAddress("192.0.2.55"));
|
|
|
+ // Set relay address.
|
|
|
+ req->setGiaddr(IOAddress("192.0.2.10"));
|
|
|
|
|
|
// We are going to test that certain options are returned
|
|
|
// in the response message when requested using 'Parameter
|
|
@@ -407,33 +486,6 @@ public:
|
|
|
|
|
|
}
|
|
|
|
|
|
- if (relay_addr.toText() != "0.0.0.0") {
|
|
|
- // This is relayed message. It should be sent brsp to relay address.
|
|
|
- EXPECT_EQ(req->getGiaddr().toText(),
|
|
|
- rsp->getRemoteAddr().toText());
|
|
|
-
|
|
|
- } else if (client_addr.toText() != "0.0.0.0") {
|
|
|
- // This is a message from a client having an IP address.
|
|
|
- EXPECT_EQ(req->getRemoteAddr().toText(),
|
|
|
- rsp->getRemoteAddr().toText());
|
|
|
-
|
|
|
- } else {
|
|
|
- // This is a message from a client having no IP address yet.
|
|
|
- // If IfaceMgr supports direct traffic the response should
|
|
|
- // be sent to the new address assigned to the client.
|
|
|
- if (IfaceMgr::instance().isDirectResponseSupported()) {
|
|
|
- EXPECT_EQ(rsp->getYiaddr(),
|
|
|
- rsp->getRemoteAddr().toText());
|
|
|
-
|
|
|
- // If direct response to the client having no IP address is
|
|
|
- // not supported, response should go to broadcast.
|
|
|
- } else {
|
|
|
- EXPECT_EQ("255.255.255.255", rsp->getRemoteAddr().toText());
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
messageCheck(req, rsp);
|
|
|
|
|
|
// We did not request any options so these should not be present
|
|
@@ -471,12 +523,35 @@ public:
|
|
|
|
|
|
}
|
|
|
|
|
|
- ~Dhcpv4SrvTest() {
|
|
|
+ /// @brief This function cleans up after the test.
|
|
|
+ virtual void TearDown() {
|
|
|
+
|
|
|
CfgMgr::instance().deleteSubnets4();
|
|
|
|
|
|
// Let's clean up if there is such a file.
|
|
|
unlink(SRVID_FILE);
|
|
|
- };
|
|
|
+
|
|
|
+ // Close all open sockets.
|
|
|
+ IfaceMgr::instance().closeSockets();
|
|
|
+
|
|
|
+ // Some unit tests override the default packet filtering class, used
|
|
|
+ // by the IfaceMgr. The dummy class, called PktFilterTest, reports the
|
|
|
+ // capability to directly respond to the clients without IP address
|
|
|
+ // assigned. This capability is not supported by the default packet
|
|
|
+ // filtering class: PktFilterInet. Therefore setting the dummy class
|
|
|
+ // allows to test scenarios, when server responds to the broadcast address
|
|
|
+ // on client's request, despite having support for direct response.
|
|
|
+ // The following call restores the use of original packet filtering class
|
|
|
+ // after the test.
|
|
|
+ try {
|
|
|
+ IfaceMgr::instance().setPacketFilter(PktFilterPtr(new PktFilterInet()));
|
|
|
+
|
|
|
+ } catch (const Exception& ex) {
|
|
|
+ FAIL() << "Failed to restore the default (PktFilterInet) packet filtering"
|
|
|
+ << " class after the test. Exception has been caught: "
|
|
|
+ << ex.what();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/// @brief A subnet used in most tests
|
|
|
Subnet4Ptr subnet_;
|
|
@@ -494,20 +569,220 @@ TEST_F(Dhcpv4SrvTest, basic) {
|
|
|
|
|
|
// Check that the base class can be instantiated
|
|
|
boost::scoped_ptr<Dhcpv4Srv> srv;
|
|
|
- ASSERT_NO_THROW(srv.reset(new Dhcpv4Srv(DHCP4_SERVER_PORT + 10000)));
|
|
|
+ ASSERT_NO_THROW(srv.reset(new Dhcpv4Srv(DHCP4_SERVER_PORT + 10000, "type=memfile",
|
|
|
+ false, false)));
|
|
|
srv.reset();
|
|
|
+ // We have to close open sockets because further in this test we will
|
|
|
+ // call the Dhcpv4Srv constructor again. This constructor will try to
|
|
|
+ // set the appropriate packet filter class for IfaceMgr. This requires
|
|
|
+ // that all sockets are closed.
|
|
|
+ IfaceMgr::instance().closeSockets();
|
|
|
|
|
|
// Check that the derived class can be instantiated
|
|
|
boost::scoped_ptr<NakedDhcpv4Srv> naked_srv;
|
|
|
ASSERT_NO_THROW(
|
|
|
- naked_srv.reset(new NakedDhcpv4Srv(DHCP4_SERVER_PORT + 10000)));
|
|
|
+ naked_srv.reset(new NakedDhcpv4Srv(DHCP4_SERVER_PORT + 10000)));
|
|
|
EXPECT_TRUE(naked_srv->getServerID());
|
|
|
+ // Close sockets again for the next test.
|
|
|
+ IfaceMgr::instance().closeSockets();
|
|
|
|
|
|
ASSERT_NO_THROW(naked_srv.reset(new NakedDhcpv4Srv(0)));
|
|
|
EXPECT_TRUE(naked_srv->getServerID());
|
|
|
}
|
|
|
|
|
|
-// Verifies that DISCOVER received via relay can be processed correctly,
|
|
|
+// This test verifies that the destination address of the response
|
|
|
+// message is set to giaddr, when giaddr is set to non-zero address
|
|
|
+// in the received message.
|
|
|
+TEST_F(Dhcpv4SrvTest, adjustRemoteAddressRelay) {
|
|
|
+ boost::scoped_ptr<NakedDhcpv4Srv> srv(new NakedDhcpv4Srv(0));
|
|
|
+
|
|
|
+ // Create the instance of the incoming packet.
|
|
|
+ boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));
|
|
|
+ // Set the giaddr to non-zero address as if it was relayed.
|
|
|
+ req->setGiaddr(IOAddress("192.0.2.1"));
|
|
|
+ // Set ciaddr to zero. This simulates the client which applies
|
|
|
+ // for the new lease.
|
|
|
+ req->setCiaddr(IOAddress("0.0.0.0"));
|
|
|
+ // Clear broadcast flag.
|
|
|
+ req->setFlags(0x0000);
|
|
|
+
|
|
|
+ // Create a response packet. Assume that the new lease have
|
|
|
+ // been created and new address allocated. This address is
|
|
|
+ // stored in yiaddr field.
|
|
|
+ boost::shared_ptr<Pkt4> resp(new Pkt4(DHCPOFFER, 1234));
|
|
|
+ resp->setYiaddr(IOAddress("192.0.2.100"));
|
|
|
+ // Clear the remote address.
|
|
|
+ resp->setRemoteAddr(IOAddress("0.0.0.0"));
|
|
|
+
|
|
|
+ // This function never throws.
|
|
|
+ ASSERT_NO_THROW(srv->adjustRemoteAddr(req, resp));
|
|
|
+
|
|
|
+ // Now the destination address should be relay's address.
|
|
|
+ EXPECT_EQ("192.0.2.1", resp->getRemoteAddr().toText());
|
|
|
+
|
|
|
+ // Let's do another test and set other fields: ciaddr and
|
|
|
+ // flags. By doing it, we want to make sure that the relay
|
|
|
+ // address will take precedence.
|
|
|
+ req->setGiaddr(IOAddress("192.0.2.50"));
|
|
|
+ req->setCiaddr(IOAddress("192.0.2.11"));
|
|
|
+ req->setFlags(Pkt4::FLAG_BROADCAST_MASK);
|
|
|
+
|
|
|
+ resp->setYiaddr(IOAddress("192.0.2.100"));
|
|
|
+ // Clear remote address.
|
|
|
+ resp->setRemoteAddr(IOAddress("0.0.0.0"));
|
|
|
+
|
|
|
+ ASSERT_NO_THROW(srv->adjustRemoteAddr(req, resp));
|
|
|
+
|
|
|
+ // Response should be sent back to the relay address.
|
|
|
+ EXPECT_EQ("192.0.2.50", resp->getRemoteAddr().toText());
|
|
|
+}
|
|
|
+
|
|
|
+// This test verifies that the destination address of the response message
|
|
|
+// is set to ciaddr when giaddr is set to zero and the ciaddr is set to
|
|
|
+// non-zero address in the received message. This is the case when the
|
|
|
+// client is in Renew or Rebind state.
|
|
|
+TEST_F(Dhcpv4SrvTest, adjustRemoteAddressRenewRebind) {
|
|
|
+ boost::scoped_ptr<NakedDhcpv4Srv> srv(new NakedDhcpv4Srv(0));
|
|
|
+
|
|
|
+ // Create instance of the incoming packet.
|
|
|
+ boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));
|
|
|
+
|
|
|
+ // Clear giaddr to simulate direct packet.
|
|
|
+ req->setGiaddr(IOAddress("0.0.0.0"));
|
|
|
+ // Set ciaddr to non-zero address. The response should be sent to this
|
|
|
+ // address as the client is in renewing or rebinding state (it is fully
|
|
|
+ // configured).
|
|
|
+ req->setCiaddr(IOAddress("192.0.2.15"));
|
|
|
+ // Let's configure broadcast flag. It should be ignored because
|
|
|
+ // we are responding directly to the client having an address
|
|
|
+ // and trying to extend his lease. Broadcast flag is only used
|
|
|
+ // when new lease is acquired and server must make a decision
|
|
|
+ // whether to unicast the response to the acquired address or
|
|
|
+ // broadcast it.
|
|
|
+ req->setFlags(Pkt4::FLAG_BROADCAST_MASK);
|
|
|
+
|
|
|
+ // Create a response.
|
|
|
+ boost::shared_ptr<Pkt4> resp(new Pkt4(DHCPOFFER, 1234));
|
|
|
+ // Let's extend the lease for the client in such a way that
|
|
|
+ // it will actually get different address. The response
|
|
|
+ // should not be sent to this address but rather to ciaddr
|
|
|
+ // as client still have ciaddr configured.
|
|
|
+ resp->setYiaddr(IOAddress("192.0.2.13"));
|
|
|
+ // Clear the remote address.
|
|
|
+ resp->setRemoteAddr(IOAddress("0.0.0.0"));
|
|
|
+
|
|
|
+ ASSERT_NO_THROW(srv->adjustRemoteAddr(req, resp));
|
|
|
+
|
|
|
+ // Check that server responds to ciaddr
|
|
|
+ EXPECT_EQ("192.0.2.15", resp->getRemoteAddr().toText());
|
|
|
+}
|
|
|
+
|
|
|
+// This test verifies that the destination address of the response message
|
|
|
+// is set correctly when giaddr and ciaddr is zeroed in the received message
|
|
|
+// and the new lease is acquired. The lease address is carried in the
|
|
|
+// response message in the yiaddr field. In this case destination address
|
|
|
+// of the response should be set to yiaddr if server supports direct responses
|
|
|
+// to the client which doesn't have an address yet or broadcast if the server
|
|
|
+// doesn't support direct responses.
|
|
|
+TEST_F(Dhcpv4SrvTest, adjustRemoteAddressSelect) {
|
|
|
+ boost::scoped_ptr<NakedDhcpv4Srv> srv(new NakedDhcpv4Srv(0));
|
|
|
+
|
|
|
+ // Create instance of the incoming packet.
|
|
|
+ boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));
|
|
|
+
|
|
|
+ // Clear giaddr to simulate direct packet.
|
|
|
+ req->setGiaddr(IOAddress("0.0.0.0"));
|
|
|
+ // Clear client address as it hasn't got any address configured yet.
|
|
|
+ req->setCiaddr(IOAddress("0.0.0.0"));
|
|
|
+
|
|
|
+ // Let's clear the broadcast flag.
|
|
|
+ req->setFlags(0);
|
|
|
+
|
|
|
+ // Create a response.
|
|
|
+ boost::shared_ptr<Pkt4> resp(new Pkt4(DHCPOFFER, 1234));
|
|
|
+ // Assign some new address for this client.
|
|
|
+ resp->setYiaddr(IOAddress("192.0.2.13"));
|
|
|
+
|
|
|
+ // Clear the remote address.
|
|
|
+ resp->setRemoteAddr(IOAddress("0.0.0.0"));
|
|
|
+
|
|
|
+ // When running unit tests, the IfaceMgr is using the default Packet
|
|
|
+ // Filtering class, PktFilterInet. This class does not support direct
|
|
|
+ // responses to clients without address assigned. When giaddr and ciaddr
|
|
|
+ // are zero and client has just got new lease, the assigned address is
|
|
|
+ // carried in yiaddr. In order to send this address to the client,
|
|
|
+ // server must broadcast its response.
|
|
|
+ ASSERT_NO_THROW(srv->adjustRemoteAddr(req, resp));
|
|
|
+
|
|
|
+ // Check that the response is sent to broadcast address as the
|
|
|
+ // server doesn't have capability to respond directly.
|
|
|
+ EXPECT_EQ("255.255.255.255", resp->getRemoteAddr().toText());
|
|
|
+
|
|
|
+ // We also want to test the case when the server has capability to
|
|
|
+ // respond directly to the client which is not configured. Server
|
|
|
+ // makes decision whether it responds directly or broadcast its
|
|
|
+ // response based on the capability reported by IfaceMgr. In order
|
|
|
+ // to set this capability we have to provide a dummy Packet Filter
|
|
|
+ // class which would report the support for direct responses.
|
|
|
+ // This class is called PktFilterTest.
|
|
|
+ IfaceMgr::instance().setPacketFilter(PktFilterPtr(new PktFilterTest()));
|
|
|
+
|
|
|
+ // Now we expect that the server will send its response to the
|
|
|
+ // address assigned for the client.
|
|
|
+ ASSERT_NO_THROW(srv->adjustRemoteAddr(req, resp));
|
|
|
+
|
|
|
+ EXPECT_EQ("192.0.2.13", resp->getRemoteAddr().toText());
|
|
|
+}
|
|
|
+
|
|
|
+// This test verifies that the destination address of the response message
|
|
|
+// is set to broadcast address when client set broadcast flag in its
|
|
|
+// query. Client sets this flag to indicate that it can't receive direct
|
|
|
+// responses from the server when it doesn't have its interface configured.
|
|
|
+// Server must respect broadcast flag.
|
|
|
+TEST_F(Dhcpv4SrvTest, adjustRemoteAddressBroadcast) {
|
|
|
+ boost::scoped_ptr<NakedDhcpv4Srv> srv(new NakedDhcpv4Srv(0));
|
|
|
+
|
|
|
+ // Create instance of the incoming packet.
|
|
|
+ boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));
|
|
|
+
|
|
|
+ // Clear giaddr to simulate direct packet.
|
|
|
+ req->setGiaddr(IOAddress("0.0.0.0"));
|
|
|
+ // Clear client address as it hasn't got any address configured yet.
|
|
|
+ req->setCiaddr(IOAddress("0.0.0.0"));
|
|
|
+
|
|
|
+ // Let's set the broadcast flag.
|
|
|
+ req->setFlags(Pkt4::FLAG_BROADCAST_MASK);
|
|
|
+
|
|
|
+ // Create a response.
|
|
|
+ boost::shared_ptr<Pkt4> resp(new Pkt4(DHCPOFFER, 1234));
|
|
|
+ // Assign some new address for this client.
|
|
|
+ resp->setYiaddr(IOAddress("192.0.2.13"));
|
|
|
+
|
|
|
+ // Clear the remote address.
|
|
|
+ resp->setRemoteAddr(IOAddress("0.0.0.0"));
|
|
|
+
|
|
|
+ // When running unit tests, the IfaceMgr is using the default Packet
|
|
|
+ // Filtering class, PktFilterInet. This class does not support direct
|
|
|
+ // responses to the clients without address assigned. If giaddr and
|
|
|
+ // ciaddr are zero and client has just got the new lease, the assigned
|
|
|
+ // address is carried in yiaddr. In order to send this address to the
|
|
|
+ // client, server must send the response to the broadcast address when
|
|
|
+ // direct response is not supported. This conflicts with the purpose
|
|
|
+ // of this test which is supposed to verify that responses are sent
|
|
|
+ // to broadcast address only, when broadcast flag is set. Therefore,
|
|
|
+ // in order to simulate that direct responses are supported we have
|
|
|
+ // to replace the default packet filtering class with a dummy class
|
|
|
+ // which reports direct response capability.
|
|
|
+ IfaceMgr::instance().setPacketFilter(PktFilterPtr(new PktFilterTest()));
|
|
|
+
|
|
|
+ ASSERT_NO_THROW(srv->adjustRemoteAddr(req, resp));
|
|
|
+
|
|
|
+ // Server must repond to broadcast address when client desired that
|
|
|
+ // by setting the broadcast flag in its request.
|
|
|
+ EXPECT_EQ("255.255.255.255", resp->getRemoteAddr().toText());
|
|
|
+}
|
|
|
+
|
|
|
+// Verifies that DISCOVER message can be processed correctly,
|
|
|
// that the OFFER message generated in response is valid and
|
|
|
// contains necessary options.
|
|
|
//
|
|
@@ -515,29 +790,11 @@ TEST_F(Dhcpv4SrvTest, basic) {
|
|
|
// are other tests that verify correctness of the allocation
|
|
|
// engine. See DiscoverBasic, DiscoverHint, DiscoverNoClientId
|
|
|
// and DiscoverInvalidHint.
|
|
|
-TEST_F(Dhcpv4SrvTest, processDiscoverRelay) {
|
|
|
- testDiscoverRequest(DHCPDISCOVER,
|
|
|
- IOAddress("192.0.2.56"),
|
|
|
- IOAddress("192.0.2.67"));
|
|
|
-}
|
|
|
-
|
|
|
-// Verifies that the non-relayed DISCOVER is processed correctly when
|
|
|
-// client source address is specified.
|
|
|
-TEST_F(Dhcpv4SrvTest, processDiscoverNoRelay) {
|
|
|
- testDiscoverRequest(DHCPDISCOVER,
|
|
|
- IOAddress("0.0.0.0"),
|
|
|
- IOAddress("192.0.2.67"));
|
|
|
+TEST_F(Dhcpv4SrvTest, processDiscover) {
|
|
|
+ testDiscoverRequest(DHCPDISCOVER);
|
|
|
}
|
|
|
|
|
|
-// Verified that the non-relayed DISCOVER is processed correctly when
|
|
|
-// client source address is not specified.
|
|
|
-TEST_F(Dhcpv4SrvTest, processDiscoverNoClientAddr) {
|
|
|
- testDiscoverRequest(DHCPDISCOVER,
|
|
|
- IOAddress("0.0.0.0"),
|
|
|
- IOAddress("0.0.0.0"));
|
|
|
-}
|
|
|
-
|
|
|
-// Verifies that REQUEST received via relay can be processed correctly,
|
|
|
+// Verifies that REQUEST message can be processed correctly,
|
|
|
// that the OFFER message generated in response is valid and
|
|
|
// contains necessary options.
|
|
|
//
|
|
@@ -545,26 +802,8 @@ TEST_F(Dhcpv4SrvTest, processDiscoverNoClientAddr) {
|
|
|
// are other tests that verify correctness of the allocation
|
|
|
// engine. See DiscoverBasic, DiscoverHint, DiscoverNoClientId
|
|
|
// and DiscoverInvalidHint.
|
|
|
-TEST_F(Dhcpv4SrvTest, processRequestRelay) {
|
|
|
- testDiscoverRequest(DHCPREQUEST,
|
|
|
- IOAddress("192.0.2.56"),
|
|
|
- IOAddress("192.0.2.67"));
|
|
|
-}
|
|
|
-
|
|
|
-// Verifies that the non-relayed REQUEST is processed correctly when
|
|
|
-// client source address is specified.
|
|
|
-TEST_F(Dhcpv4SrvTest, processRequestNoRelay) {
|
|
|
- testDiscoverRequest(DHCPREQUEST,
|
|
|
- IOAddress("0.0.0.0"),
|
|
|
- IOAddress("192.0.2.67"));
|
|
|
-}
|
|
|
-
|
|
|
-// Verified that the non-relayed REQUEST is processed correctly when
|
|
|
-// client source address is not specified.
|
|
|
-TEST_F(Dhcpv4SrvTest, processRequestNoClientAddr) {
|
|
|
- testDiscoverRequest(DHCPREQUEST,
|
|
|
- IOAddress("0.0.0.0"),
|
|
|
- IOAddress("0.0.0.0"));
|
|
|
+TEST_F(Dhcpv4SrvTest, processRequest) {
|
|
|
+ testDiscoverRequest(DHCPREQUEST);
|
|
|
}
|
|
|
|
|
|
TEST_F(Dhcpv4SrvTest, processRelease) {
|