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,22 +461,17 @@ 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,99 +624,85 @@ 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 */
|
NEXT_ARG();
|
||||||
case 1: /* remote */
|
|
||||||
NEXT_ARG();
|
|
||||||
|
|
||||||
if (peer_len) {
|
if (peer_len) {
|
||||||
duparg("peer", *argv);
|
duparg("peer", *argv);
|
||||||
}
|
|
||||||
get_prefix(&peer, *argv, req.ifa.ifa_family);
|
|
||||||
peer_len = peer.bytelen;
|
|
||||||
if (req.ifa.ifa_family == AF_UNSPEC) {
|
|
||||||
req.ifa.ifa_family = peer.family;
|
|
||||||
}
|
|
||||||
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 */
|
|
||||||
{
|
|
||||||
inet_prefix addr;
|
|
||||||
NEXT_ARG();
|
|
||||||
if (brd_len) {
|
|
||||||
duparg("broadcast", *argv);
|
|
||||||
}
|
|
||||||
if (LONE_CHAR(*argv, '+')) {
|
|
||||||
brd_len = -1;
|
|
||||||
} else if (LONE_DASH(*argv)) {
|
|
||||||
brd_len = -2;
|
|
||||||
} else {
|
|
||||||
get_addr(&addr, *argv, req.ifa.ifa_family);
|
|
||||||
if (req.ifa.ifa_family == AF_UNSPEC)
|
|
||||||
req.ifa.ifa_family = addr.family;
|
|
||||||
addattr_l(&req.n, sizeof(req), IFA_BROADCAST, &addr.data, addr.bytelen);
|
|
||||||
brd_len = addr.bytelen;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case 4: /* anycast */
|
get_prefix(&peer, *argv, req.ifa.ifa_family);
|
||||||
{
|
peer_len = peer.bytelen;
|
||||||
inet_prefix addr;
|
if (req.ifa.ifa_family == AF_UNSPEC) {
|
||||||
NEXT_ARG();
|
req.ifa.ifa_family = peer.family;
|
||||||
if (any_len) {
|
}
|
||||||
duparg("anycast", *argv);
|
addattr_l(&req.n, sizeof(req), IFA_ADDRESS, &peer.data, peer.bytelen);
|
||||||
}
|
req.ifa.ifa_prefixlen = peer.bitlen;
|
||||||
|
} else if (arg <= 3) { /* broadcast, brd */
|
||||||
|
inet_prefix addr;
|
||||||
|
NEXT_ARG();
|
||||||
|
if (brd_len) {
|
||||||
|
duparg("broadcast", *argv);
|
||||||
|
}
|
||||||
|
if (LONE_CHAR(*argv, '+')) {
|
||||||
|
brd_len = -1;
|
||||||
|
} else if (LONE_DASH(*argv)) {
|
||||||
|
brd_len = -2;
|
||||||
|
} else {
|
||||||
get_addr(&addr, *argv, req.ifa.ifa_family);
|
get_addr(&addr, *argv, req.ifa.ifa_family);
|
||||||
if (req.ifa.ifa_family == AF_UNSPEC) {
|
if (req.ifa.ifa_family == AF_UNSPEC)
|
||||||
req.ifa.ifa_family = addr.family;
|
req.ifa.ifa_family = addr.family;
|
||||||
}
|
addattr_l(&req.n, sizeof(req), IFA_BROADCAST, &addr.data, addr.bytelen);
|
||||||
addattr_l(&req.n, sizeof(req), IFA_ANYCAST, &addr.data, addr.bytelen);
|
brd_len = addr.bytelen;
|
||||||
any_len = addr.bytelen;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case 5: /* scope */
|
} else if (arg == 4) { /* anycast */
|
||||||
{
|
inet_prefix addr;
|
||||||
uint32_t scope = 0;
|
NEXT_ARG();
|
||||||
NEXT_ARG();
|
if (any_len) {
|
||||||
if (rtnl_rtscope_a2n(&scope, *argv)) {
|
duparg("anycast", *argv);
|
||||||
invarg(*argv, "scope");
|
|
||||||
}
|
|
||||||
req.ifa.ifa_scope = scope;
|
|
||||||
scoped = 1;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case 6: /* dev */
|
get_addr(&addr, *argv, req.ifa.ifa_family);
|
||||||
|
if (req.ifa.ifa_family == AF_UNSPEC) {
|
||||||
|
req.ifa.ifa_family = addr.family;
|
||||||
|
}
|
||||||
|
addattr_l(&req.n, sizeof(req), IFA_ANYCAST, &addr.data, addr.bytelen);
|
||||||
|
any_len = addr.bytelen;
|
||||||
|
} else if (arg == 5) { /* scope */
|
||||||
|
uint32_t scope = 0;
|
||||||
|
NEXT_ARG();
|
||||||
|
if (rtnl_rtscope_a2n(&scope, *argv)) {
|
||||||
|
invarg(*argv, "scope");
|
||||||
|
}
|
||||||
|
req.ifa.ifa_scope = scope;
|
||||||
|
scoped = 1;
|
||||||
|
} else if (arg == 6) { /* dev */
|
||||||
|
NEXT_ARG();
|
||||||
|
d = *argv;
|
||||||
|
} else if (arg == 7) { /* label */
|
||||||
|
NEXT_ARG();
|
||||||
|
l = *argv;
|
||||||
|
addattr_l(&req.n, sizeof(req), IFA_LABEL, l, strlen(l)+1);
|
||||||
|
} else {
|
||||||
|
if (arg == 8) /* local */
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
d = *argv;
|
if (local_len) {
|
||||||
break;
|
duparg2("local", *argv);
|
||||||
case 7: /* label */
|
}
|
||||||
NEXT_ARG();
|
get_prefix(&lcl, *argv, req.ifa.ifa_family);
|
||||||
l = *argv;
|
if (req.ifa.ifa_family == AF_UNSPEC) {
|
||||||
addattr_l(&req.n, sizeof(req), IFA_LABEL, l, strlen(l)+1);
|
req.ifa.ifa_family = lcl.family;
|
||||||
break;
|
}
|
||||||
case 8: /* local */
|
addattr_l(&req.n, sizeof(req), IFA_LOCAL, &lcl.data, lcl.bytelen);
|
||||||
NEXT_ARG();
|
local_len = lcl.bytelen;
|
||||||
default:
|
|
||||||
if (local_len) {
|
|
||||||
duparg2("local", *argv);
|
|
||||||
}
|
|
||||||
get_prefix(&lcl, *argv, req.ifa.ifa_family);
|
|
||||||
if (req.ifa.ifa_family == AF_UNSPEC) {
|
|
||||||
req.ifa.ifa_family = lcl.family;
|
|
||||||
}
|
|
||||||
addattr_l(&req.n, sizeof(req), IFA_LOCAL, &lcl.data, lcl.bytelen);
|
|
||||||
local_len = lcl.bytelen;
|
|
||||||
}
|
}
|
||||||
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