summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2015-10-08 13:02:28 +0200
committerDenys Vlasenko2015-10-08 13:02:28 +0200
commit3d8d5e8ad4d2df71e0307c385b3784586b545cbc (patch)
tree9e543be018a890ee5a2c40a2b3ed0de0f0e7dd36
parent7f3a2a22569eb8e4c9fcc1c7f4e51fe0c6155dae (diff)
downloadbusybox-3d8d5e8ad4d2df71e0307c385b3784586b545cbc.zip
busybox-3d8d5e8ad4d2df71e0307c385b3784586b545cbc.tar.gz
libiproute: use itoa() where appropriate
function old new delta rtnl_rtprot_a2n 31 88 +57 print_tunnel 647 640 -7 print_route 1865 1858 -7 print_linkinfo 820 812 -8 print_addrinfo 1241 1227 -14 rtnl_rttable_n2a 53 38 -15 rtnl_rtscope_n2a 53 38 -15 rtnl_rtrealm_n2a 53 38 -15 rtnl_dsfield_n2a 61 38 -23 rtnl_rtntype_n2a 118 89 -29 print_rule 724 689 -35 ipaddr_list_or_flush 1293 1253 -40 rtnl_rtprot_n2a 53 - -53 rtnl_rtprot_initialize 63 - -63 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 1/11 up/down: 57/-324) Total: -267 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/libiproute/ipaddress.c14
-rw-r--r--networking/libiproute/iproute.c3
-rw-r--r--networking/libiproute/iprule.c11
-rw-r--r--networking/libiproute/iptunnel.c3
-rw-r--r--networking/libiproute/ll_map.c1
-rw-r--r--networking/libiproute/rt_names.c47
-rw-r--r--networking/libiproute/rt_names.h11
-rw-r--r--networking/libiproute/rtm_map.c6
-rw-r--r--networking/libiproute/rtm_map.h2
9 files changed, 37 insertions, 61 deletions
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c
index a6d5129..8845cab 100644
--- a/networking/libiproute/ipaddress.c
+++ b/networking/libiproute/ipaddress.c
@@ -137,12 +137,11 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n)
{
unsigned m_flag = 0;
if (tb[IFLA_LINK]) {
- SPRINT_BUF(b1);
int iflink = *(int*)RTA_DATA(tb[IFLA_LINK]);
if (iflink == 0)
printf("@NONE: ");
else {
- printf("@%s: ", ll_idx_n2a(iflink, b1));
+ printf("@%s: ", ll_index_to_name(iflink));
m_flag = ll_index_to_flags(iflink);
m_flag = !(m_flag & IFF_UP);
}
@@ -158,8 +157,7 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n)
printf("qdisc %s ", (char*)RTA_DATA(tb[IFLA_QDISC]));
#ifdef IFLA_MASTER
if (tb[IFLA_MASTER]) {
- SPRINT_BUF(b1);
- printf("master %s ", ll_idx_n2a(*(int*)RTA_DATA(tb[IFLA_MASTER]), b1));
+ printf("master %s ", ll_index_to_name(*(int*)RTA_DATA(tb[IFLA_MASTER])));
}
#endif
/* IFLA_OPERSTATE was added to kernel with the same commit as IFF_DORMANT */
@@ -218,7 +216,6 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM,
int len = n->nlmsg_len;
struct rtattr * rta_tb[IFA_MAX+1];
char abuf[256];
- SPRINT_BUF(b1);
if (n->nlmsg_type != RTM_NEWADDR && n->nlmsg_type != RTM_DELADDR)
return 0;
@@ -250,7 +247,7 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM,
if (rta_tb[IFA_LABEL])
label = RTA_DATA(rta_tb[IFA_LABEL]);
else
- label = ll_idx_n2a(ifa->ifa_index, b1);
+ label = ll_index_to_name(ifa->ifa_index);
if (fnmatch(G_filter.label, label, 0) != 0)
return 0;
}
@@ -325,7 +322,7 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM,
abuf, sizeof(abuf))
);
}
- printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1));
+ printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope));
if (ifa->ifa_flags & IFA_F_SECONDARY) {
ifa->ifa_flags &= ~IFA_F_SECONDARY;
printf("secondary ");
@@ -556,12 +553,11 @@ int FAST_FUNC ipaddr_list_or_flush(char **argv, int flush)
continue;
}
if (G_filter.label) {
- SPRINT_BUF(b1);
const char *label;
if (tb[IFA_LABEL])
label = RTA_DATA(tb[IFA_LABEL]);
else
- label = ll_idx_n2a(ifa->ifa_index, b1);
+ label = ll_index_to_name(ifa->ifa_index);
if (fnmatch(G_filter.label, label, 0) != 0)
continue;
}
diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c
index 170c67b..6ecd5f7 100644
--- a/networking/libiproute/iproute.c
+++ b/networking/libiproute/iproute.c
@@ -87,7 +87,6 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
inet_prefix dst;
inet_prefix src;
int host_len = -1;
- SPRINT_BUF(b1);
if (n->nlmsg_type != RTM_NEWROUTE && n->nlmsg_type != RTM_DELROUTE) {
fprintf(stderr, "Not a route: %08x %08x %08x\n",
@@ -236,7 +235,7 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
printf("Deleted ");
}
if (r->rtm_type != RTN_UNICAST /* && !G_filter.type - always 0 */) {
- printf("%s ", rtnl_rtntype_n2a(r->rtm_type, b1));
+ printf("%s ", rtnl_rtntype_n2a(r->rtm_type));
}
if (tb[RTA_DST]) {
diff --git a/networking/libiproute/iprule.c b/networking/libiproute/iprule.c
index 8dbe6bd..774a3e2 100644
--- a/networking/libiproute/iprule.c
+++ b/networking/libiproute/iprule.c
@@ -45,7 +45,6 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
int host_len = -1;
struct rtattr * tb[RTA_MAX+1];
char abuf[256];
- SPRINT_BUF(b1);
if (n->nlmsg_type != RTM_NEWRULE)
return 0;
@@ -110,7 +109,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));
+ printf("tos %s ", rtnl_dsfield_n2a(r->rtm_tos));
}
if (tb[RTA_PROTOINFO]) {
printf("fwmark %#x ", *(uint32_t*)RTA_DATA(tb[RTA_PROTOINFO]));
@@ -121,7 +120,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));
+ printf("lookup %s ", rtnl_rttable_n2a(r->rtm_table));
if (tb[RTA_FLOW]) {
uint32_t to = *(uint32_t*)RTA_DATA(tb[RTA_FLOW]);
@@ -129,10 +128,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));
+ rtnl_rtrealm_n2a(from));
}
printf("%s ",
- rtnl_rtrealm_n2a(to, b1));
+ rtnl_rtrealm_n2a(to));
}
if (r->rtm_type == RTN_NAT) {
@@ -145,7 +144,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), stdout);
+ fputs(rtnl_rtntype_n2a(r->rtm_type), stdout);
bb_putchar('\n');
/*fflush_all();*/
diff --git a/networking/libiproute/iptunnel.c b/networking/libiproute/iptunnel.c
index b54c3c5..a65d5e5 100644
--- a/networking/libiproute/iptunnel.c
+++ b/networking/libiproute/iptunnel.c
@@ -432,13 +432,12 @@ static void print_tunnel(struct ip_tunnel_parm *p)
else
printf(" ttl inherit ");
if (p->iph.tos) {
- SPRINT_BUF(b1);
printf(" tos");
if (p->iph.tos & 1)
printf(" inherit");
if (p->iph.tos & ~1)
printf("%c%s ", p->iph.tos & 1 ? '/' : ' ',
- rtnl_dsfield_n2a(p->iph.tos & ~1, b1));
+ rtnl_dsfield_n2a(p->iph.tos & ~1));
}
if (!(p->iph.frag_off & htons(IP_DF)))
printf(" nopmtudisc");
diff --git a/networking/libiproute/ll_map.c b/networking/libiproute/ll_map.c
index 27cd90f..feb6e8d 100644
--- a/networking/libiproute/ll_map.c
+++ b/networking/libiproute/ll_map.c
@@ -99,7 +99,6 @@ const char FAST_FUNC *ll_idx_n2a(int idx, char *buf)
return buf;
}
-
const char FAST_FUNC *ll_index_to_name(int idx)
{
static char nbuf[16];
diff --git a/networking/libiproute/rt_names.c b/networking/libiproute/rt_names.c
index c474ab9..375f145 100644
--- a/networking/libiproute/rt_names.c
+++ b/networking/libiproute/rt_names.c
@@ -88,21 +88,20 @@ static void rtnl_rtprot_initialize(void)
rtnl_tab_initialize("/etc/iproute2/rt_protos", rtnl_rtprot_tab->tab);
}
-const char* FAST_FUNC rtnl_rtprot_n2a(int id, char *buf)
+#if 0 /* UNUSED */
+const char* FAST_FUNC rtnl_rtprot_n2a(int id)
{
if (id < 0 || id >= 256) {
- sprintf(buf, "%d", id);
- return buf;
+ return itoa(id);
}
rtnl_rtprot_initialize();
if (rtnl_rtprot_tab->tab[id])
return rtnl_rtprot_tab->tab[id];
- /* buf is SPRINT_BSIZE big */
- sprintf(buf, "%d", id);
- return buf;
+ return itoa(id);
}
+#endif
int FAST_FUNC rtnl_rtprot_a2n(uint32_t *id, char *arg)
{
@@ -126,20 +125,17 @@ static void rtnl_rtscope_initialize(void)
rtnl_tab_initialize("/etc/iproute2/rt_scopes", rtnl_rtscope_tab->tab);
}
-const char* FAST_FUNC rtnl_rtscope_n2a(int id, char *buf)
+const char* FAST_FUNC rtnl_rtscope_n2a(int id)
{
if (id < 0 || id >= 256) {
- sprintf(buf, "%d", id);
- return buf;
+ return itoa(id);
}
rtnl_rtscope_initialize();
if (rtnl_rtscope_tab->tab[id])
return rtnl_rtscope_tab->tab[id];
- /* buf is SPRINT_BSIZE big */
- sprintf(buf, "%d", id);
- return buf;
+ return itoa(id);
}
int FAST_FUNC rtnl_rtscope_a2n(uint32_t *id, char *arg)
@@ -166,20 +162,17 @@ int FAST_FUNC rtnl_rtrealm_a2n(uint32_t *id, char *arg)
}
#if ENABLE_FEATURE_IP_RULE
-const char* FAST_FUNC rtnl_rtrealm_n2a(int id, char *buf)
+const char* FAST_FUNC rtnl_rtrealm_n2a(int id)
{
if (id < 0 || id >= 256) {
- sprintf(buf, "%d", id);
- return buf;
+ return itoa(id);
}
rtnl_rtrealm_initialize();
if (rtnl_rtrealm_tab->tab[id])
return rtnl_rtrealm_tab->tab[id];
- /* buf is SPRINT_BSIZE big */
- sprintf(buf, "%d", id);
- return buf;
+ return itoa(id);
}
#endif
@@ -194,20 +187,17 @@ static void rtnl_rtdsfield_initialize(void)
rtnl_tab_initialize("/etc/iproute2/rt_dsfield", rtnl_rtdsfield_tab->tab);
}
-const char* FAST_FUNC rtnl_dsfield_n2a(int id, char *buf)
+const char* FAST_FUNC rtnl_dsfield_n2a(int id)
{
if (id < 0 || id >= 256) {
- sprintf(buf, "%d", id);
- return buf;
+ return itoa(id);
}
rtnl_rtdsfield_initialize();
if (rtnl_rtdsfield_tab->tab[id])
return rtnl_rtdsfield_tab->tab[id];
- /* buf is SPRINT_BSIZE big */
- sprintf(buf, "0x%02x", id);
- return buf;
+ return itoa(id);
}
int FAST_FUNC rtnl_dsfield_a2n(uint32_t *id, char *arg)
@@ -231,20 +221,17 @@ static void rtnl_rttable_initialize(void)
rtnl_tab_initialize("/etc/iproute2/rt_tables", rtnl_rttable_tab->tab);
}
-const char* FAST_FUNC rtnl_rttable_n2a(int id, char *buf)
+const char* FAST_FUNC rtnl_rttable_n2a(int id)
{
if (id < 0 || id >= 256) {
- sprintf(buf, "%d", id);
- return buf;
+ return itoa(id);
}
rtnl_rttable_initialize();
if (rtnl_rttable_tab->tab[id])
return rtnl_rttable_tab->tab[id];
- /* buf is SPRINT_BSIZE big */
- sprintf(buf, "%d", id);
- return buf;
+ return itoa(id);
}
int FAST_FUNC rtnl_rttable_a2n(uint32_t *id, char *arg)
diff --git a/networking/libiproute/rt_names.h b/networking/libiproute/rt_names.h
index e73aa85..29932d6 100644
--- a/networking/libiproute/rt_names.h
+++ b/networking/libiproute/rt_names.h
@@ -4,12 +4,11 @@
PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
-/* 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 const char* rtnl_rtprot_n2a(int id) FAST_FUNC;
+extern const char* rtnl_rtscope_n2a(int id) FAST_FUNC;
+extern const char* rtnl_rtrealm_n2a(int id) FAST_FUNC;
+extern const char* rtnl_dsfield_n2a(int id) FAST_FUNC;
+extern const char* rtnl_rttable_n2a(int id) 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;
diff --git a/networking/libiproute/rtm_map.c b/networking/libiproute/rtm_map.c
index 3bab53b..c763da0 100644
--- a/networking/libiproute/rtm_map.c
+++ b/networking/libiproute/rtm_map.c
@@ -12,7 +12,7 @@
#include "rt_names.h"
#include "utils.h"
-const char* FAST_FUNC rtnl_rtntype_n2a(int id, char *buf)
+const char* FAST_FUNC rtnl_rtntype_n2a(int id)
{
switch (id) {
case RTN_UNSPEC:
@@ -40,9 +40,7 @@ const char* FAST_FUNC rtnl_rtntype_n2a(int id, char *buf)
case RTN_XRESOLVE:
return "xresolve";
default:
- /* buf is SPRINT_BSIZE big */
- sprintf(buf, "%d", id);
- return buf;
+ return itoa(id);
}
}
diff --git a/networking/libiproute/rtm_map.h b/networking/libiproute/rtm_map.h
index 4377bd5..63b6651 100644
--- a/networking/libiproute/rtm_map.h
+++ b/networking/libiproute/rtm_map.h
@@ -4,7 +4,7 @@
PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
-const char *rtnl_rtntype_n2a(int id, char *buf) FAST_FUNC;
+const char *rtnl_rtntype_n2a(int id) FAST_FUNC;
int rtnl_rtntype_a2n(int *id, char *arg) FAST_FUNC;
int get_rt_realms(uint32_t *realms, char *arg) FAST_FUNC;