netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Pilon <alp@alexpilon.ca>
To: netdev@vger.kernel.org
Subject: [PATCH] Allow specifying bridge port STP state by name rather than number.
Date: Thu, 19 Feb 2015 14:27:46 -0500	[thread overview]
Message-ID: <20150219192726.GA17950@alexpilon.ca> (raw)

The existing behaviour forces one to memorize the integer constants for
STP port states.

    # bridge link set dev dummy0 state 3

This patch makes it possible to use the lowercased port state name.

    # bridge link set dev dummy0 state forwarding

Invalid non-integer inputs now cause exit with status -1.

Signed-off-by: Alex Pilon <alp@alexpilon.ca>
---
 bridge/link.c     | 14 +++++++++++++-
 man/man8/bridge.8 |  4 +++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/bridge/link.c b/bridge/link.c
index c8555f8..a7bd85f 100644
--- a/bridge/link.c
+++ b/bridge/link.c
@@ -316,7 +316,19 @@ static int brlink_modify(int argc, char **argv)
 			priority = atoi(*argv);
 		} else if (strcmp(*argv, "state") == 0) {
 			NEXT_ARG();
-			state = atoi(*argv);
+			char *endptr;
+			size_t nstates = sizeof(port_states) / sizeof(*port_states);
+			state = strtol(*argv, &endptr, 10);
+			if (!(**argv != '\0' && *endptr == '\0')) {
+				for (state = 0; state < nstates; state++)
+					if (strcmp(port_states[state], *argv) == 0)
+						break;
+				if (state == nstates) {
+					fprintf(stderr,
+						"Error: invalid STP port state\n");
+					exit(-1);
+				}
+			}
 		} else if (strcmp(*argv, "hwmode") == 0) {
 			NEXT_ARG();
 			flags = BRIDGE_FLAGS_SELF;
diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
index e344db2..68ad71e 100644
--- a/man/man8/bridge.8
+++ b/man/man8/bridge.8
@@ -207,7 +207,9 @@ droot port selectio algorithms.
 .TP
 .BI state " STATE "
 the operation state of the port.  This is primarily used by user space STP/RSTP
-implementation.  The following is a list of valid values:
+implementation.  One may enter a lowercased port state name, or one of the
+numbers below.  Negative inputs are ignored, and unrecognized names return an
+error.
 
 .B 0
 - port is DISABLED.  Make this port completely inactive.
-- 
2.3.0

             reply	other threads:[~2015-02-19 19:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-19 19:27 Alex Pilon [this message]
2015-02-20  2:00 ` [PATCH] Allow specifying bridge port STP state by name rather than number Jonathon Reinhart
2015-02-20  4:57   ` Alex Pilon
2015-02-20 14:40     ` Jonathon Reinhart

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=20150219192726.GA17950@alexpilon.ca \
    --to=alp@alexpilon.ca \
    --cc=netdev@vger.kernel.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).