From patchwork Thu Mar 14 14:52:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13592505 X-Patchwork-Delegate: dsahern@gmail.com Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2067.outbound.protection.outlook.com [40.107.102.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 558E971727 for ; Thu, 14 Mar 2024 14:56:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.102.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710428175; cv=fail; b=COYPRaRWQkk3gtNwUgspbzQMIbDVEBhQn/nuz++d4x9jHIPM6cp2IrmgZFxmBNuncsAkRaGY4nQHwDlvbyfDS0P9/tPX4KfvCh+Lf1jUPm0IvbF72T3MhYqqWiJMtsk8B7gDaUfG2987gUAFUtRuXSelR2X+EBSmv5yS+hQ5Sqc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710428175; c=relaxed/simple; bh=i/NO8W1DG737OOZDLdoOOtwGo9lD6Joe9FUWRpbtQ8I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DHKlrWj8NGrwS7xm4FDuNnDS3PvvkhGvIOKJvt8VTz3votKKepA9Js8wcJKTgtbKmDDF0IKUds2kn/xW+xS/Eaw1N0AaNTHn1e7kvVxB+YdUlGitRKXe6wb4fq9Is56AiEE8wK6Q6j2siMegNSldKxDg7ISrd+DUs15TUWeoKO8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=gHd1X5ka; arc=fail smtp.client-ip=40.107.102.67 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="gHd1X5ka" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PFkindI8d8P1o81jGqovGLZgqOpr3Wz38uQRjx5bDEffLZmEgaYKpURU2/RBFisgSnoMJtXAeEDP6KUW19pDSiHMRFHKnwzJZxxuKCMSl4B2YsyHbNN12HgzOs/1q4EuH4skT1SXVOjhx+yRRckXk8LSkjfNUnp/zwoIqeimP3gd9LmmR/h8+9EY77SP6nrgFRCN4sUVj7+tQmZOGxV/6m4CyFGsu+sBTQy6GfWrWaDByF+39pxZMsQFPb/sfGo/qktEp5Z74FpYyY5McXg5piHleYlr2r9OFjsG/znqGlaAzMnf8ibXx2gq45e6LAgXzGob5vnAyf+WSduOUfnwQg== 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=bJa0/2F37+kKdHvMNj19xbSetUARlU678Vf2mPRywZs=; b=EqBqYx5+VpNdBggRm7cBvzkQRrKjCeXR31YTQETrTDGiOYIk8au9YqWRU4LC2gqTIUhWMGvhggt14X4KjMdruIDsYe/fvlCRBgTnoSFMSygQ5BsqSXiM/p2Ilqoo4LFEa4Dh+7leTAxqr6lifwknucmK06yGVxSObHwK0Mk8OeQ8ilkrk2cuCojlhL82GXFpuFngMYqSZE/PHjXARd01vlQZjd7wiYeCeKzdfo/0xEEKzCjcatk51sC+ds5UU6XHPjjGTatP2PPio3KXmJ0HXHH/D8EDhh+Wctp64AY//uQ6ny6Z0LHbHcB3cYM5AqFsfUZAjOKdMD9Qac2NBX8MCg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kernel.org 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 (0) 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=bJa0/2F37+kKdHvMNj19xbSetUARlU678Vf2mPRywZs=; b=gHd1X5ka/jjwB6fI4F1gPh2DfiaAIkWhQ1byrLlFMHfMUHvPQUNoTEswuhLN5vsNPmA+HIjROZQyiqAGeBWM0kEp8C3M0NTPVk5IJ+/ATCQQGtdJXeLbHyjnUhi6uWBBU8PSKg2Roes7io8CwTRqzskwD3WqVF1R9V49g5/Onwr8WJE9t/OQWv06zQnRIJozn/09aBbduW0sO5kHfZbEUZ45KSfjEEboZh12qHJHC0q19J/9rDDDWZLO8qq+b45DEgGQrupe/toeeUTtVSCGlLQlCQsofojn+WpAyh1+J1jGq+hZrv6jKSZ1YH6qpNapZkMdpw2qatNqeTr4jTZVIQ== Received: from DM6PR02CA0074.namprd02.prod.outlook.com (2603:10b6:5:1f4::15) by CY8PR12MB7708.namprd12.prod.outlook.com (2603:10b6:930:87::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.36; Thu, 14 Mar 2024 14:56:11 +0000 Received: from DS1PEPF00017092.namprd03.prod.outlook.com (2603:10b6:5:1f4:cafe::70) by DM6PR02CA0074.outlook.office365.com (2603:10b6:5:1f4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.22 via Frontend Transport; Thu, 14 Mar 2024 14:56:11 +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 DS1PEPF00017092.mail.protection.outlook.com (10.167.17.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.12 via Frontend Transport; Thu, 14 Mar 2024 14:56:11 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 14 Mar 2024 07:55:56 -0700 Received: from localhost.localdomain (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Thu, 14 Mar 2024 07:55:52 -0700 From: Petr Machata To: David Ahern , Stephen Hemminger , CC: Ido Schimmel , Petr Machata , "Jakub Kicinski" , Subject: [PATCH iproute2-next v2 1/4] libnetlink: Add rta_getattr_uint() Date: Thu, 14 Mar 2024 15:52:12 +0100 Message-ID: X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017092:EE_|CY8PR12MB7708:EE_ X-MS-Office365-Filtering-Correlation-Id: 42485a29-ecdf-41f2-c946-08dc4436e395 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ApTYIO/RndL/QDuiVSnm5Ehs/5yYCwqskZJ1m1lmG0/65QCNweGvTNdAedNNJfg5VbKJh0Uw8GJagpMTXW3RfaS/507XpGYEfefhxupoBt9Okb4hFGBbgDKb3AUeAY4HVuDS20eM/qqknCpnP483v7Oj2UzFY1mXZWaNOCG+EELJZqJTWNtbNKj5prwVDHASZTMxKkfoDt3XE6qs7wsn2L4omgE4uLb4R9xav/wdcfL/20DWGt8a6+Y5lOAvvmkwua+GCK6g3CmFy6n3EI55PlA3R3YA09X6NveSXYxFhWSKMIPFzn5nrEiAptjzkf7pbhvY0aBgnetyOhOmbx1ZPGDodgkv7yilLXMvwFV+ZiPp0mv3MmoHSPwXiiwLVTCIQRPOvl04dxqHREsvKYdp4ZXtkfayKLEZ20RVPpd44cR9yxiOeTpiQM+04edM7IXt2CJoDBumR93pmAmulmsLx3qodhqugrkI2AyfcugiZCoS22jQQxbxpX6aKmOYehsdhYPR0xKt0BlMpbOoAingE9SwFZOU3rR6Ci6TM4MmNUb0RKfg7hXBkpjku9AWX8Ov4oGsrYkEwHLsXECtzZOM7qA+EP0h/A6SL3k77cDiC1rspcWTEAwAjkGYbAVuNjDeWUVpjTHfDadOhIzf30F+H6rkhT21Ki66XE6Q6LaX5T/P8mU8+w9BwlzBnAsd8YBguLGguviILbGrCN5PLUA9pRkRLNFh+alxBvs59APrqGXJQbttC0MdzN4yDXi4AV3p 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:(13230031)(1800799015)(376005)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Mar 2024 14:56:11.5372 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 42485a29-ecdf-41f2-c946-08dc4436e395 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: DS1PEPF00017092.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7708 X-Patchwork-Delegate: dsahern@gmail.com NLA_UINT attributes have a 4-byte payload if possible, and an 8-byte one if necessary. Add a function to extract these. Since we need to dispatch on length anyway, make the getter truly universal by supporting also u8 and u16. Signed-off-by: Petr Machata --- Notes: v2: - have rta_getattr_uint() support 8- and 16-bit quantities as well include/libnetlink.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/libnetlink.h b/include/libnetlink.h index ad7e7127..35a9bb57 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -260,6 +260,20 @@ static inline __u64 rta_getattr_u64(const struct rtattr *rta) memcpy(&tmp, RTA_DATA(rta), sizeof(__u64)); return tmp; } +static inline __u64 rta_getattr_uint(const struct rtattr *rta) +{ + switch (RTA_PAYLOAD(rta)) { + case sizeof(__u8): + return rta_getattr_u8(rta); + case sizeof(__u16): + return rta_getattr_u16(rta); + case sizeof(__u32): + return rta_getattr_u32(rta); + case sizeof(__u64): + return rta_getattr_u64(rta); + } + return -1ULL; +} static inline __s32 rta_getattr_s32(const struct rtattr *rta) { return *(__s32 *)RTA_DATA(rta); From patchwork Thu Mar 14 14:52:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13592506 X-Patchwork-Delegate: dsahern@gmail.com Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2055.outbound.protection.outlook.com [40.107.92.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D25971735 for ; Thu, 14 Mar 2024 14:56:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710428178; cv=fail; b=r0OFGZt4N0jq/rj9m1aKWqg6iZnS/n1ZL4Wys4wkA782PkldWFt5UQUC68ojh1O0bVOwW+2t2IG/l8TUokNjm6lpaWrWhA0uJfI66crSHcWZMTHB7kq044tt1uArCsZdmBv2zXENJcFXufIG/9NqpJP+F2sf2DqugPciaUZI6mQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710428178; c=relaxed/simple; bh=uUwSYAGpidRzK9RpHnrZHkCVrqN6xxxuESoVcyVOo8A=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Fi/AEIcb01YsBGavM/qi4Q7xtIkOQ9WytaeVxw8B8+JUeuQKFp2u2ZQ0uzm8iHI0azoQNzE8+j8SFHq2QoAQ0s/ZNkFwt29avLF28/S+Uhbpz7+NWYkqJlsa1PzMlSJRVN1W3cbmAV0LbH60ac8d0x/5mBJWZHrfa3wvsY5WQG4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=FVH0Tw4R; arc=fail smtp.client-ip=40.107.92.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="FVH0Tw4R" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SXxGHESxrZMiJh+2R6nWW3UFlGtdCPHAMgNZOC0r6hxvPUDl8N7BLHwLej/FziBkWn6TGGig/nidSxfzO9V6IVb9XVk0oQjM/xRGIMqMvnPrr4pbniQBkWZdIxTBQ7Teosu5Tf0E37wL/W7P0HGBTVdp09LK1hq+c+67u3+5B0lby/6XpIqXQ3opYiFDMVrujmgOtKmOZdoej21bXtMs5SUJYGmiLHmuUuJK2RrK+zv2miEIQVzRGNmijkCK8+XcIJU9et9FaRIkT1xHYAkTlA5fN9uH6TwJn+uIZ3gEtkZDrdMUXnkoyW+id0GmgMa/3M7ae6UhxSdNACqwA2uofg== 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=2wXGl072B94HOE1sfE+IEYopNKbrtvmEqzK1KSlmZnY=; b=RiJ8g14k89x5eR8QzWYovedfgjKjnkKeJ7uNFfjf6IMtd2JnnZ6DG6DNJFJ3Pfwnr/kPJREr9Mz2douoaQEWMsrec/+lTrcXVrRPjXbL7oiW2NVVpsMZjOrD8zbNs6NJkRhMD/Zb74mO9FFvMw4ItfcDS6OnAlj2sskiQb+e6DErzQXda8bHhUnSJyUcuGKTmWB7Lt2zsR3cBZIw9gWug4oOeHtP0SI9rDjgNaYM3zDZC+6fK4v5gkAeBHjKQ4FBLgoujlQapzkdCZ9P2ufm2S4CG/hdUAMCrMdv2416x3N0ist8C1gueDgcJg2jXXEmRxsTRHicq+c++hu3xagNyw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org 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 (0) 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=2wXGl072B94HOE1sfE+IEYopNKbrtvmEqzK1KSlmZnY=; b=FVH0Tw4RpqOx1Sw35EQo5uTj+8PVUVu1Y4wekwHXfgrc67hZ0jakD9X5xfoCFdvKpKV4BQsSsHxhADeHUklgLlzKIDEtlBa6ggnkccDLiRxi7zGzDwWu9wCfekef9hTKrKK+X9ZrEomh8UONXKRGUPHWpjFSKJ6+T9zAgm3NMDI+VfkkZxaUSiZ80FMMVqvHcyBwg+2MIQFOnlU3K3r20+Bvwo52tznnaLcP5KCmYXOUtgfRWsV6D+j2kii1/dkjybwziQ1lLmCX9HBc2WFiXPXOtCUtTXgYDd9lVwLRVvyOuogMDoaLZnaMmacbj7Fu0t7YV0dxv/CRdx8o1kEXjg== Received: from SJ0PR13CA0071.namprd13.prod.outlook.com (2603:10b6:a03:2c4::16) by BY5PR12MB4146.namprd12.prod.outlook.com (2603:10b6:a03:20d::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.19; Thu, 14 Mar 2024 14:56:12 +0000 Received: from SJ5PEPF000001D7.namprd05.prod.outlook.com (2603:10b6:a03:2c4:cafe::8d) by SJ0PR13CA0071.outlook.office365.com (2603:10b6:a03:2c4::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.8 via Frontend Transport; Thu, 14 Mar 2024 14:56:12 +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 SJ5PEPF000001D7.mail.protection.outlook.com (10.167.242.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.12 via Frontend Transport; Thu, 14 Mar 2024 14:56:11 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) 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.41; Thu, 14 Mar 2024 07:55:59 -0700 Received: from localhost.localdomain (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Thu, 14 Mar 2024 07:55:56 -0700 From: Petr Machata To: David Ahern , Stephen Hemminger , CC: Ido Schimmel , Petr Machata , "Jakub Kicinski" , Subject: [PATCH iproute2-next v2 2/4] ip: ipnexthop: Support dumping next hop group stats Date: Thu, 14 Mar 2024 15:52:13 +0100 Message-ID: <66b2df7b7226a5a25bfcf32c9ef7f41394729ef4.1710427655.git.petrm@nvidia.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF000001D7:EE_|BY5PR12MB4146:EE_ X-MS-Office365-Filtering-Correlation-Id: a0c851de-c451-4efa-a260-08dc4436e3c4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ksb3Z41F8Y4P86L186JHLEQfD4UY6ww6xB6KoRwr14ocVLVGp2emrBZzJ0mwBd3SPodZLM5/WZ2GNU9CvlxQ3KMEZhX0OfOQeEi85F9TJwqaTHfGUasB4SjhCeBXcvGZB+EB4o9dgeJEp9lZ754Z5gJJe4dG1F1eNrMuRrh6Oaq6hM8ETqlZJ6VYxiP0+400BotpYXIGpBVcOFMTXidCks5D0U7Fv95BA4TiByROMctVqlyRqMW0xvM+ewDJuxYDpIR3ILkOFz2IvRAJDJk2Fw3uRCXdBPIZzOsS2AFLMuG0Jl2hP2V6JIQ6c4gPuPFNJ0QqR4WUxo2Gu1kaLg/6gVx2dFg1NIWf/Hicv0ETpNUDj3uD4eBgqc6dvwpdzqWrUHNgCD6+eULghPzhmTz/N1vXEKJzFIsODPeXojQF8wlyYy0+i2Zm1aSvw7YgpmKz4L07/isS3koC2bqqR/UU1Es3ft8nL1KcX5ZVLhY8MsZrhgfG09icIUSMXLs2ZZaw+XAuhh7oVw5uiaX3SzkFKJuZHzS24y+O886Pt5/X03vdSFHfftO1b77YEEDkF9WOVPUlxmn87BB64J3GtheJ55qBu7kdThmOB6Q8DfuQDPT0d6XcVE4F6JlxHsISe4q0NXjSPYBd8256+Id0UI8aoAkKvhTQvp21IqWez1Tln+EoI9FQyO0E5q9BFLNay296VlhRvNAp1txvQrbiGuyRS835VB7Hm14lahyQ+VfsKJzt+FvLSnWbDD2zS/0S52E2 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:(13230031)(376005)(36860700004)(82310400014)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Mar 2024 14:56:11.9692 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a0c851de-c451-4efa-a260-08dc4436e3c4 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: SJ5PEPF000001D7.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4146 X-Patchwork-Delegate: dsahern@gmail.com Next hop group stats allow verification of balancedness of a next hop group. The feature was merged in kernel commit 7cf497e5a122 ("Merge branch 'nexthop-group-stats'"). Add to ip the corresponding support. The statistics are requested if "ip nexthop" is started with -s. Signed-off-by: Petr Machata --- Notes: v2: - Use print_nl() for the newlines ip/ipnexthop.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ ip/nh_common.h | 6 ++++ 2 files changed, 95 insertions(+) diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c index e946d6f9..cba3d934 100644 --- a/ip/ipnexthop.c +++ b/ip/ipnexthop.c @@ -25,6 +25,7 @@ static struct { unsigned int fdb; unsigned int id; unsigned int nhid; + unsigned int op_flags; } filter; enum { @@ -92,6 +93,14 @@ static int nh_dump_filter(struct nlmsghdr *nlh, int reqlen) return err; } + if (filter.op_flags) { + __u32 op_flags = filter.op_flags; + + err = addattr32(nlh, reqlen, NHA_OP_FLAGS, op_flags); + if (err) + return err; + } + return 0; } @@ -296,6 +305,31 @@ static void parse_nh_res_group_rta(const struct rtattr *res_grp_attr, } } +static void parse_nh_group_stats_rta(const struct rtattr *grp_stats_attr, + struct nh_entry *nhe) +{ + const struct rtattr *pos; + int i = 0; + + rtattr_for_each_nested(pos, grp_stats_attr) { + struct nh_grp_stats *nh_grp_stats = &nhe->nh_grp_stats[i++]; + struct rtattr *tb[NHA_GROUP_STATS_ENTRY_MAX + 1]; + struct rtattr *rta; + + parse_rtattr_nested(tb, NHA_GROUP_STATS_ENTRY_MAX, pos); + + if (tb[NHA_GROUP_STATS_ENTRY_ID]) { + rta = tb[NHA_GROUP_STATS_ENTRY_ID]; + nh_grp_stats->nh_id = rta_getattr_u32(rta); + } + + if (tb[NHA_GROUP_STATS_ENTRY_PACKETS]) { + rta = tb[NHA_GROUP_STATS_ENTRY_PACKETS]; + nh_grp_stats->packets = rta_getattr_uint(rta); + } + } +} + static void print_nh_res_group(const struct nha_res_grp *res_grp) { struct timeval tv; @@ -343,8 +377,35 @@ static void print_nh_res_bucket(FILE *fp, const struct rtattr *res_bucket_attr) close_json_object(); } +static void print_nh_grp_stats(const struct nh_entry *nhe) +{ + int i; + + if (!show_stats) + return; + + open_json_array(PRINT_JSON, "group_stats"); + print_nl(); + print_string(PRINT_FP, NULL, " stats:", NULL); + print_nl(); + for (i = 0; i < nhe->nh_groups_cnt; i++) { + open_json_object(NULL); + + print_uint(PRINT_ANY, "id", " id %u", + nhe->nh_grp_stats[i].nh_id); + print_u64(PRINT_ANY, "packets", " packets %llu", + nhe->nh_grp_stats[i].packets); + + if (i != nhe->nh_groups_cnt - 1) + print_nl(); + close_json_object(); + } + close_json_array(PRINT_JSON, NULL); +} + static void ipnh_destroy_entry(struct nh_entry *nhe) { + free(nhe->nh_grp_stats); free(nhe->nh_encap); free(nhe->nh_groups); } @@ -418,6 +479,16 @@ static int ipnh_parse_nhmsg(FILE *fp, const struct nhmsg *nhm, int len, nhe->nh_has_res_grp = true; } + if (tb[NHA_GROUP_STATS]) { + nhe->nh_grp_stats = calloc(nhe->nh_groups_cnt, + sizeof(*nhe->nh_grp_stats)); + if (!nhe->nh_grp_stats) { + err = -ENOMEM; + goto out_err; + } + parse_nh_group_stats_rta(tb[NHA_GROUP_STATS], nhe); + } + nhe->nh_blackhole = !!tb[NHA_BLACKHOLE]; nhe->nh_fdb = !!tb[NHA_FDB]; @@ -484,9 +555,23 @@ static void __print_nexthop_entry(FILE *fp, const char *jsobj, if (nhe->nh_fdb) print_null(PRINT_ANY, "fdb", "fdb", NULL); + if (nhe->nh_grp_stats) + print_nh_grp_stats(nhe); + close_json_object(); } +static __u32 ipnh_get_op_flags(void) +{ + __u32 op_flags = 0; + + if (show_stats) { + op_flags |= NHA_OP_FLAG_DUMP_STATS; + } + + return op_flags; +} + static int __ipnh_get_id(struct rtnl_handle *rthp, __u32 nh_id, struct nlmsghdr **answer) { @@ -500,8 +585,10 @@ static int __ipnh_get_id(struct rtnl_handle *rthp, __u32 nh_id, .n.nlmsg_type = RTM_GETNEXTHOP, .nhm.nh_family = preferred_family, }; + __u32 op_flags = ipnh_get_op_flags(); addattr32(&req.n, sizeof(req), NHA_ID, nh_id); + addattr32(&req.n, sizeof(req), NHA_OP_FLAGS, op_flags); return rtnl_talk(rthp, &req.n, answer); } @@ -1093,6 +1180,8 @@ static int ipnh_list_flush(int argc, char **argv, int action) argc--; argv++; } + filter.op_flags = ipnh_get_op_flags(); + if (action == IPNH_FLUSH) return ipnh_flush(all); diff --git a/ip/nh_common.h b/ip/nh_common.h index 4d6677e6..e2f74ec5 100644 --- a/ip/nh_common.h +++ b/ip/nh_common.h @@ -13,6 +13,11 @@ struct nha_res_grp { __u64 unbalanced_time; }; +struct nh_grp_stats { + __u32 nh_id; + __u64 packets; +}; + struct nh_entry { struct hlist_node nh_hash; @@ -44,6 +49,7 @@ struct nh_entry { int nh_groups_cnt; struct nexthop_grp *nh_groups; + struct nh_grp_stats *nh_grp_stats; }; void print_cache_nexthop_id(FILE *fp, const char *fp_prefix, const char *jsobj, From patchwork Thu Mar 14 14:52:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13592507 X-Patchwork-Delegate: dsahern@gmail.com Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2085.outbound.protection.outlook.com [40.107.220.85]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53AE43B182 for ; Thu, 14 Mar 2024 14:56:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710428185; cv=fail; b=Sew9No+4gnEmMMBkMPBn3z/mQ4t56sIJ3T4H6xcCVBVAXeu2KNP1b4OcFti/Aju/jZSgmeiM9GJqZ2I0jYoPHUeJWyaxilKOjuVuYJy52l6aAaEBu70alvws+gM568i1HcsTxvsXMSn0GCpRA03hI9jmy4gTfEfv1vFRWrMLlCw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710428185; c=relaxed/simple; bh=/bDWdh7/JKRsWfYMSgBbr3zbKedpGvjRfhPb+sa+LeI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rtcsPnc9l90VeXhnJxIDjllPzQ4zAp1Hpzi4UVZV+ELZBkv/sXYRQ684OOeHwqmdKIJfh6EoEp9nrSb5+c9PShH8MJzPDBO+L8FYjZ4l2ybHQwFkMGWXLoxCXiYZMIK/FQule8t0DBF6vWYE+PPT3BGEeI/l4T0TRXXrLmfUBao= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=svY8Og18; arc=fail smtp.client-ip=40.107.220.85 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="svY8Og18" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IuoRS7bkn6K8r45qp2SbvhvRrXPC++8+ocinwRRYGNKolwfxaxcgdkXdP2KZd9/sUlSG4o7rENHq7clNHC03dRz+2XWAfk4f4vcaMIYKa1xZPZGpoNIQbkKwfKtz2l0RvozDKXBbVhOHMrHPYdzkHGmZhs70Ba3gb2yGV9HzaxKXFWMV7R3ZmIcYJS0Gy5NHVHSbiebiSw36kVhwZO2J8TiaXTQO8ZfFvZEo2BkaTe9qv6JwicxRh7SiMYJNTfQUQ0BBFc6DnkugsT2bDBzh0vDB/0jVwTzd9Ry5V4DHsuLe3cBykmHnq6lmIFPmA2VtzgGvUjuenLVomerejCQbqw== 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=Kr8BR33hGdyABqPe4lj+2KTyLdZCjRtKmSxqGgcwIFM=; b=BvQvmNgiuTLDkQajm4/hAomJDBmxzVKIcbDCO/gDhbG3Mfw56b6q5ksgTIeKBykz3L8dRjjTfZ/tLF4g7V4UJn55wBZuxccGeCgF9cSOnW9Z8/l5qTCXjzghTARsEvxs7+pnn42zkKbw+yQ9wozFnggLq9PFQKOGVZBXl3AcCronWMaWT53anEt6QfV2qrEEktypyF3jXibFFpchrr5b+Nnyk3An3TrTC229IRVkW+hUMgJwo8bNA9EMiVd1kuKzIpyM/B18yNbnc/VwbDhYl4giFbSMpFGQoesp7fa3FiT8uID0cVr/y/8ZbACAAeAvmQyP7isczJFLJmVjuwqKqQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org 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 (0) 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=Kr8BR33hGdyABqPe4lj+2KTyLdZCjRtKmSxqGgcwIFM=; b=svY8Og18PUJZJ54AF2KngfhyyI8ZBgoB0iNUCSK0HnQuENv3M2sqD3h5tK0SNDW0P6596H+XHc+RMOHJRZSszmlnjtnqDZbq5dBaFZDMttDkwd8qW7GT3q4mujO6bNon9sPwzllBwwnZb/y1CsD2xovkf3yG9fV4OMo4qM+AGPVyTd7Lwa20HqI7MKFNwM00oEXVuOPR+QNgbPi5gIHkEmAlVVmvLEA7MyHp/vL+cJOnULnkbi6FAz5GZVGbGJiJ4m9YKCHXZjD8Hax8H21em+oFy3nFVBP8jYkfmpBfjWdxMVL2BdbIKQJMlJX925HeJAJxpUI3iqUuth3C93ppSA== Received: from SJ0PR03CA0377.namprd03.prod.outlook.com (2603:10b6:a03:3a1::22) by DM4PR12MB7576.namprd12.prod.outlook.com (2603:10b6:8:10c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.36; Thu, 14 Mar 2024 14:56:19 +0000 Received: from SJ5PEPF000001D2.namprd05.prod.outlook.com (2603:10b6:a03:3a1:cafe::11) by SJ0PR03CA0377.outlook.office365.com (2603:10b6:a03:3a1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.21 via Frontend Transport; Thu, 14 Mar 2024 14:56:19 +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 SJ5PEPF000001D2.mail.protection.outlook.com (10.167.242.54) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.12 via Frontend Transport; Thu, 14 Mar 2024 14:56:19 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) 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.41; Thu, 14 Mar 2024 07:56:03 -0700 Received: from localhost.localdomain (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Thu, 14 Mar 2024 07:56:00 -0700 From: Petr Machata To: David Ahern , Stephen Hemminger , CC: Ido Schimmel , Petr Machata , "Jakub Kicinski" , Subject: [PATCH iproute2-next v2 3/4] ip: ipnexthop: Support dumping next hop group HW stats Date: Thu, 14 Mar 2024 15:52:14 +0100 Message-ID: <51d1686b5a2124b67a796945e117ce824c012811.1710427655.git.petrm@nvidia.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF000001D2:EE_|DM4PR12MB7576:EE_ X-MS-Office365-Filtering-Correlation-Id: f7a5526e-50e5-4d07-a207-08dc4436e82d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QLg8oXohrNhUqExMkikZX9jW00N+PFpG2asEOYfIjGnSlh9YY7TxDO0HiAzqe0+D2AIFMpGM92j4C84uPYk6Hy2CeuE1ztTyWZpgFRuyUbWC/qydyaP/gzmwiy64pSjnB488nsNXf0V1XjCUnY3C728XLEFN59POCjEkG2ppUTGPNXaXSRcDU/J2us7y8fW6kPQin6sxLF9kLukRrPBnfkVqgcbYFP6Oroxw7OOS+5Bvmd7clYp70UxRe16uVI29WX86FLIX1NYjEMOnBUS5e7einfwUX2c/W5pyjNtMMWrHI3czeKm9JXBGyw91C4IeGWM4tw5T4ksMIA02wNSlUdFRVTA7Fu9i/gZIvNHhZscHggcMTulMQIsc+QE+Lp95eusrJU3mCRG7NU0WJpB1opNbZPbQ7fu2fcKzSFLxiEukNPVByAY068JrrDNfw7kfO2+GNfOnKR0q1iO0JfAnDikDMZluVYmgqGGJULKucf9iglZbtusm0GldlBJgXtpPMU0caCZT7hr1l2zTw9BX1js8sx7RLErV7cnjndNB4NB7gnyM3vXPR2bSnEQZAUzIXcYi291uvYPCLych0LmfNuudHVIkkLTyBEjlXHBJPj6FysakO76S+Lx8a/3KrhQ+tuXyFmtayF00EDkSzt+srkRuvIbZXEKKZ6ujTMr7Iv2f7ETaFs2kWaklgD4JIb+gAswvDsVyQkjy7dKVI3BvflQ6dj3oplZEUWhh8mRMgIMAiiWV0uSZshJdk7gSqXyV 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:(13230031)(1800799015)(82310400014)(36860700004)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Mar 2024 14:56:19.3682 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f7a5526e-50e5-4d07-a207-08dc4436e82d 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: SJ5PEPF000001D2.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7576 X-Patchwork-Delegate: dsahern@gmail.com Besides SW datapath stats, the kernel also support collecting statistics from HW datapath, for nexthop groups offloaded to HW. Request that these be collected when ip is given "-s -s", similarly to how "ip link" shows more statistics in that case. Besides the statistics themselves, also show whether the collection of HW statistics was in fact requested, and whether any driver actually implemented the request. Signed-off-by: Petr Machata --- ip/ipnexthop.c | 28 ++++++++++++++++++++++++++++ ip/nh_common.h | 5 +++++ 2 files changed, 33 insertions(+) diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c index cba3d934..6c5d524b 100644 --- a/ip/ipnexthop.c +++ b/ip/ipnexthop.c @@ -327,6 +327,11 @@ static void parse_nh_group_stats_rta(const struct rtattr *grp_stats_attr, rta = tb[NHA_GROUP_STATS_ENTRY_PACKETS]; nh_grp_stats->packets = rta_getattr_uint(rta); } + + if (tb[NHA_GROUP_STATS_ENTRY_PACKETS_HW]) { + rta = tb[NHA_GROUP_STATS_ENTRY_PACKETS_HW]; + nh_grp_stats->packets_hw = rta_getattr_uint(rta); + } } } @@ -395,6 +400,9 @@ static void print_nh_grp_stats(const struct nh_entry *nhe) nhe->nh_grp_stats[i].nh_id); print_u64(PRINT_ANY, "packets", " packets %llu", nhe->nh_grp_stats[i].packets); + if (show_stats > 1) + print_u64(PRINT_ANY, "packets_hw", " packets_hw %llu", + nhe->nh_grp_stats[i].packets_hw); if (i != nhe->nh_groups_cnt - 1) print_nl(); @@ -479,6 +487,15 @@ static int ipnh_parse_nhmsg(FILE *fp, const struct nhmsg *nhm, int len, nhe->nh_has_res_grp = true; } + if (tb[NHA_HW_STATS_ENABLE]) { + nhe->nh_hw_stats_supported = true; + nhe->nh_hw_stats_enabled = + !!rta_getattr_u32(tb[NHA_HW_STATS_ENABLE]); + } + + if (tb[NHA_HW_STATS_USED]) + nhe->nh_hw_stats_used = !!rta_getattr_u32(tb[NHA_HW_STATS_USED]); + if (tb[NHA_GROUP_STATS]) { nhe->nh_grp_stats = calloc(nhe->nh_groups_cnt, sizeof(*nhe->nh_grp_stats)); @@ -555,6 +572,15 @@ static void __print_nexthop_entry(FILE *fp, const char *jsobj, if (nhe->nh_fdb) print_null(PRINT_ANY, "fdb", "fdb", NULL); + if ((show_details > 0 || show_stats) && nhe->nh_hw_stats_supported) { + open_json_object("hw_stats"); + print_on_off(PRINT_ANY, "enabled", "hw_stats %s ", + nhe->nh_hw_stats_enabled); + print_on_off(PRINT_ANY, "used", "used %s ", + nhe->nh_hw_stats_used); + close_json_object(); + } + if (nhe->nh_grp_stats) print_nh_grp_stats(nhe); @@ -567,6 +593,8 @@ static __u32 ipnh_get_op_flags(void) if (show_stats) { op_flags |= NHA_OP_FLAG_DUMP_STATS; + if (show_stats > 1) + op_flags |= NHA_OP_FLAG_DUMP_HW_STATS; } return op_flags; diff --git a/ip/nh_common.h b/ip/nh_common.h index e2f74ec5..33b1d847 100644 --- a/ip/nh_common.h +++ b/ip/nh_common.h @@ -16,6 +16,7 @@ struct nha_res_grp { struct nh_grp_stats { __u32 nh_id; __u64 packets; + __u64 packets_hw; }; struct nh_entry { @@ -32,6 +33,10 @@ struct nh_entry { bool nh_blackhole; bool nh_fdb; + bool nh_hw_stats_supported; + bool nh_hw_stats_enabled; + bool nh_hw_stats_used; + int nh_gateway_len; union { __be32 ipv4; From patchwork Thu Mar 14 14:52:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13592508 X-Patchwork-Delegate: dsahern@gmail.com Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2078.outbound.protection.outlook.com [40.107.243.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC6C429CE3 for ; Thu, 14 Mar 2024 14:56:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.78 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710428191; cv=fail; b=EixnJJsaP5FEXZ+mp5SClrfnhpxn+3NSSZyEWVexvCrdxAFlJd9RGAfN07snqIYP7xnabjyvvIC55j9yCMEAZuhGntyYEjUpe8a+1wp0icnwBxAmMD60ieBqDhgDXzOSMGCKvzcFLoVAPwF73rx5jAQNR/P7P5akYHxXGLnMOFI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710428191; c=relaxed/simple; bh=OYsd7y/+EzcmS9JOznGACWalf5o+aSWwmK4UxacAP2s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QuVI++X2/i3rbhUKGZz80nslZkHA0JWFtZVL4vTGg3j0Pw6015oATYhWyj3P1qozhpt80tYRkj9aEH1e3v/E1PdeTPmbwgN+Ba1YPlnLxcCMmEAMu5uBX+MGKA9H7qB49HouJYCqEnsnXLY61QFTpZIT3QsB2gl38v1gFj3qTdo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=C96j1HZk; arc=fail smtp.client-ip=40.107.243.78 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="C96j1HZk" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ErSWb1aWvVej1XLROjR7Mo/f8wWG2P1tH7ZtmGYbsXAu2DiZEK5g6xj4pDRcKu5CCLJL31MpoGx8Y9680Ps65j8frrOBQuYsTOCoAo/nIodoxptlcZtqZmLjsl7IrKCOtciQ43Kq6jrDwkp1JvWM1UwyP53c6hHzhF1O8lG5fBu62TsSGWcruoXTl+t5Oxg6HJL1Dpl2L01A2nd3ZytmuznfDOBIss/UCcRpEGtMXLlDRQi3SdUoMwZBsFxdqvg45r0YI0AlLlPjNbY1AD0Ng1DoZOLw9qRvg6tg684Bw2YYaSzCaFm+oNylXvF4GPHryRowOy9pW1frNrHAUAf+Mw== 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=wUsHSDDEx1swruY3bfxLHQTnrDufM7QCPF2Y/rBrRUw=; b=Yy0msQNFrmm4xtb+p96AO+4y2ocHsOEKCwy/4k8BjGzHti3nT75HYqb2CZ22MPSTexkYA30jY3st6IsL/8zK0fhxnN3q5RP6fNsc8rjBi7iWpcUraVP+q4HM3vSCupMzbqZFHeq5b/syweBRcgLeY049y7WD4H5QKt0WOJaCGCqX3K+00hgmW0I0PdA3h+2f/INpJExhJVR2EIcgEAThYCk8mBW2YARksArrKZaxltj21k3cz54b0+GPi5EE57dfV8Z/L4z2mouQTiqqWBtrBVVd0R7/sTkhqiCowSmBHYw37rnKrr88XYAFivTi8yY9hZ4cG54JYYVPSA4jrNq8Eg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org 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 (0) 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=wUsHSDDEx1swruY3bfxLHQTnrDufM7QCPF2Y/rBrRUw=; b=C96j1HZknq1mpbQGtyYIBy75ktXmrfSzUgXcQji9U1Kzrrd9JX6e7OVQrXPRuGuUtEKDRFbRApxM/4YYk0vZu/vZCl1oIQTXnXmNaNQ1mE+ou4tU3LPEkqlL8IJlst6iQ02yHzXZKT0gHO5YwoprA6PKEbwPbfL+71JO6Au5tI3F62cTK2/BfBeZF/VKXdGvzFjTdaDNQJLO33nMhtUX8Co+ChYB+X3FNgQoy0veQGNPu/OkYk+K6ziQWrdpl7aAsShUqkp1jRzmbFv9PrjKgmMmLzgulw+yfrF5sNsbPf3ErsSGr4LJtL8G6K8+Jd6JDZnrb0m227r7PBuvcgh48Q== Received: from SJ0PR13CA0036.namprd13.prod.outlook.com (2603:10b6:a03:2c2::11) by SJ2PR12MB8954.namprd12.prod.outlook.com (2603:10b6:a03:541::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.20; Thu, 14 Mar 2024 14:56:24 +0000 Received: from SJ5PEPF000001D6.namprd05.prod.outlook.com (2603:10b6:a03:2c2:cafe::2c) by SJ0PR13CA0036.outlook.office365.com (2603:10b6:a03:2c2::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.20 via Frontend Transport; Thu, 14 Mar 2024 14:56:24 +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 SJ5PEPF000001D6.mail.protection.outlook.com (10.167.242.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.12 via Frontend Transport; Thu, 14 Mar 2024 14:56:24 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) 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.41; Thu, 14 Mar 2024 07:56:07 -0700 Received: from localhost.localdomain (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Thu, 14 Mar 2024 07:56:04 -0700 From: Petr Machata To: David Ahern , Stephen Hemminger , CC: Ido Schimmel , Petr Machata , "Jakub Kicinski" , Subject: [PATCH iproute2-next v2 4/4] ip: ipnexthop: Allow toggling collection of nexthop group HW statistics Date: Thu, 14 Mar 2024 15:52:15 +0100 Message-ID: <88f549693a2699465ae7c9bfba68cd2b8495e9df.1710427655.git.petrm@nvidia.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF000001D6:EE_|SJ2PR12MB8954:EE_ X-MS-Office365-Filtering-Correlation-Id: 63a1f941-eaa0-43cc-0afe-08dc4436eb4c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: B6/OTbTPmP/yagP3DTwajdnbo+iTmSAYp4W092Vee4763suKf4rNvPY0yepz7TtmeN4v6uvUesNdbLnwfHImbKMHgTyiqAzJ+r//FT72R0r9+p9qyU1q+V5Ug4cvTY2kWNyiFJE7s7dtteCRXj5y9zKE3D0UqKjkfjWg6c4K56tNGHPfsqTV4HvFuuiDjLVDTEz/8FU8qWqkdHed7noxs/tqvChVaLXA+P+UJgK+262n4zF3eSqPtdGfLep0xULOI7ZfKLvR7rxk89bQFLoi62+am/33rOHTP0eUajZGnYnG4HL4vNrAaqiAri91suxZpsNKnHgQatZyJoL+ovqCtCaUUFn2i3/2kqrFTHg2BV4G0fT7Q/Twsn93crqIrLiJZpBpsEheRcNOHiXRgHSibcrstm+dJH75dO0TULlBOntcnYFw3LkzkuH9Whoy1783UU6hd+JWglkehrU78J8yHlME6wOHLPhn9cIsoKx3bclq8j7sHIZeuW9qSb7Pr1eAHXvW9lIdqSm/L23BMDgDjTyUoxPx0UOqffYraKeef/+m1hw7l+yiSlfYTf8UA5yuMAsv+VeiKx/izTqgtgS1oXZvWCk+1NgcJw2Kjgtx3nzfYIY+FomtWo0APuWjccNEC9o1977kJ1RWTmZgMRHZaClejqxebLnPLjG0zQALR3HitU9Hir2D5AKwzN0LdvuW6+Y7yO6zowsjOm46LWnN51EFy3cRAogymnffzGg3ddTuIObkF8XHfIdJKRdOmJB8 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:(13230031)(376005)(82310400014)(36860700004)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Mar 2024 14:56:24.5851 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 63a1f941-eaa0-43cc-0afe-08dc4436eb4c 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: SJ5PEPF000001D6.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8954 X-Patchwork-Delegate: dsahern@gmail.com Besides SW datapath stats, the kernel also support collecting statistics from HW datapath, for nexthop groups offloaded to HW. Since collection of these statistics may consume HW resources, there is an interface to request that the HW stats be recorded. Add this toggle to "ip nexthop". Signed-off-by: Petr Machata --- ip/ipnexthop.c | 12 ++++++++++++ man/man8/ip-nexthop.8 | 2 ++ 2 files changed, 14 insertions(+) diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c index 6c5d524b..8aa06de0 100644 --- a/ip/ipnexthop.c +++ b/ip/ipnexthop.c @@ -56,6 +56,7 @@ static void usage(void) " [ encap ENCAPTYPE ENCAPHDR ] |\n" " group GROUP [ fdb ] [ type TYPE [ TYPE_ARGS ] ] }\n" "GROUP := [ //... ]\n" + " [ hw_stats {off|on} ]\n" "TYPE := { mpath | resilient }\n" "TYPE_ARGS := [ RESILIENT_ARGS ]\n" "RESILIENT_ARGS := [ buckets BUCKETS ] [ idle_timer IDLE ]\n" @@ -1102,6 +1103,17 @@ static int ipnh_modify(int cmd, unsigned int flags, int argc, char **argv) if (rtnl_rtprot_a2n(&prot, *argv)) invarg("\"protocol\" value is invalid\n", *argv); req.nhm.nh_protocol = prot; + } else if (!strcmp(*argv, "hw_stats")) { + bool hw_stats; + int ret; + + NEXT_ARG(); + hw_stats = parse_on_off("hw_stats", *argv, &ret); + if (ret) + return ret; + + addattr32(&req.n, sizeof(req), NHA_HW_STATS_ENABLE, + hw_stats); } else if (strcmp(*argv, "help") == 0) { usage(); } else { diff --git a/man/man8/ip-nexthop.8 b/man/man8/ip-nexthop.8 index f81a5910..aad68696 100644 --- a/man/man8/ip-nexthop.8 +++ b/man/man8/ip-nexthop.8 @@ -68,6 +68,8 @@ ip-nexthop \- nexthop object management .BR fdb " ] | " .B group .IR GROUP " [ " +.BR hw_stats " { " +.BR on " | " off " } ] [ " .BR fdb " ] [ " .B type .IR TYPE " [ " TYPE_ARGS " ] ] }"