libiproute/*: code shrink
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 13 Oct 2009 15:58:24 +0000 (17:58 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 13 Oct 2009 15:58:24 +0000 (17:58 +0200)
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>
networking/libiproute/ipaddress.c
networking/libiproute/iproute.c
networking/libiproute/iprule.c
networking/libiproute/iptunnel.c
networking/libiproute/ll_addr.c
networking/libiproute/ll_proto.c
networking/libiproute/ll_types.c
networking/libiproute/rt_names.c
networking/libiproute/rt_names.h
networking/libiproute/rtm_map.c
networking/libiproute/rtm_map.h

index 39af883240cd1e0aaf808db24c5e53ba05eb0bbe..86d27548baf219f43e5d2962f5ca7a7b41fdadc6 100644 (file)
@@ -162,7 +162,7 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n)
 
        if (!filter.family || filter.family == AF_PACKET) {
                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]) {
                        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]),
                                    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) {
                ifa->ifa_flags &= ~IFA_F_SECONDARY;
                printf("secondary ");
index ac7eec59883b67b33276901c9c712b1ff30efcc4..7031bed347805b1d47dead2812d0aad41f226f03 100644 (file)
@@ -196,7 +196,7 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
                printf("Deleted ");
        }
        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]) {
index bec530dcba979ecd55a5ca47bae2bd6bef0428bd..e52473117f6b03baf5ff864b4f63d93b31574137 100644 (file)
@@ -113,7 +113,7 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
        }
 
        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]) {
                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)
-               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]) {
                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;
                if (from) {
                        printf("realms %s/",
-                               rtnl_rtrealm_n2a(from, b1, sizeof(b1)));
+                               rtnl_rtrealm_n2a(from, b1));
                }
                printf("%s ",
-                       rtnl_rtrealm_n2a(to, b1, sizeof(b1)));
+                       rtnl_rtrealm_n2a(to, b1));
        }
 
        if (r->rtm_type == RTN_NAT) {
@@ -148,7 +148,7 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
                } else
                        printf("masquerade");
        } 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');
        /*fflush(stdout);*/
index 6a841aadbb0d9406c9e0714420dda8f5c4d0b5c8..836709c7e65fd3884be0e092ff7aacf488477f9e 100644 (file)
@@ -436,7 +436,7 @@ static void print_tunnel(struct ip_tunnel_parm *p)
                        printf(" inherit");
                if (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)))
                printf(" nopmtudisc");
index f50e3719338e89e6a42ea11d80809be8c07382fa..f59831cc190f0aca46a054f9b653fae983510d06 100644 (file)
@@ -17,7 +17,7 @@
 #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 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);
        }
        l = 0;
-       for (i=0; i<alen; i++) {
-               if (i==0) {
-                       snprintf(buf+l, blen, ":%02x"+1, addr[i]);
+       for (i = 0; i < alen; i++) {
+               if (i == 0) {
+                       snprintf(buf + l, blen, ":%02x"+1, addr[i]);
                        blen -= 2;
                        l += 2;
                } else {
-                       snprintf(buf+l, blen, ":%02x", addr[i]);
+                       snprintf(buf + l, blen, ":%02x", addr[i]);
                        blen -= 3;
                        l += 3;
                }
@@ -41,7 +41,7 @@ const char *ll_addr_n2a(unsigned char *addr, int alen, int type, char *buf, int
        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;
 
index a93493538cb947f9b2c8969b49e3f3f4e325bd37..145902b2e5ad2c5cf699e267e569bc557fef3e4c 100644 (file)
@@ -98,7 +98,7 @@ __PF(ECONET,econet)
 #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;
        id = ntohs(id);
@@ -110,7 +110,7 @@ const char *ll_proto_n2a(unsigned short id, char *buf, int len)
        return buf;
 }
 
-int ll_proto_a2n(unsigned short *id, char *buf)
+int FAST_FUNC ll_proto_a2n(unsigned short *id, char *buf)
 {
        unsigned i;
        for (i = 0; i < ARRAY_SIZE(llproto_names); i++) {
index d5d2a1f39ecd401a02cf7b0b69e4ee786a476642..3861c2870fe6dbe767999a7ed307742e8ef69901 100644 (file)
@@ -15,7 +15,7 @@
 #include "libbb.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[] =
        /* 0,                  */ "generic" "\0"
@@ -200,6 +200,6 @@ const char *ll_type_n2a(int type, char *buf, int len)
                        return aname;
                aname += strlen(aname) + 1;
        }
-       snprintf(buf, len, "[%d]", type);
+       sprintf(buf, "[%d]", type);
        return buf;
 }
index 2699dba3d7022eaf8d459ab21a0dbb264fd2e071..8dd16e3d38d2539e0a1555c15168ab9c855a4a70 100644 (file)
@@ -90,10 +90,10 @@ static void rtnl_rtprot_initialize(void)
        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) {
-               snprintf(buf, len, "%d", id);
+               sprintf(buf, "%d", id);
                return buf;
        }
 
@@ -101,11 +101,12 @@ const char* rtnl_rtprot_n2a(int id, char *buf, int len)
 
        if (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;
 }
 
-int rtnl_rtprot_a2n(uint32_t *id, char *arg)
+int FAST_FUNC rtnl_rtprot_a2n(uint32_t *id, char *arg)
 {
        rtnl_rtprot_initialize();
        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);
 }
 
-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) {
-               snprintf(buf, len, "%d", id);
+               sprintf(buf, "%d", id);
                return buf;
        }
 
@@ -138,11 +139,12 @@ const char* rtnl_rtscope_n2a(int id, char *buf, int len)
 
        if (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;
 }
 
-int rtnl_rtscope_a2n(uint32_t *id, char *arg)
+int FAST_FUNC rtnl_rtscope_a2n(uint32_t *id, char *arg)
 {
        rtnl_rtscope_initialize();
        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);
 }
 
-int rtnl_rtrealm_a2n(uint32_t *id, char *arg)
+int FAST_FUNC rtnl_rtrealm_a2n(uint32_t *id, char *arg)
 {
        rtnl_rtrealm_initialize();
        return rtnl_a2n(rtnl_rtrealm_tab, id, arg, 0);
 }
 
 #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) {
-               snprintf(buf, len, "%d", id);
+               sprintf(buf, "%d", id);
                return buf;
        }
 
@@ -177,7 +179,8 @@ const char* rtnl_rtrealm_n2a(int id, char *buf, int len)
 
        if (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;
 }
 #endif
@@ -193,10 +196,10 @@ static void rtnl_rtdsfield_initialize(void)
        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) {
-               snprintf(buf, len, "%d", id);
+               sprintf(buf, "%d", id);
                return buf;
        }
 
@@ -204,11 +207,12 @@ const char * rtnl_dsfield_n2a(int id, char *buf, int len)
 
        if (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;
 }
 
-int rtnl_dsfield_a2n(uint32_t *id, char *arg)
+int FAST_FUNC rtnl_dsfield_a2n(uint32_t *id, char *arg)
 {
        rtnl_rtdsfield_initialize();
        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);
 }
 
-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) {
-               snprintf(buf, len, "%d", id);
+               sprintf(buf, "%d", id);
                return buf;
        }
 
@@ -240,11 +244,12 @@ const char *rtnl_rttable_n2a(int id, char *buf, int len)
 
        if (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;
 }
 
-int rtnl_rttable_a2n(uint32_t *id, char *arg)
+int FAST_FUNC rtnl_rttable_a2n(uint32_t *id, char *arg)
 {
        rtnl_rttable_initialize();
        return rtnl_a2n(rtnl_rttable_tab, id, arg, 0);
index a2d4fd142528c1e465624b021ed3722fecbae616..e73aa851c08a8a2a540384559896ae8424c90e71 100644 (file)
@@ -4,25 +4,26 @@
 
 PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
 
-extern const char* rtnl_rtprot_n2a(int id, char *buf, int len);
-extern const char* rtnl_rtscope_n2a(int id, char *buf, int len);
-extern const char* rtnl_rtrealm_n2a(int id, char *buf, int len);
-extern const char* rtnl_dsfield_n2a(int id, char *buf, int len);
-extern const char* rtnl_rttable_n2a(int id, char *buf, int len);
-extern int rtnl_rtprot_a2n(uint32_t *id, char *arg);
-extern int rtnl_rtscope_a2n(uint32_t *id, char *arg);
-extern int rtnl_rtrealm_a2n(uint32_t *id, char *arg);
-extern int rtnl_dsfield_a2n(uint32_t *id, char *arg);
-extern int rtnl_rttable_a2n(uint32_t *id, char *arg);
+/* buf is SPRINT_BSIZE big */
+extern const char* rtnl_rtprot_n2a(int id, char *buf) FAST_FUNC;
+extern const char* rtnl_rtscope_n2a(int id, char *buf) FAST_FUNC;
+extern const char* rtnl_rtrealm_n2a(int id, char *buf) FAST_FUNC;
+extern const char* rtnl_dsfield_n2a(int id, char *buf) FAST_FUNC;
+extern const char* rtnl_rttable_n2a(int id, char *buf) FAST_FUNC;
+extern int rtnl_rtprot_a2n(uint32_t *id, char *arg) FAST_FUNC;
+extern int rtnl_rtscope_a2n(uint32_t *id, char *arg) FAST_FUNC;
+extern int rtnl_rtrealm_a2n(uint32_t *id, char *arg) FAST_FUNC;
+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,
-                               char *buf, int blen);
-extern int ll_addr_a2n(unsigned char *lladdr, int len, char *arg);
+                               char *buf, int blen) FAST_FUNC;
+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 int ll_proto_a2n(unsigned short *id, char *buf);
+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) FAST_FUNC;
 
 POP_SAVED_FUNCTION_VISIBILITY
 
index 6fe5c4b751c31057b13d81c83224a908c4f2af47..5e358e1058a089acb791932deff2eac577649896 100644 (file)
@@ -15,7 +15,7 @@
 #include "rt_names.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) {
        case RTN_UNSPEC:
@@ -43,13 +43,14 @@ const char *rtnl_rtntype_n2a(int id, char *buf, int len)
        case RTN_XRESOLVE:
                return "xresolve";
        default:
-               snprintf(buf, len, "%d", id);
+               /* buf is SPRINT_BSIZE big */
+               sprintf(buf, "%d", id);
                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 =
                "local\0""nat\0""broadcast\0""brd\0""anycast\0"
@@ -95,7 +96,7 @@ int rtnl_rtntype_a2n(int *id, char *arg)
        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;
        char *p = strchr(arg, '/');
index ab1b70e454701d2849d50bd30c9b486675a3d1c2..4377bd5902ffc640aa7f616412ce5c93731e729b 100644 (file)
@@ -4,10 +4,10 @@
 
 PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
 
-const char *rtnl_rtntype_n2a(int id, char *buf, int len);
-int rtnl_rtntype_a2n(int *id, char *arg);
+const char *rtnl_rtntype_n2a(int id, char *buf) FAST_FUNC;
+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