ip addr: shrink
function old new delta ipaddr_list_or_flush 1254 1248 -6 ipaddr_modify 1299 1279 -20 .rodata 135249 135193 -56 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-82) Total: -82 bytes Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
This commit is contained in:
parent
cc4493a95c
commit
c5f30c0df8
@ -442,16 +442,14 @@ int ipaddr_list_or_flush(char **argv, int flush)
|
||||
}
|
||||
|
||||
while (*argv) {
|
||||
const int option_num = index_in_strings(option, *argv);
|
||||
switch (option_num) {
|
||||
case 0: /* to */
|
||||
const smalluint key = index_in_strings(option, *argv);
|
||||
if (key == 0) { /* to */
|
||||
NEXT_ARG();
|
||||
get_prefix(&G_filter.pfx, *argv, G_filter.family);
|
||||
if (G_filter.family == AF_UNSPEC) {
|
||||
G_filter.family = G_filter.pfx.family;
|
||||
}
|
||||
break;
|
||||
case 1: { /* scope */
|
||||
} else if (key == 1) { /* scope */
|
||||
uint32_t scope = 0;
|
||||
NEXT_ARG();
|
||||
G_filter.scopemask = -1;
|
||||
@ -463,21 +461,16 @@ int ipaddr_list_or_flush(char **argv, int flush)
|
||||
G_filter.scopemask = 0;
|
||||
}
|
||||
G_filter.scope = scope;
|
||||
break;
|
||||
}
|
||||
case 2: /* up */
|
||||
} else if (key == 2) { /* up */
|
||||
G_filter.up = 1;
|
||||
break;
|
||||
case 3: /* label */
|
||||
} else if (key == 3) { /* label */
|
||||
NEXT_ARG();
|
||||
G_filter.label = *argv;
|
||||
break;
|
||||
case 4: /* dev */
|
||||
} else {
|
||||
if (key == 4) /* dev */
|
||||
NEXT_ARG();
|
||||
default:
|
||||
if (filter_dev) {
|
||||
if (filter_dev)
|
||||
duparg2("dev", *argv);
|
||||
}
|
||||
filter_dev = *argv;
|
||||
}
|
||||
argv++;
|
||||
@ -631,10 +624,8 @@ static int ipaddr_modify(int cmd, char **argv)
|
||||
req.ifa.ifa_family = preferred_family;
|
||||
|
||||
while (*argv) {
|
||||
const int option_num = index_in_strings(option, *argv);
|
||||
switch (option_num) {
|
||||
case 0: /* peer */
|
||||
case 1: /* remote */
|
||||
const smalluint arg = index_in_strings(option, *argv);
|
||||
if (arg <= 1) { /* peer, remote */
|
||||
NEXT_ARG();
|
||||
|
||||
if (peer_len) {
|
||||
@ -647,10 +638,7 @@ static int ipaddr_modify(int cmd, char **argv)
|
||||
}
|
||||
addattr_l(&req.n, sizeof(req), IFA_ADDRESS, &peer.data, peer.bytelen);
|
||||
req.ifa.ifa_prefixlen = peer.bitlen;
|
||||
break;
|
||||
case 2: /* broadcast */
|
||||
case 3: /* brd */
|
||||
{
|
||||
} else if (arg <= 3) { /* broadcast, brd */
|
||||
inet_prefix addr;
|
||||
NEXT_ARG();
|
||||
if (brd_len) {
|
||||
@ -667,10 +655,7 @@ static int ipaddr_modify(int cmd, char **argv)
|
||||
addattr_l(&req.n, sizeof(req), IFA_BROADCAST, &addr.data, addr.bytelen);
|
||||
brd_len = addr.bytelen;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 4: /* anycast */
|
||||
{
|
||||
} else if (arg == 4) { /* anycast */
|
||||
inet_prefix addr;
|
||||
NEXT_ARG();
|
||||
if (any_len) {
|
||||
@ -682,10 +667,7 @@ static int ipaddr_modify(int cmd, char **argv)
|
||||
}
|
||||
addattr_l(&req.n, sizeof(req), IFA_ANYCAST, &addr.data, addr.bytelen);
|
||||
any_len = addr.bytelen;
|
||||
break;
|
||||
}
|
||||
case 5: /* scope */
|
||||
{
|
||||
} else if (arg == 5) { /* scope */
|
||||
uint32_t scope = 0;
|
||||
NEXT_ARG();
|
||||
if (rtnl_rtscope_a2n(&scope, *argv)) {
|
||||
@ -693,20 +675,16 @@ static int ipaddr_modify(int cmd, char **argv)
|
||||
}
|
||||
req.ifa.ifa_scope = scope;
|
||||
scoped = 1;
|
||||
break;
|
||||
}
|
||||
case 6: /* dev */
|
||||
} else if (arg == 6) { /* dev */
|
||||
NEXT_ARG();
|
||||
d = *argv;
|
||||
break;
|
||||
case 7: /* label */
|
||||
} else if (arg == 7) { /* label */
|
||||
NEXT_ARG();
|
||||
l = *argv;
|
||||
addattr_l(&req.n, sizeof(req), IFA_LABEL, l, strlen(l)+1);
|
||||
break;
|
||||
case 8: /* local */
|
||||
} else {
|
||||
if (arg == 8) /* local */
|
||||
NEXT_ARG();
|
||||
default:
|
||||
if (local_len) {
|
||||
duparg2("local", *argv);
|
||||
}
|
||||
@ -720,10 +698,11 @@ static int ipaddr_modify(int cmd, char **argv)
|
||||
argv++;
|
||||
}
|
||||
|
||||
if (d == NULL) {
|
||||
bb_error_msg(bb_msg_requires_arg, "\"dev\"");
|
||||
return -1;
|
||||
}
|
||||
// d cannot be null here, NEXT_ARG() of "dev" ensures that
|
||||
//if (d == NULL) {
|
||||
// bb_error_msg(bb_msg_requires_arg, "\"dev\"");
|
||||
// return -1;
|
||||
//}
|
||||
if (l && strncmp(d, l, strlen(d)) != 0) {
|
||||
bb_error_msg_and_die("\"dev\" (%s) must match \"label\" (%s)", d, l);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user