]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[lotest] Include sequence number within loopback test packets
authorMichael Brown <mcb30@ipxe.org>
Sun, 14 Jul 2013 09:37:17 +0000 (11:37 +0200)
committerMichael Brown <mcb30@ipxe.org>
Sun, 14 Jul 2013 09:40:11 +0000 (11:40 +0200)
Include a sequence number as the first four bytes of the loopback test
packet payload.  When a content mismatch occurs, this gives some
information about the source of the mismatched packet.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/usr/lotest.c

index c4b0b4413f9bd94a6daa398090802e08eafea6c0..905290a5e4aed750e89fa1e3a3efb8a8f6cdc2c0 100644 (file)
@@ -175,7 +175,8 @@ static int loopback_wait ( struct net_device *receiver, void *data,
  */
 int loopback_test ( struct net_device *sender, struct net_device *receiver,
                    size_t mtu ) {
-       uint8_t buf[mtu];
+       uint8_t *buf;
+       uint32_t *seq;
        struct io_buffer *iobuf;
        unsigned int i;
        unsigned int successes;
@@ -193,6 +194,14 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,
        if ( ( rc = iflinkwait ( receiver, LINK_WAIT_MS ) ) != 0 )
                return rc;
 
+       /* Allocate data buffer */
+       if ( mtu < sizeof ( *seq ) )
+               mtu = sizeof ( *seq );
+       buf = malloc ( mtu );
+       if ( ! buf )
+               return -ENOMEM;
+       seq = ( ( void * ) buf );
+
        /* Print initial statistics */
        printf ( "Performing loopback test from %s to %s with %zd byte MTU\n",
                 sender->name, receiver->name, mtu );
@@ -211,17 +220,17 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,
                printf ( "\r%d", successes );
 
                /* Generate random packet */
-               for ( i = 0 ; i < sizeof ( buf ) ; i++ )
+               *seq = htonl ( successes );
+               for ( i = sizeof ( *seq ) ; i < mtu ; i++ )
                        buf[i] = random();
-               iobuf = alloc_iob ( MAX_LL_HEADER_LEN + sizeof ( buf ) );
+               iobuf = alloc_iob ( MAX_LL_HEADER_LEN + mtu );
                if ( ! iobuf ) {
                        printf ( "\nFailed to allocate I/O buffer" );
                        rc = -ENOMEM;
                        break;
                }
                iob_reserve ( iobuf, MAX_LL_HEADER_LEN );
-               memcpy ( iob_put ( iobuf, sizeof ( buf ) ),
-                        buf, sizeof ( buf ) );
+               memcpy ( iob_put ( iobuf, mtu ), buf, mtu );
 
                /* Transmit packet */
                if ( ( rc = net_tx ( iob_disown ( iobuf ), sender,
@@ -233,10 +242,8 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,
                }
 
                /* Wait for received packet */
-               if ( ( rc = loopback_wait ( receiver, buf,
-                                           sizeof ( buf ) ) ) != 0 ) {
+               if ( ( rc = loopback_wait ( receiver, buf, mtu ) ) != 0 )
                        break;
-               }
        }
 
        printf ( "\n");
@@ -246,5 +253,8 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,
        ifstat ( sender );
        ifstat ( receiver );
 
+       /* Free buffer */
+       free ( buf );
+
        return 0;
 }