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
38struct 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
57struct ifvxlanparam {
58	uint64_t		vxlp_with;
59
60#define VXLAN_PARAM_WITH_VNI		0x0001
61#define VXLAN_PARAM_WITH_LOCAL_ADDR4	0x0002
62#define VXLAN_PARAM_WITH_LOCAL_ADDR6	0x0004
63#define VXLAN_PARAM_WITH_REMOTE_ADDR4	0x0008
64#define VXLAN_PARAM_WITH_REMOTE_ADDR6	0x0010
65#define VXLAN_PARAM_WITH_LOCAL_PORT	0x0020
66#define VXLAN_PARAM_WITH_REMOTE_PORT	0x0040
67#define VXLAN_PARAM_WITH_PORT_RANGE	0x0080
68#define VXLAN_PARAM_WITH_FTABLE_TIMEOUT	0x0100
69#define VXLAN_PARAM_WITH_FTABLE_MAX	0x0200
70#define VXLAN_PARAM_WITH_MULTICAST_IF	0x0400
71#define VXLAN_PARAM_WITH_TTL		0x0800
72#define VXLAN_PARAM_WITH_LEARN		0x1000
73
74	uint32_t		vxlp_vni;
75	struct in_addr		vxlp_local_in4;
76	struct in6_addr		vxlp_local_in6;
77	struct in_addr		vxlp_remote_in4;
78	struct in6_addr		vxlp_remote_in6;
79	uint16_t		vxlp_local_port;
80	uint16_t		vxlp_remote_port;
81	uint16_t		vxlp_min_port;
82	uint16_t		vxlp_max_port;
83	char			vxlp_mc_ifname[IFNAMSIZ];
84	uint32_t		vxlp_ftable_timeout;
85	uint32_t		vxlp_ftable_max;
86	uint8_t			vxlp_ttl;
87	uint8_t			vxlp_learn;
88};
89
90union vxlan_sockaddr {
91	struct sockaddr		sa;
92	struct sockaddr_in	in4;
93	struct sockaddr_in6	in6;
94};
95
96#define VXLAN_SOCKADDR_IS_IPV4(_vxsin)	((_vxsin)->sa.sa_family == AF_INET)
97#define VXLAN_SOCKADDR_IS_IPV6(_vxsin)	((_vxsin)->sa.sa_family == AF_INET6)
98#define VXLAN_SOCKADDR_IS_IPV46(_vxsin) \
99    (VXLAN_SOCKADDR_IS_IPV4(_vxsin) || VXLAN_SOCKADDR_IS_IPV6(_vxsin))
100
101#define VXLAN_CMD_GET_CONFIG		0
102#define VXLAN_CMD_SET_VNI		1
103#define VXLAN_CMD_SET_LOCAL_ADDR	2
104#define VXLAN_CMD_SET_REMOTE_ADDR	4
105#define VXLAN_CMD_SET_LOCAL_PORT	5
106#define VXLAN_CMD_SET_REMOTE_PORT	6
107#define VXLAN_CMD_SET_PORT_RANGE	7
108#define VXLAN_CMD_SET_FTABLE_TIMEOUT	8
109#define VXLAN_CMD_SET_FTABLE_MAX	9
110#define VXLAN_CMD_SET_MULTICAST_IF	10
111#define VXLAN_CMD_SET_TTL		11
112#define VXLAN_CMD_SET_LEARN		12
113#define VXLAN_CMD_FTABLE_ENTRY_ADD	13
114#define VXLAN_CMD_FTABLE_ENTRY_REM	14
115#define VXLAN_CMD_FLUSH			15
116
117struct ifvxlancfg {
118	uint32_t		vxlc_vni;
119	union vxlan_sockaddr	vxlc_local_sa;
120	union vxlan_sockaddr	vxlc_remote_sa;
121	uint32_t		vxlc_mc_ifindex;
122	uint32_t		vxlc_ftable_cnt;
123	uint32_t		vxlc_ftable_max;
124	uint32_t		vxlc_ftable_timeout;
125	uint16_t		vxlc_port_min;
126	uint16_t		vxlc_port_max;
127	uint8_t			vxlc_learn;
128	uint8_t			vxlc_ttl;
129};
130
131struct ifvxlancmd {
132	uint32_t		vxlcmd_flags;
133#define VXLAN_CMD_FLAG_FLUSH_ALL	0x0001
134#define VXLAN_CMD_FLAG_LEARN		0x0002
135
136	uint32_t		vxlcmd_vni;
137	uint32_t		vxlcmd_ftable_timeout;
138	uint32_t		vxlcmd_ftable_max;
139	uint16_t		vxlcmd_port;
140	uint16_t		vxlcmd_port_min;
141	uint16_t		vxlcmd_port_max;
142	uint8_t			vxlcmd_mac[ETHER_ADDR_LEN];
143	uint8_t			vxlcmd_ttl;
144	union vxlan_sockaddr	vxlcmd_sa;
145	char			vxlcmd_ifname[IFNAMSIZ];
146};
147
148#endif /* _NET_IF_VXLAN_H_ */
149