]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3242] Added unit test to check that direct packet is dropped on iface.
authorMarcin Siodelski <marcin@isc.org>
Tue, 4 Feb 2014 10:14:11 +0000 (11:14 +0100)
committerMarcin Siodelski <marcin@isc.org>
Tue, 4 Feb 2014 10:14:11 +0000 (11:14 +0100)
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
src/bin/dhcp4/tests/dhcp4_test_utils.h

index 34f4d96839fb54a0a170acb55cf6b208e66b485c..2b00c24820457acbc5b944f68fc2d6c37cd05403 100644 (file)
@@ -3309,4 +3309,56 @@ TEST_F(Dhcpv4SrvTest, clientClassification) {
     EXPECT_FALSE(dis2->inClass("docsis3.0"));
 }
 
+// This test verifies that the direct message is dropped when it has been
+// received by the server via an interface for which there is no subnet
+// configured. It also checks that the message is not dropped (is processed)
+// when it is relayed or unicast.
+TEST_F(Dhcpv4SrvTest, acceptDirectRequest) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
+    NakedDhcpv4Srv srv(0);
+
+    Pkt4Ptr pkt(new Pkt4(DHCPDISCOVER, 1234));
+    // Set Giaddr and local server's unicast address, but don't set hops.
+    // Hops value must be greater than 0, when giaddr is set. Otherwise,
+    // message is considered malformed and the accept() function should
+    // return false.
+    pkt->setGiaddr(IOAddress("192.0.10.1"));
+    pkt->setLocalAddr(IOAddress("192.0.2.3"));
+    pkt->setIface("eth1");
+    EXPECT_FALSE(srv.accept(pkt));
+
+    // Let's set hops and check that the message is now accepted as
+    // a relayed message.
+    pkt->setHops(1);
+    EXPECT_TRUE(srv.accept(pkt));
+
+    // Make it a direct message but keep unicast server's address. The
+    // messages sent to unicast address should be accepted as they are
+    // most likely to renew existing leases. The server should respond
+    // to renews so they have to be accepted and processed.
+    pkt->setHops(0);
+    pkt->setGiaddr(IOAddress("0.0.0.0"));
+    EXPECT_TRUE(srv.accept(pkt));
+
+    // Direct message is now sent to a broadcast address. The server
+    // should accept this message because it has been received via
+    // eth1 for which there is a subnet configured (see test fixture
+    // class constructor).
+    pkt->setLocalAddr(IOAddress("255.255.255.255"));
+    EXPECT_TRUE(srv.accept(pkt));
+
+    // For eth0, there is no subnet configured. Such message is expected
+    // to be silently dropped.
+    pkt->setIface("eth0");
+    EXPECT_FALSE(srv.accept(pkt));
+
+    // But, if the message is unicast it should be accepted, even though
+    // it has been received via eth0.
+    pkt->setLocalAddr(IOAddress("10.0.0.1"));
+    EXPECT_TRUE(srv.accept(pkt));
+
+}
+
 }; // end of anonymous namespace
index 03f58d47850361bbc62b4f7732b14e501d53b9af..69e13f0c272d2fe32e654df6ee6dcb9cfa6a4ca0 100644 (file)
@@ -408,6 +408,7 @@ public:
     using Dhcpv4Srv::unpackOptions;
     using Dhcpv4Srv::name_change_reqs_;
     using Dhcpv4Srv::classifyPacket;
+    using Dhcpv4Srv::accept;
 };
 
 }; // end of isc::dhcp::test namespace