brctl: fixing stp parameters incompatibility
authorMaciek Borzecki <maciek.borzecki@gmail.com>
Tue, 23 Mar 2010 04:18:38 +0000 (05:18 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 23 Mar 2010 04:18:38 +0000 (05:18 +0100)
function                                             old     new   delta
static.stp_opts                                        -      23     +23
brctl_main                                          1148    1169     +21
packed_usage                                       26786   26794      +8
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/0 up/down: 52/0)               Total: 52 bytes

Signed-off-by: Maciek Borzecki <maciek.borzecki@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
include/usage.h
networking/brctl.c

index a7855cdf4a2f2ffa78835dda61b704b21358874d..40cb6b2bbeffb004c82cbd15a7beceec57fd2f71 100644 (file)
      "\n       setpathcost BRIDGE COST         Set path cost" \
      "\n       setportprio BRIDGE PRIO         Set port priority" \
      "\n       setbridgeprio BRIDGE PRIO       Set bridge priority" \
-     "\n       stp BRIDGE [1|0]                STP on/off" \
+     "\n       stp BRIDGE [1/yes/on|0/no/off]  STP on/off" \
        ) \
 
 #define bunzip2_trivial_usage \
index e062dabb8145049f6529814576fad7cc05580fb7..023518a26f54fa1baf502893e9430c747e2b90e1 100644 (file)
@@ -32,7 +32,7 @@
 
 /* Maximum number of ports supported per bridge interface.  */
 #ifndef MAX_PORTS
-#define MAX_PORTS 32
+# define MAX_PORTS 32
 #endif
 
 /* Use internal number parsing and not the "exact" conversion.  */
 #define BRCTL_USE_INTERNAL 1
 
 #if ENABLE_FEATURE_BRCTL_FANCY
-#include <linux/if_bridge.h>
+# include <linux/if_bridge.h>
 
 /* FIXME: These 4 funcs are not really clean and could be improved */
 static ALWAYS_INLINE void strtotimeval(struct timeval *tv,
                const char *time_str)
 {
        double secs;
-#if BRCTL_USE_INTERNAL
+# if BRCTL_USE_INTERNAL
        char *endptr;
        secs = /*bb_*/strtod(time_str, &endptr);
        if (endptr == time_str)
-#else
+# else
        if (sscanf(time_str, "%lf", &secs) != 1)
-#endif
-               bb_error_msg_and_die (bb_msg_invalid_arg, time_str, "timespec");
+# endif
+               bb_error_msg_and_die(bb_msg_invalid_arg, time_str, "timespec");
        tv->tv_sec = secs;
        tv->tv_usec = 1000000 * (secs - tv->tv_sec);
 }
 
-static ALWAYS_INLINE unsigned long __tv_to_jiffies(const struct timeval *tv)
+static ALWAYS_INLINE unsigned long tv_to_jiffies(const struct timeval *tv)
 {
        unsigned long long jif;
 
@@ -68,7 +68,7 @@ static ALWAYS_INLINE unsigned long __tv_to_jiffies(const struct timeval *tv)
        return jif/10000;
 }
 # if 0
-static void __jiffies_to_tv(struct timeval *tv, unsigned long jiffies)
+static void jiffies_to_tv(struct timeval *tv, unsigned long jiffies)
 {
        unsigned long long tvusec;
 
@@ -81,7 +81,7 @@ static unsigned long str_to_jiffies(const char *time_str)
 {
        struct timeval tv;
        strtotimeval(&tv, time_str);
-       return __tv_to_jiffies(&tv);
+       return tv_to_jiffies(&tv);
 }
 
 static void arm_ioctl(unsigned long *args,
@@ -220,9 +220,14 @@ int brctl_main(int argc UNUSED_PARAM, char **argv)
                }
 #if ENABLE_FEATURE_BRCTL_FANCY
                if (key == ARG_stp) { /* stp */
-                       /* FIXME: parsing yes/y/on/1 versus no/n/off/0 is too involved */
-                       arm_ioctl(args, BRCTL_SET_BRIDGE_STP_STATE,
-                                         (unsigned)(**argv - '0'), 0);
+                       static const char stp_opts[] ALIGN1 =
+                               "0\0" "off\0" "n\0" "no\0"   /* 0 .. 3 */
+                               "1\0" "on\0"  "y\0" "yes\0"; /* 4 .. 7 */
+                       int onoff = index_in_strings(stp_opts, *argv);
+                       if (onoff < 0)
+                               bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
+                       onoff = (unsigned)onoff / 4;
+                       arm_ioctl(args, BRCTL_SET_BRIDGE_STP_STATE, onoff, 0);
                        goto fire;
                }
                if ((unsigned)(key - ARG_setageing) < 4) { /* time related ops */