diff options
Diffstat (limited to 'networking/libiproute/ll_proto.c')
-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..da2b53cbf 100644 --- a/networking/libiproute/ll_proto.c +++ b/networking/libiproute/ll_proto.c | |||
@@ -14,19 +14,10 @@ | |||
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 | ||
19 | #endif | ||
20 | /* Before re-enabling this, please (1) conditionalize exotic protocols | ||
21 | * on CONFIG_something, and (2) decouple strings and numbers | ||
22 | * (use llproto_ids[] = n,n,n..; and llproto_names[] = "loop\0" "pup\0" ...;) | ||
23 | */ | ||
24 | 18 | ||
25 | #define __PF(f,n) { ETH_P_##f, #n }, | 19 | static const uint16_t llproto_ids[] = { |
26 | static struct { | 20 | #define __PF(f,n) ETH_P_##f, |
27 | int id; | ||
28 | const char *name; | ||
29 | } llproto_names[] = { | ||
30 | __PF(LOOP,loop) | 21 | __PF(LOOP,loop) |
31 | __PF(PUP,pup) | 22 | __PF(PUP,pup) |
32 | #ifdef ETH_P_PUPAT | 23 | #ifdef ETH_P_PUPAT |
@@ -86,33 +77,104 @@ __PF(IRDA,irda) | |||
86 | __PF(ECONET,econet) | 77 | __PF(ECONET,econet) |
87 | #endif | 78 | #endif |
88 | 79 | ||
89 | { 0x8100, "802.1Q" }, | 80 | 0x8100, |
90 | { ETH_P_IP, "ipv4" }, | 81 | ETH_P_IP |
91 | }; | 82 | }; |
92 | #undef __PF | 83 | #undef __PF |
93 | 84 | ||
85 | /* Keep declarations above and below in sync! */ | ||
86 | |||
87 | static const char llproto_names[] = | ||
88 | #define __PF(f,n) #n "\0" | ||
89 | __PF(LOOP,loop) | ||
90 | __PF(PUP,pup) | ||
91 | #ifdef ETH_P_PUPAT | ||
92 | __PF(PUPAT,pupat) | ||
93 | #endif | ||
94 | __PF(IP,ip) | ||
95 | __PF(X25,x25) | ||
96 | __PF(ARP,arp) | ||
97 | __PF(BPQ,bpq) | ||
98 | #ifdef ETH_P_IEEEPUP | ||
99 | __PF(IEEEPUP,ieeepup) | ||
100 | #endif | ||
101 | #ifdef ETH_P_IEEEPUPAT | ||
102 | __PF(IEEEPUPAT,ieeepupat) | ||
103 | #endif | ||
104 | __PF(DEC,dec) | ||
105 | __PF(DNA_DL,dna_dl) | ||
106 | __PF(DNA_RC,dna_rc) | ||
107 | __PF(DNA_RT,dna_rt) | ||
108 | __PF(LAT,lat) | ||
109 | __PF(DIAG,diag) | ||
110 | __PF(CUST,cust) | ||
111 | __PF(SCA,sca) | ||
112 | __PF(RARP,rarp) | ||
113 | __PF(ATALK,atalk) | ||
114 | __PF(AARP,aarp) | ||
115 | __PF(IPX,ipx) | ||
116 | __PF(IPV6,ipv6) | ||
117 | #ifdef ETH_P_PPP_DISC | ||
118 | __PF(PPP_DISC,ppp_disc) | ||
119 | #endif | ||
120 | #ifdef ETH_P_PPP_SES | ||
121 | __PF(PPP_SES,ppp_ses) | ||
122 | #endif | ||
123 | #ifdef ETH_P_ATMMPOA | ||
124 | __PF(ATMMPOA,atmmpoa) | ||
125 | #endif | ||
126 | #ifdef ETH_P_ATMFATE | ||
127 | __PF(ATMFATE,atmfate) | ||
128 | #endif | ||
129 | |||
130 | __PF(802_3,802_3) | ||
131 | __PF(AX25,ax25) | ||
132 | __PF(ALL,all) | ||
133 | __PF(802_2,802_2) | ||
134 | __PF(SNAP,snap) | ||
135 | __PF(DDCMP,ddcmp) | ||
136 | __PF(WAN_PPP,wan_ppp) | ||
137 | __PF(PPP_MP,ppp_mp) | ||
138 | __PF(LOCALTALK,localtalk) | ||
139 | __PF(PPPTALK,ppptalk) | ||
140 | __PF(TR_802_2,tr_802_2) | ||
141 | __PF(MOBITEX,mobitex) | ||
142 | __PF(CONTROL,control) | ||
143 | __PF(IRDA,irda) | ||
144 | #ifdef ETH_P_ECONET | ||
145 | __PF(ECONET,econet) | ||
146 | #endif | ||
147 | |||
148 | "802.1Q" "\0" | ||
149 | "ipv4" "\0" | ||
150 | ; | ||
151 | #undef __PF | ||
152 | |||
94 | 153 | ||
95 | const char* FAST_FUNC ll_proto_n2a(unsigned short id, char *buf, int len) | 154 | 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; |