From: Francis Dupont Date: Mon, 4 Feb 2019 16:12:51 +0000 (+0100) Subject: [417-incorrect-return-value-of-ifacemgr-send] Fixed interface manager and UDP socket... X-Git-Tag: 397-cb-implement-mysqlconfigbackenddhcpv6_base~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4be58523f38097cea81ea06161aead58e00aeb2a;p=thirdparty%2Fkea.git [417-incorrect-return-value-of-ifacemgr-send] Fixed interface manager and UDP socket packet filters send returned value --- diff --git a/src/lib/dhcp/iface_mgr.cc b/src/lib/dhcp/iface_mgr.cc index ff90384beb..a4dc8ad636 100644 --- a/src/lib/dhcp/iface_mgr.cc +++ b/src/lib/dhcp/iface_mgr.cc @@ -958,7 +958,8 @@ IfaceMgr::send(const Pkt6Ptr& pkt) { } // Assuming that packet filter is not NULL, because its modifier checks it. - return (packet_filter6_->send(*iface, getSocket(*pkt), pkt)); + // The packet filter returns an int but in fact it either returns 0 or throws. + return (packet_filter6_->send(*iface, getSocket(*pkt), pkt) == 0); } bool @@ -971,7 +972,8 @@ IfaceMgr::send(const Pkt4Ptr& pkt) { } // Assuming that packet filter is not NULL, because its modifier checks it. - return (packet_filter_->send(*iface, getSocket(*pkt).sockfd_, pkt)); + // The packet filter returns an int but in fact it either returns 0 or throws. + return (packet_filter_->send(*iface, getSocket(*pkt).sockfd_, pkt) == 0); } Pkt4Ptr IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */) { diff --git a/src/lib/dhcp/pkt_filter_inet.cc b/src/lib/dhcp/pkt_filter_inet.cc index 9953e8780c..59c32e749e 100644 --- a/src/lib/dhcp/pkt_filter_inet.cc +++ b/src/lib/dhcp/pkt_filter_inet.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2013-2019 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 @@ -283,7 +283,7 @@ PktFilterInet::send(const Iface&, uint16_t sockfd, " with an error: " << strerror(errno)); } - return (result); + return (0); } diff --git a/src/lib/dhcp/pkt_filter_inet6.cc b/src/lib/dhcp/pkt_filter_inet6.cc index eede050a71..939be3c819 100644 --- a/src/lib/dhcp/pkt_filter_inet6.cc +++ b/src/lib/dhcp/pkt_filter_inet6.cc @@ -319,12 +319,12 @@ PktFilterInet6::send(const Iface&, uint16_t sockfd, const Pkt6Ptr& pkt) { pkt->updateTimestamp(); int result = sendmsg(sockfd, &m, 0); - if (result < 0) { + if (result < 0) { isc_throw(SocketWriteError, "pkt6 send failed: sendmsg() returned" " with an error: " << strerror(errno)); } - return (result); + return (0); } diff --git a/src/lib/dhcp/tests/iface_mgr_unittest.cc b/src/lib/dhcp/tests/iface_mgr_unittest.cc index 6478e17349..09ad40630b 100644 --- a/src/lib/dhcp/tests/iface_mgr_unittest.cc +++ b/src/lib/dhcp/tests/iface_mgr_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2011-2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2011-2019 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 @@ -608,7 +608,9 @@ public: ); // OK, Send the PACKET! - EXPECT_NO_THROW(ifacemgr->send(sendPkt)); + bool result = false; + EXPECT_NO_THROW(result = ifacemgr->send(sendPkt)); + EXPECT_TRUE(result); // Now let's try and receive it. boost::shared_ptr rcvPkt; diff --git a/src/lib/dhcp/tests/pkt_filter_inet6_unittest.cc b/src/lib/dhcp/tests/pkt_filter_inet6_unittest.cc index 06878b7c19..77104dcaae 100644 --- a/src/lib/dhcp/tests/pkt_filter_inet6_unittest.cc +++ b/src/lib/dhcp/tests/pkt_filter_inet6_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2013-2019 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 @@ -66,7 +66,9 @@ TEST_F(PktFilterInet6Test, send) { ASSERT_GE(sock_info_.sockfd_, 0); // Send the packet over the socket. - ASSERT_NO_THROW(pkt_filter.send(iface, sock_info_.sockfd_, test_message_)); + int result = -1; + ASSERT_NO_THROW(result = pkt_filter.send(iface, sock_info_.sockfd_, test_message_)); + ASSERT_EQ(0, result); // Read the data from socket. fd_set readfds; @@ -76,7 +78,7 @@ TEST_F(PktFilterInet6Test, send) { struct timeval timeout; timeout.tv_sec = 5; timeout.tv_usec = 0; - int result = select(sock_info_.sockfd_ + 1, &readfds, NULL, NULL, &timeout); + result = select(sock_info_.sockfd_ + 1, &readfds, NULL, NULL, &timeout); // We should receive some data from loopback interface. ASSERT_GT(result, 0); diff --git a/src/lib/dhcp/tests/pkt_filter_inet_unittest.cc b/src/lib/dhcp/tests/pkt_filter_inet_unittest.cc index ec8c41b795..a8d495ca8e 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-2016 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2015-2019 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 @@ -80,7 +80,9 @@ TEST_F(PktFilterInetTest, send) { ASSERT_GE(sock_info_.sockfd_, 0); // Send the packet over the socket. - ASSERT_NO_THROW(pkt_filter.send(iface, sock_info_.sockfd_, test_message_)); + int result = -1; + ASSERT_NO_THROW(result = pkt_filter.send(iface, sock_info_.sockfd_, test_message_)); + ASSERT_EQ(0, result); // Read the data from socket. fd_set readfds; @@ -90,7 +92,7 @@ TEST_F(PktFilterInetTest, send) { struct timeval timeout; timeout.tv_sec = 5; timeout.tv_usec = 0; - int result = select(sock_info_.sockfd_ + 1, &readfds, NULL, NULL, &timeout); + result = select(sock_info_.sockfd_ + 1, &readfds, NULL, NULL, &timeout); // We should receive some data from loopback interface. ASSERT_GT(result, 0);