blob: b8268732e6f9f046088e0fe403ceea24974b3ff4 [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 Vlasenko1c781cc2008-09-06 14:14:01 +000023#if !ENABLE_WERROR
Bernhard Reutner-Fischer0901c512008-09-04 13:22:58 +000024#warning de-bloat
Denis Vlasenko1c781cc2008-09-06 14:14:01 +000025#endif
Denis Vlasenkodfc07402007-10-29 19:33:26 +000026/* Before re-enabling this, please (1) conditionalize exotic protocols
27 * on CONFIG_something, and (2) decouple strings and numbers
28 * (use llproto_ids[] = n,n,n..; and llproto_names[] = "loop\0" "pup\0" ...;)
29 */
30
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000031#define __PF(f,n) { ETH_P_##f, #n },
32static struct {
33 int id;
Denis Vlasenko322661d2007-01-29 23:43:52 +000034 const char *name;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000035} llproto_names[] = {
36__PF(LOOP,loop)
Eric Andersenc7bda1c2004-03-15 08:29:22 +000037__PF(PUP,pup)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000038#ifdef ETH_P_PUPAT
Eric Andersenc7bda1c2004-03-15 08:29:22 +000039__PF(PUPAT,pupat)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000040#endif
41__PF(IP,ip)
42__PF(X25,x25)
43__PF(ARP,arp)
44__PF(BPQ,bpq)
45#ifdef ETH_P_IEEEPUP
Eric Andersenc7bda1c2004-03-15 08:29:22 +000046__PF(IEEEPUP,ieeepup)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000047#endif
48#ifdef ETH_P_IEEEPUPAT
Eric Andersenc7bda1c2004-03-15 08:29:22 +000049__PF(IEEEPUPAT,ieeepupat)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000050#endif
Eric Andersenc7bda1c2004-03-15 08:29:22 +000051__PF(DEC,dec)
52__PF(DNA_DL,dna_dl)
53__PF(DNA_RC,dna_rc)
54__PF(DNA_RT,dna_rt)
55__PF(LAT,lat)
56__PF(DIAG,diag)
57__PF(CUST,cust)
58__PF(SCA,sca)
59__PF(RARP,rarp)
60__PF(ATALK,atalk)
61__PF(AARP,aarp)
62__PF(IPX,ipx)
63__PF(IPV6,ipv6)
Eric Andersen0f08e532003-06-20 09:05:00 +000064#ifdef ETH_P_PPP_DISC
Eric Andersenc7bda1c2004-03-15 08:29:22 +000065__PF(PPP_DISC,ppp_disc)
Eric Andersen0f08e532003-06-20 09:05:00 +000066#endif
67#ifdef ETH_P_PPP_SES
Eric Andersenc7bda1c2004-03-15 08:29:22 +000068__PF(PPP_SES,ppp_ses)
Eric Andersen0f08e532003-06-20 09:05:00 +000069#endif
70#ifdef ETH_P_ATMMPOA
Eric Andersenc7bda1c2004-03-15 08:29:22 +000071__PF(ATMMPOA,atmmpoa)
Eric Andersen0f08e532003-06-20 09:05:00 +000072#endif
73#ifdef ETH_P_ATMFATE
Eric Andersenc7bda1c2004-03-15 08:29:22 +000074__PF(ATMFATE,atmfate)
Eric Andersen0f08e532003-06-20 09:05:00 +000075#endif
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000076
Eric Andersenc7bda1c2004-03-15 08:29:22 +000077__PF(802_3,802_3)
78__PF(AX25,ax25)
79__PF(ALL,all)
80__PF(802_2,802_2)
81__PF(SNAP,snap)
82__PF(DDCMP,ddcmp)
83__PF(WAN_PPP,wan_ppp)
84__PF(PPP_MP,ppp_mp)
85__PF(LOCALTALK,localtalk)
86__PF(PPPTALK,ppptalk)
87__PF(TR_802_2,tr_802_2)
88__PF(MOBITEX,mobitex)
89__PF(CONTROL,control)
90__PF(IRDA,irda)
Eric Andersen0f08e532003-06-20 09:05:00 +000091#ifdef ETH_P_ECONET
Eric Andersenc7bda1c2004-03-15 08:29:22 +000092__PF(ECONET,econet)
Eric Andersen0f08e532003-06-20 09:05:00 +000093#endif
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000094
95{ 0x8100, "802.1Q" },
96{ ETH_P_IP, "ipv4" },
97};
98#undef __PF
99
100
Denis Vlasenkodfc07402007-10-29 19:33:26 +0000101const char *ll_proto_n2a(unsigned short id, char *buf, int len)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000102{
Denis Vlasenko6b06cb82008-05-15 21:30:45 +0000103 unsigned i;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000104 id = ntohs(id);
Denis Vlasenko284d0fa2008-02-16 13:18:17 +0000105 for (i = 0; i < ARRAY_SIZE(llproto_names); i++) {
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000106 if (llproto_names[i].id == id)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000107 return llproto_names[i].name;
108 }
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000109 snprintf(buf, len, "[%d]", id);
110 return buf;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000111}
112
113int ll_proto_a2n(unsigned short *id, char *buf)
114{
Denis Vlasenko6b06cb82008-05-15 21:30:45 +0000115 unsigned i;
Denis Vlasenko284d0fa2008-02-16 13:18:17 +0000116 for (i = 0; i < ARRAY_SIZE(llproto_names); i++) {
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000117 if (strcasecmp(llproto_names[i].name, buf) == 0) {
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000118 *id = htons(llproto_names[i].id);
119 return 0;
120 }
121 }
122 if (get_u16(id, buf, 0))
123 return -1;
124 *id = htons(*id);
125 return 0;
126}
Denis Vlasenkodfc07402007-10-29 19:33:26 +0000127