From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: dsahern@gmail.com, stephen@networkplumber.org, mlxsw@mellanox.com
Subject: [patch iproute2/net-next 3/8] devlink: fix encap mode manupulation
Date: Sat, 4 Apr 2020 18:16:16 +0200 [thread overview]
Message-ID: <20200404161621.3452-4-jiri@resnulli.us> (raw)
In-Reply-To: <20200404161621.3452-1-jiri@resnulli.us>
From: Jiri Pirko <jiri@mellanox.com>
DEVLINK_ATTR_ESWITCH_ENCAP_MODE netlink attribute carries enum. But the
code assumes bool value. Fix this by treating the encap mode in the same
way as other eswitch mode attributes, switching from "enable"/"disable"
to "basic"/"none", according to the enum. Maintain the backward
compatibility to allow user to pass "enable"/"disable" too. Also to be
in-sync with the rest of the "mode" commands, rename to "encap-mode".
Adjust the help and man page accordingly.
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
bash-completion/devlink | 8 +++----
devlink/devlink.c | 46 ++++++++++++++++++++++++++++++-----------
man/man8/devlink-dev.8 | 8 +++----
3 files changed, 42 insertions(+), 20 deletions(-)
diff --git a/bash-completion/devlink b/bash-completion/devlink
index 45fba75c1539..73d85d5eafb6 100644
--- a/bash-completion/devlink
+++ b/bash-completion/devlink
@@ -100,11 +100,11 @@ _devlink_dev_eswitch_set()
local -A settings=(
[mode]=notseen
[inline-mode]=notseen
- [encap]=notseen
+ [encap-mode]=notseen
)
if [[ $cword -eq 5 ]]; then
- COMPREPLY=( $( compgen -W "mode inline-mode encap" -- "$cur" ) )
+ COMPREPLY=( $( compgen -W "mode inline-mode encap-mode" -- "$cur" ) )
fi
# Mark seen settings
@@ -127,8 +127,8 @@ _devlink_dev_eswitch_set()
"$cur" ) )
return
;;
- encap)
- COMPREPLY=( $( compgen -W "disable enable" -- "$cur" ) )
+ encap-mode)
+ COMPREPLY=( $( compgen -W "none basic" -- "$cur" ) )
return
;;
esac
diff --git a/devlink/devlink.c b/devlink/devlink.c
index 559b6cec2fae..79a1c3829c31 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -41,6 +41,9 @@
#define ESWITCH_INLINE_MODE_NETWORK "network"
#define ESWITCH_INLINE_MODE_TRANSPORT "transport"
+#define ESWITCH_ENCAP_MODE_NONE "none"
+#define ESWITCH_ENCAP_MODE_BASIC "basic"
+
#define PARAM_CMODE_RUNTIME_STR "runtime"
#define PARAM_CMODE_DRIVERINIT_STR "driverinit"
#define PARAM_CMODE_PERMANENT_STR "permanent"
@@ -305,7 +308,7 @@ struct dl_opts {
enum devlink_eswitch_inline_mode eswitch_inline_mode;
const char *dpipe_table_name;
bool dpipe_counters_enable;
- bool eswitch_encap_mode;
+ enum devlink_eswitch_encap_mode eswitch_encap_mode;
const char *resource_path;
uint64_t resource_size;
uint32_t resource_id;
@@ -1091,12 +1094,19 @@ static int eswitch_inline_mode_get(const char *typestr,
return 0;
}
-static int eswitch_encap_mode_get(const char *typestr, bool *p_mode)
+static int
+eswitch_encap_mode_get(const char *typestr,
+ enum devlink_eswitch_encap_mode *p_encap_mode)
{
- if (strcmp(typestr, "enable") == 0) {
- *p_mode = true;
- } else if (strcmp(typestr, "disable") == 0) {
- *p_mode = false;
+ /* The initial implementation incorrectly accepted "enable"/"disable".
+ * Carry it to maintain backward compatibility.
+ */
+ if (strcmp(typestr, "disable") == 0 ||
+ strcmp(typestr, ESWITCH_ENCAP_MODE_NONE) == 0) {
+ *p_encap_mode = DEVLINK_ESWITCH_ENCAP_MODE_NONE;
+ } else if (strcmp(typestr, "enable") == 0 ||
+ strcmp(typestr, ESWITCH_ENCAP_MODE_BASIC) == 0) {
+ *p_encap_mode = DEVLINK_ESWITCH_ENCAP_MODE_BASIC;
} else {
pr_err("Unknown eswitch encap mode \"%s\"\n", typestr);
return -EINVAL;
@@ -1342,7 +1352,8 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
if (err)
return err;
o_found |= DL_OPT_DPIPE_TABLE_COUNTERS;
- } else if (dl_argv_match(dl, "encap") &&
+ } else if ((dl_argv_match(dl, "encap") || /* Original incorrect implementation */
+ dl_argv_match(dl, "encap-mode")) &&
(o_all & DL_OPT_ESWITCH_ENCAP_MODE)) {
const char *typestr;
@@ -1678,7 +1689,7 @@ static void cmd_dev_help(void)
pr_err("Usage: devlink dev show [ DEV ]\n");
pr_err(" devlink dev eswitch set DEV [ mode { legacy | switchdev } ]\n");
pr_err(" [ inline-mode { none | link | network | transport } ]\n");
- pr_err(" [ encap { disable | enable } ]\n");
+ pr_err(" [ encap-mode { none | basic } ]\n");
pr_err(" devlink dev eswitch show DEV\n");
pr_err(" devlink dev param set DEV name PARAMETER value VALUE cmode { permanent | driverinit | runtime }\n");
pr_err(" devlink dev param show [DEV name PARAMETER]\n");
@@ -2105,6 +2116,18 @@ static const char *eswitch_inline_mode_name(uint32_t mode)
}
}
+static const char *eswitch_encap_mode_name(uint32_t mode)
+{
+ switch (mode) {
+ case DEVLINK_ESWITCH_ENCAP_MODE_NONE:
+ return ESWITCH_ENCAP_MODE_NONE;
+ case DEVLINK_ESWITCH_ENCAP_MODE_BASIC:
+ return ESWITCH_ENCAP_MODE_BASIC;
+ default:
+ return "<unknown mode>";
+ }
+}
+
static void pr_out_eswitch(struct dl *dl, struct nlattr **tb)
{
__pr_out_handle_start(dl, tb, true, false);
@@ -2122,11 +2145,10 @@ static void pr_out_eswitch(struct dl *dl, struct nlattr **tb)
tb[DEVLINK_ATTR_ESWITCH_INLINE_MODE])));
}
if (tb[DEVLINK_ATTR_ESWITCH_ENCAP_MODE]) {
- bool encap_mode = !!mnl_attr_get_u8(tb[DEVLINK_ATTR_ESWITCH_ENCAP_MODE]);
-
check_indent_newline(dl);
- print_string(PRINT_ANY, "encap", "encap %s",
- encap_mode ? "enable" : "disable");
+ print_string(PRINT_ANY, "encap-mode", "encap-mode %s",
+ eswitch_encap_mode_name(mnl_attr_get_u8(
+ tb[DEVLINK_ATTR_ESWITCH_ENCAP_MODE])));
}
pr_out_handle_end(dl);
diff --git a/man/man8/devlink-dev.8 b/man/man8/devlink-dev.8
index 289935dbcac9..ac01bf603a44 100644
--- a/man/man8/devlink-dev.8
+++ b/man/man8/devlink-dev.8
@@ -35,7 +35,7 @@ devlink-dev \- devlink device configuration
.BR inline-mode " { " none " | " link " | " network " | " transport " } "
.RI "]"
.RI "[ "
-.BR encap " { " disable " | " enable " } "
+.BR encap-mode " { " none " | " basic " } "
.RI "]"
.ti -8
@@ -125,13 +125,13 @@ Some HWs need the VF driver to put part of the packet headers on the TX descript
- L4 mode
.TP
-.BR encap " { " disable " | " enable " } "
+.BR encap-mode " { " none " | " basic " } "
Set eswitch encapsulation support
-.I disable
+.I none
- Disable encapsulation support
-.I enable
+.I basic
- Enable encapsulation support
.SS devlink dev param set - set new value to devlink device configuration parameter
--
2.21.1
next prev parent reply other threads:[~2020-04-04 16:16 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-04 16:16 [patch iproute2/net-next 0/8] devlink: spring cleanup Jiri Pirko
2020-04-04 16:16 ` [patch iproute2/net-next 1/8] devlink: remove custom bool command line options parsing Jiri Pirko
2020-04-04 16:16 ` [patch iproute2/net-next 2/8] devlink: Fix help and man of "devlink health set" command Jiri Pirko
2020-04-04 16:16 ` Jiri Pirko [this message]
2020-04-04 16:16 ` [patch iproute2/net-next 4/8] devlink: Add alias "counters_enabled" for "counters" option Jiri Pirko
2020-04-04 16:16 ` [patch iproute2/net-next 5/8] devlink: rename dpipe_counters_enable struct field to dpipe_counters_enabled Jiri Pirko
2020-04-04 16:16 ` [patch iproute2/net-next 6/8] devlink: Fix help message for dpipe Jiri Pirko
2020-04-04 16:16 ` [patch iproute2/net-next 7/8] devlink: remove "dev" object sub help messages Jiri Pirko
2020-04-04 16:16 ` [patch iproute2/net-next 8/8] man: add man page for devlink dpipe Jiri Pirko
2020-04-06 17:30 ` Stephen Hemminger
2020-04-06 18:06 ` Jiri Pirko
2020-04-06 2:21 ` [patch iproute2/net-next 0/8] devlink: spring cleanup Stephen Hemminger
2020-04-06 6:53 ` Jiri Pirko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200404161621.3452-4-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=dsahern@gmail.com \
--cc=mlxsw@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).