diff options
-rw-r--r-- | networking/libiproute/ll_proto.c | 108 |
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 | |
19 | static 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 | |||
80 | 0x8100, | ||
81 | ETH_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 }, | 87 | static const char llproto_names[] = |
26 | static 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 | ||
107 | int FAST_FUNC ll_proto_a2n(unsigned short *id, char *buf) | 166 | int 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; |