summaryrefslogtreecommitdiffstats
path: root/src/net/netdevice.c
diff options
context:
space:
mode:
authorMichael Brown2014-07-14 13:14:18 +0200
committerMichael Brown2014-07-14 13:17:19 +0200
commitc4af97727131a6675c67de4f2fc3f72e4dd4fc35 (patch)
tree25d937f57b3b4c143243d16af837a3f244005acb /src/net/netdevice.c
parent[crypto] Fix debug message (diff)
downloadipxe-c4af97727131a6675c67de4f2fc3f72e4dd4fc35.tar.gz
ipxe-c4af97727131a6675c67de4f2fc3f72e4dd4fc35.tar.xz
ipxe-c4af97727131a6675c67de4f2fc3f72e4dd4fc35.zip
[netdevice] Reset network device index when last device is unregistered
When functioning as an EFI driver, drivers can be disconnected and reconnected multiple times (e.g. via the EFI shell "connect" command, or by running an executable such as ipxe.efi which will temporarily disconnect existing drivers). Minimise surprise by resetting the network device index to zero whenever the last device is unregistered. This is not foolproof, but it does handle the common case of having all devices unregistered and then reregistered in the original order. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/net/netdevice.c')
-rw-r--r--src/net/netdevice.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/net/netdevice.c b/src/net/netdevice.c
index a05d6610..2350256f 100644
--- a/src/net/netdevice.c
+++ b/src/net/netdevice.c
@@ -50,6 +50,9 @@ struct list_head net_devices = LIST_HEAD_INIT ( net_devices );
/** List of open network devices, in reverse order of opening */
static struct list_head open_net_devices = LIST_HEAD_INIT ( open_net_devices );
+/** Network device index */
+static unsigned int netdev_index = 0;
+
/** Network polling profiler */
static struct profiler net_poll_profiler __profiler = { .name = "net.poll" };
@@ -597,14 +600,13 @@ struct net_device * alloc_netdev ( size_t priv_len ) {
* devices.
*/
int register_netdev ( struct net_device *netdev ) {
- static unsigned int ifindex = 0;
struct ll_protocol *ll_protocol = netdev->ll_protocol;
struct net_driver *driver;
uint32_t seed;
int rc;
/* Record device index and create device name */
- netdev->index = ifindex++;
+ netdev->index = netdev_index++;
if ( netdev->name[0] == '\0' ) {
snprintf ( netdev->name, sizeof ( netdev->name ), "net%d",
netdev->index );
@@ -764,6 +766,10 @@ void unregister_netdev ( struct net_device *netdev ) {
DBGC ( netdev, "NETDEV %s unregistered\n", netdev->name );
list_del ( &netdev->list );
netdev_put ( netdev );
+
+ /* Reset network device index if no devices remain */
+ if ( list_empty ( &net_devices ) )
+ netdev_index = 0;
}
/** Enable or disable interrupts