From patchwork Wed Oct 28 07:42:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Kanzenbach X-Patchwork-Id: 316089 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=-8.8 required=3.0 tests=BAYES_00, DATE_IN_PAST_12_24, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable 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 DC0D9C55179 for ; Thu, 29 Oct 2020 02:01:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F01F20791 for ; Thu, 29 Oct 2020 02:01:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="AwXkRw7d"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3eGVq149" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729005AbgJ2CBm (ORCPT ); Wed, 28 Oct 2020 22:01:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727819AbgJ1Vt2 (ORCPT ); Wed, 28 Oct 2020 17:49:28 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70F72C0613D1; Wed, 28 Oct 2020 14:49:28 -0700 (PDT) From: Kurt Kanzenbach DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1603870981; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+V3E0mNbqmC+z3DHzjYNErh3LMSMmsuM3JkFFcoNFcM=; b=AwXkRw7dHxas8UvK7LuAsShNF6Ia9sFfyzkFXFoXcWcFXZoj9jREbAiRO4I6sNV1jNXElZ amRKPZZIt8CQed7Na0WuS+juxYmBaQ3dw8X7zRgU+WCWUYNil73BlZ/n452U+5DkdMbPMh V7d6dK6l7nRg/UZgFD59GPu/+Ry6v+nNa8URZPIVrfUxYSz3a7qnb4hAvcsRfGwhelw5DJ u+g9a/BX3ZtYSkC+hY8C/4/33MrB6IxvhA/NSd+Q3lXrOkyw6wNF/M1dKWk3DzF1YOqI0H JcKx0LimoFjxLnaewnwCSiMLDdQ8ViDClLGNao454sC1ySs3DQPKGJfnHr5OXw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1603870981; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+V3E0mNbqmC+z3DHzjYNErh3LMSMmsuM3JkFFcoNFcM=; b=3eGVq149Bb4Vs+VHIzhKhW/xY6OSWhRvBxdb8xhE49rgmpBBnyMP1r3IbA7oXxQk/X9yAa 0uWalw/44ON9MkCg== To: Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean Cc: "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org, Rob Herring , devicetree@vger.kernel.org, Sebastian Andrzej Siewior , Richard Cochran , Kamil Alkhouri , ilias.apalodimas@linaro.org, Vladimir Oltean , Kurt Kanzenbach Subject: [PATCH net-next v7 2/8] net: dsa: Give drivers the chance to veto certain upper devices Date: Wed, 28 Oct 2020 08:42:15 +0100 Message-Id: <20201028074221.29326-3-kurt@linutronix.de> In-Reply-To: <20201028074221.29326-1-kurt@linutronix.de> References: <20201028074221.29326-1-kurt@linutronix.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean Some switches rely on unique pvids to ensure port separation in standalone mode, because they don't have a port forwarding matrix configurable in hardware. So, setups like a group of 2 uppers with the same VLAN, swp0.100 and swp1.100, will cause traffic tagged with VLAN 100 to be autonomously forwarded between these switch ports, in spite of there being no bridge between swp0 and swp1. These drivers need to prevent this from happening. They need to have VLAN filtering enabled in standalone mode (so they'll drop frames tagged with unknown VLANs) and they can only accept an 8021q upper on a port as long as it isn't installed on any other port too. So give them the chance to veto bad user requests. Signed-off-by: Vladimir Oltean Signed-off-by: Kurt Kanzenbach Reviewed-by: Florian Fainelli --- include/net/dsa.h | 6 ++++++ net/dsa/slave.c | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/net/dsa.h b/include/net/dsa.h index 04e93bafb7bd..4e60d2610f20 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -536,6 +536,12 @@ struct dsa_switch_ops { void (*get_regs)(struct dsa_switch *ds, int port, struct ethtool_regs *regs, void *p); + /* + * Upper device tracking. + */ + int (*port_prechangeupper)(struct dsa_switch *ds, int port, + struct netdev_notifier_changeupper_info *info); + /* * Bridge integration */ diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 3bc5ca40c9fb..1919a025c06f 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -1987,10 +1987,22 @@ static int dsa_slave_netdevice_event(struct notifier_block *nb, switch (event) { case NETDEV_PRECHANGEUPPER: { struct netdev_notifier_changeupper_info *info = ptr; + struct dsa_switch *ds; + struct dsa_port *dp; + int err; if (!dsa_slave_dev_check(dev)) return dsa_prevent_bridging_8021q_upper(dev, ptr); + dp = dsa_slave_to_port(dev); + ds = dp->ds; + + if (ds->ops->port_prechangeupper) { + err = ds->ops->port_prechangeupper(ds, dp->index, ptr); + if (err) + return notifier_from_errno(err); + } + if (is_vlan_dev(info->upper_dev)) return dsa_slave_check_8021q_upper(dev, ptr); break;