xref: /freebsd/sys/net/if_vxlan.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1007054f0SBryan Venteicher /*-
2007054f0SBryan Venteicher  * Copyright (c) 2014, Bryan Venteicher <bryanv@FreeBSD.org>
3007054f0SBryan Venteicher  * All rights reserved.
4007054f0SBryan Venteicher  *
5007054f0SBryan Venteicher  * Redistribution and use in source and binary forms, with or without
6007054f0SBryan Venteicher  * modification, are permitted provided that the following conditions
7007054f0SBryan Venteicher  * are met:
8007054f0SBryan Venteicher  * 1. Redistributions of source code must retain the above copyright
9007054f0SBryan Venteicher  *    notice unmodified, this list of conditions, and the following
10007054f0SBryan Venteicher  *    disclaimer.
11007054f0SBryan Venteicher  * 2. Redistributions in binary form must reproduce the above copyright
12007054f0SBryan Venteicher  *    notice, this list of conditions and the following disclaimer in the
13007054f0SBryan Venteicher  *    documentation and/or other materials provided with the distribution.
14007054f0SBryan Venteicher  *
15007054f0SBryan Venteicher  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16007054f0SBryan Venteicher  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17007054f0SBryan Venteicher  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18007054f0SBryan Venteicher  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19007054f0SBryan Venteicher  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20007054f0SBryan Venteicher  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21007054f0SBryan Venteicher  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22007054f0SBryan Venteicher  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23007054f0SBryan Venteicher  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24007054f0SBryan Venteicher  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25007054f0SBryan Venteicher  */
26007054f0SBryan Venteicher 
27007054f0SBryan Venteicher #ifndef _NET_IF_VXLAN_H_
28007054f0SBryan Venteicher #define _NET_IF_VXLAN_H_
29007054f0SBryan Venteicher 
30007054f0SBryan Venteicher #include <sys/types.h>
31007054f0SBryan Venteicher #include <sys/socket.h>
32007054f0SBryan Venteicher #include <net/ethernet.h>
33007054f0SBryan Venteicher #include <net/if.h>
34007054f0SBryan Venteicher #include <netinet/in.h>
35007054f0SBryan Venteicher 
36007054f0SBryan Venteicher struct vxlan_header {
37007054f0SBryan Venteicher 	uint32_t	vxlh_flags;
38007054f0SBryan Venteicher 	uint32_t	vxlh_vni;
39007054f0SBryan Venteicher };
40007054f0SBryan Venteicher 
41007054f0SBryan Venteicher #define VXLAN_HDR_FLAGS_VALID_VNI	0x08000000
42007054f0SBryan Venteicher #define VXLAN_HDR_VNI_SHIFT		8
43007054f0SBryan Venteicher 
44007054f0SBryan Venteicher #define VXLAN_VNI_MAX	(1 << 24)
45007054f0SBryan Venteicher #define VXLAN_VNI_MASK	(VXLAN_VNI_MAX - 1)
46007054f0SBryan Venteicher 
47007054f0SBryan Venteicher /*
48007054f0SBryan Venteicher  * The port assigned by IANA is 4789, but some early implementations
49007054f0SBryan Venteicher  * (like Linux) use 8472 instead. If not specified, we default to
50007054f0SBryan Venteicher  * the IANA port.
51007054f0SBryan Venteicher  */
52007054f0SBryan Venteicher #define VXLAN_PORT		4789
53007054f0SBryan Venteicher #define VXLAN_LEGACY_PORT	8472
54007054f0SBryan Venteicher 
5533e0d8f0SBryan Venteicher union vxlan_sockaddr {
5633e0d8f0SBryan Venteicher 	struct sockaddr		sa;
5733e0d8f0SBryan Venteicher 	struct sockaddr_in	in4;
5833e0d8f0SBryan Venteicher 	struct sockaddr_in6	in6;
5933e0d8f0SBryan Venteicher };
6033e0d8f0SBryan Venteicher 
61007054f0SBryan Venteicher struct ifvxlanparam {
62007054f0SBryan Venteicher 	uint64_t		vxlp_with;
63007054f0SBryan Venteicher 
64007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_VNI		0x0001
65007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_LOCAL_ADDR4	0x0002
66007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_LOCAL_ADDR6	0x0004
67007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_REMOTE_ADDR4	0x0008
68007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_REMOTE_ADDR6	0x0010
69007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_LOCAL_PORT	0x0020
70007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_REMOTE_PORT	0x0040
71007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_PORT_RANGE	0x0080
72007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_FTABLE_TIMEOUT	0x0100
73007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_FTABLE_MAX	0x0200
74007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_MULTICAST_IF	0x0400
75007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_TTL		0x0800
76007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_LEARN		0x1000
77007054f0SBryan Venteicher 
78007054f0SBryan Venteicher 	uint32_t		vxlp_vni;
7933e0d8f0SBryan Venteicher 	union vxlan_sockaddr 	vxlp_local_sa;
8033e0d8f0SBryan Venteicher 	union vxlan_sockaddr 	vxlp_remote_sa;
81007054f0SBryan Venteicher 	uint16_t		vxlp_local_port;
82007054f0SBryan Venteicher 	uint16_t		vxlp_remote_port;
83007054f0SBryan Venteicher 	uint16_t		vxlp_min_port;
84007054f0SBryan Venteicher 	uint16_t		vxlp_max_port;
85007054f0SBryan Venteicher 	char			vxlp_mc_ifname[IFNAMSIZ];
86007054f0SBryan Venteicher 	uint32_t		vxlp_ftable_timeout;
87007054f0SBryan Venteicher 	uint32_t		vxlp_ftable_max;
88007054f0SBryan Venteicher 	uint8_t			vxlp_ttl;
89007054f0SBryan Venteicher 	uint8_t			vxlp_learn;
90007054f0SBryan Venteicher };
91007054f0SBryan Venteicher 
92007054f0SBryan Venteicher #define VXLAN_SOCKADDR_IS_IPV4(_vxsin)	((_vxsin)->sa.sa_family == AF_INET)
93007054f0SBryan Venteicher #define VXLAN_SOCKADDR_IS_IPV6(_vxsin)	((_vxsin)->sa.sa_family == AF_INET6)
94007054f0SBryan Venteicher #define VXLAN_SOCKADDR_IS_IPV46(_vxsin) \
95007054f0SBryan Venteicher     (VXLAN_SOCKADDR_IS_IPV4(_vxsin) || VXLAN_SOCKADDR_IS_IPV6(_vxsin))
96007054f0SBryan Venteicher 
97007054f0SBryan Venteicher #define VXLAN_CMD_GET_CONFIG		0
98007054f0SBryan Venteicher #define VXLAN_CMD_SET_VNI		1
99007054f0SBryan Venteicher #define VXLAN_CMD_SET_LOCAL_ADDR	2
100007054f0SBryan Venteicher #define VXLAN_CMD_SET_REMOTE_ADDR	4
101007054f0SBryan Venteicher #define VXLAN_CMD_SET_LOCAL_PORT	5
102007054f0SBryan Venteicher #define VXLAN_CMD_SET_REMOTE_PORT	6
103007054f0SBryan Venteicher #define VXLAN_CMD_SET_PORT_RANGE	7
104007054f0SBryan Venteicher #define VXLAN_CMD_SET_FTABLE_TIMEOUT	8
105007054f0SBryan Venteicher #define VXLAN_CMD_SET_FTABLE_MAX	9
106007054f0SBryan Venteicher #define VXLAN_CMD_SET_MULTICAST_IF	10
107007054f0SBryan Venteicher #define VXLAN_CMD_SET_TTL		11
108007054f0SBryan Venteicher #define VXLAN_CMD_SET_LEARN		12
109007054f0SBryan Venteicher #define VXLAN_CMD_FTABLE_ENTRY_ADD	13
110007054f0SBryan Venteicher #define VXLAN_CMD_FTABLE_ENTRY_REM	14
111007054f0SBryan Venteicher #define VXLAN_CMD_FLUSH			15
112007054f0SBryan Venteicher 
113007054f0SBryan Venteicher struct ifvxlancfg {
114007054f0SBryan Venteicher 	uint32_t		vxlc_vni;
115007054f0SBryan Venteicher 	union vxlan_sockaddr	vxlc_local_sa;
116007054f0SBryan Venteicher 	union vxlan_sockaddr	vxlc_remote_sa;
117007054f0SBryan Venteicher 	uint32_t		vxlc_mc_ifindex;
118007054f0SBryan Venteicher 	uint32_t		vxlc_ftable_cnt;
119007054f0SBryan Venteicher 	uint32_t		vxlc_ftable_max;
120007054f0SBryan Venteicher 	uint32_t		vxlc_ftable_timeout;
121007054f0SBryan Venteicher 	uint16_t		vxlc_port_min;
122007054f0SBryan Venteicher 	uint16_t		vxlc_port_max;
123007054f0SBryan Venteicher 	uint8_t			vxlc_learn;
124007054f0SBryan Venteicher 	uint8_t			vxlc_ttl;
125007054f0SBryan Venteicher };
126007054f0SBryan Venteicher 
127007054f0SBryan Venteicher struct ifvxlancmd {
128007054f0SBryan Venteicher 	uint32_t		vxlcmd_flags;
129007054f0SBryan Venteicher #define VXLAN_CMD_FLAG_FLUSH_ALL	0x0001
130007054f0SBryan Venteicher #define VXLAN_CMD_FLAG_LEARN		0x0002
131007054f0SBryan Venteicher 
132007054f0SBryan Venteicher 	uint32_t		vxlcmd_vni;
133007054f0SBryan Venteicher 	uint32_t		vxlcmd_ftable_timeout;
134007054f0SBryan Venteicher 	uint32_t		vxlcmd_ftable_max;
135007054f0SBryan Venteicher 	uint16_t		vxlcmd_port;
136007054f0SBryan Venteicher 	uint16_t		vxlcmd_port_min;
137007054f0SBryan Venteicher 	uint16_t		vxlcmd_port_max;
138007054f0SBryan Venteicher 	uint8_t			vxlcmd_mac[ETHER_ADDR_LEN];
139007054f0SBryan Venteicher 	uint8_t			vxlcmd_ttl;
140007054f0SBryan Venteicher 	union vxlan_sockaddr	vxlcmd_sa;
141007054f0SBryan Venteicher 	char			vxlcmd_ifname[IFNAMSIZ];
142007054f0SBryan Venteicher };
143007054f0SBryan Venteicher 
144*b092fd6cSNavdeep Parhar #ifdef _KERNEL
145*b092fd6cSNavdeep Parhar typedef void (*vxlan_event_handler_t)(void *, struct ifnet *, sa_family_t,
146*b092fd6cSNavdeep Parhar     u_int);
147*b092fd6cSNavdeep Parhar EVENTHANDLER_DECLARE(vxlan_start, vxlan_event_handler_t);
148*b092fd6cSNavdeep Parhar EVENTHANDLER_DECLARE(vxlan_stop, vxlan_event_handler_t);
149*b092fd6cSNavdeep Parhar #endif
150*b092fd6cSNavdeep Parhar 
151007054f0SBryan Venteicher #endif /* _NET_IF_VXLAN_H_ */
152