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