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 27#ifndef _NET_IF_VXLAN_H_ 28#define _NET_IF_VXLAN_H_ 29 30#include <sys/types.h> 31#include <sys/socket.h> 32#include <net/ethernet.h> 33#include <net/if.h> 34#include <netinet/in.h> 35 36struct vxlan_header { 37 uint32_t vxlh_flags; 38 uint32_t vxlh_vni; 39}; 40 41#define VXLAN_HDR_FLAGS_VALID_VNI 0x08000000 42#define VXLAN_HDR_VNI_SHIFT 8 43 44#define VXLAN_VNI_MAX (1 << 24) 45#define VXLAN_VNI_MASK (VXLAN_VNI_MAX - 1) 46 47/* 48 * The port assigned by IANA is 4789, but some early implementations 49 * (like Linux) use 8472 instead. If not specified, we default to 50 * the IANA port. 51 */ 52#define VXLAN_PORT 4789 53#define VXLAN_LEGACY_PORT 8472 54 55union vxlan_sockaddr { 56 struct sockaddr sa; 57 struct sockaddr_in in4; 58 struct sockaddr_in6 in6; 59}; 60 61struct ifvxlanparam { 62 uint64_t vxlp_with; 63 64#define VXLAN_PARAM_WITH_VNI 0x0001 65#define VXLAN_PARAM_WITH_LOCAL_ADDR4 0x0002 66#define VXLAN_PARAM_WITH_LOCAL_ADDR6 0x0004 67#define VXLAN_PARAM_WITH_REMOTE_ADDR4 0x0008 68#define VXLAN_PARAM_WITH_REMOTE_ADDR6 0x0010 69#define VXLAN_PARAM_WITH_LOCAL_PORT 0x0020 70#define VXLAN_PARAM_WITH_REMOTE_PORT 0x0040 71#define VXLAN_PARAM_WITH_PORT_RANGE 0x0080 72#define VXLAN_PARAM_WITH_FTABLE_TIMEOUT 0x0100 73#define VXLAN_PARAM_WITH_FTABLE_MAX 0x0200 74#define VXLAN_PARAM_WITH_MULTICAST_IF 0x0400 75#define VXLAN_PARAM_WITH_TTL 0x0800 76#define VXLAN_PARAM_WITH_LEARN 0x1000 77 78 uint32_t vxlp_vni; 79 union vxlan_sockaddr vxlp_local_sa; 80 union vxlan_sockaddr vxlp_remote_sa; 81 uint16_t vxlp_local_port; 82 uint16_t vxlp_remote_port; 83 uint16_t vxlp_min_port; 84 uint16_t vxlp_max_port; 85 char vxlp_mc_ifname[IFNAMSIZ]; 86 uint32_t vxlp_ftable_timeout; 87 uint32_t vxlp_ftable_max; 88 uint8_t vxlp_ttl; 89 uint8_t vxlp_learn; 90}; 91 92#define VXLAN_SOCKADDR_IS_IPV4(_vxsin) ((_vxsin)->sa.sa_family == AF_INET) 93#define VXLAN_SOCKADDR_IS_IPV6(_vxsin) ((_vxsin)->sa.sa_family == AF_INET6) 94#define VXLAN_SOCKADDR_IS_IPV46(_vxsin) \ 95 (VXLAN_SOCKADDR_IS_IPV4(_vxsin) || VXLAN_SOCKADDR_IS_IPV6(_vxsin)) 96 97#define VXLAN_CMD_GET_CONFIG 0 98#define VXLAN_CMD_SET_VNI 1 99#define VXLAN_CMD_SET_LOCAL_ADDR 2 100#define VXLAN_CMD_SET_REMOTE_ADDR 4 101#define VXLAN_CMD_SET_LOCAL_PORT 5 102#define VXLAN_CMD_SET_REMOTE_PORT 6 103#define VXLAN_CMD_SET_PORT_RANGE 7 104#define VXLAN_CMD_SET_FTABLE_TIMEOUT 8 105#define VXLAN_CMD_SET_FTABLE_MAX 9 106#define VXLAN_CMD_SET_MULTICAST_IF 10 107#define VXLAN_CMD_SET_TTL 11 108#define VXLAN_CMD_SET_LEARN 12 109#define VXLAN_CMD_FTABLE_ENTRY_ADD 13 110#define VXLAN_CMD_FTABLE_ENTRY_REM 14 111#define VXLAN_CMD_FLUSH 15 112 113struct ifvxlancfg { 114 uint32_t vxlc_vni; 115 union vxlan_sockaddr vxlc_local_sa; 116 union vxlan_sockaddr vxlc_remote_sa; 117 uint32_t vxlc_mc_ifindex; 118 uint32_t vxlc_ftable_cnt; 119 uint32_t vxlc_ftable_max; 120 uint32_t vxlc_ftable_timeout; 121 uint16_t vxlc_port_min; 122 uint16_t vxlc_port_max; 123 uint8_t vxlc_learn; 124 uint8_t vxlc_ttl; 125}; 126 127struct ifvxlancmd { 128 uint32_t vxlcmd_flags; 129#define VXLAN_CMD_FLAG_FLUSH_ALL 0x0001 130#define VXLAN_CMD_FLAG_LEARN 0x0002 131 132 uint32_t vxlcmd_vni; 133 uint32_t vxlcmd_ftable_timeout; 134 uint32_t vxlcmd_ftable_max; 135 uint16_t vxlcmd_port; 136 uint16_t vxlcmd_port_min; 137 uint16_t vxlcmd_port_max; 138 uint8_t vxlcmd_mac[ETHER_ADDR_LEN]; 139 uint8_t vxlcmd_ttl; 140 union vxlan_sockaddr vxlcmd_sa; 141 char vxlcmd_ifname[IFNAMSIZ]; 142}; 143 144#ifdef _KERNEL 145typedef void (*vxlan_event_handler_t)(void *, struct ifnet *, sa_family_t, 146 u_int); 147EVENTHANDLER_DECLARE(vxlan_start, vxlan_event_handler_t); 148EVENTHANDLER_DECLARE(vxlan_stop, vxlan_event_handler_t); 149#endif 150 151#endif /* _NET_IF_VXLAN_H_ */ 152