blob: 8d9637408091107f1e36daef78298fa17f19b4a3 [file] [log] [blame]
"Robert P. J. Day"63fc1a92006-07-02 19:47:05 +00001/* vi: set sw=4 ts=4: */
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00002/*
3 * ll_proto.c
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
9 *
10 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
11 */
12
Rob Landleyea224be2006-06-18 20:20:07 +000013#include "libbb.h"
Bernhard Reutner-Fischer9a67ca32006-04-02 21:14:19 +000014#include "rt_names.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000015#include "utils.h"
16
Denis Vlasenko83e5d6f2006-12-18 21:49:06 +000017#if defined(__GLIBC__) && __GLIBC__ >=2 && __GLIBC_MINOR__ >= 1
Eric Andersenfeb283a2003-07-14 08:49:43 +000018#include <net/ethernet.h>
19#else
20#include <linux/if_ether.h>
21#endif
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000022
Denis Vlasenkodfc07402007-10-29 19:33:26 +000023#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
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000029#define __PF(f,n) { ETH_P_##f, #n },
30static struct {
31 int id;
Denis Vlasenko322661d2007-01-29 23:43:52 +000032 const char *name;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000033} llproto_names[] = {
34__PF(LOOP,loop)
Eric Andersenc7bda1c2004-03-15 08:29:22 +000035__PF(PUP,pup)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000036#ifdef ETH_P_PUPAT
Eric Andersenc7bda1c2004-03-15 08:29:22 +000037__PF(PUPAT,pupat)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000038#endif
39__PF(IP,ip)
40__PF(X25,x25)
41__PF(ARP,arp)
42__PF(BPQ,bpq)
43#ifdef ETH_P_IEEEPUP
Eric Andersenc7bda1c2004-03-15 08:29:22 +000044__PF(IEEEPUP,ieeepup)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000045#endif
46#ifdef ETH_P_IEEEPUPAT
Eric Andersenc7bda1c2004-03-15 08:29:22 +000047__PF(IEEEPUPAT,ieeepupat)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000048#endif
Eric Andersenc7bda1c2004-03-15 08:29:22 +000049__PF(DEC,dec)
50__PF(DNA_DL,dna_dl)
51__PF(DNA_RC,dna_rc)
52__PF(DNA_RT,dna_rt)
53__PF(LAT,lat)
54__PF(DIAG,diag)
55__PF(CUST,cust)
56__PF(SCA,sca)
57__PF(RARP,rarp)
58__PF(ATALK,atalk)
59__PF(AARP,aarp)
60__PF(IPX,ipx)
61__PF(IPV6,ipv6)
Eric Andersen0f08e532003-06-20 09:05:00 +000062#ifdef ETH_P_PPP_DISC
Eric Andersenc7bda1c2004-03-15 08:29:22 +000063__PF(PPP_DISC,ppp_disc)
Eric Andersen0f08e532003-06-20 09:05:00 +000064#endif
65#ifdef ETH_P_PPP_SES
Eric Andersenc7bda1c2004-03-15 08:29:22 +000066__PF(PPP_SES,ppp_ses)
Eric Andersen0f08e532003-06-20 09:05:00 +000067#endif
68#ifdef ETH_P_ATMMPOA
Eric Andersenc7bda1c2004-03-15 08:29:22 +000069__PF(ATMMPOA,atmmpoa)
Eric Andersen0f08e532003-06-20 09:05:00 +000070#endif
71#ifdef ETH_P_ATMFATE
Eric Andersenc7bda1c2004-03-15 08:29:22 +000072__PF(ATMFATE,atmfate)
Eric Andersen0f08e532003-06-20 09:05:00 +000073#endif
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000074
Eric Andersenc7bda1c2004-03-15 08:29:22 +000075__PF(802_3,802_3)
76__PF(AX25,ax25)
77__PF(ALL,all)
78__PF(802_2,802_2)
79__PF(SNAP,snap)
80__PF(DDCMP,ddcmp)
81__PF(WAN_PPP,wan_ppp)
82__PF(PPP_MP,ppp_mp)
83__PF(LOCALTALK,localtalk)
84__PF(PPPTALK,ppptalk)
85__PF(TR_802_2,tr_802_2)
86__PF(MOBITEX,mobitex)
87__PF(CONTROL,control)
88__PF(IRDA,irda)
Eric Andersen0f08e532003-06-20 09:05:00 +000089#ifdef ETH_P_ECONET
Eric Andersenc7bda1c2004-03-15 08:29:22 +000090__PF(ECONET,econet)
Eric Andersen0f08e532003-06-20 09:05:00 +000091#endif
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000092
93{ 0x8100, "802.1Q" },
94{ ETH_P_IP, "ipv4" },
95};
96#undef __PF
97
98
Denis Vlasenkodfc07402007-10-29 19:33:26 +000099const char *ll_proto_n2a(unsigned short id, char *buf, int len)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000100{
Denis Vlasenko6b06cb82008-05-15 21:30:45 +0000101 unsigned i;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000102 id = ntohs(id);
Denis Vlasenko284d0fa2008-02-16 13:18:17 +0000103 for (i = 0; i < ARRAY_SIZE(llproto_names); i++) {
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000104 if (llproto_names[i].id == id)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000105 return llproto_names[i].name;
106 }
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000107 snprintf(buf, len, "[%d]", id);
108 return buf;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000109}
110
111int ll_proto_a2n(unsigned short *id, char *buf)
112{
Denis Vlasenko6b06cb82008-05-15 21:30:45 +0000113 unsigned i;
Denis Vlasenko284d0fa2008-02-16 13:18:17 +0000114 for (i = 0; i < ARRAY_SIZE(llproto_names); i++) {
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000115 if (strcasecmp(llproto_names[i].name, buf) == 0) {
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000116 *id = htons(llproto_names[i].id);
117 return 0;
118 }
119 }
120 if (get_u16(id, buf, 0))
121 return -1;
122 *id = htons(*id);
123 return 0;
124}
Denis Vlasenkodfc07402007-10-29 19:33:26 +0000125
126#endif /* UNUSED */