diff options
author | Bernhard Reutner-Fischer | 2010-05-25 18:46:09 +0200 |
---|---|---|
committer | Bernhard Reutner-Fischer | 2010-05-25 18:48:33 +0200 |
commit | c5f30c0df8f0ce5e94ca22a5100496233067708a (patch) | |
tree | 593d5ef0b5e57ac67e1aabd6b729c4fde038e1ca | |
parent | cc4493a95c877354ee267e29629b72cd9d010262 (diff) | |
download | busybox-c5f30c0df8f0ce5e94ca22a5100496233067708a.zip busybox-c5f30c0df8f0ce5e94ca22a5100496233067708a.tar.gz |
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>
-rw-r--r-- | networking/libiproute/ipaddress.c | 177 |
1 files changed, 78 insertions, 99 deletions
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index 8a5edb9..601b348 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c @@ -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,22 +461,17 @@ 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) { - duparg2("dev", *argv); - } - filter_dev = *argv; + if (filter_dev) + duparg2("dev", *argv); + filter_dev = *argv; } argv++; } @@ -631,99 +624,85 @@ 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 */ - NEXT_ARG(); + const smalluint arg = index_in_strings(option, *argv); + if (arg <= 1) { /* peer, remote */ + NEXT_ARG(); - if (peer_len) { - 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; + if (peer_len) { + duparg("peer", *argv); } - case 4: /* anycast */ - { - inet_prefix addr; - NEXT_ARG(); - if (any_len) { - duparg("anycast", *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; + } 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); - if (req.ifa.ifa_family == AF_UNSPEC) { + 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; - break; + addattr_l(&req.n, sizeof(req), IFA_BROADCAST, &addr.data, addr.bytelen); + brd_len = addr.bytelen; } - case 5: /* scope */ - { - uint32_t scope = 0; - NEXT_ARG(); - if (rtnl_rtscope_a2n(&scope, *argv)) { - invarg(*argv, "scope"); - } - req.ifa.ifa_scope = scope; - scoped = 1; - break; + } else if (arg == 4) { /* anycast */ + inet_prefix addr; + NEXT_ARG(); + if (any_len) { + duparg("anycast", *argv); } - case 6: /* dev */ - NEXT_ARG(); - d = *argv; - break; - case 7: /* label */ - NEXT_ARG(); - l = *argv; - addattr_l(&req.n, sizeof(req), IFA_LABEL, l, strlen(l)+1); - break; - case 8: /* local */ + 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(); - 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; + 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++; } - 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); } |