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
 struct lotest_options {
43
 struct lotest_options {
44
 	/** MTU */
44
 	/** MTU */
45
 	unsigned int mtu;
45
 	unsigned int mtu;
46
+	/** Broadcast */
47
+	int broadcast;
46
 };
48
 };
47
 
49
 
48
 /** "lotest" option list */
50
 /** "lotest" option list */
49
 static struct option_descriptor lotest_opts[] = {
51
 static struct option_descriptor lotest_opts[] = {
50
 	OPTION_DESC ( "mtu", 'm', required_argument,
52
 	OPTION_DESC ( "mtu", 'm', required_argument,
51
 		      struct lotest_options, mtu, parse_integer ),
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
 /** "lotest" command descriptor */
58
 /** "lotest" command descriptor */
86
 		opts.mtu = ETH_MAX_MTU;
90
 		opts.mtu = ETH_MAX_MTU;
87
 
91
 
88
 	/* Perform loopback test */
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
 		printf ( "Test failed: %s\n", strerror ( rc ) );
95
 		printf ( "Test failed: %s\n", strerror ( rc ) );
91
 		return rc;
96
 		return rc;
92
 	}
97
 	}

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

10
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
10
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
 
11
 
12
 extern int loopback_test ( struct net_device *sender,
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
 #endif /* _USR_LOTEST_H */
16
 #endif /* _USR_LOTEST_H */

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

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

Loading…
Cancel
Save