"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 | |
Denys Vlasenko | 405daff | 2012-09-02 14:29:45 +0200 | [diff] [blame] | 17 | /* Please conditionalize exotic protocols on CONFIG_something */ |
Denis Vlasenko | dfc0740 | 2007-10-29 19:33:26 +0000 | [diff] [blame] | 18 | |
Denys Vlasenko | 5f10fdf | 2012-09-03 11:41:30 +0200 | [diff] [blame] | 19 | static const uint16_t llproto_ids[] = { |
Denys Vlasenko | 405daff | 2012-09-02 14:29:45 +0200 | [diff] [blame] | 20 | #define __PF(f,n) ETH_P_##f, |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 21 | __PF(LOOP,loop) |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 22 | __PF(PUP,pup) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 23 | #ifdef ETH_P_PUPAT |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 24 | __PF(PUPAT,pupat) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 25 | #endif |
| 26 | __PF(IP,ip) |
| 27 | __PF(X25,x25) |
| 28 | __PF(ARP,arp) |
| 29 | __PF(BPQ,bpq) |
| 30 | #ifdef ETH_P_IEEEPUP |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 31 | __PF(IEEEPUP,ieeepup) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 32 | #endif |
| 33 | #ifdef ETH_P_IEEEPUPAT |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 34 | __PF(IEEEPUPAT,ieeepupat) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 35 | #endif |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 36 | __PF(DEC,dec) |
| 37 | __PF(DNA_DL,dna_dl) |
| 38 | __PF(DNA_RC,dna_rc) |
| 39 | __PF(DNA_RT,dna_rt) |
| 40 | __PF(LAT,lat) |
| 41 | __PF(DIAG,diag) |
| 42 | __PF(CUST,cust) |
| 43 | __PF(SCA,sca) |
| 44 | __PF(RARP,rarp) |
| 45 | __PF(ATALK,atalk) |
| 46 | __PF(AARP,aarp) |
| 47 | __PF(IPX,ipx) |
| 48 | __PF(IPV6,ipv6) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 49 | #ifdef ETH_P_PPP_DISC |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 50 | __PF(PPP_DISC,ppp_disc) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 51 | #endif |
| 52 | #ifdef ETH_P_PPP_SES |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 53 | __PF(PPP_SES,ppp_ses) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 54 | #endif |
| 55 | #ifdef ETH_P_ATMMPOA |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 56 | __PF(ATMMPOA,atmmpoa) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 57 | #endif |
| 58 | #ifdef ETH_P_ATMFATE |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 59 | __PF(ATMFATE,atmfate) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 60 | #endif |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 61 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 62 | __PF(802_3,802_3) |
| 63 | __PF(AX25,ax25) |
| 64 | __PF(ALL,all) |
| 65 | __PF(802_2,802_2) |
| 66 | __PF(SNAP,snap) |
| 67 | __PF(DDCMP,ddcmp) |
| 68 | __PF(WAN_PPP,wan_ppp) |
| 69 | __PF(PPP_MP,ppp_mp) |
| 70 | __PF(LOCALTALK,localtalk) |
| 71 | __PF(PPPTALK,ppptalk) |
| 72 | __PF(TR_802_2,tr_802_2) |
| 73 | __PF(MOBITEX,mobitex) |
| 74 | __PF(CONTROL,control) |
| 75 | __PF(IRDA,irda) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 76 | #ifdef ETH_P_ECONET |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 77 | __PF(ECONET,econet) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 78 | #endif |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 79 | |
Denys Vlasenko | 405daff | 2012-09-02 14:29:45 +0200 | [diff] [blame] | 80 | 0x8100, |
| 81 | ETH_P_IP |
Denys Vlasenko | 5f10fdf | 2012-09-03 11:41:30 +0200 | [diff] [blame] | 82 | }; |
Denys Vlasenko | 405daff | 2012-09-02 14:29:45 +0200 | [diff] [blame] | 83 | #undef __PF |
| 84 | |
| 85 | /* Keep declarations above and below in sync! */ |
| 86 | |
Denys Vlasenko | 3e134eb | 2016-04-22 18:09:21 +0200 | [diff] [blame] | 87 | static const char llproto_names[] ALIGN1 = |
Denys Vlasenko | 405daff | 2012-09-02 14:29:45 +0200 | [diff] [blame] | 88 | #define __PF(f,n) #n "\0" |
| 89 | __PF(LOOP,loop) |
| 90 | __PF(PUP,pup) |
| 91 | #ifdef ETH_P_PUPAT |
| 92 | __PF(PUPAT,pupat) |
| 93 | #endif |
| 94 | __PF(IP,ip) |
| 95 | __PF(X25,x25) |
| 96 | __PF(ARP,arp) |
| 97 | __PF(BPQ,bpq) |
| 98 | #ifdef ETH_P_IEEEPUP |
| 99 | __PF(IEEEPUP,ieeepup) |
| 100 | #endif |
| 101 | #ifdef ETH_P_IEEEPUPAT |
| 102 | __PF(IEEEPUPAT,ieeepupat) |
| 103 | #endif |
| 104 | __PF(DEC,dec) |
| 105 | __PF(DNA_DL,dna_dl) |
| 106 | __PF(DNA_RC,dna_rc) |
| 107 | __PF(DNA_RT,dna_rt) |
| 108 | __PF(LAT,lat) |
| 109 | __PF(DIAG,diag) |
| 110 | __PF(CUST,cust) |
| 111 | __PF(SCA,sca) |
| 112 | __PF(RARP,rarp) |
| 113 | __PF(ATALK,atalk) |
| 114 | __PF(AARP,aarp) |
| 115 | __PF(IPX,ipx) |
| 116 | __PF(IPV6,ipv6) |
| 117 | #ifdef ETH_P_PPP_DISC |
| 118 | __PF(PPP_DISC,ppp_disc) |
| 119 | #endif |
| 120 | #ifdef ETH_P_PPP_SES |
| 121 | __PF(PPP_SES,ppp_ses) |
| 122 | #endif |
| 123 | #ifdef ETH_P_ATMMPOA |
| 124 | __PF(ATMMPOA,atmmpoa) |
| 125 | #endif |
| 126 | #ifdef ETH_P_ATMFATE |
| 127 | __PF(ATMFATE,atmfate) |
| 128 | #endif |
| 129 | |
| 130 | __PF(802_3,802_3) |
| 131 | __PF(AX25,ax25) |
| 132 | __PF(ALL,all) |
| 133 | __PF(802_2,802_2) |
| 134 | __PF(SNAP,snap) |
| 135 | __PF(DDCMP,ddcmp) |
| 136 | __PF(WAN_PPP,wan_ppp) |
| 137 | __PF(PPP_MP,ppp_mp) |
| 138 | __PF(LOCALTALK,localtalk) |
| 139 | __PF(PPPTALK,ppptalk) |
| 140 | __PF(TR_802_2,tr_802_2) |
| 141 | __PF(MOBITEX,mobitex) |
| 142 | __PF(CONTROL,control) |
| 143 | __PF(IRDA,irda) |
| 144 | #ifdef ETH_P_ECONET |
| 145 | __PF(ECONET,econet) |
| 146 | #endif |
| 147 | |
| 148 | "802.1Q" "\0" |
| 149 | "ipv4" "\0" |
| 150 | ; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 151 | #undef __PF |
| 152 | |
| 153 | |
Denys Vlasenko | d31575a | 2009-10-13 17:58:24 +0200 | [diff] [blame] | 154 | 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] | 155 | { |
Denis Vlasenko | 6b06cb8 | 2008-05-15 21:30:45 +0000 | [diff] [blame] | 156 | unsigned i; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 157 | id = ntohs(id); |
Denys Vlasenko | 405daff | 2012-09-02 14:29:45 +0200 | [diff] [blame] | 158 | for (i = 0; i < ARRAY_SIZE(llproto_ids); i++) { |
| 159 | if (llproto_ids[i] == id) |
| 160 | return nth_string(llproto_names, i); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 161 | } |
Denys Vlasenko | 405daff | 2012-09-02 14:29:45 +0200 | [diff] [blame] | 162 | snprintf(buf, len, "[%u]", id); |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 163 | return buf; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Denys Vlasenko | d31575a | 2009-10-13 17:58:24 +0200 | [diff] [blame] | 166 | int FAST_FUNC ll_proto_a2n(unsigned short *id, char *buf) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 167 | { |
Denis Vlasenko | 6b06cb8 | 2008-05-15 21:30:45 +0000 | [diff] [blame] | 168 | unsigned i; |
Denys Vlasenko | 405daff | 2012-09-02 14:29:45 +0200 | [diff] [blame] | 169 | const char *name = llproto_names; |
| 170 | for (i = 0; i < ARRAY_SIZE(llproto_ids); i++) { |
| 171 | if (strcasecmp(name, buf) == 0) { |
| 172 | i = llproto_ids[i]; |
| 173 | goto good; |
| 174 | } |
| 175 | name += strlen(name) + 1; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 176 | } |
Denys Vlasenko | 405daff | 2012-09-02 14:29:45 +0200 | [diff] [blame] | 177 | errno = 0; |
Denis Vlasenko | 76140a7 | 2009-03-05 09:21:57 +0000 | [diff] [blame] | 178 | i = bb_strtou(buf, NULL, 0); |
| 179 | if (errno || i > 0xffff) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 180 | return -1; |
Denis Vlasenko | 76140a7 | 2009-03-05 09:21:57 +0000 | [diff] [blame] | 181 | good: |
| 182 | *id = htons(i); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 183 | return 0; |
| 184 | } |