diff options
author | Jiri Pirko <jiri@mellanox.com> | 2020-04-04 18:16:14 +0200 |
---|---|---|
committer | Stephen Hemminger <stephen@networkplumber.org> | 2020-04-06 10:00:32 -0700 |
commit | b37a863cb2d09ad0736334bd6606c05b802c85cf (patch) | |
tree | fe56bcde1aac1d7a27a591ef6bd5515953556f00 | |
parent | 5d10f24fddb6352526a061a829e73b2a8bcd5425 (diff) | |
download | iproute2-b37a863cb2d09ad0736334bd6606c05b802c85cf.tar.gz |
devlink: remove custom bool command line options parsing
Change the code that is doing custom processing of boolean command line
options to use dl_argv_bool(). Extend strtobool() to accept
"enable"/"disable" to maintain current behavior.
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
-rw-r--r-- | devlink/devlink.c | 28 |
1 files changed, 5 insertions, 23 deletions
diff --git a/devlink/devlink.c b/devlink/devlink.c index 6405d4be7..ce6e349ed 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -739,9 +739,11 @@ static int strtobool(const char *str, bool *p_val) { bool val; - if (!strcmp(str, "true") || !strcmp(str, "1")) + if (!strcmp(str, "true") || !strcmp(str, "1") || + !strcmp(str, "enable")) val = true; - else if (!strcmp(str, "false") || !strcmp(str, "0")) + else if (!strcmp(str, "false") || !strcmp(str, "0") || + !strcmp(str, "disable")) val = false; else return -EINVAL; @@ -1076,20 +1078,6 @@ static int eswitch_inline_mode_get(const char *typestr, return 0; } -static int dpipe_counters_enable_get(const char *typestr, - bool *counters_enable) -{ - if (strcmp(typestr, "enable") == 0) { - *counters_enable = 1; - } else if (strcmp(typestr, "disable") == 0) { - *counters_enable = 0; - } else { - pr_err("Unknown counter_state \"%s\"\n", typestr); - return -EINVAL; - } - return 0; -} - static int eswitch_encap_mode_get(const char *typestr, bool *p_mode) { if (strcmp(typestr, "enable") == 0) { @@ -1336,14 +1324,8 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required, o_found |= DL_OPT_DPIPE_TABLE_NAME; } else if (dl_argv_match(dl, "counters") && (o_all & DL_OPT_DPIPE_TABLE_COUNTERS)) { - const char *typestr; - dl_arg_inc(dl); - err = dl_argv_str(dl, &typestr); - if (err) - return err; - err = dpipe_counters_enable_get(typestr, - &opts->dpipe_counters_enable); + err = dl_argv_bool(dl, &opts->dpipe_counters_enable); if (err) return err; o_found |= DL_OPT_DPIPE_TABLE_COUNTERS; |