osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * ll_proto.c |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version |
| 7 | * 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
| 10 | */ |
| 11 | |
| 12 | #include <stdio.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <unistd.h> |
| 15 | #include <syslog.h> |
| 16 | #include <fcntl.h> |
| 17 | #include <sys/ioctl.h> |
| 18 | #include <sys/socket.h> |
| 19 | #include <sys/ioctl.h> |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 20 | #include <netinet/in.h> |
| 21 | #include <arpa/inet.h> |
| 22 | #include <string.h> |
| 23 | |
osdl.org!shemminger | ea7436f | 2004-06-09 22:53:56 +0000 | [diff] [blame] | 24 | #include <linux/netdevice.h> |
| 25 | #include <linux/if_arp.h> |
| 26 | #include <linux/sockios.h> |
| 27 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 28 | #include "utils.h" |
osdl.org!shemminger | ea7436f | 2004-06-09 22:53:56 +0000 | [diff] [blame] | 29 | #include "rt_names.h" |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 30 | |
| 31 | |
| 32 | #define __PF(f,n) { ETH_P_##f, #n }, |
Stephen Hemminger | 75dbf13 | 2011-08-31 10:45:04 -0700 | [diff] [blame] | 33 | static const struct { |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 34 | int id; |
osdl.org!shemminger | ea7436f | 2004-06-09 22:53:56 +0000 | [diff] [blame] | 35 | const char *name; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 36 | } llproto_names[] = { |
| 37 | __PF(LOOP,loop) |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 38 | __PF(PUP,pup) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 39 | __PF(PUPAT,pupat) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 40 | __PF(IP,ip) |
| 41 | __PF(X25,x25) |
| 42 | __PF(ARP,arp) |
| 43 | __PF(BPQ,bpq) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 44 | __PF(IEEEPUP,ieeepup) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 45 | __PF(IEEEPUPAT,ieeepupat) |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 46 | __PF(DEC,dec) |
| 47 | __PF(DNA_DL,dna_dl) |
| 48 | __PF(DNA_RC,dna_rc) |
| 49 | __PF(DNA_RT,dna_rt) |
| 50 | __PF(LAT,lat) |
| 51 | __PF(DIAG,diag) |
| 52 | __PF(CUST,cust) |
| 53 | __PF(SCA,sca) |
| 54 | __PF(RARP,rarp) |
| 55 | __PF(ATALK,atalk) |
| 56 | __PF(AARP,aarp) |
| 57 | __PF(IPX,ipx) |
| 58 | __PF(IPV6,ipv6) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 59 | __PF(PPP_DISC,ppp_disc) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 60 | __PF(PPP_SES,ppp_ses) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 61 | __PF(ATMMPOA,atmmpoa) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 62 | __PF(ATMFATE,atmfate) |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 63 | __PF(802_3,802_3) |
| 64 | __PF(AX25,ax25) |
| 65 | __PF(ALL,all) |
| 66 | __PF(802_2,802_2) |
| 67 | __PF(SNAP,snap) |
| 68 | __PF(DDCMP,ddcmp) |
| 69 | __PF(WAN_PPP,wan_ppp) |
| 70 | __PF(PPP_MP,ppp_mp) |
| 71 | __PF(LOCALTALK,localtalk) |
Oliver Hartkopp | 98f9a1d | 2009-03-27 11:21:29 -0700 | [diff] [blame] | 72 | __PF(CAN,can) |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 73 | __PF(PPPTALK,ppptalk) |
| 74 | __PF(TR_802_2,tr_802_2) |
| 75 | __PF(MOBITEX,mobitex) |
| 76 | __PF(CONTROL,control) |
| 77 | __PF(IRDA,irda) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 78 | __PF(ECONET,econet) |
Stephen Hemminger | 10bd7e8 | 2008-02-07 19:24:31 -0800 | [diff] [blame] | 79 | __PF(TIPC,tipc) |
| 80 | __PF(AOE,aoe) |
Patric McHardy | 8fd8f6e | 2013-06-21 08:59:24 -0700 | [diff] [blame] | 81 | __PF(8021Q,802.1Q) |
| 82 | __PF(8021AD,802.1ad) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 83 | |
| 84 | { 0x8100, "802.1Q" }, |
Stephen Hemminger | 75dbf13 | 2011-08-31 10:45:04 -0700 | [diff] [blame] | 85 | { 0x88cc, "LLDP" }, |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 86 | { ETH_P_IP, "ipv4" }, |
| 87 | }; |
| 88 | #undef __PF |
| 89 | |
| 90 | |
osdl.org!shemminger | ea7436f | 2004-06-09 22:53:56 +0000 | [diff] [blame] | 91 | const char * ll_proto_n2a(unsigned short id, char *buf, int len) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 92 | { |
| 93 | int i; |
| 94 | |
| 95 | id = ntohs(id); |
| 96 | |
| 97 | for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) { |
| 98 | if (llproto_names[i].id == id) |
| 99 | return llproto_names[i].name; |
| 100 | } |
| 101 | snprintf(buf, len, "[%d]", id); |
| 102 | return buf; |
| 103 | } |
| 104 | |
Stephen Hemminger | 46ac8a5 | 2013-02-12 11:39:07 -0800 | [diff] [blame] | 105 | int ll_proto_a2n(unsigned short *id, const char *buf) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 106 | { |
| 107 | int i; |
Stephen Hemminger | 46ac8a5 | 2013-02-12 11:39:07 -0800 | [diff] [blame] | 108 | for (i=0; i < sizeof(llproto_names)/sizeof(llproto_names[0]); i++) { |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 109 | if (strcasecmp(llproto_names[i].name, buf) == 0) { |
| 110 | *id = htons(llproto_names[i].id); |
| 111 | return 0; |
| 112 | } |
| 113 | } |
Sabrina Dubroca | 9f7401f | 2016-06-03 16:45:46 +0200 | [diff] [blame] | 114 | if (get_be16(id, buf, 0)) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 115 | return -1; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 116 | return 0; |
| 117 | } |