Commit b0414cf5 authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[2231] Added sanity check for microsecond timeout.

parent d8dd6f7c
......@@ -786,7 +786,11 @@ IfaceMgr::send(const Pkt4Ptr& pkt)
boost::shared_ptr<Pkt4>
IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec) {
// Sanity check for microsecond timeout.
if (timeout_usec >= 1000000) {
isc_throw(BadValue, "fractional timeout must be shorter than"
" one million microseconds");
}
const SocketInfo* candidate = 0;
IfaceCollection::const_iterator iface;
fd_set sockets;
......@@ -953,6 +957,11 @@ IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec) {
}
Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec) {
// Sanity check for microsecond timeout.
if (timeout_usec >= 1000000) {
isc_throw(BadValue, "fractional timeout must be shorter than"
" one million microseconds");
}
const SocketInfo* candidate = 0;
fd_set sockets;
......
......@@ -349,6 +349,7 @@ public:
/// @param timeout_usec specifies fractional part of the timeout
/// (in microseconds)
///
/// @throw isc::BadValue if timeout_usec is greater than one million
/// @return Pkt6 object representing received packet (or NULL)
Pkt6Ptr receive6(uint32_t timeout_sec, uint32_t timeout_usec = 0);
......@@ -362,6 +363,7 @@ public:
/// @param timeout_usec specifies fractional part of the timeout
/// (in microseconds)
///
/// @throw isc::BadValue if timeout_usec is greater than one million
/// @return Pkt4 object representing received packet (or NULL)
Pkt4Ptr receive4(uint32_t timeout_sec, uint32_t timeout_usec = 0);
......
......@@ -240,7 +240,8 @@ TEST_F(IfaceMgrTest, receiveTimeout6) {
// Remember when we call receive6().
gettimeofday(&start_time, NULL);
// Call receive with timeout of 1s + 1000us.
Pkt6Ptr pkt = ifacemgr->receive6(1, 1000);
Pkt6Ptr pkt;
ASSERT_NO_THROW(pkt = ifacemgr->receive6(1, 1000));
// Remember when call to receive6() ended.
gettimeofday(&stop_time, NULL);
// We did not send a packet to lo interface so we expect that
......@@ -256,7 +257,7 @@ TEST_F(IfaceMgrTest, receiveTimeout6) {
// Test timeout shorter than 1s.
gettimeofday(&start_time, NULL);
pkt = ifacemgr->receive6(0, 500);
ASSERT_NO_THROW(pkt = ifacemgr->receive6(0, 500));
gettimeofday(&stop_time, NULL);
ASSERT_FALSE(pkt);
stop_time.tv_sec -= start_time.tv_sec;
......@@ -268,6 +269,10 @@ TEST_F(IfaceMgrTest, receiveTimeout6) {
// should be investigated.
EXPECT_EQ(0, stop_time.tv_sec);
EXPECT_GT(stop_time.tv_usec, 500);
// Test with invalid fractional timeout values.
EXPECT_THROW(ifacemgr->receive6(0, 1000000), isc::BadValue);
EXPECT_THROW(ifacemgr->receive6(1, 1000010), isc::BadValue);
}
TEST_F(IfaceMgrTest, receiveTimeout4) {
......@@ -293,7 +298,8 @@ TEST_F(IfaceMgrTest, receiveTimeout4) {
// Remember when we call receive4().
gettimeofday(&start_time, NULL);
// Call receive with timeout of 2s + 150us.
Pkt4Ptr pkt = ifacemgr->receive4(2, 150);
Pkt4Ptr pkt;
ASSERT_NO_THROW(pkt = ifacemgr->receive4(2, 150));
// Remember when call to receive4() ended.
gettimeofday(&stop_time, NULL);
// We did not send a packet to lo interface so we expect that
......@@ -309,7 +315,7 @@ TEST_F(IfaceMgrTest, receiveTimeout4) {
// Test timeout shorter than 1s.
gettimeofday(&start_time, NULL);
pkt = ifacemgr->receive4(0, 350);
ASSERT_NO_THROW(pkt = ifacemgr->receive4(0, 350));
gettimeofday(&stop_time, NULL);
ASSERT_FALSE(pkt);
stop_time.tv_sec -= start_time.tv_sec;
......@@ -321,6 +327,10 @@ TEST_F(IfaceMgrTest, receiveTimeout4) {
// should be investigated.
EXPECT_EQ(0, stop_time.tv_sec);
EXPECT_GT(stop_time.tv_usec, 350);
// Test with invalid fractional timeout values.
EXPECT_THROW(ifacemgr->receive6(0, 1000000), isc::BadValue);
EXPECT_THROW(ifacemgr->receive6(2, 1000005), isc::BadValue);
}
TEST_F(IfaceMgrTest, sockets6) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment