Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7C09C61DA4 for ; Mon, 13 Mar 2023 07:53:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230180AbjCMHxL (ORCPT ); Mon, 13 Mar 2023 03:53:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230305AbjCMHwb (ORCPT ); Mon, 13 Mar 2023 03:52:31 -0400 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2060.outbound.protection.outlook.com [40.107.212.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E14E353D99; Mon, 13 Mar 2023 00:52:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OTjMBfy8p4eCdFR4KuVQA1CJcpIZs6QW9Vchf1En12oj+whvTwSlxRdCxhW6Oq5m3mzswZikkCyLSdYWGc/vYkqVFqxq5YAqQmuBX7hgyIX5x5SrTb6W5gypc8Ln7fpVVOapERJETX/7YGC0WlScptrVUPitXDPKEuLUhkFcMhPLJ56GQdlqzjY345Af5l6KegjmWVh5eArn7tB33U8JxQMnXkW1E9HMWS1dZIIqBzk9BP1m8qWB4avy5nzA7HkeaNRRFOKnQYqA61rlkk02nPqJfmq6pJcmbQfPYiUFFq/Tt0jPL20Yefc76+yhImG44BXxhq2yrEF8LgBDUawAdw== 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=N179DlG4Bn/W8g7JOeG9FuYbjDYjXPaJecv7CzHK2fc=; b=JFP4XgMGqn3N+d7XevgEijnuj99OP5e9jkmTe68lnChBFEdLBjf6jEHOnrIs0sR6sD+8fA6sNl3xHptqay3KvKBRE4O+RDRQxQMM6h3MNrL5Sz9w6zBeRjeQeNmDo9PSMB/Yv/j79RsjgtSkqE8ufzjE8t6cLs0EiaNWw35QZzhNGA9PPxoES/VIfkYGyqThHFt+/IxgUWtHPvQN6Cc0WVn3KddygIknLHrrr7DCMs55jviPDb6UmG0TyzmZ4mdlo37+SpjRnxJ2nzPWWB0ucmMTBHpmFXe2FUaSbNQQPJvv/ZsLywyDpkNPagnQQL+iTPT73pAKsGwZBkzfbSdCrg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=N179DlG4Bn/W8g7JOeG9FuYbjDYjXPaJecv7CzHK2fc=; b=WmKlamMIR5NxDyOTqr86Eb8rEy5TbBkK4ShBAdzct5Q+I8IrCiowa7KpP53qOZDWf0vV1FYQNWZrfinW5NJsvlOYrvqj06ewriX7nVsT+Bn8KOCVCWM2cBtMJAvu9564cF/5GMaZH3Gl0sh1+m/GxD3RcAiLau6d2veNDSyX7N8zBYpTotogUaMhYEUUnWr3GB0Osrahy99xH/1rIsVFM179i3PgyVyyqreZH7rgC4lGSYQCS0DFLIn40NOhDw4Aqr+y7iftg25qCL2yLHDSvWxwc+cs/0ug+u00DCCFRIwkdwnfRu+HRUZ2gpbLRV6RifZKGU1JkEoBHgC5KyDAZA== Received: from CY5PR19CA0103.namprd19.prod.outlook.com (2603:10b6:930:83::17) by PH8PR12MB7374.namprd12.prod.outlook.com (2603:10b6:510:216::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.24; Mon, 13 Mar 2023 07:51:48 +0000 Received: from CY4PEPF0000C982.namprd02.prod.outlook.com (2603:10b6:930:83:cafe::c9) by CY5PR19CA0103.outlook.office365.com (2603:10b6:930:83::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.25 via Frontend Transport; Mon, 13 Mar 2023 07:51:48 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CY4PEPF0000C982.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.13 via Frontend Transport; Mon, 13 Mar 2023 07:51:48 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Mon, 13 Mar 2023 00:51:43 -0700 Received: from nvidia.com (10.126.231.37) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Mon, 13 Mar 2023 00:51:39 -0700 From: Gavin Li To: , , , , , , CC: , , , , , Subject: [PATCH net-next v7 3/5] net/mlx5e: Add helper for encap_info_equal for tunnels with options Date: Mon, 13 Mar 2023 09:51:05 +0200 Message-ID: <20230313075107.376898-4-gavinl@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313075107.376898-1-gavinl@nvidia.com> References: <20230313075107.376898-1-gavinl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.231.37] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000C982:EE_|PH8PR12MB7374:EE_ X-MS-Office365-Filtering-Correlation-Id: 7bc6ca57-2292-4947-180e-08db2397ccbd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UoRz5gwFiYo/qr//oJE0c5MuoazsJllT5MTXWgHD7DVZ2kV5M9Xq62ooisJemnIUdi+gvbQqBy/Rj8aOiukygSGGx7TuDmeI8qBkCMlYLsZ8+duvOM8X5ZmtGsYa3Iw5MDmgQnz+UbuHmjIIrJIri36Rq50h+XcLpirdfxZVtIIl44qM8y1mxIUFiLdl1b12kuAmaIJREYUv1YOmUxSiZuBpC12K2Iv5qee0CHkI3mRRfETihxb1PRRnwqNugilt3LZqJtOEQGJ3iThgToTkxaUzfwq+GjA8nd59ruczgAe8C3bzv4KVX/E4Ep6z7gekjWU96D6CnAHxQk4B6Hv7TaWsW0GVi/DasmopfB9VTLG3/Y2uPGYfUlEaiZiteo4ymRP1oyipouaGTBK+Fluv02KjRM7G3X777WnZVNkHrs4NRIMn7+AZpMjuC2vNmH0VkHoqBdSbCjW0WxRvbxkJwvEoG3nAtUa/W+w1tgX0K3OgDm2g171JiV89Ax3cvJSZxfDFzBPaiCJD0EbzFAaziq70QxfTiXoQkmgDWP1IQ3+5wYMgUjXVX0+STuiLJGux+7diJJOT8pQupdo3K6TrHHYfaxvcduVNLiSwSlmvDQWYoBmU7yKosrxfgy3KocLiG8lKnqtknKRVZ7mqrZPYk5yKJh87L5CGRVJdhceWvuZ3kMvttYLKWQgqOjKzWBRjq8J2bOsK8g/3ezTAoUtNGEKteD7zcJduFShoGSNj3fYopXSClzS7hFPe/IyFGapG X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230025)(4636009)(39860400002)(396003)(346002)(376002)(136003)(451199018)(46966006)(40470700004)(36840700001)(86362001)(82310400005)(356005)(36756003)(7636003)(36860700001)(82740400003)(55016003)(40480700001)(40460700003)(4326008)(8676002)(70586007)(70206006)(41300700001)(8936002)(54906003)(110136005)(478600001)(316002)(5660300002)(2906002)(426003)(47076005)(336012)(2616005)(83380400001)(7696005)(16526019)(186003)(107886003)(6666004)(6286002)(1076003)(26005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2023 07:51:48.3785 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7bc6ca57-2292-4947-180e-08db2397ccbd X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000C982.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7374 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For tunnels with options, eg, geneve and vxlan with gbp, they share the same way to compare the headers and options. Extract the code as a common function for them. Signed-off-by: Gavin Li Reviewed-by: Gavi Teitz Reviewed-by: Roi Dayan Reviewed-by: Maor Dickman Acked-by: Saeed Mahameed --- .../ethernet/mellanox/mlx5/core/en/tc_tun.h | 3 ++ .../mellanox/mlx5/core/en/tc_tun_encap.c | 32 +++++++++++++++++++ .../mellanox/mlx5/core/en/tc_tun_geneve.c | 24 +------------- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h index b38f693bbb52..92065568bb19 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h @@ -115,6 +115,9 @@ int mlx5e_tc_tun_parse_udp_ports(struct mlx5e_priv *priv, bool mlx5e_tc_tun_encap_info_equal_generic(struct mlx5e_encap_key *a, struct mlx5e_encap_key *b); +bool mlx5e_tc_tun_encap_info_equal_options(struct mlx5e_encap_key *a, + struct mlx5e_encap_key *b, + __be16 tun_flags); #endif /* CONFIG_MLX5_ESWITCH */ #endif //__MLX5_EN_TC_TUNNEL_H__ diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c index 780224fd67a1..a108e73c9f66 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c @@ -3,6 +3,7 @@ #include #include +#include #include "tc_tun_encap.h" #include "en_tc.h" #include "tc_tun.h" @@ -571,6 +572,37 @@ bool mlx5e_tc_tun_encap_info_equal_generic(struct mlx5e_encap_key *a, a->tc_tunnel->tunnel_type == b->tc_tunnel->tunnel_type; } +bool mlx5e_tc_tun_encap_info_equal_options(struct mlx5e_encap_key *a, + struct mlx5e_encap_key *b, + __be16 tun_flags) +{ + struct ip_tunnel_info *a_info; + struct ip_tunnel_info *b_info; + bool a_has_opts, b_has_opts; + + if (!mlx5e_tc_tun_encap_info_equal_generic(a, b)) + return false; + + a_has_opts = !!(a->ip_tun_key->tun_flags & tun_flags); + b_has_opts = !!(b->ip_tun_key->tun_flags & tun_flags); + + /* keys are equal when both don't have any options attached */ + if (!a_has_opts && !b_has_opts) + return true; + + if (a_has_opts != b_has_opts) + return false; + + /* options stored in memory next to ip_tunnel_info struct */ + a_info = container_of(a->ip_tun_key, struct ip_tunnel_info, key); + b_info = container_of(b->ip_tun_key, struct ip_tunnel_info, key); + + return a_info->options_len == b_info->options_len && + !memcmp(ip_tunnel_info_opts(a_info), + ip_tunnel_info_opts(b_info), + a_info->options_len); +} + static int cmp_decap_info(struct mlx5e_decap_key *a, struct mlx5e_decap_key *b) { diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_geneve.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_geneve.c index 054d80c4e65c..2bcd10b6d653 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_geneve.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_geneve.c @@ -337,29 +337,7 @@ static int mlx5e_tc_tun_parse_geneve(struct mlx5e_priv *priv, static bool mlx5e_tc_tun_encap_info_equal_geneve(struct mlx5e_encap_key *a, struct mlx5e_encap_key *b) { - struct ip_tunnel_info *a_info; - struct ip_tunnel_info *b_info; - bool a_has_opts, b_has_opts; - - if (!mlx5e_tc_tun_encap_info_equal_generic(a, b)) - return false; - - a_has_opts = !!(a->ip_tun_key->tun_flags & TUNNEL_GENEVE_OPT); - b_has_opts = !!(b->ip_tun_key->tun_flags & TUNNEL_GENEVE_OPT); - - /* keys are equal when both don't have any options attached */ - if (!a_has_opts && !b_has_opts) - return true; - - if (a_has_opts != b_has_opts) - return false; - - /* geneve options stored in memory next to ip_tunnel_info struct */ - a_info = container_of(a->ip_tun_key, struct ip_tunnel_info, key); - b_info = container_of(b->ip_tun_key, struct ip_tunnel_info, key); - - return a_info->options_len == b_info->options_len && - memcmp(a_info + 1, b_info + 1, a_info->options_len) == 0; + return mlx5e_tc_tun_encap_info_equal_options(a, b, TUNNEL_GENEVE_OPT); } struct mlx5e_tc_tunnel geneve_tunnel = { -- 2.31.1