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 BB5E6C6FD1B for ; Tue, 7 Mar 2023 09:48:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230502AbjCGJsL (ORCPT ); Tue, 7 Mar 2023 04:48:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230433AbjCGJrr (ORCPT ); Tue, 7 Mar 2023 04:47:47 -0500 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2076.outbound.protection.outlook.com [40.107.101.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 863A156144; Tue, 7 Mar 2023 01:47:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IwxVMzWcYzTAyO48vo1Yr0H4pxetzgxntXSaSJ9e8CNicKSZo8rFYoSrDu+vjsdtoaFKT6JBosm1E63yqalrQK0G8QhEJihybxAvAFdiuPiexraEQ83Y0ekPTt/1Llul4QvRplqjXHY25N7TKacehHBGM7RYLzzrzG7EH1VgNvZS4tYlIuIlf97bny6sS/QKpMeMDytxT1tQ21gAXph2XjHMtY93Fiy6T9oNjVxApRTJe5lAGD+MQ5IpCV0zOtVPI1PMA6kzdU13PAGCGt8ih5EhiUPcq2dCq9MWAroh6oBb90DJr1S4hCp/pBW4Sn63hyDyYYGbHImoen161xYMpg== 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=RKegf/3rC+aKtUU1TjTZn6GishSeEcEdCtMESb46zBvf48NVkR8k/XHx5Z4pmUSymUY5NFG0iFeIDajrr43r4GbtGO7xN6/RcQt/Aqooa7rjZBRFLfddlHSiPDlIKGJRuMPezIeTmATrxzD20/6fB1/4ffdSMCc0MHw2xuT1V+O2oEwgPvNMb0Z12Pp3+zlhqLEyxyaIJXyD5fzBLArbp8f/ZIq7ruSpbwctrCMcY618iUx+s7H/73EuFWSuu8ttz/wa96hJgYzPi7u/qa5wZFOHaRjDhRW0H9RUY9Ze5j1poL3BnsL/DQJ1diJnQhue2bjW8W4qRUWLyvYUX/XLjg== 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=mSrfNdthtGmbpijozoz4HpQlnPVLieY2QbvgJ13qzMhQIWTdZm6AA6E4jAQ7QciXS349MH1twZU+hjlT0AKmqJt0WupGM9a3rQ9HMAzVaUk/omp5x7dh2ddAl6VfeIV2ZUqnF77tiw3qljlN0kFJTYw4nC1qXdTCjfBv0AJgSAqgRO4IszPvlMoaK1vU5ictXZ22AuCOveqXyoFHmivLjTXHckhawrGTuyTu+SEyOS+Ap1HzJMm5v0dW4mmnd4b4cFmFu0syAqLeRAAJqlLwLwW53i71TY/Vke3qdNDEfXeY1e/PmVJa6IRuJrVHG1bUNcvoGGpPxwFmUlkkLExzpg== Received: from BN0PR04CA0003.namprd04.prod.outlook.com (2603:10b6:408:ee::8) by DM4PR12MB6424.namprd12.prod.outlook.com (2603:10b6:8:be::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.29; Tue, 7 Mar 2023 09:47:18 +0000 Received: from BN8NAM11FT041.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ee:cafe::24) by BN0PR04CA0003.outlook.office365.com (2603:10b6:408:ee::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.28 via Frontend Transport; Tue, 7 Mar 2023 09:47:18 +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 BN8NAM11FT041.mail.protection.outlook.com (10.13.177.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.16 via Frontend Transport; Tue, 7 Mar 2023 09:47:17 +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; Tue, 7 Mar 2023 01:47:12 -0800 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; Tue, 7 Mar 2023 01:47:08 -0800 From: Gavin Li To: , , , , , , CC: , , , , , Subject: [PATCH net-next v5 3/4] net/mlx5e: Add helper for encap_info_equal for tunnels with options Date: Tue, 7 Mar 2023 11:46:36 +0200 Message-ID: <20230307094637.246993-4-gavinl@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307094637.246993-1-gavinl@nvidia.com> References: <20230307094637.246993-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: BN8NAM11FT041:EE_|DM4PR12MB6424:EE_ X-MS-Office365-Filtering-Correlation-Id: d4469650-1998-40f5-4af4-08db1ef0f068 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hYZuDYD9ZwAI3vm6vmIEL1siPS0W6ZA/84mWj7o9X3J+spogOkKFgjFfjnBZFAkUotsUsJitYdCWiABo5zbF1ZPfXjQSzcE2Xd9lgS/08CvRyNfjqT8zM2rrWj1UiSO4W2Bw6pCoQz12KgXD+cyRdQHpiP8YltMPE6unjhtN9Xygn9bA2hn1/vlNDrm8XqYj1WkGIByMg3nrYi0qkUSPHlBOa4GE1WtMDZZD+Hhf7rxxqpJUxjfF4MhgTUWUFqUL9LmPPa9CH94/jBqOWHJszVU1LGnS0HiaSvz0JqFdHppyunlMo5nsdSK8nowoa2ZrojYKUXdeeQYB3JjizVDatzpatrYS8PqNxb7Wnu9tN/PN9XmhaSR2jnJ6/7HlXnM01JTVZfH6obYwy+HYuU6OgYhdPG7FSbu0Z1X8HxWA6NH7fqT4+yPVrSD9gXYkaCXMgE3tvPkJ3Jz2rY6wi4072CST9cMJxtKEMZrcKIkCQvig+gyb6rIvzeuFK5iWg0yC7ylb3niylXs5GqMB8oKDemkha255ePVusXEf5SK6dqX5mnkfI9tH+XWqOH10ukpGPNJT0lF0FaSU0IC379/ZOq2nhZSywIlkHvHFXOcM+MREbiOp/hBejQyG0Mb4yvSLNn0GVW3kpzhjkPxoYpqCHFv50FfS3OTKYVMChxBUnQ53mzig0FJEPfvo4g8zo96zI2iHGv85xxFz8ZFinljeiQ== 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)(396003)(376002)(39860400002)(346002)(136003)(451199018)(46966006)(40470700004)(36840700001)(426003)(2906002)(47076005)(5660300002)(54906003)(83380400001)(8936002)(36756003)(82310400005)(336012)(41300700001)(70206006)(70586007)(4326008)(40460700003)(316002)(8676002)(86362001)(2616005)(55016003)(40480700001)(110136005)(478600001)(356005)(7636003)(7696005)(82740400003)(26005)(186003)(107886003)(36860700001)(1076003)(6286002)(16526019)(6666004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2023 09:47:17.5220 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d4469650-1998-40f5-4af4-08db1ef0f068 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: BN8NAM11FT041.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6424 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