Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17450624rwd; Tue, 27 Jun 2023 03:15:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ61hOcix0qLRtCB8aKPdszU9IHJf52t1FhxXhEgHzIwoQvQ/UUpib7lCSqZj3IXOSF2lasX X-Received: by 2002:a05:6a00:a86:b0:657:f26e:b01a with SMTP id b6-20020a056a000a8600b00657f26eb01amr19324473pfl.26.1687860929368; Tue, 27 Jun 2023 03:15:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687860929; cv=pass; d=google.com; s=arc-20160816; b=dJuTfEXXVZ7OthTNUGvbt2u5xthTxEenpW0h0ygxGI/Ag7vGGqfMC4sRPt1bkSr2+n /cKPdjxVamCzADs777mo7vDSLY1QZL0VPRyY5rOi/1xnLzZBwUH/iXu+SRwBqF/JicGP rp/1dvAXZ3h+tMfouzDGdknhyACh+xBlCY3ZDPTq1iSRZA2SIXaJHUIY4xoIFNHcVm7r GDuZ7g+O6wOO9pUuz9c8DTLgNDdul5yLqALT9us+LQtdIMnde3RsE2h+diGZqOinQ5/X oEaFuVDKSNbAAB6p7afUcQu0joEQwZ/8bzAeLS2eKNexQYxQ7fu6ekUm5WBQqFI48dP4 tuVw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3UYcsHQ8GOaQvypkoK7QQ/YEx7HJ50SjmS8VhAeC/Po=; fh=9p/1aqzINVh8DO/zPcykqNKgLrhLVZ/UEQZMM3tSbYQ=; b=NNEqsL/PDgLiMZB8J+z12/sPoYq7Cnr29oXvRPyTaSyhDpnsgr8etnSvGiP3ThAYfP L3zyySCVMqj3HNBFUl1W3C3HEc34D3k5kMcwGmN4QOWimVyufsbIfbxTr5A6AwRM1qpo Mw8ZmWF8GdOlgDa74iZ0k5NHKBVZTbXyWFCUdAGTZ9gKVxiNOFG0If/3+faAGGLcA12o +oei0BJBM5ch1dJ/i+klYxlON+iayi5ocncmAE6Fhs/04OqT5gGOLkPhSfyvxk3+8j7n +gmMlDsQDEtBLZiwWHx9OKyS1x+/ijDf8DVBi6Ialw2r8zLwuWFJPNYgGGdEpuDJd497 88YA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=X8vic6M5; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 125-20020a630083000000b0055acc7f805bsi5044961pga.334.2023.06.27.03.15.17; Tue, 27 Jun 2023 03:15:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=X8vic6M5; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231305AbjF0Jmj (ORCPT + 99 others); Tue, 27 Jun 2023 05:42:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230109AbjF0Jm1 (ORCPT ); Tue, 27 Jun 2023 05:42:27 -0400 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2040.outbound.protection.outlook.com [40.107.7.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 801B3E54; Tue, 27 Jun 2023 02:42:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nqKVtGnuyg/2fgvViUiTCW9JS2HjrCzHIVdyYfC8ORAHPSbF4fDAsPZgREEsl7JpHAPnEsQz1AWs5OUVyUDyYhFu3yfdFGL+JckKVOJDfAEW8G/hcuEdXorZtSEzXR0aHEBye0b0I5YMsEORvzLPANmU3rVRFJW7AN/gbDASfMt06hXHD7PZfMB6AKcr2nRbXe7nR/mQlH+TJZ5wkh/eeF2kwa5qBc0Z+MxPgXxanA12iM3KKWRWfCB4LhlpbCDX0QOBLboIqK81CIW1tkqBUS8CwOGoPvA0KmJcJPFBOqU0OO2+aVGiCwPM60F+CIUjiNIiFw89ze/r8hSoC1E9qQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3UYcsHQ8GOaQvypkoK7QQ/YEx7HJ50SjmS8VhAeC/Po=; b=El3cKjGqHPE9cL24yc28RipCMGcdz9l4emus2yZmmOdvNznGrxKzW5LtTY+VJkxtf0W+KxpCi5TvTqNikCL3A8JFfjtD2wCTji0JIOfZz/+YprxWv+ZLEcTRptrmHNuFZ5awaRby6OFWqYdOqEY2B3UWCb4TbZxWh8kt3SbN+WQ4FVU4ZcfwjKYlQccqTLippQPYQnSwTelNyfvyC33iEIxYNIwHiQr8GEE86RX9Yv24U8XaCZgVUtZmrG/vL4jn6+RunvECTwa1WTr/VU41YSnLQ1iYQ+iKSijzs8EajIGFYqn20++OtMKpkv9P2U8xkX19nz6+nCWMWnpg2Ew6MQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3UYcsHQ8GOaQvypkoK7QQ/YEx7HJ50SjmS8VhAeC/Po=; b=X8vic6M5ROg1b72cwaCgqCg+R/r5buWCWr8NU8B+kaMwzZc1ySHPbHSBNh7iPY7IXqpucYbPs8GTEMuRwlidc+rxGRjCW1peUFFHrAmB1FRFZKipOXTCM/PykHgVx1bMeGAhjAHMOuWpTQ2Pg84x2Ndm0Dk0aqptPF7cESlWcdE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by AM9PR04MB8649.eurprd04.prod.outlook.com (2603:10a6:20b:43c::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26; Tue, 27 Jun 2023 09:42:20 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c40e:d76:fd88:f460]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c40e:d76:fd88:f460%5]) with mapi id 15.20.6521.026; Tue, 27 Jun 2023 09:42:20 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org Subject: [PATCH v2 net 2/2] net: dsa: tag_sja1105: always prefer source port information from INCL_SRCPT Date: Tue, 27 Jun 2023 12:42:07 +0300 Message-Id: <20230627094207.3385231-3-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230627094207.3385231-1-vladimir.oltean@nxp.com> References: <20230627094207.3385231-1-vladimir.oltean@nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: FR0P281CA0004.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:15::9) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|AM9PR04MB8649:EE_ X-MS-Office365-Filtering-Correlation-Id: 98b4557a-9869-4515-2b4b-08db76f2cd53 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8dLggMjy85oUNTmMe+c2OaqBxH95BMW6JE1kN0JAJhOxJIvWQHAx15sw/TupSaQSwbqN1X4oiVcxxP6iWBH10XbxrDMemvk5p+nfAFzbbU5tAkuKTNjYge3PWN9hlT8NpiyEPgB2PeCxfFChlg7Mr4FjhBLTy+nhhzunWQfoqS2ZSdr51dh06lkuKDKs+oHZLOds88aCXZdSrw5HfSWQXtOfQTlo7IrtGueMANCDA0G7E1Yl5x5FP3FSQPPsythThxQk5q1/atq6bechOaNMljynX9elX2830O9OxCjdj6TzNFjNF0bO84MvqcwEraA/OF1OlVW56SBNUWqK+cGZNDjMXU2/8afbmgIOL8y4ZAvVT8wOC0I+X+OkcXikPJxgm2uqiaQiH9UMeHYcZ7T9WjhlDfYnxU28H8T7pubfQgf0Ae2gKVVouxmlDhAKiA/YrjksYwW+lPwF2W3DclJuQxPop2a+vqtaw9e3zsuiTLsA2WMFt+ps9evgs1n2ghJc4O7zcmsUIBzYtyWkSz/cdTl3UNsAUIAbdN8HWqy8ie2BVsH2glpuJwFs58OreQ6uXUAJKFS2D4nUoAFMbW+Kixg/dr31Et7RKr0bKQ3iQEczuF7ZyG+6Ucl8djaLWn5/ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(366004)(346002)(376002)(396003)(136003)(451199021)(1076003)(52116002)(6486002)(38100700002)(26005)(83380400001)(2616005)(6666004)(38350700002)(186003)(6506007)(6512007)(41300700001)(2906002)(86362001)(54906003)(478600001)(4326008)(316002)(66946007)(66476007)(6916009)(66556008)(44832011)(8936002)(36756003)(8676002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Nvejej0crlS4aBgELuGsDZDVFhTn67Qp+YlaZkzzCzvxwjXcqVo5UKEgRfTL?= =?us-ascii?Q?Lo8CggboCGLKLtE2vOc0BSGjvWsNT9JstnemcsSy2sj/TBnmyETwRkBaYoRs?= =?us-ascii?Q?FxwtmtZlCrcQ4WbPo1xC4rBirvXTERDkzxhN4JeHGRoLyPJaq4wtjjJaQ7QK?= =?us-ascii?Q?zgQInowVtAY1/GFju8BeprlImO11yINRyGOpk74YqvSAyVIDCLQPJJrSILKU?= =?us-ascii?Q?cmpomkbASIJArKPlPLeiF/OpkTNpX8+jTdTN4IU2wylEe9nT2RMsWKyNINFj?= =?us-ascii?Q?A0RHPctTIOhNuWZk86bTEW6ahSTVLmA5tzPy3swE7cz1gX4CG9NUdDowIduy?= =?us-ascii?Q?vqfopcuokN2Sbp6B4afFbqvTmhNNoOrUr6W24prJdWX/K9/OlZK1Pr1H/In7?= =?us-ascii?Q?qJtp5Ur6ySqL9okkSqz1YBtEK80k/HgEUr2ttdauvA3z8/o58VGetLS94pz8?= =?us-ascii?Q?QFPEb0YgCtVQ0FFFQlecpQ5JTdZFnCFMAuKIO5Ht786LePGITKmt6TAMZ201?= =?us-ascii?Q?RZ8KXI2xpFpdSkBPdWV/IuiOOMomFkytXHTfRuxVJ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XVRjC1bjactrBvMu8oqt0GOmze5b7dspzzASDPu8iQ/VNEmc5hgmE0LWcR7B?= =?us-ascii?Q?ym3EgWy6N6Iz1zjno4mHvLYCLJOdYospGPHnd183ZXq3EgPYyHA1asS0MZI9?= =?us-ascii?Q?DhNo+NqnTfHJZJEy6dCBEgSHmKEKRun7VDon+X7uIiW6616bvAyyr65u0cU9?= =?us-ascii?Q?WQ=3D=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 98b4557a-9869-4515-2b4b-08db76f2cd53 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jun 2023 09:42:20.3548 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jHoWbLVUGt0mtowENERgeBmoV8HTUZo53o8PsZDGtp63tQgo+w4W5yDaQ2rTa0QNWlmY12zaon0vMKbi5U4xyw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8649 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently the sja1105 tagging protocol prefers using the source port information from the VLAN header if that is available, falling back to the INCL_SRCPT option if it isn't. The VLAN header is available for all frames except for META frames initiated by the switch (containing RX timestamps), and thus, the "if (is_link_local)" branch is practically dead. The tag_8021q source port identification has become more loose ("imprecise") and will report a plausible rather than exact bridge port, when under a bridge (be it VLAN-aware or VLAN-unaware). But link-local traffic always needs to know the precise source port. With incorrect source port reporting, for example PTP traffic over 2 bridged ports will all be seen on sockets opened on the first such port, which is incorrect. Now that the tagging protocol has been changed to make link-local frames always contain source port information, we can reverse the order of the checks so that we always give precedence to that information (which is always precise) in lieu of the tag_8021q VID which is only precise for a standalone port. Fixes: d7f9787a763f ("net: dsa: tag_8021q: add support for imprecise RX based on the VBID") Fixes: 91495f21fcec ("net: dsa: tag_8021q: replace the SVL bridging with VLAN-unaware IVL bridging") Signed-off-by: Vladimir Oltean --- v1->v2: protect against malformed input packets ("vid" variable may be uninitialized) net/dsa/tag_sja1105.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c index a5f3b73da417..92a626a05e82 100644 --- a/net/dsa/tag_sja1105.c +++ b/net/dsa/tag_sja1105.c @@ -545,10 +545,7 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb, is_link_local = sja1105_is_link_local(skb); is_meta = sja1105_is_meta_frame(skb); - if (sja1105_skb_has_tag_8021q(skb)) { - /* Normal traffic path. */ - sja1105_vlan_rcv(skb, &source_port, &switch_id, &vbid, &vid); - } else if (is_link_local) { + if (is_link_local) { /* Management traffic path. Switch embeds the switch ID and * port ID into bytes of the destination MAC, courtesy of * the incl_srcpt options. @@ -562,16 +559,39 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb, sja1105_meta_unpack(skb, &meta); source_port = meta.source_port; switch_id = meta.switch_id; - } else { + } + + /* Normal data plane traffic and link-local frames are tagged with + * a tag_8021q VLAN which we have to strip + */ + if (sja1105_skb_has_tag_8021q(skb)) { + int tmp_source_port = -1, tmp_switch_id = -1; + + sja1105_vlan_rcv(skb, &tmp_source_port, &tmp_switch_id, &vbid, + &vid); + /* Preserve the source information from the INCL_SRCPT option, + * if available. This allows us to not overwrite a valid source + * port and switch ID with zeroes when receiving link-local + * frames from a VLAN-unaware bridged port (non-zero vbid) or a + * VLAN-aware bridged port (non-zero vid). + */ + if (source_port == -1) + source_port = tmp_source_port; + if (switch_id == -1) + switch_id = tmp_switch_id; + } else if (source_port == -1 && switch_id == -1) { + /* Packets with no source information have no chance of + * getting accepted, drop them straight away. + */ return NULL; } - if (vbid >= 1) + if (source_port != -1 && switch_id != -1) + skb->dev = dsa_master_find_slave(netdev, switch_id, source_port); + else if (vbid >= 1) skb->dev = dsa_tag_8021q_find_port_by_vbid(netdev, vbid); - else if (source_port == -1 || switch_id == -1) - skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid); else - skb->dev = dsa_master_find_slave(netdev, switch_id, source_port); + skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid); if (!skb->dev) { netdev_warn(netdev, "Couldn't decode source port\n"); return NULL; -- 2.34.1