|
@@ -45,6 +45,9 @@ static struct net_protocol net_protocols_end[0]
|
45
|
45
|
/** List of network devices */
|
46
|
46
|
struct list_head net_devices = LIST_HEAD_INIT ( net_devices );
|
47
|
47
|
|
|
48
|
+/** List of open network devices, in reverse order of opening */
|
|
49
|
+struct list_head open_net_devices = LIST_HEAD_INIT ( open_net_devices );
|
|
50
|
+
|
48
|
51
|
/**
|
49
|
52
|
* Record network device statistic
|
50
|
53
|
*
|
|
@@ -368,6 +371,10 @@ int netdev_open ( struct net_device *netdev ) {
|
368
|
371
|
|
369
|
372
|
/* Mark as opened */
|
370
|
373
|
netdev->state |= NETDEV_OPEN;
|
|
374
|
+
|
|
375
|
+ /* Add to head of open devices list */
|
|
376
|
+ list_add ( &netdev->open_list, &open_net_devices );
|
|
377
|
+
|
371
|
378
|
return 0;
|
372
|
379
|
}
|
373
|
380
|
|
|
@@ -393,6 +400,9 @@ void netdev_close ( struct net_device *netdev ) {
|
393
|
400
|
|
394
|
401
|
/* Mark as closed */
|
395
|
402
|
netdev->state &= ~NETDEV_OPEN;
|
|
403
|
+
|
|
404
|
+ /* Remove from open devices list */
|
|
405
|
+ list_del ( &netdev->open_list );
|
396
|
406
|
}
|
397
|
407
|
|
398
|
408
|
/**
|
|
@@ -462,6 +472,22 @@ struct net_device * find_netdev_by_location ( unsigned int bus_type,
|
462
|
472
|
return NULL;
|
463
|
473
|
}
|
464
|
474
|
|
|
475
|
+/**
|
|
476
|
+ * Get most recently opened network device
|
|
477
|
+ *
|
|
478
|
+ * @ret netdev Most recently opened network device, or NULL
|
|
479
|
+ */
|
|
480
|
+struct net_device * last_opened_netdev ( void ) {
|
|
481
|
+ struct net_device *netdev;
|
|
482
|
+
|
|
483
|
+ list_for_each_entry ( netdev, &open_net_devices, open_list ) {
|
|
484
|
+ assert ( netdev->state & NETDEV_OPEN );
|
|
485
|
+ return netdev;
|
|
486
|
+ }
|
|
487
|
+
|
|
488
|
+ return NULL;
|
|
489
|
+}
|
|
490
|
+
|
465
|
491
|
/**
|
466
|
492
|
* Transmit network-layer packet
|
467
|
493
|
*
|