From patchwork Thu Sep 2 10:18:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roi Dayan X-Patchwork-Id: 1523589 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=CqWHmJ5s; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H0cMv6c9Mz9sCD for ; Thu, 2 Sep 2021 20:18:51 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id D6D1940712; Thu, 2 Sep 2021 10:18:48 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TzzxoqsZTFzP; Thu, 2 Sep 2021 10:18:45 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id CB7E4406EA; Thu, 2 Sep 2021 10:18:42 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 9C6DFC001B; Thu, 2 Sep 2021 10:18:42 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 522DEC001A for ; Thu, 2 Sep 2021 10:18:41 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 33C09406D8 for ; Thu, 2 Sep 2021 10:18:41 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Q0QH8mkFaPNJ for ; Thu, 2 Sep 2021 10:18:37 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2080.outbound.protection.outlook.com [40.107.237.80]) by smtp2.osuosl.org (Postfix) with ESMTPS id 0FB6C406D0 for ; Thu, 2 Sep 2021 10:18:36 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YbRA3/Us08ujCkrRTiN56/yfj3FF6yVD2hOXvpBnVkLEqtXQk8qw0s5oaDeF56rxvJK0SBhpJFU7Jbyv50WDgO45fduQTPBM3D9+m4Q3w5l4n8IXp+9vphoXRTkzm2ftjwuHWYfrOnUmv1G0V0YWw/tK48QcqkB4R1aS6HhEvK5nIQhuisuDyNAmlDbUfkB0jClXKmuTn0JK7U/1wZ4PGd8qO0A5/wPaX4jCbzEhsVHr+OxU7NT00apCEWb63rm9g/rvF0HWOgKWPj2auM+rRCrihJq8p+BENqf9y/ornHIu7iY3f8Zmq98mJH9xae98BcuLBgMO273gZDguQa5GaQ== 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; bh=3lwRT7NpqwxqlJ1CzLHP18aP8OoXbzUEfGPp12vKXRg=; b=ZDbPG8R8VOIzISyDkbpmmeW9kU/yAXYlro++HHMSxMySYyg9kFCl4XRwTHIuQ4KsHsmmzURU/RoB9GFtupp9LZPRbKabI6FOIRG+VolcbrXzYICBgk0smrSiH+K6QKVM8rbKcVnr9LfPOdhm5vaW9TnbBQzMgNJ9Xdj1fVVM9b14svctPMY1od63/7sJ/I2r/WyUmdGkZv40M8Yu4Uj5z/Bbbca3TJM8t+ujHZwS/Vp7x3u1jKmG87+2lHRbFirZK4HK9OesNbWlYy/RqLOAnPk03c9p6v+5IaSpVyPxNCelGvxrIh5dc3XE7hAir9ONDrQyHukqUTTyJ5wCGy+WCA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=ovn.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none 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=3lwRT7NpqwxqlJ1CzLHP18aP8OoXbzUEfGPp12vKXRg=; b=CqWHmJ5sBBvT0ZkN2yKI5EOXwLenmK7zOMCYCk5/xabRSfUMmOdN0fGxXVuP3sw/+pEFMCRd0uaQKJklxbBOfSNrytmtIZP7jhVAybOwfybxADG0WFv7BT2m8lMIMvDC332Few7jzGaDqQXLYkFe+2LckApEvSis9lPkjGg/PYN1O+O1pwNg2pKCjurNFjQtY61qbIwbqMldnb/PvnIXC3lnvZoPoqWhwiblliEEbHTclY5wx5jLu/vM6apvK85XK4u3rurdJvHHsUFxL+ePh0ARbPAyLtsY3m7bBJxEA+rL2OLIcW69usw4SE2HNQcY/XfVchjGlPYNi1M2C5O26A== Received: from MW4PR03CA0251.namprd03.prod.outlook.com (2603:10b6:303:b4::16) by CO6PR12MB5409.namprd12.prod.outlook.com (2603:10b6:5:357::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19; Thu, 2 Sep 2021 10:18:34 +0000 Received: from CO1NAM11FT013.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b4:cafe::c3) by MW4PR03CA0251.outlook.office365.com (2603:10b6:303:b4::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.17 via Frontend Transport; Thu, 2 Sep 2021 10:18:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; ovn.org; dkim=none (message not signed) header.d=none;ovn.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by CO1NAM11FT013.mail.protection.outlook.com (10.13.174.227) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 10:18:31 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Sep 2021 10:18:31 +0000 Received: from dev-r-vrt-138.mtr.labs.mlnx (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 2 Sep 2021 03:18:30 -0700 To: , Ilya Maximets Date: Thu, 2 Sep 2021 13:18:18 +0300 Message-ID: <20210902101823.3403153-2-roid@nvidia.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210902101823.3403153-1-roid@nvidia.com> References: <20210902101823.3403153-1-roid@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: def9c856-57c6-40fd-3c6a-08d96dfb03f4 X-MS-TrafficTypeDiagnostic: CO6PR12MB5409: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J44c7cejAKVAQIZz80retrCPGNmjvF7k+NyQYmjUxkWrv2uGoZcMxYMbFKTNocx25xXwpx5dQfKKd26OzeAMSkBrzC9veuOhdOqzDLBVhRH6g1FbLnqAin7AkomZ4KIiK5mVWtdQNcLJiEY1BJvOdesRVvLPMFFgmd6mF/Nype5BofEKa5PJoBIGQxtJ9p4kbUwUMqV60UOFQUq8Z9IrdPDmHsrBixdPzO0P6Xufre9V4YC98dpEBf1NcoTLm48hjtGTxJyJcYXsL4HHP56ZpNlNbq+wjDzfoJ7uOTTx2edtyyB08BJtSax3qgU0eVzGYDej/C9CGTVt2MGZlDpTHxacoN0dgp62qXf6ATJbH+biWYKnXAXkCdy3P5VlBCn98lsGtul9r3WCnlajcgBSF1dXLPxFV91Ir29SIDRLTjpzmZ1q+6cEJOShS0canM0gJztNWnCD/f7Xhpl/nlixpWfaAVC5gX8cJ3UmE3DtK1CRsygh1Mk1Z074upPM7V2pXUu47dwcN6vZIfbJNmpsEzhDbiy4opzTcS6ei1tzrvkQ9wNAmUfkMiQ5C1rCDU4cVJ16D5/Ohd8vt2IJSmmdOehdHMPPUnMDhBIEJhsgIQVK24nOqU1caMcFHQcbnttYuHhhXZ5HReHJwcJ4zOIO/IQRLHstir524/G7oiwzZHYWxWxZwEiEY7xijvgaSuMN9ErxmRlFNXc9D1Gfdt1HIA== X-Forefront-Antispam-Report: CIP:216.228.112.35; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid04.nvidia.com; CAT:NONE; SFS:(4636009)(136003)(39860400002)(396003)(376002)(346002)(36840700001)(46966006)(4326008)(1076003)(47076005)(107886003)(36906005)(5660300002)(54906003)(478600001)(356005)(26005)(110136005)(6666004)(316002)(7636003)(82740400003)(15650500001)(83380400001)(70586007)(70206006)(36756003)(86362001)(2906002)(82310400003)(36860700001)(8936002)(336012)(2616005)(186003)(8676002)(426003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 10:18:31.9083 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: def9c856-57c6-40fd-3c6a-08d96dfb03f4 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.35]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT013.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR12MB5409 Cc: Jianbo Liu Subject: [ovs-dev] [PATCH 1/6] netdev-linux: Refactor put police action netlink message X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Roi Dayan via dev From: Roi Dayan Reply-To: Roi Dayan Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Jianbo Liu To reuse the code for manipulating police action, move the common initialization code to a function, and change PPS parameters as meter pktps is in unit of packet per second. null_police is redundant because either BPS or PPS, not both, can be configured in one message. So the police passed in to nl_msg_put_act_police can be reused as its rate is zero for PPS, and it also provides the index for police action to be created. Signed-off-by: Jianbo Liu Reviewed-by: Roi Dayan --- lib/netdev-linux.c | 82 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 60dd138914a2..ca730a15fede 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -2629,37 +2629,27 @@ nl_msg_act_police_end_nest(struct ofpbuf *request, size_t offset, } static void -nl_msg_put_act_police(struct ofpbuf *request, struct tc_police police, - uint32_t kpkts_rate, uint32_t kpkts_burst) +nl_msg_put_act_police(struct ofpbuf *request, struct tc_police *police, + uint32_t pkts_rate, uint32_t pkts_burst) { size_t offset, act_offset; uint32_t prio = 0; - /* used for PPS, set rate as 0 to act as a single action */ - struct tc_police null_police; - - memset(&null_police, 0, sizeof null_police); - - if (police.rate.rate) { - nl_msg_act_police_start_nest(request, ++prio, &offset, &act_offset); - tc_put_rtab(request, TCA_POLICE_RATE, &police.rate); - nl_msg_put_unspec(request, TCA_POLICE_TBF, &police, sizeof police); - nl_msg_act_police_end_nest(request, offset, act_offset); - } - if (kpkts_rate) { - unsigned int pkt_burst_ticks, pps_rate, size; - nl_msg_act_police_start_nest(request, ++prio, &offset, &act_offset); - pps_rate = kpkts_rate * 1000; - size = MIN(UINT32_MAX / 1000, kpkts_burst) * 1000; + + nl_msg_act_police_start_nest(request, ++prio, &offset, &act_offset); + if (police->rate.rate) { + tc_put_rtab(request, TCA_POLICE_RATE, &police->rate); + } + if (pkts_rate) { + unsigned int pkt_burst_ticks; /* Here tc_bytes_to_ticks is used to convert packets rather than bytes to ticks. */ - pkt_burst_ticks = tc_bytes_to_ticks(pps_rate, size); - nl_msg_put_u64(request, TCA_POLICE_PKTRATE64, (uint64_t) pps_rate); + pkt_burst_ticks = tc_bytes_to_ticks(pkts_rate, pkts_burst); + nl_msg_put_u64(request, TCA_POLICE_PKTRATE64, (uint64_t) pkts_rate); nl_msg_put_u64(request, TCA_POLICE_PKTBURST64, (uint64_t) pkt_burst_ticks); - nl_msg_put_unspec(request, TCA_POLICE_TBF, &null_police, - sizeof null_police); - nl_msg_act_police_end_nest(request, offset, act_offset); } + nl_msg_put_unspec(request, TCA_POLICE_TBF, police, sizeof *police); + nl_msg_act_police_end_nest(request, offset, act_offset); } static int @@ -2692,7 +2682,8 @@ tc_add_matchall_policer(struct netdev *netdev, uint32_t kbits_rate, nl_msg_put_string(&request, TCA_KIND, "matchall"); basic_offset = nl_msg_start_nested(&request, TCA_OPTIONS); action_offset = nl_msg_start_nested(&request, TCA_MATCHALL_ACT); - nl_msg_put_act_police(&request, pol_act, kpkts_rate, kpkts_burst); + nl_msg_put_act_police(&request, &pol_act, kpkts_rate * 1000, + kpkts_burst * 1000); nl_msg_end_nested(&request, action_offset); nl_msg_end_nested(&request, basic_offset); @@ -5589,6 +5580,29 @@ netdev_linux_tc_make_request(const struct netdev *netdev, int type, return tc_make_request(ifindex, type, flags, request); } +static void +tc_policer_init(struct tc_police *tc_police, uint32_t kbits_rate, + uint32_t kbits_burst) +{ + int mtu = 65535; + + memset(tc_police, 0, sizeof *tc_police); + + tc_police->action = TC_POLICE_SHOT; + tc_police->mtu = mtu; + tc_fill_rate(&tc_police->rate, ((uint64_t) kbits_rate * 1000) / 8, mtu); + + /* The following appears wrong in one way: In networking a kilobit is + * usually 1000 bits but this uses 1024 bits. + * + * However if you "fix" those problems then "tc filter show ..." shows + * "125000b", meaning 125,000 bits, when OVS configures it for 1000 kbit == + * 1,000,000 bits, whereas this actually ends up doing the right thing from + * tc's point of view. Whatever. */ + tc_police->burst = tc_bytes_to_ticks( + tc_police->rate.rate, MIN(UINT32_MAX / 1024, kbits_burst) * 1024 / 8); +} + /* Adds a policer to 'netdev' with a rate of 'kbits_rate' and a burst size * of 'kbits_burst', with a rate of 'kpkts_rate' and a burst size of * 'kpkts_burst'. @@ -5613,22 +5627,8 @@ tc_add_policer(struct netdev *netdev, uint32_t kbits_rate, struct ofpbuf request; struct tcmsg *tcmsg; int error; - int mtu = 65535; - memset(&tc_police, 0, sizeof tc_police); - tc_police.action = TC_POLICE_SHOT; - tc_police.mtu = mtu; - tc_fill_rate(&tc_police.rate, ((uint64_t) kbits_rate * 1000)/8, mtu); - - /* The following appears wrong in one way: In networking a kilobit is - * usually 1000 bits but this uses 1024 bits. - * - * However if you "fix" those problems then "tc filter show ..." shows - * "125000b", meaning 125,000 bits, when OVS configures it for 1000 kbit == - * 1,000,000 bits, whereas this actually ends up doing the right thing from - * tc's point of view. Whatever. */ - tc_police.burst = tc_bytes_to_ticks( - tc_police.rate.rate, MIN(UINT32_MAX / 1024, kbits_burst) * 1024 / 8); + tc_policer_init(&tc_police, kbits_rate, kbits_burst); tcmsg = netdev_linux_tc_make_request(netdev, RTM_NEWTFILTER, NLM_F_EXCL | NLM_F_CREATE, &request); if (!tcmsg) { @@ -5638,9 +5638,11 @@ tc_add_policer(struct netdev *netdev, uint32_t kbits_rate, tcmsg->tcm_info = tc_make_handle(49, (OVS_FORCE uint16_t) htons(ETH_P_ALL)); nl_msg_put_string(&request, TCA_KIND, "basic"); + basic_offset = nl_msg_start_nested(&request, TCA_OPTIONS); police_offset = nl_msg_start_nested(&request, TCA_BASIC_ACT); - nl_msg_put_act_police(&request, tc_police, kpkts_rate, kpkts_burst); + nl_msg_put_act_police(&request, &tc_police, kpkts_rate * 1000, + kpkts_burst * 1000); nl_msg_end_nested(&request, police_offset); nl_msg_end_nested(&request, basic_offset); From patchwork Thu Sep 2 10:18:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roi Dayan X-Patchwork-Id: 1523591 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=A2QSXyd3; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H0cN20HZ5z9sCD for ; Thu, 2 Sep 2021 20:18:57 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 67B3380ED1; Thu, 2 Sep 2021 10:18:55 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id irO1o0ewg91O; Thu, 2 Sep 2021 10:18:51 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 3E02082ACA; Thu, 2 Sep 2021 10:18:47 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id EE84CC001B; Thu, 2 Sep 2021 10:18:46 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id BFCE2C001B for ; Thu, 2 Sep 2021 10:18:45 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 684B8404E0 for ; Thu, 2 Sep 2021 10:18:45 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp4.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9kUPwalGPaPf for ; Thu, 2 Sep 2021 10:18:40 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2074.outbound.protection.outlook.com [40.107.92.74]) by smtp4.osuosl.org (Postfix) with ESMTPS id 7B2B340285 for ; Thu, 2 Sep 2021 10:18:40 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U9HSpPxQh9ukuZklg8h/c32chL2DNlbVU249sjMybMYQx7Kd9izmNfxbVIfY6wTj5S1+085VQLa3MFqVw0//Gfb84LBIeoEORsyJiEkjHsltfgrame5fXTT7LVfYn/bANSSLIk5PxpjUK2rAZUjV0cCbcdfxN11Q5Hk9RAMIKxYVdKPawGSiR7iMR9BUIY1BY6ZQV9UbO+sdeFDCHLBWrRr/C6Q5KCkqWPxpof1nGojKHF5JQ1ZHRfAj7lfnTtCbodcnXaa7IFvJp67fkGyQmO5Ra1Tft1lVpVKgYUzD7oMGGRsPUihFfTuqhevo/tfSlieAjoDG+RK6KPPec4KyAA== 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; bh=CmDABi5FcorcIfDx0jwt3CEQZ674RvKhKYcUEHXnBlc=; b=RkSzpdDUpM8C+H67sNw1UPVeAVof7a+2oo5Luo0hn7pewXFrxHb8TKURRpE3oBGpr1SwB8OQu+UNb5R+43UUekXcGVaKO1VQqOO/maV+KR6+6kbFA8Qu+Yo6RpJ46ErP/mWjSNRabQjHpjx2YWLr9zLBj/1V1FIox6G0pkLR8Stmxrz7BU2x3L7Ywoz+5/JeYKck9zbxFhQwCuUTowhZu8czi4o0Gs4UiUefS9a0Dq001L2N8z5g983sJvO6eUWvBsh+mT/aSTIOdDEqLsUOBmuaN7p09uw+Zg/Byg2rBLgDUshm73YZ6h489R7Hv7s1CMQ+dr5Ok+bhTfqWdcB5UA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=ovn.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none 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=CmDABi5FcorcIfDx0jwt3CEQZ674RvKhKYcUEHXnBlc=; b=A2QSXyd3AfyPVDRk422RPkeWb7fHSXYQYLoBv/K0SK1IQ3s5c8S44zZsZJgwHxJBTsP8R0Wmb4YqBT1QLjCMDq2maRS70zMnI4tZ6Z3o3R32j/+kMMHODg8YVlAi6liEYSK6fMiEGd+Rn/Tn4eYPTxxITyUi5EIadG5GlBrOaEi9284PAKX3kRBAg5ay005OrtPa0ssFURkDHIZ/RaIGxMyZnB5sbKFQmGw5LoPmV99dcQ6UQOTBIFOlPHVM4y2MaL698hXFRR88Nh7+NczGUxy4HohSdfFihW+wOO3rIBv27soxbs7UU+AvMWHgB6Qz2XYJnZYDIudZ400FEsAl9A== Received: from MW4PR03CA0258.namprd03.prod.outlook.com (2603:10b6:303:b4::23) by CH2PR12MB3766.namprd12.prod.outlook.com (2603:10b6:610:16::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.21; Thu, 2 Sep 2021 10:18:36 +0000 Received: from CO1NAM11FT013.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b4:cafe::2e) by MW4PR03CA0258.outlook.office365.com (2603:10b6:303:b4::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 10:18:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; ovn.org; dkim=none (message not signed) header.d=none;ovn.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by CO1NAM11FT013.mail.protection.outlook.com (10.13.174.227) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 10:18:36 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Sep 2021 10:18:32 +0000 Received: from dev-r-vrt-138.mtr.labs.mlnx (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 2 Sep 2021 03:18:31 -0700 To: , Ilya Maximets Date: Thu, 2 Sep 2021 13:18:19 +0300 Message-ID: <20210902101823.3403153-3-roid@nvidia.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210902101823.3403153-1-roid@nvidia.com> References: <20210902101823.3403153-1-roid@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f84472d0-60a1-4838-29e4-08d96dfb0692 X-MS-TrafficTypeDiagnostic: CH2PR12MB3766: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:64; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YDiIcoSFbeZ19rNjJJbFieT+wNQnQ3QlgESZkaCOUm2M69GSXQPD1BTh6UDbHeXz9TJ1nU8BqIPdVkVtPImt1FMnG003PodnWa73aN6zuXAR5P0B2cVdd++8tsbiyKbYMzoFm6pSAgr2No9+jsNJX/A/XUF2UQfwLu58y/q/JyYebPCZ1nl4Ty4/EwlfHtdv8d84NAG393sfDL0uf7Cg3FO7ZsxsgHP3xMK+NBIJ4WkNFiG0Yrs/RUQpswSf7I2LH6RhbkZ70VQFv6jj/u2aajdcYXojvHTcWxSQqueY/fGN2E17WEku4SdmfUNuCuit4/kX6VHyLgbTUNq0DjmXvkyvA1AG4ru3mupZQqMnvWsA+DmuqM9S39aT6ycd1BV8/66oPRXxyX4lHpKT6wQ9TiqGXNJVHVhNFywnWJZUHyf/6GYc0qJhWwQ8J0Rg8kYMPLP2QhcPsVSHUbBjKw7/v5Nmw6BRbGhB7ALiCFlzY5MZBRIuc3TZpRp6oO9bO2TGWJXilyFeojOxcF8XZVrivZP6Tc2fsYs+OlIa0ND1jP3AhdoInWd7EfDCWlDO9/VlqHBDnLl3HtBggOyiZXeyglls15nZ1zCJ8mTlEyxS8eBP1tBdt1em55jaxQuTWTY2hHBNzYS7GpmoIoPuMe2Flp/PNRgSCbT7lMZswZKgHWGJEIlP6G9sIh0YG/jDENvFhwkU4FwPVEgyosc+E9amXg== X-Forefront-Antispam-Report: CIP:216.228.112.35; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid04.nvidia.com; CAT:NONE; SFS:(4636009)(36840700001)(46966006)(86362001)(47076005)(26005)(110136005)(2616005)(36756003)(186003)(426003)(1076003)(336012)(36906005)(6666004)(4326008)(54906003)(70586007)(8676002)(36860700001)(107886003)(356005)(508600001)(2906002)(5660300002)(83380400001)(316002)(82310400003)(7636003)(70206006)(8936002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 10:18:36.3017 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f84472d0-60a1-4838-29e4-08d96dfb0692 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.35]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT013.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB3766 Cc: Jianbo Liu Subject: [ovs-dev] [PATCH 2/6] tc: Add support parsing tc police action X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Roi Dayan via dev From: Roi Dayan Reply-To: Roi Dayan Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Jianbo Liu Add function to parse police action from netlink message. Signed-off-by: Jianbo Liu Reviewed-by: Roi Dayan --- lib/tc.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/tc.h | 4 ++++ 2 files changed, 52 insertions(+) diff --git a/lib/tc.c b/lib/tc.c index 38a1dfc0ebc8..b351f0e1e65f 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -1341,6 +1341,54 @@ nl_parse_act_gact(struct nlattr *options, struct tc_flower *flower) return 0; } +static const struct nl_policy police_policy[] = { + [TCA_POLICE_TBF] = { .type = NL_A_UNSPEC, + .min_len = sizeof(struct tc_police), + .optional = false, }, + [TCA_POLICE_RATE] = { .type = NL_A_UNSPEC, + .min_len = 1024, + .optional = true, }, + [TCA_POLICE_PEAKRATE] = { .type = NL_A_UNSPEC, + .min_len = 1024, + .optional = true, }, + [TCA_POLICE_AVRATE] = { .type = NL_A_U32, + .optional = true, }, + [TCA_POLICE_RESULT] = { .type = NL_A_U32, + .optional = true, }, + [TCA_POLICE_TM] = { .type = NL_A_UNSPEC, + .min_len = sizeof(struct tcf_t), + .optional = true, }, +}; + +static int +nl_parse_act_police(const struct nlattr *options, struct tc_flower *flower) +{ + struct nlattr *police_attrs[ARRAY_SIZE(police_policy)] = {}; + struct tc_action *action; + const struct tc_police *police; + struct nlattr *police_tm; + const struct tcf_t *tm; + + if (!nl_parse_nested(options, police_policy, police_attrs, + ARRAY_SIZE(police_policy))) { + VLOG_ERR_RL(&error_rl, "failed to parse police action options"); + return EPROTO; + } + + police = nl_attr_get(police_attrs[TCA_POLICE_TBF]); + action = &flower->actions[flower->action_count++]; + action->type = TC_ACT_POLICE; + action->police.index = police->index; + + police_tm = police_attrs[TCA_POLICE_TM]; + if (police_tm) { + tm = nl_attr_get_unspec(police_tm, sizeof *tm); + nl_parse_tcf(tm, flower); + } + + return 0; +} + static const struct nl_policy mirred_policy[] = { [TCA_MIRRED_PARMS] = { .type = NL_A_UNSPEC, .min_len = sizeof(struct tc_mirred), diff --git a/lib/tc.h b/lib/tc.h index a147ca461dc5..85ae5a8908ea 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -174,6 +174,7 @@ enum tc_action_type { TC_ACT_MPLS_SET, TC_ACT_GOTO, TC_ACT_CT, + TC_ACT_POLICE, }; enum nat_type { @@ -256,6 +257,9 @@ struct tc_action { bool force; bool commit; } ct; + struct { + uint32_t index; + } police; }; enum tc_action_type type; From patchwork Thu Sep 2 10:18:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roi Dayan X-Patchwork-Id: 1523590 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=bWCZhk9j; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H0cMy1jPfz9sCD for ; Thu, 2 Sep 2021 20:18:54 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id B7784614BF; Thu, 2 Sep 2021 10:18:51 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id clB9rYzwcFqU; Thu, 2 Sep 2021 10:18:47 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 251A561471; Thu, 2 Sep 2021 10:18:44 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 44D4DC0025; Thu, 2 Sep 2021 10:18:43 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 98CF2C001A for ; Thu, 2 Sep 2021 10:18:41 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 8934082733 for ; Thu, 2 Sep 2021 10:18:41 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eZbfl1t0hULr for ; Thu, 2 Sep 2021 10:18:37 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2074.outbound.protection.outlook.com [40.107.236.74]) by smtp1.osuosl.org (Postfix) with ESMTPS id 9AB6D80ECC for ; Thu, 2 Sep 2021 10:18:37 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZV+7fpdWRQjmtLsE2k0/25ZzaMoosP8mdt8xoRGNdOXl9vvZE3yH1rzAxQGS0Vz6PD0f9N4+Md6kfZ+Olbt/0Uw92rflI4yhvlIjkI6/06WmNvIjP7dz2wyAS+spoo8yQ6Wq/gp/HrjTf5iCIj0jgSBlZtgWo2Yd4llVRVWxDCmE9kHbbGCGoaQgCw788qlFjO1aQ7Th1Tmaq+4DP8x1T0HZQJaf3Jdro0KgSM2EaVUZNYtKVRkWStV5ldCNaqsJCV6KHrAYrfqlna7MVYf+1+7m/1DHXfuQ2AdHUZ5WHySva0YCEMMQ4LDJBTjyqU4N+WRykG0TVwPWnKXVU6lCIQ== 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-SenderADCheck; bh=ImwziaQAQtoOfClolum1m6LIcMrsPcXEQLAC/ZzJH8M=; b=DUwfSdLzTcbt++ddxXfcB0GR7+3ORIIYbltXWs7DoBhJ/LKO93h3aKmXy/90+n7d/9ossq+m2fVuXOaubt/QOXdDvmlqGkwJYZNuLJAagVRa1DZW1vZlcZbjRGjKgES9qSqbYtnvjy7ubD/2nc7wCouZcnL1u/EPdAzG4LWGSusRfAuPBzS/+SMtu3FaQK/DEbi1sv8IavZH7D2/R9uAmPmGkIvAT7kBPDGa/fJ5pltommz2YNXos0lbYxGliGeSK4AoMdq9qpHufIHAGbUldY6d8PE9vpqBXIO5qgzd7Vpr23U1boJpoJxetrKAzqTr9k2dSePki1ds5hnAXTd/6w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=ovn.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none 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=ImwziaQAQtoOfClolum1m6LIcMrsPcXEQLAC/ZzJH8M=; b=bWCZhk9jPnYt5T8uTD/YQhabVvC7haAxywX+PjRkwegWsfQAJPlT/GGCvTKU8QqzM4mRZbUJYnnx/C7JLx4cNXDri3EOAmojvlBtv9OAyFhFij8uf8TkHcYFvZtC0h/vQDhmNfdVg8lhR/ceV8uyaufcGESxfgqYGl8HLmRrc+42QPrVh6On6zVCAJD58pYykqrIELi8oNtJpmSVuVQtsqMYPMA4byMX+Y8YadwTi5I15xQkL52PuUSp7ylIiHzkHCc+lRSyPFv26/iF01XusgVBvDLr7lSC8K60tJxULGDFAxz1i0Du577g+7czV4SBO7R+G594L+t/2f/7H9rJzA== Received: from MWHPR03CA0006.namprd03.prod.outlook.com (2603:10b6:300:117::16) by CH2PR12MB4103.namprd12.prod.outlook.com (2603:10b6:610:7e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20; Thu, 2 Sep 2021 10:18:35 +0000 Received: from CO1NAM11FT061.eop-nam11.prod.protection.outlook.com (2603:10b6:300:117:cafe::85) by MWHPR03CA0006.outlook.office365.com (2603:10b6:300:117::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 10:18:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; ovn.org; dkim=none (message not signed) header.d=none;ovn.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by CO1NAM11FT061.mail.protection.outlook.com (10.13.175.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 10:18:35 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Sep 2021 03:18:34 -0700 Received: from dev-r-vrt-138.mtr.labs.mlnx (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 2 Sep 2021 03:18:33 -0700 To: , Ilya Maximets Date: Thu, 2 Sep 2021 13:18:20 +0300 Message-ID: <20210902101823.3403153-4-roid@nvidia.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210902101823.3403153-1-roid@nvidia.com> References: <20210902101823.3403153-1-roid@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1fc1aa64-af34-4858-6206-08d96dfb05d7 X-MS-TrafficTypeDiagnostic: CH2PR12MB4103: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qhQGV6tpus/kUO9TN3aYKwiLek9zcLxMrV3tpOKA7vQFMK8knmr/BRuzDXnsHyXg72WSiQRxe6d77mahVneiNPa326rCpZsW9caD6mVaMCVd7ggy9OhUdpajB/wU4NVikgGM50wQJgxg8grpg8B3jns7KoCB+NXrNc75RU4ajGQM8gtp/4ajE0LqwHm2IkY0OyGLW9MyCAI0PYzJqwsewmNZS5AGwZOrTa/+EQkmWR1wUcnbz45ljSPwIzFZkVCrHFd0Q52o55p8oHnMnw5VlblkNJYkm9J5OLbChcmuhtUZ9CIEaIu3YYgR3VqjNmZqxaWGmSIL4TIAcQgzl92huFClKaxfLb0kBgR+W4J6b658Vux2gcejJkbbjkkJRxezVROXFd0lYh2z1ekB17nxbN1NSB/rv66kC8j3I8xG6jNZIyMQR8GX8ocO1JSG7Wn++jDp16V3/NxU7dFHwpzqrhtC6bGc9Q8guvYiXQRfT/Hugya8wEncnKYtb/FL0UbrRRgHcwN6O3Jz4CaEv5lwbHFdfzrKnnV5Gi9eDl1MGl4Cxcx6OOrGOXdH3Ev3DPZRgnWPeUHNzpY3k+luNffwQ/l7teaZyLE7fVLPuhcX6H42/SgC1D5QZPxEkdwXc+V+3Ce0PoDD9C8YXulMIExn858REo0qVHKcBbGEAb1+/8Qac88u1nNytUka8tEacNz3KFJ9omqIOnPKxnwoGI3uVw== X-Forefront-Antispam-Report: CIP:216.228.112.32; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid01.nvidia.com; CAT:NONE; SFS:(4636009)(396003)(39860400002)(376002)(136003)(346002)(46966006)(36840700001)(110136005)(8936002)(70206006)(7636003)(2616005)(54906003)(2906002)(82740400003)(356005)(316002)(36860700001)(1076003)(426003)(47076005)(26005)(82310400003)(36756003)(478600001)(186003)(107886003)(4326008)(86362001)(70586007)(5660300002)(6666004)(8676002)(83380400001)(336012); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 10:18:35.0696 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1fc1aa64-af34-4858-6206-08d96dfb05d7 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.32]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT061.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4103 Cc: Jianbo Liu Subject: [ovs-dev] [PATCH 3/6] netdev-linux: Add functions to manipulate tc police action X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Roi Dayan via dev From: Roi Dayan Reply-To: Roi Dayan Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Jianbo Liu Add helpers to add, delete and get stats of police action with the specified index. Signed-off-by: Jianbo Liu Reviewed-by: Roi Dayan --- lib/netdev-linux.c | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/netdev-linux.h | 6 +++ lib/tc.c | 21 +++++++++ lib/tc.h | 6 +++ 4 files changed, 162 insertions(+) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index ca730a15fede..63bcb8f9b173 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -5654,6 +5654,135 @@ tc_add_policer(struct netdev *netdev, uint32_t kbits_rate, return 0; } +int +tc_add_policer_action(uint32_t index, uint32_t kbits_rate, + uint32_t kbits_burst, uint32_t pkts_rate, + uint32_t pkts_burst, bool update) +{ + struct tc_police tc_police; + struct ofpbuf request; + struct tcamsg *tcamsg; + size_t offset; + int flags; + + tc_policer_init(&tc_police, kbits_rate, kbits_burst); + tc_police.index = index; + + flags = (update ? NLM_F_REPLACE : NLM_F_EXCL) | NLM_F_CREATE; + tcamsg = tc_make_action_request(RTM_NEWACTION, flags, &request); + if (!tcamsg) { + return ENODEV; + } + + offset = nl_msg_start_nested(&request, TCA_ACT_TAB); + nl_msg_put_act_police(&request, &tc_police, pkts_rate, pkts_burst); + nl_msg_end_nested(&request, offset); + + return tc_transact(&request, NULL); +} + +static int +tc_update_policer_action_stats(struct ofpbuf *msg, + struct ofputil_meter_stats *stats) +{ + const struct nlattr *act = NULL; + struct tc_flower flower; + struct nlattr *prio; + struct tcamsg *tca; + int error; + + if (NLMSG_HDRLEN + sizeof *tca > msg->size) { + return EPROTO; + } + + tca = ofpbuf_at_assert(msg, NLMSG_HDRLEN, sizeof *tca); + + act = nl_attr_find(msg, NLMSG_HDRLEN + sizeof *tca, TCA_ACT_TAB); + if (!act) { + return EPROTO; + } + + prio = (struct nlattr *) act + 1; + memset(&flower, 0, sizeof(struct tc_flower)); + error = tc_parse_single_action(prio, &flower, false); + if (!error) { + stats->packet_in_count += get_32aligned_u64(&flower.stats.n_packets); + stats->byte_in_count += get_32aligned_u64(&flower.stats.n_bytes); + } + + return error; +} + +int +tc_get_policer_action(uint32_t index, struct ofputil_meter_stats *stats) +{ + struct ofpbuf *replyp = NULL; + struct ofpbuf request; + struct tcamsg *tcamsg; + size_t root_offset; + size_t prio_offset; + int prio = 0; + int error; + + tcamsg = tc_make_action_request(RTM_GETACTION, 0, &request); + if (!tcamsg) { + return ENODEV; + } + + root_offset = nl_msg_start_nested(&request, TCA_ACT_TAB); + prio_offset = nl_msg_start_nested(&request, ++prio); + nl_msg_put_string(&request, TCA_ACT_KIND, "police"); + nl_msg_put_u32(&request, TCA_ACT_INDEX, index); + nl_msg_end_nested(&request, prio_offset); + nl_msg_end_nested(&request, root_offset); + + error = tc_transact(&request, &replyp); + if (error) { + VLOG_ERR_RL(&rl, "failed to dump police action (index: %u), err=%d", + index, error); + return error; + } + + error = tc_update_policer_action_stats(replyp, stats); + if (error) { + VLOG_ERR_RL(&rl, "failed to update police stats (index: %u), err=%d", + index, error); + } + + return error; +} + +int +tc_del_policer_action(uint32_t index, struct ofputil_meter_stats *stats) +{ + struct ofpbuf *replyp = NULL; + struct ofpbuf request; + struct tcamsg *tcamsg; + size_t root_offset; + size_t prio_offset; + int prio = 0; + int error; + + tcamsg = tc_make_action_request(RTM_DELACTION, NLM_F_ACK, &request); + if (!tcamsg) { + return ENODEV; + } + + root_offset = nl_msg_start_nested(&request, TCA_ACT_TAB); + prio_offset = nl_msg_start_nested(&request, ++prio); + nl_msg_put_string(&request, TCA_ACT_KIND, "police"); + nl_msg_put_u32(&request, TCA_ACT_INDEX, index); + nl_msg_end_nested(&request, prio_offset); + nl_msg_end_nested(&request, root_offset); + + error = tc_transact(&request, &replyp); + if (!error && stats) { + error = tc_update_policer_action_stats(replyp, stats); + } + + return error; +} + static void read_psched(void) { diff --git a/lib/netdev-linux.h b/lib/netdev-linux.h index e1e30f806557..9a416ce505c9 100644 --- a/lib/netdev-linux.h +++ b/lib/netdev-linux.h @@ -19,6 +19,7 @@ #include #include +#include "openvswitch/ofp-meter.h" /* These functions are Linux specific, so they should be used directly only by * Linux-specific code. */ @@ -28,5 +29,10 @@ struct netdev; int netdev_linux_ethtool_set_flag(struct netdev *netdev, uint32_t flag, const char *flag_name, bool enable); int linux_get_ifindex(const char *netdev_name); +int tc_add_policer_action(uint32_t index, uint32_t kbits_rate, + uint32_t kbits_burst, uint32_t pkts_rate, + uint32_t pkts_burst, bool update); +int tc_del_policer_action(uint32_t index, struct ofputil_meter_stats *stats); +int tc_get_policer_action(uint32_t index, struct ofputil_meter_stats *stats); #endif /* netdev-linux.h */ diff --git a/lib/tc.c b/lib/tc.c index b351f0e1e65f..75c9e1ad16ea 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -199,6 +199,20 @@ tc_make_request(int ifindex, int type, unsigned int flags, return tcmsg; } +struct tcamsg * +tc_make_action_request(int type, unsigned int flags, + struct ofpbuf *request) +{ + struct tcamsg *tcamsg; + + ofpbuf_init(request, 512); + nl_msg_put_nlmsghdr(request, sizeof *tcamsg, type, NLM_F_REQUEST | flags); + tcamsg = ofpbuf_put_zeros(request, sizeof *tcamsg); + tcamsg->tca_family = AF_UNSPEC; + + return tcamsg; +} + static void request_from_tcf_id(struct tcf_id *id, uint16_t eth_type, int type, unsigned int flags, struct ofpbuf *request) @@ -1828,6 +1842,13 @@ nl_parse_single_action(struct nlattr *action, struct tc_flower *flower, return 0; } +int +tc_parse_single_action(struct nlattr *action, struct tc_flower *flower, + bool terse) +{ + return nl_parse_single_action(action, flower, terse); +} + #define TCA_ACT_MIN_PRIO 1 static int diff --git a/lib/tc.h b/lib/tc.h index 85ae5a8908ea..f31bec5d2b4b 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -80,6 +80,8 @@ tc_get_minor(unsigned int handle) struct tcmsg *tc_make_request(int ifindex, int type, unsigned int flags, struct ofpbuf *); +struct tcamsg *tc_make_action_request(int type, unsigned int flags, + struct ofpbuf *request); int tc_transact(struct ofpbuf *request, struct ofpbuf **replyp); int tc_add_del_qdisc(int ifindex, bool add, uint32_t block_id, enum tc_qdisc_hook hook); @@ -356,6 +358,8 @@ struct tc_flower { enum tc_offload_policy tc_policy; }; +struct nlattr; + /* assert that if we overflow with a masked write of uint32_t to the last byte * of flower.rewrite we overflow inside struct flower. * shouldn't happen unless someone moves rewrite to the end of flower */ @@ -374,5 +378,7 @@ int parse_netlink_to_tc_flower(struct ofpbuf *reply, bool terse); int parse_netlink_to_tc_chain(struct ofpbuf *reply, uint32_t *chain); void tc_set_policy(const char *policy); +int tc_parse_single_action(struct nlattr *action, struct tc_flower *flower, + bool terse); #endif /* tc.h */ From patchwork Thu Sep 2 10:18:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roi Dayan X-Patchwork-Id: 1523594 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=AyknS5D3; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H0cN45hC4z9sPf for ; Thu, 2 Sep 2021 20:19:00 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 76541614B2; Thu, 2 Sep 2021 10:18:58 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Z3oC7Ri4VeqN; Thu, 2 Sep 2021 10:18:54 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 806B1614BA; Thu, 2 Sep 2021 10:18:50 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 75B67C002F; Thu, 2 Sep 2021 10:18:48 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id EDC3EC0029 for ; Thu, 2 Sep 2021 10:18:47 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id DD0E542548 for ; Thu, 2 Sep 2021 10:18:47 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp4.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JtOt20REgWTu for ; Thu, 2 Sep 2021 10:18:44 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2062d.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e8a::62d]) by smtp4.osuosl.org (Postfix) with ESMTPS id 4B19A402A1 for ; Thu, 2 Sep 2021 10:18:42 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C6ucwzNZdN2MOXRS4aovCdWYW++pvfmyC3tfaKk6KQ5tX4bK2MZF/fzUrYlbsHXoqdbsvg5RimWYvMPxAUeWjFsX66NgA0jvH/rKgDjiJjiGlyImIZ2UHtNBwHtM35QZn7uZ8WSA0E4qqSeE6d4X1LPI9l1oE982zKNPp2pux0ONm3Mcu8juzEstF1f3nRey0pfYxAxJur4YWK2m0TqUcjxr0Iu4xqZy4mbLxMkbEOAsLRL9QTMFhO5DAXBPd+oV5Ozbf3DAmep4ezNTn3wa0eyCi9MmI54WvKCyp/Eeozz/NqfALsXfmB35i5IGpRm4X7il7uDv80/A4fnmTP8yMQ== 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-SenderADCheck; bh=6IR+J5VUaRdxan15FFCkSTPyS2KzXaSJoA8VJbKXbS8=; b=LWQTN7RO5Oc/v4fbL9N92/Xw2saBQiGUqJm/+gQSAmErSDnGS+nSgRx6DRL4Af8uhbXXujtO5PnxjON/RAF4fQfVe/MBNjOyB69nfGqOkoFGPBXXW+2SNM3PWp/JjS1x1et1cw95GpTk1oamSS5AX9U0OcLgvbgxa/1S0xsKxM3/66bbLzwQ/tX/Cb7JtpapaSET1Zlp2eu78i3+xrH49dGW5JG/Fs7+7vRfRcsuHXuUp8iS/d1b/7a4MFhPxb2VMM9c12C9PzuHA3D94cm3PO4sRlRbKe45V9pODYWLFWCV9/BApp2ORR5hwrBKVoVtJC1PfsAFFwv+WhMNrfG2ug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=ovn.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none 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=6IR+J5VUaRdxan15FFCkSTPyS2KzXaSJoA8VJbKXbS8=; b=AyknS5D3h48g4LawLnnGAMHLJOOY/Ftyz9z3YikiJYiCq62lMFBaN++cA6qKOmXQVrWYntsw8L2FfTi9tHTYT7yJ39saZh+DCO1qdLi7iJlaAWYIXLEQn2NvuSSESVxEou7RfHrtFq7GTVrj2ErIPWWA/cZQ7h7AG8QT2S0wT2g/iO/pwljATDkc77aPEXQaarSTYZHkxFi4nKI3D3plRuKgMPs74Gffmu7mTMSysNbgCLGR+I2H8ByUInEv3yg02W62+905eCmqnfueljJ7y3s6acBfR4dGDlf5Zk3mKCEwqwPNyiCAlWrHXMVN/JLs2Gyf5rA+dVBCkXqtw9osxQ== Received: from MW4PR03CA0268.namprd03.prod.outlook.com (2603:10b6:303:b4::33) by BN8PR12MB3076.namprd12.prod.outlook.com (2603:10b6:408:61::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.20; Thu, 2 Sep 2021 10:18:38 +0000 Received: from CO1NAM11FT013.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b4:cafe::d) by MW4PR03CA0268.outlook.office365.com (2603:10b6:303:b4::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.20 via Frontend Transport; Thu, 2 Sep 2021 10:18:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; ovn.org; dkim=none (message not signed) header.d=none;ovn.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by CO1NAM11FT013.mail.protection.outlook.com (10.13.174.227) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 10:18:37 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Sep 2021 10:18:36 +0000 Received: from dev-r-vrt-138.mtr.labs.mlnx (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 2 Sep 2021 03:18:34 -0700 To: , Ilya Maximets Date: Thu, 2 Sep 2021 13:18:21 +0300 Message-ID: <20210902101823.3403153-5-roid@nvidia.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210902101823.3403153-1-roid@nvidia.com> References: <20210902101823.3403153-1-roid@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a43ca6f9-0600-47ec-f1c8-08d96dfb077b X-MS-TrafficTypeDiagnostic: BN8PR12MB3076: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:109; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yXyr00xN2LCErNoriO7SN44nbjUVtLraqHx86XhUmQQv6TwQLfaDO6JqwGuLpPpyjsNPrTvlc3Cq0VYGYKD37P5FFbLmBDXwUNdkgwn/SUk8IwLW/nLFxPN0gjJ82rLZft1JrMU9yxFXI7L3CrOfvj650f3IXqqUzfVbktYLKKIYDGNXmem6zEN2mcXTyUzBXkAkKdN0DMnTSFFfeIgjnKSncePMmhkM7ghEHWK4KVz3BpXf3mQdnMP4hPbsDK7d42oTYAS2tCsnwkPYcynnK+6s8wtOBqLYGa9uvABLPniF8F/6ZJGoKBqsJqhIqa7u9YvpX13uG84REtmns37Qd/zxKc1emxSwzubcqzJFIUP/k8JXKbSfJIf442JxIP9mZ1vx9jLAObRgw0z8FfFgr1P9OWACbZvpQDPzPZlbJN6WNODssDDyJIwI9saVEfBw1tnhgkiVvrDomKlIPKxMpLh7qAqJwRkyJZxSU0Hd9kwBKj1aTR1Jhr0DlQd3QpKjf1Cmd/C5hDwZD4WpsL8/+UkIOrKBvKz2yiraabuLXY9632FyY8f7BtxkdOrCpt6h/2Ey0AeCGrhOvH91mQ8b/R3a7qiKr1oh98mqhOpU3aU2RoCe930pgDdQ9ME0Oh7oPCXcXQcYNa1IxLmgRs9i6t4MEJZw3b4J/AQ9T4I2zT4mNDT2YLN0yGwkd017ddMTD0e2PBTvaiomX+zAO0vPIg== X-Forefront-Antispam-Report: CIP:216.228.112.35; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid04.nvidia.com; CAT:NONE; SFS:(4636009)(136003)(39860400002)(346002)(396003)(376002)(36840700001)(46966006)(1076003)(47076005)(8676002)(7636003)(83380400001)(6666004)(36860700001)(8936002)(82740400003)(356005)(82310400003)(426003)(336012)(186003)(26005)(70586007)(70206006)(5660300002)(478600001)(316002)(36906005)(4326008)(2906002)(2616005)(54906003)(110136005)(107886003)(36756003)(86362001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 10:18:37.8378 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a43ca6f9-0600-47ec-f1c8-08d96dfb077b X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.35]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT013.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3076 Cc: Jianbo Liu Subject: [ovs-dev] [PATCH 4/6] dpif-netlink: Offloading meter to tc police action X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Roi Dayan via dev From: Roi Dayan Reply-To: Roi Dayan Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Jianbo Liu OVS meters are created in advance and openflow rules refer to them by their unique ID. In order to offload meters, they are mapped to tc police actions with one-to-one relationship, then these actions can be used in tc filter rules by the index. So a police action is created when meter is created, and deleted after meter is deleted. An id-pool is used to manage all the available police indexes, which are 50000-59999, reserved only for OVS. Signed-off-by: Jianbo Liu Reviewed-by: Roi Dayan --- lib/dpif-netlink.c | 240 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 235 insertions(+), 5 deletions(-) diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index 34fc04237333..fa68e69efbbe 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -37,6 +37,7 @@ #include "dpif-provider.h" #include "fat-rwlock.h" #include "flow.h" +#include "id-pool.h" #include "netdev-linux.h" #include "netdev-offload.h" #include "netdev-provider.h" @@ -122,6 +123,23 @@ static void dpif_netlink_unixctl_dispatch_mode(struct unixctl_conn *conn, int argc, const char *argv[], void *aux); +#define METER_POLICE_IDS_BASE 50000 +#define METER_POLICE_IDS_MAX 59999 +/* Protects below meter ids pool and hashmaps. */ +static struct ovs_mutex meter_mutex = OVS_MUTEX_INITIALIZER; +static struct id_pool *meter_police_ids; +static struct hmap meter_id_to_police_idx OVS_GUARDED_BY(meter_mutex) + = HMAP_INITIALIZER(&meter_id_to_police_idx); + +struct meter_id_to_police_idx_data { + struct hmap_node meter_id_node; + uint32_t meter_id; + uint32_t police_idx; +}; + +static int +meter_id_lookup(uint32_t meter_id, uint32_t *police_idx); + struct dpif_netlink_flow { /* Generic Netlink header. */ uint8_t cmd; @@ -704,6 +722,7 @@ dpif_netlink_destroy(struct dpif *dpif_) struct dpif_netlink *dpif = dpif_netlink_cast(dpif_); struct dpif_netlink_dp dp; + id_pool_destroy(meter_police_ids); dpif_netlink_dp_init(&dp); dp.cmd = OVS_DP_CMD_DEL; dp.dp_ifindex = dpif->dp_ifindex; @@ -3921,6 +3940,96 @@ dpif_netlink_ct_timeout_policy_dump_done(struct dpif *dpif OVS_UNUSED, * zero. Check for that condition and disable meters on those kernels. */ static bool probe_broken_meters(struct dpif *); +static struct meter_id_to_police_idx_data * +meter_id_find_locked(uint32_t meter_id) + OVS_REQUIRES(meter_mutex) +{ + struct meter_id_to_police_idx_data *data; + size_t hash = hash_int(meter_id, 0); + + HMAP_FOR_EACH_WITH_HASH (data, meter_id_node, hash, + &meter_id_to_police_idx) { + if (data->meter_id == meter_id) { + return data; + } + } + + return NULL; +} + +static int +meter_id_lookup(uint32_t meter_id, uint32_t *police_idx) +{ + struct meter_id_to_police_idx_data *data; + int ret = 0; + + ovs_mutex_lock(&meter_mutex); + data = meter_id_find_locked(meter_id); + if (data) { + *police_idx = data->police_idx; + } else { + ret = ENOENT; + } + ovs_mutex_unlock(&meter_mutex); + + return ret; +} + +static void +meter_id_insert(uint32_t meter_id, uint32_t police_idx) +{ + struct meter_id_to_police_idx_data *data; + + ovs_mutex_lock(&meter_mutex); + data = meter_id_find_locked(meter_id); + if (!data) { + data = xzalloc(sizeof *data); + data->meter_id = meter_id; + data->police_idx = police_idx; + hmap_insert(&meter_id_to_police_idx, &data->meter_id_node, + hash_int(meter_id, 0)); + } else { + VLOG_WARN_RL(&error_rl, + "try to insert meter %d (%d) with different police (%d)", + meter_id, data->police_idx, police_idx); + } + ovs_mutex_unlock(&meter_mutex); +} + +static void +meter_id_remove(uint32_t meter_id) +{ + struct meter_id_to_police_idx_data *data; + + ovs_mutex_lock(&meter_mutex); + data = meter_id_find_locked(meter_id); + if (data) { + hmap_remove(&meter_id_to_police_idx, &data->meter_id_node); + free(data); + } + ovs_mutex_unlock(&meter_mutex); +} + +static bool +meter_alloc_police_index(uint32_t *police_index) +{ + bool ret; + + ovs_mutex_lock(&meter_mutex); + ret = id_pool_alloc_id(meter_police_ids, police_index); + ovs_mutex_unlock(&meter_mutex); + + return ret; +} + +static void +meter_free_police_index(uint32_t police_index) +{ + ovs_mutex_lock(&meter_mutex); + id_pool_free_id(meter_police_ids, police_index); + ovs_mutex_unlock(&meter_mutex); +} + static void dpif_netlink_meter_init(struct dpif_netlink *dpif, struct ofpbuf *buf, void *stub, size_t size, uint32_t command) @@ -4107,14 +4216,75 @@ dpif_netlink_meter_set__(struct dpif *dpif_, ofproto_meter_id meter_id, } static int +dpif_netlink_meter_set_policer(struct dpif *dpif_, ofproto_meter_id meter_id, + struct ofputil_meter_config *config) +{ + uint32_t police_index; + uint32_t rate, burst; + bool add_policer; + int err; + + ovs_assert(config->bands != NULL); + + rate = config->bands[0].rate; + if (config->flags & OFPMF13_BURST) { + burst = config->bands[0].burst_size; + } else { + burst = config->bands[0].rate; + } + + add_policer = (meter_id_lookup(meter_id.uint32, &police_index) == ENOENT); + if (add_policer) { + if (!meter_alloc_police_index(&police_index)) { + VLOG_WARN_RL(&error_rl, "%s: no free police index for meter id %d", + dpif_name(dpif_), meter_id.uint32); + return ENOENT; + } + } + + err = tc_add_policer_action(police_index, + (config->flags & OFPMF13_KBPS) ? rate : 0, + (config->flags & OFPMF13_KBPS) ? burst : 0, + (config->flags & OFPMF13_PKTPS) ? rate : 0, + (config->flags & OFPMF13_PKTPS) ? burst : 0, + !add_policer); + if (err) { + VLOG_WARN_RL(&error_rl, + "%s: failed to %s police %d for meter id %d: %s", + dpif_name(dpif_), add_policer ? "add" : "modify", + police_index, meter_id.uint32, ovs_strerror(err)); + goto err_add_policer; + } + + if (add_policer) { + meter_id_insert(meter_id.uint32, police_index); + } + + return 0; + +err_add_policer: + if (add_policer) { + meter_free_police_index(police_index); + } + return err; +} + +static int dpif_netlink_meter_set(struct dpif *dpif_, ofproto_meter_id meter_id, struct ofputil_meter_config *config) { + int err; + if (probe_broken_meters(dpif_)) { return ENOMEM; } - return dpif_netlink_meter_set__(dpif_, meter_id, config); + err = dpif_netlink_meter_set__(dpif_, meter_id, config); + if (!err && netdev_is_flow_api_enabled()) { + dpif_netlink_meter_set_policer(dpif_, meter_id, config); + } + + return err; } /* Retrieve statistics and/or delete meter 'meter_id'. Statistics are @@ -4202,19 +4372,77 @@ dpif_netlink_meter_get_stats(const struct dpif *dpif_, } static int +dpif_netlink_meter_get_policer(const struct dpif *dpif, + ofproto_meter_id meter_id, + struct ofputil_meter_stats *stats) +{ + uint32_t police_index; + int err = 0; + + if (!meter_id_lookup(meter_id.uint32, &police_index)) { + err = tc_get_policer_action(police_index, stats); + if (err) { + VLOG_WARN_RL(&error_rl, + "%s: failed to get police %d stats for meter %d: %s", + dpif_name(dpif), police_index, meter_id.uint32, + ovs_strerror(err)); + } + } + + return err; +} + +static int dpif_netlink_meter_get(const struct dpif *dpif, ofproto_meter_id meter_id, struct ofputil_meter_stats *stats, uint16_t max_bands) { - return dpif_netlink_meter_get_stats(dpif, meter_id, stats, max_bands, - OVS_METER_CMD_GET); + int err; + + err = dpif_netlink_meter_get_stats(dpif, meter_id, stats, max_bands, + OVS_METER_CMD_GET); + if (!err && netdev_is_flow_api_enabled()) { + dpif_netlink_meter_get_policer(dpif, meter_id, stats); + } + + return err; +} + +static int +dpif_netlink_meter_del_policer(struct dpif *dpif, ofproto_meter_id meter_id, + struct ofputil_meter_stats *stats) +{ + uint32_t police_index; + int err = 0; + + if (!meter_id_lookup(meter_id.uint32, &police_index)) { + err = tc_del_policer_action(police_index, stats); + if (err) { + VLOG_WARN_RL(&error_rl, + "%s: failed to del police %d for meter %d: %s", + dpif_name(dpif), police_index, + meter_id.uint32, ovs_strerror(err)); + } else { + meter_free_police_index(police_index); + } + meter_id_remove(meter_id.uint32); + } + + return err; } static int dpif_netlink_meter_del(struct dpif *dpif, ofproto_meter_id meter_id, struct ofputil_meter_stats *stats, uint16_t max_bands) { - return dpif_netlink_meter_get_stats(dpif, meter_id, stats, max_bands, - OVS_METER_CMD_DEL); + int err; + + err = dpif_netlink_meter_get_stats(dpif, meter_id, stats, + max_bands, OVS_METER_CMD_DEL); + if (!err && netdev_is_flow_api_enabled()) { + dpif_netlink_meter_del_policer(dpif, meter_id, stats); + } + + return err; } static bool @@ -4256,6 +4484,8 @@ probe_broken_meters(struct dpif *dpif) static bool broken_meters = false; if (ovsthread_once_start(&once)) { + meter_police_ids = id_pool_create(METER_POLICE_IDS_BASE, + METER_POLICE_IDS_MAX - METER_POLICE_IDS_BASE + 1); broken_meters = probe_broken_meters__(dpif); ovsthread_once_done(&once); } From patchwork Thu Sep 2 10:18:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roi Dayan X-Patchwork-Id: 1523592 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=Xs6c4U9c; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H0cN22B4Fz9sPf for ; Thu, 2 Sep 2021 20:18:58 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id B2BD26147E; Thu, 2 Sep 2021 10:18:52 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id j-uyNm1G_xZv; Thu, 2 Sep 2021 10:18:48 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id BA0236147F; Thu, 2 Sep 2021 10:18:45 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 35FFEC0029; Thu, 2 Sep 2021 10:18:45 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id B0090C001B for ; Thu, 2 Sep 2021 10:18:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 9B746406EB for ; Thu, 2 Sep 2021 10:18:44 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IiPV8sfa7leZ for ; Thu, 2 Sep 2021 10:18:41 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2084.outbound.protection.outlook.com [40.107.223.84]) by smtp2.osuosl.org (Postfix) with ESMTPS id 896D0406D8 for ; Thu, 2 Sep 2021 10:18:41 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QnuTIjBvBofPKHIvoW/My7nqQsqmm4XVeOz8GAJ5ooNJAH9me5/Z+/cA3hYJmwNyx9AAYgpvFPow1+o9aTKnzRkc0nb+xUINRYT7ZTB1EUllIqa+VogTOqAG/pLDhTCahy3jsqOLZsy1E5m2zkhc+4x+XAyo/VA96eMULTcwph0FIhD/AoD2IKHlC0hey7EDtgshgN6slfP924UId+LfVZ5GWi+MsqPRbAcNFOANOvLlYKpOs7U1H4FkwqGEocHdXWK6OZyT8vGWpRsW02RgA15wX+s7gNaPXii6uPkRSh4bAJahJxuUy9e5JcwS3oS8OnNlgNpioyc/hxmsLJ46Nw== 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-SenderADCheck; bh=6jwp7ZUmsmFjwSxedVUK0NqSAZjLKXJgIbFKEhx5ixw=; b=Qcyn40CXbM5+b6NntSFJ5M7Qw0lPdqdiA0iN7mk1ccsLGxuVLWnnLMFL4wukdu4axf6nJ4Yvi/dvuujO3W05DVhG3MvhG7MrLbmDvLeQaif5NBQ4sYqOqWZX/FILY0bAFaQzCa4yueKS1t+Qu1doSAJ1rdoVob7vwGIAlDfSKEtwOR6dtIUnuyyEKZJZh8mbkwaPVCTCqdYg4HZ1tqd5teJT+S2Q0/Pt6bkiT6sk5iXNdrIwIx0Zzy2QyZa5Xq+T7JZ4a5Ro8JdVPv58M8DrADTlYHntEId9LFZisXCmQy+l+RfUG3rQRGO02VkxcYhTyqIcwklMTi2+8yAE22M/3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=ovn.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none 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=6jwp7ZUmsmFjwSxedVUK0NqSAZjLKXJgIbFKEhx5ixw=; b=Xs6c4U9c+CPk3d9Rzg825Dd2HFEcW1OJ1fRSD1VuvX1WaBCYCUml6NFey64lE9hivwbgrnmMVUA6jsad/RX06YMdiLlSn2e+ODj0HKTjQHFRIJu3HL2owfKCGpJl57hMqoOULufv4ny0zJvN42H3ItXeWtKl4pPUzx7RwlOtAoLLcYlTZ/5go4AoaAAIpQ5DYP/1QyYE+WWP6gagTC0BQuLwCz+cyqGnnbtYuVet0lWR6Qpbd65otPD9RsL+W5TYuPd4CKA81KGMPi9y5aoF69pLLhNb18URaDQHz6s1GMbDBUcHFYdGAE30AhcVICEZFLSkMrkNv2Q1iVU7sFDeuQ== Received: from MWHPR12CA0070.namprd12.prod.outlook.com (2603:10b6:300:103::32) by MW2PR12MB2538.namprd12.prod.outlook.com (2603:10b6:907:5::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.24; Thu, 2 Sep 2021 10:18:38 +0000 Received: from CO1NAM11FT067.eop-nam11.prod.protection.outlook.com (2603:10b6:300:103:cafe::a9) by MWHPR12CA0070.outlook.office365.com (2603:10b6:300:103::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 10:18:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) smtp.mailfrom=nvidia.com; ovn.org; dkim=none (message not signed) header.d=none;ovn.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by CO1NAM11FT067.mail.protection.outlook.com (10.13.174.212) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 10:18:38 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Sep 2021 10:18:37 +0000 Received: from dev-r-vrt-138.mtr.labs.mlnx (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 2 Sep 2021 03:18:36 -0700 To: , Ilya Maximets Date: Thu, 2 Sep 2021 13:18:22 +0300 Message-ID: <20210902101823.3403153-6-roid@nvidia.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210902101823.3403153-1-roid@nvidia.com> References: <20210902101823.3403153-1-roid@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 476d9c49-ce6f-4256-8969-08d96dfb07d5 X-MS-TrafficTypeDiagnostic: MW2PR12MB2538: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sIoxezedFY1tYUamYS6DeA0O7H7D0GPzC7vU7fduYzyy8Vn1JnER++iogKf4/Cgmq+9uhtwW8Lj56G3hezW5tlxt/OR7MYlhpl8pym51k8UsSal0CvZStqZiDh0vgXYdaXGxp6dijIACiY54tfzwM3SzGh4qDN4RVcu9GLs0SGXHXefEhB/c6Ule8cYKYga/3ocIVqVrtjcFoHBGO8faOHnAnRQmF62SAya+K7X9Kq61yBDobPdDOvNDEr1hhyG1zpGzjJHCAkniu6Rsn/mN8mk0baHhaPP7N/u4+MyWQ+T1EbgUEEHmVWwgp1AJi/uw98So7zUjfoTU0F6+B+iv3GIyyDfz6S9qlILzEkk0PhBrKa1a+W+Me/S9gYEW70SrmsqrJ5wJQCncDXloMbwnCwJCa3XAtb3MD/2wnImDTu+aJ5M400elSPNBEGWmzm/zGqGuEeirY0XZuAISkEhCLNRkKB8nR48Y3hswUdDWfafOshNMJZiKC0VkZAJCDEbb2SEONi0cAkbCd+h03IAMCbCI1U2XFiyckJwcoEaYJzNBTEcWnRsnuovPR/n9RTVHvRkC8AsrcjXeWfhUMpFZtl1HdY0EzpqLpp5P0jd/ebGfn8aX3V4lYbwaO7Bwn7mksZSfb456/+vNhhgLnj8pPIVMYg2cmeKCmpuhcC6Jw/GSOTw2+GPcEkjRNKgDqRpJtc+huIa68VAW3fuGpmqAmQ== X-Forefront-Antispam-Report: CIP:216.228.112.36; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid05.nvidia.com; CAT:NONE; SFS:(4636009)(39860400002)(136003)(346002)(396003)(376002)(46966006)(36840700001)(186003)(36756003)(54906003)(2616005)(8936002)(86362001)(336012)(426003)(26005)(36906005)(107886003)(316002)(2906002)(83380400001)(8676002)(1076003)(7636003)(36860700001)(70206006)(4326008)(47076005)(70586007)(110136005)(6666004)(356005)(82740400003)(5660300002)(82310400003)(478600001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 10:18:38.4080 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 476d9c49-ce6f-4256-8969-08d96dfb07d5 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.36]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT067.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR12MB2538 Cc: Jianbo Liu Subject: [ovs-dev] [PATCH 5/6] dpif-netlink: Cleanup police actions with reserved indexes on startup X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Roi Dayan via dev From: Roi Dayan Reply-To: Roi Dayan Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Jianbo Liu The police actions with indexes of 50000-59999 are reserved for OVS. To provide a clean environment for OVS, these reserved police actions should be deleted on startup. So dump all the tc police actions, delete those police actions if their indexes are in the ragne. Signed-off-by: Jianbo Liu Reviewed-by: Roi Dayan --- lib/dpif-netlink.c | 5 ++ lib/netdev-linux.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/netdev-linux.h | 3 ++ 3 files changed, 147 insertions(+) diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index fa68e69efbbe..409f3f4b6d2b 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -4469,6 +4469,11 @@ probe_broken_meters__(struct dpif *dpif) return true; } + if (netdev_is_flow_api_enabled()) { + tc_cleanup_policer_action(meter_police_ids, METER_POLICE_IDS_BASE, + METER_POLICE_IDS_MAX); + } + dpif_netlink_meter_del(dpif, id1, NULL, 0); dpif_netlink_meter_del(dpif, id2, NULL, 0); diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 63bcb8f9b173..6564cdf08dee 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -5783,6 +5783,145 @@ tc_del_policer_action(uint32_t index, struct ofputil_meter_stats *stats) return error; } +struct policer_node { + struct hmap_node node; + uint32_t police_idx; +}; + +static int +parse_netlink_to_tc_policer(struct ofpbuf *reply, uint32_t police_idx[]) +{ + static struct nl_policy actions_orders_policy[TCA_ACT_MAX_PRIO] = {}; + struct nlattr *actions_orders[ARRAY_SIZE(actions_orders_policy)]; + const int max_size = ARRAY_SIZE(actions_orders_policy); + const struct nlattr *actions; + struct tc_flower flower; + struct tcamsg *tca; + int i, cnt = 0; + int err; + + for (i = 0; i < max_size; i++) { + actions_orders_policy[i].type = NL_A_NESTED; + actions_orders_policy[i].optional = true; + } + + tca = ofpbuf_at_assert(reply, NLMSG_HDRLEN, sizeof *tca); + actions = nl_attr_find(reply, NLMSG_HDRLEN + sizeof *tca, TCA_ACT_TAB); + if (!actions || !nl_parse_nested(actions, actions_orders_policy, + actions_orders, max_size)) { + VLOG_ERR_RL(&rl, "failed to parse police actions"); + return EPROTO; + } + + for (i = 0; i < TCA_ACT_MAX_PRIO; i++) { + if (actions_orders[i]) { + memset(&flower, 0, sizeof(struct tc_flower)); + err = tc_parse_single_action(actions_orders[i], &flower, false); + if (err) { + continue; + } + if (flower.actions[0].police.index) { + police_idx[cnt++] = flower.actions[0].police.index; + } + } + } + + return 0; +} + +static int +tc_dump_tc_policer_start(struct nl_dump *dump) +{ + struct nla_bitfield32 flag_select; + size_t offset, root_offset; + struct ofpbuf request; + uint32_t prio = 0; + + tc_make_action_request(RTM_GETACTION, NLM_F_DUMP, &request); + root_offset = nl_msg_start_nested(&request, TCA_ACT_TAB); + offset = nl_msg_start_nested(&request, ++prio); + nl_msg_put_string(&request, TCA_ACT_KIND, "police"); + nl_msg_end_nested(&request, offset); + nl_msg_end_nested(&request, root_offset); + + flag_select.value = TCA_FLAG_LARGE_DUMP_ON; + flag_select.selector = TCA_FLAG_LARGE_DUMP_ON; + nl_msg_put_unspec(&request, TCA_ROOT_FLAGS, &flag_select, + sizeof(struct nla_bitfield32)); + nl_dump_start(dump, NETLINK_ROUTE, &request); + ofpbuf_uninit(&request); + + return 0; +} + +static int +tc_get_policer_action_ids(struct hmap *map) +{ + uint32_t police_idx[TCA_ACT_MAX_PRIO] = {}; + struct policer_node *policer_node; + struct netdev_flow_dump *dump; + struct ofpbuf rbuffer, reply; + size_t hash; + int i, err; + + dump = xzalloc(sizeof *dump); + dump->nl_dump = xzalloc(sizeof *dump->nl_dump); + + ofpbuf_init(&rbuffer, NL_DUMP_BUFSIZE); + tc_dump_tc_policer_start(dump->nl_dump); + + while (nl_dump_next(dump->nl_dump, &reply, &rbuffer)) { + if (parse_netlink_to_tc_policer(&reply, police_idx)) { + continue; + } + + for (i = 0; i < TCA_ACT_MAX_PRIO; i++) { + if (!police_idx[i]) { + break; + } + policer_node = xzalloc(sizeof *policer_node); + policer_node->police_idx = police_idx[i]; + hash = hash_int(police_idx[i], 0); + hmap_insert(map, &policer_node->node, hash); + } + memset(police_idx, 0, TCA_ACT_MAX_PRIO * sizeof(uint32_t)); + } + + err = nl_dump_done(dump->nl_dump); + ofpbuf_uninit(&rbuffer); + free(dump->nl_dump); + free(dump); + + return err; +} + +void +tc_cleanup_policer_action(struct id_pool *meter_police_ids, + uint32_t id_min, uint32_t id_max) +{ + struct policer_node *policer_node; + uint32_t police_idx; + struct hmap map; + int err; + + hmap_init(&map); + tc_get_policer_action_ids(&map); + + HMAP_FOR_EACH_POP (policer_node, node, &map) { + police_idx = policer_node->police_idx; + if (police_idx >= id_min && police_idx <= id_max) { + err = tc_del_policer_action(police_idx, NULL); + if (err) { + /* don't use this police any more */ + id_pool_add(meter_police_ids, police_idx); + } + } + free(policer_node); + } + + hmap_destroy(&map); +} + static void read_psched(void) { diff --git a/lib/netdev-linux.h b/lib/netdev-linux.h index 9a416ce505c9..cecb98e555d7 100644 --- a/lib/netdev-linux.h +++ b/lib/netdev-linux.h @@ -19,6 +19,7 @@ #include #include +#include "id-pool.h" #include "openvswitch/ofp-meter.h" /* These functions are Linux specific, so they should be used directly only by @@ -34,5 +35,7 @@ int tc_add_policer_action(uint32_t index, uint32_t kbits_rate, uint32_t pkts_burst, bool update); int tc_del_policer_action(uint32_t index, struct ofputil_meter_stats *stats); int tc_get_policer_action(uint32_t index, struct ofputil_meter_stats *stats); +void tc_cleanup_policer_action(struct id_pool *meter_police_ids, + uint32_t id_min, uint32_t id_max); #endif /* netdev-linux.h */ From patchwork Thu Sep 2 10:18:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roi Dayan X-Patchwork-Id: 1523593 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=O8Unw3fS; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H0cN40yN8z9sCD for ; Thu, 2 Sep 2021 20:19:00 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id D1A9C42549; Thu, 2 Sep 2021 10:18:57 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iJIQ6wzgwaoO; Thu, 2 Sep 2021 10:18:53 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 979494254A; Thu, 2 Sep 2021 10:18:48 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A30DAC0026; Thu, 2 Sep 2021 10:18:47 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id CF5E5C0025 for ; Thu, 2 Sep 2021 10:18:45 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id BE71B82AC3 for ; Thu, 2 Sep 2021 10:18:45 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LslMUB5mqVdV for ; Thu, 2 Sep 2021 10:18:44 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2053.outbound.protection.outlook.com [40.107.244.53]) by smtp1.osuosl.org (Postfix) with ESMTPS id 61ACB82768 for ; Thu, 2 Sep 2021 10:18:43 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eOLtasR8qoCvtdIsb2zf/4bbqPTGEG7DIkKMMr7f4keBGrbeVxAE4L4V+kI1BixYUrQCQVmXlQJpInaGVv60ODRWfsyab3KQmCZshILBnID2odC6vD97ut+pSWzFq5F7APwsIotMhhYqYEe74gE/Ve9wv3t5Z67XQagf9DhF37Zkfkwos6Sc6OHCljQVGX8jeevCuQBF24N/OYx1JGzhAW/HsNq53AY+47EjogUFJcTUdyXuPRKvUiBA5/SHdR26EA53OZ1HH2Ny9neikw3KKeaAkKfTxXlW4I0hKbjczCt+Wjcm8Rz0v90Z9Z0dAXUd7Z03yQwkbtL3C4xBfWUVTg== 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-SenderADCheck; bh=7s5IfFEtpNtdp7X1qgcPoP12vtuT2iI6WEDrIRfIBuE=; b=TddFwk9PA0Cs84i+gsEzVSl2RgHDuREnBBM+TUe0ZH/Q18BdZyvf1p2oqqQ6yBD69Mq7fhjUnO+9zMVMJP5mZj7T+erGFXQddIjOMxo//sQaGkviBqknZBHMssqMLphsJ8f64BxKuG9vu5vF+z20eSpNut8WzOlOCARzGdZmalgDbKEU8SOumQCW7HbfWzlLMtqQQ11h7xYFyjPtHrsqkAiZ/eKCyWXRyNvGrXtaSWh/ZxLyNd7WxUNEYlINdImcJ0iNyhiqZNWYHSBNMK9nUuSVFZzURxb2Co/lqVQDwk3FkrDhIVIAZv+fVOKP+cFlImfAYnimxeMLKkQijeIAlw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=ovn.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none 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=7s5IfFEtpNtdp7X1qgcPoP12vtuT2iI6WEDrIRfIBuE=; b=O8Unw3fSRWODhqx4lzT9a7OjVi8QGb9p/dzpY89cBmJgw5+m3Od1C1d2vyRA8TDuQtfZcGerwDxBan9jOvBFH6a+UB9c0sW+DbaorgpyQegtbp3xEQoTtgPXXkLzFaLbUB8K8mgRMsz9TmpAtGQ38ysC9PTa2Yu+ViEe3V5cJ3DdOCmLXhBKXwP/QLlxWeuZG7+8/zadiYGOeVwBuY61e/VdyiDjylFPlfCYuIxW/hs4R8MSp3iYkSePum0x6tN/7LrrFrt5wWcytb3nPQwFvpaeA/cu9QJDkZsZAOTLVKTF5e73qGeWcjWAj0PjAyLOQJqaTD7KeCcC2xIdrG7xjA== Received: from MW4P222CA0020.NAMP222.PROD.OUTLOOK.COM (2603:10b6:303:114::25) by DM5PR1201MB2473.namprd12.prod.outlook.com (2603:10b6:3:e2::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.19; Thu, 2 Sep 2021 10:18:41 +0000 Received: from CO1NAM11FT049.eop-nam11.prod.protection.outlook.com (2603:10b6:303:114:cafe::d4) by MW4P222CA0020.outlook.office365.com (2603:10b6:303:114::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.20 via Frontend Transport; Thu, 2 Sep 2021 10:18:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; ovn.org; dkim=none (message not signed) header.d=none;ovn.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by CO1NAM11FT049.mail.protection.outlook.com (10.13.175.50) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 10:18:40 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Sep 2021 10:18:39 +0000 Received: from dev-r-vrt-138.mtr.labs.mlnx (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 2 Sep 2021 03:18:38 -0700 To: , Ilya Maximets Date: Thu, 2 Sep 2021 13:18:23 +0300 Message-ID: <20210902101823.3403153-7-roid@nvidia.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210902101823.3403153-1-roid@nvidia.com> References: <20210902101823.3403153-1-roid@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a514fa2d-cd58-4ecd-d8c3-08d96dfb090d X-MS-TrafficTypeDiagnostic: DM5PR1201MB2473: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6lQdWv8ZqtoVdjKoN7uncNX6wOMuVjJvVvOEkB//OxMiyOvE1V2BhCDHJjqmFFMaAzXWHfsMaoCqwPhEz1bpkKnL6a0aFruHfKbpm35WpCypBAJhJR/7CwvoVD5j4NWql/nnpOpKkZEIaR5HxX+fjkAdZjlGXcpoA+bHLDcP+xhHPD7mtEgFRPuVZjDAU6xgVcFrC73kHWxr6e5OBvJ1KBaBtxjJVid8HcKtaCh5MZNZwcy/r5eTyTQ6AcNb1bk8PL/ByprELKVA9l6jM/YL2FPuZDS3CuB3PXcd3x3hzzCWCFhjnytFPdLnyKm0LAM0Iz4qPIgZJyczr6X0lzACYoQVFssOODA2ILvzDTsjDvkgCuGJpH4CvYYejmZberTdAlTORwfe+R661aI4MhNeMpBYY8jqsPKHZqtj/RUKDVkWpQ1O0/F0EHZOop/m47wpUrisj2snkzA1f++Nh37+XoxczhJA20NJEpGRVPMzH5bFq+y9+p4Q3nhXQFXgw/Tiy9vMktv9D4eGJMl9P0hkLuF1SAKUSRvDGwDytQSmVCXt+HwVy+NroyC/0JY5D4dld531HtkBPSzQAbLBXnwFnp1QhWQjpVP03Rur2eSpsPJHYluARpg4xkn3x+PUPzzjcf3E8FrkcCaNaGgkXSoyA68qMjFPd/7iuspmbhDkPki+/3bwlAVBIL3Cm9lopb7KX5lwEEBB4fe7WT7i4taqpg== X-Forefront-Antispam-Report: CIP:216.228.112.35; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid02.nvidia.com; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(4326008)(70206006)(1076003)(83380400001)(82310400003)(107886003)(36906005)(36860700001)(2616005)(2906002)(336012)(508600001)(316002)(36756003)(110136005)(54906003)(426003)(70586007)(8676002)(8936002)(5660300002)(47076005)(6666004)(7636003)(86362001)(356005)(26005)(186003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 10:18:40.4048 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a514fa2d-cd58-4ecd-d8c3-08d96dfb090d X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.35]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT049.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB2473 Cc: Jianbo Liu Subject: [ovs-dev] [PATCH 6/6] netdev-offload-tc: Offloading rules with police actions X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Roi Dayan via dev From: Roi Dayan Reply-To: Roi Dayan Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Jianbo Liu To offload OVS meter, a meter is mapped to police action. While offoading rule, tc should be filled with police index, instead of meter id. So dpif passes police indexes in the additional info to tc offload, then they are used to replace meter id in tc rule. An action cookie is created to save meter id on rule creation, so meter id can be retrieved from the cookie, and pass to dpif while dumping. Signed-off-by: Jianbo Liu Reviewed-by: Roi Dayan --- lib/dpif-netlink.c | 14 ++++++++++++++ lib/netdev-offload-tc.c | 11 +++++++++++ lib/netdev-offload.h | 4 ++++ lib/tc.c | 36 +++++++++++++++++++++++++++++++++++- lib/tc.h | 1 + 5 files changed, 65 insertions(+), 1 deletion(-) diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index 409f3f4b6d2b..2ca8ff308c91 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -2205,6 +2205,7 @@ parse_flow_put(struct dpif_netlink *dpif, struct dpif_flow_put *put) struct offload_info info; ovs_be16 dst_port = 0; uint8_t csum_on = false; + int n_meters = 0; int err; info.tc_modify_flow_deleted = false; @@ -2245,6 +2246,19 @@ parse_flow_put(struct dpif_netlink *dpif, struct dpif_flow_put *put) csum_on = tnl_cfg->csum; } netdev_close(outdev); + } else if (nl_attr_type(nla) == OVS_ACTION_ATTR_METER) { + uint32_t meter_id = nl_attr_get_u32(nla); + uint32_t police_idx; + + if (meter_id_lookup(meter_id, &police_idx)) { + err = EINVAL; + goto out; + } + if (n_meters >= MAX_OFFLOAD_METERS) { + err = EOPNOTSUPP; + goto out; + } + info.police_ids[n_meters++] = police_idx; } } diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index 9845e8d3feae..757f60fbe8bf 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -1015,6 +1015,11 @@ parse_tc_flower_to_match(struct tc_flower *flower, nl_msg_put_u32(buf, OVS_ACTION_ATTR_RECIRC, action->chain); } break; + case TC_ACT_POLICE: { + nl_msg_put_u32(buf, OVS_ACTION_ATTR_METER, + action->police.meter_id); + } + break; } } } @@ -1580,6 +1585,7 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, uint32_t block_id = 0; struct nlattr *nla; struct tcf_id id; + int n_meters = 0; uint32_t chain; size_t left; int prio = 0; @@ -1917,6 +1923,11 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, action->type = TC_ACT_GOTO; action->chain = 0; /* 0 is reserved and not used by recirc. */ flower.action_count++; + } else if (nl_attr_type(nla) == OVS_ACTION_ATTR_METER) { + action->type = TC_ACT_POLICE; + action->police.meter_id = nl_attr_get_u32(nla); + action->police.index = info->police_ids[n_meters++]; + flower.action_count++; } else { VLOG_DBG_RL(&rl, "unsupported put action type: %d", nl_attr_type(nla)); diff --git a/lib/netdev-offload.h b/lib/netdev-offload.h index e7fcedae9397..370542e2315c 100644 --- a/lib/netdev-offload.h +++ b/lib/netdev-offload.h @@ -27,6 +27,8 @@ extern "C" { #endif +#define MAX_OFFLOAD_METERS 4 + struct dp_packet_batch; struct dp_packet; struct netdev_class; @@ -77,6 +79,8 @@ struct offload_info { bool tc_modify_flow_deleted; /* Indicate the tc modify flow put success * to delete the original flow. */ odp_port_t orig_in_port; /* Originating in_port for tnl flows. */ + uint32_t police_ids[MAX_OFFLOAD_METERS]; /* police ids of the offloaded + * meters in the flow */ }; int netdev_flow_flush(struct netdev *); diff --git a/lib/tc.c b/lib/tc.c index 75c9e1ad16ea..4685fc22f4e2 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -1375,7 +1375,8 @@ static const struct nl_policy police_policy[] = { }; static int -nl_parse_act_police(const struct nlattr *options, struct tc_flower *flower) +nl_parse_act_police(const struct nlattr *options, struct tc_flower *flower, + struct nlattr *act_cookie) { struct nlattr *police_attrs[ARRAY_SIZE(police_policy)] = {}; struct tc_action *action; @@ -1394,6 +1395,10 @@ nl_parse_act_police(const struct nlattr *options, struct tc_flower *flower) action->type = TC_ACT_POLICE; action->police.index = police->index; + if (act_cookie) { + action->police.meter_id = nl_attr_get_u32(act_cookie); + } + police_tm = police_attrs[TCA_POLICE_TM]; if (police_tm) { tm = nl_attr_get_unspec(police_tm, sizeof *tm); @@ -1811,6 +1816,8 @@ nl_parse_single_action(struct nlattr *action, struct tc_flower *flower, /* Added for TC rule only (not in OvS rule) so ignore. */ } else if (!strcmp(act_kind, "ct")) { nl_parse_act_ct(act_options, flower); + } else if (!strcmp(act_kind, "police")) { + nl_parse_act_police(act_options, flower, act_cookie); } else { VLOG_ERR_RL(&error_rl, "unknown tc action kind: %s", act_kind); err = EINVAL; @@ -2326,6 +2333,22 @@ nl_msg_put_act_gact(struct ofpbuf *request, uint32_t chain) } static void +nl_msg_put_act_police_index(struct ofpbuf *request, uint32_t police_idx) +{ + struct tc_police police; + size_t offset; + + memset(&police, 0, sizeof police); + police.index = police_idx; + + nl_msg_put_string(request, TCA_ACT_KIND, "police"); + offset = nl_msg_start_nested(request, TCA_ACT_OPTIONS); + nl_msg_put_unspec(request, TCA_POLICE_TBF, &police, sizeof police); + nl_msg_put_u32(request, TCA_POLICE_RESULT, TC_ACT_PIPE); + nl_msg_end_nested(request, offset); +} + +static void nl_msg_put_act_ct(struct ofpbuf *request, struct tc_action *action) { uint16_t ct_action = 0; @@ -2775,6 +2798,17 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower) nl_msg_end_nested(request, act_offset); } break; + case TC_ACT_POLICE: { + struct tc_cookie act_cookie; + + act_offset = nl_msg_start_nested(request, act_index++); + nl_msg_put_act_police_index(request, action->police.index); + act_cookie.data = &action->police.meter_id; + act_cookie.len = sizeof(action->police.meter_id); + nl_msg_put_act_cookie(request, &act_cookie); + nl_msg_end_nested(request, act_offset); + } + break; } } } diff --git a/lib/tc.h b/lib/tc.h index f31bec5d2b4b..32751a8ba6dd 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -261,6 +261,7 @@ struct tc_action { } ct; struct { uint32_t index; + uint32_t meter_id; } police; };