ip: code shrink
function old new delta do_ipaddr 78 81 +3 do_iprule 140 139 -1 do_iptunnel 283 278 -5 iprule_modify 851 841 -10 ipaddr_modify 1293 1236 -57 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/4 up/down: 3/-73) Total: -70 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
25ce3ee9f3
commit
9b58fe9c0b
@ -627,10 +627,12 @@ static int ipaddr_modify(int cmd, char **argv)
|
|||||||
req.ifa.ifa_family = preferred_family;
|
req.ifa.ifa_family = preferred_family;
|
||||||
|
|
||||||
while (*argv) {
|
while (*argv) {
|
||||||
const smalluint arg = index_in_strings(option, *argv);
|
unsigned arg = index_in_strings(option, *argv);
|
||||||
if (arg <= 1) { /* peer, remote */
|
/* if search fails, "local" is assumed */
|
||||||
|
if ((int)arg >= 0)
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
|
|
||||||
|
if (arg <= 1) { /* peer, remote */
|
||||||
if (peer_len) {
|
if (peer_len) {
|
||||||
duparg("peer", *argv);
|
duparg("peer", *argv);
|
||||||
}
|
}
|
||||||
@ -643,7 +645,6 @@ static int ipaddr_modify(int cmd, char **argv)
|
|||||||
req.ifa.ifa_prefixlen = peer.bitlen;
|
req.ifa.ifa_prefixlen = peer.bitlen;
|
||||||
} else if (arg <= 3) { /* broadcast, brd */
|
} else if (arg <= 3) { /* broadcast, brd */
|
||||||
inet_prefix addr;
|
inet_prefix addr;
|
||||||
NEXT_ARG();
|
|
||||||
if (brd_len) {
|
if (brd_len) {
|
||||||
duparg("broadcast", *argv);
|
duparg("broadcast", *argv);
|
||||||
}
|
}
|
||||||
@ -660,7 +661,6 @@ static int ipaddr_modify(int cmd, char **argv)
|
|||||||
}
|
}
|
||||||
} else if (arg == 4) { /* anycast */
|
} else if (arg == 4) { /* anycast */
|
||||||
inet_prefix addr;
|
inet_prefix addr;
|
||||||
NEXT_ARG();
|
|
||||||
if (any_len) {
|
if (any_len) {
|
||||||
duparg("anycast", *argv);
|
duparg("anycast", *argv);
|
||||||
}
|
}
|
||||||
@ -672,22 +672,18 @@ static int ipaddr_modify(int cmd, char **argv)
|
|||||||
any_len = addr.bytelen;
|
any_len = addr.bytelen;
|
||||||
} else if (arg == 5) { /* scope */
|
} else if (arg == 5) { /* scope */
|
||||||
uint32_t scope = 0;
|
uint32_t scope = 0;
|
||||||
NEXT_ARG();
|
|
||||||
if (rtnl_rtscope_a2n(&scope, *argv)) {
|
if (rtnl_rtscope_a2n(&scope, *argv)) {
|
||||||
invarg(*argv, "scope");
|
invarg(*argv, "scope");
|
||||||
}
|
}
|
||||||
req.ifa.ifa_scope = scope;
|
req.ifa.ifa_scope = scope;
|
||||||
scoped = 1;
|
scoped = 1;
|
||||||
} else if (arg == 6) { /* dev */
|
} else if (arg == 6) { /* dev */
|
||||||
NEXT_ARG();
|
|
||||||
d = *argv;
|
d = *argv;
|
||||||
} else if (arg == 7) { /* label */
|
} else if (arg == 7) { /* label */
|
||||||
NEXT_ARG();
|
|
||||||
l = *argv;
|
l = *argv;
|
||||||
addattr_l(&req.n, sizeof(req), IFA_LABEL, l, strlen(l) + 1);
|
addattr_l(&req.n, sizeof(req), IFA_LABEL, l, strlen(l) + 1);
|
||||||
} else {
|
} else {
|
||||||
if (arg == 8) /* local */
|
/* local (specified or assumed) */
|
||||||
NEXT_ARG();
|
|
||||||
if (local_len) {
|
if (local_len) {
|
||||||
duparg2("local", *argv);
|
duparg2("local", *argv);
|
||||||
}
|
}
|
||||||
@ -724,7 +720,7 @@ static int ipaddr_modify(int cmd, char **argv)
|
|||||||
}
|
}
|
||||||
brd = peer;
|
brd = peer;
|
||||||
if (brd.bitlen <= 30) {
|
if (brd.bitlen <= 30) {
|
||||||
for (i=31; i>=brd.bitlen; i--) {
|
for (i = 31; i >= brd.bitlen; i--) {
|
||||||
if (brd_len == -1)
|
if (brd_len == -1)
|
||||||
brd.data[0] |= htonl(1<<(31-i));
|
brd.data[0] |= htonl(1<<(31-i));
|
||||||
else
|
else
|
||||||
@ -754,11 +750,11 @@ int FAST_FUNC do_ipaddr(char **argv)
|
|||||||
{
|
{
|
||||||
static const char commands[] ALIGN1 =
|
static const char commands[] ALIGN1 =
|
||||||
"add\0""delete\0""list\0""show\0""lst\0""flush\0";
|
"add\0""delete\0""list\0""show\0""lst\0""flush\0";
|
||||||
smalluint cmd = 2;
|
int cmd = 2;
|
||||||
if (*argv) {
|
if (*argv) {
|
||||||
cmd = index_in_substrings(commands, *argv);
|
cmd = index_in_substrings(commands, *argv);
|
||||||
if (cmd > 5)
|
if (cmd < 0)
|
||||||
bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
|
invarg(*argv, applet_name);
|
||||||
argv++;
|
argv++;
|
||||||
if (cmd <= 1)
|
if (cmd <= 1)
|
||||||
return ipaddr_modify((cmd == 0) ? RTM_NEWADDR : RTM_DELADDR, argv);
|
return ipaddr_modify((cmd == 0) ? RTM_NEWADDR : RTM_DELADDR, argv);
|
||||||
|
@ -215,7 +215,7 @@ static int iprule_modify(int cmd, char **argv)
|
|||||||
while (*argv) {
|
while (*argv) {
|
||||||
key = index_in_substrings(keywords, *argv) + 1;
|
key = index_in_substrings(keywords, *argv) + 1;
|
||||||
if (key == 0) /* no match found in keywords array, bail out. */
|
if (key == 0) /* no match found in keywords array, bail out. */
|
||||||
bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
|
invarg(*argv, applet_name);
|
||||||
if (key == ARG_from) {
|
if (key == ARG_from) {
|
||||||
inet_prefix dst;
|
inet_prefix dst;
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
@ -308,9 +308,9 @@ int FAST_FUNC do_iprule(char **argv)
|
|||||||
static const char ip_rule_commands[] ALIGN1 =
|
static const char ip_rule_commands[] ALIGN1 =
|
||||||
"add\0""delete\0""list\0""show\0";
|
"add\0""delete\0""list\0""show\0";
|
||||||
if (*argv) {
|
if (*argv) {
|
||||||
smalluint cmd = index_in_substrings(ip_rule_commands, *argv);
|
int cmd = index_in_substrings(ip_rule_commands, *argv);
|
||||||
if (cmd > 3)
|
if (cmd < 0)
|
||||||
bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
|
invarg(*argv, applet_name);
|
||||||
argv++;
|
argv++;
|
||||||
if (cmd < 2)
|
if (cmd < 2)
|
||||||
return iprule_modify((cmd == 0) ? RTM_NEWRULE : RTM_DELRULE, argv);
|
return iprule_modify((cmd == 0) ? RTM_NEWRULE : RTM_DELRULE, argv);
|
||||||
|
@ -561,9 +561,9 @@ int FAST_FUNC do_iptunnel(char **argv)
|
|||||||
enum { ARG_add = 0, ARG_change, ARG_del, ARG_show, ARG_list, ARG_lst };
|
enum { ARG_add = 0, ARG_change, ARG_del, ARG_show, ARG_list, ARG_lst };
|
||||||
|
|
||||||
if (*argv) {
|
if (*argv) {
|
||||||
smalluint key = index_in_substrings(keywords, *argv);
|
int key = index_in_substrings(keywords, *argv);
|
||||||
if (key > 5)
|
if (key < 0)
|
||||||
bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
|
invarg(*argv, applet_name);
|
||||||
argv++;
|
argv++;
|
||||||
if (key == ARG_add)
|
if (key == ARG_add)
|
||||||
return do_add(SIOCADDTUNNEL, argv);
|
return do_add(SIOCADDTUNNEL, argv);
|
||||||
|
Loading…
Reference in New Issue
Block a user