Browse Source

[netdevice] Mark devices as open before calling open() method

When opening a VLAN device, vlan_open() will call netdev_open() on the
trunk device.  This will result in a call to netdev_notify(), which
will cause vlan_notify() to call vlan_sync() on the original VLAN
device, which will see that the trunk device is now open but the VLAN
device apparently isn't (since it has not yet been flagged as open by
netdev_open()).  The upshot is a second attempt to open the VLAN
device, which will result in an erroneous second call to vlan_open().
This convoluted chain of events then terminates harmlessly since
vlan_open() calls netdev_open() on the trunk device, which just
returns immediately since the trunk device is by now flagged as being
already open.

Prevent this from happening by having netdev_open() flag the device as
open prior to calling the device's open() method, and reflagging it as
closed if the open() method fails.

Originally-fixed-by: Wissam Shoukair <wissams@mellanox.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 years ago
parent
commit
f17a30d547
1 changed files with 8 additions and 4 deletions
  1. 8
    4
      src/net/netdevice.c

+ 8
- 4
src/net/netdevice.c View File

636
 
636
 
637
 	DBGC ( netdev, "NETDEV %s opening\n", netdev->name );
637
 	DBGC ( netdev, "NETDEV %s opening\n", netdev->name );
638
 
638
 
639
-	/* Open the device */
640
-	if ( ( rc = netdev->op->open ( netdev ) ) != 0 )
641
-		return rc;
642
-
643
 	/* Mark as opened */
639
 	/* Mark as opened */
644
 	netdev->state |= NETDEV_OPEN;
640
 	netdev->state |= NETDEV_OPEN;
645
 
641
 
642
+	/* Open the device */
643
+	if ( ( rc = netdev->op->open ( netdev ) ) != 0 )
644
+		goto err;
645
+
646
 	/* Add to head of open devices list */
646
 	/* Add to head of open devices list */
647
 	list_add ( &netdev->open_list, &open_net_devices );
647
 	list_add ( &netdev->open_list, &open_net_devices );
648
 
648
 
650
 	netdev_notify ( netdev );
650
 	netdev_notify ( netdev );
651
 
651
 
652
 	return 0;
652
 	return 0;
653
+
654
+ err:
655
+	netdev->state &= ~NETDEV_OPEN;
656
+	return rc;
653
 }
657
 }
654
 
658
 
655
 /**
659
 /**

Loading…
Cancel
Save