aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-10-29 19:33:26 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-10-29 19:33:26 +0000
commitdfc0740b044cad91100bae35fa060b31a88f40ce (patch)
tree3a9f63ba36ec3b0a1ae248fb759caafa55f1480c
parent15ca51e3e2a31efc275b616106244d8ec3f8f773 (diff)
downloadbusybox-w32-dfc0740b044cad91100bae35fa060b31a88f40ce.tar.gz
busybox-w32-dfc0740b044cad91100bae35fa060b31a88f40ce.tar.bz2
busybox-w32-dfc0740b044cad91100bae35fa060b31a88f40ce.zip
ll_types.c: optimize link type table, make it conditional
on FEATURE_IP_RARE_PROTOCOLS function old new delta static.arphrd_name - 373 +373 static.arphrd_type - 124 +124 ll_type_n2a 58 78 +20 static.arphrd_names 496 - -496 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 1/0 up/down: 517/-496) Total: 21 bytes text data bss dec hex filename 776880 974 9420 787274 c034a busybox_old 776594 974 9420 786988 c022c busybox_unstripped
-rw-r--r--networking/Config.in10
-rw-r--r--networking/libiproute/Kbuild1
-rw-r--r--networking/libiproute/ipaddress.c2
-rw-r--r--networking/libiproute/ll_proto.c10
-rw-r--r--networking/libiproute/ll_types.c232
-rw-r--r--networking/libiproute/rt_names.h2
6 files changed, 179 insertions, 78 deletions
diff --git a/networking/Config.in b/networking/Config.in
index bd6c6ef7a..7dbad30b3 100644
--- a/networking/Config.in
+++ b/networking/Config.in
@@ -463,6 +463,16 @@ config FEATURE_IP_SHORT_FORMS
463 Say N unless you desparately need the short form of the ip 463 Say N unless you desparately need the short form of the ip
464 object commands. 464 object commands.
465 465
466config FEATURE_IP_RARE_PROTOCOLS
467 bool "Suport display of rarely-used link types."
468 default n
469 depends on IP
470 help
471 If you are not going to use links of type "frad", "econet",
472 "bif" etc, you probably don't need to enable this.
473 Ethernet, wireless, infrared, ppp/slip, ip tunnelling
474 link types are supported without this option selected.
475
466config IPADDR 476config IPADDR
467 bool 477 bool
468 default y 478 default y
diff --git a/networking/libiproute/Kbuild b/networking/libiproute/Kbuild
index 9e9e760ad..5f9dd32b6 100644
--- a/networking/libiproute/Kbuild
+++ b/networking/libiproute/Kbuild
@@ -62,4 +62,3 @@ lib-$(CONFIG_FEATURE_IP_RULE) += \
62 iprule.o \ 62 iprule.o \
63 rt_names.o \ 63 rt_names.o \
64 utils.o 64 utils.o
65
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c
index 86eaf7d86..b25981900 100644
--- a/networking/libiproute/ipaddress.c
+++ b/networking/libiproute/ipaddress.c
@@ -173,7 +173,7 @@ static int print_linkinfo(struct sockaddr_nl ATTRIBUTE_UNUSED *who,
173 b1, sizeof(b1)), fp); 173 b1, sizeof(b1)), fp);
174 } 174 }
175 if (tb[IFLA_BROADCAST]) { 175 if (tb[IFLA_BROADCAST]) {
176 if (ifi->ifi_flags&IFF_POINTOPOINT) 176 if (ifi->ifi_flags & IFF_POINTOPOINT)
177 fprintf(fp, " peer "); 177 fprintf(fp, " peer ");
178 else 178 else
179 fprintf(fp, " brd "); 179 fprintf(fp, " brd ");
diff --git a/networking/libiproute/ll_proto.c b/networking/libiproute/ll_proto.c
index 4e62e876e..6933ce239 100644
--- a/networking/libiproute/ll_proto.c
+++ b/networking/libiproute/ll_proto.c
@@ -20,6 +20,12 @@
20#include <linux/if_ether.h> 20#include <linux/if_ether.h>
21#endif 21#endif
22 22
23#ifdef UNUSED
24/* Before re-enabling this, please (1) conditionalize exotic protocols
25 * on CONFIG_something, and (2) decouple strings and numbers
26 * (use llproto_ids[] = n,n,n..; and llproto_names[] = "loop\0" "pup\0" ...;)
27 */
28
23#define __PF(f,n) { ETH_P_##f, #n }, 29#define __PF(f,n) { ETH_P_##f, #n },
24static struct { 30static struct {
25 int id; 31 int id;
@@ -90,7 +96,7 @@ __PF(ECONET,econet)
90#undef __PF 96#undef __PF
91 97
92 98
93const char * ll_proto_n2a(unsigned short id, char *buf, int len) 99const char *ll_proto_n2a(unsigned short id, char *buf, int len)
94{ 100{
95 int i; 101 int i;
96 102
@@ -118,3 +124,5 @@ int ll_proto_a2n(unsigned short *id, char *buf)
118 *id = htons(*id); 124 *id = htons(*id);
119 return 0; 125 return 0;
120} 126}
127
128#endif /* UNUSED */
diff --git a/networking/libiproute/ll_types.c b/networking/libiproute/ll_types.c
index 84fd628cb..60a78c715 100644
--- a/networking/libiproute/ll_types.c
+++ b/networking/libiproute/ll_types.c
@@ -15,102 +15,184 @@
15#include "libbb.h" 15#include "libbb.h"
16#include "rt_names.h" 16#include "rt_names.h"
17 17
18const char* ll_type_n2a(int type, char *buf, int len) 18const char *ll_type_n2a(int type, char *buf, int len)
19{ 19{
20#define __PF(f,n) { ARPHRD_##f, #n }, 20 static const char arphrd_name[] =
21static const struct { 21 /* 0, */ "generic" "\0"
22 int type; 22 /* ARPHRD_LOOPBACK, */ "loopback" "\0"
23 const char *name; 23 /* ARPHRD_ETHER, */ "ether" "\0"
24} arphrd_names[] = {
25{ 0, "generic" },
26__PF(ETHER,ether)
27__PF(EETHER,eether)
28__PF(AX25,ax25)
29__PF(PRONET,pronet)
30__PF(CHAOS,chaos)
31#ifdef ARPHRD_IEEE802_TR 24#ifdef ARPHRD_IEEE802_TR
32__PF(IEEE802,ieee802) 25 /* ARPHRD_IEEE802, */ "ieee802" "\0"
26 /* ARPHRD_IEEE802_TR, */ "tr" "\0"
33#else 27#else
34__PF(IEEE802,tr) 28 /* ARPHRD_IEEE802, */ "tr" "\0"
35#endif 29#endif
36__PF(ARCNET,arcnet) 30#ifdef ARPHRD_IEEE80211
37__PF(APPLETLK,atalk) 31 /* ARPHRD_IEEE80211, */ "ieee802.11" "\0"
38__PF(DLCI,dlci)
39#ifdef ARPHRD_ATM
40__PF(ATM,atm)
41#endif 32#endif
42__PF(METRICOM,metricom)
43#ifdef ARPHRD_IEEE1394 33#ifdef ARPHRD_IEEE1394
44__PF(IEEE1394,ieee1394) 34 /* ARPHRD_IEEE1394, */ "ieee1394" "\0"
35#endif
36 /* ARPHRD_IRDA, */ "irda" "\0"
37 /* ARPHRD_SLIP, */ "slip" "\0"
38 /* ARPHRD_CSLIP, */ "cslip" "\0"
39 /* ARPHRD_SLIP6, */ "slip6" "\0"
40 /* ARPHRD_CSLIP6, */ "cslip6" "\0"
41 /* ARPHRD_PPP, */ "ppp" "\0"
42 /* ARPHRD_TUNNEL, */ "ipip" "\0"
43 /* ARPHRD_TUNNEL6, */ "tunnel6" "\0"
44 /* ARPHRD_SIT, */ "sit" "\0"
45 /* ARPHRD_IPGRE, */ "gre" "\0"
46#ifdef ARPHRD_VOID
47 /* ARPHRD_VOID, */ "void" "\0"
45#endif 48#endif
46 49
47__PF(SLIP,slip) 50#if ENABLE_FEATURE_IP_RARE_PROTOCOLS
48__PF(CSLIP,cslip) 51 /* ARPHRD_EETHER, */ "eether" "\0"
49__PF(SLIP6,slip6) 52 /* ARPHRD_AX25, */ "ax25" "\0"
50__PF(CSLIP6,cslip6) 53 /* ARPHRD_PRONET, */ "pronet" "\0"
51__PF(RSRVD,rsrvd) 54 /* ARPHRD_CHAOS, */ "chaos" "\0"
52__PF(ADAPT,adapt) 55 /* ARPHRD_ARCNET, */ "arcnet" "\0"
53__PF(ROSE,rose) 56 /* ARPHRD_APPLETLK, */ "atalk" "\0"
54__PF(X25,x25) 57 /* ARPHRD_DLCI, */ "dlci" "\0"
58#ifdef ARPHRD_ATM
59 /* ARPHRD_ATM, */ "atm" "\0"
60#endif
61 /* ARPHRD_METRICOM, */ "metricom" "\0"
62 /* ARPHRD_RSRVD, */ "rsrvd" "\0"
63 /* ARPHRD_ADAPT, */ "adapt" "\0"
64 /* ARPHRD_ROSE, */ "rose" "\0"
65 /* ARPHRD_X25, */ "x25" "\0"
55#ifdef ARPHRD_HWX25 66#ifdef ARPHRD_HWX25
56__PF(HWX25,hwx25) 67 /* ARPHRD_HWX25, */ "hwx25" "\0"
57#endif 68#endif
58__PF(PPP,ppp) 69 /* ARPHRD_HDLC, */ "hdlc" "\0"
59__PF(HDLC,hdlc) 70 /* ARPHRD_LAPB, */ "lapb" "\0"
60__PF(LAPB,lapb)
61#ifdef ARPHRD_DDCMP 71#ifdef ARPHRD_DDCMP
62__PF(DDCMP,ddcmp) 72 /* ARPHRD_DDCMP, */ "ddcmp" "\0"
63__PF(RAWHDLC,rawhdlc) 73 /* ARPHRD_RAWHDLC, */ "rawhdlc" "\0"
64#endif 74#endif
75 /* ARPHRD_FRAD, */ "frad" "\0"
76 /* ARPHRD_SKIP, */ "skip" "\0"
77 /* ARPHRD_LOCALTLK, */ "ltalk" "\0"
78 /* ARPHRD_FDDI, */ "fddi" "\0"
79 /* ARPHRD_BIF, */ "bif" "\0"
80 /* ARPHRD_IPDDP, */ "ip/ddp" "\0"
81 /* ARPHRD_PIMREG, */ "pimreg" "\0"
82 /* ARPHRD_HIPPI, */ "hippi" "\0"
83 /* ARPHRD_ASH, */ "ash" "\0"
84 /* ARPHRD_ECONET, */ "econet" "\0"
85 /* ARPHRD_FCPP, */ "fcpp" "\0"
86 /* ARPHRD_FCAL, */ "fcal" "\0"
87 /* ARPHRD_FCPL, */ "fcpl" "\0"
88 /* ARPHRD_FCFABRIC, */ "fcfb0" "\0"
89 /* ARPHRD_FCFABRIC+1, */ "fcfb1" "\0"
90 /* ARPHRD_FCFABRIC+2, */ "fcfb2" "\0"
91 /* ARPHRD_FCFABRIC+3, */ "fcfb3" "\0"
92 /* ARPHRD_FCFABRIC+4, */ "fcfb4" "\0"
93 /* ARPHRD_FCFABRIC+5, */ "fcfb5" "\0"
94 /* ARPHRD_FCFABRIC+6, */ "fcfb6" "\0"
95 /* ARPHRD_FCFABRIC+7, */ "fcfb7" "\0"
96 /* ARPHRD_FCFABRIC+8, */ "fcfb8" "\0"
97 /* ARPHRD_FCFABRIC+9, */ "fcfb9" "\0"
98 /* ARPHRD_FCFABRIC+10, */ "fcfb10" "\0"
99 /* ARPHRD_FCFABRIC+11, */ "fcfb11" "\0"
100 /* ARPHRD_FCFABRIC+12, */ "fcfb12" "\0"
101#endif /* FEATURE_IP_RARE_PROTOCOLS */
102 ;
103
104 /* Keep these arrays in sync! */
65 105
66__PF(TUNNEL,ipip) 106 static const uint16_t arphrd_type[] = {
67__PF(TUNNEL6,tunnel6) 107 0, /* "generic" "\0" */
68__PF(FRAD,frad) 108 ARPHRD_LOOPBACK, /* "loopback" "\0" */
69__PF(SKIP,skip) 109 ARPHRD_ETHER, /* "ether" "\0" */
70__PF(LOOPBACK,loopback)
71__PF(LOCALTLK,ltalk)
72__PF(FDDI,fddi)
73__PF(BIF,bif)
74__PF(SIT,sit)
75__PF(IPDDP,ip/ddp)
76__PF(IPGRE,gre)
77__PF(PIMREG,pimreg)
78__PF(HIPPI,hippi)
79__PF(ASH,ash)
80__PF(ECONET,econet)
81__PF(IRDA,irda)
82__PF(FCPP,fcpp)
83__PF(FCAL,fcal)
84__PF(FCPL,fcpl)
85__PF(FCFABRIC,fcfb0)
86__PF(FCFABRIC+1,fcfb1)
87__PF(FCFABRIC+2,fcfb2)
88__PF(FCFABRIC+3,fcfb3)
89__PF(FCFABRIC+4,fcfb4)
90__PF(FCFABRIC+5,fcfb5)
91__PF(FCFABRIC+6,fcfb6)
92__PF(FCFABRIC+7,fcfb7)
93__PF(FCFABRIC+8,fcfb8)
94__PF(FCFABRIC+9,fcfb9)
95__PF(FCFABRIC+10,fcfb10)
96__PF(FCFABRIC+11,fcfb11)
97__PF(FCFABRIC+12,fcfb12)
98#ifdef ARPHRD_IEEE802_TR 110#ifdef ARPHRD_IEEE802_TR
99__PF(IEEE802_TR,tr) 111 ARPHRD_IEEE802, /* "ieee802" "\0" */
112 ARPHRD_IEEE802_TR, /* "tr" "\0" */
113#else
114 ARPHRD_IEEE802, /* "tr" "\0" */
100#endif 115#endif
101#ifdef ARPHRD_IEEE80211 116#ifdef ARPHRD_IEEE80211
102__PF(IEEE80211,ieee802.11) 117 ARPHRD_IEEE80211, /* "ieee802.11" "\0" */
103#endif 118#endif
119#ifdef ARPHRD_IEEE1394
120 ARPHRD_IEEE1394, /* "ieee1394" "\0" */
121#endif
122 ARPHRD_IRDA, /* "irda" "\0" */
123 ARPHRD_SLIP, /* "slip" "\0" */
124 ARPHRD_CSLIP, /* "cslip" "\0" */
125 ARPHRD_SLIP6, /* "slip6" "\0" */
126 ARPHRD_CSLIP6, /* "cslip6" "\0" */
127 ARPHRD_PPP, /* "ppp" "\0" */
128 ARPHRD_TUNNEL, /* "ipip" "\0" */
129 ARPHRD_TUNNEL6, /* "tunnel6" "\0" */
130 ARPHRD_SIT, /* "sit" "\0" */
131 ARPHRD_IPGRE, /* "gre" "\0" */
104#ifdef ARPHRD_VOID 132#ifdef ARPHRD_VOID
105__PF(VOID,void) 133 ARPHRD_VOID, /* "void" "\0" */
134#endif
135
136#if ENABLE_FEATURE_IP_RARE_PROTOCOLS
137 ARPHRD_EETHER, /* "eether" "\0" */
138 ARPHRD_AX25, /* "ax25" "\0" */
139 ARPHRD_PRONET, /* "pronet" "\0" */
140 ARPHRD_CHAOS, /* "chaos" "\0" */
141 ARPHRD_ARCNET, /* "arcnet" "\0" */
142 ARPHRD_APPLETLK, /* "atalk" "\0" */
143 ARPHRD_DLCI, /* "dlci" "\0" */
144#ifdef ARPHRD_ATM
145 ARPHRD_ATM, /* "atm" "\0" */
146#endif
147 ARPHRD_METRICOM, /* "metricom" "\0" */
148 ARPHRD_RSRVD, /* "rsrvd" "\0" */
149 ARPHRD_ADAPT, /* "adapt" "\0" */
150 ARPHRD_ROSE, /* "rose" "\0" */
151 ARPHRD_X25, /* "x25" "\0" */
152#ifdef ARPHRD_HWX25
153 ARPHRD_HWX25, /* "hwx25" "\0" */
154#endif
155 ARPHRD_HDLC, /* "hdlc" "\0" */
156 ARPHRD_LAPB, /* "lapb" "\0" */
157#ifdef ARPHRD_DDCMP
158 ARPHRD_DDCMP, /* "ddcmp" "\0" */
159 ARPHRD_RAWHDLC, /* "rawhdlc" "\0" */
106#endif 160#endif
107}; 161 ARPHRD_FRAD, /* "frad" "\0" */
108#undef __PF 162 ARPHRD_SKIP, /* "skip" "\0" */
163 ARPHRD_LOCALTLK, /* "ltalk" "\0" */
164 ARPHRD_FDDI, /* "fddi" "\0" */
165 ARPHRD_BIF, /* "bif" "\0" */
166 ARPHRD_IPDDP, /* "ip/ddp" "\0" */
167 ARPHRD_PIMREG, /* "pimreg" "\0" */
168 ARPHRD_HIPPI, /* "hippi" "\0" */
169 ARPHRD_ASH, /* "ash" "\0" */
170 ARPHRD_ECONET, /* "econet" "\0" */
171 ARPHRD_FCPP, /* "fcpp" "\0" */
172 ARPHRD_FCAL, /* "fcal" "\0" */
173 ARPHRD_FCPL, /* "fcpl" "\0" */
174 ARPHRD_FCFABRIC, /* "fcfb0" "\0" */
175 ARPHRD_FCFABRIC+1, /* "fcfb1" "\0" */
176 ARPHRD_FCFABRIC+2, /* "fcfb2" "\0" */
177 ARPHRD_FCFABRIC+3, /* "fcfb3" "\0" */
178 ARPHRD_FCFABRIC+4, /* "fcfb4" "\0" */
179 ARPHRD_FCFABRIC+5, /* "fcfb5" "\0" */
180 ARPHRD_FCFABRIC+6, /* "fcfb6" "\0" */
181 ARPHRD_FCFABRIC+7, /* "fcfb7" "\0" */
182 ARPHRD_FCFABRIC+8, /* "fcfb8" "\0" */
183 ARPHRD_FCFABRIC+9, /* "fcfb9" "\0" */
184 ARPHRD_FCFABRIC+10, /* "fcfb10" "\0" */
185 ARPHRD_FCFABRIC+11, /* "fcfb11" "\0" */
186 ARPHRD_FCFABRIC+12, /* "fcfb12" "\0" */
187#endif /* FEATURE_IP_RARE_PROTOCOLS */
188 };
109 189
110 int i; 190 int i;
111 for (i = 0; i < ARRAY_SIZE(arphrd_names); i++) { 191 const char *aname = arphrd_name;
112 if (arphrd_names[i].type == type) 192 for (i = 0; i < ARRAY_SIZE(arphrd_type); i++) {
113 return arphrd_names[i].name; 193 if (arphrd_type[i] == type)
194 return aname;
195 aname += strlen(aname) + 1;
114 } 196 }
115 snprintf(buf, len, "[%d]", type); 197 snprintf(buf, len, "[%d]", type);
116 return buf; 198 return buf;
diff --git a/networking/libiproute/rt_names.h b/networking/libiproute/rt_names.h
index 98c22b0b0..f560f248b 100644
--- a/networking/libiproute/rt_names.h
+++ b/networking/libiproute/rt_names.h
@@ -22,7 +22,9 @@ extern const char* ll_addr_n2a(unsigned char *addr, int alen, int type,
22 char *buf, int blen); 22 char *buf, int blen);
23extern int ll_addr_a2n(unsigned char *lladdr, int len, char *arg); 23extern int ll_addr_a2n(unsigned char *lladdr, int len, char *arg);
24 24
25#ifdef UNUSED
25extern const char* ll_proto_n2a(unsigned short id, char *buf, int len); 26extern const char* ll_proto_n2a(unsigned short id, char *buf, int len);
26extern int ll_proto_a2n(unsigned short *id, char *buf); 27extern int ll_proto_a2n(unsigned short *id, char *buf);
28#endif
27 29
28#endif 30#endif