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 * $FreeBSD$ 27007054f0SBryan Venteicher */ 28007054f0SBryan Venteicher 29007054f0SBryan Venteicher #ifndef _NET_IF_VXLAN_H_ 30007054f0SBryan Venteicher #define _NET_IF_VXLAN_H_ 31007054f0SBryan Venteicher 32007054f0SBryan Venteicher #include <sys/types.h> 33007054f0SBryan Venteicher #include <sys/socket.h> 34007054f0SBryan Venteicher #include <net/ethernet.h> 35007054f0SBryan Venteicher #include <net/if.h> 36007054f0SBryan Venteicher #include <netinet/in.h> 37007054f0SBryan Venteicher 38007054f0SBryan Venteicher struct vxlan_header { 39007054f0SBryan Venteicher uint32_t vxlh_flags; 40007054f0SBryan Venteicher uint32_t vxlh_vni; 41007054f0SBryan Venteicher }; 42007054f0SBryan Venteicher 43007054f0SBryan Venteicher #define VXLAN_HDR_FLAGS_VALID_VNI 0x08000000 44007054f0SBryan Venteicher #define VXLAN_HDR_VNI_SHIFT 8 45007054f0SBryan Venteicher 46007054f0SBryan Venteicher #define VXLAN_VNI_MAX (1 << 24) 47007054f0SBryan Venteicher #define VXLAN_VNI_MASK (VXLAN_VNI_MAX - 1) 48007054f0SBryan Venteicher 49007054f0SBryan Venteicher /* 50007054f0SBryan Venteicher * The port assigned by IANA is 4789, but some early implementations 51007054f0SBryan Venteicher * (like Linux) use 8472 instead. If not specified, we default to 52007054f0SBryan Venteicher * the IANA port. 53007054f0SBryan Venteicher */ 54007054f0SBryan Venteicher #define VXLAN_PORT 4789 55007054f0SBryan Venteicher #define VXLAN_LEGACY_PORT 8472 56007054f0SBryan Venteicher 57*33e0d8f0SBryan Venteicher union vxlan_sockaddr { 58*33e0d8f0SBryan Venteicher struct sockaddr sa; 59*33e0d8f0SBryan Venteicher struct sockaddr_in in4; 60*33e0d8f0SBryan Venteicher struct sockaddr_in6 in6; 61*33e0d8f0SBryan Venteicher }; 62*33e0d8f0SBryan Venteicher 63007054f0SBryan Venteicher struct ifvxlanparam { 64007054f0SBryan Venteicher uint64_t vxlp_with; 65007054f0SBryan Venteicher 66007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_VNI 0x0001 67007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_LOCAL_ADDR4 0x0002 68007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_LOCAL_ADDR6 0x0004 69007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_REMOTE_ADDR4 0x0008 70007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_REMOTE_ADDR6 0x0010 71007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_LOCAL_PORT 0x0020 72007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_REMOTE_PORT 0x0040 73007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_PORT_RANGE 0x0080 74007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_FTABLE_TIMEOUT 0x0100 75007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_FTABLE_MAX 0x0200 76007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_MULTICAST_IF 0x0400 77007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_TTL 0x0800 78007054f0SBryan Venteicher #define VXLAN_PARAM_WITH_LEARN 0x1000 79007054f0SBryan Venteicher 80007054f0SBryan Venteicher uint32_t vxlp_vni; 81*33e0d8f0SBryan Venteicher union vxlan_sockaddr vxlp_local_sa; 82*33e0d8f0SBryan Venteicher union vxlan_sockaddr vxlp_remote_sa; 83007054f0SBryan Venteicher uint16_t vxlp_local_port; 84007054f0SBryan Venteicher uint16_t vxlp_remote_port; 85007054f0SBryan Venteicher uint16_t vxlp_min_port; 86007054f0SBryan Venteicher uint16_t vxlp_max_port; 87007054f0SBryan Venteicher char vxlp_mc_ifname[IFNAMSIZ]; 88007054f0SBryan Venteicher uint32_t vxlp_ftable_timeout; 89007054f0SBryan Venteicher uint32_t vxlp_ftable_max; 90007054f0SBryan Venteicher uint8_t vxlp_ttl; 91007054f0SBryan Venteicher uint8_t vxlp_learn; 92007054f0SBryan Venteicher }; 93007054f0SBryan Venteicher 94007054f0SBryan Venteicher #define VXLAN_SOCKADDR_IS_IPV4(_vxsin) ((_vxsin)->sa.sa_family == AF_INET) 95007054f0SBryan Venteicher #define VXLAN_SOCKADDR_IS_IPV6(_vxsin) ((_vxsin)->sa.sa_family == AF_INET6) 96007054f0SBryan Venteicher #define VXLAN_SOCKADDR_IS_IPV46(_vxsin) \ 97007054f0SBryan Venteicher (VXLAN_SOCKADDR_IS_IPV4(_vxsin) || VXLAN_SOCKADDR_IS_IPV6(_vxsin)) 98007054f0SBryan Venteicher 99007054f0SBryan Venteicher #define VXLAN_CMD_GET_CONFIG 0 100007054f0SBryan Venteicher #define VXLAN_CMD_SET_VNI 1 101007054f0SBryan Venteicher #define VXLAN_CMD_SET_LOCAL_ADDR 2 102007054f0SBryan Venteicher #define VXLAN_CMD_SET_REMOTE_ADDR 4 103007054f0SBryan Venteicher #define VXLAN_CMD_SET_LOCAL_PORT 5 104007054f0SBryan Venteicher #define VXLAN_CMD_SET_REMOTE_PORT 6 105007054f0SBryan Venteicher #define VXLAN_CMD_SET_PORT_RANGE 7 106007054f0SBryan Venteicher #define VXLAN_CMD_SET_FTABLE_TIMEOUT 8 107007054f0SBryan Venteicher #define VXLAN_CMD_SET_FTABLE_MAX 9 108007054f0SBryan Venteicher #define VXLAN_CMD_SET_MULTICAST_IF 10 109007054f0SBryan Venteicher #define VXLAN_CMD_SET_TTL 11 110007054f0SBryan Venteicher #define VXLAN_CMD_SET_LEARN 12 111007054f0SBryan Venteicher #define VXLAN_CMD_FTABLE_ENTRY_ADD 13 112007054f0SBryan Venteicher #define VXLAN_CMD_FTABLE_ENTRY_REM 14 113007054f0SBryan Venteicher #define VXLAN_CMD_FLUSH 15 114007054f0SBryan Venteicher 115007054f0SBryan Venteicher struct ifvxlancfg { 116007054f0SBryan Venteicher uint32_t vxlc_vni; 117007054f0SBryan Venteicher union vxlan_sockaddr vxlc_local_sa; 118007054f0SBryan Venteicher union vxlan_sockaddr vxlc_remote_sa; 119007054f0SBryan Venteicher uint32_t vxlc_mc_ifindex; 120007054f0SBryan Venteicher uint32_t vxlc_ftable_cnt; 121007054f0SBryan Venteicher uint32_t vxlc_ftable_max; 122007054f0SBryan Venteicher uint32_t vxlc_ftable_timeout; 123007054f0SBryan Venteicher uint16_t vxlc_port_min; 124007054f0SBryan Venteicher uint16_t vxlc_port_max; 125007054f0SBryan Venteicher uint8_t vxlc_learn; 126007054f0SBryan Venteicher uint8_t vxlc_ttl; 127007054f0SBryan Venteicher }; 128007054f0SBryan Venteicher 129007054f0SBryan Venteicher struct ifvxlancmd { 130007054f0SBryan Venteicher uint32_t vxlcmd_flags; 131007054f0SBryan Venteicher #define VXLAN_CMD_FLAG_FLUSH_ALL 0x0001 132007054f0SBryan Venteicher #define VXLAN_CMD_FLAG_LEARN 0x0002 133007054f0SBryan Venteicher 134007054f0SBryan Venteicher uint32_t vxlcmd_vni; 135007054f0SBryan Venteicher uint32_t vxlcmd_ftable_timeout; 136007054f0SBryan Venteicher uint32_t vxlcmd_ftable_max; 137007054f0SBryan Venteicher uint16_t vxlcmd_port; 138007054f0SBryan Venteicher uint16_t vxlcmd_port_min; 139007054f0SBryan Venteicher uint16_t vxlcmd_port_max; 140007054f0SBryan Venteicher uint8_t vxlcmd_mac[ETHER_ADDR_LEN]; 141007054f0SBryan Venteicher uint8_t vxlcmd_ttl; 142007054f0SBryan Venteicher union vxlan_sockaddr vxlcmd_sa; 143007054f0SBryan Venteicher char vxlcmd_ifname[IFNAMSIZ]; 144007054f0SBryan Venteicher }; 145007054f0SBryan Venteicher 146007054f0SBryan Venteicher #endif /* _NET_IF_VXLAN_H_ */ 147