brctl: fold show_bridge_ports_ into its caller

function                                             old     new   delta
brctl_main                                          2235    2171     -64

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2019-10-12 19:42:37 +02:00
parent 3398753818
commit b4fa16d5ed

View File

@ -390,28 +390,6 @@ static void show_bridge_port(const char *name)
printf("\n\n");
}
static void show_bridge_ports(const char *name)
{
DIR *ifaces;
struct dirent *ent;
char pathbuf[IFNAMSIZ + sizeof("/brif") + 8];
#if IFNAMSIZ == 16
sprintf(pathbuf, "%.16s/brif", name);
#else
sprintf(pathbuf, "%.*s/brif", (int)IFNAMSIZ, name);
#endif
ifaces = opendir(pathbuf);
if (ifaces) {
while ((ent = readdir(ifaces)) != NULL) {
if (DOT_OR_DOTDOT(ent->d_name))
continue; /* . or .. */
show_bridge_port(ent->d_name);
}
closedir(ifaces);
}
}
static void show_bridge_stp(const char *name)
{
char pathbuf[IFNAMSIZ + sizeof("/bridge/topology_change_timer") + 8];
@ -490,7 +468,24 @@ static void show_bridge_stp(const char *name)
printf("TOPOLOGY_CHANGE_DETECTED ");
printf("\n\n\n");
show_bridge_ports(name);
/* Show bridge ports */
{
DIR *ifaces;
/* sfx points past "BR/bridge/", turn it to "BR/brif": */
strcpy(sfx - 4, "f");
ifaces = opendir(pathbuf);
if (ifaces) {
struct dirent *ent;
while ((ent = readdir(ifaces)) != NULL) {
if (DOT_OR_DOTDOT(ent->d_name))
continue; /* . or .. */
show_bridge_port(ent->d_name);
}
if (ENABLE_FEATURE_CLEAN_UP)
closedir(ifaces);
}
}
}
#endif
@ -519,6 +514,8 @@ int brctl_main(int argc UNUSED_PARAM, char **argv)
)
IF_FEATURE_BRCTL_SHOW(, ARG_show)
};
int key;
char *br;
argv++;
if (!*argv) {
@ -528,11 +525,6 @@ int brctl_main(int argc UNUSED_PARAM, char **argv)
xchdir("/sys/class/net");
// while (*argv)
{
smallint key;
char *br;
key = index_in_strings(keywords, *argv);
if (key == -1) /* no match found in keywords array, bail out. */
bb_error_msg_and_die(bb_msg_invalid_arg_to, *argv, applet_name);
@ -580,7 +572,6 @@ int brctl_main(int argc UNUSED_PARAM, char **argv)
br = *argv++;
if (key == ARG_addbr || key == ARG_delbr) {
/* addbr or delbr */
/* brctl from bridge-utils 1.6 still uses ioctl
* for SIOCBRADDBR / SIOCBRDELBR, not /sys accesses
*/
@ -612,7 +603,7 @@ int brctl_main(int argc UNUSED_PARAM, char **argv)
bb_show_usage();
#if ENABLE_FEATURE_BRCTL_FANCY
if (key == ARG_stp) { /* stp */
if (key == ARG_stp) {
static const char no_yes[] ALIGN1 =
"0\0" "off\0" "n\0" "no\0" /* 0 .. 3 */
"1\0" "on\0" "y\0" "yes\0"; /* 4 .. 7 */
@ -671,7 +662,6 @@ int brctl_main(int argc UNUSED_PARAM, char **argv)
}
#endif
/* always true: if (key == ARG_addif || key == ARG_delif) */ {
/* addif or delif */
struct ifreq ifr;
int fd = xsocket(AF_INET, SOCK_STREAM, 0);
@ -686,8 +676,6 @@ int brctl_main(int argc UNUSED_PARAM, char **argv)
);
if (ENABLE_FEATURE_CLEAN_UP)
close(fd);
return EXIT_SUCCESS;
}
}
return EXIT_SUCCESS;