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

Alin Nastac alin.nastac at gmail.com
Mon Dec 12 04:57:38 PST 2022


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 at gmail.com>
---
 vlandev.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

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)
-- 
2.34.1




More information about the openwrt-devel mailing list