From patchwork Tue Jan 24 14:02:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlad Buslov X-Patchwork-Id: 13114175 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53FFCC61D9D for ; Tue, 24 Jan 2023 14:03:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234537AbjAXODs (ORCPT ); Tue, 24 Jan 2023 09:03:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234383AbjAXODq (ORCPT ); Tue, 24 Jan 2023 09:03:46 -0500 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2075.outbound.protection.outlook.com [40.107.223.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46784166F4; Tue, 24 Jan 2023 06:03:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T1RiTcupa/8z4XAGE9REmUx9BU65LO+lW7H3CpTIi7ilqBrhG9jZj+bl10UBFm6K26LIltl5I0GFUqvGZ+Ix8nCgXEIowZeGcOxeeogcIDTgOAu3/YVG4luRQI/HTtuuT7R6LLv08alF8otlMtYWIAz/jhqjsSMLbhinVm7t6Ua5aARo2EaKXLl0N1HCKiWSL7Y5PK1gVZumRedFQNpKgNuXeoaytA5HcV7bFEx1oCCHbtHtmNoCtAuGyHF7Y5tuixorFyxz8LqneeBXpzyB5d/mR2NvlwdPT+cEecf8NZl/otM4nHy5/gz+vljzx+E7AA+weaytgEWOUvwj+MZg4Q== 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=5yCSI090vdvvgrXiokyByxwXHMggpZF2LwKEnNUtykU=; b=YcMUIGhHA6mzqJLYW7NHFwHK2xv7b730bVzeTlTe56v9yM92SuSkmRzbrQeFDVDhyKPfFtBTmFxR3lQGjGCVlUZLuNJitUWAnreRS5hfOGuxQRGb3I1mbp7dKhhujqRxQEFIm/1OSV9rdqgqiSVpEaDwcONz36yPfLbp1ULKUwwyOO7IEAF8Q5V7xCHi+w0WcSv0Amtrrn5bV5YpmGgKeZD0Vb0ekA7MgzMLBXevhdgrWQcqvApTdOyKnLPYNgQKJHNxy+2cF6Da6N+Iam5H5n3DSN5w13vKAryxYok9hKOR8r8Bd0roY3Fhny8WOgod6Uw6m/8zGL/SknZxkNvS+g== 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=5yCSI090vdvvgrXiokyByxwXHMggpZF2LwKEnNUtykU=; b=p1vLBBfOOlppPbyzsBwIszyxgkQgIGIV3QgoDPfyM8W8oq/84t9tqppPJxNDdLLeBs6VPNMcEqmXq1XYEwxSb9vXjMo5Wu/MLxqTIg5ud+tj1iYslsulWgCyx/gjBazxrhYcs/xrzNjU+dXxcicEhr+zcGihnY5qtCjSfNy8JW6ics9LxKm/wKU1cmkfLY5oLLHIS/Aml/zr3JzWkpDluZ6OOb+67LuDZpuO9A48s6/hFsSZVKcn6B8x47r6a5CMkzD4im1l0Q8QIgtV/xjHzUPDvGY87Mz6Mxt0TNLkCT3z3DBRAyyTih435kdYIXQciwTEZT9yIKk2LNll9lIZBA== Received: from BN9P223CA0008.NAMP223.PROD.OUTLOOK.COM (2603:10b6:408:10b::13) by CO6PR12MB5459.namprd12.prod.outlook.com (2603:10b6:303:13b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33; Tue, 24 Jan 2023 14:03:14 +0000 Received: from BN8NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:408:10b:cafe::c7) by BN9P223CA0008.outlook.office365.com (2603:10b6:408:10b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33 via Frontend Transport; Tue, 24 Jan 2023 14:03:14 +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 BN8NAM11FT047.mail.protection.outlook.com (10.13.177.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.17 via Frontend Transport; Tue, 24 Jan 2023 14:03:13 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) 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.36; Tue, 24 Jan 2023 06:02:52 -0800 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Tue, 24 Jan 2023 06:02:52 -0800 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.36 via Frontend Transport; Tue, 24 Jan 2023 06:02:47 -0800 From: Vlad Buslov To: , , , CC: , , , , , , , , Vlad Buslov Subject: [PATCH net-next v4 1/7] net: flow_offload: provision conntrack info in ct_metadata Date: Tue, 24 Jan 2023 15:02:01 +0100 Message-ID: <20230124140207.3975283-2-vladbu@nvidia.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230124140207.3975283-1-vladbu@nvidia.com> References: <20230124140207.3975283-1-vladbu@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT047:EE_|CO6PR12MB5459:EE_ X-MS-Office365-Filtering-Correlation-Id: cdcfe3dd-ae27-4c8d-0f88-08dafe13bc09 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nx6594WyGYVicv55MDa0S7LN7/ZepqyUyypXunQIeVoBHISyuILwXd3+VIn50VwdWh9C9OrMgnVeuPgoFT99yED260OWLTXEz4nUqujyBYeZVbTv4Gx2SYGb9sbJmtal+6zJ2APo1YVdDfd9edBj1cr9lNQB+btqKMCT/HwtLo3ONdTobK/uZS/rIDz/kEczE35cF40glOoVSBj+I95jA+cT2PpPVa0rRrY2INkBkRcVHc4Ywmd6OQo7s9tUI1eswPmDc8BCDDiL7x/0gkbzL5EK6hdbGUQMBhw1S3g7O6MMxV9Xw4l9J1LK9sOxqd/A3F++Oo6L98BaER31Az5rwRLzHVpmFzxmOdLRwwBHZPwK2hWqSm6Ov8neHDoU9Dn7M+C2xf417gcSj/LncoTPICJtAIQ7F8v3id09M6IjNBExH1xxHNd0kNaEV/AbNl1F7qLQ2ur55lYTCTBNStozuRLhHVWFqUKXlqfSN1M+lTKeLw7EWAB9MdSpBCCQJE6ZrYPyoaN+mFbZHp38hmOkTO5T8EoB/4jbCfz4+IyviyG6zV1iXizMe7od7ZUlrB8ZSfd6bp6pNp/MQJbqq+XXpElxIG/BJrLhndwsr3NBH/m4RVgX9tZJXHVvvePDPw2P6soBNS1Hacjh/Xgyv85CUwnPQ5Q5cQmQe1Rrs0XlqHP0vViD7Gl2/D9bRFbnH7ynh/TXMdIn3I4iE8vUi6AU9zaFvSPdQK7hgHEE8gu6aIQ= 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:(13230022)(4636009)(346002)(39860400002)(136003)(396003)(376002)(451199015)(40470700004)(46966006)(36840700001)(36756003)(82740400003)(2906002)(5660300002)(356005)(7416002)(7636003)(8936002)(4326008)(82310400005)(41300700001)(83380400001)(36860700001)(86362001)(40460700003)(478600001)(7696005)(110136005)(40480700001)(26005)(186003)(8676002)(316002)(54906003)(70206006)(2616005)(336012)(1076003)(426003)(107886003)(70586007)(47076005)(6666004)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2023 14:03:13.6859 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cdcfe3dd-ae27-4c8d-0f88-08dafe13bc09 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: BN8NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR12MB5459 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org In order to offload connections in other states besides "established" the driver offload callbacks need to have access to connection conntrack info. Flow offload intermediate representation data structure already contains that data encoded in 'cookie' field, so just reuse it in the drivers. Reject offloading IP_CT_NEW connections for now by returning an error in relevant driver callbacks based on value of ctinfo. Support for offloading such connections will need to be added to the drivers afterwards. Signed-off-by: Vlad Buslov --- Notes: Changes V3 -> V4: - Only obtain ctinfo in mlx5 after checking the meta action pointer. Changes V2 -> V3: - Reuse existing meta action 'cookie' field to obtain ctinfo instead of introducing a new field as suggested by Marcelo. Changes V1 -> V2: - Add missing include that caused compilation errors on certain configs. - Change naming in nfp driver as suggested by Simon and Baowen. .../ethernet/mellanox/mlx5/core/en/tc_ct.c | 4 ++++ .../ethernet/netronome/nfp/flower/conntrack.c | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c index 313df8232db7..193562c14c44 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c @@ -1073,12 +1073,16 @@ mlx5_tc_ct_block_flow_offload_add(struct mlx5_ct_ft *ft, struct mlx5_tc_ct_priv *ct_priv = ft->ct_priv; struct flow_action_entry *meta_action; unsigned long cookie = flow->cookie; + enum ip_conntrack_info ctinfo; struct mlx5_ct_entry *entry; int err; meta_action = mlx5_tc_ct_get_ct_metadata_action(flow_rule); if (!meta_action) return -EOPNOTSUPP; + ctinfo = meta_action->ct_metadata.cookie & NFCT_INFOMASK; + if (ctinfo == IP_CT_NEW) + return -EOPNOTSUPP; spin_lock_bh(&ct_priv->ht_lock); entry = rhashtable_lookup_fast(&ft->ct_entries_ht, &cookie, cts_ht_params); diff --git a/drivers/net/ethernet/netronome/nfp/flower/conntrack.c b/drivers/net/ethernet/netronome/nfp/flower/conntrack.c index f693119541d5..d23830b5bcb8 100644 --- a/drivers/net/ethernet/netronome/nfp/flower/conntrack.c +++ b/drivers/net/ethernet/netronome/nfp/flower/conntrack.c @@ -1964,6 +1964,27 @@ int nfp_fl_ct_stats(struct flow_cls_offload *flow, return 0; } +static bool +nfp_fl_ct_offload_nft_supported(struct flow_cls_offload *flow) +{ + struct flow_rule *flow_rule = flow->rule; + struct flow_action *flow_action = + &flow_rule->action; + struct flow_action_entry *act; + int i; + + flow_action_for_each(i, act, flow_action) { + if (act->id == FLOW_ACTION_CT_METADATA) { + enum ip_conntrack_info ctinfo = + act->ct_metadata.cookie & NFCT_INFOMASK; + + return ctinfo != IP_CT_NEW; + } + } + + return false; +} + static int nfp_fl_ct_offload_nft_flow(struct nfp_fl_ct_zone_entry *zt, struct flow_cls_offload *flow) { @@ -1976,6 +1997,9 @@ nfp_fl_ct_offload_nft_flow(struct nfp_fl_ct_zone_entry *zt, struct flow_cls_offl extack = flow->common.extack; switch (flow->command) { case FLOW_CLS_REPLACE: + if (!nfp_fl_ct_offload_nft_supported(flow)) + return -EOPNOTSUPP; + /* Netfilter can request offload multiple times for the same * flow - protect against adding duplicates. */ From patchwork Tue Jan 24 14:02:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlad Buslov X-Patchwork-Id: 13114176 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1373CC54E94 for ; Tue, 24 Jan 2023 14:03:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234567AbjAXODt (ORCPT ); Tue, 24 Jan 2023 09:03:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234524AbjAXODr (ORCPT ); Tue, 24 Jan 2023 09:03:47 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2054.outbound.protection.outlook.com [40.107.243.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3E6229E01; Tue, 24 Jan 2023 06:03:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ew8+q1CS0Q2u8JUndXT4fzmexVcvnruj/xrnxU/SkxPxECU9+Do17efnYV/2XAqw9pS3IV2v2RGFAQfvJT55Lkgrsv68pDrGslQ/3GLd7V44YPf0StH5yyepNrDG81ucPNgThuSVqpbiAZip0hBojie9EEyY6qVwsMmTFuIGotAHGxUYo4idCXDyCfPzlO5flrQN/Qk7L8O00EC/FHBDg4dXMDHbAaeJ5mwvNl3KyJYi+dgcO+kjDksgq8lZ0/OMvRwWFNaX0Fk6o/bxDY/DgxSnsyJRiswr/8AdxP/+Vd1fikZaKbNFZ9Fw0eVagZ9QvHzRtDYxPPsgOziE401W4g== 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=6hRCCIrcOIvrOs9yZYI2nP2cP9hmUlhGTKjvzGb2BZs=; b=SL9zSMFdmPAbqGF+6M+/1fDo2p3CYWGT96URPS0P0fqdaJodQL7TCoQim6P4r9/vVmDVIf9VM+btyvncU8VlbqurGve1ObXUpMsYDvkZssVkN2R3EcJoqUXpRvhRfXHyJPIHVTcQe80XJRt+tnbi1fzTeyUmOY1Dfp9HP8Zvw+3P5Fzb/3pE0PeKj+iOYZYRTh4rv4xIPyQVNHhv7EK5A4cdnHtT9gxg1K1bs7P7xRogjWxpkqopQ6yEcCNu3Sk8fL3JJJyj+qtDN0dKIXTngIHjJMM4RbJonhS9ezshalzf5Ny6t6EvOp3f0czxCuViWysBNWAarxqXMhgJhTBlaA== 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=6hRCCIrcOIvrOs9yZYI2nP2cP9hmUlhGTKjvzGb2BZs=; b=KS355yK4YJqi8aH3mTVWbJPMsZ01u7UZyyBp20fFKgU9YOJ2bkJgQxv6jiZtl3CKMzFOP91yc6Hk7G153ZHppLwKQOP/wIi8Nv71AYTJx8bcQSJMBIUUlZoTasQw5WfJFLtMSdyea8v/DU3kGae0oWGI1fJ2TyKV+BYXPGbDbNx/72GIEqb5L9LwIoO82I3H1zRL1wFAQYA70KKj+bOKCf3cokjil7RwhffUmH8MZ8vwo0/PT07vD74Xf9EXWc5huRdp50eArkse/3amYBPiXpS1fBoUab7ojJAUOmNXCSMiIp9RRmstcwtOBelfIYhfPMhWVh5BxJRgSIlJ2q9fxA== Received: from BN9PR03CA0250.namprd03.prod.outlook.com (2603:10b6:408:ff::15) by PH7PR12MB6610.namprd12.prod.outlook.com (2603:10b6:510:212::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33; Tue, 24 Jan 2023 14:03:20 +0000 Received: from BN8NAM11FT065.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ff:cafe::28) by BN9PR03CA0250.outlook.office365.com (2603:10b6:408:ff::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33 via Frontend Transport; Tue, 24 Jan 2023 14:03:20 +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 BN8NAM11FT065.mail.protection.outlook.com (10.13.177.63) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6023.16 via Frontend Transport; Tue, 24 Jan 2023 14:03:19 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) 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.36; Tue, 24 Jan 2023 06:02:57 -0800 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Tue, 24 Jan 2023 06:02:56 -0800 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.36 via Frontend Transport; Tue, 24 Jan 2023 06:02:52 -0800 From: Vlad Buslov To: , , , CC: , , , , , , , , Vlad Buslov Subject: [PATCH net-next v4 2/7] netfilter: flowtable: fixup UDP timeout depending on ct state Date: Tue, 24 Jan 2023 15:02:02 +0100 Message-ID: <20230124140207.3975283-3-vladbu@nvidia.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230124140207.3975283-1-vladbu@nvidia.com> References: <20230124140207.3975283-1-vladbu@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT065:EE_|PH7PR12MB6610:EE_ X-MS-Office365-Filtering-Correlation-Id: 2b226c6e-d570-4101-a038-08dafe13bf53 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WsvNsVU9MusEpVT5sYToTADQfsm4PpE40lYPpJZnxH66PIeBZ1G+srCxszVlnf3D1KirCg7ZoZtVS/IHFCwFXFk5Sfrzl1kLRgYkMOG7Me8jU+KsCDLxLnOPIrsf5k1MycIb8IhuITqMT/BQF8hW98M/si8fqlwRjJVSNkZdCQw4IIdKyQGsy8YYEJKRctxns2spXoHiX2Gn9meBgjZI0APBDyYSzInCuBc1CcjsHQoSmORxv/UXz8LjBEYPCoPGX/nWa1W4ZWyaAS9z4AusQB6487/IEdUieoZOlgaEeEAY52cKT1JjUXnbyjxTrmd2CnaG4DftFqzWODiP+Q+Are2XcrLXzymNvHPlyR0UcoZ+sT3UE0f5p+ub6j0Gw1aUNvpgzR5WSIq3sdktl+goRg/xVBpX9axiX8WmTSrmNfKWXveMu9gRHHbwRDRbu2CgN9VLM6MrpiPB3mGvlxKL867irCiCfoVw4wcr8IMNadSefYLJ1KvGoX0zhUCTr3wioLjNL1sCzDKqCjmTJ2EcM6ZLL3FOD1I8xgetmNHhphQPui2pZJW0S9w3QQi8ppsccpxSmHqtTMGBX3X169LLUTHQx9aGKTjj/UDNKaeZ8CHUolbRrYOZEaKhbjlOlrLWU3KtaTNkHmCmzOS/GzkhS6QdGtutoj7AmA5tdtEakmw0PyNbeOOdEUiCx2rQbHomCTn91I3s2zhZl1gZEqTtS8qKxPPjVXZDcXXWpBY4148= 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:(13230022)(4636009)(39860400002)(396003)(376002)(136003)(346002)(451199015)(46966006)(40470700004)(36840700001)(36860700001)(83380400001)(82740400003)(7416002)(41300700001)(86362001)(356005)(7636003)(2906002)(82310400005)(8936002)(5660300002)(4326008)(40460700003)(316002)(40480700001)(26005)(186003)(8676002)(6666004)(107886003)(47076005)(426003)(336012)(70586007)(70206006)(54906003)(2616005)(1076003)(110136005)(478600001)(7696005)(36756003)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2023 14:03:19.2077 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2b226c6e-d570-4101-a038-08dafe13bf53 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: BN8NAM11FT065.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6610 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Currently flow_offload_fixup_ct() function assumes that only replied UDP connections can be offloaded and hardcodes UDP_CT_REPLIED timeout value. Allow users to modify timeout calculation by implementing new flowtable type callback 'timeout' and use the existing algorithm otherwise. To enable UDP NEW connection offload in following patches implement 'timeout' callback in flowtable_ct of act_ct which extracts the actual connections state from ct->status and set the timeout according to it. Signed-off-by: Vlad Buslov --- Notes: Changes V3 -> V4: - Rework the patch to decouple netfilter and act_ct timeout fixup algorithms. include/net/netfilter/nf_flow_table.h | 6 +++- net/netfilter/nf_flow_table_core.c | 40 +++++++++++++++++++-------- net/netfilter/nf_flow_table_ip.c | 17 ++++++------ net/sched/act_ct.c | 35 ++++++++++++++++++++++- 4 files changed, 76 insertions(+), 22 deletions(-) diff --git a/include/net/netfilter/nf_flow_table.h b/include/net/netfilter/nf_flow_table.h index cd982f4a0f50..a3e4b5127ad0 100644 --- a/include/net/netfilter/nf_flow_table.h +++ b/include/net/netfilter/nf_flow_table.h @@ -61,6 +61,9 @@ struct nf_flowtable_type { enum flow_offload_tuple_dir dir, struct nf_flow_rule *flow_rule); void (*free)(struct nf_flowtable *ft); + bool (*timeout)(struct nf_flowtable *ft, + struct flow_offload *flow, + s32 *val); nf_hookfn *hook; struct module *owner; }; @@ -278,7 +281,8 @@ void nf_flow_table_cleanup(struct net_device *dev); int nf_flow_table_init(struct nf_flowtable *flow_table); void nf_flow_table_free(struct nf_flowtable *flow_table); -void flow_offload_teardown(struct flow_offload *flow); +void flow_offload_teardown(struct nf_flowtable *flow_table, + struct flow_offload *flow); void nf_flow_snat_port(const struct flow_offload *flow, struct sk_buff *skb, unsigned int thoff, diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c index 81c26a96c30b..e3eeea349c8d 100644 --- a/net/netfilter/nf_flow_table_core.c +++ b/net/netfilter/nf_flow_table_core.c @@ -178,28 +178,43 @@ static void flow_offload_fixup_tcp(struct ip_ct_tcp *tcp) tcp->seen[1].td_maxwin = 0; } -static void flow_offload_fixup_ct(struct nf_conn *ct) +static bool flow_offload_timeout_default(struct nf_conn *ct, s32 *timeout) { struct net *net = nf_ct_net(ct); int l4num = nf_ct_protonum(ct); - s32 timeout; if (l4num == IPPROTO_TCP) { struct nf_tcp_net *tn = nf_tcp_pernet(net); flow_offload_fixup_tcp(&ct->proto.tcp); - timeout = tn->timeouts[ct->proto.tcp.state]; - timeout -= tn->offload_timeout; + *timeout = tn->timeouts[ct->proto.tcp.state]; + *timeout -= tn->offload_timeout; } else if (l4num == IPPROTO_UDP) { struct nf_udp_net *tn = nf_udp_pernet(net); - timeout = tn->timeouts[UDP_CT_REPLIED]; - timeout -= tn->offload_timeout; + *timeout = tn->timeouts[UDP_CT_REPLIED]; + *timeout -= tn->offload_timeout; } else { - return; + return false; } + return true; +} + +static void flow_offload_fixup_ct(struct nf_flowtable *flow_table, + struct flow_offload *flow) +{ + struct nf_conn *ct = flow->ct; + bool needs_fixup; + s32 timeout; + + needs_fixup = flow_table->type->timeout ? + flow_table->type->timeout(flow_table, flow, &timeout) : + flow_offload_timeout_default(ct, &timeout); + if (!needs_fixup) + return; + if (timeout < 0) timeout = 0; @@ -348,11 +363,12 @@ static void flow_offload_del(struct nf_flowtable *flow_table, flow_offload_free(flow); } -void flow_offload_teardown(struct flow_offload *flow) +void flow_offload_teardown(struct nf_flowtable *flow_table, + struct flow_offload *flow) { clear_bit(IPS_OFFLOAD_BIT, &flow->ct->status); set_bit(NF_FLOW_TEARDOWN, &flow->flags); - flow_offload_fixup_ct(flow->ct); + flow_offload_fixup_ct(flow_table, flow); } EXPORT_SYMBOL_GPL(flow_offload_teardown); @@ -421,7 +437,7 @@ static void nf_flow_offload_gc_step(struct nf_flowtable *flow_table, { if (nf_flow_has_expired(flow) || nf_ct_is_dying(flow->ct)) - flow_offload_teardown(flow); + flow_offload_teardown(flow_table, flow); if (test_bit(NF_FLOW_TEARDOWN, &flow->flags)) { if (test_bit(NF_FLOW_HW, &flow->flags)) { @@ -569,14 +585,14 @@ static void nf_flow_table_do_cleanup(struct nf_flowtable *flow_table, struct net_device *dev = data; if (!dev) { - flow_offload_teardown(flow); + flow_offload_teardown(flow_table, flow); return; } if (net_eq(nf_ct_net(flow->ct), dev_net(dev)) && (flow->tuplehash[0].tuple.iifidx == dev->ifindex || flow->tuplehash[1].tuple.iifidx == dev->ifindex)) - flow_offload_teardown(flow); + flow_offload_teardown(flow_table, flow); } void nf_flow_table_gc_cleanup(struct nf_flowtable *flowtable, diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c index 19efba1e51ef..9c97b9994a96 100644 --- a/net/netfilter/nf_flow_table_ip.c +++ b/net/netfilter/nf_flow_table_ip.c @@ -18,7 +18,8 @@ #include #include -static int nf_flow_state_check(struct flow_offload *flow, int proto, +static int nf_flow_state_check(struct nf_flowtable *flow_table, + struct flow_offload *flow, int proto, struct sk_buff *skb, unsigned int thoff) { struct tcphdr *tcph; @@ -28,7 +29,7 @@ static int nf_flow_state_check(struct flow_offload *flow, int proto, tcph = (void *)(skb_network_header(skb) + thoff); if (unlikely(tcph->fin || tcph->rst)) { - flow_offload_teardown(flow); + flow_offload_teardown(flow_table, flow); return -1; } @@ -373,11 +374,11 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, iph = (struct iphdr *)(skb_network_header(skb) + offset); thoff = (iph->ihl * 4) + offset; - if (nf_flow_state_check(flow, iph->protocol, skb, thoff)) + if (nf_flow_state_check(flow_table, flow, iph->protocol, skb, thoff)) return NF_ACCEPT; if (!nf_flow_dst_check(&tuplehash->tuple)) { - flow_offload_teardown(flow); + flow_offload_teardown(flow_table, flow); return NF_ACCEPT; } @@ -419,7 +420,7 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, case FLOW_OFFLOAD_XMIT_DIRECT: ret = nf_flow_queue_xmit(state->net, skb, tuplehash, ETH_P_IP); if (ret == NF_DROP) - flow_offload_teardown(flow); + flow_offload_teardown(flow_table, flow); break; default: WARN_ON_ONCE(1); @@ -639,11 +640,11 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb, ip6h = (struct ipv6hdr *)(skb_network_header(skb) + offset); thoff = sizeof(*ip6h) + offset; - if (nf_flow_state_check(flow, ip6h->nexthdr, skb, thoff)) + if (nf_flow_state_check(flow_table, flow, ip6h->nexthdr, skb, thoff)) return NF_ACCEPT; if (!nf_flow_dst_check(&tuplehash->tuple)) { - flow_offload_teardown(flow); + flow_offload_teardown(flow_table, flow); return NF_ACCEPT; } @@ -684,7 +685,7 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb, case FLOW_OFFLOAD_XMIT_DIRECT: ret = nf_flow_queue_xmit(state->net, skb, tuplehash, ETH_P_IPV6); if (ret == NF_DROP) - flow_offload_teardown(flow); + flow_offload_teardown(flow_table, flow); break; default: WARN_ON_ONCE(1); diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c index 0ca2bb8ed026..861305c9c079 100644 --- a/net/sched/act_ct.c +++ b/net/sched/act_ct.c @@ -274,8 +274,41 @@ static int tcf_ct_flow_table_fill_actions(struct net *net, return err; } +static bool tcf_ct_flow_table_get_timeout(struct nf_flowtable *ft, + struct flow_offload *flow, + s32 *val) +{ + struct nf_conn *ct = flow->ct; + int l4num = + nf_ct_protonum(ct); + struct net *net = + nf_ct_net(ct); + + if (l4num == IPPROTO_TCP) { + struct nf_tcp_net *tn = nf_tcp_pernet(net); + + ct->proto.tcp.seen[0].td_maxwin = 0; + ct->proto.tcp.seen[1].td_maxwin = 0; + *val = tn->timeouts[ct->proto.tcp.state]; + *val -= tn->offload_timeout; + } else if (l4num == IPPROTO_UDP) { + struct nf_udp_net *tn = nf_udp_pernet(net); + enum udp_conntrack state = + test_bit(IPS_SEEN_REPLY_BIT, &ct->status) ? + UDP_CT_REPLIED : UDP_CT_UNREPLIED; + + *val = tn->timeouts[state]; + *val -= tn->offload_timeout; + } else { + return false; + } + + return true; +} + static struct nf_flowtable_type flowtable_ct = { .action = tcf_ct_flow_table_fill_actions, + .timeout = tcf_ct_flow_table_get_timeout, .owner = THIS_MODULE, }; @@ -622,7 +655,7 @@ static bool tcf_ct_flow_table_lookup(struct tcf_ct_params *p, ct = flow->ct; if (tcph && (unlikely(tcph->fin || tcph->rst))) { - flow_offload_teardown(flow); + flow_offload_teardown(nf_ft, flow); return false; } From patchwork Tue Jan 24 14:02:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlad Buslov X-Patchwork-Id: 13114178 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9BB5C54EAA for ; Tue, 24 Jan 2023 14:04:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234189AbjAXOEG (ORCPT ); Tue, 24 Jan 2023 09:04:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234591AbjAXODw (ORCPT ); Tue, 24 Jan 2023 09:03:52 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2083.outbound.protection.outlook.com [40.107.93.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF58342DD7; Tue, 24 Jan 2023 06:03:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mMVMTd/+8vxqrMXvh4o9+Ny0W7MUY/S2sQpeeuZCJQH+VXIQWllJtLrQ7XqZF2Tepff4M/WMPSxFvj1OHRWoCHEDxV4CtSzJuIjVbgQzGCkAAVa9Ux/J8qrVhf6gQMHOsHeIS5Hc4naX4tUOOEFPOQLnWTUFpEyZMh4O8YaHNBiiwdvT79VXMZD9hUYnCjsDO6uhkGulafJBB5ryQwqik/8GPUQVijNK3nvUuJxRjT+0S4Jl3Te5Ov/60NS+FAkYK83Cwx1PakiXsW10XXgPyvZhwkPGpyx6584l7aOGALbgNXyjG/5EVs6R0YnbOmVQa2SshZsBmaFhWTkMwo05JQ== 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=jiEHwNRseUOKk2qsnr28Ib/6wkMAHi8nqCcurGrTgE8=; b=RaRQ6HgQOkrwC8IWEEjtvCVx7xqcepKpBNo4lj88SKTBGFZGyityWQ1jRyROcSBvRqsLrsmGf2CyDWa3gBkgFpXE37qOjTsh+pqg1JCX7X/8kCLK0k8mQ7jAHIg4Kveqh5IuYxn7uAIiy4NIWUAm+VckdibkvaJzgcjoQ6ZLcrYt3gqHLUR/DvcS0VecA5YrzV4iI41QTKZg3IZAnrgEbwMZVYACT3md9xyFOIWFTAckkGNxVSKIIbbHV1d4lHDYx+LKM0bXEidqjoltW+8y9lR23kSJghzQd/79/Y5+Iq65cK0AEI6CD8USottE6KkQomMPNxmgb8NxMP3Hg+RNyA== 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=jiEHwNRseUOKk2qsnr28Ib/6wkMAHi8nqCcurGrTgE8=; b=bUqLCHcr88+JG/aFzFqvJsbrh8pet8+ZmYqMyJC+O6CaZxmntIEKtqwinPBiOffuj2PCPN2YOeiZascI1eN1GBv0Ehy12QcIZfqz7Yrzet7AZjcYilpMxDZaCgXfvIqGvohoosQIOLM9RJXXGq9KidyRPCRdLgrT36vO0W5nqVR711867mvxQeTnHuF3u4SJAVIwDSYsiXoJMig59Z7y/m7WZDpzFTUSL/Yd73jj/Th30/2WIF7YNGUoNqocwB2ClLtm1oqbEGL0QfCQYr1FUtaX8MyycP0DPb2weVl2togGhzFQiV0MJD71gXg+UF35o14rm9ad1ukyLPoH174fSQ== Received: from BN9PR03CA0243.namprd03.prod.outlook.com (2603:10b6:408:ff::8) by SA1PR12MB7039.namprd12.prod.outlook.com (2603:10b6:806:24e::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33; Tue, 24 Jan 2023 14:03:21 +0000 Received: from BN8NAM11FT065.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ff:cafe::15) by BN9PR03CA0243.outlook.office365.com (2603:10b6:408:ff::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33 via Frontend Transport; Tue, 24 Jan 2023 14:03:21 +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 BN8NAM11FT065.mail.protection.outlook.com (10.13.177.63) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6023.16 via Frontend Transport; Tue, 24 Jan 2023 14:03:20 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) 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.36; Tue, 24 Jan 2023 06:03:00 -0800 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Tue, 24 Jan 2023 06:03:00 -0800 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.36 via Frontend Transport; Tue, 24 Jan 2023 06:02:57 -0800 From: Vlad Buslov To: , , , CC: , , , , , , , , Vlad Buslov Subject: [PATCH net-next v4 3/7] netfilter: flowtable: allow unidirectional rules Date: Tue, 24 Jan 2023 15:02:03 +0100 Message-ID: <20230124140207.3975283-4-vladbu@nvidia.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230124140207.3975283-1-vladbu@nvidia.com> References: <20230124140207.3975283-1-vladbu@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT065:EE_|SA1PR12MB7039:EE_ X-MS-Office365-Filtering-Correlation-Id: 1ea236de-c524-4651-93b7-08dafe13c02c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sV04RJYNhwrctf6UJU6gbdNk6bK+hvOvrpcLmmL9HFDseoieSS1vnHr68vRKsD1mhZjpFZ7cOU6kUtifgu7ssPSv3cV2iZoKYEmPBKpGUEhbMgszR9JqGTdKX25bZIoUGE1n4vNhITyrhpSvsEMh+/FWoRMpZyJdRW3wUfjfKJZrXXdcahUFc54MsAsrOLk7lAvQ8RxEP2mxB+rfw6n1GnFfvVfjzDjWC903rNiKLllrLa7b/vtKIf/sxBDHkQZ/S9Rk8Rd57eXPhU306OAan/10cP61LoR9gRKvUoktJ0dkly1pH7199v8DjLHKu3skL8KpXo4T/wBmDXjjF8nLbwCJvLRFCzp5uHAt+emZYOZOa00MONzmXPrJ/hRhIkpVE5OdtypsCWM9vNBPJyd8B2dTWlQYsYXnEVsupeLr0tLDcVxYHL9BSI6PVrw0JgxzwQu12xK98maG8Lxn3TZIGHLcCHV6/atrgba5rCPAwYCUSPclDAFrFvmu98HhvKv7POyn9yvBomUAEZMPp/Dhk32qpuX9THDq06XwPFygMDONV+eCj/fswoBKypWgcU72MjB9XWiSRNj/HLddlEfruIr1WnEcEFu4MvToogN6PDUg7LsDQ4e/5lwxIyS9QdryMVFCPsbYJhXw5XfPH/nPsiSSca3Uen0M8TawHF7xMPAB8L6gGdDO7KXbQKDjk9FH774GH7iqeidz8VC/+4KfM5/de7DEdMvDnk6+DhJbvog= 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:(13230022)(4636009)(39860400002)(136003)(346002)(396003)(376002)(451199015)(46966006)(40470700004)(36840700001)(7636003)(82740400003)(40460700003)(36756003)(40480700001)(356005)(82310400005)(86362001)(478600001)(316002)(336012)(110136005)(8676002)(70206006)(70586007)(4326008)(2616005)(426003)(47076005)(7696005)(54906003)(2906002)(1076003)(36860700001)(83380400001)(6666004)(5660300002)(41300700001)(26005)(186003)(107886003)(7416002)(8936002)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2023 14:03:20.6295 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1ea236de-c524-4651-93b7-08dafe13c02c 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: BN8NAM11FT065.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7039 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Modify flow table offload to support unidirectional connections by extending enum nf_flow_flags with new "NF_FLOW_HW_BIDIRECTIONAL" flag. Only offload reply direction when the flag is set. This infrastructure change is necessary to support offloading UDP NEW connections in original direction in following patches in series. Signed-off-by: Vlad Buslov --- Notes: Changes V2 -> V3: - Fix error in commit message (spotted by Marcelo). include/net/netfilter/nf_flow_table.h | 1 + net/netfilter/nf_flow_table_offload.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/net/netfilter/nf_flow_table.h b/include/net/netfilter/nf_flow_table.h index a3e4b5127ad0..103798ae10fc 100644 --- a/include/net/netfilter/nf_flow_table.h +++ b/include/net/netfilter/nf_flow_table.h @@ -167,6 +167,7 @@ enum nf_flow_flags { NF_FLOW_HW_DYING, NF_FLOW_HW_DEAD, NF_FLOW_HW_PENDING, + NF_FLOW_HW_BIDIRECTIONAL, }; enum flow_offload_type { diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c index 4d9b99abe37d..8b852f10fab4 100644 --- a/net/netfilter/nf_flow_table_offload.c +++ b/net/netfilter/nf_flow_table_offload.c @@ -895,8 +895,9 @@ static int flow_offload_rule_add(struct flow_offload_work *offload, ok_count += flow_offload_tuple_add(offload, flow_rule[0], FLOW_OFFLOAD_DIR_ORIGINAL); - ok_count += flow_offload_tuple_add(offload, flow_rule[1], - FLOW_OFFLOAD_DIR_REPLY); + if (test_bit(NF_FLOW_HW_BIDIRECTIONAL, &offload->flow->flags)) + ok_count += flow_offload_tuple_add(offload, flow_rule[1], + FLOW_OFFLOAD_DIR_REPLY); if (ok_count == 0) return -ENOENT; @@ -926,7 +927,8 @@ static void flow_offload_work_del(struct flow_offload_work *offload) { clear_bit(IPS_HW_OFFLOAD_BIT, &offload->flow->ct->status); flow_offload_tuple_del(offload, FLOW_OFFLOAD_DIR_ORIGINAL); - flow_offload_tuple_del(offload, FLOW_OFFLOAD_DIR_REPLY); + if (test_bit(NF_FLOW_HW_BIDIRECTIONAL, &offload->flow->flags)) + flow_offload_tuple_del(offload, FLOW_OFFLOAD_DIR_REPLY); set_bit(NF_FLOW_HW_DEAD, &offload->flow->flags); } @@ -946,7 +948,9 @@ static void flow_offload_work_stats(struct flow_offload_work *offload) u64 lastused; flow_offload_tuple_stats(offload, FLOW_OFFLOAD_DIR_ORIGINAL, &stats[0]); - flow_offload_tuple_stats(offload, FLOW_OFFLOAD_DIR_REPLY, &stats[1]); + if (test_bit(NF_FLOW_HW_BIDIRECTIONAL, &offload->flow->flags)) + flow_offload_tuple_stats(offload, FLOW_OFFLOAD_DIR_REPLY, + &stats[1]); lastused = max_t(u64, stats[0].lastused, stats[1].lastused); offload->flow->timeout = max_t(u64, offload->flow->timeout, From patchwork Tue Jan 24 14:02:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlad Buslov X-Patchwork-Id: 13114177 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05856C54E94 for ; Tue, 24 Jan 2023 14:04:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234705AbjAXOEF (ORCPT ); Tue, 24 Jan 2023 09:04:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234262AbjAXODv (ORCPT ); Tue, 24 Jan 2023 09:03:51 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2080.outbound.protection.outlook.com [40.107.94.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58F7E135; Tue, 24 Jan 2023 06:03:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aSYieJRchEwxqWe1d2Hlhmwx+Di1Pkq05Bm9H6aS1UY9rZ6le+GxHfauQtzUsB1seczfL+gm8CbWz11oQeT7Z0QTu7EThrV+OSO6o/frcIqqC99f3ILeynOcubg3T1Eit3nvaWVOfmsabgioX2xcMzq8gYXZkO3XkIlDOdkT5NmrVG8hwmBU4ricXUCafawBuPy4XJLtEzZ1CeXQXBnyDhb1GMJisVhwz4z08g+llNk6td2TbZRAV3FIkS/sIiUE07TOEXVdGLPJstau/fyOYbThwsq09PNPfD10id4Gh6Lm2BmDHgTIqYpMtqXGEL+XP4M9wUYJslJfvqDFuFH0aA== 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=4MqW2wuBqP+NUSb1oqVUHY/8syLIRcYnfLrWqhyD3oQ=; b=RruCAl0QkWIXrwLWFMg85MHhYdbBLFhzNIkaVJuuD7hLcQU3LTusp9VqCgJwQcCL8CtwS9inWckS0U77CZIKcoqRbQhTq0WyCvHAikuigQNH18S7s+nU02z399HAU9jWJFWSI3JIXfVdO6fqLUTnksd4WRgS+ZyrfVO2j+14RvVXKQaGtxx9F+L/grWQuNdfd4kNLgWP7/8e0KkiwRmsR6ZI7O1B8wRiN9PSSmVWk8d5Nm2cweczuoe5bzh9ea/1OF9anDvNpmNlyWWK1I8dsf61tgUs5F/JwyIbmwLOXMUk0Dsibn1b9HguaTlvDRgwTgC+zuEZAzl9XLdArgEJ0A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=4MqW2wuBqP+NUSb1oqVUHY/8syLIRcYnfLrWqhyD3oQ=; b=LJL1NiafPFWHhLByV6rNdRqBgdGenn4EsPWXbNE2lMJfH4Uiy6C+VNcDXHTWORlJavna/OdGxpE94tGm3aCvfzDdw+NmF/ScennTYuYztAr2U6CCcUGv3s+7oW3cdFk23cdiYgN08QbWmjMotci0gEF7Upm68GQAtT6WNPOfmECzQkgEtHPWhJ0XtG0b6HJ2SZPWmfYCRY/yc9yEzjqpVBQMR5kV1iCZ4LyW7kLJWv+f4RT0u9YqwwjxGSg/cvdPfBlJ+TMGfNWWQuYt2LkurvGJrdiYocoGihholfGN1/jbgz2RwT9pWPZl2emxC8sWOAgjCDFY2YXDtyR8OfkcRg== Received: from DM6PR14CA0058.namprd14.prod.outlook.com (2603:10b6:5:18f::35) by IA1PR12MB7760.namprd12.prod.outlook.com (2603:10b6:208:422::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33; Tue, 24 Jan 2023 14:03:21 +0000 Received: from DM6NAM11FT072.eop-nam11.prod.protection.outlook.com (2603:10b6:5:18f:cafe::54) by DM6PR14CA0058.outlook.office365.com (2603:10b6:5:18f::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33 via Frontend Transport; Tue, 24 Jan 2023 14:03:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by DM6NAM11FT072.mail.protection.outlook.com (10.13.173.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6023.16 via Frontend Transport; Tue, 24 Jan 2023 14:03:20 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Tue, 24 Jan 2023 06:03:04 -0800 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Tue, 24 Jan 2023 06:03:04 -0800 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.36 via Frontend Transport; Tue, 24 Jan 2023 06:03:01 -0800 From: Vlad Buslov To: , , , CC: , , , , , , , , Vlad Buslov Subject: [PATCH net-next v4 4/7] netfilter: flowtable: save ctinfo in flow_offload Date: Tue, 24 Jan 2023 15:02:04 +0100 Message-ID: <20230124140207.3975283-5-vladbu@nvidia.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230124140207.3975283-1-vladbu@nvidia.com> References: <20230124140207.3975283-1-vladbu@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT072:EE_|IA1PR12MB7760:EE_ X-MS-Office365-Filtering-Correlation-Id: b25a715a-b0b2-419d-9713-08dafe13bfdd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +Qlfzg5s0TzziKKi/qs2Y1TQk1ao/h6izdAO/iitXq5uBcmexfAaVLmUrjFUXVzWYL1tBLPq0vadgVfSbsc5BtOKYpYxkYqzeZ0gkyxOzFy/jUtRyD7qnvKY1EgeG9miWaeZvBTxlgN4093wcvzrT6IzQy1SxIJ2/vwEYauvc8AXbxX0Ogj5SJUWww2xrRyWVgyCzKX+XEGA1GxXncTA/ZNxTy2DKANBYPPcbjA6I8bWbfYR3oltvRxUpSCLCIs7IFxX0gN2dbxK9/gvn9sNu2j4PCC0JF1JuKFgH9U4Rliaom05JMEwwYXcuOL3scyIwyFeN+SxvFuZV390uLmNUhIjspDj3g+WqI/uQ9tP8ETW8i5J1k55KwGA66hogDfbcLo51Cro/N4AlRMzYF0Ky2QruyWhMpeM05+v7MYuh8YB/VzjyX2hRWK2fIVJeUsy5NQly9U+QB03+vHUwsJmKDEXmkspPl3MgNxCByRN33EmzO6kQBY+iEHZJ1RpQdnBko7N3VK7GPa/CNMgCV44OkCU2ZCNsw4gfCnRHQ05yQ6BPGKMr0Laivt0/EgxA+iaA7cFEeiD/xmLsCVSgUZTnksgyFANwf5IIgPiPf8DcsF/10wsZe/YUAHBDLZYJf+f39NvVeKdCDIcV7hkJOpmjFdbuMExzMPheVwXZyuozKUoBKnKoa9XMMN+pu/zIFYzoeGSsUFA3XrQ2PxtcTbKD1GgDjAcl917ckNlzIdjf3s= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230022)(4636009)(346002)(136003)(376002)(396003)(39860400002)(451199015)(46966006)(40470700004)(36840700001)(36756003)(86362001)(5660300002)(82740400003)(7636003)(356005)(7416002)(82310400005)(8936002)(2906002)(4326008)(41300700001)(83380400001)(36860700001)(7696005)(478600001)(110136005)(186003)(26005)(40480700001)(8676002)(40460700003)(70206006)(316002)(70586007)(54906003)(2616005)(1076003)(47076005)(426003)(107886003)(336012)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2023 14:03:20.1431 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b25a715a-b0b2-419d-9713-08dafe13bfdd 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT072.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7760 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Extend struct flow_offload with generic 'ext_data' field. Use the field in act_ct to cache the last ctinfo value that was used to update the hardware offload when generating the actions. This is used to optimize the flow refresh algorithm in following patches. Signed-off-by: Vlad Buslov --- Notes: Changes V3 -> V4: - New patch replaces gc async update that is no longer needed after refactoring of following act_ct patches. include/net/netfilter/nf_flow_table.h | 7 ++++--- net/netfilter/nf_flow_table_inet.c | 2 +- net/netfilter/nf_flow_table_offload.c | 6 +++--- net/sched/act_ct.c | 12 +++++++----- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/include/net/netfilter/nf_flow_table.h b/include/net/netfilter/nf_flow_table.h index 103798ae10fc..6f3250624d49 100644 --- a/include/net/netfilter/nf_flow_table.h +++ b/include/net/netfilter/nf_flow_table.h @@ -57,7 +57,7 @@ struct nf_flowtable_type { struct net_device *dev, enum flow_block_command cmd); int (*action)(struct net *net, - const struct flow_offload *flow, + struct flow_offload *flow, enum flow_offload_tuple_dir dir, struct nf_flow_rule *flow_rule); void (*free)(struct nf_flowtable *ft); @@ -178,6 +178,7 @@ enum flow_offload_type { struct flow_offload { struct flow_offload_tuple_rhash tuplehash[FLOW_OFFLOAD_DIR_MAX]; struct nf_conn *ct; + void *ext_data; unsigned long flags; u16 type; u32 timeout; @@ -317,10 +318,10 @@ void nf_flow_table_offload_flush_cleanup(struct nf_flowtable *flowtable); int nf_flow_table_offload_setup(struct nf_flowtable *flowtable, struct net_device *dev, enum flow_block_command cmd); -int nf_flow_rule_route_ipv4(struct net *net, const struct flow_offload *flow, +int nf_flow_rule_route_ipv4(struct net *net, struct flow_offload *flow, enum flow_offload_tuple_dir dir, struct nf_flow_rule *flow_rule); -int nf_flow_rule_route_ipv6(struct net *net, const struct flow_offload *flow, +int nf_flow_rule_route_ipv6(struct net *net, struct flow_offload *flow, enum flow_offload_tuple_dir dir, struct nf_flow_rule *flow_rule); diff --git a/net/netfilter/nf_flow_table_inet.c b/net/netfilter/nf_flow_table_inet.c index 0ccabf3fa6aa..9505f9d188ff 100644 --- a/net/netfilter/nf_flow_table_inet.c +++ b/net/netfilter/nf_flow_table_inet.c @@ -39,7 +39,7 @@ nf_flow_offload_inet_hook(void *priv, struct sk_buff *skb, } static int nf_flow_rule_route_inet(struct net *net, - const struct flow_offload *flow, + struct flow_offload *flow, enum flow_offload_tuple_dir dir, struct nf_flow_rule *flow_rule) { diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c index 8b852f10fab4..1c26f03fc661 100644 --- a/net/netfilter/nf_flow_table_offload.c +++ b/net/netfilter/nf_flow_table_offload.c @@ -679,7 +679,7 @@ nf_flow_rule_route_common(struct net *net, const struct flow_offload *flow, return 0; } -int nf_flow_rule_route_ipv4(struct net *net, const struct flow_offload *flow, +int nf_flow_rule_route_ipv4(struct net *net, struct flow_offload *flow, enum flow_offload_tuple_dir dir, struct nf_flow_rule *flow_rule) { @@ -704,7 +704,7 @@ int nf_flow_rule_route_ipv4(struct net *net, const struct flow_offload *flow, } EXPORT_SYMBOL_GPL(nf_flow_rule_route_ipv4); -int nf_flow_rule_route_ipv6(struct net *net, const struct flow_offload *flow, +int nf_flow_rule_route_ipv6(struct net *net, struct flow_offload *flow, enum flow_offload_tuple_dir dir, struct nf_flow_rule *flow_rule) { @@ -735,7 +735,7 @@ nf_flow_offload_rule_alloc(struct net *net, { const struct nf_flowtable *flowtable = offload->flowtable; const struct flow_offload_tuple *tuple, *other_tuple; - const struct flow_offload *flow = offload->flow; + struct flow_offload *flow = offload->flow; struct dst_entry *other_dst = NULL; struct nf_flow_rule *flow_rule; int err = -ENOMEM; diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c index 861305c9c079..48b88c96de86 100644 --- a/net/sched/act_ct.c +++ b/net/sched/act_ct.c @@ -170,11 +170,11 @@ tcf_ct_flow_table_add_action_nat_udp(const struct nf_conntrack_tuple *tuple, static void tcf_ct_flow_table_add_action_meta(struct nf_conn *ct, enum ip_conntrack_dir dir, + enum ip_conntrack_info ctinfo, struct flow_action *action) { struct nf_conn_labels *ct_labels; struct flow_action_entry *entry; - enum ip_conntrack_info ctinfo; u32 *act_ct_labels; entry = tcf_ct_flow_table_flow_action_get_next(action); @@ -182,8 +182,6 @@ static void tcf_ct_flow_table_add_action_meta(struct nf_conn *ct, #if IS_ENABLED(CONFIG_NF_CONNTRACK_MARK) entry->ct_metadata.mark = READ_ONCE(ct->mark); #endif - ctinfo = dir == IP_CT_DIR_ORIGINAL ? IP_CT_ESTABLISHED : - IP_CT_ESTABLISHED_REPLY; /* aligns with the CT reference on the SKB nf_ct_set */ entry->ct_metadata.cookie = (unsigned long)ct | ctinfo; entry->ct_metadata.orig_dir = dir == IP_CT_DIR_ORIGINAL; @@ -237,22 +235,26 @@ static int tcf_ct_flow_table_add_action_nat(struct net *net, } static int tcf_ct_flow_table_fill_actions(struct net *net, - const struct flow_offload *flow, + struct flow_offload *flow, enum flow_offload_tuple_dir tdir, struct nf_flow_rule *flow_rule) { struct flow_action *action = &flow_rule->rule->action; int num_entries = action->num_entries; struct nf_conn *ct = flow->ct; + enum ip_conntrack_info ctinfo; enum ip_conntrack_dir dir; int i, err; switch (tdir) { case FLOW_OFFLOAD_DIR_ORIGINAL: dir = IP_CT_DIR_ORIGINAL; + ctinfo = IP_CT_ESTABLISHED; + WRITE_ONCE(flow->ext_data, (void *)ctinfo); break; case FLOW_OFFLOAD_DIR_REPLY: dir = IP_CT_DIR_REPLY; + ctinfo = IP_CT_ESTABLISHED_REPLY; break; default: return -EOPNOTSUPP; @@ -262,7 +264,7 @@ static int tcf_ct_flow_table_fill_actions(struct net *net, if (err) goto err_nat; - tcf_ct_flow_table_add_action_meta(ct, dir, action); + tcf_ct_flow_table_add_action_meta(ct, dir, ctinfo, action); return 0; err_nat: From patchwork Tue Jan 24 14:02:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlad Buslov X-Patchwork-Id: 13114179 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D60EC38142 for ; Tue, 24 Jan 2023 14:04:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234819AbjAXOES (ORCPT ); Tue, 24 Jan 2023 09:04:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234771AbjAXOEH (ORCPT ); Tue, 24 Jan 2023 09:04:07 -0500 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2077.outbound.protection.outlook.com [40.107.92.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C26E88A7F; Tue, 24 Jan 2023 06:03:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fuyB31zh3Ov7W0fKolmYmL3ilwibfp47fsfYnRo2Y4cBbYjwYUjT2aReGp5dtjF3puz6eyIR3QJrTF9zR1CiXJyBh4BlWlTuTD55MEbQVO/5Gf9aLZwzegJIvymOdm0L/OS7O0pLTLW+su+qBnJ4vvzo9INrXJgdkdss49mXZAwdlDnC/gbZ8tyXqa2Fcv/AOZswHR1HYPW0x9TeQzImHwXMlyQQ8Q9Fr8lB6F9WHG+BOxGP+lHQRYEXT2oYGESFgttkQRYi0+I5YlOcBYuXEBn5dADbH4C8dgsTlFnu5bRgf3Yy8hoKtKvxWPhruXePBRy2+txDc8axy6r/ZjnNOQ== 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=Fc5chHB3Hj+JbD878mPb0uD62fVD37gKGI4Eclruct0=; b=fzZCj6FhN1GDNYsD7ZvmNQqhj94Vjhx92+HHwkhyh+Afsc/Iiq/riQfU1auHFc57qMKbSU8NJlYj0Z73jZHQwWkI+vU4aP2RQrQKw4LQSYKO8dhj/BboV4qIUNHpjy+Hggjmq0c3dphRM2T92tgCgcYnYvGXYRznJm6IzJ3pci+JBGBHJPkCjBdeMLrQVycGP0pdeJURb34BtJy1cV9Lj4lujrtBd27A0K/yAOCLJ6heoihZkhEI1rhCpsp3pTz9VNNNv+fythsXZZHTaaCK0eMufAMxysBgxlBMJBrP0WhvbBk1OwQlD1x9ZXUGDWGAMTbIqk35R20DIctP5T1R1g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=Fc5chHB3Hj+JbD878mPb0uD62fVD37gKGI4Eclruct0=; b=lRn3wOmxwqh60g3pADvu9wzMGwGkyw08jGPJfF1Sfjr4W1vyMvhuBgpTWiYRKKSFph484QmhimODIV0CnjzC0jaXCieiau1t9l/YvkwtHZEflTUAP5BxpWxv8Zq2o4gA5C4rB/Ch3vOSqow14plnqJ/ncrAbv8c66ZSKrwioUT3yZrnm+1HluxD3dMbVZM2gDdEfa0zahdfkK7omv4dXYpsEDoRMG+qP2TBMqitpbKQ+1tCvsnAoiG6ZBwaukLco7VRP6BBaLv+kTL3Ggos2SAFxXHpuDDnkSUp8p3sftWWoBCGNcHGVBW9a/ntcRaHn7iUFMK5SF52rmYvF60KfFQ== Received: from DM6PR18CA0035.namprd18.prod.outlook.com (2603:10b6:5:15b::48) by MW4PR12MB7360.namprd12.prod.outlook.com (2603:10b6:303:22b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33; Tue, 24 Jan 2023 14:03:25 +0000 Received: from DM6NAM11FT020.eop-nam11.prod.protection.outlook.com (2603:10b6:5:15b:cafe::72) by DM6PR18CA0035.outlook.office365.com (2603:10b6:5:15b::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33 via Frontend Transport; Tue, 24 Jan 2023 14:03:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by DM6NAM11FT020.mail.protection.outlook.com (10.13.172.224) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6023.16 via Frontend Transport; Tue, 24 Jan 2023 14:03:24 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Tue, 24 Jan 2023 06:03:08 -0800 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Tue, 24 Jan 2023 06:03:08 -0800 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.36 via Frontend Transport; Tue, 24 Jan 2023 06:03:04 -0800 From: Vlad Buslov To: , , , CC: , , , , , , , , Vlad Buslov Subject: [PATCH net-next v4 5/7] net/sched: act_ct: set ctinfo in meta action depending on ct state Date: Tue, 24 Jan 2023 15:02:05 +0100 Message-ID: <20230124140207.3975283-6-vladbu@nvidia.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230124140207.3975283-1-vladbu@nvidia.com> References: <20230124140207.3975283-1-vladbu@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT020:EE_|MW4PR12MB7360:EE_ X-MS-Office365-Filtering-Correlation-Id: dfd4c832-040c-43d8-d323-08dafe13c269 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: L0AfHpn8qhJTZT4+8xCnN16RX+AzjNevK5sHQeAfQrvxjLltUwJD/b6ORW+jFyOU5K5ELLosLTC4VnV3HoaoJgyqrLemCQwJHYttbHGTGLRvsvgxJx/tnu4JMc8wBMc56kMrq11Q9xKVrwBsTzq00xKzU8z/T9Ln4ahjQA/3Roo8kRWyPpXZRsIn/qSjxLlsajnWfgkP8oCBYq+TFLaF19m09u2OpNLBJmWOLex4yo2Oy7tmBy2JH3IOLLoGkHSLq0T0003TXmbhHzNkT06ut+GEhbA9yJdmHiqrwE4X7aizDgsAhX3nePij5AyRr7+P8DyHzQy3TmJ/qfNgZrx97auxSTIRxOp0l+ymt/dRH/Q7zsnRbaNqmcsaIJ0jxwEkhTv5yWa9RcBb9mS6D7wH/N/7145JT13DSjRr1X834zOAqJyQEgLVj2ZiabNkT9wF2kRDaOqeKFRWGGExTKTy9wfVjn/ONu6QQ16ladepD6K1MsgZUCJb3wP1cpyNvl1KospCiZ23bbNw6umDNz3jAkBdqMKmt/9MKhDyVveQGh+3HuvJqD1vjQHbtlotNPW1B86BC2fnnjvlS/719vrmLNsyVB5SzEjvEfMELBu4YG98Tp8gWWRL+3ddmW/QQIJ/ZM8aRuQ4PY5G7UVcUAdmzGjwQVQ7PCbdW7n3exPB0Ec+8OHskPzbIIA1aJNTmzro87KgT/QQjBbHJTMavU4tkGKLUqEXx3I7icnCoTOv8QLNgf2E7jjBzgLY6+O1Li9ezaj3CfQ71B4MwEJvsrJkAg== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230022)(4636009)(346002)(39860400002)(136003)(396003)(376002)(451199015)(40470700004)(46966006)(36840700001)(36756003)(82740400003)(2906002)(5660300002)(356005)(7416002)(7636003)(8936002)(4326008)(82310400005)(41300700001)(4744005)(83380400001)(36860700001)(86362001)(40460700003)(478600001)(7696005)(110136005)(40480700001)(26005)(186003)(8676002)(316002)(54906003)(70206006)(2616005)(336012)(1076003)(426003)(107886003)(70586007)(47076005)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2023 14:03:24.4333 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dfd4c832-040c-43d8-d323-08dafe13c269 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT020.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7360 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Currently tcf_ct_flow_table_add_action_meta() function assumes that only established connections can be offloaded and always sets ctinfo to either IP_CT_ESTABLISHED or IP_CT_ESTABLISHED_REPLY strictly based on direction without checking actual connection state. To enable UDP NEW connection offload set the ctinfo and metadata cookie based on ct->status value. Signed-off-by: Vlad Buslov --- net/sched/act_ct.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c index 48b88c96de86..2b81a7898662 100644 --- a/net/sched/act_ct.c +++ b/net/sched/act_ct.c @@ -249,7 +249,8 @@ static int tcf_ct_flow_table_fill_actions(struct net *net, switch (tdir) { case FLOW_OFFLOAD_DIR_ORIGINAL: dir = IP_CT_DIR_ORIGINAL; - ctinfo = IP_CT_ESTABLISHED; + ctinfo = test_bit(IPS_SEEN_REPLY_BIT, &ct->status) ? + IP_CT_ESTABLISHED : IP_CT_NEW; WRITE_ONCE(flow->ext_data, (void *)ctinfo); break; case FLOW_OFFLOAD_DIR_REPLY: From patchwork Tue Jan 24 14:02:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlad Buslov X-Patchwork-Id: 13114180 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B423C25B4E for ; Tue, 24 Jan 2023 14:04:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234589AbjAXOEX (ORCPT ); Tue, 24 Jan 2023 09:04:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233807AbjAXOEO (ORCPT ); Tue, 24 Jan 2023 09:04:14 -0500 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2075.outbound.protection.outlook.com [40.107.244.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9006046728; Tue, 24 Jan 2023 06:03:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JNRRN8bc9BuFjPPyM8vwlzcuzqoSn/etRpcUuMPzhpQdaNA4kZuA5su9BU7oS/GbDc3HFNbRV66ZL49LdLhfXsCIAZTEI45X0pXkVd0okMdpYPuNoMC1RsGYWqwed+KsBBIkPxiU/lV3UB5X9tqxKODwHprSBl5Hl00KZSnvrTu32pNoXFCLdm0yo5IKRSpIdG3zEWemLiETgkloUZdRmB6murxbpC8YmbixJASuDaha1hkc34rgahLgyBFtVIG7IfcoVfrLIxt8Q6NqKnFsn8Dt6/uYDl0qbLt5tLvrzb6uP8J1+B91WMt6qkC8MSVLoUKCNB2sPVfUO/llzJkpsw== 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=sx7rDKIENmpYfMMvC0RZJw+lI6iyP0Ps6js6T3lSVgM=; b=PDnK9UBM0bri74xs0PqpPou+A6X8C05QfI9UBLxxSQ3Yf++Ll2D9qcvBhusIcUtMmB1ucOhfMCoJ7SCWsflR1eJM1gknjjqCPSHg2cOnQloP/6JQZKwvx0SYlXMDM446m6d963Pn6B1mGbNz/dIis8JR46z6WjcN9Kq0ThrSRf4R9p28FmcSBWxQRS5cnDiIbuGYagD/ZN0byEdDf51FwxEcVZSkiYYf6Z5GbV9uBRVf2ROWaikz97WqoPue13/ni0SVcNK6cQAegkPgEIE6LWBdUrxFhtPLEsDRTjhGbKi6vczqfQ3WBRp+N4X4d9GcaLD9Bs1p3FH+mAVe6hvfUQ== 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=sx7rDKIENmpYfMMvC0RZJw+lI6iyP0Ps6js6T3lSVgM=; b=N6PiyMQWUjBAE9NMql0sSpfUIKxb4L+XqrbR8fB0Xyesq/O1HDiF2zYCp+uldP3op5i4fHmBhQR5Eo5WU+2Zmr0YpqsKm9siJwbE1cmXa8qyZtQ9C3JdMBuBlVxFtnwTbxqWaxYL7VMt48HEmTxJ/FeeFLjs+rkt4DUWpQu3VYez6FYgfNuPz7ko0bALcNiQF9GbttrcGnh9S8cP6H1K9BnyeiO6zjXEHu0SsSHl8r9bycdcENiFbwi/dyDZG6XE8LXDUsovFr+WCfwd7UDwx4rs8SC52c0PbGXsQYoT3JTtOSYW5AiViOHPMjk352jwvy/epspzM63BXoxwTLyQKw== Received: from BN9PR03CA0243.namprd03.prod.outlook.com (2603:10b6:408:ff::8) by DM4PR12MB5962.namprd12.prod.outlook.com (2603:10b6:8:69::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33; Tue, 24 Jan 2023 14:03:34 +0000 Received: from BN8NAM11FT065.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ff:cafe::9) by BN9PR03CA0243.outlook.office365.com (2603:10b6:408:ff::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33 via Frontend Transport; Tue, 24 Jan 2023 14:03:34 +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 BN8NAM11FT065.mail.protection.outlook.com (10.13.177.63) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6023.16 via Frontend Transport; Tue, 24 Jan 2023 14:03:33 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) 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.36; Tue, 24 Jan 2023 06:03:12 -0800 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Tue, 24 Jan 2023 06:03:12 -0800 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.36 via Frontend Transport; Tue, 24 Jan 2023 06:03:08 -0800 From: Vlad Buslov To: , , , CC: , , , , , , , , Vlad Buslov Subject: [PATCH net-next v4 6/7] net/sched: act_ct: offload UDP NEW connections Date: Tue, 24 Jan 2023 15:02:06 +0100 Message-ID: <20230124140207.3975283-7-vladbu@nvidia.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230124140207.3975283-1-vladbu@nvidia.com> References: <20230124140207.3975283-1-vladbu@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT065:EE_|DM4PR12MB5962:EE_ X-MS-Office365-Filtering-Correlation-Id: 5c8fb2b4-793f-4cb2-7117-08dafe13c7db X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gbUsaRBJiNUlaf5wDSGpqNBeo06a+KwrRKw3xbeUIVdeawG1ZHkit3947T0fm1O3AC+lrF7ce/LHNFcraVXMQByLRvYTu6OFaqOVgQwVu3Y7eZPyCrwhJHvs7we4oJq/JhejrgHT+LfzUoT0noIxN/4MZraG2/kU8fAXyIA+wlFXiMX3CFdcXJBD3gbZIUQt7YpBcIYo3sn27VAuXrkQnsyEWkCsmPh0oonya87vcYkcHdJn6nXVsN31lrM4pgS4XBmewybNoL9GTKO4jBFNeJbZcTx6MdeOPf6oYX3Yyx74Yrnu3rkqNUJ3WuEJmoDofj+7SLPg1SNIWdAJTlBWgaXIlBTRh2TRvPjTAFdQkwiaBrQerUoNeJsaD16EBCI9MhI8iM+AeTM8cJzezF7zWv9qixpZymiaNprOnZ/lw7bPSSjh4L7ULH5plHNS7jwO6tOZddcoXXxxobZY/GEI+haYrgu/pTktkjRxntz1ct4vNKrqlWmyax5johXgcdIqK1b2Lh10yOA7KSHnA7MQPXBPBT1KMaL37BVjDw25ox24cwi9aWcuilBAiO1aXC2S4hPRYOYIvasKqgm61V7LHsAhsGz41xtaiNiPGHAPRtOLw3bRTt5QpcU8wWcklfDRisJV9yncTGyydVT0n8CfFnmEXcYFB+9ccPwt9R8TVGBUos7dFCjHUpKz8XlnJjyo+OuPOpHrq7vF8ijPQMD8+PZrywyNZKbsUv2Z5ReZfM0= 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:(13230022)(4636009)(376002)(346002)(39860400002)(396003)(136003)(451199015)(40470700004)(36840700001)(46966006)(82310400005)(36756003)(107886003)(478600001)(2906002)(40480700001)(2616005)(7416002)(336012)(186003)(26005)(5660300002)(8936002)(7636003)(356005)(54906003)(36860700001)(47076005)(70206006)(40460700003)(8676002)(110136005)(316002)(426003)(70586007)(83380400001)(4326008)(7696005)(82740400003)(1076003)(86362001)(41300700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2023 14:03:33.5196 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5c8fb2b4-793f-4cb2-7117-08dafe13c7db 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: BN8NAM11FT065.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5962 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Modify the offload algorithm of UDP connections to the following: - Offload NEW connection as unidirectional. - When connection state changes to ESTABLISHED also update the hardware flow. However, in order to prevent act_ct from spamming offload add wq for every packet coming in reply direction in this state verify whether connection has already been updated to ESTABLISHED in the drivers. If that it the case, then skip flow_table and let conntrack handle such packets which will also allow conntrack to potentially promote the connection to ASSURED. - When connection state changes to ASSURED set the flow_table flow NF_FLOW_HW_BIDIRECTIONAL flag which will cause refresh mechanism to offload the reply direction. All other protocols have their offload algorithm preserved and are always offloaded as bidirectional. Note that this change tries to minimize the load on flow_table add workqueue. First, it tracks the last ctinfo that was offloaded by using new flow 'ext_data' field and doesn't schedule the refresh for reply direction packets when the offloads have already been updated with current ctinfo. Second, when 'add' task executes on workqueue it always update the offload with current flow state (by checking 'bidirectional' flow flag and obtaining actual ctinfo/cookie through meta action instead of caching any of these from the moment of scheduling the 'add' work) preventing the need from scheduling more updates if state changed concurrently while the 'add' work was pending on workqueue. Signed-off-by: Vlad Buslov --- Notes: Changes V3 -> V4: - Refactor the patch to leverage the refresh code and new flow 'ext_data' field in order to change the offload state instead of relying on async gc update. net/sched/act_ct.c | 52 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c index 2b81a7898662..355ae48bd371 100644 --- a/net/sched/act_ct.c +++ b/net/sched/act_ct.c @@ -401,7 +401,7 @@ static void tcf_ct_flow_tc_ifidx(struct flow_offload *entry, static void tcf_ct_flow_table_add(struct tcf_ct_flow_table *ct_ft, struct nf_conn *ct, - bool tcp) + bool tcp, bool bidirectional) { struct nf_conn_act_ct_ext *act_ct_ext; struct flow_offload *entry; @@ -420,6 +420,8 @@ static void tcf_ct_flow_table_add(struct tcf_ct_flow_table *ct_ft, ct->proto.tcp.seen[0].flags |= IP_CT_TCP_FLAG_BE_LIBERAL; ct->proto.tcp.seen[1].flags |= IP_CT_TCP_FLAG_BE_LIBERAL; } + if (bidirectional) + __set_bit(NF_FLOW_HW_BIDIRECTIONAL, &entry->flags); act_ct_ext = nf_conn_act_ct_ext_find(ct); if (act_ct_ext) { @@ -443,26 +445,34 @@ static void tcf_ct_flow_table_process_conn(struct tcf_ct_flow_table *ct_ft, struct nf_conn *ct, enum ip_conntrack_info ctinfo) { - bool tcp = false; - - if ((ctinfo != IP_CT_ESTABLISHED && ctinfo != IP_CT_ESTABLISHED_REPLY) || - !test_bit(IPS_ASSURED_BIT, &ct->status)) - return; + bool tcp = false, bidirectional = true; switch (nf_ct_protonum(ct)) { case IPPROTO_TCP: - tcp = true; - if (ct->proto.tcp.state != TCP_CONNTRACK_ESTABLISHED) + if ((ctinfo != IP_CT_ESTABLISHED && + ctinfo != IP_CT_ESTABLISHED_REPLY) || + !test_bit(IPS_ASSURED_BIT, &ct->status) || + ct->proto.tcp.state != TCP_CONNTRACK_ESTABLISHED) return; + + tcp = true; break; case IPPROTO_UDP: + if (!nf_ct_is_confirmed(ct)) + return; + if (!test_bit(IPS_ASSURED_BIT, &ct->status)) + bidirectional = false; break; #ifdef CONFIG_NF_CT_PROTO_GRE case IPPROTO_GRE: { struct nf_conntrack_tuple *tuple; - if (ct->status & IPS_NAT_MASK) + if ((ctinfo != IP_CT_ESTABLISHED && + ctinfo != IP_CT_ESTABLISHED_REPLY) || + !test_bit(IPS_ASSURED_BIT, &ct->status) || + ct->status & IPS_NAT_MASK) return; + tuple = &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple; /* No support for GRE v1 */ if (tuple->src.u.gre.key || tuple->dst.u.gre.key) @@ -478,7 +488,7 @@ static void tcf_ct_flow_table_process_conn(struct tcf_ct_flow_table *ct_ft, ct->status & IPS_SEQ_ADJUST) return; - tcf_ct_flow_table_add(ct_ft, ct, tcp); + tcf_ct_flow_table_add(ct_ft, ct, tcp, bidirectional); } static bool @@ -657,13 +667,31 @@ static bool tcf_ct_flow_table_lookup(struct tcf_ct_params *p, flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]); ct = flow->ct; + if (dir == FLOW_OFFLOAD_DIR_REPLY && + !test_bit(NF_FLOW_HW_BIDIRECTIONAL, &flow->flags)) { + /* Only offload reply direction after connection became + * assured. + */ + if (test_bit(IPS_ASSURED_BIT, &ct->status)) + set_bit(NF_FLOW_HW_BIDIRECTIONAL, &flow->flags); + else if ((enum ip_conntrack_info)READ_ONCE(flow->ext_data) == + IP_CT_ESTABLISHED) + /* If flow_table flow has already been updated to the + * established state, then don't refresh. + */ + return false; + } + if (tcph && (unlikely(tcph->fin || tcph->rst))) { flow_offload_teardown(nf_ft, flow); return false; } - ctinfo = dir == FLOW_OFFLOAD_DIR_ORIGINAL ? IP_CT_ESTABLISHED : - IP_CT_ESTABLISHED_REPLY; + if (dir == FLOW_OFFLOAD_DIR_ORIGINAL) + ctinfo = test_bit(IPS_SEEN_REPLY_BIT, &ct->status) ? + IP_CT_ESTABLISHED : IP_CT_NEW; + else + ctinfo = IP_CT_ESTABLISHED_REPLY; flow_offload_refresh(nf_ft, flow); nf_conntrack_get(&ct->ct_general); From patchwork Tue Jan 24 14:02:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlad Buslov X-Patchwork-Id: 13114181 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2703C54E94 for ; Tue, 24 Jan 2023 14:04:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234715AbjAXOEa (ORCPT ); Tue, 24 Jan 2023 09:04:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234793AbjAXOEQ (ORCPT ); Tue, 24 Jan 2023 09:04:16 -0500 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73449166F4; Tue, 24 Jan 2023 06:03:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bOKHN7G9BTK1GskV3FNEzd/oDZ0dbISqg+wP29pMwzeK0/BqsK1pgznb1mjOLuP1IjGlcb/wcbbCH1hpbLlrmtoALcC7XTtQ0+o1GkBldNakG2oN/JantovAIWq1ds5GqzDsy8OfZ6kao4wfT+gTXHH6D9gfR+aOiJ55Viv6e1XIv7EUuUR3tGX/9xZmRAWGxuugCVpasCUi49Qs2yij4jsdE95hKZCMahC/Eh0Usvb0bByOUzsJts2o+71RgMzScg5+TzAhWqFPxH3MhO/QR5xlUfNPsAZjk1pr4I9Fm1K+3BIYE/Uka3vKZPXt2YCZsbEtvL1TSRdAbQqvltmY7Q== 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=JLcQDuTm7f0BQbsr+DZXqTDP8Fsw23ph80Ixl7U15/8=; b=V3Ib0n8cimV+9C88QEcc+spydU5xnjmmMVtsXA3M34KiawgCIaeqGnhModghoffVSgjMmybAu6NZdrw75xj4EPVyWnfa/RIWvVddaHMKTXR7E6dorUlJyrRO3pgnDK8cMYyN2Zp1Frm9jqzUwne7ESaZsfY+Mv0H0ZEZuRoTdi2YJbrUEY7ls2XDD2o+ekQdTf6aEPKZwgfikINjzvJj53+bJRUbeYK1ML7C9fG65XFps3PJFpbZRHA4sDPaN3x+5P/0uAKv4JJt4rL7ohW6A6gvQlEXgYS/gm1LuwVL6v5qniMQLFGvo0jUB3bTswC6rsP3DoLTdKRk7OSfpNq7MA== 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=JLcQDuTm7f0BQbsr+DZXqTDP8Fsw23ph80Ixl7U15/8=; b=oz06saRn7xf1dRi+BZWsOFAWD2WjzqzgYE4IvmYQ+kPYR4bVLXOHZwmdvwLbLiavGiBgFNA3CbnIjevencL9UT975lEe8aRPSBE+Sy2WeW3YKVnYmQd5t0WBlhQWQRVrOSKKO63Q6P+eg2yBhF4TKADQlbSOQ+H7tdNPJ7QpHc0sJU/fJ91eu6d5nL9ZHskloQTc4LdOjimD3uABh2tg/YDQ1On/m9go8Geoc4abewkgfZiDSDFq7sYJpO37NVzuL7o4FvQy/m6t+1tyuFVs13YOoz2gdy6i1ErYC+V8sgioY4GuIbi44bmL7fa83hvJiM4B9jpEpQO02Rg6HDte+A== Received: from BN9PR03CA0254.namprd03.prod.outlook.com (2603:10b6:408:ff::19) by SJ0PR12MB5456.namprd12.prod.outlook.com (2603:10b6:a03:3ae::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33; Tue, 24 Jan 2023 14:03:37 +0000 Received: from BN8NAM11FT065.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ff:cafe::23) by BN9PR03CA0254.outlook.office365.com (2603:10b6:408:ff::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33 via Frontend Transport; Tue, 24 Jan 2023 14:03:36 +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 BN8NAM11FT065.mail.protection.outlook.com (10.13.177.63) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6023.16 via Frontend Transport; Tue, 24 Jan 2023 14:03:36 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) 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.36; Tue, 24 Jan 2023 06:03:16 -0800 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Tue, 24 Jan 2023 06:03:15 -0800 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.36 via Frontend Transport; Tue, 24 Jan 2023 06:03:12 -0800 From: Vlad Buslov To: , , , CC: , , , , , , , , Vlad Buslov Subject: [PATCH net-next v4 7/7] netfilter: nf_conntrack: allow early drop of offloaded UDP conns Date: Tue, 24 Jan 2023 15:02:07 +0100 Message-ID: <20230124140207.3975283-8-vladbu@nvidia.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230124140207.3975283-1-vladbu@nvidia.com> References: <20230124140207.3975283-1-vladbu@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT065:EE_|SJ0PR12MB5456:EE_ X-MS-Office365-Filtering-Correlation-Id: 48a9ff5e-590e-48d1-ba67-08dafe13c98f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YDn0/USuMWwHYIPJZLAhPhu0Aa9zDFhSx1H+TvAu2OU0zwpTEmMobZuOgpqlVUcerL4kPR0BYz1UT9gjWJzJLSXzsZ/F91n+Izn0t7rBX1OCyTXOzVBBqzJBY3jsdFXKh4KDI3/EWmgwBuhokB6j+5VCwuNjzCNz8QuzrfJJtN7itC7NaMFPgyaa75XQVOx9wjI8qjt6EsvtKWL/ep2HS/MmYfL8mdP+tJ/1Td6DmJgkMoN7x5XzLHItjLT5xffgWTeSbY9Sxs1durwPryU+oaCBEjeUyGsODAJYYvKgDu/XUPaE+OuRRi0XkjqfdCitlcBCeXc8WWTZOtO9hJqm61gI0UtyM70LKA/pPsjf4+gfo23wkj3GZMPQv3LMb1yBCh9CCPq2kUGkZ76MX3HKS94G1059Z2KLxNxqpxNy/72zbTpSqhlmTEfstaJcrJmnt/CmEE1trGM1ENLiEdYo1niB0ZGzAUa7ZPxgfMnY3vrZAkXoX+aQA4guQr6a9oTKaM/iXrC8EEnO6fQDmBIxLy4vxxH8FY4HHLJIR5gOHXOOR/gFnKQ4thisHSUK1dfomM8VQALP/92vFNojyt/1E1rzpBRqGhg9cMf26OHgSGmYCrpgpYsdEDTM/su4nSWrnk9Bsb9A0UEuGld07a8DSZ3YquPCec5uYE6saveWEoT3341RNit8euclfjkoew3mXXxV3w6TU/MJowA3uavb2Mbugyb7G0LSxgPKPR10Y9Y= 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:(13230022)(4636009)(396003)(136003)(346002)(376002)(39860400002)(451199015)(36840700001)(46966006)(40470700004)(36860700001)(4326008)(83380400001)(41300700001)(5660300002)(8936002)(7636003)(86362001)(356005)(2906002)(82740400003)(7416002)(82310400005)(40480700001)(40460700003)(316002)(8676002)(26005)(6666004)(47076005)(426003)(107886003)(336012)(1076003)(70206006)(70586007)(54906003)(2616005)(7696005)(186003)(110136005)(478600001)(36756003)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2023 14:03:36.3788 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 48a9ff5e-590e-48d1-ba67-08dafe13c98f 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: BN8NAM11FT065.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5456 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Both synchronous early drop algorithm and asynchronous gc worker completely ignore connections with IPS_OFFLOAD_BIT status bit set. With new functionality that enabled UDP NEW connection offload in action CT malicious user can flood the conntrack table with offloaded UDP connections by just sending a single packet per 5tuple because such connections can no longer be deleted by early drop algorithm. To mitigate the issue allow both early drop and gc to consider offloaded UDP connections for deletion. Signed-off-by: Vlad Buslov --- net/netfilter/nf_conntrack_core.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index 496c4920505b..52b824a60176 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -1374,9 +1374,6 @@ static unsigned int early_drop_list(struct net *net, hlist_nulls_for_each_entry_rcu(h, n, head, hnnode) { tmp = nf_ct_tuplehash_to_ctrack(h); - if (test_bit(IPS_OFFLOAD_BIT, &tmp->status)) - continue; - if (nf_ct_is_expired(tmp)) { nf_ct_gc_expired(tmp); continue; @@ -1446,11 +1443,14 @@ static bool gc_worker_skip_ct(const struct nf_conn *ct) static bool gc_worker_can_early_drop(const struct nf_conn *ct) { const struct nf_conntrack_l4proto *l4proto; + u8 protonum = nf_ct_protonum(ct); + if (test_bit(IPS_OFFLOAD_BIT, &ct->status) && protonum != IPPROTO_UDP) + return false; if (!test_bit(IPS_ASSURED_BIT, &ct->status)) return true; - l4proto = nf_ct_l4proto_find(nf_ct_protonum(ct)); + l4proto = nf_ct_l4proto_find(protonum); if (l4proto->can_early_drop && l4proto->can_early_drop(ct)) return true; @@ -1507,7 +1507,8 @@ static void gc_worker(struct work_struct *work) if (test_bit(IPS_OFFLOAD_BIT, &tmp->status)) { nf_ct_offload_timeout(tmp); - continue; + if (!nf_conntrack_max95) + continue; } if (expired_count > GC_SCAN_EXPIRED_MAX) {