From patchwork Fri Apr 22 08:30:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12823069 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE5C5C433EF for ; Fri, 22 Apr 2022 08:31:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445524AbiDVIec (ORCPT ); Fri, 22 Apr 2022 04:34:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445513AbiDVIe2 (ORCPT ); Fri, 22 Apr 2022 04:34:28 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2075.outbound.protection.outlook.com [40.107.94.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B33E852E4D for ; Fri, 22 Apr 2022 01:31:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UVngiv6mNEenOcqws36XwQf7AHlF5dXGeaEIK22zwbpaqBr8KKgDqR/R2R9GXMkzTrfA1wCYkMvsK04FYoKSvIj1Mx7t+pj8MdGLjonEbW2e5xgiM5m/PFvljrim/ifEDqMfhpXw35ojU9mVohXi1AKin3sD7lXHgBZhvCDAciiKxLeXcd2UPKi5QtMQ1x2c3Y1bQmCQRatA5joK9yG/YBA3oCNVK9io5/2FejVOUSDf3I+ZJiSU/2WTo+L4SjFcdlZdzZp8/kWrDV7UxAE5Vpo6GTvpd1e/ER9+CLHtp8+UpBclicfhXCAX7LQRybPe/lpHw/WBc9acXGolJsfzew== 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=ti9qkNLUjZZzjnR8TBB/HmItok1HQ11ZfgUYNsRHNjk=; b=QaTzUBR2leeyoO9+k0HIwXKbJIZXZJHcDbwigeCzr86AtmFF4knO3jv2bK38pFQ/hxuC7/kaheK8o2IfwCMv+Ftu0utVSzLSxhZXxIpTggw4700tY1GpSPpOC29d6OWRSxrz71BF7DMRvck73OM9qKUyPDqLDKwi4YagRrhXmYc6kDbJpcgOheDdJaxz59LDnXHnwR+inhDh8H1G4o1nscRy1iCE27wAyvax4S+i7JAenxCPj8UlqsagaTai/aYXtnKfCNCT16adhjfurv+5IhznE/8M0mjF+PX6pGj8cl7fjtceeEmiAKAd1357WVUes4UMczOTOTV8D1J6ZB7wZA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=networkplumber.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 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=ti9qkNLUjZZzjnR8TBB/HmItok1HQ11ZfgUYNsRHNjk=; b=k2axw7qUcTJhayVVszrr5GR40OV5srMOYAAdosJNkEf8r29SBTYzTB4xfcQ2hSVcWboX+4w0yJKreJ8Lq/l573kAY+GiR/OMyvrkG5i3UTbPEejXu7pPYpflc2ZNxRccoBVon2BEZeimJ/3FBeg0Lns2ZQ0HJ/kvd09wxl4L79rWVis0NS3JEE3ekHuHlbT2T3RWAsFzPm5Hx4TCeSGqlxy8DSi55VK2LKzGY2+mZo8fvdtDZPF53YafuYzcLLdZB5+tO7f+ewvl998nJb5XBNPNqo2YlcACqEU6rIY4Z2pTxLg8UFr8kt5N3jrKDtDmfuwPHu6w+e4ByRnDEWf0mg== Received: from DM6PR06CA0089.namprd06.prod.outlook.com (2603:10b6:5:336::22) by MN2PR12MB4302.namprd12.prod.outlook.com (2603:10b6:208:1de::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14; Fri, 22 Apr 2022 08:31:31 +0000 Received: from DM6NAM11FT032.eop-nam11.prod.protection.outlook.com (2603:10b6:5:336:cafe::bd) by DM6PR06CA0089.outlook.office365.com (2603:10b6:5:336::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14 via Frontend Transport; Fri, 22 Apr 2022 08:31:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) 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 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.238) by DM6NAM11FT032.mail.protection.outlook.com (10.13.173.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5186.14 via Frontend Transport; Fri, 22 Apr 2022 08:31:31 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 22 Apr 2022 08:31:30 +0000 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.986.22; Fri, 22 Apr 2022 01:31:28 -0700 From: Petr Machata To: CC: David Ahern , Stephen Hemminger , Ido Schimmel , Petr Machata Subject: [PATCH iproute2-next 01/11] libnetlink: Add filtering to rtnl_statsdump_req_filter() Date: Fri, 22 Apr 2022 10:30:50 +0200 Message-ID: <0a0459d981354797db52a1c037c677f75d24b0e2.1650615982.git.petrm@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6362c433-efa1-4d55-cd19-08da243a80aa X-MS-TrafficTypeDiagnostic: MN2PR12MB4302:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WI3kesQiZTZG33/7Ck2nJcuZGbeFDdronbmHZ9c59klAYUH5NfwQP7wZn9SFEHrqTqPriMpaioCy605iHkfIP52j72kjU0z1tul7mXLnyyOxug0a+RYn3jgKO+342H0KQkOnNrCMguvEBM8pIRYjA4JGvNDXpW862et1sGuw2ABn2fZR4Bq11axb3rapZuZHFJRCEYJGzuTWQyjd8ekcTqIwoO9Pv8koie62fDBar34mBd7HfGn25fX0Xa5ChSDkqcAlFMUf3DA5Y1hvwDqaizio0v0WJfjCzDqyuTrE59UjSxTFm1R8wYHXy50pQWR8pZ4jO6Ie5tWHRQ4bzBKQ2ETkxglBDQ8Ry2Okvm/WMGXC8YkdK7VLTPPjELFl/s5iv0FuHbAC2Ou3NNDWcxjEu5BIumFqaTGT0R6HSJOzDRIZgjDT3CJFEgVvPFvE66D0MunrHDAbvFZhyxKLiyq+z/MNCJhH7jrDgDTO3rNsdtrWdDtHBplVv+XLvxPHAQ8ux++TuJfy5erMGCJF8nZ9lQSOrtfkelxCt927EWm+rh2ZGC6c1YlM5KCUQo0iR4rQXSe0R1T6ETdWQAw/tsqgGtDb2rpQ6CADYIEgtTAlH1FmWCHdKISW4oswIWpBDysA5P59Y4QeC4sxP0h8bUlFbvHvCPHgfEgudXnkZ6D5eI19D9gqaIR3m2EbsCYliSOS9LZWLWwx1SThEGy0Rb0V2Q== X-Forefront-Antispam-Report: CIP:12.22.5.238;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(36756003)(316002)(40460700003)(8676002)(70586007)(81166007)(70206006)(356005)(6666004)(4326008)(6916009)(2906002)(5660300002)(82310400005)(86362001)(54906003)(8936002)(107886003)(83380400001)(508600001)(36860700001)(47076005)(26005)(16526019)(336012)(2616005)(426003)(186003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2022 08:31:31.0476 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6362c433-efa1-4d55-cd19-08da243a80aa X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.238];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT032.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4302 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com A number of functions in the rtnl_*_req family accept a caller-provided callback to set up arbitrary filtering. rtnl_statsdump_req_filter() currently only allows setting a field in the IFSM header, not custom attributes. So far these were not necessary, but with introduction of more detailed filtering settings, the callback becomes necessary. To that end, add a filter_fn and filter_data arguments to the function. Unlike the other filters, this one is typed to expect an IFSM pointer, to permit tweaking the header itself as well. Pass NULLs in the existing callers. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- bridge/vlan.c | 6 ++++-- include/libnetlink.h | 11 ++++++++++- ip/iplink.c | 3 ++- ip/iplink_xstats.c | 3 ++- lib/libnetlink.c | 19 ++++++++++++++----- misc/ifstat.c | 2 +- 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index 8300f353..390a2037 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -1179,7 +1179,8 @@ static int vlan_show(int argc, char **argv, int subject) __u32 filt_mask; filt_mask = IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_XSTATS); - if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask) < 0) { + if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask, + NULL, NULL) < 0) { perror("Cannot send dump request"); exit(1); } @@ -1194,7 +1195,8 @@ static int vlan_show(int argc, char **argv, int subject) } filt_mask = IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_XSTATS_SLAVE); - if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask) < 0) { + if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask, + NULL, NULL) < 0) { perror("Cannot send slave dump request"); exit(1); } diff --git a/include/libnetlink.h b/include/libnetlink.h index 9e4cc101..372c3706 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -37,6 +37,12 @@ struct nlmsg_chain { struct nlmsg_list *tail; }; +struct ipstats_req { + struct nlmsghdr nlh; + struct if_stats_msg ifsm; + char buf[128]; +}; + extern int rcvbuf; int rtnl_open(struct rtnl_handle *rth, unsigned int subscriptions) @@ -88,7 +94,10 @@ int rtnl_fdb_linkdump_req_filter_fn(struct rtnl_handle *rth, int rtnl_nsiddump_req_filter_fn(struct rtnl_handle *rth, int family, req_filter_fn_t filter_fn) __attribute__((warn_unused_result)); -int rtnl_statsdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask) +int rtnl_statsdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask, + int (*filter_fn)(struct ipstats_req *req, + void *data), + void *filter_data) __attribute__((warn_unused_result)); int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len) diff --git a/ip/iplink.c b/ip/iplink.c index dc76a12b..23eb6c6e 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -1644,7 +1644,8 @@ static int iplink_afstats(int argc, char **argv) } } - if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask) < 0) { + if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask, + NULL, NULL) < 0) { perror("Cannont send dump request"); return 1; } diff --git a/ip/iplink_xstats.c b/ip/iplink_xstats.c index c64e6885..1d180b0b 100644 --- a/ip/iplink_xstats.c +++ b/ip/iplink_xstats.c @@ -65,7 +65,8 @@ int iplink_ifla_xstats(int argc, char **argv) else filt_mask = IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_XSTATS); - if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask) < 0) { + if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask, + NULL, NULL) < 0) { perror("Cannont send dump request"); return -1; } diff --git a/lib/libnetlink.c b/lib/libnetlink.c index 6d1b1187..4d33e4dd 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -619,12 +619,13 @@ int rtnl_fdb_linkdump_req_filter_fn(struct rtnl_handle *rth, return send(rth->fd, &req, sizeof(req), 0); } -int rtnl_statsdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask) +int rtnl_statsdump_req_filter(struct rtnl_handle *rth, int fam, + __u32 filt_mask, + int (*filter_fn)(struct ipstats_req *req, + void *data), + void *filter_data) { - struct { - struct nlmsghdr nlh; - struct if_stats_msg ifsm; - } req; + struct ipstats_req req; memset(&req, 0, sizeof(req)); req.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct if_stats_msg)); @@ -635,6 +636,14 @@ int rtnl_statsdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask) req.ifsm.family = fam; req.ifsm.filter_mask = filt_mask; + if (filter_fn) { + int err; + + err = filter_fn(&req, filter_data); + if (err) + return err; + } + return send(rth->fd, &req, sizeof(req), 0); } diff --git a/misc/ifstat.c b/misc/ifstat.c index d4a33429..291f288b 100644 --- a/misc/ifstat.c +++ b/misc/ifstat.c @@ -202,7 +202,7 @@ static void load_info(void) ll_init_map(&rth); filter_mask = IFLA_STATS_FILTER_BIT(filter_type); if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, - filter_mask) < 0) { + filter_mask, NULL, NULL) < 0) { perror("Cannot send dump request"); exit(1); } From patchwork Fri Apr 22 08:30:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12823068 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14DA6C433EF for ; Fri, 22 Apr 2022 08:31:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445520AbiDVIea (ORCPT ); Fri, 22 Apr 2022 04:34:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445056AbiDVIe1 (ORCPT ); Fri, 22 Apr 2022 04:34:27 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2046.outbound.protection.outlook.com [40.107.223.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5FCF44A11 for ; Fri, 22 Apr 2022 01:31:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hwWaPj6Wmc2fGZpDkCNmPpslGbgQKPBphN2PmYK1Vjvg+gmxyUbqQwYI/RHhMjmI0LkmcBIaealo2LIEMnD1QAFRT9ZxZduOC8i+67Nk5ooUVedOXY/ZXP1Ptwl5/fG3+bbDgG3B/a4jwHLf+C3U6diuP53KrKM4qGPsDg4cnht+HZPn/Rmn3tqzyrOaZr39BV+Hm01OCVtxut4bKTSqYW0VURUgVbdo3He32IsEWimkKZv0It/D04H+cWx+KZcsPWWzM+/bKUYdupTovc+6w2dWrkV52+Am21sz1n6tGzysiwuhdY3T7bcJnXsYgGUMHbndaILuOE10n3agJbgT6Q== 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=lMAe0IeKIypUNUHs6oO8rt0D9rLkwWYY76SX/PJZ+xs=; b=Pk0wlZynxBa4Gb/BD3hDM2KeL+6Yky4aNaFbEa6qyBVq8ajWmHNr0V5IFMOxWPX5NCA9VOZO0WR1v04yFWsCjWWPXtSQGIbM9GDTPtg6OCyALCAsgkwLd4hG9USuSnGUuNc0xgS4i/zVcKOyVGdtWldVkYnYf5/UArf7jvqtEyzYlyUvCSfYqNToSx8WFE6fgANU/IYLsHyJv48mKaJruxW6+KGTTqH0XepbIXzo0zJ9Q38odQuAtvjOD+ak9QMixIhskk0rJrfqePwMEqOGp9RaggsLS56U+P6c8tPA9Swk4rAkbelFTpfGu2sSr27SXlfRN9ZFIhLZNLdwAQ1KjQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=networkplumber.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 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=lMAe0IeKIypUNUHs6oO8rt0D9rLkwWYY76SX/PJZ+xs=; b=g96ZxTPhuTECOCM5R9+3yNP7M8TiBA+xziQsLiiRv3WPBV61+xHfkQvn9YItSddkBxPLvc5nsac5PCb53cFVEmi1Os4iUpblONuTZW84URoYXV4EG3r2vTuI2ESIjlWoHCt8gqbE+5suQM8SGySO9gV+ja4ohbAb9uk9rWZo4t+Dd/zOJoQUzJpl78C525kPFVDouGMGiQOAQpng7SoMSAJ5bj3txBaMfnWycaTDyMxRWFyb36uA7ksnzqZpmwem9xT0MQkarqDKHmWE7FcGyUhWqAjlXlKs1LkXSQQOJBG11Gi13Vo4vFMPyevpcp/7S0kZwdzwozjqmLwybjzylg== Received: from BN9PR03CA0922.namprd03.prod.outlook.com (2603:10b6:408:107::27) by BN8PR12MB3298.namprd12.prod.outlook.com (2603:10b6:408:69::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.13; Fri, 22 Apr 2022 08:31:33 +0000 Received: from BN8NAM11FT052.eop-nam11.prod.protection.outlook.com (2603:10b6:408:107:cafe::3d) by BN9PR03CA0922.outlook.office365.com (2603:10b6:408:107::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.13 via Frontend Transport; Fri, 22 Apr 2022 08:31:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) 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 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.234) by BN8NAM11FT052.mail.protection.outlook.com (10.13.177.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5186.14 via Frontend Transport; Fri, 22 Apr 2022 08:31:32 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 22 Apr 2022 08:31:32 +0000 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.986.22; Fri, 22 Apr 2022 01:31:30 -0700 From: Petr Machata To: CC: David Ahern , Stephen Hemminger , Ido Schimmel , Petr Machata Subject: [PATCH iproute2-next 02/11] ip: Publish functions for stats formatting Date: Fri, 22 Apr 2022 10:30:51 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cc94e508-53ca-422c-cf62-08da243a81c9 X-MS-TrafficTypeDiagnostic: BN8PR12MB3298:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wZ4cJYdhQY2QSK5CxrDDGCqHz7o2hm+4LDKDCCAi6i1C8bs8bSOu1VfWQz0lICVO3BiTSXfVHT6NgfdGqm0M4+eeV+ZGnz66wsdxV/ocebcE3ggc78ftgW91FdvvZvSbzLRqgYBpkIZj80kI1l/GfQuM+slRFtWsZPznjP6MO8J0syq5eBCqDxpl7VtaY7suGFTDsti2UnbC2W7eh3x0fqNFI1AfGTJg+hPFbxatp27WEBUPfcOFyHCisRUrfGJJ5Z/68PZl+OMqPt59fxvmStc5ys3hs/cG1L/WmjZgjfKpkMcU7JM8WO7O0ysCq1s0MMR6maO2+KMYL0lty+K0mlZ86ZlOQuH18bPuK+E1grXFqNbKUbNdmGiMvmlxCcfqk2SJINaxUp6MFrLKlSutjlUvSJ1BRhxqb6Zud6/wgwd2uJ8HiHemC3p94Qt3L/aP0F+g4bym6qlK7wA+9VNrTzEueNyiExKioyDreRsuFtakcjIXYULTkDcwdEWfXFCs4Bjv4QrqJerpobxGglS+KIZV2MNrJZZ7mQZdgM4Gymn2qsQL2eV7ROtxZTeQd+SO5i5PzGz6ygCqIuWUqBgJFvop1krjAyFLB0zmovhSJh7czxQqTvnuT+kksqx8DFgo3iUNA9RxW0wpr3fh9QMmp7JUsnXB1sx+ZQkRi7ZTiDj1Xltjt/No5Hwkgre9w+QrbLVFGpXHUJqtYWZAWT7sVg== X-Forefront-Antispam-Report: CIP:12.22.5.234;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(4326008)(8676002)(40460700003)(81166007)(336012)(426003)(47076005)(26005)(86362001)(8936002)(5660300002)(508600001)(70206006)(70586007)(356005)(36860700001)(83380400001)(186003)(82310400005)(16526019)(6666004)(107886003)(2906002)(2616005)(36756003)(54906003)(316002)(6916009)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2022 08:31:32.8661 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cc94e508-53ca-422c-cf62-08da243a81c9 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.234];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT052.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3298 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Formatting struct rtnl_link_stats64 will be useful outside of iplink.c as well. Extract from __print_link_stats() a new function, print_stats64(), make it non-static and publish in the header file. Additionally, publish the helper size_columns(), which will be useful for formatting the new struct rtnl_hw_stats64. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- ip/ip_common.h | 3 +++ ip/ipaddress.c | 33 ++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/ip/ip_common.h b/ip/ip_common.h index ea04c8ff..51a7edc7 100644 --- a/ip/ip_common.h +++ b/ip/ip_common.h @@ -171,4 +171,7 @@ void print_rta_ifidx(FILE *fp, __u32 ifidx, const char *prefix); void __print_rta_gateway(FILE *fp, unsigned char family, const char *gateway); void print_rta_gateway(FILE *fp, unsigned char family, const struct rtattr *rta); +void size_columns(unsigned int cols[], unsigned int n, ...); +void print_stats64(FILE *fp, struct rtnl_link_stats64 *s, + const struct rtattr *carrier_changes, const char *what); #endif /* _IP_COMMON_H_ */ diff --git a/ip/ipaddress.c b/ip/ipaddress.c index a80996ef..17341d28 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -546,7 +546,7 @@ static void print_vfinfo(FILE *fp, struct ifinfomsg *ifi, struct rtattr *vfinfo) print_vf_stats64(fp, vf[IFLA_VF_STATS]); } -static void size_columns(unsigned int cols[], unsigned int n, ...) +void size_columns(unsigned int cols[], unsigned int n, ...) { unsigned int i, len; uint64_t val, powi; @@ -680,10 +680,10 @@ static void print_vf_stats64(FILE *fp, struct rtattr *vfstats) } } -static void __print_link_stats(FILE *fp, struct rtattr *tb[]) +void print_stats64(FILE *fp, struct rtnl_link_stats64 *s, + const struct rtattr *carrier_changes, + const char *what) { - const struct rtattr *carrier_changes = tb[IFLA_CARRIER_CHANGES]; - struct rtnl_link_stats64 _s, *s = &_s; unsigned int cols[] = { strlen("*X errors:"), strlen("packets"), @@ -693,14 +693,10 @@ static void __print_link_stats(FILE *fp, struct rtattr *tb[]) strlen("overrun"), strlen("compressed"), }; - int ret; - - ret = get_rtnl_link_stats_rta(s, tb); - if (ret < 0) - return; if (is_json_context()) { - open_json_object((ret == sizeof(*s)) ? "stats64" : "stats"); + if (what) + open_json_object(what); /* RX stats */ open_json_object("rx"); @@ -771,7 +767,8 @@ static void __print_link_stats(FILE *fp, struct rtattr *tb[]) } close_json_object(); - close_json_object(); + if (what) + close_json_object(); } else { size_columns(cols, ARRAY_SIZE(cols), s->rx_bytes, s->rx_packets, s->rx_errors, @@ -870,6 +867,20 @@ static void __print_link_stats(FILE *fp, struct rtattr *tb[]) } } +static void __print_link_stats(FILE *fp, struct rtattr *tb[]) +{ + const struct rtattr *carrier_changes = tb[IFLA_CARRIER_CHANGES]; + struct rtnl_link_stats64 _s, *s = &_s; + int ret; + + ret = get_rtnl_link_stats_rta(s, tb); + if (ret < 0) + return; + + print_stats64(fp, s, carrier_changes, + (ret == sizeof(*s)) ? "stats64" : "stats"); +} + static void print_link_stats(FILE *fp, struct nlmsghdr *n) { struct ifinfomsg *ifi = NLMSG_DATA(n); From patchwork Fri Apr 22 08:30:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12823070 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCF55C433EF for ; Fri, 22 Apr 2022 08:31:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445526AbiDVIef (ORCPT ); Fri, 22 Apr 2022 04:34:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445518AbiDVIea (ORCPT ); Fri, 22 Apr 2022 04:34:30 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2044.outbound.protection.outlook.com [40.107.237.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3997A52E58 for ; Fri, 22 Apr 2022 01:31:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OpSaw2W5moXt2miMViT056+mzQhUf63b2+gIo9kmAO/aT5ZGzQ3aNFWBMO96L8QfG9KXopbjx+KaJNGJz5f/knsjM35SNbaWltqZMh0N7HCA4I6ChpsSydggyrVVrciDcwsl6JEPhE3Tz4Kmb4O2S/eHEWleiLOP64dY6jUPIjioeXH0TcRdLO4gPbgjL24SAKE/Zv1w/x9EcifhI557l4vJQ1DRbXyE+vN7SK6CFt3ZcKLZjj615gimFwWTtC61XfCu0X3+XU6onF5X5ISMEn9eSYFDI7BctBRFeOOFa9f+AJNiRAGicBZ3oDOUimDKvF9gJ+mYYQTT+pOyBsUgiA== 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=oab3wxmzgmtNk9LXxQ3TKvAeMVU+VR2R7JtNC+DBzjc=; b=Z4K+pyMHqtwbx1kzp+m/ClYof4ua/DUDQk6vQOHXQtsZWZ1Z2NUXxrCefuyle4295lphTkTgyjxHaCaZYeNIbkXQJcHk/WSe4IrNCrtzXwOtTZ9kRmKNVpvZvAkBc6ogVIrekpvBViQau52+frZ73CdDEEisYObUC4Ildyywv/CAKBeJdVH35dU7yBYbuncEQ52giEwd74glD8d+RsRpzmnwyIYgmifdoh5o9tGAj8NUV0CBg65v3yAWXNf4G8teU+Bi/Wei5nm+g8c6usVDgfJfp+UReBQqNtRIhLNoVeSMKPadNWLx5sLC05MK/sWS6Q+kc7qas7S5X2iKmHObfA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) smtp.rcpttodomain=networkplumber.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 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=oab3wxmzgmtNk9LXxQ3TKvAeMVU+VR2R7JtNC+DBzjc=; b=DckXdja1fPDuXe5s9UQtFjfdYaDIbCGtbE1IfmyA8YKRfpmKe8pya6H/Hnk3xzh/KAfr8/CZwcUiv83p3HF4u/Lg1Z3+KP4yh6DIJFRjDQSL3Xw924oLpS56vW+/qcOfG4A2xDiv3ZGYt2zRZNF9adeMBmA7+gMMfblMbV1ZJ71mWWTMa7JcYX4ozr/nhUMYhsrwQvpAbIQwLF5qsjztwN7SGWSp9dmjoZtKyjs1yN2ChtXNORNidFowdBZBN/rqnzPo8tNjnIabQbia2ks/xgJlXOlH8oE64Nt9d4j01GesMuDFYSh7RtK+7RnrNRS1uzO0w6be27u06ed9kPdjAA== Received: from MW4PR04CA0191.namprd04.prod.outlook.com (2603:10b6:303:86::16) by CY5PR12MB6129.namprd12.prod.outlook.com (2603:10b6:930:27::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14; Fri, 22 Apr 2022 08:31:34 +0000 Received: from CO1NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:303:86:cafe::ff) by MW4PR04CA0191.outlook.office365.com (2603:10b6:303:86::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.13 via Frontend Transport; Fri, 22 Apr 2022 08:31:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) 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 12.22.5.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.236) by CO1NAM11FT008.mail.protection.outlook.com (10.13.175.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5186.14 via Frontend Transport; Fri, 22 Apr 2022 08:31:34 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 22 Apr 2022 08:31:33 +0000 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.986.22; Fri, 22 Apr 2022 01:31:31 -0700 From: Petr Machata To: CC: David Ahern , Stephen Hemminger , Ido Schimmel , Petr Machata Subject: [PATCH iproute2-next 03/11] ip: Add a new family of commands, "stats" Date: Fri, 22 Apr 2022 10:30:52 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 31a44c9c-c407-47d6-f2bd-08da243a82b5 X-MS-TrafficTypeDiagnostic: CY5PR12MB6129:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kVWuOBxgi+lV7/MYoRGHB+TJ0bi5VOjMY9ag7Zbs/U3zQr0bKOJGLM9z7Wpxh97l9lu0RqDOJwQjvjapvxibO5Y1Ws4CEEg2LG5/Rl16t/+6R9t0zBzSHpfo1gl6xFAhvQ8H/YX7Ois67+MpyUWcv42yhJCDDa2AQhxuu/bky2pMWZol4kzIA2LOUgUimvw51BOZowvvz7kHwtZG3ZPXXNqUnUHOuoSRUnIG7qCiWvUHU4sYcDL42s7CxOLyP871gSepCZVoVDE9rVYqkOO/EuN2zsz4PvHbtH7itOvfv+xkgke4dARtdNMaI4BCEu4Q2NX9zx23MAPBoM/emAz6dz7dOxP01wVFuhEHLnqUNhTCNWiuG9pnVXOiN5DoSycGF2Tjb5rs/xiotvK8JucjHb6HJfN+YSISQQeMZSJtkYCV/qGfslpgeIGRGpqnTe4nHIsx4zc6MS33YxBHGgMwhAWhLfTHFOiZH4Rmzp8MEa2eOqVSd5/GTxUTIxHLlMNiPmw8tRKGhSjBqkXrGrTYrVzn8Cm6SNKRhntCqYoQL5pm/xZgoQRW7kdJCHX3riNoZJ8djhwtg/XHMn77LU5wgc1qOQWT8T3SgXdPZe3i8Vo0HgnRuvvgs3H9SPw9bR8zYTbMpi//6sMzZkTMyxejwy6p9Ljo4Vp/pRnPvVjgGhB5yukM6q1uVe44iEa3C7Dm/LaxJLZdMs1ozwYaAAMhKw== X-Forefront-Antispam-Report: CIP:12.22.5.236;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(186003)(26005)(16526019)(82310400005)(36756003)(316002)(4326008)(2906002)(5660300002)(47076005)(336012)(107886003)(36860700001)(8936002)(6666004)(426003)(2616005)(83380400001)(86362001)(8676002)(81166007)(40460700003)(54906003)(356005)(508600001)(70206006)(6916009)(70586007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2022 08:31:34.4605 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 31a44c9c-c407-47d6-f2bd-08da243a82b5 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.236];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6129 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Add a core of a new frontend tool for interfacing with the RTM_*STATS family of messages. The following patches will add subcommands for showing and setting individual statistics suites. Note that in this patch, "ip stats" is made to be an invalid command line. This will be changed in later patches to default to "show" when that is introduced. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- ip/Makefile | 3 ++- ip/ip.c | 1 + ip/ip_common.h | 1 + ip/ipstats.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 ip/ipstats.c diff --git a/ip/Makefile b/ip/Makefile index e06a7c84..6c2e0720 100644 --- a/ip/Makefile +++ b/ip/Makefile @@ -12,7 +12,8 @@ IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o ipnetns.o \ iplink_geneve.o iplink_vrf.o iproute_lwtunnel.o ipmacsec.o ipila.o \ ipvrf.o iplink_xstats.o ipseg6.o iplink_netdevsim.o iplink_rmnet.o \ ipnexthop.o ipmptcp.o iplink_bareudp.o iplink_wwan.o ipioam6.o \ - iplink_amt.o iplink_batadv.o iplink_gtp.o iplink_virt_wifi.o + iplink_amt.o iplink_batadv.o iplink_gtp.o iplink_virt_wifi.o \ + ipstats.o RTMONOBJ=rtmon.o diff --git a/ip/ip.c b/ip/ip.c index c784f819..82282bab 100644 --- a/ip/ip.c +++ b/ip/ip.c @@ -123,6 +123,7 @@ static const struct cmd { { "mptcp", do_mptcp }, { "ioam", do_ioam6 }, { "help", do_help }, + { "stats", do_ipstats }, { 0 } }; diff --git a/ip/ip_common.h b/ip/ip_common.h index 51a7edc7..53866d7a 100644 --- a/ip/ip_common.h +++ b/ip/ip_common.h @@ -90,6 +90,7 @@ int do_seg6(int argc, char **argv); int do_ipnh(int argc, char **argv); int do_mptcp(int argc, char **argv); int do_ioam6(int argc, char **argv); +int do_ipstats(int argc, char **argv); int iplink_get(char *name, __u32 filt_mask); int iplink_ifla_xstats(int argc, char **argv); diff --git a/ip/ipstats.c b/ip/ipstats.c new file mode 100644 index 00000000..099e18a2 --- /dev/null +++ b/ip/ipstats.c @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0+ +#include "utils.h" +#include "ip_common.h" + +static int do_help(void) +{ + fprintf(stderr, + "Usage: ip stats help\n" + ); + + return 0; +} + +int do_ipstats(int argc, char **argv) +{ + int rc; + + if (argc == 0) { + do_help(); + rc = -1; + } else if (strcmp(*argv, "help") == 0) { + do_help(); + rc = 0; + } else { + fprintf(stderr, "Command \"%s\" is unknown, try \"ip stats help\".\n", + *argv); + rc = -1; + } + + return rc; +} From patchwork Fri Apr 22 08:30:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12823071 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37E72C433F5 for ; Fri, 22 Apr 2022 08:31:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445535AbiDVIer (ORCPT ); Fri, 22 Apr 2022 04:34:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445056AbiDVIeb (ORCPT ); Fri, 22 Apr 2022 04:34:31 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2079.outbound.protection.outlook.com [40.107.237.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F11AF52E4D for ; Fri, 22 Apr 2022 01:31:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j4XSogA+omHVPvb1hNxttmSbN+T0DobmA+yu2KZRESmKUfdDUr46sSAJsdwqEySJe5Pzcc/jUiEftck2u0b802qjC8JYHI7Cr/udQzaU/B3fOboWDU7Sl0tR62B++N9E3aq9Q92GrBA09gc13BW6rg+gcH16pbXN088QekdDy4H8mJkbX1gVp/PZPr6sSgbnO9Xntrs6eOdHdbBxyChrHRN+f51NwosfjKY6n+0vFaCKE76wzwXtN8JFypqVxAODh0CKLDiSSSIbl/iUIpubL0EhQAtnvKvCnpQeSjMn62lk4xqpd/Wqpx715c8Q27p7p3Tx5HvNTRQKnXWipsb9/w== 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=eIZ7jUUHokyUqYqmaO5cexSh9EkdR1+oEBjm4PLuGGk=; b=fq4rwONCllEluNGEPRywNrUmb9Lgjx7Uhntiletuifny+W9HsYijEW3I0M/kM0bE4uk1B5ji2vp2SCO+MRcbKKUuHDZyWuF387Dp/cPHrtNNLDO3xcOPa/SwK2UMjkefSMX14/3uEJF7VxB98SlcFvun0E+HJUJAFBVjXFpytdZI7cx37sBwoteGubHPjohZ4LZSR35T+Dm7bhXqoS4CWxQEpp+JnOGFP5RnGolPyHteptNGGVVsN06LCiQE+QFtJthIfuuPJtKir/hx489vK5ou+FarI27Ux4oGSnQ0jXY521djq0/6PB+lVEmblNTjCtwaqo1xcMOzPwTfKYvX2Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=networkplumber.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 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=eIZ7jUUHokyUqYqmaO5cexSh9EkdR1+oEBjm4PLuGGk=; b=qsCIKO8OHoJ2MNjftf1b5+yp9B/AzfN+khlv16J+jFRutyhhNtu9ITOlfcXnsI1XpzJNWxqb4aXRqCFMMmjmXkuE3x1zs0rJXfr9z9OePhU3scoYmXuTPGGa0qQatmdNLs/Zc66QU4lrNs6yK67HBpg1qNOeXlAtIGJbF/yyJG31S8agP9OFIupFB3bwpZ7Xo6JoQb0LnY8XyfnvgNsqKoDIxT6QawihskGYd9t/X7EQH0NkhtkKWglOYT/k7Hhv4GvM6pwV3onE+d7JxSJNXPKAV1V8VEDLzvR9H/bVAbs9cimospaGFj9IbQKyFA1Pqjq+X/+118VKzFPWBpk/Gw== Received: from DM6PR13CA0001.namprd13.prod.outlook.com (2603:10b6:5:bc::14) by BY5PR12MB3972.namprd12.prod.outlook.com (2603:10b6:a03:1a8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.15; Fri, 22 Apr 2022 08:31:36 +0000 Received: from DM6NAM11FT038.eop-nam11.prod.protection.outlook.com (2603:10b6:5:bc:cafe::cc) by DM6PR13CA0001.outlook.office365.com (2603:10b6:5:bc::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.6 via Frontend Transport; Fri, 22 Apr 2022 08:31:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) 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 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.235) by DM6NAM11FT038.mail.protection.outlook.com (10.13.173.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5186.14 via Frontend Transport; Fri, 22 Apr 2022 08:31:36 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 22 Apr 2022 08:31:35 +0000 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.986.22; Fri, 22 Apr 2022 01:31:33 -0700 From: Petr Machata To: CC: David Ahern , Stephen Hemminger , Ido Schimmel , Petr Machata Subject: [PATCH iproute2-next 04/11] ipstats: Add a "set" command Date: Fri, 22 Apr 2022 10:30:53 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ba58aefe-f4b2-4a55-92ab-08da243a83b7 X-MS-TrafficTypeDiagnostic: BY5PR12MB3972:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5k03yqJVK8B/T/x9dgvBoUgBAmQpLRh8uFSaQCsaKrI3ykSpUFnW/nidKdoEDwxXc5HTKS7mnT9rUBu66k8Mof0vS8/hqBgKgMEgmxDiVoCVaUEH7jYbULWhdSOnWhzyAO2GWdKwLDHUqoMmq0nnDYKEZK3XJnJhwa2fPkhSGYWYxZt+hWyXopSHtzt8JTF94IG9Pm1FwSIV8Bdy/O30IhdUaoAoRBT2AlwG0FHIaglBEA7GHTBMeH7NA9UKa7fwHdr1gW/hiDN/WRvZ1XiOvqLPeNCEv9nXsMFfYjtZPZO+4zMT9k4fyHN84I8UWrEN+DfT1zvU36dNOIScDU9w2FbmQCn1JDLUvFOEDPQOr17oupDP3f+/fK7WSHS36JRkL6KoNFRnmPydJlt3yKgjntg2wxA0N+21JJOxu9X8K2HWzcGVV3osyX9mijHeNu2asd7DFFXg8XeRAqkAZVxozCpB/H+EKZKPrT7I5WyPnniR54eEGiXGxWp6g0QsIEmUSmO8AFdy8Wrdl2XQG6n/xV9rOuNzsXwf6AIZzYngvA1dPW5eGWWeOb/A0ieI1vgGjN8vFeY96FISehHW/nknLn5v5x0eT+9gPIko/IpOfy/kEBrmCZvJ4EyOJeaGHzO5wjFACEhYYeKkPapqEZs4g+6CQSfAEDJiCP4i/AoQgvMTYIVTirwSb8FoAwbtCQnusqVv7Vc8NMshyG7yH6SQEA== X-Forefront-Antispam-Report: CIP:12.22.5.235;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(5660300002)(508600001)(316002)(8676002)(86362001)(4326008)(82310400005)(54906003)(356005)(70586007)(70206006)(26005)(6666004)(81166007)(36756003)(6916009)(47076005)(186003)(2906002)(107886003)(16526019)(336012)(2616005)(426003)(8936002)(40460700003)(83380400001)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2022 08:31:36.1801 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ba58aefe-f4b2-4a55-92ab-08da243a83b7 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.235];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT038.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB3972 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Add a command to allow toggling HW stats. An example usage: # ip stats set dev swp1 l3_stats on Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- ip/ipstats.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/ip/ipstats.c b/ip/ipstats.c index 099e18a2..1f5b3f77 100644 --- a/ip/ipstats.c +++ b/ip/ipstats.c @@ -1,4 +1,6 @@ // SPDX-License-Identifier: GPL-2.0+ +#include + #include "utils.h" #include "ip_common.h" @@ -6,11 +8,85 @@ static int do_help(void) { fprintf(stderr, "Usage: ip stats help\n" + " ip stats set dev DEV l3_stats { on | off }\n" ); return 0; } +static int ipstats_set_do(int ifindex, int at, bool enable) +{ + struct ipstats_req req = { + .nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct if_stats_msg)), + .nlh.nlmsg_flags = NLM_F_REQUEST, + .nlh.nlmsg_type = RTM_SETSTATS, + .ifsm.family = PF_UNSPEC, + .ifsm.ifindex = ifindex, + }; + + addattr8(&req.nlh, sizeof(req), at, enable); + + if (rtnl_talk(&rth, &req.nlh, NULL) < 0) + return -2; + return 0; +} + +static int ipstats_set(int argc, char **argv) +{ + const char *dev = NULL; + bool enable = false; + int ifindex; + int at = 0; + + while (argc > 0) { + if (strcmp(*argv, "dev") == 0) { + NEXT_ARG(); + if (dev) + duparg2("dev", *argv); + if (check_ifname(*argv)) + invarg("\"dev\" not a valid ifname", *argv); + dev = *argv; + } else if (strcmp(*argv, "l3_stats") == 0) { + int err; + + NEXT_ARG(); + if (at) { + fprintf(stderr, "A statistics suite to toggle was already given.\n"); + return -EINVAL; + } + at = IFLA_STATS_SET_OFFLOAD_XSTATS_L3_STATS; + enable = parse_on_off("l3_stats", *argv, &err); + if (err) + return err; + } else if (strcmp(*argv, "help") == 0) { + do_help(); + return 0; + } else { + fprintf(stderr, "What is \"%s\"?\n", *argv); + do_help(); + return -EINVAL; + } + + NEXT_ARG_FWD(); + } + + if (!dev) { + fprintf(stderr, "Not enough information: \"dev\" argument is required.\n"); + exit(-1); + } + + if (!at) { + fprintf(stderr, "Not enough information: stat type to toggle is required.\n"); + exit(-1); + } + + ifindex = ll_name_to_index(dev); + if (!ifindex) + return nodev(dev); + + return ipstats_set_do(ifindex, at, enable); +} + int do_ipstats(int argc, char **argv) { int rc; @@ -21,6 +97,8 @@ int do_ipstats(int argc, char **argv) } else if (strcmp(*argv, "help") == 0) { do_help(); rc = 0; + } else if (strcmp(*argv, "set") == 0) { + rc = ipstats_set(argc-1, argv+1); } else { fprintf(stderr, "Command \"%s\" is unknown, try \"ip stats help\".\n", *argv); From patchwork Fri Apr 22 08:30:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12823073 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B24D3C433EF for ; Fri, 22 Apr 2022 08:31:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237544AbiDVIet (ORCPT ); Fri, 22 Apr 2022 04:34:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445065AbiDVIed (ORCPT ); Fri, 22 Apr 2022 04:34:33 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2086.outbound.protection.outlook.com [40.107.93.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A255A52E58 for ; Fri, 22 Apr 2022 01:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BnJ8+gqRLlmyS51E5dGY68WpJd7/ErGeFClwkLWKIuc5/T7IN68cSqY3S5OzAcwwIZ9jLM4kALN0Wsq1ZWEd6biXIug3L6X6fnjdhYz7j4JmQgUFPj+2O4KD3vCV41Ggmk26keCmHWVQRNPSqDOaGIXDgsVKQ/w9cVL0c31T7o0Ux/Tadt/rk2EUvrXKjf9LK9EaNnLh5nAb6/r3DKUD3fnWqfP1mIwVDEge3pk3ghISbrJZCqGIThBFtQSY604+JZBtFLAg2cvzshjUwNVMRaA0npVjuikDRdvMyYHaPs/LXox0QyCAm/zF2Pekq+3aH6or167s6t/Z49quMH/AXA== 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=lmSgSNU0AOeSiE7+j4ut120m4g2q6CS4LZTUEI7Qc58=; b=NYXwQvIlARTtWjFnJ1zypQU4ZkJrrU0FATY9Vi2N45hqvcr/d5h2tbUmZ3E+hlCxJscoyUFeDSAbgOdfmrh++S6LnVviCfaViXHUPmkCIyJvjv5dBQdeji741MqRPDA/0dUoBVIcwwPlJO18o5Iq3IIJZilm0TLt0sMicemeN2OBzWscG+fanlrR7h91czM2BW2fgtrBTpzALWsQ4gGGVbe0QiD84CRC/5G4Yn4JnInk2eD91zyRDNL3ZCxl6pMBPQIEkiF+HmVyxqr4+BMEdq1Es94osGNRGGsojahQmblh5VbYtk9VGYpX2VO72fa9e4J9NWfdtiKfLo5ZU2q4PQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=networkplumber.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 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=lmSgSNU0AOeSiE7+j4ut120m4g2q6CS4LZTUEI7Qc58=; b=MBG2f06VThxtr4hLdqauMF5GlBZUa5v+3bGH/pdkkNWRRbZTXNfNIhGcepWgnIgHURG2ktgEVrIFCJtNJ3+EZGfU/YrXOqEew4iRF8nljpQJ4zni0xDlm7yF+Le9gKWiSYxouReZobxGm6GqQI8/OOqKcmHErYr4kTwLuQbNlNC0ID6ujrhVJF7lZMOmhtzvggAGPFbRSxGLPAecVDSUa62j4ShcrCNpbe5iKTlQdQ700soz+ne6ymh8hQOFOUBEtGvTJoIHYchooQd/GeILXeL5vt1ogVMCjjGdYwABk3AXf/gKMEYJaQlLsLcaRbjMAzYO977XkzyA7x5sWk772g== Received: from DS7PR05CA0071.namprd05.prod.outlook.com (2603:10b6:8:57::14) by DS7PR12MB5936.namprd12.prod.outlook.com (2603:10b6:8:7f::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Fri, 22 Apr 2022 08:31:39 +0000 Received: from DM6NAM11FT003.eop-nam11.prod.protection.outlook.com (2603:10b6:8:57:cafe::b2) by DS7PR05CA0071.outlook.office365.com (2603:10b6:8:57::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.6 via Frontend Transport; Fri, 22 Apr 2022 08:31:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) 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 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.238) by DM6NAM11FT003.mail.protection.outlook.com (10.13.173.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5186.14 via Frontend Transport; Fri, 22 Apr 2022 08:31:38 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 22 Apr 2022 08:31:37 +0000 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.986.22; Fri, 22 Apr 2022 01:31:35 -0700 From: Petr Machata To: CC: David Ahern , Stephen Hemminger , Ido Schimmel , Petr Machata Subject: [PATCH iproute2-next 05/11] ipstats: Add a shell of "show" command Date: Fri, 22 Apr 2022 10:30:54 +0200 Message-ID: <23fce511c8d55a07204b22d59dd3ffabf3c0abe6.1650615982.git.petrm@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 76d2d49d-2748-46a7-3650-08da243a855f X-MS-TrafficTypeDiagnostic: DS7PR12MB5936:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qsDyboQqoFZA3TGxMp9rmWsBXWDek/3BwMd2ccd47OQy0xkdQre+USBjD1/D1X15jSG8L0HOi/jPd1dSUMGLTECEyXgDm2WxGb6f4fJcHioBOzL36xca7skR8z0aOf2/gFjzW5cLin9jMjFz3ksBSDbvrfCFrrWcZkb4+6s9sKDQK1LWuJvuxWAmdGdXG1FiZmc5MK+Sig3AY3+jqpuStBltmuuWq6ahhWwYWiMPS5fFzcXN7S2rcYdGR2v+YuRFJ5nkao1oyWD3gTIvrbxB/tA6dsQKg7berkC/3tU4yhVfihMHgBUdd75VRMvyO+3u1npCC3o3rMdwuu5oguglYCMX1mblEjK+7Wb+oP5tXfKDCNzZTNqZNjCtPsaYxq+KX7pKt5cWIf9r2/wxZZLp9HPABCY5tt/gHlXUvKtJP9U2YzM9Ml9GFJ2k6t1gvwAIkIo2Em4huO/9t3kopnVVi0Q1ZSYYDlNjkD8jmZ/voiUERiK9x24ASv2SRzMshnlUuppogL4n4NWO+COgKJCeWJOciZd9C9tnEFNsetYmw1w76RnIDLO0M2DdJ54NXmL84ufJ11z662pTopiLif6HZtCbFGq1Pn1BuIXAWFUlXdZqaqBNaRL+cr0iGOYtzh5bMkM2A/CsBjk5/0OVR8wNiZBjIk242zs4+nxg1sSWjigOkJSeBS2gIvw7j3dEdRFjY76Rnz+Yd/MrOfPS4TLbcQ== X-Forefront-Antispam-Report: CIP:12.22.5.238;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(107886003)(54906003)(47076005)(2616005)(26005)(186003)(336012)(2906002)(86362001)(426003)(30864003)(16526019)(82310400005)(40460700003)(81166007)(8936002)(36756003)(356005)(70586007)(6666004)(508600001)(6916009)(83380400001)(5660300002)(4326008)(70206006)(36860700001)(8676002)(316002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2022 08:31:38.9409 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 76d2d49d-2748-46a7-3650-08da243a855f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.238];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT003.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5936 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Add the scaffolding necessary for adding individual stats suites to show. Expose some ipstats artifacts in ip_common.h. These will be used to support "xstats" in a follow-up patchset. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- ip/ip_common.h | 26 +++ ip/ipstats.c | 614 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 638 insertions(+), 2 deletions(-) diff --git a/ip/ip_common.h b/ip/ip_common.h index 53866d7a..8b0a6426 100644 --- a/ip/ip_common.h +++ b/ip/ip_common.h @@ -158,6 +158,32 @@ void xdp_dump(FILE *fp, struct rtattr *tb, bool link, bool details); __u32 ipvrf_get_table(const char *name); int name_is_vrf(const char *name); +/* ipstats.c */ +enum ipstats_stat_desc_kind { + IPSTATS_STAT_DESC_KIND_LEAF, + IPSTATS_STAT_DESC_KIND_GROUP, +}; + +struct ipstats_stat_dump_filters; +struct ipstats_stat_show_attrs; + +struct ipstats_stat_desc { + const char *name; + enum ipstats_stat_desc_kind kind; + union { + struct { + const struct ipstats_stat_desc **subs; + size_t nsubs; + }; + struct { + void (*pack)(struct ipstats_stat_dump_filters *filters, + const struct ipstats_stat_desc *desc); + int (*show)(struct ipstats_stat_show_attrs *attrs, + const struct ipstats_stat_desc *desc); + }; + }; +}; + #ifndef INFINITY_LIFE_TIME #define INFINITY_LIFE_TIME 0xFFFFFFFFU #endif diff --git a/ip/ipstats.c b/ip/ipstats.c index 1f5b3f77..79f7b1ff 100644 --- a/ip/ipstats.c +++ b/ip/ipstats.c @@ -1,19 +1,624 @@ // SPDX-License-Identifier: GPL-2.0+ +#include #include #include "utils.h" #include "ip_common.h" +struct ipstats_stat_dump_filters { + /* mask[0] filters outer attributes. Then individual nests have their + * filtering mask at the index of the nested attribute. + */ + __u32 mask[IFLA_STATS_MAX + 1]; +}; + +struct ipstats_stat_show_attrs { + struct if_stats_msg *ifsm; + int len; + + /* tbs[0] contains top-level attribute table. Then individual nests have + * their attribute tables at the index of the nested attribute. + */ + struct rtattr **tbs[IFLA_STATS_MAX + 1]; +}; + +static const char *const ipstats_levels[] = { + "group", + "subgroup", +}; + +enum { + IPSTATS_LEVELS_COUNT = ARRAY_SIZE(ipstats_levels), +}; + +struct ipstats_sel { + const char *sel[IPSTATS_LEVELS_COUNT]; +}; + +struct ipstats_stat_enabled_one { + const struct ipstats_stat_desc *desc; + struct ipstats_sel sel; +}; + +struct ipstats_stat_enabled { + struct ipstats_stat_enabled_one *enabled; + size_t nenabled; +}; + +static const unsigned int ipstats_stat_ifla_max[] = { + [0] = IFLA_STATS_MAX, + [IFLA_STATS_LINK_XSTATS] = LINK_XSTATS_TYPE_MAX, + [IFLA_STATS_LINK_XSTATS_SLAVE] = LINK_XSTATS_TYPE_MAX, + [IFLA_STATS_LINK_OFFLOAD_XSTATS] = IFLA_OFFLOAD_XSTATS_MAX, + [IFLA_STATS_AF_SPEC] = AF_MAX - 1, +}; + +static_assert(ARRAY_SIZE(ipstats_stat_ifla_max) == IFLA_STATS_MAX + 1, + "An IFLA_STATS attribute is missing from the ifla_max table"); + +static int +ipstats_stat_show_attrs_alloc_tb(struct ipstats_stat_show_attrs *attrs, + unsigned int group) +{ + unsigned int ifla_max; + int err; + + assert(group < ARRAY_SIZE(ipstats_stat_ifla_max)); + assert(group < ARRAY_SIZE(attrs->tbs)); + ifla_max = ipstats_stat_ifla_max[group]; + assert(ifla_max != 0); + + if (attrs->tbs[group]) + return 0; + + attrs->tbs[group] = calloc(ifla_max + 1, sizeof(*attrs->tbs[group])); + if (attrs->tbs[group] == NULL) + return -ENOMEM; + + if (group == 0) + err = parse_rtattr(attrs->tbs[group], ifla_max, + IFLA_STATS_RTA(attrs->ifsm), attrs->len); + else + err = parse_rtattr_nested(attrs->tbs[group], ifla_max, + attrs->tbs[0][group]); + + if (err != 0) { + free(attrs->tbs[group]); + attrs->tbs[group] = NULL; + } + return err; +} + +static void +ipstats_stat_show_attrs_free(struct ipstats_stat_show_attrs *attrs) +{ + size_t i; + + for (i = 0; i < ARRAY_SIZE(attrs->tbs); i++) + free(attrs->tbs[i]); +} + +static const struct ipstats_stat_desc *ipstats_stat_desc_toplev_subs[] = { +}; + +static const struct ipstats_stat_desc ipstats_stat_desc_toplev_group = { + .name = "top-level", + .kind = IPSTATS_STAT_DESC_KIND_GROUP, + .subs = ipstats_stat_desc_toplev_subs, + .nsubs = ARRAY_SIZE(ipstats_stat_desc_toplev_subs), +}; + +static void ipstats_show_group(const struct ipstats_sel *sel) +{ + int i; + + for (i = 0; i < IPSTATS_LEVELS_COUNT; i++) { + if (sel->sel[i] == NULL) + break; + print_string(PRINT_JSON, ipstats_levels[i], NULL, sel->sel[i]); + print_string(PRINT_FP, NULL, " %s ", ipstats_levels[i]); + print_string(PRINT_FP, NULL, "%s", sel->sel[i]); + } +} + +static int +ipstats_process_ifsm(struct nlmsghdr *answer, + struct ipstats_stat_enabled *enabled) +{ + struct ipstats_stat_show_attrs show_attrs = {}; + const char *dev; + int err = 0; + int i; + + show_attrs.ifsm = NLMSG_DATA(answer); + show_attrs.len = (answer->nlmsg_len - + NLMSG_LENGTH(sizeof(*show_attrs.ifsm))); + if (show_attrs.len < 0) { + fprintf(stderr, "BUG: wrong nlmsg len %d\n", show_attrs.len); + return -EINVAL; + } + + err = ipstats_stat_show_attrs_alloc_tb(&show_attrs, 0); + if (err != 0) { + fprintf(stderr, "Error parsing netlink answer: %s\n", + strerror(err)); + return err; + } + + dev = ll_index_to_name(show_attrs.ifsm->ifindex); + + for (i = 0; i < enabled->nenabled; i++) { + const struct ipstats_stat_desc *desc = enabled->enabled[i].desc; + + open_json_object(NULL); + print_int(PRINT_ANY, "ifindex", "%d:", + show_attrs.ifsm->ifindex); + print_color_string(PRINT_ANY, COLOR_IFNAME, + "ifname", " %s:", dev); + ipstats_show_group(&enabled->enabled[i].sel); + err = desc->show(&show_attrs, desc); + if (err != 0) + goto out; + close_json_object(); + print_nl(); + } + +out: + ipstats_stat_show_attrs_free(&show_attrs); + return err; +} + +static bool +ipstats_req_should_filter_at(struct ipstats_stat_dump_filters *filters, int at) +{ + return filters->mask[at] != 0 && + filters->mask[at] != (1 << ipstats_stat_ifla_max[at]) - 1; +} + +static int +ipstats_req_add_filters(struct ipstats_req *req, void *data) +{ + struct ipstats_stat_dump_filters dump_filters = {}; + struct ipstats_stat_enabled *enabled = data; + bool get_filters = false; + int i; + + for (i = 0; i < enabled->nenabled; i++) + enabled->enabled[i].desc->pack(&dump_filters, + enabled->enabled[i].desc); + + for (i = 1; i < ARRAY_SIZE(dump_filters.mask); i++) { + if (ipstats_req_should_filter_at(&dump_filters, i)) { + get_filters = true; + break; + } + } + + req->ifsm.filter_mask = dump_filters.mask[0]; + if (get_filters) { + struct rtattr *nest; + + nest = addattr_nest(&req->nlh, sizeof(*req), + IFLA_STATS_GET_FILTERS | NLA_F_NESTED); + + for (i = 1; i < ARRAY_SIZE(dump_filters.mask); i++) { + if (ipstats_req_should_filter_at(&dump_filters, i)) + addattr32(&req->nlh, sizeof(*req), i, + dump_filters.mask[i]); + } + + addattr_nest_end(&req->nlh, nest); + } + + return 0; +} + +static int +ipstats_show_one(int ifindex, struct ipstats_stat_enabled *enabled) +{ + struct ipstats_req req = { + .nlh.nlmsg_flags = NLM_F_REQUEST, + .nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct if_stats_msg)), + .nlh.nlmsg_type = RTM_GETSTATS, + .ifsm.family = PF_UNSPEC, + .ifsm.ifindex = ifindex, + }; + struct nlmsghdr *answer; + int err = 0; + + ipstats_req_add_filters(&req, enabled); + if (rtnl_talk(&rth, &req.nlh, &answer) < 0) + return -2; + err = ipstats_process_ifsm(answer, enabled); + free(answer); + + return err; +} + +static int ipstats_dump_one(struct nlmsghdr *n, void *arg) +{ + struct ipstats_stat_enabled *enabled = arg; + int rc; + + rc = ipstats_process_ifsm(n, enabled); + if (rc) + return rc; + + print_nl(); + return 0; +} + +static int ipstats_dump(struct ipstats_stat_enabled *enabled) +{ + int rc = 0; + + if (rtnl_statsdump_req_filter(&rth, PF_UNSPEC, 0, + ipstats_req_add_filters, + enabled) < 0) { + perror("Cannot send dump request"); + return -2; + } + + if (rtnl_dump_filter(&rth, ipstats_dump_one, enabled) < 0) { + fprintf(stderr, "Dump terminated\n"); + rc = -2; + } + + fflush(stdout); + return rc; +} + +static int +ipstats_show_do(int ifindex, struct ipstats_stat_enabled *enabled) +{ + int rc; + + new_json_obj(json); + if (ifindex) + rc = ipstats_show_one(ifindex, enabled); + else + rc = ipstats_dump(enabled); + delete_json_obj(); + + return rc; +} + +static int ipstats_add_enabled(struct ipstats_stat_enabled_one ens[], + size_t nens, + struct ipstats_stat_enabled *enabled) +{ + struct ipstats_stat_enabled_one *new_en; + + new_en = realloc(enabled->enabled, + sizeof(*new_en) * (enabled->nenabled + nens)); + if (new_en == NULL) + return -ENOMEM; + + enabled->enabled = new_en; + while (nens-- > 0) + enabled->enabled[enabled->nenabled++] = *ens++; + return 0; +} + +static void ipstats_select_push(struct ipstats_sel *sel, const char *name) +{ + int i; + + for (i = 0; i < IPSTATS_LEVELS_COUNT; i++) + if (sel->sel[i] == NULL) { + sel->sel[i] = name; + return; + } + + assert(false); +} + +static int +ipstats_enable_recursively(const struct ipstats_stat_desc *desc, + struct ipstats_stat_enabled *enabled, + const struct ipstats_sel *sel) +{ + bool found = false; + size_t i; + int err; + + if (desc->kind == IPSTATS_STAT_DESC_KIND_LEAF) { + struct ipstats_stat_enabled_one en[] = {{ + .desc = desc, + .sel = *sel, + }}; + + return ipstats_add_enabled(en, ARRAY_SIZE(en), enabled); + } + + for (i = 0; i < desc->nsubs; i++) { + struct ipstats_sel subsel = *sel; + + ipstats_select_push(&subsel, desc->subs[i]->name); + err = ipstats_enable_recursively(desc->subs[i], enabled, + &subsel); + if (err == -ENOENT) + continue; + if (err != 0) + return err; + found = true; + } + + return found ? 0 : -ENOENT; +} + +static int ipstats_comp_enabled(const void *a, const void *b) +{ + const struct ipstats_stat_enabled_one *en_a = a; + const struct ipstats_stat_enabled_one *en_b = b; + + if (en_a->desc < en_b->desc) + return -1; + if (en_a->desc > en_b->desc) + return 1; + + return 0; +} + +static void ipstats_enabled_free(struct ipstats_stat_enabled *enabled) +{ + free(enabled->enabled); +} + +static const struct ipstats_stat_desc * +ipstats_stat_desc_find(const struct ipstats_stat_desc *desc, + const char *name) +{ + size_t i; + + assert(desc->kind == IPSTATS_STAT_DESC_KIND_GROUP); + for (i = 0; i < desc->nsubs; i++) { + const struct ipstats_stat_desc *sub = desc->subs[i]; + + if (strcmp(sub->name, name) == 0) + return sub; + } + + return NULL; +} + +static const struct ipstats_stat_desc * +ipstats_enable_find_stat_desc(struct ipstats_sel *sel) +{ + const struct ipstats_stat_desc *toplev = &ipstats_stat_desc_toplev_group; + const struct ipstats_stat_desc *desc = toplev; + int i; + + for (i = 0; i < IPSTATS_LEVELS_COUNT; i++) { + const struct ipstats_stat_desc *next_desc; + + if (sel->sel[i] == NULL) + break; + if (desc->kind == IPSTATS_STAT_DESC_KIND_LEAF) { + fprintf(stderr, "Error: %s %s requested inside leaf %s %s\n", + ipstats_levels[i], sel->sel[i], + ipstats_levels[i - 1], desc->name); + return NULL; + } + + next_desc = ipstats_stat_desc_find(desc, sel->sel[i]); + if (next_desc == NULL) { + fprintf(stderr, "Error: no %s named %s found inside %s\n", + ipstats_levels[i], sel->sel[i], desc->name); + return NULL; + } + + desc = next_desc; + } + + return desc; +} + +static int ipstats_enable(struct ipstats_sel *sel, + struct ipstats_stat_enabled *enabled) +{ + struct ipstats_stat_enabled new_enabled = {}; + const struct ipstats_stat_desc *desc; + size_t i, j; + int err = 0; + + desc = ipstats_enable_find_stat_desc(sel); + if (desc == NULL) + return -EINVAL; + + err = ipstats_enable_recursively(desc, &new_enabled, sel); + if (err != 0) + return err; + + err = ipstats_add_enabled(new_enabled.enabled, new_enabled.nenabled, + enabled); + if (err != 0) + goto out; + + qsort(enabled->enabled, enabled->nenabled, sizeof(*enabled->enabled), + ipstats_comp_enabled); + + for (i = 1, j = 1; i < enabled->nenabled; i++) { + if (enabled->enabled[i].desc != enabled->enabled[j - 1].desc) + enabled->enabled[j++] = enabled->enabled[i]; + } + enabled->nenabled = j; + +out: + ipstats_enabled_free(&new_enabled); + return err; +} + +static int ipstats_enable_check(struct ipstats_sel *sel, + struct ipstats_stat_enabled *enabled) +{ + int err; + int i; + + err = ipstats_enable(sel, enabled); + if (err == -ENOENT) { + fprintf(stderr, "The request for"); + for (i = 0; i < IPSTATS_LEVELS_COUNT; i++) + if (sel->sel[i] != NULL) + fprintf(stderr, " %s %s", + ipstats_levels[i], sel->sel[i]); + else + break; + fprintf(stderr, " did not match any known stats.\n"); + } + + return err; +} + static int do_help(void) { + const struct ipstats_stat_desc *toplev = &ipstats_stat_desc_toplev_group; + int i; + fprintf(stderr, "Usage: ip stats help\n" + " ip stats show [ dev DEV ] [ group GROUP [ subgroup SUBGROUP ] ... ] ...\n" " ip stats set dev DEV l3_stats { on | off }\n" ); + for (i = 0; i < toplev->nsubs; i++) { + const struct ipstats_stat_desc *desc = toplev->subs[i]; + + if (i == 0) + fprintf(stderr, "GROUP := { %s", desc->name); + else + fprintf(stderr, " | %s", desc->name); + } + if (i > 0) + fprintf(stderr, " }\n"); + + for (i = 0; i < toplev->nsubs; i++) { + const struct ipstats_stat_desc *desc = toplev->subs[i]; + bool opened = false; + size_t j; + + if (desc->kind != IPSTATS_STAT_DESC_KIND_GROUP) + continue; + + for (j = 0; j < desc->nsubs; j++) { + if (j == 0) + fprintf(stderr, "%s SUBGROUP := {", desc->name); + else + fprintf(stderr, " |"); + fprintf(stderr, " %s", desc->subs[j]->name); + opened = true; + + if (desc->subs[j]->kind != IPSTATS_STAT_DESC_KIND_GROUP) + continue; + } + if (opened) + fprintf(stderr, " }\n"); + } + return 0; } +static int ipstats_select(struct ipstats_sel *old_sel, + const char *new_sel, int level, + struct ipstats_stat_enabled *enabled) +{ + int err; + int i; + + for (i = 0; i < level; i++) { + if (old_sel->sel[i] == NULL) { + fprintf(stderr, "Error: %s %s requested without selecting a %s first\n", + ipstats_levels[level], new_sel, + ipstats_levels[i]); + return -EINVAL; + } + } + + for (i = level; i < IPSTATS_LEVELS_COUNT; i++) { + if (old_sel->sel[i] != NULL) { + err = ipstats_enable_check(old_sel, enabled); + if (err) + return err; + break; + } + } + + old_sel->sel[level] = new_sel; + for (i = level + 1; i < IPSTATS_LEVELS_COUNT; i++) + old_sel->sel[i] = NULL; + + return 0; +} + +static int ipstats_show(int argc, char **argv) +{ + struct ipstats_stat_enabled enabled = {}; + struct ipstats_sel sel = {}; + const char *dev = NULL; + int ifindex; + int err; + int i; + + while (argc > 0) { + if (strcmp(*argv, "dev") == 0) { + NEXT_ARG(); + if (dev != NULL) + duparg2("dev", *argv); + if (check_ifname(*argv)) + invarg("\"dev\" not a valid ifname", *argv); + dev = *argv; + } else if (strcmp(*argv, "help") == 0) { + do_help(); + return 0; + } else { + bool found_level = false; + + for (i = 0; i < ARRAY_SIZE(ipstats_levels); i++) { + if (strcmp(*argv, ipstats_levels[i]) == 0) { + NEXT_ARG(); + err = ipstats_select(&sel, *argv, i, + &enabled); + if (err) + goto err; + + found_level = true; + } + } + + if (!found_level) { + fprintf(stderr, "What is \"%s\"?\n", *argv); + do_help(); + err = -EINVAL; + goto err; + } + } + + NEXT_ARG_FWD(); + } + + /* Push whatever was given. */ + err = ipstats_enable_check(&sel, &enabled); + if (err) + goto err; + + if (dev) { + ifindex = ll_name_to_index(dev); + if (!ifindex) { + err = nodev(dev); + goto err; + } + } else { + ifindex = 0; + } + + + err = ipstats_show_do(ifindex, &enabled); + +err: + ipstats_enabled_free(&enabled); + return err; +} + static int ipstats_set_do(int ifindex, int at, bool enable) { struct ipstats_req req = { @@ -92,11 +697,16 @@ int do_ipstats(int argc, char **argv) int rc; if (argc == 0) { - do_help(); - rc = -1; + rc = ipstats_show(0, NULL); } else if (strcmp(*argv, "help") == 0) { do_help(); rc = 0; + } else if (strcmp(*argv, "show") == 0) { + /* Invoking "stats show" implies one -s. Passing -d adds one + * more -s. + */ + show_stats += show_details + 1; + rc = ipstats_show(argc-1, argv+1); } else if (strcmp(*argv, "set") == 0) { rc = ipstats_set(argc-1, argv+1); } else { From patchwork Fri Apr 22 08:30:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12823074 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6270AC433FE for ; Fri, 22 Apr 2022 08:32:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445523AbiDVIeu (ORCPT ); Fri, 22 Apr 2022 04:34:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445525AbiDVIee (ORCPT ); Fri, 22 Apr 2022 04:34:34 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2058.outbound.protection.outlook.com [40.107.243.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABD4752E61 for ; Fri, 22 Apr 2022 01:31:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZldIJTUFlRTw47yYNy2RFOwIsQvDDTZIxP0CjQn4jEipmbDcGwEX4A9d3cVNfHC6R8N/qCP4pWxpXnJ5jINx7aiTCGSiRDAlnIG/PoaNU2xcrWVgoxfaNbrWbinsvAglBTzQmYCGJsc9++lQjzaCTN+BwDnb+QxWM4g3Rfk31mBSELJw7oTTvDmBn6b1p1hEFURGaT8FF7hJBa2sjLm4x7aFGQjP1weIFOmiXpvwpZV+C7zZDMhqU+oARA4T1RFwFaLa+IkUPCBpljTXU42jPanATMCZZYc8irE91Kfqp23AalVto5orJjzAL/sNwg7ZbwoVMhE2+vg4OIB4MOnSeQ== 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=hG/iXGJPwzzHjv31xsOV4/MlTwtccaeBl4hnu+by9a8=; b=RDDFbNUhCVShT/hgz77DEvIBIiWXt1XDc4HaAVlr3SRsXFZcEREaSMt+uaTTBOdc2wTndmrq1r2uTzj2FsP77A15i1aFquCrchEP3Jj2XmfT72Y4vzC34CZwe7AThPMamVP9JgelgJN7+EG0Fsix+qCJGLKvvokgxqQLbQSi1vFakDOnASJU6Hafx+1PBE9WVIU7t+OjSW0GjjtHV+L+CUV+ibUReJDirsPbzk9OQv2aUtthok040iWdKy3dk3Edo411IQrjDYNvCJVjn4VYAVzxRaZa/9Aa6ck8IQBofkxc6aIpgy1/Rb44W5etZArD37hklcTwPTcliWy944VmXA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=networkplumber.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 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=hG/iXGJPwzzHjv31xsOV4/MlTwtccaeBl4hnu+by9a8=; b=JK/h//s6wiaUQc1H45c6X+yLCHfJdjp2hlc9ZQv/qeGuq+oUq9t8yPhVm14c+KJRvewJOw4kpok82KBFh9FTk0kW+Tzk/ujA4en/BsVZxrVNHzyYuB5yVpp7eJ7RpAlnbtZdEXtDzU0NKc1w9JOAcFTHJ3Uw9DZ8cKC4SdnnxO/tv0XrqrVVV3mJOIj8U5ciS+pTJ5T+mphwxodduMHStHHzAFWZta0i2js/UC+H06UMSu1Jn3LIye/dqnzH3SoxKM1Qvg81IZyxubbhu8Pm/6vDZCujyuRuhfXrmcJKzf2Zih3q39vuVz4X6jCr3uyTSOtGsTSVFzvk8uIKCck+mw== Received: from BN9PR03CA0698.namprd03.prod.outlook.com (2603:10b6:408:ef::13) by BN8PR12MB3073.namprd12.prod.outlook.com (2603:10b6:408:66::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Fri, 22 Apr 2022 08:31:39 +0000 Received: from BN8NAM11FT035.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ef:cafe::a8) by BN9PR03CA0698.outlook.office365.com (2603:10b6:408:ef::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14 via Frontend Transport; Fri, 22 Apr 2022 08:31:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) 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 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.234) by BN8NAM11FT035.mail.protection.outlook.com (10.13.177.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5186.14 via Frontend Transport; Fri, 22 Apr 2022 08:31:39 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 22 Apr 2022 08:31:39 +0000 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.986.22; Fri, 22 Apr 2022 01:31:37 -0700 From: Petr Machata To: CC: David Ahern , Stephen Hemminger , Ido Schimmel , Petr Machata Subject: [PATCH iproute2-next 06/11] ipstats: Add a group "link" Date: Fri, 22 Apr 2022 10:30:55 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d9f50801-4886-417c-dbf8-08da243a85c5 X-MS-TrafficTypeDiagnostic: BN8PR12MB3073:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dncu4OFil33DDjzpvQBFNSL7hrQBvTCscQXlMXlqFwLsLY1+WEdq5L8tE7lqIDfGo4MTZRxwQuDNZoVtk0yEyPYe+DKKJ23SSRNSYVrgI+cgCENoOPMCOmhs4kMmDM3m9iiDWM9kZZAMj6gp0pvyY/963jC+WCCoUgfOKgycePTF4qrlM+DepHZdJMjDjf9G1qRlDj84zrDgSL5Dz0fjElyRpAMPeBWlC2k24gL5TmweQWeWqdcNlBdMxaOtYX3Dps0mo55+N4KMcZ96CM6q9I4QtpOt5IOs0U5ApV7Tdh79euS1KmkjCHYJbQSNS5U66cSjnngieuMpkzRK8wA+6KTjk+s6HQzC4cxCisKQhekq18i9yH6a3Gg8jzMqoMtOdFRJ+F8YDMUWrd2XwDkszTfEe2HX+6h4bw31igH7qT0hcUEkNDwGaC7busqKQFPAORaP3KKU6Mj5pbAtXSkq4QJHTCc4YEl+2erArRIsV5GaUarEDYIcDRJX8dsEKaAxtopUi1jFXKNLax+pf4x5Ma7zI2YVlk3Ms1rUOxYctvsa/45keXZUx/gmCZhhuRruN14Q6e6H+6F+alnCqvMSfMmpwXKgx0f879695x3rf/v3nPdFaVao64GaFvcMgShSf+xjAFeVWeBpSIwplhBxDVDSyT86l6Wr7eKrKEDF5DOY4Wwl5Tfxt5LJeiObp3a7CowB3nKt4zY3sxaY5PYJ6A== X-Forefront-Antispam-Report: CIP:12.22.5.234;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(82310400005)(36756003)(5660300002)(81166007)(40460700003)(36860700001)(2906002)(107886003)(426003)(6916009)(316002)(47076005)(356005)(16526019)(86362001)(54906003)(26005)(336012)(70586007)(8676002)(4326008)(83380400001)(186003)(2616005)(70206006)(6666004)(508600001)(8936002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2022 08:31:39.5511 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d9f50801-4886-417c-dbf8-08da243a85c5 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.234];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT035.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3073 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Add the "link" top-level group for showing IFLA_STATS_LINK_64 statistics. For example: # ip stats show dev swp1 group link 4178: swp1: group link RX: bytes packets errors dropped missed mcast 47048 354 0 0 0 64 TX: bytes packets errors dropped carrier collsns 47474 355 0 0 0 0 # ip -j stats show dev swp1 group link | jq [ { "ifindex": 4178, "ifname": "swp1", "group": "link", "stats64": { "rx": { "bytes": 47048, "packets": 354, "errors": 0, "dropped": 0, "over_errors": 0, "multicast": 64 }, "tx": { "bytes": 47474, "packets": 355, "errors": 0, "dropped": 0, "carrier_errors": 0, "collisions": 0 } } } ] Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- ip/ipstats.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/ip/ipstats.c b/ip/ipstats.c index 79f7b1ff..e4f97ddd 100644 --- a/ip/ipstats.c +++ b/ip/ipstats.c @@ -12,6 +12,15 @@ struct ipstats_stat_dump_filters { __u32 mask[IFLA_STATS_MAX + 1]; }; +static void +ipstats_stat_desc_enable_bit(struct ipstats_stat_dump_filters *filters, + unsigned int group, unsigned int subgroup) +{ + filters->mask[0] |= IFLA_STATS_FILTER_BIT(group); + if (subgroup) + filters->mask[group] |= IFLA_STATS_FILTER_BIT(subgroup); +} + struct ipstats_stat_show_attrs { struct if_stats_msg *ifsm; int len; @@ -89,6 +98,29 @@ ipstats_stat_show_attrs_alloc_tb(struct ipstats_stat_show_attrs *attrs, return err; } +static const struct rtattr * +ipstats_stat_show_get_attr(struct ipstats_stat_show_attrs *attrs, + int group, int subgroup, int *err) +{ + int tmp_err; + + if (err == NULL) + err = &tmp_err; + + *err = 0; + if (subgroup == 0) + return attrs->tbs[0][group]; + + if (attrs->tbs[0][group] == NULL) + return NULL; + + *err = ipstats_stat_show_attrs_alloc_tb(attrs, group); + if (*err != 0) + return NULL; + + return attrs->tbs[group][subgroup]; +} + static void ipstats_stat_show_attrs_free(struct ipstats_stat_show_attrs *attrs) { @@ -98,7 +130,65 @@ ipstats_stat_show_attrs_free(struct ipstats_stat_show_attrs *attrs) free(attrs->tbs[i]); } +#define IPSTATS_RTA_PAYLOAD(TYPE, AT) \ + ({ \ + const struct rtattr *__at = (AT); \ + TYPE *__ret = NULL; \ + \ + if (__at != NULL && \ + __at->rta_len - RTA_LENGTH(0) >= sizeof(TYPE)) \ + __ret = RTA_DATA(__at); \ + __ret; \ + }) + +static int ipstats_show_64(struct ipstats_stat_show_attrs *attrs, + unsigned int group, unsigned int subgroup) +{ + struct rtnl_link_stats64 *stats; + const struct rtattr *at; + int err; + + at = ipstats_stat_show_get_attr(attrs, group, subgroup, &err); + if (at == NULL) + return err; + + stats = IPSTATS_RTA_PAYLOAD(struct rtnl_link_stats64, at); + if (stats == NULL) { + fprintf(stderr, "Error: attribute payload too short"); + return -EINVAL; + } + + open_json_object("stats64"); + print_stats64(stdout, stats, NULL, NULL); + close_json_object(); + return 0; +} + +static void +ipstats_stat_desc_pack_link(struct ipstats_stat_dump_filters *filters, + const struct ipstats_stat_desc *desc) +{ + ipstats_stat_desc_enable_bit(filters, + IFLA_STATS_LINK_64, 0); +} + +static int +ipstats_stat_desc_show_link(struct ipstats_stat_show_attrs *attrs, + const struct ipstats_stat_desc *desc) +{ + print_nl(); + return ipstats_show_64(attrs, IFLA_STATS_LINK_64, 0); +} + +static const struct ipstats_stat_desc ipstats_stat_desc_toplev_link = { + .name = "link", + .kind = IPSTATS_STAT_DESC_KIND_LEAF, + .pack = &ipstats_stat_desc_pack_link, + .show = &ipstats_stat_desc_show_link, +}; + static const struct ipstats_stat_desc *ipstats_stat_desc_toplev_subs[] = { + &ipstats_stat_desc_toplev_link, }; static const struct ipstats_stat_desc ipstats_stat_desc_toplev_group = { From patchwork Fri Apr 22 08:30:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12823072 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47CB6C433FE for ; Fri, 22 Apr 2022 08:31:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445518AbiDVIer (ORCPT ); Fri, 22 Apr 2022 04:34:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445527AbiDVIeq (ORCPT ); Fri, 22 Apr 2022 04:34:46 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2083.outbound.protection.outlook.com [40.107.244.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 383D352E65 for ; Fri, 22 Apr 2022 01:31:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WS3+Z8eAFeDiPyA11+rIyUQ9UUJEYODyktbYZgIBH05QnwriHY5HR2zPCmMoK/nap6S3fj4dcSC4EPIvy2S2FguTAf/aP3SQgIh2HpygGVvHwJMi2T61VFxsiMdOYKMxfQuGD1fs/JzMr+0NaszX+9TDt9i0N9KFQWhlZNVHvx5nPxxIikx6+ouYG0S1Vavjz4bzaZWlRHctT1NRQ15z143wBnMYeUMUWxyO/dqvLApguAOhqygSLwgNw2xRlXn4gK4ax5Q2TouTZRFIp1AxjdfkZYDmIR9ySLlbzOjm2r4JxZXgQIcwuoPqMEg58iC4MldpRoojPOzQCkxjIVLscg== 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=ckMCROME+WX4LEg6mdRK4Hx+V09UqspIiEM5/B0+Owg=; b=j0vJz2R+SBjB2xM1GQLgrRkxPPUCEz2f5SJbj1C5g0MHvCScNzJQZX3gOrV9pjysiEeZtcbRVn/aMnxQ7JPlIXBvfmBrlxZwB8iplSC0A1jMCYvgzDeQ9bQbRwwbj7M6Lss1z4qjcPYOKTXLZdeiL7c4j4jAD2uwud+tuZtlXFUCKlbUQu3UQgXClhF5grp6eESotjs58R0gjT5cc074usLJqF717RoRX5OC1fO4exJQMeedCNXEgQZYXEGEl3qYcSCYL+2buY73TS5fKVRo1eaTC9A1ouhPFBscaN0DM9FiZ1YNH7vI4GS5GbvIrXCmkpoyjZT0TQRX/2gGCxsEzQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) smtp.rcpttodomain=networkplumber.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 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=ckMCROME+WX4LEg6mdRK4Hx+V09UqspIiEM5/B0+Owg=; b=TEul+EGCn9/rvGoHkYmIf4EuYoyWj/s0yqo0wBbNe1+IVGUk/gn+BXi3mbh/Q4p/QK5l/lr6G7PfwtvMDl8glvJpqZs9aAjW4dxeXIkB+XUpyUGesKaXqKDBccaEBxzRlGKhoPCcPamahsFj0dDcbPQTC0khVjVazwu1WXGX6P/WRKwrfI5yo0HbAQvdCY07CPhWeXr3daXCuxZ+H8bN7Wugbh/dQIop35yt8oQPsdAEkvzAsFRhtUsdq4ndpQYdnUImjHHeYEBVT33ACjUzcN3WtsKOGp+ESFuUvjRNHTWTr9c8fnH0zeC4CTBRX66BEbUgFzt2Vw18IDAHplDhzw== Received: from MW4PR04CA0207.namprd04.prod.outlook.com (2603:10b6:303:86::32) by BN8PR12MB3235.namprd12.prod.outlook.com (2603:10b6:408:6e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.15; Fri, 22 Apr 2022 08:31:42 +0000 Received: from CO1NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:303:86:cafe::dc) by MW4PR04CA0207.outlook.office365.com (2603:10b6:303:86::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.15 via Frontend Transport; Fri, 22 Apr 2022 08:31:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) 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 12.22.5.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.236) by CO1NAM11FT031.mail.protection.outlook.com (10.13.174.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5186.14 via Frontend Transport; Fri, 22 Apr 2022 08:31:41 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 22 Apr 2022 08:31:40 +0000 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.986.22; Fri, 22 Apr 2022 01:31:39 -0700 From: Petr Machata To: CC: David Ahern , Stephen Hemminger , Ido Schimmel , Petr Machata Subject: [PATCH iproute2-next 07/11] ipstats: Add a group "offload", subgroup "cpu_hit" Date: Fri, 22 Apr 2022 10:30:56 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ac09d0a0-951a-4b1f-75cb-08da243a86dd X-MS-TrafficTypeDiagnostic: BN8PR12MB3235:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PoYeVVWHDiHXND+KdnwwMFbLEgTjFhLWNXpqhIlBgWBqaT/n3wGVkXgwL36euR4jsAFcJszYeSwcl9jNMCNEXfTapIf2BYNO5sbp1vWV0Wq2bRblTAyF1hWZRFNtZ/oFWg/MwJWkya+sUktdrxIOxXpclNJLZWzLyO1OwE//qhK1t08LpC5hyWf115NaphskFTKKNxX88h9NDCphMJZY/f6EW8ntyBOST2GuRU/Mt9PDyxyjjqZANWkRLjTzydWa5fvTv6h8qzj5CpuaTiGyxbey9810WHdaIiF6+kfqYe5tiIErjcg0C0IfpmALxG5zeMKmtGRQnTaylzv8uxWpckoCaTxOUONrZeLrJqpKFQzvF2VA6HS6sbYRMl3UGQF+BlLXcNcfkzp02dr6TI01MtvC5fPyHWIZpPOHg32k0kHXqpWf9Vf41DWdDtxE/w+Yzl2cqxeFYsNPz9Y+15LJfJL5CdU2ZWKyEShRrH2PFnQ6bkxtg59vKu8RIujAYPK/0bCLecIN/+oz1Mjhf5QBmL0ocP9xXo9GDUOFjRCTsngdwyNOtSOeUIdUJUo3JUHBo140CDOiYVz8yL1LJnd1h9FPIFfzfvyy1JohSZaw4AUefFJcYzrZkpkZ1+pvdmHaLX3nohuslQybWyi9EYi1JGaOwNn7NcGzlB2Be01eJIqMdL41B07FLiscZDU/+NPxQn3b/y1u8ZrAIxwNeYCOfg== X-Forefront-Antispam-Report: CIP:12.22.5.236;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(2906002)(426003)(356005)(8936002)(6666004)(26005)(508600001)(70206006)(70586007)(107886003)(186003)(336012)(16526019)(54906003)(6916009)(316002)(2616005)(81166007)(36756003)(86362001)(40460700003)(36860700001)(8676002)(4326008)(47076005)(82310400005)(5660300002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2022 08:31:41.4616 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ac09d0a0-951a-4b1f-75cb-08da243a86dd X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.236];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT031.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3235 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Add a new group, "offload", for showing counters from the IFLA_STATS_LINK_OFFLOAD_XSTATS nest, and a subgroup "cpu_hit" for the IFLA_OFFLOAD_XSTATS_CPU_HIT stats suite. For example: # ip stats show dev swp1 group offload subgroup cpu_hit 4178: swp1: group offload subgroup cpu_hit RX: bytes packets errors dropped missed mcast 45522 353 0 0 0 0 TX: bytes packets errors dropped carrier collsns 46054 355 0 0 0 0 # ip -j stats show dev swp1 group offload subgroup cpu_hit | jq [ { "ifindex": 4178, "ifname": "swp1", "group": "offload", "subgroup": "cpu_hit", "stats64": { "rx": { "bytes": 45522, "packets": 353, "errors": 0, "dropped": 0, "over_errors": 0, "multicast": 0 }, "tx": { "bytes": 46054, "packets": 355, "errors": 0, "dropped": 0, "carrier_errors": 0, "collisions": 0 } } } ] Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- ip/ipstats.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/ip/ipstats.c b/ip/ipstats.c index e4f97ddd..283fba4e 100644 --- a/ip/ipstats.c +++ b/ip/ipstats.c @@ -164,6 +164,42 @@ static int ipstats_show_64(struct ipstats_stat_show_attrs *attrs, return 0; } +static void +ipstats_stat_desc_pack_cpu_hit(struct ipstats_stat_dump_filters *filters, + const struct ipstats_stat_desc *desc) +{ + ipstats_stat_desc_enable_bit(filters, + IFLA_STATS_LINK_OFFLOAD_XSTATS, + IFLA_OFFLOAD_XSTATS_CPU_HIT); +} + +static int ipstats_stat_desc_show_cpu_hit(struct ipstats_stat_show_attrs *attrs, + const struct ipstats_stat_desc *desc) +{ + print_nl(); + return ipstats_show_64(attrs, + IFLA_STATS_LINK_OFFLOAD_XSTATS, + IFLA_OFFLOAD_XSTATS_CPU_HIT); +} + +static const struct ipstats_stat_desc ipstats_stat_desc_offload_cpu_hit = { + .name = "cpu_hit", + .kind = IPSTATS_STAT_DESC_KIND_LEAF, + .pack = &ipstats_stat_desc_pack_cpu_hit, + .show = &ipstats_stat_desc_show_cpu_hit, +}; + +static const struct ipstats_stat_desc *ipstats_stat_desc_offload_subs[] = { + &ipstats_stat_desc_offload_cpu_hit, +}; + +static const struct ipstats_stat_desc ipstats_stat_desc_offload_group = { + .name = "offload", + .kind = IPSTATS_STAT_DESC_KIND_GROUP, + .subs = ipstats_stat_desc_offload_subs, + .nsubs = ARRAY_SIZE(ipstats_stat_desc_offload_subs), +}; + static void ipstats_stat_desc_pack_link(struct ipstats_stat_dump_filters *filters, const struct ipstats_stat_desc *desc) @@ -189,6 +225,7 @@ static const struct ipstats_stat_desc ipstats_stat_desc_toplev_link = { static const struct ipstats_stat_desc *ipstats_stat_desc_toplev_subs[] = { &ipstats_stat_desc_toplev_link, + &ipstats_stat_desc_offload_group, }; static const struct ipstats_stat_desc ipstats_stat_desc_toplev_group = { From patchwork Fri Apr 22 08:30:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12823076 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F6E3C433EF for ; Fri, 22 Apr 2022 08:32:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445530AbiDVIex (ORCPT ); Fri, 22 Apr 2022 04:34:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445529AbiDVIeq (ORCPT ); Fri, 22 Apr 2022 04:34:46 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2078.outbound.protection.outlook.com [40.107.243.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9739A52E69 for ; Fri, 22 Apr 2022 01:31:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CTD9C26VRxolaUXP57ufX0q7sRDoiFA+i4f9+5uN20K9oaaqmAkKi8oTttSwBHnqHxmuEUoTrU9/YWPOQq8uNSkJUpD/0Fq0CVbLzalGo1ylyWUriQmA1w8JnD5330miwN4oYqRs9mLW7AdStVgsFhaM2oFhaWhHMvf4gAch/9qYYwBVyTFt9M+vI00d7Fw6EjKwA/BMrpoExusVEhVeMqz6aJ+S57VtJ3RX3eJAN8G4fRWxkEGPQLl3NnlegvfkeRm+AEW7wQSywWdSNQE1whidNFXrnD8TvhLuqK64rHRZpMiNV8/RG87OgWM82T40MZcE16GkFcArOjticoxxzA== 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=vb3x5BV93RiIowGj0a8+FV74nWiFRzR+0kGSQrT0EYE=; b=YndFyvvhPwbDaDL21mHUdtG/3K8+QbHPuaTEp/u6uJiZLQAY+UKnF8wyjx5A7/FR2DpgoZNielCun8OzId8KbFFi44DZFmFgKqA1K6VVN0LU+MQTXSz4om5X8sx1NpVWfz4F6bF7YAGHfH3snY3DHdKvCanmo241zCuhTt4G2IE4iENrseA0i+3gUCJJuNrNcMFpfnJOrZzdCpDHZWHn5dkYUFDrspfGqjpUoF9gbVnjQbEx2c3iRYRqxDWR2P50Cl8uIfKNZZr9eOS7IahAER33nvd+ReFTEPTcRL0SqYmc8d/+fcgvo7Aolcbq1lm3C5oMm+a3hxXnpzngfPbDyA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=networkplumber.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 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=vb3x5BV93RiIowGj0a8+FV74nWiFRzR+0kGSQrT0EYE=; b=Apu2/dkDtxYIA6vwAS6V3tQjg0xsKj6tOL5IUfJtsSlE1gWMViLulzLZbsr04HN1Fb4TbF3IHxwQ/whvvQUEw0yoTjS1s7JnKV0wcQBMsh3Yyy9b4EZ4Iu7kXI+RnJNm3x9CM2OAs490na3VYghZRbHLCYPT58zDzSZJU6ay8CravfjpGDKIOYSRvy8kQ9oTLcgWUaOEB4rduTFDhZ8usE6yFX+3GpQmdM7BrM3Ct2NRZ6nXy3U7OqibcDm6lsQd7B+pYigQcaT3pq24r2wo9mc4ACIxonhG3/FrXjlzPZU2MNqjWu0avJ07alL1PTt18QKGamX+WKBgxv6jk8NmZw== Received: from DS7PR05CA0099.namprd05.prod.outlook.com (2603:10b6:8:56::20) by MN2PR12MB3920.namprd12.prod.outlook.com (2603:10b6:208:168::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.15; Fri, 22 Apr 2022 08:31:43 +0000 Received: from DM6NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:8:56:cafe::83) by DS7PR05CA0099.outlook.office365.com (2603:10b6:8:56::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.6 via Frontend Transport; Fri, 22 Apr 2022 08:31:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) 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 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.235) by DM6NAM11FT008.mail.protection.outlook.com (10.13.172.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5186.14 via Frontend Transport; Fri, 22 Apr 2022 08:31:43 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 22 Apr 2022 08:31:42 +0000 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.986.22; Fri, 22 Apr 2022 01:31:40 -0700 From: Petr Machata To: CC: David Ahern , Stephen Hemminger , Ido Schimmel , Petr Machata Subject: [PATCH iproute2-next 08/11] ipstats: Add offload subgroup "hw_stats_info" Date: Fri, 22 Apr 2022 10:30:57 +0200 Message-ID: <10e22980dbca5f96408672266a96baf32b88712f.1650615982.git.petrm@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 438a0fe5-c1a6-4f17-cf84-08da243a8803 X-MS-TrafficTypeDiagnostic: MN2PR12MB3920:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UW5Oat1ZGcp5OB4THbbBd8UHYXN18azesPuPTJs7vB+ijB3oJfPvSS0+mglFADtyiXsgd184Vw60zkJs/hLOvg1a3WACEhA5UaWoaVRCOr7PcgMSn2U/tc1XQbGRi3VIyn8Wkzm9ENt04boH9ZkXoQitWg48GJjjZpdFSgnUqwPQVtQ1fY3UPkqQ0wZYGjjKMGX+AsiO/263ELNVG2pOZBfwdVhFQQBVzh3XcuUmTqRzEKQDi5sjGTdrgFY4fBWoGWxuWD7KdlQ8JPI8yO/7Tthlcf/4+umdycBN9HfsLTpDKEpVXhhtjPLqdlCAPcFj9782kZa3/ex1SczSsKy3NlsLoXEZpM9R6729MiYCuiVE1NDhi5MXFAlUXHCPEEI4x3SD8OwoSDAeh+6bVx6sIVboS0bhngmPtYHUzCA6zNnytwnTxch9nnka4YLZWkK797wrU6WAvNw7kImlwcWq2f4qtcc+vMzbTRsst5HM1pa7ycdJerg/dUnbR+p1E46H8bIpCjyn08CgeYieufuZmI1i3cv4C0oY7acbp3GRs7KyuytDUj8wA3Ijf+1L2QxPFqtTIqn3JhLv+L/vjvkZo6zeKum1CK1hj8yqxy9MzN2+N76vyz/KJJGU5ZCAfujtrdIByq+s0+f5j/qiqneMPK3mdiKUKk/x8GjI9UB18ITG65hhiWURjQmsmA2wLlAkFliOtqpay4QBo6SVJPptfQ== X-Forefront-Antispam-Report: CIP:12.22.5.235;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(426003)(70206006)(70586007)(186003)(16526019)(47076005)(336012)(40460700003)(107886003)(2616005)(26005)(36756003)(83380400001)(356005)(82310400005)(6916009)(81166007)(54906003)(4326008)(8676002)(86362001)(36860700001)(6666004)(2906002)(316002)(8936002)(508600001)(5660300002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2022 08:31:43.3594 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 438a0fe5-c1a6-4f17-cf84-08da243a8803 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.235];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3920 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Add into the group "offload" a subgroup "hw_stats_info" for showing information about HW statistics counters. For example: # ip stats show dev swp1 group offload subgroup hw_stats_info 4178: swp1: group offload subgroup hw_stats_info l3_stats on used off # ip -j stats show dev swp1 group offload subgroup hw_stats_info | jq [ { "ifindex": 4178, "ifname": "swp1", "group": "offload", "subgroup": "hw_stats_info", "info": { "l3_stats": { "request": true, "used": false } } } ] Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- ip/ipstats.c | 217 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) diff --git a/ip/ipstats.c b/ip/ipstats.c index 283fba4e..4cdd5122 100644 --- a/ip/ipstats.c +++ b/ip/ipstats.c @@ -164,6 +164,197 @@ static int ipstats_show_64(struct ipstats_stat_show_attrs *attrs, return 0; } +enum ipstats_maybe_on_off { + IPSTATS_MOO_OFF = -1, + IPSTATS_MOO_INVALID, + IPSTATS_MOO_ON, +}; + +static bool ipstats_moo_to_bool(enum ipstats_maybe_on_off moo) +{ + assert(moo != IPSTATS_MOO_INVALID); + return moo + 1; +} + +static int ipstats_print_moo(enum output_type t, const char *key, + const char *fmt, enum ipstats_maybe_on_off moo) +{ + if (!moo) + return 0; + return print_on_off(t, key, fmt, ipstats_moo_to_bool(moo)); +} + +struct ipstats_hw_s_info_one { + enum ipstats_maybe_on_off request; + enum ipstats_maybe_on_off used; +}; + +enum ipstats_hw_s_info_idx { + IPSTATS_HW_S_INFO_IDX_L3_STATS, + IPSTATS_HW_S_INFO_IDX_COUNT +}; + +static const char *const ipstats_hw_s_info_name[] = { + "l3_stats", +}; + +static_assert(ARRAY_SIZE(ipstats_hw_s_info_name) == + IPSTATS_HW_S_INFO_IDX_COUNT, + "mismatch: enum ipstats_hw_s_info_idx x ipstats_hw_s_info_name"); + +struct ipstats_hw_s_info { + /* Indexed by enum ipstats_hw_s_info_idx. */ + struct ipstats_hw_s_info_one *infos[IPSTATS_HW_S_INFO_IDX_COUNT]; +}; + +static enum ipstats_maybe_on_off ipstats_dissect_01(int value, const char *what) +{ + switch (value) { + case 0: + return IPSTATS_MOO_OFF; + case 1: + return IPSTATS_MOO_ON; + default: + fprintf(stderr, "Invalid value for %s: expected 0 or 1, got %d.\n", + what, value); + return IPSTATS_MOO_INVALID; + } +} + +static int ipstats_dissect_hw_s_info_one(const struct rtattr *at, + struct ipstats_hw_s_info_one *p_hwsio, + const char *what) +{ + int attr_id_request = IFLA_OFFLOAD_XSTATS_HW_S_INFO_REQUEST; + struct rtattr *tb[IFLA_OFFLOAD_XSTATS_HW_S_INFO_MAX + 1]; + int attr_id_used = IFLA_OFFLOAD_XSTATS_HW_S_INFO_USED; + struct ipstats_hw_s_info_one hwsio = {}; + int err; + int v; + + err = parse_rtattr_nested(tb, IFLA_OFFLOAD_XSTATS_HW_S_INFO_MAX, at); + if (err) + return err; + + if (tb[attr_id_request]) { + v = rta_getattr_u8(tb[attr_id_request]); + hwsio.request = ipstats_dissect_01(v, "request"); + + /* This has to be present & valid. */ + if (!hwsio.request) + return -EINVAL; + } + + if (tb[attr_id_used]) { + v = rta_getattr_u8(tb[attr_id_used]); + hwsio.used = ipstats_dissect_01(v, "used"); + } + + *p_hwsio = hwsio; + return 0; +} + +static int ipstats_dissect_hw_s_info(const struct rtattr *at, + struct ipstats_hw_s_info *hwsi) +{ + struct rtattr *tb[IFLA_OFFLOAD_XSTATS_MAX + 1]; + int attr_id_l3 = IFLA_OFFLOAD_XSTATS_L3_STATS; + struct ipstats_hw_s_info_one *hwsio = NULL; + int err; + + err = parse_rtattr_nested(tb, IFLA_OFFLOAD_XSTATS_MAX, at); + if (err) + return err; + + *hwsi = (struct ipstats_hw_s_info){}; + + if (tb[attr_id_l3]) { + hwsio = malloc(sizeof(*hwsio)); + if (!hwsio) { + err = -ENOMEM; + goto out; + } + + err = ipstats_dissect_hw_s_info_one(tb[attr_id_l3], hwsio, "l3"); + if (err) + goto out; + + hwsi->infos[IPSTATS_HW_S_INFO_IDX_L3_STATS] = hwsio; + hwsio = NULL; + } + + return 0; + +out: + free(hwsio); + return err; +} + +static void ipstats_fini_hw_s_info(struct ipstats_hw_s_info *hwsi) +{ + int i; + + for (i = 0; i < IPSTATS_HW_S_INFO_IDX_COUNT; i++) + free(hwsi->infos[i]); +} + +static void +__ipstats_show_hw_s_info_one(const struct ipstats_hw_s_info_one *hwsio) +{ + if (hwsio == NULL) + return; + + ipstats_print_moo(PRINT_ANY, "request", " %s", hwsio->request); + ipstats_print_moo(PRINT_ANY, "used", " used %s", hwsio->used); +} + +static void +ipstats_show_hw_s_info_one(const struct ipstats_hw_s_info *hwsi, + enum ipstats_hw_s_info_idx idx) +{ + const struct ipstats_hw_s_info_one *hwsio = hwsi->infos[idx]; + const char *name = ipstats_hw_s_info_name[idx]; + + if (hwsio == NULL) + return; + + print_string(PRINT_FP, NULL, " %s", name); + open_json_object(name); + __ipstats_show_hw_s_info_one(hwsio); + close_json_object(); +} + +static int __ipstats_show_hw_s_info(const struct rtattr *at) +{ + struct ipstats_hw_s_info hwsi = {}; + int err; + + err = ipstats_dissect_hw_s_info(at, &hwsi); + if (err) + return err; + + open_json_object("info"); + ipstats_show_hw_s_info_one(&hwsi, IPSTATS_HW_S_INFO_IDX_L3_STATS); + close_json_object(); + + ipstats_fini_hw_s_info(&hwsi); + return 0; +} + +static int ipstats_show_hw_s_info(struct ipstats_stat_show_attrs *attrs, + unsigned int group, unsigned int subgroup) +{ + const struct rtattr *at; + int err; + + at = ipstats_stat_show_get_attr(attrs, group, subgroup, &err); + if (at == NULL) + return err; + + print_nl(); + return __ipstats_show_hw_s_info(at); +} + static void ipstats_stat_desc_pack_cpu_hit(struct ipstats_stat_dump_filters *filters, const struct ipstats_stat_desc *desc) @@ -189,8 +380,34 @@ static const struct ipstats_stat_desc ipstats_stat_desc_offload_cpu_hit = { .show = &ipstats_stat_desc_show_cpu_hit, }; +static void +ipstats_stat_desc_pack_hw_stats_info(struct ipstats_stat_dump_filters *filters, + const struct ipstats_stat_desc *desc) +{ + ipstats_stat_desc_enable_bit(filters, + IFLA_STATS_LINK_OFFLOAD_XSTATS, + IFLA_OFFLOAD_XSTATS_HW_S_INFO); +} + +static int +ipstats_stat_desc_show_hw_stats_info(struct ipstats_stat_show_attrs *attrs, + const struct ipstats_stat_desc *desc) +{ + return ipstats_show_hw_s_info(attrs, + IFLA_STATS_LINK_OFFLOAD_XSTATS, + IFLA_OFFLOAD_XSTATS_HW_S_INFO); +} + +static const struct ipstats_stat_desc ipstats_stat_desc_offload_hw_s_info = { + .name = "hw_stats_info", + .kind = IPSTATS_STAT_DESC_KIND_LEAF, + .pack = &ipstats_stat_desc_pack_hw_stats_info, + .show = &ipstats_stat_desc_show_hw_stats_info, +}; + static const struct ipstats_stat_desc *ipstats_stat_desc_offload_subs[] = { &ipstats_stat_desc_offload_cpu_hit, + &ipstats_stat_desc_offload_hw_s_info, }; static const struct ipstats_stat_desc ipstats_stat_desc_offload_group = { From patchwork Fri Apr 22 08:30:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12823077 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 436C0C433EF for ; Fri, 22 Apr 2022 08:32:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445182AbiDVIez (ORCPT ); Fri, 22 Apr 2022 04:34:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445532AbiDVIeq (ORCPT ); Fri, 22 Apr 2022 04:34:46 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2054.outbound.protection.outlook.com [40.107.236.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3251852E75 for ; Fri, 22 Apr 2022 01:31:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hUsbi5DLh3KC5sV302Hv78SsVKH+21V2ZCaoFSy+U6UIRadzMYRP6zk1qvJFFqmHw9jAq3wo3uUgLEzb1Gq0INpeSMPx6r/mPaxqqnRhl/ie7BAG8K46K3f/Xjw8pNghTc46g8M0V+EkwnuKhNzIzocGVn66qegYFJjtz1WebAvOzBcjZ9vqJC+ZGBwWPgzP8wsHOb0hrHVYBYAncs2kPhhg7k0nCT5YhU2RVEbtq/uQ11sbaJcivWN3f01MYoy9nedAwxL4aESiuMEdZf5mrGQ5w9yy2LJteiA69jIFxQdOzp73BW3RqlDshwECoNFgHH42Dl6ZlUrZzopizodz+g== 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=Xon3V8m3B3G+2sFOaEz6Hxg7y7D1d5S+/B+mHbrFumQ=; b=fFlvoNPcD/s/KnsGTi1Ty4uIm9fT7SLUFT+/eUmFszXKeQSZZkfl4KqntXKrB+IemgzEKInQuBV4E2HSC+EpGMqMSA3KmKYnbmxQ2eXOsJHzI2/s7fdMS8b/D2zWm92KfUdlgJ2BHLbfak3sQAb3oDDeyPpvLe4NFHuscOJt8OZDSVPlcG0hpe6hXE20ksB2NJ4Cwd9m5OXYwgBenoKae/X8RyIHVv9zJ3P9zZ1OuphQgdICs5U+NNmL0nFRReVO1huckcMjBGwDzh2POV1cGKKCEYyQ3QlDMwe1ZvK4buceyyXtt3fVPWgwQqouxzI19cZI9uy6D5crCKBCIdO5UA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=networkplumber.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 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=Xon3V8m3B3G+2sFOaEz6Hxg7y7D1d5S+/B+mHbrFumQ=; b=VIvZkUGnrpEcyJJ8QBSVjcToa8KokJv0bUfCDuHsU3oFfKV9e3qRPTNTrpkL5XLMrsDREeCjh9fg2ebrwNvQsxr2z855AKac2HbBUnvW9w69+ctuGEnYGn7fWckv1X/3ZrN/6fOkGYkK/M8WuyZNzK6EAlW2GhtGKSuyi1Cd8eMnAdNe9Xh9hu3Rm67GlWvJrozg7XPUgpLb0/mGCyZ2k1UZJMBWK+c73/MeIwbxegem0g6Ok50b6Tml2F5FNXvyjp6l+MwnrGMbyWMkbVkTgNbtSsi4RK3wpRJRSyEDupZ9RRGz9kXf5xnDJ1kcxouJX8X6qBK6woXQYMf0uTc1Hw== Received: from DM6PR03CA0045.namprd03.prod.outlook.com (2603:10b6:5:100::22) by DM6PR12MB3052.namprd12.prod.outlook.com (2603:10b6:5:11e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Fri, 22 Apr 2022 08:31:45 +0000 Received: from DM6NAM11FT056.eop-nam11.prod.protection.outlook.com (2603:10b6:5:100:cafe::72) by DM6PR03CA0045.outlook.office365.com (2603:10b6:5:100::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14 via Frontend Transport; Fri, 22 Apr 2022 08:31:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) 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 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.238) by DM6NAM11FT056.mail.protection.outlook.com (10.13.173.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5186.14 via Frontend Transport; Fri, 22 Apr 2022 08:31:45 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 22 Apr 2022 08:31:44 +0000 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.986.22; Fri, 22 Apr 2022 01:31:42 -0700 From: Petr Machata To: CC: David Ahern , Stephen Hemminger , Ido Schimmel , Petr Machata Subject: [PATCH iproute2-next 09/11] ipstats: Add offload subgroup "l3_stats" Date: Fri, 22 Apr 2022 10:30:58 +0200 Message-ID: <42aace625494db72cb0b7252bbeba12df7703f78.1650615982.git.petrm@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2bc84a5a-8f8e-4240-dbb5-08da243a8912 X-MS-TrafficTypeDiagnostic: DM6PR12MB3052:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BsXRlgbR6d1C1sP9fAHdYeCcCCdhpp8uoqu33Y4IcsTXhnCLYgZlZwYwxNsqyYMJxE9dKLjjhRdfOKnBUrmKLDdewsfeOdfj+F3apxg0S7K0Cw78q02QtftBeZExjWPNwcaUvS3adGNVqoW5MCzEw4GD/vA0f8jqpTN0eI5wd9lj6Ud3aoFLLyu6Lk+i+1ZXKqKv8DaFDeQjIsxVKZNhDzf8OHwDbJH2GGnUp1esZMl8/xIc6Kdd2cqzTvtmsQUQhLwQufJ4L0UvxB6nA0S+YIgl7xKZ8+vvkCt8aUCXe60AtYXnVuT6VCEuZ1yX+t3ixhIXm/2u4+WKLpd93CahuhWW2V6ezjZch4x3jyvVOfIexfvBSxrS6QtXCNhYm4elrsM2ivuNyLWIwJuRk/+69bs1d8YfEq28vmhdLSc2FloSeFY7cmFDWhGxLri51m4Gf2uyA72d1C+JLdsKtKPNMVi3b5bJBkrHlYEigKfDBZByvQ/jFQhA8ndFJduVvZBhBADz/0zE6gnLI9uLdHHByVJNm4Peim7FXNM/+EVsKSev+gccsE5gS8Akg7z4/zMEkr8sb3pqeK3HGdrqw6tnUU2XeC87IErDRfi2jqQxnB39+xemeFXuvSaEufgeiUWRWAPcIZZHjZXjHqEghhkR84H7sfAxc2dU4aiKipEX/sFju0LRT3xdRRpNoy5gzvxWa65h8+JFolfCFyHXApX/HA== X-Forefront-Antispam-Report: CIP:12.22.5.238;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(2616005)(47076005)(81166007)(356005)(70586007)(8936002)(8676002)(4326008)(70206006)(336012)(426003)(186003)(107886003)(6666004)(26005)(6916009)(16526019)(36860700001)(2906002)(83380400001)(316002)(54906003)(40460700003)(82310400005)(5660300002)(508600001)(86362001)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2022 08:31:45.1514 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2bc84a5a-8f8e-4240-dbb5-08da243a8912 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.238];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT056.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3052 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Add into the group "offload" a subgroup "l3_stats" for showing L3 statistics. For example: # ip stats show dev swp2.200 group offload subgroup l3_stats 4212: swp2.200: group offload subgroup l3_stats on used on RX: bytes packets errors dropped mcast 1920 21 1 0 0 TX: bytes packets errors dropped 756 9 0 0 # ip -j stats show dev swp2.200 group offload subgroup l3_stats | jq [ { "ifindex": 4212, "ifname": "swp2.200", "group": "offload", "subgroup": "l3_stats", "info": { "request": true, "used": true }, "stats64": { "rx": { "bytes": 1920, "packets": 21, "errors": 1, "dropped": 0, "multicast": 0 }, "tx": { "bytes": 756, "packets": 9, "errors": 0, "dropped": 0 } } } ] Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- ip/ipstats.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) diff --git a/ip/ipstats.c b/ip/ipstats.c index 4cdd5122..29ca0731 100644 --- a/ip/ipstats.c +++ b/ip/ipstats.c @@ -164,6 +164,82 @@ static int ipstats_show_64(struct ipstats_stat_show_attrs *attrs, return 0; } +static void print_hw_stats64(FILE *fp, struct rtnl_hw_stats64 *s) +{ + unsigned int cols[] = { + strlen("*X: bytes"), + strlen("packets"), + strlen("errors"), + strlen("dropped"), + strlen("overrun"), + }; + + if (is_json_context()) { + /* RX stats */ + open_json_object("rx"); + print_u64(PRINT_JSON, "bytes", NULL, s->rx_bytes); + print_u64(PRINT_JSON, "packets", NULL, s->rx_packets); + print_u64(PRINT_JSON, "errors", NULL, s->rx_errors); + print_u64(PRINT_JSON, "dropped", NULL, s->rx_dropped); + print_u64(PRINT_JSON, "multicast", NULL, s->multicast); + close_json_object(); + + /* TX stats */ + open_json_object("tx"); + print_u64(PRINT_JSON, "bytes", NULL, s->tx_bytes); + print_u64(PRINT_JSON, "packets", NULL, s->tx_packets); + print_u64(PRINT_JSON, "errors", NULL, s->tx_errors); + print_u64(PRINT_JSON, "dropped", NULL, s->tx_dropped); + close_json_object(); + } else { + size_columns(cols, ARRAY_SIZE(cols), + s->rx_bytes, s->rx_packets, s->rx_errors, + s->rx_dropped, s->multicast); + size_columns(cols, ARRAY_SIZE(cols), + s->tx_bytes, s->tx_packets, s->tx_errors, + s->tx_dropped, 0); + + /* RX stats */ + fprintf(fp, " RX: %*s %*s %*s %*s %*s%s", + cols[0] - 4, "bytes", cols[1], "packets", + cols[2], "errors", cols[3], "dropped", + cols[4], "mcast", _SL_); + + fprintf(fp, " "); + print_num(fp, cols[0], s->rx_bytes); + print_num(fp, cols[1], s->rx_packets); + print_num(fp, cols[2], s->rx_errors); + print_num(fp, cols[3], s->rx_dropped); + print_num(fp, cols[4], s->multicast); + fprintf(fp, "%s", _SL_); + + /* TX stats */ + fprintf(fp, " TX: %*s %*s %*s %*s%s", + cols[0] - 4, "bytes", cols[1], "packets", + cols[2], "errors", cols[3], "dropped", _SL_); + + fprintf(fp, " "); + print_num(fp, cols[0], s->tx_bytes); + print_num(fp, cols[1], s->tx_packets); + print_num(fp, cols[2], s->tx_errors); + print_num(fp, cols[3], s->tx_dropped); + } +} + +static int ipstats_show_hw64(const struct rtattr *at) +{ + struct rtnl_hw_stats64 *stats; + + stats = IPSTATS_RTA_PAYLOAD(struct rtnl_hw_stats64, at); + if (stats == NULL) { + fprintf(stderr, "Error: attribute payload too short"); + return -EINVAL; + } + + print_hw_stats64(stdout, stats); + return 0; +} + enum ipstats_maybe_on_off { IPSTATS_MOO_OFF = -1, IPSTATS_MOO_INVALID, @@ -355,6 +431,57 @@ static int ipstats_show_hw_s_info(struct ipstats_stat_show_attrs *attrs, return __ipstats_show_hw_s_info(at); } +static int __ipstats_show_hw_stats(const struct rtattr *at_hwsi, + const struct rtattr *at_stats, + enum ipstats_hw_s_info_idx idx) +{ + int err = 0; + + if (at_hwsi != NULL) { + struct ipstats_hw_s_info hwsi = {}; + + err = ipstats_dissect_hw_s_info(at_hwsi, &hwsi); + if (err) + return err; + + open_json_object("info"); + __ipstats_show_hw_s_info_one(hwsi.infos[idx]); + close_json_object(); + + ipstats_fini_hw_s_info(&hwsi); + } + + if (at_stats != NULL) { + print_nl(); + open_json_object("stats64"); + err = ipstats_show_hw64(at_stats); + close_json_object(); + } + + return err; +} + +static int ipstats_show_hw_stats(struct ipstats_stat_show_attrs *attrs, + unsigned int group, + unsigned int hw_s_info, + unsigned int hw_stats, + enum ipstats_hw_s_info_idx idx) +{ + const struct rtattr *at_stats; + const struct rtattr *at_hwsi; + int err = 0; + + at_hwsi = ipstats_stat_show_get_attr(attrs, group, hw_s_info, &err); + if (at_hwsi == NULL) + return err; + + at_stats = ipstats_stat_show_get_attr(attrs, group, hw_stats, &err); + if (at_stats == NULL && err != 0) + return err; + + return __ipstats_show_hw_stats(at_hwsi, at_stats, idx); +} + static void ipstats_stat_desc_pack_cpu_hit(struct ipstats_stat_dump_filters *filters, const struct ipstats_stat_desc *desc) @@ -405,9 +532,40 @@ static const struct ipstats_stat_desc ipstats_stat_desc_offload_hw_s_info = { .show = &ipstats_stat_desc_show_hw_stats_info, }; +static void +ipstats_stat_desc_pack_l3_stats(struct ipstats_stat_dump_filters *filters, + const struct ipstats_stat_desc *desc) +{ + ipstats_stat_desc_enable_bit(filters, + IFLA_STATS_LINK_OFFLOAD_XSTATS, + IFLA_OFFLOAD_XSTATS_L3_STATS); + ipstats_stat_desc_enable_bit(filters, + IFLA_STATS_LINK_OFFLOAD_XSTATS, + IFLA_OFFLOAD_XSTATS_HW_S_INFO); +} + +static int +ipstats_stat_desc_show_l3_stats(struct ipstats_stat_show_attrs *attrs, + const struct ipstats_stat_desc *desc) +{ + return ipstats_show_hw_stats(attrs, + IFLA_STATS_LINK_OFFLOAD_XSTATS, + IFLA_OFFLOAD_XSTATS_HW_S_INFO, + IFLA_OFFLOAD_XSTATS_L3_STATS, + IPSTATS_HW_S_INFO_IDX_L3_STATS); +} + +static const struct ipstats_stat_desc ipstats_stat_desc_offload_l3_stats = { + .name = "l3_stats", + .kind = IPSTATS_STAT_DESC_KIND_LEAF, + .pack = &ipstats_stat_desc_pack_l3_stats, + .show = &ipstats_stat_desc_show_l3_stats, +}; + static const struct ipstats_stat_desc *ipstats_stat_desc_offload_subs[] = { &ipstats_stat_desc_offload_cpu_hit, &ipstats_stat_desc_offload_hw_s_info, + &ipstats_stat_desc_offload_l3_stats, }; static const struct ipstats_stat_desc ipstats_stat_desc_offload_group = { From patchwork Fri Apr 22 08:30:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12823075 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40A1CC433F5 for ; Fri, 22 Apr 2022 08:32:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445527AbiDVIew (ORCPT ); Fri, 22 Apr 2022 04:34:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445530AbiDVIeq (ORCPT ); Fri, 22 Apr 2022 04:34:46 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2055.outbound.protection.outlook.com [40.107.243.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DCCF52E77 for ; Fri, 22 Apr 2022 01:31:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H0RkFdiwWfMuOxBLXhgcM4OJrw22C0wcshyt/ZasshrlA8EUBs4ViWInynJCf+33U5io6B4EhmFEn52U4Z8DqJCmRES9dcNbf/zifrGhEwD4WSJ4ORetxqSRv6RIEL8lIDJq/jKGf2Je524j7BcJjhBWmVx0aRwfsT9VxILPYKO0xSsGb0LwFkk+dmgPusmhC2piBDSQxM+3eij+wrVQeM++vbbWprzc766FLhEOEF+o35bXSWUkqIQ5YlfDwViHDrIYDraorFOIQ/CmlYcLqQDD7HOK9cxHm4XMUi898pYqC+0bE6E9u4yXOMunqvc146BGb/IIiLMflUOGnWpZ6w== 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=roINls9zHxI0KLFTVbHBZSRS3ArvIzeIf0TBJ+gJYDI=; b=S0ZZT1HpHUiCORWdu7pADB3Xp3h7NZWuwATri0+7b3xBdFkaQT3yd6ZJzupVkYvJy9TdP8KVl1uwKvjDtadvxLMD3NQI4dTFbKaVa7Lq1cORvCdy4Dtj9wB8CJ+eBD2vdTPpfKMABqAPVWm8z7OWU6galmlazbRE8o07GgtpSTDYHQNql3EIqpSKlrVBoZ7ohIPgr7HMCijVXNNX1dekB5rlhWdQSFXL8XAsjtF+DMk9ttyOR6hkfhF0yZOEgOKlIVn67tNjzoyCCnnoTORn4BwDvjAO77h/djniklcoz0DxWv1lKrBaga90DIg56mi0HEWvNr5Is4+oYkaYWizccg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=networkplumber.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 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=roINls9zHxI0KLFTVbHBZSRS3ArvIzeIf0TBJ+gJYDI=; b=lOywx6+B7XQNfg9p8J5oVMrgY5JlRiZzfhXwa5pevTgNNuf1ELPT+ngY8RZf583V+wn+P7TFbGrMy9gc/wLDMcyDHQYUyOj0DmJsuP75fO0kevOSUuIDEJL+SfmeiiQuhwagzjuTHjtrJrO3EYNLIr/JV27NBJ2wKIljudMpe/ItzX5kMgraQ0GAAucsQ+lI4D1XjnPQXzXYQ8I51DAgt8po9A1DEa+zB0puJfedCpdaLnOCFs+3kTrcR/Xr2EzBPVscvRNg/CnqKiASwZo+m1Kx9T0owYUKGp2j3u2B+NDvR5kLwFGhYgsS7RaX8DWEg2MBizLQJZPPQAazgmBxsw== Received: from BN1PR10CA0026.namprd10.prod.outlook.com (2603:10b6:408:e0::31) by DS7PR12MB5960.namprd12.prod.outlook.com (2603:10b6:8:7f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14; Fri, 22 Apr 2022 08:31:47 +0000 Received: from BN8NAM11FT063.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e0:cafe::ef) by BN1PR10CA0026.outlook.office365.com (2603:10b6:408:e0::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.13 via Frontend Transport; Fri, 22 Apr 2022 08:31:47 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) 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 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.234) by BN8NAM11FT063.mail.protection.outlook.com (10.13.177.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5186.14 via Frontend Transport; Fri, 22 Apr 2022 08:31:46 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 22 Apr 2022 08:31:46 +0000 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.986.22; Fri, 22 Apr 2022 01:31:44 -0700 From: Petr Machata To: CC: David Ahern , Stephen Hemminger , Ido Schimmel , Petr Machata Subject: [PATCH iproute2-next 10/11] ipmonitor: Add monitoring support for stats events Date: Fri, 22 Apr 2022 10:30:59 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a7337dc7-aa9d-4620-a400-08da243a8a32 X-MS-TrafficTypeDiagnostic: DS7PR12MB5960:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iBpWi+sDna/x2NIgzg8Bt8Uw35htZxIB+bVoCCh2/IaheK1KRDTIdAKCPg3Niw1tb0HlxEqtGI4pnRNRB3RmpRSSTYlWxO/6nNn0+wGN9JpxdH1CLfJvKymN0Js1FhLRoaAN2h2tGpyEQIqg9EGuy2PLqMoUU6U7qmcDp/Dn5QHscVcOb60iA9D2EnQ5wuqU3em5mIQ8L5ZcfAEUnjRd6o6AZwPIuxe1HKdpcXBseF/V+F0K8zNF39da9CvtWir8WdybZkYs6xHCBQCvR8R49pWOWDS9fFrEkcUBXdGrbXnNfyRDq1NDBUymraY69jj63U9uLYegBUWQf1CNyWSindPAAs7tMoW2DRM3Y8nZM1h8X2uTlkAa9h59koYvBr1uH4lgJOJctEeYRXYIrejdGQe4ajD1EAV28Fvt7Sy6M/TN1MyJFsThdqdlJJzcyLhQFzmixqxUMoBdeUQfiTrkMREzb8hPak6AAqkpupFYDfrXEij2h4DakRQ97OdRaKhFEMWilfv4G+rx+ZcmStrReGuaiT5imhn8H6NeFkiofzRgZmKOjQN0k4GgI72argcuxw93V+EGJ8Aq2mbelajocw5aRFpegSveCbLB61URbvAzI2FODffmo+AEYjpBhpgLFU5x35cET0yVT++GmxduhZB7+4mGYyTEgJTAK1V4pohyH3cUyV9zR96fmYSBi+3Tgjm0WKMMXIlydDDBZl6VTA== X-Forefront-Antispam-Report: CIP:12.22.5.234;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(2906002)(26005)(81166007)(356005)(36860700001)(8936002)(36756003)(5660300002)(107886003)(2616005)(16526019)(186003)(40460700003)(6666004)(4326008)(508600001)(83380400001)(82310400005)(47076005)(336012)(426003)(6916009)(8676002)(86362001)(316002)(54906003)(70206006)(70586007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2022 08:31:46.9905 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a7337dc7-aa9d-4620-a400-08da243a8a32 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.234];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT063.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5960 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Toggles and offloads of HW statistics cause emission of and RTM_NEWSTATS event. Add support to "ip monitor" for these events. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- ip/ip_common.h | 1 + ip/ipmonitor.c | 16 +++++++++++++++- ip/ipstats.c | 20 ++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/ip/ip_common.h b/ip/ip_common.h index 8b0a6426..9eeeb387 100644 --- a/ip/ip_common.h +++ b/ip/ip_common.h @@ -57,6 +57,7 @@ int print_nexthop_bucket(struct nlmsghdr *n, void *arg); void netns_map_init(void); void netns_nsid_socket_init(void); int print_nsid(struct nlmsghdr *n, void *arg); +int ipstats_print(struct nlmsghdr *n, void *arg); char *get_name_from_nsid(int nsid); int get_netnsid_from_name(const char *name); int set_netnsid_from_name(const char *name, int nsid); diff --git a/ip/ipmonitor.c b/ip/ipmonitor.c index 0badda4e..a4326d2a 100644 --- a/ip/ipmonitor.c +++ b/ip/ipmonitor.c @@ -34,7 +34,7 @@ static void usage(void) "Usage: ip monitor [ all | OBJECTS ] [ FILE ] [ label ] [ all-nsid ]\n" " [ dev DEVICE ]\n" "OBJECTS := address | link | mroute | neigh | netconf |\n" - " nexthop | nsid | prefix | route | rule\n" + " nexthop | nsid | prefix | route | rule | stats\n" "FILE := file FILENAME\n"); exit(-1); } @@ -158,6 +158,11 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl, print_nsid(n, arg); return 0; + case RTM_NEWSTATS: + print_headers(fp, "[STATS]", ctrl); + ipstats_print(n, arg); + return 0; + case NLMSG_ERROR: case NLMSG_NOOP: case NLMSG_DONE: @@ -185,6 +190,7 @@ int do_ipmonitor(int argc, char **argv) int lprefix = 0; int lneigh = 0; int lnetconf = 0; + int lstats = 0; int lrule = 0; int lnsid = 0; int ifindex = 0; @@ -253,6 +259,9 @@ int do_ipmonitor(int argc, char **argv) } else if (matches(*argv, "nexthop") == 0) { lnexthop = 1; groups = 0; + } else if (strcmp(*argv, "stats") == 0) { + lstats = 1; + groups = 0; } else if (strcmp(*argv, "all") == 0) { prefix_banner = 1; } else if (matches(*argv, "all-nsid") == 0) { @@ -349,6 +358,11 @@ int do_ipmonitor(int argc, char **argv) exit(1); } + if (lstats && rtnl_add_nl_group(&rth, RTNLGRP_STATS) < 0) { + fprintf(stderr, "Failed to add stats group to list\n"); + exit(1); + } + if (listen_all_nsid && rtnl_listen_all_nsid(&rth) < 0) exit(1); diff --git a/ip/ipstats.c b/ip/ipstats.c index 29ca0731..39ddca01 100644 --- a/ip/ipstats.c +++ b/ip/ipstats.c @@ -1219,3 +1219,23 @@ int do_ipstats(int argc, char **argv) return rc; } + +int ipstats_print(struct nlmsghdr *n, void *arg) +{ + struct ipstats_stat_enabled_one one = { + .desc = &ipstats_stat_desc_offload_hw_s_info, + }; + struct ipstats_stat_enabled enabled = { + .enabled = &one, + .nenabled = 1, + }; + FILE *fp = arg; + int rc; + + rc = ipstats_process_ifsm(n, &enabled); + if (rc) + return rc; + + fflush(fp); + return 0; +} From patchwork Fri Apr 22 08:31:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12823078 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0042AC433FE for ; Fri, 22 Apr 2022 08:32:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445536AbiDVIe5 (ORCPT ); Fri, 22 Apr 2022 04:34:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445533AbiDVIeq (ORCPT ); Fri, 22 Apr 2022 04:34:46 -0400 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2060.outbound.protection.outlook.com [40.107.96.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56A4752E7B for ; Fri, 22 Apr 2022 01:31:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OP4kQZq/KO+kCEUEBUvdzeu0eRxBLgYyTgMZ3R+0vmOunMGf8zG9a09gHT3qEu0xYsnYINZKXtNsj9V9G1aUn6CRrCe5b810J/WMymmIhlaPx/18s/2xI6FKGyRa4X09hsyi+ZvuHDDfHi6OaBYayDbRp/BESaYDvpWNllyw2Fqh/ss1NFGr+x9W48erT0qSpHOmA46ctMbsL0jfHcmnk0tp1lXI0Mr6W99OVzXckK6J+5Tsx+hWKRIS3FpNiWfACAkgBsrgd2eyHHxBnG4Luo8nk8uc57ze+UUH8wW8O3bKdc93hTy0jCUyCTDyYnn0+soGpV4gRHawBGUKdIqb0g== 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=8MZaotlU4/qHIPhORc8Jz17PTSwXR6nwJyPkX4SyxpA=; b=G4gPO04hBB64+rIrv46Q8r10wtO+fMqsKB+eNnEj9CF3S5q4hboM70gGkXH90N0/mCJGSlGKKzQvjBlzFy17AGTqqp2sQsm3WQ3uHlfmrCtasPgTVOLIpjL83YEJvabLJTetvdrjfEGvWKTI2TOHn9lbjhHNaNyUPkFBbepJouVSXBvTkyTclzRoTri9eVGe4Se1+TEowxWp+xokiUaY04x3wzl36No7QnlkZe6fERCJeVCL83n4sSWvPqpevihwGeSS6BsseAGtQH36blKvI4uQjmSEJ/gJ6KI3uK2EHnkbkZuAiunGvcK7TmJWEG82wgslJva7iZsRGB/GWTlUpQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=networkplumber.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 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=8MZaotlU4/qHIPhORc8Jz17PTSwXR6nwJyPkX4SyxpA=; b=l5QbIX0QQgEVBDZtpe/CNGnR+FQgm927PniS0q7DI+xx9xtIyMki3+5wKLc8FppBkRjLIXBkC+Tk7uKw8NTykufy0Hy/KnOWxYmREilNoEpJFzIhjzKq+ZwgitD01BtTGqW9YqaKdFoykk5tL8N6zv4Ut5V3g0NjGcM9ZvWsdmDmAUJkj1Apm6/3cSakOY9mkjYed8ayf/mu2xGXQICytpO45aTVKiKHkzwMBPBQdVAfzdlf60HQx3ig3f/3zWK2uhV8omzLoteLK5ovQ+/q+d6PqhzfaqEmMj2pBgSPnDu89KbLB/a01opt6eu55uyEsnWeMgpHawzBYUOJc67iyw== Received: from DM6PR06CA0016.namprd06.prod.outlook.com (2603:10b6:5:120::29) by DM6PR12MB5022.namprd12.prod.outlook.com (2603:10b6:5:20e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.13; Fri, 22 Apr 2022 08:31:48 +0000 Received: from DM6NAM11FT022.eop-nam11.prod.protection.outlook.com (2603:10b6:5:120:cafe::ab) by DM6PR06CA0016.outlook.office365.com (2603:10b6:5:120::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14 via Frontend Transport; Fri, 22 Apr 2022 08:31:48 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) 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 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.235) by DM6NAM11FT022.mail.protection.outlook.com (10.13.172.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5186.14 via Frontend Transport; Fri, 22 Apr 2022 08:31:48 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 22 Apr 2022 08:31:48 +0000 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.986.22; Fri, 22 Apr 2022 01:31:46 -0700 From: Petr Machata To: CC: David Ahern , Stephen Hemminger , Ido Schimmel , Petr Machata Subject: [PATCH iproute2-next 11/11] man: Add man pages for the "stats" functions Date: Fri, 22 Apr 2022 10:31:00 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7e0d93bb-8e05-4941-0922-08da243a8b1a X-MS-TrafficTypeDiagnostic: DM6PR12MB5022:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mSV0PfrO7X45Sw4y5074sA/Kk6Ag973KU1UdCQJjxjkEe6c0wuGtIpSKMsYv7TluoBgv2ILviUH1dDp3a8jP+VCxCvHZN3YAFRtzL8LJtU1v1zv7I3X4KLEaKGiF+UIIDm/oS/nCrIM9v72yXsnUZ9PwtQIhvSXzxQkfwzBiDks/giNWUbTGNmQKmVq0FfkOnENysPDX4ePYQy91zFEEpWwkP9fgWxJx38JlKA8pXs5+rqInPWQeqPPVNWZH4u1L0rPLqd2c78jQu6wlQ10O1XDWeQY//k/f65QHRYuxVdgknGpwTArMgFYkDwfDcEfi87J/R1f7jNz7Fwtqtswgi3gv5sljcZ4/261zyKfAHzb3M8ph2ua7Rteklw3SI+n7FTmyzMJoxKJyEJzzj8B7QrHpQT7NVHD/ASNZbmaa/Jb9tnb1a6OP1fme43bvNgfvTKFu2ux8ka1kuwd9xEQV1BQc0sBAmOS5rVEg9B7zOlzZsKVBD2NNQrauSCEOxSM2jB31bdP1Mh1P9bbkmDiV5dR5ccbi51D+iDjPZOc+UnFgMjtmcs+A2nTWTzU9PBNtGcrt6+scx21WH/95SQguA+497IxyXjRnYBIcwr08SKjtL1eA3Kb6GV4ZLJsVBBrJFc2KDl65BIYwCrnez6r0p2xhCNpOhWNGVRfL+RWCQSQUcIJ0klPb4A5m8Ty+Y4+9/4cG2aZ0ErVzrGqt5YCZzQ== X-Forefront-Antispam-Report: CIP:12.22.5.235;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(36860700001)(47076005)(2906002)(83380400001)(426003)(26005)(82310400005)(316002)(336012)(36756003)(186003)(16526019)(107886003)(6916009)(2616005)(54906003)(8936002)(6666004)(8676002)(4326008)(81166007)(5660300002)(508600001)(86362001)(70206006)(70586007)(356005)(40460700003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2022 08:31:48.5538 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7e0d93bb-8e05-4941-0922-08da243a8b1a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.235];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT022.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB5022 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Add a man page for the new "stats" command. Also mention the new "stats" group in ip-monitor. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- man/man8/ip-monitor.8 | 2 +- man/man8/ip-stats.8 | 160 ++++++++++++++++++++++++++++++++++++++++++ man/man8/ip.8 | 7 +- 3 files changed, 167 insertions(+), 2 deletions(-) create mode 100644 man/man8/ip-stats.8 diff --git a/man/man8/ip-monitor.8 b/man/man8/ip-monitor.8 index f886d31b..ec033c69 100644 --- a/man/man8/ip-monitor.8 +++ b/man/man8/ip-monitor.8 @@ -55,7 +55,7 @@ command is the first in the command line and then the object list follows: is the list of object types that we want to monitor. It may contain .BR link ", " address ", " route ", " mroute ", " prefix ", " -.BR neigh ", " netconf ", " rule ", " nsid " and " nexthop "." +.BR neigh ", " netconf ", " rule ", " stats ", " nsid " and " nexthop "." If no .B file argument is given, diff --git a/man/man8/ip-stats.8 b/man/man8/ip-stats.8 new file mode 100644 index 00000000..7eaaf122 --- /dev/null +++ b/man/man8/ip-stats.8 @@ -0,0 +1,160 @@ +.TH IP\-STATS 8 "16 Mar 2022" "iproute2" "Linux" +.SH NAME +ip-stats \- manage and show interface statistics +.SH SYNOPSIS +.sp +.ad l +.in +8 +.ti -8 +.B ip +.B stats +.RI " { " COMMAND " | " +.BR help " }" +.sp + +.ti -8 +.BR "ip stats show" +.RB "[ " dev +.IR DEV " ] " +.RB "[ " group +.IR GROUP " [ " +.BI subgroup " SUBGROUP" +.R " ] ... ] ..." + +.ti -8 +.BR "ip stats set" +.BI dev " DEV" +.BR l3_stats " { " +.BR on " | " off " }" + +.SH DESCRIPTION + +.TP +.B ip stats set +is used for toggling whether a certain HW statistics suite is collected on +a given netdevice. The following statistics suites are supported: + +.in 21 + +.ti 14 +.B l3_stats +L3 stats reflect traffic that takes place in a HW device on an object that +corresponds to the given software netdevice. + +.TP +.B ip stats show +is used for showing stats on a given netdevice, or dumping statistics +across all netdevices. By default, all stats are requested. It is possible +to filter which stats are requested by using the +.B group +and +.B subgroup +keywords. + +It is possible to specify several groups, or several subgroups for one +group. When no subgroups are given for a group, all the subgroups are +requested. + +The following groups are recognized: +.in 21 + +.ti 14 +.B group link +- Link statistics. The same suite that "ip -s link show" shows. + +.ti 14 +.B group offload +- A group that contains a number of HW-oriented statistics. See below for +individual subgroups within this group. + +.TQ +.BR "group offload " subgroups: +.in 21 + +.ti 14 +.B subgroup cpu_hit +- The +.B cpu_hit +statistics suite is useful on hardware netdevices. The +.B link +statistics on these devices reflect both the hardware- and +software-datapath traffic. The +.B cpu_hit +statistics then only reflect software-datapath traffic. + +.ti 14 +.B subgroup hw_stats_info +- This suite does not include traffic statistics, but rather communicates +the state of other statistics. Through this subgroup, it is possible to +discover whether a given statistic was enabled, and when it was, whether +any device driver actually configured its device to collect these +statistics. For example, +.B l3_stats +was enabled in the following case, but no driver has installed it: + +# ip stats show dev swp1 group offload subgroup hw_stats_info +.br +56: swp1: group offload subgroup hw_stats_info +.br + l3_stats on used off + +After an L3 address is added to the netdevice, the counter will be +installed: + +# ip addr add dev swp1 192.0.2.1/28 +.br +# ip stats show dev swp1 group offload subgroup hw_stats_info +.br +56: swp1: group offload subgroup hw_stats_info +.br + l3_stats on used on + +.ti 14 +.B subgroup l3_stats +- These statistics reflect L3 traffic that takes place in HW on an object +that corresponds to the netdevice. Note that this suite is disabled by +default and needs to be first enabled through +.B ip stats set\fR. + +For example: + +# ip stats show dev swp2.200 group offload subgroup l3_stats +.br +112: swp2.200: group offload subgroup l3_stats on used on +.br + RX: bytes packets errors dropped mcast +.br + 8900 72 2 0 3 +.br + TX: bytes packets errors dropped +.br + 7176 58 0 0 + +Note how the l3_stats_info for the selected group is also part of the dump. + +.SH EXAMPLES +.PP +# ip stats set dev swp1 l3_stats on +.RS +Enables collection of L3 HW statistics on swp1. +.RE + +.PP +# ip stats show group offload +.RS +Shows all offload statistics on all netdevices. +.RE + +.PP +# ip stats show dev swp1 group link +.RS +Shows link statistics on the given netdevice. +.RE + +.SH SEE ALSO +.br +.BR ip (8), +.BR ip-link (8), + +.SH AUTHOR +Manpage by Petr Machata. diff --git a/man/man8/ip.8 b/man/man8/ip.8 index 2a4848b7..f6adbc77 100644 --- a/man/man8/ip.8 +++ b/man/man8/ip.8 @@ -22,7 +22,7 @@ ip \- show / manipulate routing, network devices, interfaces and tunnels .BR link " | " address " | " addrlabel " | " route " | " rule " | " neigh " | "\ ntable " | " tunnel " | " tuntap " | " maddress " | " mroute " | " mrule " | "\ monitor " | " xfrm " | " netns " | " l2tp " | " tcp_metrics " | " token " | "\ - macsec " | " vrf " | " mptcp " | " ioam " }" + macsec " | " vrf " | " mptcp " | " ioam " | " stats " }" .sp .ti -8 @@ -302,6 +302,10 @@ readability. .B rule - rule in routing policy database. +.TP +.B stats +- manage and show interface statistics. + .TP .B tcp_metrics/tcpmetrics - manage TCP Metrics @@ -419,6 +423,7 @@ was written by Alexey N. Kuznetsov and added in Linux 2.2. .BR ip-ntable (8), .BR ip-route (8), .BR ip-rule (8), +.BR ip-stats (8) .BR ip-tcp_metrics (8), .BR ip-token (8), .BR ip-tunnel (8),