From patchwork Wed Apr 7 20:14:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12189275 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9414C433B4 for ; Wed, 7 Apr 2021 20:15:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6A90A611C9 for ; Wed, 7 Apr 2021 20:15:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356033AbhDGUPj (ORCPT ); Wed, 7 Apr 2021 16:15:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356007AbhDGUPU (ORCPT ); Wed, 7 Apr 2021 16:15:20 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A6B5C061764 for ; Wed, 7 Apr 2021 13:15:09 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id r9so7213177ejj.3 for ; Wed, 07 Apr 2021 13:15:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=au+A1lvEoXA2bUIVl7MRId97EuktINPHfrNJIRdysmE=; b=M3PzpoDQ9W48GX7CoTdCc0UYGdD0Sf/5O/Abc6SZmRQTCOuXuVitrEKf55kjwKn7bl VZRSUQ2nH/E8AaPiR5RKNtU1ckFeq+QDObigOh/Ayy9ukTnIeX5X1DDmH7oj/w7RmzAJ a8TFrKh/rFFrdJss0uNIw6ZvbmiTSRsBXcpq9yGj4ywxXXx8ybmDERlADEA1bKtYx8Qi 5A1DZ/oV/1S0v2xM+rICL6xAWffS0lmibKnorA12leAq3G8TFE8qLa/OY7g5c0m1mgcC EcCh/Mnfar/fAZ2j6iEC72WyePMLvva1kCMkUSEjWjNSjhUwZBssx+wIgpRBro8x1zTs FbGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=au+A1lvEoXA2bUIVl7MRId97EuktINPHfrNJIRdysmE=; b=CDNmn7vGBEnG9hWAReNBG5pbMMjoFmmB4A+Nrzw0utHaPp+dtRtUqNDxtKYY+lrSXT ITDIciCNBqCmWPiH4zXHaparnQtZ+cgarPk2lgrh1lpAmfriKe14clIM4aobD4rDm5QY mrVILNoj61PsfFL6AA98HqU7hPNcK30b55/DLA9tFUT7WPlQq5f6QCn86LsMHmxCS9nw s5qefezmNUHwy9Qass3O2HxZSjSyuzsTkOWAucc55hHXdHFOc6bb01h3mNsilDj+O1ud Y+aL8II1BZCtsYzeW1b8FsvZFQ78KBxwMjO+k7vDNtsReAOAmyvMYl9nzVE4KuiMLnnD MFCQ== X-Gm-Message-State: AOAM532GZOzQNTOKmp+TOlSOSgrDPOgCTXvfYDKhSQw3hwRdCsT09UI7 odWnKfs+abxV9AqcrpdzjZ8= X-Google-Smtp-Source: ABdhPJyd8zq6zO9vTgLyBeFoBALzOFZYgSUX0fMF5B6s/BNY8l3t+GTWpzlHBfgWX44YerUIDnnPmg== X-Received: by 2002:a17:906:4b0e:: with SMTP id y14mr5699361eju.393.1617826507822; Wed, 07 Apr 2021 13:15:07 -0700 (PDT) Received: from localhost.localdomain (5-12-16-165.residential.rdsnet.ro. [5.12.16.165]) by smtp.gmail.com with ESMTPSA id r26sm4982892edc.43.2021.04.07.13.15.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Apr 2021 13:15:07 -0700 (PDT) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski , netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean Subject: [PATCH net 3/3] net: dsa: sja1105: update existing VLANs from the bridge VLAN list Date: Wed, 7 Apr 2021 23:14:52 +0300 Message-Id: <20210407201452.1703261-4-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210407201452.1703261-1-olteanv@gmail.com> References: <20210407201452.1703261-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean When running this sequence of operations: ip link add br0 type bridge vlan_filtering 1 ip link set swp4 master br0 bridge vlan add dev swp4 vid 1 We observe the traffic sent on swp4 is still untagged, even though the bridge has overwritten the existing VLAN entry: port vlan ids swp4 1 PVID br0 1 PVID Egress Untagged This happens because we didn't consider that the 'bridge vlan add' command just overwrites VLANs like it's nothing. We treat the 'vid 1 pvid untagged' and the 'vid 1' as two separate VLANs, and the first still has precedence when calling sja1105_build_vlan_table. Obviously there is a disagreement regarding semantics, and we end up doing something unexpected from the PoV of the bridge. Let's actually consider an "existing VLAN" to be one which is on the same port, and has the same VLAN ID, as one we already have, and update it if it has different flags than we do. The first blamed commit is the one introducing the bug, the second one is the latest on top of which the bugfix still applies. Fixes: ec5ae61076d0 ("net: dsa: sja1105: save/restore VLANs using a delta commit method") Fixes: 5899ee367ab3 ("net: dsa: tag_8021q: add a context structure") Signed-off-by: Vladimir Oltean --- drivers/net/dsa/sja1105/sja1105_main.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index 61133098f588..5e40ee14030a 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -2829,11 +2829,22 @@ static int sja1105_vlan_add_one(struct dsa_switch *ds, int port, u16 vid, bool pvid = flags & BRIDGE_VLAN_INFO_PVID; struct sja1105_bridge_vlan *v; - list_for_each_entry(v, vlan_list, list) - if (v->port == port && v->vid == vid && - v->untagged == untagged && v->pvid == pvid) + list_for_each_entry(v, vlan_list, list) { + if (v->port == port && v->vid == vid) { /* Already added */ - return 0; + if (v->untagged == untagged && v->pvid == pvid) + /* Nothing changed */ + return 0; + + /* It's the same VLAN, but some of the flags changed + * and the user did not bother to delete it first. + * Update it and trigger sja1105_build_vlan_table. + */ + v->untagged = untagged; + v->pvid = pvid; + return 1; + } + } v = kzalloc(sizeof(*v), GFP_KERNEL); if (!v) {