xref: /freebsd/sys/net/if_vxlan.h (revision c697fb7f)
1 /*-
2  * Copyright (c) 2014, Bryan Venteicher <bryanv@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice unmodified, this list of conditions, and the following
10  *    disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #ifndef _NET_IF_VXLAN_H_
30 #define _NET_IF_VXLAN_H_
31 
32 #include <sys/types.h>
33 #include <sys/socket.h>
34 #include <net/ethernet.h>
35 #include <net/if.h>
36 #include <netinet/in.h>
37 
38 struct vxlan_header {
39 	uint32_t	vxlh_flags;
40 	uint32_t	vxlh_vni;
41 };
42 
43 #define VXLAN_HDR_FLAGS_VALID_VNI	0x08000000
44 #define VXLAN_HDR_VNI_SHIFT		8
45 
46 #define VXLAN_VNI_MAX	(1 << 24)
47 #define VXLAN_VNI_MASK	(VXLAN_VNI_MAX - 1)
48 
49 /*
50  * The port assigned by IANA is 4789, but some early implementations
51  * (like Linux) use 8472 instead. If not specified, we default to
52  * the IANA port.
53  */
54 #define VXLAN_PORT		4789
55 #define VXLAN_LEGACY_PORT	8472
56 
57 union vxlan_sockaddr {
58 	struct sockaddr		sa;
59 	struct sockaddr_in	in4;
60 	struct sockaddr_in6	in6;
61 };
62 
63 struct ifvxlanparam {
64 	uint64_t		vxlp_with;
65 
66 #define VXLAN_PARAM_WITH_VNI		0x0001
67 #define VXLAN_PARAM_WITH_LOCAL_ADDR4	0x0002
68 #define VXLAN_PARAM_WITH_LOCAL_ADDR6	0x0004
69 #define VXLAN_PARAM_WITH_REMOTE_ADDR4	0x0008
70 #define VXLAN_PARAM_WITH_REMOTE_ADDR6	0x0010
71 #define VXLAN_PARAM_WITH_LOCAL_PORT	0x0020
72 #define VXLAN_PARAM_WITH_REMOTE_PORT	0x0040
73 #define VXLAN_PARAM_WITH_PORT_RANGE	0x0080
74 #define VXLAN_PARAM_WITH_FTABLE_TIMEOUT	0x0100
75 #define VXLAN_PARAM_WITH_FTABLE_MAX	0x0200
76 #define VXLAN_PARAM_WITH_MULTICAST_IF	0x0400
77 #define VXLAN_PARAM_WITH_TTL		0x0800
78 #define VXLAN_PARAM_WITH_LEARN		0x1000
79 
80 	uint32_t		vxlp_vni;
81 	union vxlan_sockaddr 	vxlp_local_sa;
82 	union vxlan_sockaddr 	vxlp_remote_sa;
83 	uint16_t		vxlp_local_port;
84 	uint16_t		vxlp_remote_port;
85 	uint16_t		vxlp_min_port;
86 	uint16_t		vxlp_max_port;
87 	char			vxlp_mc_ifname[IFNAMSIZ];
88 	uint32_t		vxlp_ftable_timeout;
89 	uint32_t		vxlp_ftable_max;
90 	uint8_t			vxlp_ttl;
91 	uint8_t			vxlp_learn;
92 };
93 
94 #define VXLAN_SOCKADDR_IS_IPV4(_vxsin)	((_vxsin)->sa.sa_family == AF_INET)
95 #define VXLAN_SOCKADDR_IS_IPV6(_vxsin)	((_vxsin)->sa.sa_family == AF_INET6)
96 #define VXLAN_SOCKADDR_IS_IPV46(_vxsin) \
97     (VXLAN_SOCKADDR_IS_IPV4(_vxsin) || VXLAN_SOCKADDR_IS_IPV6(_vxsin))
98 
99 #define VXLAN_CMD_GET_CONFIG		0
100 #define VXLAN_CMD_SET_VNI		1
101 #define VXLAN_CMD_SET_LOCAL_ADDR	2
102 #define VXLAN_CMD_SET_REMOTE_ADDR	4
103 #define VXLAN_CMD_SET_LOCAL_PORT	5
104 #define VXLAN_CMD_SET_REMOTE_PORT	6
105 #define VXLAN_CMD_SET_PORT_RANGE	7
106 #define VXLAN_CMD_SET_FTABLE_TIMEOUT	8
107 #define VXLAN_CMD_SET_FTABLE_MAX	9
108 #define VXLAN_CMD_SET_MULTICAST_IF	10
109 #define VXLAN_CMD_SET_TTL		11
110 #define VXLAN_CMD_SET_LEARN		12
111 #define VXLAN_CMD_FTABLE_ENTRY_ADD	13
112 #define VXLAN_CMD_FTABLE_ENTRY_REM	14
113 #define VXLAN_CMD_FLUSH			15
114 
115 struct ifvxlancfg {
116 	uint32_t		vxlc_vni;
117 	union vxlan_sockaddr	vxlc_local_sa;
118 	union vxlan_sockaddr	vxlc_remote_sa;
119 	uint32_t		vxlc_mc_ifindex;
120 	uint32_t		vxlc_ftable_cnt;
121 	uint32_t		vxlc_ftable_max;
122 	uint32_t		vxlc_ftable_timeout;
123 	uint16_t		vxlc_port_min;
124 	uint16_t		vxlc_port_max;
125 	uint8_t			vxlc_learn;
126 	uint8_t			vxlc_ttl;
127 };
128 
129 struct ifvxlancmd {
130 	uint32_t		vxlcmd_flags;
131 #define VXLAN_CMD_FLAG_FLUSH_ALL	0x0001
132 #define VXLAN_CMD_FLAG_LEARN		0x0002
133 
134 	uint32_t		vxlcmd_vni;
135 	uint32_t		vxlcmd_ftable_timeout;
136 	uint32_t		vxlcmd_ftable_max;
137 	uint16_t		vxlcmd_port;
138 	uint16_t		vxlcmd_port_min;
139 	uint16_t		vxlcmd_port_max;
140 	uint8_t			vxlcmd_mac[ETHER_ADDR_LEN];
141 	uint8_t			vxlcmd_ttl;
142 	union vxlan_sockaddr	vxlcmd_sa;
143 	char			vxlcmd_ifname[IFNAMSIZ];
144 };
145 
146 #endif /* _NET_IF_VXLAN_H_ */
147