aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/libiproute/ll_proto.c108
1 files changed, 85 insertions, 23 deletions
diff --git a/networking/libiproute/ll_proto.c b/networking/libiproute/ll_proto.c
index 7aac8364d..60add2f0c 100644
--- a/networking/libiproute/ll_proto.c
+++ b/networking/libiproute/ll_proto.c
@@ -14,19 +14,78 @@
14 14
15#include <netinet/if_ether.h> 15#include <netinet/if_ether.h>
16 16
17#if !ENABLE_WERROR 17/* Please conditionalize exotic protocols on CONFIG_something */
18#warning de-bloat 18
19static const uint16_t llproto_ids[] =
20#define __PF(f,n) ETH_P_##f,
21__PF(LOOP,loop)
22__PF(PUP,pup)
23#ifdef ETH_P_PUPAT
24__PF(PUPAT,pupat)
19#endif 25#endif
20/* Before re-enabling this, please (1) conditionalize exotic protocols 26__PF(IP,ip)
21 * on CONFIG_something, and (2) decouple strings and numbers 27__PF(X25,x25)
22 * (use llproto_ids[] = n,n,n..; and llproto_names[] = "loop\0" "pup\0" ...;) 28__PF(ARP,arp)
23 */ 29__PF(BPQ,bpq)
30#ifdef ETH_P_IEEEPUP
31__PF(IEEEPUP,ieeepup)
32#endif
33#ifdef ETH_P_IEEEPUPAT
34__PF(IEEEPUPAT,ieeepupat)
35#endif
36__PF(DEC,dec)
37__PF(DNA_DL,dna_dl)
38__PF(DNA_RC,dna_rc)
39__PF(DNA_RT,dna_rt)
40__PF(LAT,lat)
41__PF(DIAG,diag)
42__PF(CUST,cust)
43__PF(SCA,sca)
44__PF(RARP,rarp)
45__PF(ATALK,atalk)
46__PF(AARP,aarp)
47__PF(IPX,ipx)
48__PF(IPV6,ipv6)
49#ifdef ETH_P_PPP_DISC
50__PF(PPP_DISC,ppp_disc)
51#endif
52#ifdef ETH_P_PPP_SES
53__PF(PPP_SES,ppp_ses)
54#endif
55#ifdef ETH_P_ATMMPOA
56__PF(ATMMPOA,atmmpoa)
57#endif
58#ifdef ETH_P_ATMFATE
59__PF(ATMFATE,atmfate)
60#endif
61
62__PF(802_3,802_3)
63__PF(AX25,ax25)
64__PF(ALL,all)
65__PF(802_2,802_2)
66__PF(SNAP,snap)
67__PF(DDCMP,ddcmp)
68__PF(WAN_PPP,wan_ppp)
69__PF(PPP_MP,ppp_mp)
70__PF(LOCALTALK,localtalk)
71__PF(PPPTALK,ppptalk)
72__PF(TR_802_2,tr_802_2)
73__PF(MOBITEX,mobitex)
74__PF(CONTROL,control)
75__PF(IRDA,irda)
76#ifdef ETH_P_ECONET
77__PF(ECONET,econet)
78#endif
79
800x8100,
81ETH_P_IP
82;
83#undef __PF
84
85/* Keep declarations above and below in sync! */
24 86
25#define __PF(f,n) { ETH_P_##f, #n }, 87static const char llproto_names[] =
26static struct { 88#define __PF(f,n) #n "\0"
27 int id;
28 const char *name;
29} llproto_names[] = {
30__PF(LOOP,loop) 89__PF(LOOP,loop)
31__PF(PUP,pup) 90__PF(PUP,pup)
32#ifdef ETH_P_PUPAT 91#ifdef ETH_P_PUPAT
@@ -86,9 +145,9 @@ __PF(IRDA,irda)
86__PF(ECONET,econet) 145__PF(ECONET,econet)
87#endif 146#endif
88 147
89{ 0x8100, "802.1Q" }, 148"802.1Q" "\0"
90{ ETH_P_IP, "ipv4" }, 149"ipv4" "\0"
91}; 150;
92#undef __PF 151#undef __PF
93 152
94 153
@@ -96,23 +155,26 @@ const char* FAST_FUNC ll_proto_n2a(unsigned short id, char *buf, int len)
96{ 155{
97 unsigned i; 156 unsigned i;
98 id = ntohs(id); 157 id = ntohs(id);
99 for (i = 0; i < ARRAY_SIZE(llproto_names); i++) { 158 for (i = 0; i < ARRAY_SIZE(llproto_ids); i++) {
100 if (llproto_names[i].id == id) 159 if (llproto_ids[i] == id)
101 return llproto_names[i].name; 160 return nth_string(llproto_names, i);
102 } 161 }
103 snprintf(buf, len, "[%d]", id); 162 snprintf(buf, len, "[%u]", id);
104 return buf; 163 return buf;
105} 164}
106 165
107int FAST_FUNC ll_proto_a2n(unsigned short *id, char *buf) 166int FAST_FUNC ll_proto_a2n(unsigned short *id, char *buf)
108{ 167{
109 unsigned i; 168 unsigned i;
110 for (i = 0; i < ARRAY_SIZE(llproto_names); i++) { 169 const char *name = llproto_names;
111 if (strcasecmp(llproto_names[i].name, buf) == 0) { 170 for (i = 0; i < ARRAY_SIZE(llproto_ids); i++) {
112 i = llproto_names[i].id; 171 if (strcasecmp(name, buf) == 0) {
113 goto good; 172 i = llproto_ids[i];
114 } 173 goto good;
174 }
175 name += strlen(name) + 1;
115 } 176 }
177 errno = 0;
116 i = bb_strtou(buf, NULL, 0); 178 i = bb_strtou(buf, NULL, 0);
117 if (errno || i > 0xffff) 179 if (errno || i > 0xffff)
118 return -1; 180 return -1;