aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
Diffstat (limited to 'networking')
-rw-r--r--networking/brctl.c69
1 files changed, 38 insertions, 31 deletions
diff --git a/networking/brctl.c b/networking/brctl.c
index bbd14c471..2bb03dd82 100644
--- a/networking/brctl.c
+++ b/networking/brctl.c
@@ -33,13 +33,15 @@
#if ENABLE_FEATURE_BRCTL_FANCY
#include <linux/if_bridge.h>
+
/* FIXME: These 4 funcs are not really clean and could be improved */
-static inline ALWAYS_INLINE void strtotimeval(struct timeval *tv,
- const char *time_str)
+static ALWAYS_INLINE void strtotimeval(struct timeval *tv,
+ const char *time_str)
{
double secs;
#if BRCTL_USE_INTERNAL
- if (!(secs = /*bb_*/strtod(time_str, NULL)))
+ secs = /*bb_*/strtod(time_str, NULL);
+ if (!secs)
#else
if (sscanf(time_str, "%lf", &secs) != 1)
#endif
@@ -48,7 +50,7 @@ static inline ALWAYS_INLINE void strtotimeval(struct timeval *tv,
tv->tv_usec = 1000000 * (secs - tv->tv_sec);
}
-static inline 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;
@@ -56,7 +58,7 @@ static inline ALWAYS_INLINE unsigned long __tv_to_jiffies(const struct timeval *
return jif/10000;
}
-# if 00
+# if 0
static void __jiffies_to_tv(struct timeval *tv, unsigned long jiffies)
{
unsigned long long tvusec;
@@ -74,7 +76,7 @@ static unsigned long str_to_jiffies(const char *time_str)
}
static void arm_ioctl(unsigned long *args,
- unsigned long arg0, unsigned long arg1, unsigned long arg2)
+ unsigned long arg0, unsigned long arg1, unsigned long arg2)
{
args[0] = arg0;
args[1] = arg1;
@@ -84,10 +86,9 @@ static void arm_ioctl(unsigned long *args,
#endif
-int brctl_main(int argc ATTRIBUTE_UNUSED, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int brctl_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int brctl_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
- int fd;
static const char keywords[] ALIGN1 =
"addbr\0" "delbr\0" "addif\0" "delif\0"
USE_FEATURE_BRCTL_FANCY(
@@ -96,16 +97,19 @@ int brctl_main(int argc ATTRIBUTE_UNUSED, char **argv)
"setpathcost\0" "setportprio\0" "setbridgeprio\0"
)
USE_FEATURE_BRCTL_SHOW("showmacs\0" "show\0");
+
enum { ARG_addbr = 0, ARG_delbr, ARG_addif, ARG_delif
USE_FEATURE_BRCTL_FANCY(,
ARG_stp,
ARG_setageing, ARG_setfd, ARG_sethello, ARG_setmaxage,
ARG_setpathcost, ARG_setportprio, ARG_setbridgeprio
)
- USE_FEATURE_BRCTL_SHOW(, ARG_showmacs, ARG_show) };
+ USE_FEATURE_BRCTL_SHOW(, ARG_showmacs, ARG_show)
+ };
+
+ int fd;
smallint key;
struct ifreq ifr;
- static char info[] = "bridge %s\0 iface %s";
char *br, *brif;
#if ENABLE_FEATURE_BRCTL_FANCY
unsigned long args[4] = {0, 0, 0, 0};
@@ -125,25 +129,26 @@ int brctl_main(int argc ATTRIBUTE_UNUSED, char **argv)
}
#endif
fd = xsocket(AF_INET, SOCK_STREAM, 0);
- br = *(argv++);
+ br = *argv++;
if (key == ARG_addbr || key == ARG_delbr) { /* addbr or delbr */
ioctl_or_perror_and_die(fd,
- key == ARG_addbr ? SIOCBRADDBR : SIOCBRDELBR,
- br, info, br);
+ key == ARG_addbr ? SIOCBRADDBR : SIOCBRDELBR,
+ br, "bridge %s", br);
goto done;
}
if (!*argv) /* all but 'show' need at least one argument */
bb_show_usage();
safe_strncpy(ifr.ifr_name, br, IFNAMSIZ);
if (key == ARG_addif || key == ARG_delif) { /* addif or delif */
- brif = *(argv++);
- if (!(ifr.ifr_ifindex = if_nametoindex(brif))) {
- bb_perror_msg_and_die(info+11, brif);
+ brif = *argv++;
+ ifr.ifr_ifindex = if_nametoindex(brif);
+ if (!ifr.ifr_ifindex) {
+ bb_perror_msg_and_die("iface %s", brif);
}
ioctl_or_perror_and_die(fd,
- key == ARG_addif ? SIOCBRADDIF : SIOCBRDELIF,
- &ifr, info, br);
+ key == ARG_addif ? SIOCBRADDIF : SIOCBRDELIF,
+ &ifr, "bridge %s", br);
goto done;
}
#if ENABLE_FEATURE_BRCTL_FANCY
@@ -156,11 +161,10 @@ int brctl_main(int argc ATTRIBUTE_UNUSED, char **argv)
}
if ((unsigned)(key - ARG_stp) < 5) { /* time related ops */
unsigned long op = (key == ARG_setageing) ? BRCTL_SET_AGEING_TIME :
- (key == ARG_setfd) ? BRCTL_SET_BRIDGE_FORWARD_DELAY:
- (key == ARG_sethello) ? BRCTL_SET_BRIDGE_HELLO_TIME:
- (key == ARG_setmaxage) ? BRCTL_SET_BRIDGE_MAX_AGE :
- -1/* will never be used */;
- arm_ioctl(args, op, str_to_jiffies (*argv), 0);
+ (key == ARG_setfd) ? BRCTL_SET_BRIDGE_FORWARD_DELAY :
+ (key == ARG_sethello) ? BRCTL_SET_BRIDGE_HELLO_TIME :
+ /*key == ARG_setmaxage*/ BRCTL_SET_BRIDGE_MAX_AGE;
+ arm_ioctl(args, op, str_to_jiffies(*argv), 0);
goto fire;
}
port = -1;
@@ -168,25 +172,28 @@ int brctl_main(int argc ATTRIBUTE_UNUSED, char **argv)
int ifidx[MAX_PORTS];
unsigned i;
- if (!(port = if_nametoindex(*argv)))
+ port = if_nametoindex(*argv);
+ if (!port)
bb_error_msg_and_die(bb_msg_invalid_arg, *argv, "port");
argv++;
memset(ifidx, 0, sizeof ifidx);
arm_ioctl(args, BRCTL_GET_PORT_LIST, (unsigned long)ifidx,
MAX_PORTS);
xioctl(fd, SIOCDEVPRIVATE, &ifr);
- for (i = 0; i < MAX_PORTS; i++)
+ for (i = 0; i < MAX_PORTS; i++) {
if (ifidx[i] == port) {
port = i;
break;
}
+ }
}
if (key == ARG_setpathcost
- || key == ARG_setportprio || key == ARG_setbridgeprio) {
+ || key == ARG_setportprio
+ || key == ARG_setbridgeprio
+ ) {
unsigned long op = (key == ARG_setpathcost) ? BRCTL_SET_PATH_COST :
- (key == ARG_setportprio) ? BRCTL_SET_PORT_PRIORITY :
- (key == ARG_setbridgeprio) ? BRCTL_SET_BRIDGE_PRIORITY :
- -1/* will never be used */;
+ (key == ARG_setportprio) ? BRCTL_SET_PORT_PRIORITY :
+ /*key == ARG_setbridgeprio*/ BRCTL_SET_BRIDGE_PRIORITY;
unsigned long arg1 = port;
unsigned long arg2;
# if BRCTL_USE_INTERNAL
@@ -194,7 +201,7 @@ int brctl_main(int argc ATTRIBUTE_UNUSED, char **argv)
# else
if (sscanf(*argv, "%i", &tmp) != 1)
bb_error_msg_and_die(bb_msg_invalid_arg, *argv,
- key == ARG_setpathcost ? "cost" : "prio");
+ key == ARG_setpathcost ? "cost" : "prio");
# endif
if (key == ARG_setbridgeprio) {
arg1 = tmp;
@@ -212,6 +219,6 @@ int brctl_main(int argc ATTRIBUTE_UNUSED, char **argv)
if (ENABLE_FEATURE_CLEAN_UP)
close(fd);
}
-USE_FEATURE_BRCTL_SHOW(out:)
+ USE_FEATURE_BRCTL_SHOW(out:)
return EXIT_SUCCESS;
}