libiproute/*: code shrink

function                                             old     new   delta
ll_addr_a2n                                          181     178      -3
rtnl_rtntype_a2n                                     198     194      -4
ipaddr_modify                                       1309    1305      -4
print_addrinfo                                      1303    1298      -5
do_iplink                                           1137    1132      -5
print_route                                         1609    1603      -6
parse_args                                          1440    1434      -6
iproute_list_or_flush                               1261    1254      -7
rtnl_rttable_a2n                                      39      31      -8
rtnl_rtscope_a2n                                      39      31      -8
rtnl_rtrealm_a2n                                      39      31      -8
rtnl_rtprot_a2n                                       39      31      -8
rtnl_dsfield_a2n                                      39      31      -8
ll_type_n2a                                           78      70      -8
get_rt_realms                                        115     107      -8
print_tunnel                                         656     647      -9
rtnl_rttable_n2a                                      63      53     -10
rtnl_rtscope_n2a                                      63      53     -10
rtnl_rtrealm_n2a                                      63      53     -10
rtnl_rtntype_n2a                                     128     118     -10
rtnl_dsfield_n2a                                      71      61     -10
print_linkinfo                                       815     805     -10
ipaddr_list_or_flush                                1246    1235     -11
iproute_modify                                      1048    1036     -12
iprule_modify                                        866     851     -15
print_rule                                           765     738     -27
ll_addr_n2a                                          182     150     -32
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/27 up/down: 0/-262)          Total: -262 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2009-10-13 17:58:24 +02:00
parent 94466b8b8c
commit d31575a3ae
11 changed files with 68 additions and 61 deletions

View File

@ -162,7 +162,7 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n)
if (!filter.family || filter.family == AF_PACKET) { if (!filter.family || filter.family == AF_PACKET) {
SPRINT_BUF(b1); SPRINT_BUF(b1);
printf("%c link/%s ", _SL_, ll_type_n2a(ifi->ifi_type, b1, sizeof(b1))); printf("%c link/%s ", _SL_, ll_type_n2a(ifi->ifi_type, b1));
if (tb[IFLA_ADDRESS]) { if (tb[IFLA_ADDRESS]) {
fputs(ll_addr_n2a(RTA_DATA(tb[IFLA_ADDRESS]), fputs(ll_addr_n2a(RTA_DATA(tb[IFLA_ADDRESS]),
@ -308,7 +308,7 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM,
RTA_DATA(rta_tb[IFA_ANYCAST]), RTA_DATA(rta_tb[IFA_ANYCAST]),
abuf, sizeof(abuf))); abuf, sizeof(abuf)));
} }
printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1, sizeof(b1))); printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1));
if (ifa->ifa_flags & IFA_F_SECONDARY) { if (ifa->ifa_flags & IFA_F_SECONDARY) {
ifa->ifa_flags &= ~IFA_F_SECONDARY; ifa->ifa_flags &= ~IFA_F_SECONDARY;
printf("secondary "); printf("secondary ");

View File

@ -196,7 +196,7 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
printf("Deleted "); printf("Deleted ");
} }
if (r->rtm_type != RTN_UNICAST && !filter.type) { if (r->rtm_type != RTN_UNICAST && !filter.type) {
printf("%s ", rtnl_rtntype_n2a(r->rtm_type, b1, sizeof(b1))); printf("%s ", rtnl_rtntype_n2a(r->rtm_type, b1));
} }
if (tb[RTA_DST]) { if (tb[RTA_DST]) {

View File

@ -113,7 +113,7 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
} }
if (r->rtm_tos) { if (r->rtm_tos) {
printf("tos %s ", rtnl_dsfield_n2a(r->rtm_tos, b1, sizeof(b1))); printf("tos %s ", rtnl_dsfield_n2a(r->rtm_tos, b1));
} }
if (tb[RTA_PROTOINFO]) { if (tb[RTA_PROTOINFO]) {
printf("fwmark %#x ", *(uint32_t*)RTA_DATA(tb[RTA_PROTOINFO])); printf("fwmark %#x ", *(uint32_t*)RTA_DATA(tb[RTA_PROTOINFO]));
@ -124,7 +124,7 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
} }
if (r->rtm_table) if (r->rtm_table)
printf("lookup %s ", rtnl_rttable_n2a(r->rtm_table, b1, sizeof(b1))); printf("lookup %s ", rtnl_rttable_n2a(r->rtm_table, b1));
if (tb[RTA_FLOW]) { if (tb[RTA_FLOW]) {
uint32_t to = *(uint32_t*)RTA_DATA(tb[RTA_FLOW]); uint32_t to = *(uint32_t*)RTA_DATA(tb[RTA_FLOW]);
@ -132,10 +132,10 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
to &= 0xFFFF; to &= 0xFFFF;
if (from) { if (from) {
printf("realms %s/", printf("realms %s/",
rtnl_rtrealm_n2a(from, b1, sizeof(b1))); rtnl_rtrealm_n2a(from, b1));
} }
printf("%s ", printf("%s ",
rtnl_rtrealm_n2a(to, b1, sizeof(b1))); rtnl_rtrealm_n2a(to, b1));
} }
if (r->rtm_type == RTN_NAT) { if (r->rtm_type == RTN_NAT) {
@ -148,7 +148,7 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
} else } else
printf("masquerade"); printf("masquerade");
} else if (r->rtm_type != RTN_UNICAST) } else if (r->rtm_type != RTN_UNICAST)
fputs(rtnl_rtntype_n2a(r->rtm_type, b1, sizeof(b1)), stdout); fputs(rtnl_rtntype_n2a(r->rtm_type, b1), stdout);
bb_putchar('\n'); bb_putchar('\n');
/*fflush(stdout);*/ /*fflush(stdout);*/

View File

@ -436,7 +436,7 @@ static void print_tunnel(struct ip_tunnel_parm *p)
printf(" inherit"); printf(" inherit");
if (p->iph.tos & ~1) if (p->iph.tos & ~1)
printf("%c%s ", p->iph.tos & 1 ? '/' : ' ', printf("%c%s ", p->iph.tos & 1 ? '/' : ' ',
rtnl_dsfield_n2a(p->iph.tos & ~1, b1, sizeof(b1))); rtnl_dsfield_n2a(p->iph.tos & ~1, b1));
} }
if (!(p->iph.frag_off & htons(IP_DF))) if (!(p->iph.frag_off & htons(IP_DF)))
printf(" nopmtudisc"); printf(" nopmtudisc");

View File

@ -17,7 +17,7 @@
#include "utils.h" #include "utils.h"
const char *ll_addr_n2a(unsigned char *addr, int alen, int type, char *buf, int blen) const char* FAST_FUNC ll_addr_n2a(unsigned char *addr, int alen, int type, char *buf, int blen)
{ {
int i; int i;
int l; int l;
@ -27,13 +27,13 @@ const char *ll_addr_n2a(unsigned char *addr, int alen, int type, char *buf, int
return inet_ntop(AF_INET, addr, buf, blen); return inet_ntop(AF_INET, addr, buf, blen);
} }
l = 0; l = 0;
for (i=0; i<alen; i++) { for (i = 0; i < alen; i++) {
if (i==0) { if (i == 0) {
snprintf(buf+l, blen, ":%02x"+1, addr[i]); snprintf(buf + l, blen, ":%02x"+1, addr[i]);
blen -= 2; blen -= 2;
l += 2; l += 2;
} else { } else {
snprintf(buf+l, blen, ":%02x", addr[i]); snprintf(buf + l, blen, ":%02x", addr[i]);
blen -= 3; blen -= 3;
l += 3; l += 3;
} }
@ -41,7 +41,7 @@ const char *ll_addr_n2a(unsigned char *addr, int alen, int type, char *buf, int
return buf; return buf;
} }
int ll_addr_a2n(unsigned char *lladdr, int len, char *arg) int FAST_FUNC ll_addr_a2n(unsigned char *lladdr, int len, char *arg)
{ {
int i; int i;

View File

@ -98,7 +98,7 @@ __PF(ECONET,econet)
#undef __PF #undef __PF
const char *ll_proto_n2a(unsigned short id, char *buf, int len) const char* FAST_FUNC ll_proto_n2a(unsigned short id, char *buf, int len)
{ {
unsigned i; unsigned i;
id = ntohs(id); id = ntohs(id);
@ -110,7 +110,7 @@ const char *ll_proto_n2a(unsigned short id, char *buf, int len)
return buf; return buf;
} }
int ll_proto_a2n(unsigned short *id, char *buf) int FAST_FUNC ll_proto_a2n(unsigned short *id, char *buf)
{ {
unsigned i; unsigned i;
for (i = 0; i < ARRAY_SIZE(llproto_names); i++) { for (i = 0; i < ARRAY_SIZE(llproto_names); i++) {

View File

@ -15,7 +15,7 @@
#include "libbb.h" #include "libbb.h"
#include "rt_names.h" #include "rt_names.h"
const char *ll_type_n2a(int type, char *buf, int len) const char* FAST_FUNC ll_type_n2a(int type, char *buf)
{ {
static const char arphrd_name[] = static const char arphrd_name[] =
/* 0, */ "generic" "\0" /* 0, */ "generic" "\0"
@ -200,6 +200,6 @@ const char *ll_type_n2a(int type, char *buf, int len)
return aname; return aname;
aname += strlen(aname) + 1; aname += strlen(aname) + 1;
} }
snprintf(buf, len, "[%d]", type); sprintf(buf, "[%d]", type);
return buf; return buf;
} }

View File

@ -90,10 +90,10 @@ static void rtnl_rtprot_initialize(void)
rtnl_tab_initialize("/etc/iproute2/rt_protos", rtnl_rtprot_tab->tab); rtnl_tab_initialize("/etc/iproute2/rt_protos", rtnl_rtprot_tab->tab);
} }
const char* rtnl_rtprot_n2a(int id, char *buf, int len) const char* FAST_FUNC rtnl_rtprot_n2a(int id, char *buf)
{ {
if (id < 0 || id >= 256) { if (id < 0 || id >= 256) {
snprintf(buf, len, "%d", id); sprintf(buf, "%d", id);
return buf; return buf;
} }
@ -101,11 +101,12 @@ const char* rtnl_rtprot_n2a(int id, char *buf, int len)
if (rtnl_rtprot_tab->tab[id]) if (rtnl_rtprot_tab->tab[id])
return rtnl_rtprot_tab->tab[id]; return rtnl_rtprot_tab->tab[id];
snprintf(buf, len, "%d", id); /* buf is SPRINT_BSIZE big */
sprintf(buf, "%d", id);
return buf; return buf;
} }
int rtnl_rtprot_a2n(uint32_t *id, char *arg) int FAST_FUNC rtnl_rtprot_a2n(uint32_t *id, char *arg)
{ {
rtnl_rtprot_initialize(); rtnl_rtprot_initialize();
return rtnl_a2n(rtnl_rtprot_tab, id, arg, 0); return rtnl_a2n(rtnl_rtprot_tab, id, arg, 0);
@ -127,10 +128,10 @@ static void rtnl_rtscope_initialize(void)
rtnl_tab_initialize("/etc/iproute2/rt_scopes", rtnl_rtscope_tab->tab); rtnl_tab_initialize("/etc/iproute2/rt_scopes", rtnl_rtscope_tab->tab);
} }
const char* rtnl_rtscope_n2a(int id, char *buf, int len) const char* FAST_FUNC rtnl_rtscope_n2a(int id, char *buf)
{ {
if (id < 0 || id >= 256) { if (id < 0 || id >= 256) {
snprintf(buf, len, "%d", id); sprintf(buf, "%d", id);
return buf; return buf;
} }
@ -138,11 +139,12 @@ const char* rtnl_rtscope_n2a(int id, char *buf, int len)
if (rtnl_rtscope_tab->tab[id]) if (rtnl_rtscope_tab->tab[id])
return rtnl_rtscope_tab->tab[id]; return rtnl_rtscope_tab->tab[id];
snprintf(buf, len, "%d", id); /* buf is SPRINT_BSIZE big */
sprintf(buf, "%d", id);
return buf; return buf;
} }
int rtnl_rtscope_a2n(uint32_t *id, char *arg) int FAST_FUNC rtnl_rtscope_a2n(uint32_t *id, char *arg)
{ {
rtnl_rtscope_initialize(); rtnl_rtscope_initialize();
return rtnl_a2n(rtnl_rtscope_tab, id, arg, 0); return rtnl_a2n(rtnl_rtscope_tab, id, arg, 0);
@ -159,17 +161,17 @@ static void rtnl_rtrealm_initialize(void)
rtnl_tab_initialize("/etc/iproute2/rt_realms", rtnl_rtrealm_tab->tab); rtnl_tab_initialize("/etc/iproute2/rt_realms", rtnl_rtrealm_tab->tab);
} }
int rtnl_rtrealm_a2n(uint32_t *id, char *arg) int FAST_FUNC rtnl_rtrealm_a2n(uint32_t *id, char *arg)
{ {
rtnl_rtrealm_initialize(); rtnl_rtrealm_initialize();
return rtnl_a2n(rtnl_rtrealm_tab, id, arg, 0); return rtnl_a2n(rtnl_rtrealm_tab, id, arg, 0);
} }
#if ENABLE_FEATURE_IP_RULE #if ENABLE_FEATURE_IP_RULE
const char* rtnl_rtrealm_n2a(int id, char *buf, int len) const char* FAST_FUNC rtnl_rtrealm_n2a(int id, char *buf)
{ {
if (id < 0 || id >= 256) { if (id < 0 || id >= 256) {
snprintf(buf, len, "%d", id); sprintf(buf, "%d", id);
return buf; return buf;
} }
@ -177,7 +179,8 @@ const char* rtnl_rtrealm_n2a(int id, char *buf, int len)
if (rtnl_rtrealm_tab->tab[id]) if (rtnl_rtrealm_tab->tab[id])
return rtnl_rtrealm_tab->tab[id]; return rtnl_rtrealm_tab->tab[id];
snprintf(buf, len, "%d", id); /* buf is SPRINT_BSIZE big */
sprintf(buf, "%d", id);
return buf; return buf;
} }
#endif #endif
@ -193,10 +196,10 @@ static void rtnl_rtdsfield_initialize(void)
rtnl_tab_initialize("/etc/iproute2/rt_dsfield", rtnl_rtdsfield_tab->tab); rtnl_tab_initialize("/etc/iproute2/rt_dsfield", rtnl_rtdsfield_tab->tab);
} }
const char * rtnl_dsfield_n2a(int id, char *buf, int len) const char* FAST_FUNC rtnl_dsfield_n2a(int id, char *buf)
{ {
if (id < 0 || id >= 256) { if (id < 0 || id >= 256) {
snprintf(buf, len, "%d", id); sprintf(buf, "%d", id);
return buf; return buf;
} }
@ -204,11 +207,12 @@ const char * rtnl_dsfield_n2a(int id, char *buf, int len)
if (rtnl_rtdsfield_tab->tab[id]) if (rtnl_rtdsfield_tab->tab[id])
return rtnl_rtdsfield_tab->tab[id]; return rtnl_rtdsfield_tab->tab[id];
snprintf(buf, len, "0x%02x", id); /* buf is SPRINT_BSIZE big */
sprintf(buf, "0x%02x", id);
return buf; return buf;
} }
int rtnl_dsfield_a2n(uint32_t *id, char *arg) int FAST_FUNC rtnl_dsfield_a2n(uint32_t *id, char *arg)
{ {
rtnl_rtdsfield_initialize(); rtnl_rtdsfield_initialize();
return rtnl_a2n(rtnl_rtdsfield_tab, id, arg, 16); return rtnl_a2n(rtnl_rtdsfield_tab, id, arg, 16);
@ -229,10 +233,10 @@ static void rtnl_rttable_initialize(void)
rtnl_tab_initialize("/etc/iproute2/rt_tables", rtnl_rttable_tab->tab); rtnl_tab_initialize("/etc/iproute2/rt_tables", rtnl_rttable_tab->tab);
} }
const char *rtnl_rttable_n2a(int id, char *buf, int len) const char* FAST_FUNC rtnl_rttable_n2a(int id, char *buf)
{ {
if (id < 0 || id >= 256) { if (id < 0 || id >= 256) {
snprintf(buf, len, "%d", id); sprintf(buf, "%d", id);
return buf; return buf;
} }
@ -240,11 +244,12 @@ const char *rtnl_rttable_n2a(int id, char *buf, int len)
if (rtnl_rttable_tab->tab[id]) if (rtnl_rttable_tab->tab[id])
return rtnl_rttable_tab->tab[id]; return rtnl_rttable_tab->tab[id];
snprintf(buf, len, "%d", id); /* buf is SPRINT_BSIZE big */
sprintf(buf, "%d", id);
return buf; return buf;
} }
int rtnl_rttable_a2n(uint32_t *id, char *arg) int FAST_FUNC rtnl_rttable_a2n(uint32_t *id, char *arg)
{ {
rtnl_rttable_initialize(); rtnl_rttable_initialize();
return rtnl_a2n(rtnl_rttable_tab, id, arg, 0); return rtnl_a2n(rtnl_rttable_tab, id, arg, 0);

View File

@ -4,25 +4,26 @@
PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
extern const char* rtnl_rtprot_n2a(int id, char *buf, int len); /* buf is SPRINT_BSIZE big */
extern const char* rtnl_rtscope_n2a(int id, char *buf, int len); extern const char* rtnl_rtprot_n2a(int id, char *buf) FAST_FUNC;
extern const char* rtnl_rtrealm_n2a(int id, char *buf, int len); extern const char* rtnl_rtscope_n2a(int id, char *buf) FAST_FUNC;
extern const char* rtnl_dsfield_n2a(int id, char *buf, int len); extern const char* rtnl_rtrealm_n2a(int id, char *buf) FAST_FUNC;
extern const char* rtnl_rttable_n2a(int id, char *buf, int len); extern const char* rtnl_dsfield_n2a(int id, char *buf) FAST_FUNC;
extern int rtnl_rtprot_a2n(uint32_t *id, char *arg); extern const char* rtnl_rttable_n2a(int id, char *buf) FAST_FUNC;
extern int rtnl_rtscope_a2n(uint32_t *id, char *arg); extern int rtnl_rtprot_a2n(uint32_t *id, char *arg) FAST_FUNC;
extern int rtnl_rtrealm_a2n(uint32_t *id, char *arg); extern int rtnl_rtscope_a2n(uint32_t *id, char *arg) FAST_FUNC;
extern int rtnl_dsfield_a2n(uint32_t *id, char *arg); extern int rtnl_rtrealm_a2n(uint32_t *id, char *arg) FAST_FUNC;
extern int rtnl_rttable_a2n(uint32_t *id, char *arg); extern int rtnl_dsfield_a2n(uint32_t *id, char *arg) FAST_FUNC;
extern int rtnl_rttable_a2n(uint32_t *id, char *arg) FAST_FUNC;
extern const char* ll_type_n2a(int type, char *buf, int len); extern const char* ll_type_n2a(int type, char *buf) FAST_FUNC;
extern const char* ll_addr_n2a(unsigned char *addr, int alen, int type, extern const char* ll_addr_n2a(unsigned char *addr, int alen, int type,
char *buf, int blen); char *buf, int blen) FAST_FUNC;
extern int ll_addr_a2n(unsigned char *lladdr, int len, char *arg); extern int ll_addr_a2n(unsigned char *lladdr, int len, char *arg) FAST_FUNC;
extern const char* ll_proto_n2a(unsigned short id, char *buf, int len); extern const char* ll_proto_n2a(unsigned short id, char *buf, int len) FAST_FUNC;
extern int ll_proto_a2n(unsigned short *id, char *buf); extern int ll_proto_a2n(unsigned short *id, char *buf) FAST_FUNC;
POP_SAVED_FUNCTION_VISIBILITY POP_SAVED_FUNCTION_VISIBILITY

View File

@ -15,7 +15,7 @@
#include "rt_names.h" #include "rt_names.h"
#include "utils.h" #include "utils.h"
const char *rtnl_rtntype_n2a(int id, char *buf, int len) const char* FAST_FUNC rtnl_rtntype_n2a(int id, char *buf)
{ {
switch (id) { switch (id) {
case RTN_UNSPEC: case RTN_UNSPEC:
@ -43,13 +43,14 @@ const char *rtnl_rtntype_n2a(int id, char *buf, int len)
case RTN_XRESOLVE: case RTN_XRESOLVE:
return "xresolve"; return "xresolve";
default: default:
snprintf(buf, len, "%d", id); /* buf is SPRINT_BSIZE big */
sprintf(buf, "%d", id);
return buf; return buf;
} }
} }
int rtnl_rtntype_a2n(int *id, char *arg) int FAST_FUNC rtnl_rtntype_a2n(int *id, char *arg)
{ {
static const char keywords[] ALIGN1 = static const char keywords[] ALIGN1 =
"local\0""nat\0""broadcast\0""brd\0""anycast\0" "local\0""nat\0""broadcast\0""brd\0""anycast\0"
@ -95,7 +96,7 @@ int rtnl_rtntype_a2n(int *id, char *arg)
return 0; return 0;
} }
int get_rt_realms(uint32_t *realms, char *arg) int FAST_FUNC get_rt_realms(uint32_t *realms, char *arg)
{ {
uint32_t realm = 0; uint32_t realm = 0;
char *p = strchr(arg, '/'); char *p = strchr(arg, '/');

View File

@ -4,10 +4,10 @@
PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
const char *rtnl_rtntype_n2a(int id, char *buf, int len); const char *rtnl_rtntype_n2a(int id, char *buf) FAST_FUNC;
int rtnl_rtntype_a2n(int *id, char *arg); int rtnl_rtntype_a2n(int *id, char *arg) FAST_FUNC;
int get_rt_realms(uint32_t *realms, char *arg); int get_rt_realms(uint32_t *realms, char *arg) FAST_FUNC;
POP_SAVED_FUNCTION_VISIBILITY POP_SAVED_FUNCTION_VISIBILITY