From: Nikolay Aleksandrov <razor@blackwall.org>
To: netdev@vger.kernel.org
Cc: roopa@nvidia.com, dsahern@gmail.com,
Nikolay Aleksandrov <nikolay@nvidia.com>
Subject: [PATCH iproute2-next 2/6] bridge: add parse_stp_state helper
Date: Sun, 18 Apr 2021 15:01:33 +0300 [thread overview]
Message-ID: <20210418120137.2605522-3-razor@blackwall.org> (raw)
In-Reply-To: <20210418120137.2605522-1-razor@blackwall.org>
From: Nikolay Aleksandrov <nikolay@nvidia.com>
Add a helper which parses an STP state string to its numeric value.
Signed-off-by: Nikolay Aleksandrov <nikolay@nvidia.com>
---
bridge/br_common.h | 1 +
bridge/link.c | 22 +++++++++++++++++-----
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/bridge/br_common.h b/bridge/br_common.h
index e3f46765ab89..33e56452702b 100644
--- a/bridge/br_common.h
+++ b/bridge/br_common.h
@@ -11,6 +11,7 @@ int print_linkinfo(struct nlmsghdr *n, void *arg);
int print_mdb_mon(struct nlmsghdr *n, void *arg);
int print_fdb(struct nlmsghdr *n, void *arg);
void print_stp_state(__u8 state);
+int parse_stp_state(const char *arg);
int do_fdb(int argc, char **argv);
int do_mdb(int argc, char **argv);
diff --git a/bridge/link.c b/bridge/link.c
index a8cfa1814986..205a2fe79c1a 100644
--- a/bridge/link.c
+++ b/bridge/link.c
@@ -78,6 +78,21 @@ void print_stp_state(__u8 state)
"state (%d) ", state);
}
+int parse_stp_state(const char *arg)
+{
+ size_t nstates = ARRAY_SIZE(stp_states);
+ int state;
+
+ for (state = 0; state < nstates; state++)
+ if (strcmp(stp_states[state], arg) == 0)
+ break;
+
+ if (state == nstates)
+ state = -1;
+
+ return state;
+}
+
static void print_hwmode(__u16 mode)
{
if (mode >= ARRAY_SIZE(hw_mode))
@@ -359,14 +374,11 @@ static int brlink_modify(int argc, char **argv)
} else if (strcmp(*argv, "state") == 0) {
NEXT_ARG();
char *endptr;
- size_t nstates = ARRAY_SIZE(stp_states);
state = strtol(*argv, &endptr, 10);
if (!(**argv != '\0' && *endptr == '\0')) {
- for (state = 0; state < nstates; state++)
- if (strcasecmp(stp_states[state], *argv) == 0)
- break;
- if (state == nstates) {
+ state = parse_stp_state(*argv);
+ if (state == -1) {
fprintf(stderr,
"Error: invalid STP port state\n");
return -1;
--
2.30.2
next prev parent reply other threads:[~2021-04-18 12:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-18 12:01 [PATCH iproute2-next 0/6] bridge: vlan: add per-vlan options support Nikolay Aleksandrov
2021-04-18 12:01 ` [PATCH iproute2-next 1/6] bridge: rename and export print_portstate Nikolay Aleksandrov
2021-04-18 12:01 ` Nikolay Aleksandrov [this message]
2021-04-18 12:01 ` [PATCH iproute2-next 3/6] bridge: vlan: add option set command and state option Nikolay Aleksandrov
2021-04-18 12:01 ` [PATCH iproute2-next 4/6] libnetlink: add bridge vlan dump request helper Nikolay Aleksandrov
2021-04-18 12:01 ` [PATCH iproute2-next 5/6] bridge: vlan: add support for the new rtm dump call Nikolay Aleksandrov
2021-04-18 12:01 ` [PATCH iproute2-next 6/6] bridge: monitor: add support for vlan monitoring Nikolay Aleksandrov
2021-04-22 5:21 ` [PATCH iproute2-next 0/6] bridge: vlan: add per-vlan options support David Ahern
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=20210418120137.2605522-3-razor@blackwall.org \
--to=razor@blackwall.org \
--cc=dsahern@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=nikolay@nvidia.com \
--cc=roopa@nvidia.com \
/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).