blob: 04925ecf686635fa540db8a2719f1d8b4e29f443 [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/*
Denys Vlasenkofb132e42010-10-29 11:46:52 +02003 * 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.
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00007 *
Denys Vlasenkofb132e42010-10-29 11:46:52 +02008 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00009 */
10
Rob Landleyea224be2006-06-18 20:20:07 +000011#include "libbb.h"
Bernhard Reutner-Fischer9a67ca32006-04-02 21:14:19 +000012#include "rt_names.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000013#include "utils.h"
14
Denis Vlasenko83e5d6f2006-12-18 21:49:06 +000015#if defined(__GLIBC__) && __GLIBC__ >=2 && __GLIBC_MINOR__ >= 1
Eric Andersenfeb283a2003-07-14 08:49:43 +000016#include <net/ethernet.h>
17#else
18#include <linux/if_ether.h>
19#endif
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000020
Denis Vlasenko1c781cc2008-09-06 14:14:01 +000021#if !ENABLE_WERROR
Bernhard Reutner-Fischer0901c512008-09-04 13:22:58 +000022#warning de-bloat
Denis Vlasenko1c781cc2008-09-06 14:14:01 +000023#endif
Denis Vlasenkodfc07402007-10-29 19:33:26 +000024/* 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
Denys Vlasenkod31575a2009-10-13 17:58:24 +020099const char* FAST_FUNC 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
Denys Vlasenkod31575a2009-10-13 17:58:24 +0200111int FAST_FUNC ll_proto_a2n(unsigned short *id, char *buf)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000112{
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) {
Denis Vlasenko76140a72009-03-05 09:21:57 +0000116 i = llproto_names[i].id;
117 goto good;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000118 }
119 }
Denis Vlasenko76140a72009-03-05 09:21:57 +0000120 i = bb_strtou(buf, NULL, 0);
121 if (errno || i > 0xffff)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000122 return -1;
Denis Vlasenko76140a72009-03-05 09:21:57 +0000123 good:
124 *id = htons(i);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000125 return 0;
126}