|
@@ -175,7 +175,8 @@ static int loopback_wait ( struct net_device *receiver, void *data,
|
175
|
175
|
*/
|
176
|
176
|
int loopback_test ( struct net_device *sender, struct net_device *receiver,
|
177
|
177
|
size_t mtu ) {
|
178
|
|
- uint8_t buf[mtu];
|
|
178
|
+ uint8_t *buf;
|
|
179
|
+ uint32_t *seq;
|
179
|
180
|
struct io_buffer *iobuf;
|
180
|
181
|
unsigned int i;
|
181
|
182
|
unsigned int successes;
|
|
@@ -193,6 +194,14 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,
|
193
|
194
|
if ( ( rc = iflinkwait ( receiver, LINK_WAIT_MS ) ) != 0 )
|
194
|
195
|
return rc;
|
195
|
196
|
|
|
197
|
+ /* Allocate data buffer */
|
|
198
|
+ if ( mtu < sizeof ( *seq ) )
|
|
199
|
+ mtu = sizeof ( *seq );
|
|
200
|
+ buf = malloc ( mtu );
|
|
201
|
+ if ( ! buf )
|
|
202
|
+ return -ENOMEM;
|
|
203
|
+ seq = ( ( void * ) buf );
|
|
204
|
+
|
196
|
205
|
/* Print initial statistics */
|
197
|
206
|
printf ( "Performing loopback test from %s to %s with %zd byte MTU\n",
|
198
|
207
|
sender->name, receiver->name, mtu );
|
|
@@ -211,17 +220,17 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,
|
211
|
220
|
printf ( "\r%d", successes );
|
212
|
221
|
|
213
|
222
|
/* Generate random packet */
|
214
|
|
- for ( i = 0 ; i < sizeof ( buf ) ; i++ )
|
|
223
|
+ *seq = htonl ( successes );
|
|
224
|
+ for ( i = sizeof ( *seq ) ; i < mtu ; i++ )
|
215
|
225
|
buf[i] = random();
|
216
|
|
- iobuf = alloc_iob ( MAX_LL_HEADER_LEN + sizeof ( buf ) );
|
|
226
|
+ iobuf = alloc_iob ( MAX_LL_HEADER_LEN + mtu );
|
217
|
227
|
if ( ! iobuf ) {
|
218
|
228
|
printf ( "\nFailed to allocate I/O buffer" );
|
219
|
229
|
rc = -ENOMEM;
|
220
|
230
|
break;
|
221
|
231
|
}
|
222
|
232
|
iob_reserve ( iobuf, MAX_LL_HEADER_LEN );
|
223
|
|
- memcpy ( iob_put ( iobuf, sizeof ( buf ) ),
|
224
|
|
- buf, sizeof ( buf ) );
|
|
233
|
+ memcpy ( iob_put ( iobuf, mtu ), buf, mtu );
|
225
|
234
|
|
226
|
235
|
/* Transmit packet */
|
227
|
236
|
if ( ( rc = net_tx ( iob_disown ( iobuf ), sender,
|
|
@@ -233,10 +242,8 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,
|
233
|
242
|
}
|
234
|
243
|
|
235
|
244
|
/* Wait for received packet */
|
236
|
|
- if ( ( rc = loopback_wait ( receiver, buf,
|
237
|
|
- sizeof ( buf ) ) ) != 0 ) {
|
|
245
|
+ if ( ( rc = loopback_wait ( receiver, buf, mtu ) ) != 0 )
|
238
|
246
|
break;
|
239
|
|
- }
|
240
|
247
|
}
|
241
|
248
|
|
242
|
249
|
printf ( "\n");
|
|
@@ -246,5 +253,8 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,
|
246
|
253
|
ifstat ( sender );
|
247
|
254
|
ifstat ( receiver );
|
248
|
255
|
|
|
256
|
+ /* Free buffer */
|
|
257
|
+ free ( buf );
|
|
258
|
+
|
249
|
259
|
return 0;
|
250
|
260
|
}
|