Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[lotest] Add option to use broadcast packets for loopback testing
Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed May 23, 2016
1 parent 231adda commit 80dd6cb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/hci/commands/lotest_cmd.c
Expand Up @@ -43,12 +43,16 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
struct lotest_options {
/** MTU */
unsigned int mtu;
/** Broadcast */
int broadcast;
};

/** "lotest" option list */
static struct option_descriptor lotest_opts[] = {
OPTION_DESC ( "mtu", 'm', required_argument,
struct lotest_options, mtu, parse_integer ),
OPTION_DESC ( "broadcast", 'b', no_argument,
struct lotest_options, broadcast, parse_flag ),
};

/** "lotest" command descriptor */
Expand Down Expand Up @@ -86,7 +90,8 @@ static int lotest_exec ( int argc, char **argv ) {
opts.mtu = ETH_MAX_MTU;

/* Perform loopback test */
if ( ( rc = loopback_test ( sender, receiver, opts.mtu ) ) != 0 ) {
if ( ( rc = loopback_test ( sender, receiver, opts.mtu,
opts.broadcast ) ) != 0 ) {
printf ( "Test failed: %s\n", strerror ( rc ) );
return rc;
}
Expand Down
3 changes: 2 additions & 1 deletion src/include/usr/lotest.h
Expand Up @@ -10,6 +10,7 @@
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );

extern int loopback_test ( struct net_device *sender,
struct net_device *receiver, size_t mtu );
struct net_device *receiver,
size_t mtu, int broadcast );

#endif /* _USR_LOTEST_H */
14 changes: 10 additions & 4 deletions src/usr/lotest.c
Expand Up @@ -188,13 +188,15 @@ static int loopback_wait ( void *data, size_t len ) {
* @v sender Sending network device
* @v receiver Received network device
* @v mtu Packet size (excluding link-layer headers)
* @v broadcast Use broadcast link-layer address
* @ret rc Return status code
*/
int loopback_test ( struct net_device *sender, struct net_device *receiver,
size_t mtu ) {
size_t mtu, int broadcast ) {
uint8_t *buf;
uint32_t *seq;
struct io_buffer *iobuf;
const void *ll_dest;
unsigned int i;
unsigned int successes;
int rc;
Expand All @@ -219,9 +221,13 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,
return -ENOMEM;
seq = ( ( void * ) buf );

/* Determine destination address */
ll_dest = ( broadcast ? sender->ll_broadcast : receiver->ll_addr );

/* Print initial statistics */
printf ( "Performing loopback test from %s to %s with %zd byte MTU\n",
sender->name, receiver->name, mtu );
printf ( "Performing %sloopback test from %s to %s with %zd byte MTU\n",
( broadcast ? "broadcast " : "" ), sender->name,
receiver->name, mtu );
ifstat ( sender );
ifstat ( receiver );

Expand Down Expand Up @@ -250,7 +256,7 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,

/* Transmit packet */
if ( ( rc = net_tx ( iob_disown ( iobuf ), sender,
&lotest_protocol, receiver->ll_addr,
&lotest_protocol, ll_dest,
sender->ll_addr ) ) != 0 ) {
printf ( "\nFailed to transmit packet: %s",
strerror ( rc ) );
Expand Down

0 comments on commit 80dd6cb

Please sign in to comment.