summaryrefslogtreecommitdiff
path: root/networking/libiproute/ll_proto.c (plain)
blob: 263ac78ada2d0300d74257eb07d955be413a6982
1/* vi: set sw=4 ts=4: */
2/*
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version
6 * 2 of the License, or (at your option) any later version.
7 *
8 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
9 */
10
11#include "libbb.h"
12#include "rt_names.h"
13#include "utils.h"
14
15#include <netinet/if_ether.h>
16#include <linux/if_ether.h>
17
18
19/* Please conditionalize exotic protocols on CONFIG_something */
20
21static const uint16_t llproto_ids[] = {
22#define __PF(f,n) ETH_P_##f,
23__PF(LOOP,loop)
24__PF(PUP,pup)
25#ifdef ETH_P_PUPAT
26__PF(PUPAT,pupat)
27#endif
28__PF(IP,ip)
29__PF(X25,x25)
30__PF(ARP,arp)
31__PF(BPQ,bpq)
32#ifdef ETH_P_IEEEPUP
33__PF(IEEEPUP,ieeepup)
34#endif
35#ifdef ETH_P_IEEEPUPAT
36__PF(IEEEPUPAT,ieeepupat)
37#endif
38__PF(DEC,dec)
39__PF(DNA_DL,dna_dl)
40__PF(DNA_RC,dna_rc)
41__PF(DNA_RT,dna_rt)
42__PF(LAT,lat)
43__PF(DIAG,diag)
44__PF(CUST,cust)
45__PF(SCA,sca)
46__PF(RARP,rarp)
47__PF(ATALK,atalk)
48__PF(AARP,aarp)
49__PF(IPX,ipx)
50__PF(IPV6,ipv6)
51#ifdef ETH_P_PPP_DISC
52__PF(PPP_DISC,ppp_disc)
53#endif
54#ifdef ETH_P_PPP_SES
55__PF(PPP_SES,ppp_ses)
56#endif
57#ifdef ETH_P_ATMMPOA
58__PF(ATMMPOA,atmmpoa)
59#endif
60#ifdef ETH_P_ATMFATE
61__PF(ATMFATE,atmfate)
62#endif
63
64__PF(802_3,802_3)
65__PF(AX25,ax25)
66__PF(ALL,all)
67__PF(802_2,802_2)
68__PF(SNAP,snap)
69__PF(DDCMP,ddcmp)
70__PF(WAN_PPP,wan_ppp)
71__PF(PPP_MP,ppp_mp)
72__PF(LOCALTALK,localtalk)
73__PF(PPPTALK,ppptalk)
74__PF(TR_802_2,tr_802_2)
75__PF(MOBITEX,mobitex)
76__PF(CONTROL,control)
77__PF(IRDA,irda)
78#ifdef ETH_P_ECONET
79__PF(ECONET,econet)
80#endif
81
820x8100,
83ETH_P_IP
84};
85#undef __PF
86
87/* Keep declarations above and below in sync! */
88
89static const char llproto_names[] ALIGN1 =
90#define __PF(f,n) #n "\0"
91__PF(LOOP,loop)
92__PF(PUP,pup)
93#ifdef ETH_P_PUPAT
94__PF(PUPAT,pupat)
95#endif
96__PF(IP,ip)
97__PF(X25,x25)
98__PF(ARP,arp)
99__PF(BPQ,bpq)
100#ifdef ETH_P_IEEEPUP
101__PF(IEEEPUP,ieeepup)
102#endif
103#ifdef ETH_P_IEEEPUPAT
104__PF(IEEEPUPAT,ieeepupat)
105#endif
106__PF(DEC,dec)
107__PF(DNA_DL,dna_dl)
108__PF(DNA_RC,dna_rc)
109__PF(DNA_RT,dna_rt)
110__PF(LAT,lat)
111__PF(DIAG,diag)
112__PF(CUST,cust)
113__PF(SCA,sca)
114__PF(RARP,rarp)
115__PF(ATALK,atalk)
116__PF(AARP,aarp)
117__PF(IPX,ipx)
118__PF(IPV6,ipv6)
119#ifdef ETH_P_PPP_DISC
120__PF(PPP_DISC,ppp_disc)
121#endif
122#ifdef ETH_P_PPP_SES
123__PF(PPP_SES,ppp_ses)
124#endif
125#ifdef ETH_P_ATMMPOA
126__PF(ATMMPOA,atmmpoa)
127#endif
128#ifdef ETH_P_ATMFATE
129__PF(ATMFATE,atmfate)
130#endif
131
132__PF(802_3,802_3)
133__PF(AX25,ax25)
134__PF(ALL,all)
135__PF(802_2,802_2)
136__PF(SNAP,snap)
137__PF(DDCMP,ddcmp)
138__PF(WAN_PPP,wan_ppp)
139__PF(PPP_MP,ppp_mp)
140__PF(LOCALTALK,localtalk)
141__PF(PPPTALK,ppptalk)
142__PF(TR_802_2,tr_802_2)
143__PF(MOBITEX,mobitex)
144__PF(CONTROL,control)
145__PF(IRDA,irda)
146#ifdef ETH_P_ECONET
147__PF(ECONET,econet)
148#endif
149
150"802.1Q" "\0"
151"ipv4" "\0"
152;
153#undef __PF
154
155
156const char* FAST_FUNC ll_proto_n2a(unsigned short id, char *buf, int len)
157{
158 unsigned i;
159 id = ntohs(id);
160 for (i = 0; i < ARRAY_SIZE(llproto_ids); i++) {
161 if (llproto_ids[i] == id)
162 return nth_string(llproto_names, i);
163 }
164 snprintf(buf, len, "[%u]", id);
165 return buf;
166}
167
168int FAST_FUNC ll_proto_a2n(unsigned short *id, char *buf)
169{
170 unsigned i;
171 const char *name = llproto_names;
172 for (i = 0; i < ARRAY_SIZE(llproto_ids); i++) {
173 if (strcasecmp(name, buf) == 0) {
174 i = llproto_ids[i];
175 goto good;
176 }
177 name += strlen(name) + 1;
178 }
179 errno = 0;
180 i = bb_strtou(buf, NULL, 0);
181 if (errno || i > 0xffff)
182 return -1;
183 good:
184 *id = htons(i);
185 return 0;
186}
187