]> git.proxmox.com Git - mirror_iproute2.git/blame - lib/ll_proto.c
bridge: fdb: add support for src_vni option
[mirror_iproute2.git] / lib / ll_proto.c
CommitLineData
aba5acdf
SH
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>
aba5acdf
SH
15#include <fcntl.h>
16#include <sys/ioctl.h>
17#include <sys/socket.h>
aba5acdf
SH
18#include <netinet/in.h>
19#include <arpa/inet.h>
20#include <string.h>
21
ea7436fb
SH
22#include <linux/netdevice.h>
23#include <linux/if_arp.h>
24#include <linux/sockios.h>
25
aba5acdf 26#include "utils.h"
ea7436fb 27#include "rt_names.h"
aba5acdf
SH
28
29
30#define __PF(f,n) { ETH_P_##f, #n },
75dbf137 31static const struct {
aba5acdf 32 int id;
ea7436fb 33 const char *name;
aba5acdf
SH
34} llproto_names[] = {
35__PF(LOOP,loop)
ae665a52 36__PF(PUP,pup)
aba5acdf 37__PF(PUPAT,pupat)
aba5acdf
SH
38__PF(IP,ip)
39__PF(X25,x25)
40__PF(ARP,arp)
41__PF(BPQ,bpq)
aba5acdf 42__PF(IEEEPUP,ieeepup)
aba5acdf 43__PF(IEEEPUPAT,ieeepupat)
ae665a52
SH
44__PF(DEC,dec)
45__PF(DNA_DL,dna_dl)
46__PF(DNA_RC,dna_rc)
47__PF(DNA_RT,dna_rt)
48__PF(LAT,lat)
49__PF(DIAG,diag)
50__PF(CUST,cust)
51__PF(SCA,sca)
52__PF(RARP,rarp)
53__PF(ATALK,atalk)
54__PF(AARP,aarp)
55__PF(IPX,ipx)
56__PF(IPV6,ipv6)
aba5acdf 57__PF(PPP_DISC,ppp_disc)
aba5acdf 58__PF(PPP_SES,ppp_ses)
aba5acdf 59__PF(ATMMPOA,atmmpoa)
aba5acdf 60__PF(ATMFATE,atmfate)
ae665a52
SH
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)
98f9a1d2 70__PF(CAN,can)
ae665a52
SH
71__PF(PPPTALK,ppptalk)
72__PF(TR_802_2,tr_802_2)
73__PF(MOBITEX,mobitex)
74__PF(CONTROL,control)
75__PF(IRDA,irda)
aba5acdf 76__PF(ECONET,econet)
10bd7e84
SH
77__PF(TIPC,tipc)
78__PF(AOE,aoe)
8fd8f6ed
PM
79__PF(8021Q,802.1Q)
80__PF(8021AD,802.1ad)
aba5acdf
SH
81
82{ 0x8100, "802.1Q" },
75dbf137 83{ 0x88cc, "LLDP" },
aba5acdf
SH
84{ ETH_P_IP, "ipv4" },
85};
86#undef __PF
87
88
ea7436fb 89const char * ll_proto_n2a(unsigned short id, char *buf, int len)
aba5acdf
SH
90{
91 int i;
92
93 id = ntohs(id);
94
95 for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
96 if (llproto_names[i].id == id)
97 return llproto_names[i].name;
98 }
99 snprintf(buf, len, "[%d]", id);
100 return buf;
101}
102
46ac8a55 103int ll_proto_a2n(unsigned short *id, const char *buf)
aba5acdf
SH
104{
105 int i;
46ac8a55 106 for (i=0; i < sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
aba5acdf
SH
107 if (strcasecmp(llproto_names[i].name, buf) == 0) {
108 *id = htons(llproto_names[i].id);
109 return 0;
110 }
111 }
9f7401fa 112 if (get_be16(id, buf, 0))
aba5acdf 113 return -1;
aba5acdf
SH
114 return 0;
115}