From b2050baf30c4c1a9e6aa4142a340dd9e9f5b0d1b Mon Sep 17 00:00:00 2001 From: John Fastabend Date: Wed, 27 Jul 2011 15:07:11 -0700 Subject: [PATCH 12/29] lldpad: 802.1Qaz, make ETS-CFG willing {yes|no} values valid Currently, the willing option to ETS-CFG takes a 0 or 1 value while all other attributes use "yes" or "no". So make ETS-CFG willing follow the trend and use "yes" or "no" as well. Signed-off-by: John Fastabend Signed-off-by: Petr Sabata --- docs/lldptool-ets.8 | 4 ++-- lldp_8021qaz_cmds.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/docs/lldptool-ets.8 b/docs/lldptool-ets.8 index 2b76b9c..16fdba9 100644 --- a/docs/lldptool-ets.8 +++ b/docs/lldptool-ets.8 @@ -19,7 +19,7 @@ ETS-{CFG|REC} \- Show / manipulate ETS TLV configuration .sp .BR enableTx " = " {yes|no} " | " .sp -.BR willing " = " {0|1} " | " +.BR willing " = " {yes|no} " | " .sp .BR tsa " = " tc:{ets|strict|vendor},... " | " .sp @@ -107,7 +107,7 @@ have support for specific protocols ie Fiber Channel over Ethernet (FCoE). .SH EXAMPLE & USAGE .TP Configure willing bit for interface \fIeth2\fR -.B lldptool -T -i eth2 -V ETS-CFG willing=1 +.B lldptool -T -i eth2 -V ETS-CFG willing=yes .TP Configure traffic classes for ETS and strict priority on \fIeth2\fR .B lldptool -T -i eth2 -V ETS-CFG tsa=0:ets,1:ets,2:ets,3:ets,4:strict,5:strict diff --git a/lldp_8021qaz_cmds.c b/lldp_8021qaz_cmds.c index 1ee733e..4dd8042 100644 --- a/lldp_8021qaz_cmds.c +++ b/lldp_8021qaz_cmds.c @@ -142,7 +142,7 @@ static int get_arg_willing(struct cmd *cmd, char *args, static int _set_arg_willing(struct cmd *cmd, char *args, char *arg_value, char *obuf, int obuf_len, bool test) { - long willing = strtol(arg_value, NULL, 10); + long willing; struct ieee8021qaz_tlvs *tlvs; char arg_path[256]; @@ -153,6 +153,29 @@ static int _set_arg_willing(struct cmd *cmd, char *args, if (!tlvs) return cmd_device_not_found; + + + /* To remain backward compatible and make it easier + * for everyone use to {0|1} notation we still support + * this but also support english variants as well + */ + if (!strcasecmp(arg_value, VAL_YES)) + willing = 1; + else if (!strcasecmp(arg_value, VAL_NO)) + willing = 0; + else { + char *end; + + errno = 0; + willing = strtol(arg_value, &end, 10); + + if (end == arg_value || *end != '\0') + return cmd_invalid; + + if (errno || willing < 0) + return cmd_invalid; + } + switch (cmd->tlvid) { case (OUI_IEEE_8021 << 8) | LLDP_8021QAZ_ETSCFG: if (!test) @@ -171,7 +194,8 @@ static int _set_arg_willing(struct cmd *cmd, char *args, if (test) return cmd_success; - snprintf(obuf, obuf_len, "willing = %i\n", !!willing); + snprintf(obuf, obuf_len, "willing = %s\n", + !!willing ? VAL_YES : VAL_NO); snprintf(arg_path, sizeof(arg_path), "%s%08x.%s", TLVID_PREFIX, cmd->tlvid, args); -- 1.7.6