diff options
author | Jiri Pirko <jiri@mellanox.com> | 2020-04-04 18:16:16 +0200 |
---|---|---|
committer | Stephen Hemminger <stephen@networkplumber.org> | 2020-04-06 10:00:32 -0700 |
commit | 0b1875cdc69f49184445781a62e0bf603bdfc414 (patch) | |
tree | 016d267d0f35763f276a3bd2764218691435f01d | |
parent | 90ce848b05fc1883ddafcf57af4c7fcbafd85833 (diff) | |
download | iproute2-0b1875cdc69f49184445781a62e0bf603bdfc414.tar.gz |
devlink: fix encap mode manupulation
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>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
-rw-r--r-- | bash-completion/devlink | 8 | ||||
-rw-r--r-- | devlink/devlink.c | 46 | ||||
-rw-r--r-- | man/man8/devlink-dev.8 | 8 |
3 files changed, 42 insertions, 20 deletions
diff --git a/bash-completion/devlink b/bash-completion/devlink index 45ca1fe62..8518e7aa3 100644 --- a/bash-completion/devlink +++ b/bash-completion/devlink @@ -105,11 +105,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 @@ -132,8 +132,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 6a4108108..6a24f28fa 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" @@ -284,7 +287,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; @@ -1078,12 +1081,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; @@ -1329,7 +1339,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; @@ -1700,7 +1711,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"); @@ -2130,6 +2141,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); @@ -2147,11 +2170,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 289935dbc..ac01bf603 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 |