From patchwork Mon Dec 12 12:48:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Alin_N=C4=83stac?= X-Patchwork-Id: 1714958 X-Patchwork-Delegate: hauke@hauke-m.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=2G6l4KSZ; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=f6gUsc6h; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NW1hQ0HH2z23yh for ; Mon, 12 Dec 2022 23:51:02 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=1dKlg1StBUvdf4m1Ek3l3o9AgpNOb0RX1ODzFNE1XsA=; b=2G6l4KSZNB3Pkj /UKDb6q6DJoHCgZEF7BqsJVoz9jZAG+P6bqy5ocLkOSez6yfb7KkJdjbJVQCj0MvFkjxdJFskLR77 7zsmC1JgcxbBPzy4T33K+A7P92mSS3PNYzpaOK9yoXV9HCMNcrKKfUpLCwLA5R2j1+bdLrcE90MDG hg8mc/IevQRs+Pq+drYervgNac1Xa0/kF8tGapV8r8WMdcaVtx2Mxm7VUF4F9WTWCwyGO3RDGqLP8 p9y48Y/K2xVYBVrUjczgO+Py9jn0zWF+qSoH6X23LJqi1bro578cWApizsXnA4+S3MHuRDfaBcHsk siLdlWRtqpwqhEM7CRNw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p4iEo-00FrA6-3j; Mon, 12 Dec 2022 12:48:54 +0000 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p4iEl-00Fr5p-5j for openwrt-devel@lists.openwrt.org; Mon, 12 Dec 2022 12:48:52 +0000 Received: by mail-wm1-x336.google.com with SMTP id bg10so5197736wmb.1 for ; Mon, 12 Dec 2022 04:48:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=lZrNxJGlqgUaDHQnK9I/BRLtj0BszRwKKYm+V7aoHac=; b=f6gUsc6hd9cTpjAVNf5iTu1b14Jq5BhdyHa1RVkGfsO2LCCYAvyHM5JTcvsBY8a5xU vo2nyBKYHVYNrpT4g8Wm16n3iaCeZuHEbQehrcEHVU+k7ZOAJt4uI36wlPlxgln+rVeW ja7MjF/51//2cySJCLk0ThZcIP7+lnN5x75UBxoK7lVVID0/aLzO+dexgbpoqErjjYg4 9zAIsIVKG7u7wfxPBRQlq0HnbYlY0G7qYs7MIjdfk/hXNW83/VEypuiI1qGNPjCjRw3m 6UBakk/nvlOVE1//m7Ye2wopNCXlVv8UsRnhlV6hLbxi6rKJAvCSaCmqoayGFM10ivlg jfcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lZrNxJGlqgUaDHQnK9I/BRLtj0BszRwKKYm+V7aoHac=; b=5BtvB3wUp7D0tPNejlbmcyz8N5DqwLu6HOzGj7QzHQwAok0B+/NOEYbfoj0Yila747 BzJABmwOe2k+T/kw4sp9YJyDxCi1JoUy0Ofl/lfXlqC0ymdheDiyIftb3kqQw70tVVs5 40Zc/G85XwqEpUfGIU5DDAdHnyzEv2dxqBRql3Z79TN5CcQMuzJoSAe14q6bhRO27yXO j17a+OS2sCECqhT/TXyxr/lZloo6zpPn4xX5KzA5S8Skn44hVLfbBd0V0pQZwVCmCyNw J8pHXgoGNkaXt7+l9WPYKAzK0kpYoQae5XfSCyjGgkR69tzWvObvZb+QXlor4RflJ5Aa ukpA== X-Gm-Message-State: ANoB5pmsQ72P341D43sS6SG1Yam4JfD869ThmbOMFia+djiBVSaSqJdf rEjeO11GYZ4sxSSQDEsOzj8AzG0ExvbP9a26 X-Google-Smtp-Source: AA0mqf5aqbDPnE9Ofq1qr+RsSbE9TcXezXXnxDYT8u8ZDVwYG2YT51jfogKkFXbIQV9zFJMX5xw0GQ== X-Received: by 2002:a05:600c:5010:b0:3d0:71d1:7931 with SMTP id n16-20020a05600c501000b003d071d17931mr12913887wmr.8.1670849328834; Mon, 12 Dec 2022 04:48:48 -0800 (PST) Received: from cplx1037.edegem.eu.thmulti.com ([2001:4158:f012:e81:3125:c8a2:267d:a061]) by smtp.gmail.com with ESMTPSA id f9-20020a05600c154900b003d2157627a8sm9968971wmg.47.2022.12.12.04.48.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 04:48:48 -0800 (PST) From: Alin Nastac To: Felix Fietkau Cc: openwrt-devel@lists.openwrt.org Subject: [PATCH] vlandev: fix system_vlandev_add error triggered by multiple vlandev_set_up calls Date: Mon, 12 Dec 2022 13:48:39 +0100 Message-Id: <20221212124839.644384-1-alin.nastac@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221212_044851_236340_32932E7E X-CRM114-Status: GOOD ( 11.98 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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 wi [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:336 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [alin.nastac[at]gmail.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org 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 --- 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)