From: Marcin Siodelski Date: Mon, 5 Sep 2016 12:23:06 +0000 (+0200) Subject: [5003] Test local port of the received message in pkt filter tests. X-Git-Tag: trac5006_base~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c0afa727a51c69999a68d0d477c9225a00697ec;p=thirdparty%2Fkea.git [5003] Test local port of the received message in pkt filter tests. --- diff --git a/src/lib/dhcp/pkt_filter_inet.cc b/src/lib/dhcp/pkt_filter_inet.cc index edd8c3ded4..785b764765 100644 --- a/src/lib/dhcp/pkt_filter_inet.cc +++ b/src/lib/dhcp/pkt_filter_inet.cc @@ -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; } diff --git a/src/lib/dhcp/tests/pkt_filter_bpf_unittest.cc b/src/lib/dhcp/tests/pkt_filter_bpf_unittest.cc index a143128bf4..35738b6f12 100644 --- a/src/lib/dhcp/tests/pkt_filter_bpf_unittest.cc +++ b/src/lib/dhcp/tests/pkt_filter_bpf_unittest.cc @@ -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 diff --git a/src/lib/dhcp/tests/pkt_filter_inet_unittest.cc b/src/lib/dhcp/tests/pkt_filter_inet_unittest.cc index 029808569e..ec8c41b795 100644 --- a/src/lib/dhcp/tests/pkt_filter_inet_unittest.cc +++ b/src/lib/dhcp/tests/pkt_filter_inet_unittest.cc @@ -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 diff --git a/src/lib/dhcp/tests/pkt_filter_lpf_unittest.cc b/src/lib/dhcp/tests/pkt_filter_lpf_unittest.cc index 467f341a25..9471b33666 100644 --- a/src/lib/dhcp/tests/pkt_filter_lpf_unittest.cc +++ b/src/lib/dhcp/tests/pkt_filter_lpf_unittest.cc @@ -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 diff --git a/src/lib/dhcp/tests/pkt_filter_test_utils.cc b/src/lib/dhcp/tests/pkt_filter_test_utils.cc index 1719be3c48..af00481e5f 100644 --- a/src/lib/dhcp/tests/pkt_filter_test_utils.cc +++ b/src/lib/dhcp/tests/pkt_filter_test_utils.cc @@ -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); diff --git a/src/lib/dhcp/tests/pkt_filter_test_utils.h b/src/lib/dhcp/tests/pkt_filter_test_utils.h index 89a3e5a6a5..b45da25f52 100644 --- a/src/lib/dhcp/tests/pkt_filter_test_utils.h +++ b/src/lib/dhcp/tests/pkt_filter_test_utils.h @@ -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.