"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 2 | /* |
Denys Vlasenko | fb132e4 | 2010-10-29 11:46:52 +0200 | [diff] [blame] | 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. |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 7 | * |
Denys Vlasenko | fb132e4 | 2010-10-29 11:46:52 +0200 | [diff] [blame] | 8 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Rob Landley | ea224be | 2006-06-18 20:20:07 +0000 | [diff] [blame] | 11 | #include "libbb.h" |
Bernhard Reutner-Fischer | 9a67ca3 | 2006-04-02 21:14:19 +0000 | [diff] [blame] | 12 | #include "rt_names.h" |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 13 | #include "utils.h" |
| 14 | |
Dan Fandrich | f533ec8 | 2011-06-10 05:17:59 +0200 | [diff] [blame] | 15 | #include <netinet/if_ether.h> |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 16 | |
Denis Vlasenko | 1c781cc | 2008-09-06 14:14:01 +0000 | [diff] [blame] | 17 | #if !ENABLE_WERROR |
Bernhard Reutner-Fischer | 0901c51 | 2008-09-04 13:22:58 +0000 | [diff] [blame] | 18 | #warning de-bloat |
Denis Vlasenko | 1c781cc | 2008-09-06 14:14:01 +0000 | [diff] [blame] | 19 | #endif |
Denis Vlasenko | dfc0740 | 2007-10-29 19:33:26 +0000 | [diff] [blame] | 20 | /* 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 McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 25 | #define __PF(f,n) { ETH_P_##f, #n }, |
| 26 | static struct { |
| 27 | int id; |
Denis Vlasenko | 322661d | 2007-01-29 23:43:52 +0000 | [diff] [blame] | 28 | const char *name; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 29 | } llproto_names[] = { |
| 30 | __PF(LOOP,loop) |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 31 | __PF(PUP,pup) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 32 | #ifdef ETH_P_PUPAT |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 33 | __PF(PUPAT,pupat) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 34 | #endif |
| 35 | __PF(IP,ip) |
| 36 | __PF(X25,x25) |
| 37 | __PF(ARP,arp) |
| 38 | __PF(BPQ,bpq) |
| 39 | #ifdef ETH_P_IEEEPUP |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 40 | __PF(IEEEPUP,ieeepup) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 41 | #endif |
| 42 | #ifdef ETH_P_IEEEPUPAT |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 43 | __PF(IEEEPUPAT,ieeepupat) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 44 | #endif |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 45 | __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 Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 58 | #ifdef ETH_P_PPP_DISC |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 59 | __PF(PPP_DISC,ppp_disc) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 60 | #endif |
| 61 | #ifdef ETH_P_PPP_SES |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 62 | __PF(PPP_SES,ppp_ses) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 63 | #endif |
| 64 | #ifdef ETH_P_ATMMPOA |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 65 | __PF(ATMMPOA,atmmpoa) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 66 | #endif |
| 67 | #ifdef ETH_P_ATMFATE |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 68 | __PF(ATMFATE,atmfate) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 69 | #endif |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 70 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 71 | __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 Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 85 | #ifdef ETH_P_ECONET |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 86 | __PF(ECONET,econet) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 87 | #endif |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 88 | |
| 89 | { 0x8100, "802.1Q" }, |
| 90 | { ETH_P_IP, "ipv4" }, |
| 91 | }; |
| 92 | #undef __PF |
| 93 | |
| 94 | |
Denys Vlasenko | d31575a | 2009-10-13 17:58:24 +0200 | [diff] [blame] | 95 | const char* FAST_FUNC ll_proto_n2a(unsigned short id, char *buf, int len) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 96 | { |
Denis Vlasenko | 6b06cb8 | 2008-05-15 21:30:45 +0000 | [diff] [blame] | 97 | unsigned i; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 98 | id = ntohs(id); |
Denis Vlasenko | 284d0fa | 2008-02-16 13:18:17 +0000 | [diff] [blame] | 99 | for (i = 0; i < ARRAY_SIZE(llproto_names); i++) { |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 100 | if (llproto_names[i].id == id) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 101 | return llproto_names[i].name; |
| 102 | } |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 103 | snprintf(buf, len, "[%d]", id); |
| 104 | return buf; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Denys Vlasenko | d31575a | 2009-10-13 17:58:24 +0200 | [diff] [blame] | 107 | int FAST_FUNC ll_proto_a2n(unsigned short *id, char *buf) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 108 | { |
Denis Vlasenko | 6b06cb8 | 2008-05-15 21:30:45 +0000 | [diff] [blame] | 109 | unsigned i; |
Denis Vlasenko | 284d0fa | 2008-02-16 13:18:17 +0000 | [diff] [blame] | 110 | for (i = 0; i < ARRAY_SIZE(llproto_names); i++) { |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 111 | if (strcasecmp(llproto_names[i].name, buf) == 0) { |
Denis Vlasenko | 76140a7 | 2009-03-05 09:21:57 +0000 | [diff] [blame] | 112 | i = llproto_names[i].id; |
| 113 | goto good; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 114 | } |
| 115 | } |
Denis Vlasenko | 76140a7 | 2009-03-05 09:21:57 +0000 | [diff] [blame] | 116 | i = bb_strtou(buf, NULL, 0); |
| 117 | if (errno || i > 0xffff) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 118 | return -1; |
Denis Vlasenko | 76140a7 | 2009-03-05 09:21:57 +0000 | [diff] [blame] | 119 | good: |
| 120 | *id = htons(i); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 121 | return 0; |
| 122 | } |