iplink: shrink

function                                             old     new   delta
do_change                                            490     487      -3
ipaddr_list_link                                      18       -     -18
do_iplink                                           1169    1113     -56
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/2 up/down: 0/-77)             Total: -77 bytes

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
This commit is contained in:
Bernhard Reutner-Fischer 2010-05-25 16:16:28 +02:00
parent 6faebfa663
commit d148e484db

View File

@ -186,56 +186,48 @@ static int do_set(char **argv)
if (key == ARG_up) { if (key == ARG_up) {
mask |= IFF_UP; mask |= IFF_UP;
flags |= IFF_UP; flags |= IFF_UP;
} } else if (key == ARG_down) {
if (key == ARG_down) {
mask |= IFF_UP; mask |= IFF_UP;
flags &= ~IFF_UP; flags &= ~IFF_UP;
} } else if (key == ARG_name) {
if (key == ARG_name) {
NEXT_ARG(); NEXT_ARG();
newname = *argv; newname = *argv;
} } else if (key == ARG_mtu) {
if (key == ARG_mtu) {
NEXT_ARG(); NEXT_ARG();
if (mtu != -1) if (mtu != -1)
duparg("mtu", *argv); duparg("mtu", *argv);
mtu = get_unsigned(*argv, "mtu"); mtu = get_unsigned(*argv, "mtu");
} } else if (key == ARG_addr) {
if (key == ARG_multicast) {
int param;
NEXT_ARG();
mask |= IFF_MULTICAST;
param = index_in_strings(str_on_off, *argv);
if (param < 0)
die_must_be_on_off("multicast");
if (param == PARM_on)
flags |= IFF_MULTICAST;
else
flags &= ~IFF_MULTICAST;
}
if (key == ARG_arp) {
int param;
NEXT_ARG();
mask |= IFF_NOARP;
param = index_in_strings(str_on_off, *argv);
if (param < 0)
die_must_be_on_off("arp");
if (param == PARM_on)
flags &= ~IFF_NOARP;
else
flags |= IFF_NOARP;
}
if (key == ARG_addr) {
NEXT_ARG(); NEXT_ARG();
newaddr = *argv; newaddr = *argv;
} } else if (key >= ARG_dev) {
if (key >= ARG_dev) {
if (key == ARG_dev) { if (key == ARG_dev) {
NEXT_ARG(); NEXT_ARG();
} }
if (dev) if (dev)
duparg2("dev", *argv); duparg2("dev", *argv);
dev = *argv; dev = *argv;
} else {
int param;
NEXT_ARG();
param = index_in_strings(str_on_off, *argv);
if (key == ARG_multicast) {
if (param < 0)
die_must_be_on_off("multicast");
mask |= IFF_MULTICAST;
if (param == PARM_on)
flags |= IFF_MULTICAST;
else
flags &= ~IFF_MULTICAST;
} else if (key == ARG_arp) {
if (param < 0)
die_must_be_on_off("arp");
mask |= IFF_NOARP;
if (param == PARM_on)
flags &= ~IFF_NOARP;
else
flags |= IFF_NOARP;
}
} }
argv++; argv++;
} }
@ -248,9 +240,11 @@ static int do_set(char **argv)
halen = get_address(dev, &htype); halen = get_address(dev, &htype);
if (newaddr) { if (newaddr) {
parse_address(dev, htype, halen, newaddr, &ifr0); parse_address(dev, htype, halen, newaddr, &ifr0);
set_address(&ifr0, 0);
} }
if (newbrd) { if (newbrd) {
parse_address(dev, htype, halen, newbrd, &ifr1); parse_address(dev, htype, halen, newbrd, &ifr1);
set_address(&ifr1, 1);
} }
} }
@ -264,14 +258,6 @@ static int do_set(char **argv)
if (mtu != -1) { if (mtu != -1) {
set_mtu(dev, mtu); set_mtu(dev, mtu);
} }
if (newaddr || newbrd) {
if (newbrd) {
set_address(&ifr1, 1);
}
if (newaddr) {
set_address(&ifr0, 0);
}
}
if (mask) if (mask)
do_chflags(dev, flags, mask); do_chflags(dev, flags, mask);
return 0; return 0;
@ -304,7 +290,7 @@ static int do_change(char **argv, const unsigned rtm)
struct ifinfomsg i; struct ifinfomsg i;
char buf[1024]; char buf[1024];
} req; } req;
int arg; smalluint arg;
char *name_str = NULL, *link_str = NULL, *type_str = NULL, *dev_str = NULL; char *name_str = NULL, *link_str = NULL, *type_str = NULL, *dev_str = NULL;
memset(&req, 0, sizeof(req)); memset(&req, 0, sizeof(req));
@ -375,17 +361,16 @@ int do_iplink(char **argv)
{ {
static const char keywords[] ALIGN1 = static const char keywords[] ALIGN1 =
"add\0""delete\0""set\0""show\0""lst\0""list\0"; "add\0""delete\0""set\0""show\0""lst\0""list\0";
int key; if (*argv) {
if (!*argv) smalluint key = index_in_substrings(keywords, *argv);
return ipaddr_list_link(argv); if (key > 5) /* invalid argument */
key = index_in_substrings(keywords, *argv); bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
if (key < 0) argv++;
bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name); if (key <= 1) /* add/delete */
argv++; return do_change(argv, key ? RTM_DELLINK : RTM_NEWLINK);
if (key <= 1) /* add/delete */ else if (key == 2) /* set */
return do_change(argv, key ? RTM_DELLINK : RTM_NEWLINK); return do_set(argv);
else if (key == 2) /* set */ }
return do_set(argv);
/* show, lst, list */ /* show, lst, list */
return ipaddr_list_link(argv); return ipaddr_list_link(argv);
} }