]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
Allow specifying bridge port STP state by name rather than number.
authorAlex Pilon <alp@alexpilon.ca>
Thu, 19 Feb 2015 19:27:46 +0000 (14:27 -0500)
committerStephen Hemminger <shemming@brocade.com>
Tue, 24 Feb 2015 23:59:44 +0000 (15:59 -0800)
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
man/man8/bridge.8

index c8555f82d5b41c4ffaef1446f41b16d6a5098c23..a7bd85f9d3b57463943856e81ef949d47474c294 100644 (file)
@@ -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;
index e344db285fb2efcfc115ee66742d5f9160318edc..68ad71e5d8b4675591ac7cf971f5b4122d558aee 100644 (file)
@@ -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.