Hello all,

I have submitted the attached patch via Sourceforge, however the problem detailed below existed at least as far back as Iperf v2.0.2, so it may also be of interest to anyone not using the latest release.

The problem occurs when the total number of bytes to transmit has been specified for the Iperf client (using command line flag -n), but this number is not a multiple of the write buffer size (optionally specified with flag -l).

The total size to send is stored in the thread_Settings field mAmount, which is decremented by the size written on each transmission. The client send loop terminates when mAmount <= 0, however mAmount is declared as type max_size_t which now evaluates to an unsigned integer type (uint64_t). When mAmount is not a multiple of the the write buffer size mBufLen, mAmount will underflow and wrap around, causing the client to transmit more data than desired.

An example that will cause the undesirable behavior:
   iperf -c localhost -u -n 2048 -l 1470

The expected behavior in this example is that the client exits after sending two data buffers. The observed behavior is that the client continues transmitting without bound.

This problem exists with both TCP and UDP clients.

Note that the attached patch only ensures that the client loop terminates after the desired number of buffers have been sent. It does not ensure that the final buffer written will be of a smaller size to exactly match the total size specified via the -n flag. In other words, the example above will yield two buffers of size 1470 instead of one buffer of 1470 bytes and a second of 578 bytes. For UDP traffic, however, this point is moot as the function write_UDP_FIN() will write another ten buffers anyway.


thanks,
nathan
--
Nathan Jones
MIT Lincoln Laboratory

diff -ru iperf-2.0.4-rev41/src/Client.cpp iperf/src/Client.cpp
--- iperf-2.0.4-rev41/src/Client.cpp    2008-04-10 12:13:11.000000000 -0400
+++ iperf/src/Client.cpp        2008-04-15 15:40:03.000000000 -0400
@@ -170,7 +170,12 @@
         }      
 
         if ( !mMode_Time ) {
-            mSettings->mAmount -= currLen;
+            /* mAmount may be unsigned, so don't let it underflow! */
+            if( mSettings->mAmount >= currLen ) {
+                mSettings->mAmount -= currLen;
+            } else {
+                mSettings->mAmount = 0;
+            }
         }
 
     } while ( ! (sInterupted  || 
@@ -310,7 +315,12 @@
             delay_loop( delay ); 
         }
         if ( !mMode_Time ) {
-            mSettings->mAmount -= currLen;
+            /* mAmount may be unsigned, so don't let it underflow! */
+            if( mSettings->mAmount >= currLen ) {
+                mSettings->mAmount -= currLen;
+            } else {
+                mSettings->mAmount = 0;
+            }
         }
 
     } while ( ! (sInterupted  || 
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Iperf-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/iperf-users

Reply via email to