blob: 7aac8364d362a574bf33066b3ee1b2229967852e [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
Dan Fandrichf533ec82011-06-10 05:17:59 +020015#include <netinet/if_ether.h>
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000016
Denis Vlasenko1c781cc2008-09-06 14:14:01 +000017#if !ENABLE_WERROR
Bernhard Reutner-Fischer0901c512008-09-04 13:22:58 +000018#warning de-bloat
Denis Vlasenko1c781cc2008-09-06 14:14:01 +000019#endif
Denis Vlasenkodfc07402007-10-29 19:33:26 +000020/* 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
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000025#define __PF(f,n) { ETH_P_##f, #n },
26static struct {
27 int id;
Denis Vlasenko322661d2007-01-29 23:43:52 +000028 const char *name;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000029} llproto_names[] = {
30__PF(LOOP,loop)
Eric Andersenc7bda1c2004-03-15 08:29:22 +000031__PF(PUP,pup)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000032#ifdef ETH_P_PUPAT
Eric Andersenc7bda1c2004-03-15 08:29:22 +000033__PF(PUPAT,pupat)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000034#endif
35__PF(IP,ip)
36__PF(X25,x25)
37__PF(ARP,arp)
38__PF(BPQ,bpq)
39#ifdef ETH_P_IEEEPUP
Eric Andersenc7bda1c2004-03-15 08:29:22 +000040__PF(IEEEPUP,ieeepup)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000041#endif
42#ifdef ETH_P_IEEEPUPAT
Eric Andersenc7bda1c2004-03-15 08:29:22 +000043__PF(IEEEPUPAT,ieeepupat)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000044#endif
Eric Andersenc7bda1c2004-03-15 08:29:22 +000045__PF(DEC,dec)
46__PF(DNA_DL,dna_dl)
47__PF(DNA_RC,dna_rc)
48__PF(DNA_RT,dna_rt)
49__PF(LAT,lat)
50__PF(DIAG,diag)
51__PF(CUST,cust)
52__PF(SCA,sca)
53__PF(RARP,rarp)
54__PF(ATALK,atalk)
55__PF(AARP,aarp)
56__PF(IPX,ipx)
57__PF(IPV6,ipv6)
Eric Andersen0f08e532003-06-20 09:05:00 +000058#ifdef ETH_P_PPP_DISC
Eric Andersenc7bda1c2004-03-15 08:29:22 +000059__PF(PPP_DISC,ppp_disc)
Eric Andersen0f08e532003-06-20 09:05:00 +000060#endif
61#ifdef ETH_P_PPP_SES
Eric Andersenc7bda1c2004-03-15 08:29:22 +000062__PF(PPP_SES,ppp_ses)
Eric Andersen0f08e532003-06-20 09:05:00 +000063#endif
64#ifdef ETH_P_ATMMPOA
Eric Andersenc7bda1c2004-03-15 08:29:22 +000065__PF(ATMMPOA,atmmpoa)
Eric Andersen0f08e532003-06-20 09:05:00 +000066#endif
67#ifdef ETH_P_ATMFATE
Eric Andersenc7bda1c2004-03-15 08:29:22 +000068__PF(ATMFATE,atmfate)
Eric Andersen0f08e532003-06-20 09:05:00 +000069#endif
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000070
Eric Andersenc7bda1c2004-03-15 08:29:22 +000071__PF(802_3,802_3)
72__PF(AX25,ax25)
73__PF(ALL,all)
74__PF(802_2,802_2)
75__PF(SNAP,snap)
76__PF(DDCMP,ddcmp)
77__PF(WAN_PPP,wan_ppp)
78__PF(PPP_MP,ppp_mp)
79__PF(LOCALTALK,localtalk)
80__PF(PPPTALK,ppptalk)
81__PF(TR_802_2,tr_802_2)
82__PF(MOBITEX,mobitex)
83__PF(CONTROL,control)
84__PF(IRDA,irda)
Eric Andersen0f08e532003-06-20 09:05:00 +000085#ifdef ETH_P_ECONET
Eric Andersenc7bda1c2004-03-15 08:29:22 +000086__PF(ECONET,econet)
Eric Andersen0f08e532003-06-20 09:05:00 +000087#endif
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000088
89{ 0x8100, "802.1Q" },
90{ ETH_P_IP, "ipv4" },
91};
92#undef __PF
93
94
Denys Vlasenkod31575a2009-10-13 17:58:24 +020095const char* FAST_FUNC ll_proto_n2a(unsigned short id, char *buf, int len)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000096{
Denis Vlasenko6b06cb82008-05-15 21:30:45 +000097 unsigned i;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000098 id = ntohs(id);
Denis Vlasenko284d0fa2008-02-16 13:18:17 +000099 for (i = 0; i < ARRAY_SIZE(llproto_names); i++) {
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000100 if (llproto_names[i].id == id)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000101 return llproto_names[i].name;
102 }
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000103 snprintf(buf, len, "[%d]", id);
104 return buf;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000105}
106
Denys Vlasenkod31575a2009-10-13 17:58:24 +0200107int FAST_FUNC ll_proto_a2n(unsigned short *id, char *buf)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000108{
Denis Vlasenko6b06cb82008-05-15 21:30:45 +0000109 unsigned i;
Denis Vlasenko284d0fa2008-02-16 13:18:17 +0000110 for (i = 0; i < ARRAY_SIZE(llproto_names); i++) {
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000111 if (strcasecmp(llproto_names[i].name, buf) == 0) {
Denis Vlasenko76140a72009-03-05 09:21:57 +0000112 i = llproto_names[i].id;
113 goto good;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000114 }
115 }
Denis Vlasenko76140a72009-03-05 09:21:57 +0000116 i = bb_strtou(buf, NULL, 0);
117 if (errno || i > 0xffff)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000118 return -1;
Denis Vlasenko76140a72009-03-05 09:21:57 +0000119 good:
120 *id = htons(i);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000121 return 0;
122}