]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[417-incorrect-return-value-of-ifacemgr-send] Fixed interface manager and UDP socket... 417-incorrect-return-value-of-ifacemgr-send
authorFrancis Dupont <fdupont@isc.org>
Mon, 4 Feb 2019 16:12:51 +0000 (17:12 +0100)
committerFrancis Dupont <fdupont@isc.org>
Tue, 19 Feb 2019 10:47:25 +0000 (05:47 -0500)
src/lib/dhcp/iface_mgr.cc
src/lib/dhcp/pkt_filter_inet.cc
src/lib/dhcp/pkt_filter_inet6.cc
src/lib/dhcp/tests/iface_mgr_unittest.cc
src/lib/dhcp/tests/pkt_filter_inet6_unittest.cc
src/lib/dhcp/tests/pkt_filter_inet_unittest.cc

index ff90384beb3721bb1b43d374352e806fbb7b3ad8..a4dc8ad636aedef349986f8c2c061dff1d4a1390 100644 (file)
@@ -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 */) {
index 9953e8780c049d371326b43f57515de1fd585954..59c32e749ed7e181c14d9a9a4239357c6bafd200 100644 (file)
@@ -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);
 }
 
 
index eede050a711a43a6950d3e5ac8db728beb8ab5d0..939be3c819eea4fd00b46500e5f5288ef3b1e303 100644 (file)
@@ -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);
 }
 
 
index 6478e17349c7e55c84b7e38f90600fb1fd978748..09ad40630b6efdfb8c0ac72b64c1f16e78eb9db0 100644 (file)
@@ -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<Pkt4> rcvPkt;
index 06878b7c192ea9aef1073af9f09b455f2d687af0..77104dcaaed2657878872a4866b8aadb9785169c 100644 (file)
@@ -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);
 
index ec8c41b7952d405b1953b08b94b07cb1657de9cf..a8d495ca8eeffd3dc9cc2f81680f3e4daab60266 100644 (file)
@@ -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);