Przeglądaj źródła

[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>
tags/v1.20.1
Michael Brown 10 lat temu
rodzic
commit
c4af977271
1 zmienionych plików z 8 dodań i 2 usunięć
  1. 8
    2
      src/net/netdevice.c

+ 8
- 2
src/net/netdevice.c Wyświetl plik

@@ -50,6 +50,9 @@ struct list_head net_devices = LIST_HEAD_INIT ( net_devices );
50 50
 /** List of open network devices, in reverse order of opening */
51 51
 static struct list_head open_net_devices = LIST_HEAD_INIT ( open_net_devices );
52 52
 
53
+/** Network device index */
54
+static unsigned int netdev_index = 0;
55
+
53 56
 /** Network polling profiler */
54 57
 static struct profiler net_poll_profiler __profiler = { .name = "net.poll" };
55 58
 
@@ -597,14 +600,13 @@ struct net_device * alloc_netdev ( size_t priv_len ) {
597 600
  * devices.
598 601
  */
599 602
 int register_netdev ( struct net_device *netdev ) {
600
-	static unsigned int ifindex = 0;
601 603
 	struct ll_protocol *ll_protocol = netdev->ll_protocol;
602 604
 	struct net_driver *driver;
603 605
 	uint32_t seed;
604 606
 	int rc;
605 607
 
606 608
 	/* Record device index and create device name */
607
-	netdev->index = ifindex++;
609
+	netdev->index = netdev_index++;
608 610
 	if ( netdev->name[0] == '\0' ) {
609 611
 		snprintf ( netdev->name, sizeof ( netdev->name ), "net%d",
610 612
 			   netdev->index );
@@ -764,6 +766,10 @@ void unregister_netdev ( struct net_device *netdev ) {
764 766
 	DBGC ( netdev, "NETDEV %s unregistered\n", netdev->name );
765 767
 	list_del ( &netdev->list );
766 768
 	netdev_put ( netdev );
769
+
770
+	/* Reset network device index if no devices remain */
771
+	if ( list_empty ( &net_devices ) )
772
+		netdev_index = 0;
767 773
 }
768 774
 
769 775
 /** Enable or disable interrupts

Ładowanie…
Anuluj
Zapisz