Browse Source

[lotest] Add option to use broadcast packets for loopback testing

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 years ago
parent
commit
80dd6cbcc4
3 changed files with 18 additions and 6 deletions
  1. 6
    1
      src/hci/commands/lotest_cmd.c
  2. 2
    1
      src/include/usr/lotest.h
  3. 10
    4
      src/usr/lotest.c

+ 6
- 1
src/hci/commands/lotest_cmd.c View File

@@ -43,12 +43,16 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
43 43
 struct lotest_options {
44 44
 	/** MTU */
45 45
 	unsigned int mtu;
46
+	/** Broadcast */
47
+	int broadcast;
46 48
 };
47 49
 
48 50
 /** "lotest" option list */
49 51
 static struct option_descriptor lotest_opts[] = {
50 52
 	OPTION_DESC ( "mtu", 'm', required_argument,
51 53
 		      struct lotest_options, mtu, parse_integer ),
54
+	OPTION_DESC ( "broadcast", 'b', no_argument,
55
+		      struct lotest_options, broadcast, parse_flag ),
52 56
 };
53 57
 
54 58
 /** "lotest" command descriptor */
@@ -86,7 +90,8 @@ static int lotest_exec ( int argc, char **argv ) {
86 90
 		opts.mtu = ETH_MAX_MTU;
87 91
 
88 92
 	/* Perform loopback test */
89
-	if ( ( rc = loopback_test ( sender, receiver, opts.mtu ) ) != 0 ) {
93
+	if ( ( rc = loopback_test ( sender, receiver, opts.mtu,
94
+				    opts.broadcast ) ) != 0 ) {
90 95
 		printf ( "Test failed: %s\n", strerror ( rc ) );
91 96
 		return rc;
92 97
 	}

+ 2
- 1
src/include/usr/lotest.h View File

@@ -10,6 +10,7 @@
10 10
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 11
 
12 12
 extern int loopback_test ( struct net_device *sender,
13
-			   struct net_device *receiver, size_t mtu );
13
+			   struct net_device *receiver,
14
+			   size_t mtu, int broadcast );
14 15
 
15 16
 #endif /* _USR_LOTEST_H */

+ 10
- 4
src/usr/lotest.c View File

@@ -188,13 +188,15 @@ static int loopback_wait ( void *data, size_t len ) {
188 188
  * @v sender		Sending network device
189 189
  * @v receiver		Received network device
190 190
  * @v mtu		Packet size (excluding link-layer headers)
191
+ * @v broadcast		Use broadcast link-layer address
191 192
  * @ret rc		Return status code
192 193
  */
193 194
 int loopback_test ( struct net_device *sender, struct net_device *receiver,
194
-		    size_t mtu ) {
195
+		    size_t mtu, int broadcast ) {
195 196
 	uint8_t *buf;
196 197
 	uint32_t *seq;
197 198
 	struct io_buffer *iobuf;
199
+	const void *ll_dest;
198 200
 	unsigned int i;
199 201
 	unsigned int successes;
200 202
 	int rc;
@@ -219,9 +221,13 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,
219 221
 		return -ENOMEM;
220 222
 	seq = ( ( void * ) buf );
221 223
 
224
+	/* Determine destination address */
225
+	ll_dest = ( broadcast ? sender->ll_broadcast : receiver->ll_addr );
226
+
222 227
 	/* Print initial statistics */
223
-	printf ( "Performing loopback test from %s to %s with %zd byte MTU\n",
224
-		 sender->name, receiver->name, mtu );
228
+	printf ( "Performing %sloopback test from %s to %s with %zd byte MTU\n",
229
+		 ( broadcast ? "broadcast " : "" ), sender->name,
230
+		 receiver->name, mtu );
225 231
 	ifstat ( sender );
226 232
 	ifstat ( receiver );
227 233
 
@@ -250,7 +256,7 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,
250 256
 
251 257
 		/* Transmit packet */
252 258
 		if ( ( rc = net_tx ( iob_disown ( iobuf ), sender,
253
-				     &lotest_protocol, receiver->ll_addr,
259
+				     &lotest_protocol, ll_dest,
254 260
 				     sender->ll_addr ) ) != 0 ) {
255 261
 			printf ( "\nFailed to transmit packet: %s",
256 262
 				 strerror ( rc ) );

Loading…
Cancel
Save