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) {
|
while (*argv) {
|
||||||
const int option_num = index_in_strings(option, *argv);
|
const smalluint key = index_in_strings(option, *argv);
|
||||||
switch (option_num) {
|
if (key == 0) { /* to */
|
||||||
case 0: /* to */
|
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
get_prefix(&G_filter.pfx, *argv, G_filter.family);
|
get_prefix(&G_filter.pfx, *argv, G_filter.family);
|
||||||
if (G_filter.family == AF_UNSPEC) {
|
if (G_filter.family == AF_UNSPEC) {
|
||||||
G_filter.family = G_filter.pfx.family;
|
G_filter.family = G_filter.pfx.family;
|
||||||
}
|
}
|
||||||
break;
|
} else if (key == 1) { /* scope */
|
||||||
case 1: { /* scope */
|
|
||||||
uint32_t scope = 0;
|
uint32_t scope = 0;
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
G_filter.scopemask = -1;
|
G_filter.scopemask = -1;
|
||||||
@ -463,21 +461,16 @@ int ipaddr_list_or_flush(char **argv, int flush)
|
|||||||
G_filter.scopemask = 0;
|
G_filter.scopemask = 0;
|
||||||
}
|
}
|
||||||
G_filter.scope = scope;
|
G_filter.scope = scope;
|
||||||
break;
|
} else if (key == 2) { /* up */
|
||||||
}
|
|
||||||
case 2: /* up */
|
|
||||||
G_filter.up = 1;
|
G_filter.up = 1;
|
||||||
break;
|
} else if (key == 3) { /* label */
|
||||||
case 3: /* label */
|
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
G_filter.label = *argv;
|
G_filter.label = *argv;
|
||||||
break;
|
} else {
|
||||||
case 4: /* dev */
|
if (key == 4) /* dev */
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
default:
|
if (filter_dev)
|
||||||
if (filter_dev) {
|
|
||||||
duparg2("dev", *argv);
|
duparg2("dev", *argv);
|
||||||
}
|
|
||||||
filter_dev = *argv;
|
filter_dev = *argv;
|
||||||
}
|
}
|
||||||
argv++;
|
argv++;
|
||||||
@ -631,10 +624,8 @@ 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 int option_num = index_in_strings(option, *argv);
|
const smalluint arg = index_in_strings(option, *argv);
|
||||||
switch (option_num) {
|
if (arg <= 1) { /* peer, remote */
|
||||||
case 0: /* peer */
|
|
||||||
case 1: /* remote */
|
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
|
|
||||||
if (peer_len) {
|
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);
|
addattr_l(&req.n, sizeof(req), IFA_ADDRESS, &peer.data, peer.bytelen);
|
||||||
req.ifa.ifa_prefixlen = peer.bitlen;
|
req.ifa.ifa_prefixlen = peer.bitlen;
|
||||||
break;
|
} else if (arg <= 3) { /* broadcast, brd */
|
||||||
case 2: /* broadcast */
|
|
||||||
case 3: /* brd */
|
|
||||||
{
|
|
||||||
inet_prefix addr;
|
inet_prefix addr;
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
if (brd_len) {
|
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);
|
addattr_l(&req.n, sizeof(req), IFA_BROADCAST, &addr.data, addr.bytelen);
|
||||||
brd_len = addr.bytelen;
|
brd_len = addr.bytelen;
|
||||||
}
|
}
|
||||||
break;
|
} else if (arg == 4) { /* anycast */
|
||||||
}
|
|
||||||
case 4: /* anycast */
|
|
||||||
{
|
|
||||||
inet_prefix addr;
|
inet_prefix addr;
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
if (any_len) {
|
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);
|
addattr_l(&req.n, sizeof(req), IFA_ANYCAST, &addr.data, addr.bytelen);
|
||||||
any_len = addr.bytelen;
|
any_len = addr.bytelen;
|
||||||
break;
|
} else if (arg == 5) { /* scope */
|
||||||
}
|
|
||||||
case 5: /* scope */
|
|
||||||
{
|
|
||||||
uint32_t scope = 0;
|
uint32_t scope = 0;
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
if (rtnl_rtscope_a2n(&scope, *argv)) {
|
if (rtnl_rtscope_a2n(&scope, *argv)) {
|
||||||
@ -693,20 +675,16 @@ static int ipaddr_modify(int cmd, char **argv)
|
|||||||
}
|
}
|
||||||
req.ifa.ifa_scope = scope;
|
req.ifa.ifa_scope = scope;
|
||||||
scoped = 1;
|
scoped = 1;
|
||||||
break;
|
} else if (arg == 6) { /* dev */
|
||||||
}
|
|
||||||
case 6: /* dev */
|
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
d = *argv;
|
d = *argv;
|
||||||
break;
|
} else if (arg == 7) { /* label */
|
||||||
case 7: /* label */
|
|
||||||
NEXT_ARG();
|
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);
|
||||||
break;
|
} else {
|
||||||
case 8: /* local */
|
if (arg == 8) /* local */
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
default:
|
|
||||||
if (local_len) {
|
if (local_len) {
|
||||||
duparg2("local", *argv);
|
duparg2("local", *argv);
|
||||||
}
|
}
|
||||||
@ -720,10 +698,11 @@ static int ipaddr_modify(int cmd, char **argv)
|
|||||||
argv++;
|
argv++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d == NULL) {
|
// d cannot be null here, NEXT_ARG() of "dev" ensures that
|
||||||
bb_error_msg(bb_msg_requires_arg, "\"dev\"");
|
//if (d == NULL) {
|
||||||
return -1;
|
// bb_error_msg(bb_msg_requires_arg, "\"dev\"");
|
||||||
}
|
// return -1;
|
||||||
|
//}
|
||||||
if (l && strncmp(d, l, strlen(d)) != 0) {
|
if (l && strncmp(d, l, strlen(d)) != 0) {
|
||||||
bb_error_msg_and_die("\"dev\" (%s) must match \"label\" (%s)", d, l);
|
bb_error_msg_and_die("\"dev\" (%s) must match \"label\" (%s)", d, l);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user