diff mbox series

[netifd] vlandev: fix system_vlandev_add error triggered by multiple vlandev_set_up calls

Message ID 20221212125738.644468-1-alin.nastac@gmail.com
State New
Headers show
Series [netifd] vlandev: fix system_vlandev_add error triggered by multiple vlandev_set_up calls | expand

Commit Message

Alin Năstac Dec. 12, 2022, 12:57 p.m. UTC
vlan devices can be switched up more than once, in which case this error will
be traced:
  system_vlandev_add(1608): Error adding vlandev 'vlan_wan' over 'ptm0': -6
and interface that use this device will fail to start with error code
DEVICE_CLAIM_FAILED.

This change will prevent calling system_vlandev_add() when vlan device
was already created, thus solving the root cause of the issue.

Signed-off-by: Alin Nastac <alin.nastac@gmail.com>
---
 vlandev.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/vlandev.c b/vlandev.c
index 31b82b1..4780ca3 100644
--- a/vlandev.c
+++ b/vlandev.c
@@ -163,9 +163,14 @@  vlandev_set_up(struct vlandev_device *mvdev)
 	if (ret < 0)
 		return ret;
 
-	ret = system_vlandev_add(&mvdev->dev, mvdev->parent.dev, &mvdev->config);
-	if (ret < 0)
-		goto release;
+	if (mvdev->dev.ifindex && mvdev->dev.ifindex != system_if_resolve(&mvdev->dev))
+		mvdev->dev.ifindex = 0; /* previous instance of this vlan device was destroyed */
+
+	if (!mvdev->dev.ifindex) {
+		ret = system_vlandev_add(&mvdev->dev, mvdev->parent.dev, &mvdev->config);
+		if (ret < 0)
+			goto release;
+	}
 
 	ret = mvdev->set_state(&mvdev->dev, true);
 	if (ret)