From patchwork Sun Jul 7 08:01:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 1128594 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=idosch.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="Zpca2iQA"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45hLfN2yzxz9s4Y for ; Sun, 7 Jul 2019 18:02:36 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727203AbfGGICf (ORCPT ); Sun, 7 Jul 2019 04:02:35 -0400 Received: from new2-smtp.messagingengine.com ([66.111.4.224]:39163 "EHLO new2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726330AbfGGICe (ORCPT ); Sun, 7 Jul 2019 04:02:34 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailnew.nyi.internal (Postfix) with ESMTP id B2ADD17A0; Sun, 7 Jul 2019 04:02:33 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sun, 07 Jul 2019 04:02:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=Q7wc9bBhpjPTUHTBCbLesY1u7y12kUCiM4Uds7evRCY=; b=Zpca2iQA uzru5rCuKrQ84idgBRvFDUr6b8gwNgKVgORmfuDJNyAOATxS9mA1tzeDIPxPIeSV x05O191pHUJrXrPjd2QuQXUR/XRghEY2qCIrcyCdW5N0kvjtr1TdjnoXILYQaa28 h0/ZsQO1sE8XunR5yaGFiw3JVS2NYIT0xkdUxjoG2zAPeW3P4BlVe9SBmYjjqaYw MQC+/p+UFXPXqW85fOw1P0Y8n3UAeGV3EPjA2cyvS4h24GDWkVqotjtzigzedTBn /cVBfV81t4pApqJ7o28erC3Stc/6WfpC/CkDIIfjRIow6QvE4VSnpMl48yI6VUTb nbOURC3sdiTilw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrfeejgdduvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepkfguohcuufgthhhimhhmvghluceoihguohhstghhsehiugho shgthhdrohhrgheqnecukfhppeduleefrdegjedrudeihedrvdehudenucfrrghrrghmpe hmrghilhhfrhhomhepihguohhstghhsehiughoshgthhdrohhrghenucevlhhushhtvghr ufhiiigvpedt X-ME-Proxy: Received: from splinter.mtl.com (unknown [193.47.165.251]) by mail.messagingengine.com (Postfix) with ESMTPA id 3F2B38005B; Sun, 7 Jul 2019 04:02:31 -0400 (EDT) From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, jiri@mellanox.com, mlxsw@mellanox.com, dsahern@gmail.com, roopa@cumulusnetworks.com, nikolay@cumulusnetworks.com, andy@greyhouse.net, pablo@netfilter.org, jakub.kicinski@netronome.com, pieter.jansenvanvuuren@netronome.com, andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com, Ido Schimmel Subject: [PATCH iproute2-next 1/7] devlink: Increase number of supported options Date: Sun, 7 Jul 2019 11:01:54 +0300 Message-Id: <20190707080200.3699-2-idosch@idosch.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190707080200.3699-1-idosch@idosch.org> References: <20190707075828.3315-1-idosch@idosch.org> <20190707080200.3699-1-idosch@idosch.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Ido Schimmel Currently, the number of supported options is capped at 32 which is a problem given we are about to add a few more and go over the limit. Increase the limit to 64 options. Signed-off-by: Ido Schimmel Acked-by: Jiri Pirko --- devlink/devlink.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/devlink/devlink.c b/devlink/devlink.c index 559f624e3666..f631c8241a24 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -213,7 +213,7 @@ static void ifname_map_free(struct ifname_map *ifname_map) #define DL_OPT_HEALTH_REPORTER_AUTO_RECOVER BIT(28) struct dl_opts { - uint32_t present; /* flags of present items */ + uint64_t present; /* flags of present items */ char *bus_name; char *dev_name; uint32_t port_index; @@ -713,7 +713,7 @@ static int dl_argv_handle_port(struct dl *dl, char **p_bus_name, static int dl_argv_handle_both(struct dl *dl, char **p_bus_name, char **p_dev_name, uint32_t *p_port_index, - uint32_t *p_handle_bit) + uint64_t *p_handle_bit) { char *str = dl_argv_next(dl); unsigned int slash_count; @@ -993,7 +993,7 @@ static int param_cmode_get(const char *cmodestr, } struct dl_args_metadata { - uint32_t o_flag; + uint64_t o_flag; char err_msg[DL_ARGS_REQUIRED_MAX_ERR_LEN]; }; @@ -1020,10 +1020,10 @@ static const struct dl_args_metadata dl_args_required[] = { {DL_OPT_HEALTH_REPORTER_NAME, "Reporter's name is expected."}, }; -static int dl_args_finding_required_validate(uint32_t o_required, - uint32_t o_found) +static int dl_args_finding_required_validate(uint64_t o_required, + uint64_t o_found) { - uint32_t o_flag; + uint64_t o_flag; int i; for (i = 0; i < ARRAY_SIZE(dl_args_required); i++) { @@ -1036,16 +1036,16 @@ static int dl_args_finding_required_validate(uint32_t o_required, return 0; } -static int dl_argv_parse(struct dl *dl, uint32_t o_required, - uint32_t o_optional) +static int dl_argv_parse(struct dl *dl, uint64_t o_required, + uint64_t o_optional) { struct dl_opts *opts = &dl->opts; - uint32_t o_all = o_required | o_optional; - uint32_t o_found = 0; + uint64_t o_all = o_required | o_optional; + uint64_t o_found = 0; int err; if (o_required & DL_OPT_HANDLE && o_required & DL_OPT_HANDLEP) { - uint32_t handle_bit; + uint64_t handle_bit; err = dl_argv_handle_both(dl, &opts->bus_name, &opts->dev_name, &opts->port_index, &handle_bit); @@ -1424,7 +1424,7 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl) } static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl, - uint32_t o_required, uint32_t o_optional) + uint64_t o_required, uint64_t o_optional) { int err; From patchwork Sun Jul 7 08:01:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 1128595 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=idosch.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="TgHtIs3h"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45hLfR2HG4z9s4Y for ; Sun, 7 Jul 2019 18:02:39 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727235AbfGGICi (ORCPT ); Sun, 7 Jul 2019 04:02:38 -0400 Received: from new2-smtp.messagingengine.com ([66.111.4.224]:39235 "EHLO new2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726330AbfGGICh (ORCPT ); Sun, 7 Jul 2019 04:02:37 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailnew.nyi.internal (Postfix) with ESMTP id 736861926; Sun, 7 Jul 2019 04:02:36 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sun, 07 Jul 2019 04:02:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=LzUF6S9Iz3JG9oaFyw/Tx70hQ/V1ZJ82bbNQYWU9sPY=; b=TgHtIs3h 6SKqs3PZEozTLHGvRW8x6FkWgD9Ceh6OR3HweVe7G0VaMiywHWSHZfPLRrXhXkRM A+bhj+t0vhR7xIx5lMa/IRF4aQKdflgc4v50q9pdQOhUoXMbf1tFR1LniCk1ksOz yvWPMusONrgtHEQR+HNLZGcbIgh2INNefqhxiMXLanV1hEYGymgMH4N5WY3R2SjM fFjN3K6k72zHHx4yW91A/mk+iNE7x2XFKI4rVCMQwiPeM3iygQkPTFgbKQBMuY7u AJ309TnneyVhV4ftX77MlddftgApJPFx+LQIS6DRwCydjszCA2gpQlMT8diYwVpN 7TeRbZn/uY00vA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrfeejgdduvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepkfguohcuufgthhhimhhmvghluceoihguohhstghhsehiugho shgthhdrohhrgheqnecukfhppeduleefrdegjedrudeihedrvdehudenucfrrghrrghmpe hmrghilhhfrhhomhepihguohhstghhsehiughoshgthhdrohhrghenucevlhhushhtvghr ufhiiigvpedt X-ME-Proxy: Received: from splinter.mtl.com (unknown [193.47.165.251]) by mail.messagingengine.com (Postfix) with ESMTPA id C07858005A; Sun, 7 Jul 2019 04:02:33 -0400 (EDT) From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, jiri@mellanox.com, mlxsw@mellanox.com, dsahern@gmail.com, roopa@cumulusnetworks.com, nikolay@cumulusnetworks.com, andy@greyhouse.net, pablo@netfilter.org, jakub.kicinski@netronome.com, pieter.jansenvanvuuren@netronome.com, andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com, Ido Schimmel Subject: [PATCH iproute2-next 2/7] devlink: Add devlink trap set and show commands Date: Sun, 7 Jul 2019 11:01:55 +0300 Message-Id: <20190707080200.3699-3-idosch@idosch.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190707080200.3699-1-idosch@idosch.org> References: <20190707075828.3315-1-idosch@idosch.org> <20190707080200.3699-1-idosch@idosch.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Ido Schimmel The trap set command allows the user to set the action and reporting state of an individual trap. Example: # devlink trap set netdevsim/netdevsim10 trap blackhole_route action trap report true The trap show command allows the user to get the current status of an individual trap or a dump of all traps in case one is not specified. When '-s' is specified the trap's statistics are shown. When '-v' is specified the metadata types the trap can provide are shown. Example: # devlink -jvps trap show netdevsim/netdevsim10 trap blackhole_route { "trap": { "netdevsim/netdevsim10": [ { "name": "blackhole_route", "type": "drop", "generic": true, "report": true, "action": "trap", "group": "l3_drops", "metadata": [ "input_port" ], "stats": { "rx": { "bytes": 0, "packets": 0 } } } ] } } Signed-off-by: Ido Schimmel Acked-by: Jiri Pirko --- devlink/devlink.c | 313 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 308 insertions(+), 5 deletions(-) diff --git a/devlink/devlink.c b/devlink/devlink.c index f631c8241a24..90f41cbd2a9c 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -211,6 +211,9 @@ static void ifname_map_free(struct ifname_map *ifname_map) #define DL_OPT_HEALTH_REPORTER_NAME BIT(27) #define DL_OPT_HEALTH_REPORTER_GRACEFUL_PERIOD BIT(27) #define DL_OPT_HEALTH_REPORTER_AUTO_RECOVER BIT(28) +#define DL_OPT_TRAP_NAME BIT(29) +#define DL_OPT_TRAP_REPORT BIT(30) +#define DL_OPT_TRAP_ACTION BIT(31) struct dl_opts { uint64_t present; /* flags of present items */ @@ -247,6 +250,9 @@ struct dl_opts { const char *reporter_name; uint64_t reporter_graceful_period; bool reporter_auto_recover; + const char *trap_name; + bool trap_report; + enum devlink_trap_action trap_action; }; struct dl { @@ -260,6 +266,7 @@ struct dl { bool json_output; bool pretty_output; bool verbose; + bool stats; struct { bool present; char *bus_name; @@ -414,6 +421,22 @@ static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = { [DEVLINK_ATTR_HEALTH_REPORTER_RECOVER_COUNT] = MNL_TYPE_U64, [DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS] = MNL_TYPE_U64, [DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD] = MNL_TYPE_U64, + [DEVLINK_ATTR_STATS] = MNL_TYPE_NESTED, + [DEVLINK_ATTR_TRAP_NAME] = MNL_TYPE_STRING, + [DEVLINK_ATTR_TRAP_REPORT_ENABLED] = MNL_TYPE_U8, + [DEVLINK_ATTR_TRAP_ACTION] = MNL_TYPE_U8, + [DEVLINK_ATTR_TRAP_TYPE] = MNL_TYPE_U8, + [DEVLINK_ATTR_TRAP_GENERIC] = MNL_TYPE_FLAG, + [DEVLINK_ATTR_TRAP_METADATA] = MNL_TYPE_NESTED, + [DEVLINK_ATTR_TRAP_TIMESTAMP] = MNL_TYPE_BINARY, + [DEVLINK_ATTR_TRAP_IN_PORT] = MNL_TYPE_NESTED, + [DEVLINK_ATTR_TRAP_GROUP_NAME] = MNL_TYPE_STRING, +}; + +static const enum mnl_attr_data_type +devlink_stats_policy[DEVLINK_ATTR_STATS_MAX + 1] = { + [DEVLINK_ATTR_STATS_RX_PACKETS] = MNL_TYPE_U64, + [DEVLINK_ATTR_STATS_RX_BYTES] = MNL_TYPE_U64, }; static int attr_cb(const struct nlattr *attr, void *data) @@ -432,6 +455,25 @@ static int attr_cb(const struct nlattr *attr, void *data) return MNL_CB_OK; } +static int attr_stats_cb(const struct nlattr *attr, void *data) +{ + const struct nlattr **tb = data; + int type; + + /* Allow the tool to work on top of newer kernels that might contain + * more attributes. + */ + if (mnl_attr_type_valid(attr, DEVLINK_ATTR_STATS_MAX) < 0) + return MNL_CB_OK; + + type = mnl_attr_get_type(attr); + if (mnl_attr_validate(attr, devlink_stats_policy[type]) < 0) + return MNL_CB_ERROR; + + tb[type] = attr; + return MNL_CB_OK; +} + static int ifname_map_cb(const struct nlmsghdr *nlh, void *data) { struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {}; @@ -992,6 +1034,20 @@ static int param_cmode_get(const char *cmodestr, return 0; } +static int trap_action_get(const char *actionstr, + enum devlink_trap_action *p_action) +{ + if (strcmp(actionstr, "drop") == 0) { + *p_action = DEVLINK_TRAP_ACTION_DROP; + } else if (strcmp(actionstr, "trap") == 0) { + *p_action = DEVLINK_TRAP_ACTION_TRAP; + } else { + pr_err("Unknown trap action \"%s\"\n", actionstr); + return -EINVAL; + } + return 0; +} + struct dl_args_metadata { uint64_t o_flag; char err_msg[DL_ARGS_REQUIRED_MAX_ERR_LEN]; @@ -1018,6 +1074,7 @@ static const struct dl_args_metadata dl_args_required[] = { {DL_OPT_REGION_ADDRESS, "Region address value expected."}, {DL_OPT_REGION_LENGTH, "Region length value expected."}, {DL_OPT_HEALTH_REPORTER_NAME, "Reporter's name is expected."}, + {DL_OPT_TRAP_NAME, "Trap's name is expected."}, }; static int dl_args_finding_required_validate(uint64_t o_required, @@ -1307,6 +1364,32 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required, if (err) return err; o_found |= DL_OPT_HEALTH_REPORTER_AUTO_RECOVER; + } else if (dl_argv_match(dl, "trap") && + (o_all & DL_OPT_TRAP_NAME)) { + dl_arg_inc(dl); + err = dl_argv_str(dl, &opts->trap_name); + if (err) + return err; + o_found |= DL_OPT_TRAP_NAME; + } else if (dl_argv_match(dl, "report") && + (o_all & DL_OPT_TRAP_REPORT)) { + dl_arg_inc(dl); + err = dl_argv_bool(dl, &opts->trap_report); + if (err) + return err; + o_found |= DL_OPT_TRAP_REPORT; + } else if (dl_argv_match(dl, "action") && + (o_all & DL_OPT_TRAP_ACTION)) { + const char *actionstr; + + dl_arg_inc(dl); + err = dl_argv_str(dl, &actionstr); + if (err) + return err; + err = trap_action_get(actionstr, &opts->trap_action); + if (err) + return err; + o_found |= DL_OPT_TRAP_ACTION; } else { pr_err("Unknown option \"%s\"\n", dl_argv(dl)); return -EINVAL; @@ -1420,6 +1503,15 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl) if (opts->present & DL_OPT_HEALTH_REPORTER_AUTO_RECOVER) mnl_attr_put_u8(nlh, DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER, opts->reporter_auto_recover); + if (opts->present & DL_OPT_TRAP_NAME) + mnl_attr_put_strz(nlh, DEVLINK_ATTR_TRAP_NAME, + opts->trap_name); + if (opts->present & DL_OPT_TRAP_REPORT) + mnl_attr_put_u8(nlh, DEVLINK_ATTR_TRAP_REPORT_ENABLED, + opts->trap_report); + if (opts->present & DL_OPT_TRAP_ACTION) + mnl_attr_put_u8(nlh, DEVLINK_ATTR_TRAP_ACTION, + opts->trap_action); } @@ -1926,6 +2018,30 @@ static void pr_out_entry_end(struct dl *dl) __pr_out_newline(); } +static void pr_out_stats(struct dl *dl, struct nlattr *nla_stats) +{ + struct nlattr *tb[DEVLINK_ATTR_STATS_MAX + 1] = {}; + int err; + + if (!dl->stats) + return; + + err = mnl_attr_parse_nested(nla_stats, attr_stats_cb, tb); + if (err != MNL_CB_OK) + return; + + pr_out_object_start(dl, "stats"); + pr_out_object_start(dl, "rx"); + if (tb[DEVLINK_ATTR_STATS_RX_BYTES]) + pr_out_u64(dl, "bytes", + mnl_attr_get_u64(tb[DEVLINK_ATTR_STATS_RX_BYTES])); + if (tb[DEVLINK_ATTR_STATS_RX_PACKETS]) + pr_out_u64(dl, "packets", + mnl_attr_get_u64(tb[DEVLINK_ATTR_STATS_RX_PACKETS])); + pr_out_object_end(dl); + pr_out_object_end(dl); +} + static const char *param_cmode_name(uint8_t cmode) { switch (cmode) { @@ -3712,6 +3828,10 @@ static const char *cmd_name(uint8_t cmd) case DEVLINK_CMD_REGION_SET: return "set"; case DEVLINK_CMD_REGION_NEW: return "new"; case DEVLINK_CMD_REGION_DEL: return "del"; + case DEVLINK_CMD_TRAP_GET: return "get"; + case DEVLINK_CMD_TRAP_SET: return "set"; + case DEVLINK_CMD_TRAP_NEW: return "new"; + case DEVLINK_CMD_TRAP_DEL: return "del"; default: return ""; } } @@ -3740,6 +3860,11 @@ static const char *cmd_obj(uint8_t cmd) case DEVLINK_CMD_REGION_NEW: case DEVLINK_CMD_REGION_DEL: return "region"; + case DEVLINK_CMD_TRAP_GET: + case DEVLINK_CMD_TRAP_SET: + case DEVLINK_CMD_TRAP_NEW: + case DEVLINK_CMD_TRAP_DEL: + return "trap"; default: return ""; } } @@ -3765,6 +3890,7 @@ static bool cmd_filter_check(struct dl *dl, uint8_t cmd) } static void pr_out_region(struct dl *dl, struct nlattr **tb); +static void pr_out_trap(struct dl *dl, struct nlattr **tb, bool array); static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data) { @@ -3820,6 +3946,23 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data) pr_out_mon_header(genl->cmd); pr_out_region(dl, tb); break; + case DEVLINK_CMD_TRAP_GET: /* fall through */ + case DEVLINK_CMD_TRAP_SET: /* fall through */ + case DEVLINK_CMD_TRAP_NEW: /* fall through */ + case DEVLINK_CMD_TRAP_DEL: + mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb); + if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] || + !tb[DEVLINK_ATTR_TRAP_NAME] || + !tb[DEVLINK_ATTR_TRAP_TYPE] || + !tb[DEVLINK_ATTR_TRAP_REPORT_ENABLED] || + !tb[DEVLINK_ATTR_TRAP_ACTION] || + !tb[DEVLINK_ATTR_TRAP_GROUP_NAME] || + !tb[DEVLINK_ATTR_TRAP_METADATA] || + !tb[DEVLINK_ATTR_STATS]) + return MNL_CB_ERROR; + pr_out_mon_header(genl->cmd); + pr_out_trap(dl, tb, false); + break; } return MNL_CB_OK; } @@ -3833,7 +3976,8 @@ static int cmd_mon_show(struct dl *dl) while ((cur_obj = dl_argv_index(dl, index++))) { if (strcmp(cur_obj, "all") != 0 && strcmp(cur_obj, "dev") != 0 && - strcmp(cur_obj, "port") != 0) { + strcmp(cur_obj, "port") != 0 && + strcmp(cur_obj, "trap") != 0) { pr_err("Unknown object \"%s\"\n", cur_obj); return -EINVAL; } @@ -3850,7 +3994,7 @@ static int cmd_mon_show(struct dl *dl) static void cmd_mon_help(void) { pr_err("Usage: devlink monitor [ all | OBJECT-LIST ]\n" - "where OBJECT-LIST := { dev | port }\n"); + "where OBJECT-LIST := { dev | port | trap }\n"); } static int cmd_mon(struct dl *dl) @@ -6273,12 +6417,164 @@ static int cmd_health(struct dl *dl) return -ENOENT; } +static const char *trap_type_name(uint8_t type) +{ + switch (type) { + case DEVLINK_TRAP_TYPE_DROP: + return "drop"; + case DEVLINK_TRAP_TYPE_EXCEPTION: + return "exception"; + default: + return ""; + } +} + +static const char *trap_action_name(uint8_t action) +{ + switch (action) { + case DEVLINK_TRAP_ACTION_DROP: + return "drop"; + case DEVLINK_TRAP_ACTION_TRAP: + return "trap"; + default: + return ""; + } +} + +static const char *trap_metadata_name(const struct nlattr *attr) +{ + switch (attr->nla_type) { + case DEVLINK_ATTR_TRAP_METADATA_TYPE_IN_PORT: + return "input_port"; + default: + return ""; + } +} +static void pr_out_trap_metadata(struct dl *dl, struct nlattr *attr) +{ + struct nlattr *attr_metadata; + + pr_out_array_start(dl, "metadata"); + mnl_attr_for_each_nested(attr_metadata, attr) + pr_out_str_value(dl, trap_metadata_name(attr_metadata)); + pr_out_array_end(dl); +} + +static void pr_out_trap(struct dl *dl, struct nlattr **tb, bool array) +{ + uint8_t action = mnl_attr_get_u8(tb[DEVLINK_ATTR_TRAP_ACTION]); + uint8_t type = mnl_attr_get_u8(tb[DEVLINK_ATTR_TRAP_TYPE]); + + if (array) + pr_out_handle_start_arr(dl, tb); + else + __pr_out_handle_start(dl, tb, true, false); + + pr_out_str(dl, "name", mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_NAME])); + pr_out_str(dl, "type", trap_type_name(type)); + pr_out_bool(dl, "generic", !!tb[DEVLINK_ATTR_TRAP_GENERIC]); + pr_out_bool(dl, "report", + !!mnl_attr_get_u8(tb[DEVLINK_ATTR_TRAP_REPORT_ENABLED])); + pr_out_str(dl, "action", trap_action_name(action)); + pr_out_str(dl, "group", + mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_GROUP_NAME])); + if (dl->verbose) + pr_out_trap_metadata(dl, tb[DEVLINK_ATTR_TRAP_METADATA]); + pr_out_stats(dl, tb[DEVLINK_ATTR_STATS]); + pr_out_handle_end(dl); +} + +static int cmd_trap_show_cb(const struct nlmsghdr *nlh, void *data) +{ + struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh); + struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {}; + struct dl *dl = data; + + mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb); + if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] || + !tb[DEVLINK_ATTR_TRAP_NAME] || !tb[DEVLINK_ATTR_TRAP_TYPE] || + !tb[DEVLINK_ATTR_TRAP_REPORT_ENABLED] || + !tb[DEVLINK_ATTR_TRAP_ACTION] || + !tb[DEVLINK_ATTR_TRAP_GROUP_NAME] || + !tb[DEVLINK_ATTR_TRAP_METADATA] || !tb[DEVLINK_ATTR_STATS]) + return MNL_CB_ERROR; + + pr_out_trap(dl, tb, true); + + return MNL_CB_OK; +} + +static void cmd_trap_help(void) +{ + pr_err("Usage: devlink trap set DEV trap TRAP [ report { true | false } ]\n"); + pr_err(" [ action { trap | drop } ]\n"); + pr_err(" devlink trap show [ DEV trap TRAP ]\n"); +} + +static int cmd_trap_show(struct dl *dl) +{ + uint16_t flags = NLM_F_REQUEST | NLM_F_ACK; + struct nlmsghdr *nlh; + int err; + + if (dl_argc(dl) == 0) + flags |= NLM_F_DUMP; + + nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_TRAP_GET, flags); + + if (dl_argc(dl) > 0) { + err = dl_argv_parse_put(nlh, dl, + DL_OPT_HANDLE | DL_OPT_TRAP_NAME, 0); + if (err) + return err; + } + + pr_out_section_start(dl, "trap"); + err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_trap_show_cb, dl); + pr_out_section_end(dl); + + return err; +} + +static int cmd_trap_set(struct dl *dl) +{ + struct nlmsghdr *nlh; + int err; + + nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_TRAP_SET, + NLM_F_REQUEST | NLM_F_ACK); + + err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE | DL_OPT_TRAP_NAME, + DL_OPT_TRAP_REPORT | DL_OPT_TRAP_ACTION); + if (err) + return err; + + return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL); +} + +static int cmd_trap(struct dl *dl) +{ + if (dl_argv_match(dl, "help")) { + cmd_trap_help(); + return 0; + } else if (dl_argv_match(dl, "show") || + dl_argv_match(dl, "list") || dl_no_arg(dl)) { + dl_arg_inc(dl); + return cmd_trap_show(dl); + } else if (dl_argv_match(dl, "set")) { + dl_arg_inc(dl); + return cmd_trap_set(dl); + } + pr_err("Command \"%s\" not found\n", dl_argv(dl)); + return -ENOENT; +} + static void help(void) { pr_err("Usage: devlink [ OPTIONS ] OBJECT { COMMAND | help }\n" " devlink [ -f[orce] ] -b[atch] filename\n" - "where OBJECT := { dev | port | sb | monitor | dpipe | resource | region | health }\n" - " OPTIONS := { -V[ersion] | -n[o-nice-names] | -j[son] | -p[retty] | -v[erbose] }\n"); + "where OBJECT := { dev | port | sb | monitor | dpipe | resource | region | health | trap }\n" + " OPTIONS := { -V[ersion] | -n[o-nice-names] | -j[son] | -p[retty] | -v[erbose] -s[tatistics] }\n"); } static int dl_cmd(struct dl *dl, int argc, char **argv) @@ -6313,6 +6609,9 @@ static int dl_cmd(struct dl *dl, int argc, char **argv) } else if (dl_argv_match(dl, "health")) { dl_arg_inc(dl); return cmd_health(dl); + } else if (dl_argv_match(dl, "trap")) { + dl_arg_inc(dl); + return cmd_trap(dl); } pr_err("Object \"%s\" not found\n", dl_argv(dl)); return -ENOENT; @@ -6422,6 +6721,7 @@ int main(int argc, char **argv) { "json", no_argument, NULL, 'j' }, { "pretty", no_argument, NULL, 'p' }, { "verbose", no_argument, NULL, 'v' }, + { "statistics", no_argument, NULL, 's' }, { NULL, 0, NULL, 0 } }; const char *batch_file = NULL; @@ -6437,7 +6737,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - while ((opt = getopt_long(argc, argv, "Vfb:njpv", + while ((opt = getopt_long(argc, argv, "Vfb:njpvs", long_options, NULL)) >= 0) { switch (opt) { @@ -6463,6 +6763,9 @@ int main(int argc, char **argv) case 'v': dl->verbose = true; break; + case 's': + dl->stats = true; + break; default: pr_err("Unknown option.\n"); help(); From patchwork Sun Jul 7 08:01:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 1128596 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=idosch.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="Qs8ZassX"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45hLfT3d8bz9s4Y for ; Sun, 7 Jul 2019 18:02:41 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727247AbfGGICk (ORCPT ); Sun, 7 Jul 2019 04:02:40 -0400 Received: from new2-smtp.messagingengine.com ([66.111.4.224]:50771 "EHLO new2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726330AbfGGICk (ORCPT ); Sun, 7 Jul 2019 04:02:40 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailnew.nyi.internal (Postfix) with ESMTP id 056571AF7; Sun, 7 Jul 2019 04:02:39 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sun, 07 Jul 2019 04:02:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=FAfE0Q+CPGDUeQ+RCBFx+nwuMeevC3zyng2avgOpU/U=; b=Qs8ZassX 4XYm/RdecDgzlWcXPFqA2S2Oeex/j8+cRrUY22cjphnltfMXJV0h0dC7DMmOqOnN pc/if9fVM6g3etVUHRxAWJ5Eli38/pVYWyQ9T28xhMSnW3SkKiBGQdiHy+xoXh3x 9PWJGvuJq2H7DCjG848VIYIEozLeVD59ISUR2Nv9oE+KB7tjv4gJKdf1Kd8nO/r+ A2HGgvd7/utwSst9Ir8rV68bijiJQXJwxENI4WXetpMxd39wfhUADBphyW5HjBbW qcc+uqmVmmswFGvA55TdBs17fbQNzyOkPjONw9ZHANdQ1v74h0b/gDBpMwImTN4z 31Yhp+cXnO2Ifw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrfeejgdduvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepkfguohcuufgthhhimhhmvghluceoihguohhstghhsehiugho shgthhdrohhrgheqnecukfhppeduleefrdegjedrudeihedrvdehudenucfrrghrrghmpe hmrghilhhfrhhomhepihguohhstghhsehiughoshgthhdrohhrghenucevlhhushhtvghr ufhiiigvpedt X-ME-Proxy: Received: from splinter.mtl.com (unknown [193.47.165.251]) by mail.messagingengine.com (Postfix) with ESMTPA id 53C218005B; Sun, 7 Jul 2019 04:02:36 -0400 (EDT) From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, jiri@mellanox.com, mlxsw@mellanox.com, dsahern@gmail.com, roopa@cumulusnetworks.com, nikolay@cumulusnetworks.com, andy@greyhouse.net, pablo@netfilter.org, jakub.kicinski@netronome.com, pieter.jansenvanvuuren@netronome.com, andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com, Ido Schimmel Subject: [PATCH iproute2-next 3/7] devlink: Add devlink trap group set and show commands Date: Sun, 7 Jul 2019 11:01:56 +0300 Message-Id: <20190707080200.3699-4-idosch@idosch.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190707080200.3699-1-idosch@idosch.org> References: <20190707075828.3315-1-idosch@idosch.org> <20190707080200.3699-1-idosch@idosch.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Ido Schimmel These commands are similar to the trap set and show commands, but operate on a trap group and not individual traps. Example: # devlink trap group set netdevsim/netdevsim10 group l3_drops action trap report true # devlink -jps trap group show netdevsim/netdevsim10 group l3_drops { "trap_group": { "netdevsim/netdevsim10": [ { "name": "l3_drops", "generic": true, "stats": { "rx": { "bytes": 0, "packets": 0 } } } ] } } Signed-off-by: Ido Schimmel Acked-by: Jiri Pirko --- devlink/devlink.c | 136 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 2 deletions(-) diff --git a/devlink/devlink.c b/devlink/devlink.c index 90f41cbd2a9c..ad62b6162f0b 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -214,6 +214,7 @@ static void ifname_map_free(struct ifname_map *ifname_map) #define DL_OPT_TRAP_NAME BIT(29) #define DL_OPT_TRAP_REPORT BIT(30) #define DL_OPT_TRAP_ACTION BIT(31) +#define DL_OPT_TRAP_GROUP_NAME BIT(32) struct dl_opts { uint64_t present; /* flags of present items */ @@ -251,6 +252,7 @@ struct dl_opts { uint64_t reporter_graceful_period; bool reporter_auto_recover; const char *trap_name; + const char *trap_group_name; bool trap_report; enum devlink_trap_action trap_action; }; @@ -1075,6 +1077,7 @@ static const struct dl_args_metadata dl_args_required[] = { {DL_OPT_REGION_LENGTH, "Region length value expected."}, {DL_OPT_HEALTH_REPORTER_NAME, "Reporter's name is expected."}, {DL_OPT_TRAP_NAME, "Trap's name is expected."}, + {DL_OPT_TRAP_GROUP_NAME, "Trap group's name is expected."}, }; static int dl_args_finding_required_validate(uint64_t o_required, @@ -1371,6 +1374,13 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required, if (err) return err; o_found |= DL_OPT_TRAP_NAME; + } else if (dl_argv_match(dl, "group") && + (o_all & DL_OPT_TRAP_GROUP_NAME)) { + dl_arg_inc(dl); + err = dl_argv_str(dl, &opts->trap_group_name); + if (err) + return err; + o_found |= DL_OPT_TRAP_GROUP_NAME; } else if (dl_argv_match(dl, "report") && (o_all & DL_OPT_TRAP_REPORT)) { dl_arg_inc(dl); @@ -1506,6 +1516,9 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl) if (opts->present & DL_OPT_TRAP_NAME) mnl_attr_put_strz(nlh, DEVLINK_ATTR_TRAP_NAME, opts->trap_name); + if (opts->present & DL_OPT_TRAP_GROUP_NAME) + mnl_attr_put_strz(nlh, DEVLINK_ATTR_TRAP_GROUP_NAME, + opts->trap_group_name); if (opts->present & DL_OPT_TRAP_REPORT) mnl_attr_put_u8(nlh, DEVLINK_ATTR_TRAP_REPORT_ENABLED, opts->trap_report); @@ -3832,6 +3845,10 @@ static const char *cmd_name(uint8_t cmd) case DEVLINK_CMD_TRAP_SET: return "set"; case DEVLINK_CMD_TRAP_NEW: return "new"; case DEVLINK_CMD_TRAP_DEL: return "del"; + case DEVLINK_CMD_TRAP_GROUP_GET: return "get"; + case DEVLINK_CMD_TRAP_GROUP_SET: return "set"; + case DEVLINK_CMD_TRAP_GROUP_NEW: return "new"; + case DEVLINK_CMD_TRAP_GROUP_DEL: return "del"; default: return ""; } } @@ -3865,6 +3882,11 @@ static const char *cmd_obj(uint8_t cmd) case DEVLINK_CMD_TRAP_NEW: case DEVLINK_CMD_TRAP_DEL: return "trap"; + case DEVLINK_CMD_TRAP_GROUP_GET: + case DEVLINK_CMD_TRAP_GROUP_SET: + case DEVLINK_CMD_TRAP_GROUP_NEW: + case DEVLINK_CMD_TRAP_GROUP_DEL: + return "trap-group"; default: return ""; } } @@ -3891,6 +3913,7 @@ static bool cmd_filter_check(struct dl *dl, uint8_t cmd) static void pr_out_region(struct dl *dl, struct nlattr **tb); static void pr_out_trap(struct dl *dl, struct nlattr **tb, bool array); +static void pr_out_trap_group(struct dl *dl, struct nlattr **tb, bool array); static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data) { @@ -3963,6 +3986,18 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data) pr_out_mon_header(genl->cmd); pr_out_trap(dl, tb, false); break; + case DEVLINK_CMD_TRAP_GROUP_GET: /* fall through */ + case DEVLINK_CMD_TRAP_GROUP_SET: /* fall through */ + case DEVLINK_CMD_TRAP_GROUP_NEW: /* fall through */ + case DEVLINK_CMD_TRAP_GROUP_DEL: + mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb); + if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] || + !tb[DEVLINK_ATTR_TRAP_GROUP_NAME] || + !tb[DEVLINK_ATTR_STATS]) + return MNL_CB_ERROR; + pr_out_mon_header(genl->cmd); + pr_out_trap_group(dl, tb, false); + break; } return MNL_CB_OK; } @@ -3977,7 +4012,8 @@ static int cmd_mon_show(struct dl *dl) if (strcmp(cur_obj, "all") != 0 && strcmp(cur_obj, "dev") != 0 && strcmp(cur_obj, "port") != 0 && - strcmp(cur_obj, "trap") != 0) { + strcmp(cur_obj, "trap") != 0 && + strcmp(cur_obj, "trap-group") != 0) { pr_err("Unknown object \"%s\"\n", cur_obj); return -EINVAL; } @@ -3994,7 +4030,7 @@ static int cmd_mon_show(struct dl *dl) static void cmd_mon_help(void) { pr_err("Usage: devlink monitor [ all | OBJECT-LIST ]\n" - "where OBJECT-LIST := { dev | port | trap }\n"); + "where OBJECT-LIST := { dev | port | trap | trap-group }\n"); } static int cmd_mon(struct dl *dl) @@ -6509,6 +6545,9 @@ static void cmd_trap_help(void) pr_err("Usage: devlink trap set DEV trap TRAP [ report { true | false } ]\n"); pr_err(" [ action { trap | drop } ]\n"); pr_err(" devlink trap show [ DEV trap TRAP ]\n"); + pr_err(" devlink trap group set DEV group GROUP [ report { true | false } ]\n"); + pr_err(" [ action { trap | drop } ]\n"); + pr_err(" devlink trap group show [ DEV group GROUP ]\n"); } static int cmd_trap_show(struct dl *dl) @@ -6552,6 +6591,96 @@ static int cmd_trap_set(struct dl *dl) return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL); } +static void pr_out_trap_group(struct dl *dl, struct nlattr **tb, bool array) +{ + if (array) + pr_out_handle_start_arr(dl, tb); + else + __pr_out_handle_start(dl, tb, true, false); + + pr_out_str(dl, "name", + mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_GROUP_NAME])); + pr_out_bool(dl, "generic", !!tb[DEVLINK_ATTR_TRAP_GENERIC]); + pr_out_stats(dl, tb[DEVLINK_ATTR_STATS]); + pr_out_handle_end(dl); +} + +static int cmd_trap_group_show_cb(const struct nlmsghdr *nlh, void *data) +{ + struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh); + struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {}; + struct dl *dl = data; + + mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb); + if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] || + !tb[DEVLINK_ATTR_TRAP_GROUP_NAME] || !tb[DEVLINK_ATTR_STATS]) + return MNL_CB_ERROR; + + pr_out_trap_group(dl, tb, true); + + return MNL_CB_OK; +} + +static int cmd_trap_group_show(struct dl *dl) +{ + uint16_t flags = NLM_F_REQUEST | NLM_F_ACK; + struct nlmsghdr *nlh; + int err; + + if (dl_argc(dl) == 0) + flags |= NLM_F_DUMP; + + nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_TRAP_GROUP_GET, flags); + + if (dl_argc(dl) > 0) { + err = dl_argv_parse_put(nlh, dl, + DL_OPT_HANDLE | DL_OPT_TRAP_GROUP_NAME, + 0); + if (err) + return err; + } + + pr_out_section_start(dl, "trap_group"); + err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_trap_group_show_cb, dl); + pr_out_section_end(dl); + + return err; +} + +static int cmd_trap_group_set(struct dl *dl) +{ + struct nlmsghdr *nlh; + int err; + + nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_TRAP_GROUP_SET, + NLM_F_REQUEST | NLM_F_ACK); + + err = dl_argv_parse_put(nlh, dl, + DL_OPT_HANDLE | DL_OPT_TRAP_GROUP_NAME, + DL_OPT_TRAP_REPORT | DL_OPT_TRAP_ACTION); + if (err) + return err; + + return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL); +} + +static int cmd_trap_group(struct dl *dl) +{ + if (dl_argv_match(dl, "help")) { + cmd_trap_help(); + return 0; + } else if (dl_argv_match(dl, "show") || + dl_argv_match(dl, "list") || dl_no_arg(dl)) { + dl_arg_inc(dl); + return cmd_trap_group_show(dl); + } else if (dl_argv_match(dl, "set")) { + dl_arg_inc(dl); + return cmd_trap_group_set(dl); + } + pr_err("Command \"%s\" not found\n", dl_argv(dl)); + return -ENOENT; +} + static int cmd_trap(struct dl *dl) { if (dl_argv_match(dl, "help")) { @@ -6564,6 +6693,9 @@ static int cmd_trap(struct dl *dl) } else if (dl_argv_match(dl, "set")) { dl_arg_inc(dl); return cmd_trap_set(dl); + } else if (dl_argv_match(dl, "group")) { + dl_arg_inc(dl); + return cmd_trap_group(dl); } pr_err("Command \"%s\" not found\n", dl_argv(dl)); return -ENOENT; From patchwork Sun Jul 7 08:01:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 1128597 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=idosch.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="NORmeCpt"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45hLfX1vh0z9sCJ for ; Sun, 7 Jul 2019 18:02:44 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727271AbfGGICn (ORCPT ); Sun, 7 Jul 2019 04:02:43 -0400 Received: from new2-smtp.messagingengine.com ([66.111.4.224]:38333 "EHLO new2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726330AbfGGICm (ORCPT ); Sun, 7 Jul 2019 04:02:42 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailnew.nyi.internal (Postfix) with ESMTP id 826611B3D; Sun, 7 Jul 2019 04:02:41 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sun, 07 Jul 2019 04:02:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=myUabCjU6u4no0R68aK5cjFytSwi/RnzNINif7vBZ6c=; b=NORmeCpt S3en3YgLD37bR/oaxSPMNo1wRR7GMOGQkJtcBKGtay+ApvXD6zGoeBYHljJPpDOu j1Qm94AOkh4sjSUADWYFf84B7S4VyeDrqDc5pd3rJgKvQCVuOJ/iJUpOAwWqHT7F hWFjineOuj/43fosMjTE6bvlLK0w820AJkR6zMsSEBQqmoiwjPBscVKLiew9wOFl aK2Re5V9OE6879PnxbeyUPDewzs1x5N/xz/Abho/3I+SrenYcHfRLR619jG9rsZv X+Jh58EX1T975cAgm8tSeWFAirphFKqSIPQCgQ7MK6zzhWX3YDiHRVJd8ZmPvDgS YSHVIUqC/xwnjA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrfeejgdduvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepkfguohcuufgthhhimhhmvghluceoihguohhstghhsehiugho shgthhdrohhrgheqnecukfhppeduleefrdegjedrudeihedrvdehudenucfrrghrrghmpe hmrghilhhfrhhomhepihguohhstghhsehiughoshgthhdrohhrghenucevlhhushhtvghr ufhiiigvpedt X-ME-Proxy: Received: from splinter.mtl.com (unknown [193.47.165.251]) by mail.messagingengine.com (Postfix) with ESMTPA id D78C88005A; Sun, 7 Jul 2019 04:02:38 -0400 (EDT) From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, jiri@mellanox.com, mlxsw@mellanox.com, dsahern@gmail.com, roopa@cumulusnetworks.com, nikolay@cumulusnetworks.com, andy@greyhouse.net, pablo@netfilter.org, jakub.kicinski@netronome.com, pieter.jansenvanvuuren@netronome.com, andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com, Ido Schimmel Subject: [PATCH iproute2-next 4/7] devlink: Add devlink trap monitor support Date: Sun, 7 Jul 2019 11:01:57 +0300 Message-Id: <20190707080200.3699-5-idosch@idosch.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190707080200.3699-1-idosch@idosch.org> References: <20190707075828.3315-1-idosch@idosch.org> <20190707080200.3699-1-idosch@idosch.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Ido Schimmel According to the reporting state of individual traps, a notification is sent to user space about each trapped packet. Allow the user to monitor such events by having iproute2 subscribe to the 'DEVLINK_GENL_MCGRP_TRAP_NAME' group. An error is not returned in case subscription failed in order not to cause regression with old kernels and new iproute2. When '-v' is specified trap metadata (e.g., input port) is also shown. Example: # devlink -jvp mon trap-report [trap-report,report] "netdevsim/netdevsim10": { "name": "blackhole_route", "type": "drop", "group": "l3_drops", "length": 146, "timestamp": "Tue May 28 13:03:09 2019 801360651 nsec", "input_port": { "netdevsim/netdevsim10/0": { "type": "eth", "netdev": "eth0" } } } Signed-off-by: Ido Schimmel Acked-by: Jiri Pirko --- devlink/devlink.c | 79 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 2 deletions(-) diff --git a/devlink/devlink.c b/devlink/devlink.c index ad62b6162f0b..b9fce850ee00 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -3849,6 +3849,7 @@ static const char *cmd_name(uint8_t cmd) case DEVLINK_CMD_TRAP_GROUP_SET: return "set"; case DEVLINK_CMD_TRAP_GROUP_NEW: return "new"; case DEVLINK_CMD_TRAP_GROUP_DEL: return "del"; + case DEVLINK_CMD_TRAP_REPORT: return "report"; default: return ""; } } @@ -3887,6 +3888,8 @@ static const char *cmd_obj(uint8_t cmd) case DEVLINK_CMD_TRAP_GROUP_NEW: case DEVLINK_CMD_TRAP_GROUP_DEL: return "trap-group"; + case DEVLINK_CMD_TRAP_REPORT: + return "trap-report"; default: return ""; } } @@ -3914,6 +3917,7 @@ static bool cmd_filter_check(struct dl *dl, uint8_t cmd) static void pr_out_region(struct dl *dl, struct nlattr **tb); static void pr_out_trap(struct dl *dl, struct nlattr **tb, bool array); static void pr_out_trap_group(struct dl *dl, struct nlattr **tb, bool array); +static void pr_out_trap_report(struct dl *dl, struct nlattr **tb); static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data) { @@ -3998,6 +4002,18 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data) pr_out_mon_header(genl->cmd); pr_out_trap_group(dl, tb, false); break; + case DEVLINK_CMD_TRAP_REPORT: + mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb); + if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] || + !tb[DEVLINK_ATTR_TRAP_NAME] || + !tb[DEVLINK_ATTR_TRAP_TYPE] || + !tb[DEVLINK_ATTR_TRAP_GROUP_NAME] || + !tb[DEVLINK_ATTR_TRAP_PAYLOAD] || + !tb[DEVLINK_ATTR_TRAP_TIMESTAMP]) + return MNL_CB_ERROR; + pr_out_mon_header(genl->cmd); + pr_out_trap_report(dl, tb); + break; } return MNL_CB_OK; } @@ -4013,7 +4029,8 @@ static int cmd_mon_show(struct dl *dl) strcmp(cur_obj, "dev") != 0 && strcmp(cur_obj, "port") != 0 && strcmp(cur_obj, "trap") != 0 && - strcmp(cur_obj, "trap-group") != 0) { + strcmp(cur_obj, "trap-group") != 0 && + strcmp(cur_obj, "trap-report") != 0) { pr_err("Unknown object \"%s\"\n", cur_obj); return -EINVAL; } @@ -4021,6 +4038,10 @@ static int cmd_mon_show(struct dl *dl) err = _mnlg_socket_group_add(dl->nlg, DEVLINK_GENL_MCGRP_CONFIG_NAME); if (err) return err; + /* Do not bail in order to be compatible with old kernels that do not + * support this multicast group. + */ + mnlg_socket_group_add(dl->nlg, DEVLINK_GENL_MCGRP_TRAP_NAME); err = _mnlg_socket_recv_run(dl->nlg, cmd_mon_show_cb, dl); if (err) return err; @@ -4030,7 +4051,7 @@ static int cmd_mon_show(struct dl *dl) static void cmd_mon_help(void) { pr_err("Usage: devlink monitor [ all | OBJECT-LIST ]\n" - "where OBJECT-LIST := { dev | port | trap | trap-group }\n"); + "where OBJECT-LIST := { dev | port | trap | trap-group | trap-report }\n"); } static int cmd_mon(struct dl *dl) @@ -6486,6 +6507,60 @@ static const char *trap_metadata_name(const struct nlattr *attr) return ""; } } + +static void pr_out_trap_report_timestamp(struct dl *dl, + const struct nlattr *attr) +{ + struct timespec *ts; + struct tm *tm; + char buf[80]; + char *tstr; + + ts = mnl_attr_get_payload(attr); + tm = localtime(&ts->tv_sec); + + tstr = asctime(tm); + tstr[strlen(tstr) - 1] = 0; + snprintf(buf, sizeof(buf), "%s %09ld nsec", tstr, ts->tv_nsec); + + pr_out_str(dl, "timestamp", buf); +} + +static void pr_out_trap_report_port(struct dl *dl, struct nlattr *attr, + const char *name, struct nlattr **tb) +{ + int err; + + if (!dl->verbose) + return; + + err = mnl_attr_parse_nested(attr, attr_cb, tb); + if (err != MNL_CB_OK) + return; + + pr_out_object_start(dl, name); + pr_out_port(dl, tb); + pr_out_object_end(dl); +} + +static void pr_out_trap_report(struct dl *dl, struct nlattr **tb) +{ + uint8_t type = mnl_attr_get_u8(tb[DEVLINK_ATTR_TRAP_TYPE]); + + __pr_out_handle_start(dl, tb, true, false); + pr_out_str(dl, "name", mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_NAME])); + pr_out_str(dl, "type", trap_type_name(type)); + pr_out_str(dl, "group", + mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_GROUP_NAME])); + pr_out_uint(dl, "length", + mnl_attr_get_payload_len(tb[DEVLINK_ATTR_TRAP_PAYLOAD])); + pr_out_trap_report_timestamp(dl, tb[DEVLINK_ATTR_TRAP_TIMESTAMP]); + if (tb[DEVLINK_ATTR_TRAP_IN_PORT]) + pr_out_trap_report_port(dl, tb[DEVLINK_ATTR_TRAP_IN_PORT], + "input_port", tb); + pr_out_handle_end(dl); +} + static void pr_out_trap_metadata(struct dl *dl, struct nlattr *attr) { struct nlattr *attr_metadata; From patchwork Sun Jul 7 08:01:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 1128598 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=idosch.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="WYhMdmzX"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45hLfZ6plKz9s4Y for ; Sun, 7 Jul 2019 18:02:46 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727303AbfGGICp (ORCPT ); Sun, 7 Jul 2019 04:02:45 -0400 Received: from new2-smtp.messagingengine.com ([66.111.4.224]:39061 "EHLO new2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726330AbfGGICp (ORCPT ); Sun, 7 Jul 2019 04:02:45 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailnew.nyi.internal (Postfix) with ESMTP id 0A6C41BEA; Sun, 7 Jul 2019 04:02:44 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sun, 07 Jul 2019 04:02:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=fxfuOW//LY0ODQ7+OFLGqCvYWi3aOATKs4s/aAOeFZs=; b=WYhMdmzX hJlN9Ydtd5w8zYqlrtjwD8EJQNVdPV6xt24o20WgZRJjOrLXcATUZCveJxwhkJLx VtlRLaui/lmggHIoEiU2PvGzhZYYGaX0cBOU5r9FP7c6DWRPINRWPoUpQPC1yIuP QIoLGnCRRMTh5QthZcxlUv+7ioWLYeMQmBTJYYUnqGhHX6Sk9Xp6C/guy0LQWORi 9wQZ/R3WTif+kP4eA5urPm2H2l0j3EfJrx+vWXpYJCAnJAgQBNoUladjlIe+TDgT Bkfri8/u/NsZ9xPDbEVesARPp4K3Cesd5jPW3Phf3FYim0HfE/PxcbCVfSA/J7tr Grpx8VdSamI0kA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrfeejgdduvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepkfguohcuufgthhhimhhmvghluceoihguohhstghhsehiugho shgthhdrohhrgheqnecukfhppeduleefrdegjedrudeihedrvdehudenucfrrghrrghmpe hmrghilhhfrhhomhepihguohhstghhsehiughoshgthhdrohhrghenucevlhhushhtvghr ufhiiigvpedt X-ME-Proxy: Received: from splinter.mtl.com (unknown [193.47.165.251]) by mail.messagingengine.com (Postfix) with ESMTPA id 65FE08005C; Sun, 7 Jul 2019 04:02:41 -0400 (EDT) From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, jiri@mellanox.com, mlxsw@mellanox.com, dsahern@gmail.com, roopa@cumulusnetworks.com, nikolay@cumulusnetworks.com, andy@greyhouse.net, pablo@netfilter.org, jakub.kicinski@netronome.com, pieter.jansenvanvuuren@netronome.com, andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com, Ido Schimmel Subject: [PATCH iproute2-next 5/7] devlink: Set NETLINK_NO_ENOBUFS when monitoring events Date: Sun, 7 Jul 2019 11:01:58 +0300 Message-Id: <20190707080200.3699-6-idosch@idosch.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190707080200.3699-1-idosch@idosch.org> References: <20190707075828.3315-1-idosch@idosch.org> <20190707080200.3699-1-idosch@idosch.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Ido Schimmel If we lost an event, there is nothing we can do in order to recover it. Set above mentioned socket option on the netlink socket when monitoring devlink events, so that `devlink monitor` will not abort in case we are not draining the receive buffer fast enough. The number of events we lost can be retrieved using: # cat /proc/net/netlink | grep `pidof devlink` | awk '{ print $9 }' Signed-off-by: Ido Schimmel Acked-by: Jiri Pirko --- devlink/devlink.c | 22 +++++++++++++++++++++- devlink/mnlg.c | 12 ++++++++++++ devlink/mnlg.h | 2 ++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/devlink/devlink.c b/devlink/devlink.c index b9fce850ee00..817b74259ec3 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -140,6 +140,19 @@ static int _mnlg_socket_group_add(struct mnlg_socket *nlg, return 0; } +static int _mnlg_socket_setsockopt(struct mnlg_socket *nlg, int type, + void *buf, socklen_t len) +{ + int err; + + err = mnlg_socket_setsockopt(nlg, type, buf, len); + if (err < 0) { + pr_err("Failed to call mnlg_socket_setsockopt\n"); + return -errno; + } + return 0; +} + struct ifname_map { struct list_head list; char *bus_name; @@ -4020,7 +4033,7 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data) static int cmd_mon_show(struct dl *dl) { - int err; + int err, one = 1; unsigned int index = 0; const char *cur_obj; @@ -4035,6 +4048,13 @@ static int cmd_mon_show(struct dl *dl) return -EINVAL; } } + /* It is possible to lose some events if we are not draining the socket + * receive buffer fast enough. Keep processing events and do not abort. + */ + err = _mnlg_socket_setsockopt(dl->nlg, NETLINK_NO_ENOBUFS, &one, + sizeof(one)); + if (err) + return err; err = _mnlg_socket_group_add(dl->nlg, DEVLINK_GENL_MCGRP_CONFIG_NAME); if (err) return err; diff --git a/devlink/mnlg.c b/devlink/mnlg.c index ee125df042f0..23e6e794b508 100644 --- a/devlink/mnlg.c +++ b/devlink/mnlg.c @@ -231,6 +231,18 @@ int mnlg_socket_group_add(struct mnlg_socket *nlg, const char *group_name) return 0; } +int mnlg_socket_setsockopt(struct mnlg_socket *nlg, int type, void *buf, + socklen_t len) +{ + int err; + + err = mnl_socket_setsockopt(nlg->nl, type, buf, len); + if (err < 0) + return err; + + return 0; +} + static int get_family_id_attr_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; diff --git a/devlink/mnlg.h b/devlink/mnlg.h index 4d1babf3b4c2..49154215729e 100644 --- a/devlink/mnlg.h +++ b/devlink/mnlg.h @@ -21,6 +21,8 @@ struct nlmsghdr *mnlg_msg_prepare(struct mnlg_socket *nlg, uint8_t cmd, int mnlg_socket_send(struct mnlg_socket *nlg, const struct nlmsghdr *nlh); int mnlg_socket_recv_run(struct mnlg_socket *nlg, mnl_cb_t data_cb, void *data); int mnlg_socket_group_add(struct mnlg_socket *nlg, const char *group_name); +int mnlg_socket_setsockopt(struct mnlg_socket *nlg, int type, void *buf, + socklen_t len); struct mnlg_socket *mnlg_socket_open(const char *family_name, uint8_t version); void mnlg_socket_close(struct mnlg_socket *nlg); From patchwork Sun Jul 7 08:01:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 1128599 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=idosch.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="fR2juOQw"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45hLfc6S3cz9s4Y for ; Sun, 7 Jul 2019 18:02:48 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727330AbfGGICs (ORCPT ); Sun, 7 Jul 2019 04:02:48 -0400 Received: from new2-smtp.messagingengine.com ([66.111.4.224]:40255 "EHLO new2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727259AbfGGICr (ORCPT ); Sun, 7 Jul 2019 04:02:47 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailnew.nyi.internal (Postfix) with ESMTP id 815831C2E; Sun, 7 Jul 2019 04:02:46 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sun, 07 Jul 2019 04:02:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=rm7kWBoTiupsYJF0hXOuWHRvFGvVGtgnjz/KRcNVGbc=; b=fR2juOQw wJGfHLSxNcPu8ihr7XS8XTCQzJv7QxkVy2CapcmYkYIdH1K74BBr97abaYTQbY1k IAgqORcPidcBKI/esuTt2mvrHLgMIpRStqvtHGPzwPQiH8rJGluo5xNGyxcE5hnW aKs+Wb37CUyriHgIHsH/uzI0PLmfkKOSBFPpwdzx8vFY7ZRwpm6heTAVno3snVdC nkw5lhf2GCiELhbglIU42rNX1FNMAnjpap3VNnqifzxzpGaEt/4RY6t/I0Q5kvJJ JlQR2CODpDfWqzTrBzdmBHRSeLjJGZNv9KTng+k31rCL0eV1+OlPVM+tE/vzyUTb 7dvGNkb/Q1opbQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrfeejgdduvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepkfguohcuufgthhhimhhmvghluceoihguohhstghhsehiugho shgthhdrohhrgheqnecukfhppeduleefrdegjedrudeihedrvdehudenucfrrghrrghmpe hmrghilhhfrhhomhepihguohhstghhsehiughoshgthhdrohhrghenucevlhhushhtvghr ufhiiigvpedt X-ME-Proxy: Received: from splinter.mtl.com (unknown [193.47.165.251]) by mail.messagingengine.com (Postfix) with ESMTPA id E781A8005B; Sun, 7 Jul 2019 04:02:43 -0400 (EDT) From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, jiri@mellanox.com, mlxsw@mellanox.com, dsahern@gmail.com, roopa@cumulusnetworks.com, nikolay@cumulusnetworks.com, andy@greyhouse.net, pablo@netfilter.org, jakub.kicinski@netronome.com, pieter.jansenvanvuuren@netronome.com, andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com, Ido Schimmel Subject: [PATCH iproute2-next 6/7] devlink: Add fflush() to print functions Date: Sun, 7 Jul 2019 11:01:59 +0300 Message-Id: <20190707080200.3699-7-idosch@idosch.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190707080200.3699-1-idosch@idosch.org> References: <20190707075828.3315-1-idosch@idosch.org> <20190707080200.3699-1-idosch@idosch.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Ido Schimmel Similar to commit 09e0528cf977 ("ip: mroute: add fflush to print_mroute"), we need to add fflush() to the print functions to get the following to work: # devlink mon &> log Without it, stdout output is buffered and not written to the disk. This is useful when writing tests that rely on devlink-monitor output. Signed-off-by: Ido Schimmel Acked-by: Jiri Pirko --- devlink/devlink.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/devlink/devlink.c b/devlink/devlink.c index 817b74259ec3..6fa3be69ff1a 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -58,6 +58,7 @@ static int g_new_line_count; } \ fprintf(stdout, ##args); \ g_new_line_count = 0; \ + fflush(stdout); \ } while (0) #define pr_out_sp(num, args...) \ @@ -66,6 +67,7 @@ static int g_new_line_count; if (ret < num) \ fprintf(stdout, "%*s", num - ret, ""); \ g_new_line_count = 0; \ + fflush(stdout); \ } while (0) static int g_indent_level; From patchwork Sun Jul 7 08:02:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 1128600 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=idosch.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="M08+tLwk"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45hLfg6hc4z9s4Y for ; Sun, 7 Jul 2019 18:02:51 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727340AbfGGICu (ORCPT ); Sun, 7 Jul 2019 04:02:50 -0400 Received: from new2-smtp.messagingengine.com ([66.111.4.224]:41677 "EHLO new2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727259AbfGGICu (ORCPT ); Sun, 7 Jul 2019 04:02:50 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailnew.nyi.internal (Postfix) with ESMTP id 3CC181D07; Sun, 7 Jul 2019 04:02:49 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sun, 07 Jul 2019 04:02:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=RO0/hDQ3OxHfEx7QvDLJIJtC6pIo2/aOj9yjk4fd74s=; b=M08+tLwk N3RvQ4N5r0IQYnXGECG6Jvph+8Swf/sVxk3924/WSvFF2p01Bfnju3O6/8Ez/izn 3v4DlJAgLbFm2mog2HemeWjrkI8ho+ySUQnbLDnGcHbUjOcODlNVg/AmxXiQaGCE JH8JOyBidGnx4fua2fRo81PE9ImXO2vbM9fvlfhSQ9LSqwOdviVjxM/nM9txe0WO 99Qi0TXIdaKlrRfTT4Gc91k8y2Kbuey3M3tdrVNYjVjEisl4tRNGpcgn/90PS5DW ZTld64O1Ci1lKDcg/ieUSnFPE3mawgrZBw+nKEsoHeIsjonZ+3Ihxjrt0RXxqUZs STmKTcheLDxhtg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrfeejgdduvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepkfguohcuufgthhhimhhmvghluceoihguohhstghhsehiugho shgthhdrohhrgheqnecukfhppeduleefrdegjedrudeihedrvdehudenucfrrghrrghmpe hmrghilhhfrhhomhepihguohhstghhsehiughoshgthhdrohhrghenucevlhhushhtvghr ufhiiigvpedt X-ME-Proxy: Received: from splinter.mtl.com (unknown [193.47.165.251]) by mail.messagingengine.com (Postfix) with ESMTPA id 77B388005C; Sun, 7 Jul 2019 04:02:46 -0400 (EDT) From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, jiri@mellanox.com, mlxsw@mellanox.com, dsahern@gmail.com, roopa@cumulusnetworks.com, nikolay@cumulusnetworks.com, andy@greyhouse.net, pablo@netfilter.org, jakub.kicinski@netronome.com, pieter.jansenvanvuuren@netronome.com, andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com, Ido Schimmel Subject: [PATCH iproute2-next 7/7] devlink: Add man page for devlink-trap Date: Sun, 7 Jul 2019 11:02:00 +0300 Message-Id: <20190707080200.3699-8-idosch@idosch.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190707080200.3699-1-idosch@idosch.org> References: <20190707075828.3315-1-idosch@idosch.org> <20190707080200.3699-1-idosch@idosch.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Ido Schimmel Signed-off-by: Ido Schimmel Acked-by: Jiri Pirko --- man/man8/devlink-monitor.8 | 3 +- man/man8/devlink-trap.8 | 166 +++++++++++++++++++++++++++++++++++++ man/man8/devlink.8 | 11 ++- 3 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 man/man8/devlink-trap.8 diff --git a/man/man8/devlink-monitor.8 b/man/man8/devlink-monitor.8 index 13fe641dc8f5..84f0442aa272 100644 --- a/man/man8/devlink-monitor.8 +++ b/man/man8/devlink-monitor.8 @@ -21,7 +21,7 @@ command is the first in the command line and then the object list. .I OBJECT-LIST is the list of object types that we want to monitor. It may contain -.BR dev ", " port ". +.BR dev ", " port ", " trap ", " trap-group ", " trap-report . .B devlink opens Devlink Netlink socket, listens on it and dumps state changes. @@ -31,6 +31,7 @@ opens Devlink Netlink socket, listens on it and dumps state changes. .BR devlink-dev (8), .BR devlink-sb (8), .BR devlink-port (8), +.BR devlink-trap (8), .br .SH AUTHOR diff --git a/man/man8/devlink-trap.8 b/man/man8/devlink-trap.8 new file mode 100644 index 000000000000..8877df484749 --- /dev/null +++ b/man/man8/devlink-trap.8 @@ -0,0 +1,166 @@ +.TH DEVLINK\-TRAP 8 "11 June 2019" "iproute2" "Linux" +.SH NAME +devlink-trap \- devlink trap configuration +.SH SYNOPSIS +.sp +.ad l +.in +8 +.ti -8 +.B devlink +.RI "[ " OPTIONS " ]" +.B trap +.RI "{ " COMMAND " |" +.BR help " }" +.sp + +.ti -8 +.IR OPTIONS " := { " +\fB\-v\fR[\fIerbose\fR] | +\fB\-s\fR[\fItatistics\fR] } + +.ti -8 +.B "devlink trap show" +.RI "[ " DEV +.B trap +.IR TRAP " ]" + +.ti -8 +.BI "devlink trap set " DEV " trap " TRAP +.RB "[ " report " { " true " | " false " } ]" +.br +.RB "[ " action " { " trap " | " drop " } ]" + +.ti -8 +.B "devlink trap group show" +.RI "[ " DEV +.B group +.IR GROUP " ]" + +.ti -8 +.BI "devlink trap group set " DEV " group " GROUP +.RB "[ " report " { " true " | " false " } ]" +.br +.RB "[ " action " { " trap " | " drop " } ]" + +.ti -8 +.B devlink trap help + +.SH "DESCRIPTION" +.SS devlink trap show - display available packet traps and their attributes + +.PP +.I "DEV" +- specifies the devlink device from which to show packet traps. +If this argument is omitted all packet traps of all devices are listed. + +.PP +.BI "trap " TRAP +- specifies the packet trap. +Only applicable if a devlink device is also specified. + +.SS devlink trap set - set attributes of a packet trap + +.PP +.I "DEV" +- specifies the devlink device the packet trap belongs to. + +.PP +.BI "trap " TRAP +- specifies the packet trap. + +.TP +.BR report " { " true " | " false " } " +whether to report trapped packets to user space or not. + +.TP +.BR action " { " trap " | " drop " } " +packet trap action. + +.I trap +- the sole copy of the packet is sent to the CPU. + +.I drop +- the packet is dropped by the underlying device and a copy is not sent to the CPU. + +.SS devlink trap group show - display available packet trap groups and their attributes + +.PP +.I "DEV" +- specifies the devlink device from which to show packet trap groups. +If this argument is omitted all packet trap groups of all devices are listed. + +.PP +.BI "group " GROUP +- specifies the packet trap group. +Only applicable if a devlink device is also specified. + +.SS devlink trap group set - set attributes of a packet trap group + +.PP +.I "DEV" +- specifies the devlink device the packet trap group belongs to. + +.PP +.BI "group " GROUP +- specifies the packet trap group. + +.TP +.BR report " { " true " | " false " } " +whether to report trapped packets from traps member in the trap group to user +space or not. + +.TP +.BR action " { " trap " | " drop " } " +packet trap action. The action is set for all the packet traps member in the +trap group. The actions of non-drop traps cannot be changed and are thus +skipped. + +.SH "EXAMPLES" +.PP +devlink trap show +.RS 4 +List available packet traps. +.RE +.PP +devlink trap group show +.RS 4 +List available packet trap groups. +.RE +.PP +devlink -vs trap show pci/0000:01:00.0 trap source_mac_is_multicast +.RS 4 +Show attributes and statistics of a specific packet trap. +.RE +.PP +devlink -s trap group show pci/0000:01:00.0 group l2_drops +.RS 4 +Show attributes and statistics of a specific packet trap group. +.RE +.PP +devlink trap set pci/0000:01:00.0 trap source_mac_is_multicast action trap +.RS 4 +Set the action of a specific packet trap to 'trap'. +.RE +.PP +devlink trap set pci/0000:01:00.0 trap source_mac_is_multicast report true +.RS 4 +Set the report status a specific packet trap to 'true'. +.RE +.PP +devlink trap group set pci/0000:01:00.0 group l2_drops report true +.RS 4 +Set the report status a specific packet trap group to 'true'. +.RE +.PP +devlink -v monitor trap-report +.RS 4 +Monitor trapped packets. + +.SH SEE ALSO +.BR devlink (8), +.BR devlink-dev (8), +.BR devlink-monitor (8), +.br + +.SH AUTHOR +Ido Schimmel diff --git a/man/man8/devlink.8 b/man/man8/devlink.8 index 13d4dcd908b3..12d489440a3d 100644 --- a/man/man8/devlink.8 +++ b/man/man8/devlink.8 @@ -7,7 +7,7 @@ devlink \- Devlink tool .in +8 .ti -8 .B devlink -.RI "[ " OPTIONS " ] { " dev | port | monitor | sb | resource | region | health " } { " COMMAND " | " +.RI "[ " OPTIONS " ] { " dev | port | monitor | sb | resource | region | health | trap " } { " COMMAND " | " .BR help " }" .sp @@ -51,6 +51,10 @@ When combined with -j generate a pretty JSON output. .BR "\-v" , " --verbose" Turn on verbose output. +.TP +.BR "\-s" , " --statistics" +Output statistics. + .SS .I OBJECT @@ -82,6 +86,10 @@ Turn on verbose output. .B health - devlink reporting and recovery +.TP +.B trap +- devlink trap configuration + .SS .I COMMAND @@ -114,6 +122,7 @@ Exit status is 0 if command was successful or a positive integer upon failure. .BR devlink-resource (8), .BR devlink-region (8), .BR devlink-health (8), +.BR devlink-trap (8), .br .SH REPORTING BUGS