]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5003] Test local port of the received message in pkt filter tests.
authorMarcin Siodelski <marcin@isc.org>
Mon, 5 Sep 2016 12:23:06 +0000 (14:23 +0200)
committerMarcin Siodelski <marcin@isc.org>
Fri, 9 Sep 2016 09:40:22 +0000 (11:40 +0200)
src/lib/dhcp/pkt_filter_inet.cc
src/lib/dhcp/tests/pkt_filter_bpf_unittest.cc
src/lib/dhcp/tests/pkt_filter_inet_unittest.cc
src/lib/dhcp/tests/pkt_filter_lpf_unittest.cc
src/lib/dhcp/tests/pkt_filter_test_utils.cc
src/lib/dhcp/tests/pkt_filter_test_utils.h

index edd8c3ded4f66e82df075f64573d3a93b4352e95..785b76476596945d71254854bdd5ec40d0363b76 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -198,7 +198,6 @@ PktFilterInet::receive(Iface& iface, const SocketInfo& socket_info) {
         if ((cmsg->cmsg_level == IPPROTO_IP) &&
             (cmsg->cmsg_type == IP_RECVDSTADDR)) {
             to_addr = (struct in_addr*)CMSG_DATA(cmsg);
-
             pkt->setLocalAddr(IOAddress(htonl(to_addr->s_addr)));
             break;
         }
index a143128bf4a62ac522c16c60fe4e6ca0ece5d172..35738b6f121142ab8fdcdca096faeaea7ffc7c4a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2016 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -192,6 +192,7 @@ TEST_F(PktFilterBPFTest, DISABLED_receive) {
 
     // Check if the received message is correct.
     testRcvdMessage(rcvd_pkt);
+    testRcvdMessageAddressPort(rcvd_pkt);
 }
 
 // This test verifies that if the packet is received over the raw
index 029808569e5a5c8327ada7dd41009b6f80186007..ec8c41b7952d405b1953b08b94b07cb1657de9cf 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -140,6 +140,7 @@ TEST_F(PktFilterInetTest, receive) {
 
     // Check if the received message is correct.
     testRcvdMessage(rcvd_pkt);
+    testRcvdMessageAddressPort(rcvd_pkt);
 }
 
 } // anonymous namespace
index 467f341a251a8e6d8d832cdea6e37a7ee609ffa1..9471b336664138a8c7a23dc07af19db5c741d3db 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -179,6 +179,7 @@ TEST_F(PktFilterLPFTest, DISABLED_receive) {
 
     // Check if the received message is correct.
     testRcvdMessage(rcvd_pkt);
+    testRcvdMessageAddressPort(rcvd_pkt);
 }
 
 // This test verifies that if the packet is received over the raw
index 1719be3c48d76284ec21c5a8680948cf7fd606f5..af00481e5fd93d1fa471453aa1057256337317d1 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -160,6 +160,14 @@ PktFilterTest::testRcvdMessage(const Pkt4Ptr& rcvd_msg) const {
     EXPECT_EQ(test_message_->getHlen(), rcvd_msg->getHlen());
 }
 
+void
+PktFilterTest::testRcvdMessageAddressPort(const Pkt4Ptr& rcvd_msg) const {
+    EXPECT_EQ(test_message_->getRemoteAddr(), rcvd_msg->getLocalAddr());
+    EXPECT_EQ(test_message_->getLocalAddr(), rcvd_msg->getRemoteAddr());
+    EXPECT_EQ(test_message_->getRemotePort(), rcvd_msg->getLocalPort());
+    EXPECT_EQ(test_message_->getLocalPort(), rcvd_msg->getRemotePort());
+}
+
 bool
 PktFilterStub::isDirectResponseSupported() const {
     return (true);
index 89a3e5a6a52b8380fc712193e15f89b025c343fc..b45da25f52b25440ecb1d723ebe8b34e23e50241 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -71,11 +71,17 @@ public:
     /// @param sock A descriptor of the open socket.
     void testDgramSocket(const int sock) const;
 
-    /// @brief Checks if the received message matches the test_message_.
+    /// @brief Checks if a received message matches the test_message_.
     ///
     /// @param rcvd_msg An instance of the message to be tested.
     void testRcvdMessage(const Pkt4Ptr& rcvd_msg) const;
 
+    /// @brief Checks if received message has appropriate addresses and
+    /// port values set.
+    ///
+    /// @param rcvd_msg An instance of the message to be tested.
+    void testRcvdMessageAddressPort(const Pkt4Ptr& rcvd_msg) const;
+
     std::string ifname_;   ///< Loopback interface name
     uint16_t ifindex_;     ///< Loopback interface index.
     uint16_t port_;        ///< A port number used for the test.