"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 | /* |
| 3 | * ll_proto.c |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version |
| 8 | * 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
| 11 | */ |
| 12 | |
Rob Landley | ea224be | 2006-06-18 20:20:07 +0000 | [diff] [blame] | 13 | #include "libbb.h" |
Bernhard Reutner-Fischer | 9a67ca3 | 2006-04-02 21:14:19 +0000 | [diff] [blame] | 14 | #include "rt_names.h" |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 15 | #include "utils.h" |
| 16 | |
Denis Vlasenko | 83e5d6f | 2006-12-18 21:49:06 +0000 | [diff] [blame] | 17 | #if defined(__GLIBC__) && __GLIBC__ >=2 && __GLIBC_MINOR__ >= 1 |
Eric Andersen | feb283a | 2003-07-14 08:49:43 +0000 | [diff] [blame] | 18 | #include <net/ethernet.h> |
| 19 | #else |
| 20 | #include <linux/if_ether.h> |
| 21 | #endif |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 22 | |
Denis Vlasenko | dfc0740 | 2007-10-29 19:33:26 +0000 | [diff] [blame] | 23 | #ifdef UNUSED |
| 24 | /* 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 McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 29 | #define __PF(f,n) { ETH_P_##f, #n }, |
| 30 | static struct { |
| 31 | int id; |
Denis Vlasenko | 322661d | 2007-01-29 23:43:52 +0000 | [diff] [blame] | 32 | const char *name; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 33 | } llproto_names[] = { |
| 34 | __PF(LOOP,loop) |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 35 | __PF(PUP,pup) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 36 | #ifdef ETH_P_PUPAT |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 37 | __PF(PUPAT,pupat) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 38 | #endif |
| 39 | __PF(IP,ip) |
| 40 | __PF(X25,x25) |
| 41 | __PF(ARP,arp) |
| 42 | __PF(BPQ,bpq) |
| 43 | #ifdef ETH_P_IEEEPUP |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 44 | __PF(IEEEPUP,ieeepup) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 45 | #endif |
| 46 | #ifdef ETH_P_IEEEPUPAT |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 47 | __PF(IEEEPUPAT,ieeepupat) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 48 | #endif |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 49 | __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 Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 62 | #ifdef ETH_P_PPP_DISC |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 63 | __PF(PPP_DISC,ppp_disc) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 64 | #endif |
| 65 | #ifdef ETH_P_PPP_SES |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 66 | __PF(PPP_SES,ppp_ses) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 67 | #endif |
| 68 | #ifdef ETH_P_ATMMPOA |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 69 | __PF(ATMMPOA,atmmpoa) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 70 | #endif |
| 71 | #ifdef ETH_P_ATMFATE |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 72 | __PF(ATMFATE,atmfate) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 73 | #endif |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 74 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 75 | __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 Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 89 | #ifdef ETH_P_ECONET |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 90 | __PF(ECONET,econet) |
Eric Andersen | 0f08e53 | 2003-06-20 09:05:00 +0000 | [diff] [blame] | 91 | #endif |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 92 | |
| 93 | { 0x8100, "802.1Q" }, |
| 94 | { ETH_P_IP, "ipv4" }, |
| 95 | }; |
| 96 | #undef __PF |
| 97 | |
| 98 | |
Denis Vlasenko | dfc0740 | 2007-10-29 19:33:26 +0000 | [diff] [blame] | 99 | const char *ll_proto_n2a(unsigned short id, char *buf, int len) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 100 | { |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 101 | int i; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 102 | |
| 103 | id = ntohs(id); |
| 104 | |
Denis Vlasenko | 284d0fa | 2008-02-16 13:18:17 +0000 | [diff] [blame] | 105 | for (i = 0; i < ARRAY_SIZE(llproto_names); i++) { |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 106 | if (llproto_names[i].id == id) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 107 | return llproto_names[i].name; |
| 108 | } |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 109 | snprintf(buf, len, "[%d]", id); |
| 110 | return buf; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | int ll_proto_a2n(unsigned short *id, char *buf) |
| 114 | { |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 115 | int i; |
Denis Vlasenko | 284d0fa | 2008-02-16 13:18:17 +0000 | [diff] [blame] | 116 | for (i = 0; i < ARRAY_SIZE(llproto_names); i++) { |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 117 | if (strcasecmp(llproto_names[i].name, buf) == 0) { |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 118 | *id = htons(llproto_names[i].id); |
| 119 | return 0; |
| 120 | } |
| 121 | } |
| 122 | if (get_u16(id, buf, 0)) |
| 123 | return -1; |
| 124 | *id = htons(*id); |
| 125 | return 0; |
| 126 | } |
Denis Vlasenko | dfc0740 | 2007-10-29 19:33:26 +0000 | [diff] [blame] | 127 | |
| 128 | #endif /* UNUSED */ |