From patchwork Mon Oct 19 21:32:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kubecek X-Patchwork-Id: 11845291 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59D94C433E7 for ; Mon, 19 Oct 2020 21:32:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 08DCC22282 for ; Mon, 19 Oct 2020 21:32:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733088AbgJSVcn (ORCPT ); Mon, 19 Oct 2020 17:32:43 -0400 Received: from mx2.suse.de ([195.135.220.15]:41422 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733061AbgJSVcm (ORCPT ); Mon, 19 Oct 2020 17:32:42 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 1F34FAC2F; Mon, 19 Oct 2020 21:32:41 +0000 (UTC) Received: by lion.mk-sys.cz (Postfix, from userid 1000) id DBFF860563; Mon, 19 Oct 2020 23:32:40 +0200 (CEST) Message-Id: In-Reply-To: References: From: Michal Kubecek Subject: [PATCH ethtool 1/4] netlink: support u32 enumerated types in pretty printing To: netdev@vger.kernel.org Cc: Jakub Kicinski Date: Mon, 19 Oct 2020 23:32:40 +0200 (CEST) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Some numeric attributes take values from a short list/range with symbolic names. Showing the symbolic names instead of numeric values will make the pretty printed netlink messages easier to read. If the value is too big for provided names array (e.g. running on newer kernel) or the name is omitted, numeric attribute value is shown. Signed-off-by: Michal Kubecek --- netlink/prettymsg.c | 9 +++++++++ netlink/prettymsg.h | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/netlink/prettymsg.c b/netlink/prettymsg.c index f992dcaf071f..d5d999fddfbb 100644 --- a/netlink/prettymsg.c +++ b/netlink/prettymsg.c @@ -137,6 +137,15 @@ static int pretty_print_attr(const struct nlattr *attr, case NLA_BOOL: printf("%s", mnl_attr_get_u8(attr) ? "on" : "off"); break; + case NLA_U32_ENUM: { + uint32_t val = mnl_attr_get_u32(attr); + + if (adesc && val < adesc->n_names && adesc->names[val]) + printf("%s", adesc->names[val]); + else + printf("%u", val); + break; + } default: if (alen <= __DUMP_LINE) __print_binary_short(adata, alen); diff --git a/netlink/prettymsg.h b/netlink/prettymsg.h index b5e5f735ac8a..6987c6ec5bca 100644 --- a/netlink/prettymsg.h +++ b/netlink/prettymsg.h @@ -28,13 +28,20 @@ enum pretty_nla_format { NLA_BOOL, NLA_NESTED, NLA_ARRAY, + NLA_U32_ENUM, }; struct pretty_nla_desc { enum pretty_nla_format format; const char *name; - const struct pretty_nla_desc *children; - unsigned int n_children; + union { + const struct pretty_nla_desc *children; + const char *const *names; + }; + union { + unsigned int n_children; + unsigned int n_names; + }; }; struct pretty_nlmsg_desc { @@ -81,6 +88,13 @@ struct pretty_nlmsg_desc { .children = __ ## _children_desc ## _desc, \ .n_children = 1, \ } +#define NLATTR_DESC_U32_ENUM(_name, _names_table) \ + [_name] = { \ + .format = NLA_U32_ENUM, \ + .name = #_name, \ + .names = __ ## _names_table ## _names, \ + .n_children = ARRAY_SIZE(__ ## _names_table ## _names), \ + } #define NLMSG_DESC(_name, _attrs) \ [_name] = { \ From patchwork Mon Oct 19 21:32:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kubecek X-Patchwork-Id: 11845289 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31D83C433DF for ; Mon, 19 Oct 2020 21:32:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CDC0B2224D for ; Mon, 19 Oct 2020 21:32:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733094AbgJSVcq (ORCPT ); Mon, 19 Oct 2020 17:32:46 -0400 Received: from mx2.suse.de ([195.135.220.15]:41452 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733061AbgJSVcp (ORCPT ); Mon, 19 Oct 2020 17:32:45 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 274ADAD11; Mon, 19 Oct 2020 21:32:44 +0000 (UTC) Received: by lion.mk-sys.cz (Postfix, from userid 1000) id E118760563; Mon, 19 Oct 2020 23:32:43 +0200 (CEST) Message-Id: <1193886b3994f75c86327b09e6e1a966413181e1.1603142897.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [PATCH ethtool 2/4] netlink: support 64-bit attribute types in pretty printed messages To: netdev@vger.kernel.org Cc: Jakub Kicinski Date: Mon, 19 Oct 2020 23:32:43 +0200 (CEST) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Add NLA_U64 (unsigned), NLA_X64 (unsigned, printed as hex) and NLA_S64 (signed) attribute types in pretty printing code. Signed-off-by: Michal Kubecek --- netlink/prettymsg.c | 10 ++++++++++ netlink/prettymsg.h | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/netlink/prettymsg.c b/netlink/prettymsg.c index d5d999fddfbb..0a1fae3da54e 100644 --- a/netlink/prettymsg.c +++ b/netlink/prettymsg.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -110,6 +111,9 @@ static int pretty_print_attr(const struct nlattr *attr, case NLA_U32: printf("%u", mnl_attr_get_u32(attr)); break; + case NLA_U64: + printf("%" PRIu64, mnl_attr_get_u64(attr)); + break; case NLA_X8: printf("0x%02x", mnl_attr_get_u8(attr)); break; @@ -119,6 +123,9 @@ static int pretty_print_attr(const struct nlattr *attr, case NLA_X32: printf("0x%08x", mnl_attr_get_u32(attr)); break; + case NLA_X64: + printf("%" PRIx64, mnl_attr_get_u64(attr)); + break; case NLA_S8: printf("%d", (int)mnl_attr_get_u8(attr)); break; @@ -128,6 +135,9 @@ static int pretty_print_attr(const struct nlattr *attr, case NLA_S32: printf("%d", (int)mnl_attr_get_u32(attr)); break; + case NLA_S64: + printf("%" PRId64, (int64_t)mnl_attr_get_u64(attr)); + break; case NLA_STRING: printf("\"%.*s\"", alen, (const char *)adata); break; diff --git a/netlink/prettymsg.h b/netlink/prettymsg.h index 6987c6ec5bca..25990cceffca 100644 --- a/netlink/prettymsg.h +++ b/netlink/prettymsg.h @@ -17,12 +17,15 @@ enum pretty_nla_format { NLA_U8, NLA_U16, NLA_U32, + NLA_U64, NLA_X8, NLA_X16, NLA_X32, + NLA_X64, NLA_S8, NLA_S16, NLA_S32, + NLA_S64, NLA_STRING, NLA_FLAG, NLA_BOOL, @@ -62,12 +65,15 @@ struct pretty_nlmsg_desc { #define NLATTR_DESC_U8(_name) NLATTR_DESC(_name, NLA_U8) #define NLATTR_DESC_U16(_name) NLATTR_DESC(_name, NLA_U16) #define NLATTR_DESC_U32(_name) NLATTR_DESC(_name, NLA_U32) +#define NLATTR_DESC_U64(_name) NLATTR_DESC(_name, NLA_U64) #define NLATTR_DESC_X8(_name) NLATTR_DESC(_name, NLA_X8) #define NLATTR_DESC_X16(_name) NLATTR_DESC(_name, NLA_X16) #define NLATTR_DESC_X32(_name) NLATTR_DESC(_name, NLA_X32) +#define NLATTR_DESC_X64(_name) NLATTR_DESC(_name, NLA_X64) #define NLATTR_DESC_S8(_name) NLATTR_DESC(_name, NLA_U8) #define NLATTR_DESC_S16(_name) NLATTR_DESC(_name, NLA_U16) #define NLATTR_DESC_S32(_name) NLATTR_DESC(_name, NLA_U32) +#define NLATTR_DESC_S64(_name) NLATTR_DESC(_name, NLA_S64) #define NLATTR_DESC_STRING(_name) NLATTR_DESC(_name, NLA_STRING) #define NLATTR_DESC_FLAG(_name) NLATTR_DESC(_name, NLA_FLAG) #define NLATTR_DESC_BOOL(_name) NLATTR_DESC(_name, NLA_BOOL) From patchwork Mon Oct 19 21:32:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kubecek X-Patchwork-Id: 11845295 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,UPPERCASE_50_75,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BE2CC433DF for ; Mon, 19 Oct 2020 21:32:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 247A122282 for ; Mon, 19 Oct 2020 21:32:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733100AbgJSVct (ORCPT ); Mon, 19 Oct 2020 17:32:49 -0400 Received: from mx2.suse.de ([195.135.220.15]:41494 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733061AbgJSVcs (ORCPT ); Mon, 19 Oct 2020 17:32:48 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 2995CAC2F; Mon, 19 Oct 2020 21:32:47 +0000 (UTC) Received: by lion.mk-sys.cz (Postfix, from userid 1000) id E572560563; Mon, 19 Oct 2020 23:32:46 +0200 (CEST) Message-Id: <95db276533bc46dca9337a7aa37a85b7f846741f.1603142897.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [PATCH ethtool 3/4] netlink: add descriptions for genetlink policy dumps To: netdev@vger.kernel.org Cc: Jakub Kicinski Date: Mon, 19 Oct 2020 23:32:46 +0200 (CEST) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Add GENL_ID_CTRL message descriptions for messages and attributes used for policy dumps. Signed-off-by: Michal Kubecek --- netlink/desc-genlctrl.c | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/netlink/desc-genlctrl.c b/netlink/desc-genlctrl.c index 9840179b0a1a..43b41ab395b8 100644 --- a/netlink/desc-genlctrl.c +++ b/netlink/desc-genlctrl.c @@ -29,6 +29,59 @@ static const struct pretty_nla_desc __mcgrps_desc[] = { NLATTR_DESC_NESTED(0, mcgrp), }; +static const char *__policy_attr_type_names[] = { + [NL_ATTR_TYPE_INVALID] = "NL_ATTR_TYPE_INVALID", + [NL_ATTR_TYPE_FLAG] = "NL_ATTR_TYPE_FLAG", + [NL_ATTR_TYPE_U8] = "NL_ATTR_TYPE_U8", + [NL_ATTR_TYPE_U16] = "NL_ATTR_TYPE_U16", + [NL_ATTR_TYPE_U32] = "NL_ATTR_TYPE_U32", + [NL_ATTR_TYPE_U64] = "NL_ATTR_TYPE_U64", + [NL_ATTR_TYPE_S8] = "NL_ATTR_TYPE_S8", + [NL_ATTR_TYPE_S16] = "NL_ATTR_TYPE_S16", + [NL_ATTR_TYPE_S32] = "NL_ATTR_TYPE_S32", + [NL_ATTR_TYPE_S64] = "NL_ATTR_TYPE_S64", + [NL_ATTR_TYPE_BINARY] = "NL_ATTR_TYPE_BINARY", + [NL_ATTR_TYPE_STRING] = "NL_ATTR_TYPE_STRING", + [NL_ATTR_TYPE_NUL_STRING] = "NL_ATTR_TYPE_NUL_STRING", + [NL_ATTR_TYPE_NESTED] = "NL_ATTR_TYPE_NESTED", + [NL_ATTR_TYPE_NESTED_ARRAY] = "NL_ATTR_TYPE_NESTED_ARRAY", + [NL_ATTR_TYPE_BITFIELD32] = "NL_ATTR_TYPE_BITFIELD32", +}; + +static const struct pretty_nla_desc __policy_attr_desc[] = { + NLATTR_DESC_INVALID(NL_POLICY_TYPE_ATTR_UNSPEC), + NLATTR_DESC_U32_ENUM(NL_POLICY_TYPE_ATTR_TYPE, policy_attr_type), + NLATTR_DESC_S64(NL_POLICY_TYPE_ATTR_MIN_VALUE_S), + NLATTR_DESC_S64(NL_POLICY_TYPE_ATTR_MAX_VALUE_S), + NLATTR_DESC_U64(NL_POLICY_TYPE_ATTR_MIN_VALUE_U), + NLATTR_DESC_U64(NL_POLICY_TYPE_ATTR_MAX_VALUE_U), + NLATTR_DESC_U32(NL_POLICY_TYPE_ATTR_MIN_LENGTH), + NLATTR_DESC_U32(NL_POLICY_TYPE_ATTR_MAX_LENGTH), + NLATTR_DESC_U32(NL_POLICY_TYPE_ATTR_POLICY_IDX), + NLATTR_DESC_U32(NL_POLICY_TYPE_ATTR_POLICY_MAXTYPE), + NLATTR_DESC_X32(NL_POLICY_TYPE_ATTR_BITFIELD32_MASK), + NLATTR_DESC_X64(NL_POLICY_TYPE_ATTR_PAD), + NLATTR_DESC_BINARY(NL_POLICY_TYPE_ATTR_MASK), +}; + +static const struct pretty_nla_desc __policy_attrs_desc[] = { + NLATTR_DESC_NESTED(0, policy_attr), +}; + +static const struct pretty_nla_desc __policies_desc[] = { + NLATTR_DESC_ARRAY(0, policy_attrs), +}; + +static const struct pretty_nla_desc __op_policy_desc[] = { + NLATTR_DESC_INVALID(CTRL_ATTR_POLICY_UNSPEC), + NLATTR_DESC_U32(CTRL_ATTR_POLICY_DO), + NLATTR_DESC_U32(CTRL_ATTR_POLICY_DUMP), +}; + +static const struct pretty_nla_desc __op_policies_desc[] = { + NLATTR_DESC_NESTED(0, op_policy), +}; + static const struct pretty_nla_desc __attr_desc[] = { NLATTR_DESC_INVALID(CTRL_ATTR_UNSPEC), NLATTR_DESC_U16(CTRL_ATTR_FAMILY_ID), @@ -38,6 +91,9 @@ static const struct pretty_nla_desc __attr_desc[] = { NLATTR_DESC_U32(CTRL_ATTR_MAXATTR), NLATTR_DESC_ARRAY(CTRL_ATTR_OPS, attrops), NLATTR_DESC_ARRAY(CTRL_ATTR_MCAST_GROUPS, mcgrps), + NLATTR_DESC_ARRAY(CTRL_ATTR_POLICY, policies), + NLATTR_DESC_ARRAY(CTRL_ATTR_OP_POLICY, op_policies), + NLATTR_DESC_U32(CTRL_ATTR_OP), }; const struct pretty_nlmsg_desc genlctrl_msg_desc[] = { @@ -51,6 +107,7 @@ const struct pretty_nlmsg_desc genlctrl_msg_desc[] = { NLMSG_DESC(CTRL_CMD_NEWMCAST_GRP, attr), NLMSG_DESC(CTRL_CMD_DELMCAST_GRP, attr), NLMSG_DESC(CTRL_CMD_GETMCAST_GRP, attr), + NLMSG_DESC(CTRL_CMD_GETPOLICY, attr), }; const unsigned int genlctrl_msg_n_desc = ARRAY_SIZE(genlctrl_msg_desc); From patchwork Mon Oct 19 21:32:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kubecek X-Patchwork-Id: 11845293 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4FB8C433E7 for ; Mon, 19 Oct 2020 21:32:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AD0772231B for ; Mon, 19 Oct 2020 21:32:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733107AbgJSVcv (ORCPT ); Mon, 19 Oct 2020 17:32:51 -0400 Received: from mx2.suse.de ([195.135.220.15]:41570 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733061AbgJSVcv (ORCPT ); Mon, 19 Oct 2020 17:32:51 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 2FF44AE07; Mon, 19 Oct 2020 21:32:50 +0000 (UTC) Received: by lion.mk-sys.cz (Postfix, from userid 1000) id EAB8060563; Mon, 19 Oct 2020 23:32:49 +0200 (CEST) Message-Id: <1e3546d7f774db109f77c465e3d1f838ab7d169d.1603142897.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [PATCH ethtool 4/4] netlink: add message descriptions for pause stats To: netdev@vger.kernel.org Cc: Jakub Kicinski Date: Mon, 19 Oct 2020 23:32:49 +0200 (CEST) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Add message descriptions for pretty printing of new attributes used for pause statistics. Signed-off-by: Michal Kubecek --- netlink/desc-ethtool.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/netlink/desc-ethtool.c b/netlink/desc-ethtool.c index ee8fc4796987..96291b9bdd3b 100644 --- a/netlink/desc-ethtool.c +++ b/netlink/desc-ethtool.c @@ -180,12 +180,19 @@ static const struct pretty_nla_desc __coalesce_desc[] = { NLATTR_DESC_U32(ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL), }; +static const struct pretty_nla_desc __pause_stats_desc[] = { + NLATTR_DESC_BINARY(ETHTOOL_A_PAUSE_STAT_PAD), + NLATTR_DESC_U64(ETHTOOL_A_PAUSE_STAT_TX_FRAMES), + NLATTR_DESC_U64(ETHTOOL_A_PAUSE_STAT_RX_FRAMES), +}; + static const struct pretty_nla_desc __pause_desc[] = { NLATTR_DESC_INVALID(ETHTOOL_A_PAUSE_UNSPEC), NLATTR_DESC_NESTED(ETHTOOL_A_PAUSE_HEADER, header), NLATTR_DESC_BOOL(ETHTOOL_A_PAUSE_AUTONEG), NLATTR_DESC_BOOL(ETHTOOL_A_PAUSE_RX), NLATTR_DESC_BOOL(ETHTOOL_A_PAUSE_TX), + NLATTR_DESC_NESTED(ETHTOOL_A_PAUSE_STATS, pause_stats), }; static const struct pretty_nla_desc __eee_desc[] = {