blob: e094d9f81ccc20cd44611f42bfedd2e32aa7d82d [file] [log] [blame]
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +00001/*
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!shemmingeraba5acd2004-04-15 20:56:59 +000020#include <netinet/in.h>
21#include <arpa/inet.h>
22#include <string.h>
23
osdl.org!shemmingerea7436f2004-06-09 22:53:56 +000024#include <linux/netdevice.h>
25#include <linux/if_arp.h>
26#include <linux/sockios.h>
27
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000028#include "utils.h"
osdl.org!shemmingerea7436f2004-06-09 22:53:56 +000029#include "rt_names.h"
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000030
31
32#define __PF(f,n) { ETH_P_##f, #n },
Stephen Hemminger75dbf132011-08-31 10:45:04 -070033static const struct {
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000034 int id;
osdl.org!shemmingerea7436f2004-06-09 22:53:56 +000035 const char *name;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000036} llproto_names[] = {
37__PF(LOOP,loop)
Stephen Hemmingerae665a52006-12-05 10:10:22 -080038__PF(PUP,pup)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000039__PF(PUPAT,pupat)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000040__PF(IP,ip)
41__PF(X25,x25)
42__PF(ARP,arp)
43__PF(BPQ,bpq)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000044__PF(IEEEPUP,ieeepup)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000045__PF(IEEEPUPAT,ieeepupat)
Stephen Hemmingerae665a52006-12-05 10:10:22 -080046__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!shemmingeraba5acd2004-04-15 20:56:59 +000059__PF(PPP_DISC,ppp_disc)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000060__PF(PPP_SES,ppp_ses)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000061__PF(ATMMPOA,atmmpoa)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000062__PF(ATMFATE,atmfate)
Stephen Hemmingerae665a52006-12-05 10:10:22 -080063__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 Hartkopp98f9a1d2009-03-27 11:21:29 -070072__PF(CAN,can)
Stephen Hemmingerae665a52006-12-05 10:10:22 -080073__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!shemmingeraba5acd2004-04-15 20:56:59 +000078__PF(ECONET,econet)
Stephen Hemminger10bd7e82008-02-07 19:24:31 -080079__PF(TIPC,tipc)
80__PF(AOE,aoe)
Patric McHardy8fd8f6e2013-06-21 08:59:24 -070081__PF(8021Q,802.1Q)
82__PF(8021AD,802.1ad)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000083
84{ 0x8100, "802.1Q" },
Stephen Hemminger75dbf132011-08-31 10:45:04 -070085{ 0x88cc, "LLDP" },
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000086{ ETH_P_IP, "ipv4" },
87};
88#undef __PF
89
90
osdl.org!shemmingerea7436f2004-06-09 22:53:56 +000091const char * ll_proto_n2a(unsigned short id, char *buf, int len)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000092{
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 Hemminger46ac8a52013-02-12 11:39:07 -0800105int ll_proto_a2n(unsigned short *id, const char *buf)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000106{
107 int i;
Stephen Hemminger46ac8a52013-02-12 11:39:07 -0800108 for (i=0; i < sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000109 if (strcasecmp(llproto_names[i].name, buf) == 0) {
110 *id = htons(llproto_names[i].id);
111 return 0;
112 }
113 }
Sabrina Dubroca9f7401f2016-06-03 16:45:46 +0200114 if (get_be16(id, buf, 0))
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000115 return -1;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000116 return 0;
117}