diff --git a/executor-scripts/linux/vxlan b/executor-scripts/linux/vxlan new file mode 100755 index 0000000..4ee96ea --- /dev/null +++ b/executor-scripts/linux/vxlan @@ -0,0 +1,88 @@ +#!/bin/sh +# +# This executor is responsible for setting up the Virtual Extensible LAN (VXLA) overlay interfaces. +# +# Fri, 02 Oct 2020 01:10:29 +0200 +# -- Maximilian Wilhelm +# +# Known options for the main interface are: +# +# IF_VXLAN_ID The VXLAN Network Identifier (VNI) +# IF_VXLAN_PHYSDEV Specifies the physical device to use for tunnel endpoint communication +# IF_VXLAN_LOCAL_IP Specifies the source IP address to use in outgoing packets +# IF_VXLAN_REMOTE_IP IP of the remote VTEP endpoint (for ptp mode) +# IF_VXLAN_REMOTE_GROUP Multicast group to use for this VNI (for ptmp mode) +# IF_VXLAN_LEARNING Wether to activate MAC learning on this instance (on/off) +# IF_VXLAN_AGEING Specifies the lifetime in seconds of FDB entries learnt by the kernel +# IF_VXLAN_DSTPORT UDP destination port to communicate to the remote VXLAN tunnel endpoint (default 4789) +# + +set -e + +[ -n "$VERBOSE" ] && set -x + +# No VNI, nuthin' to do for us +if [ ! "${IF_VXLAN_ID}" ]; then + exit 0 +fi + +case "$PHASE" in + depend) + if [ "${IF_VXLAN_PHYSDEV}" ]; then + echo "${IF_VXLAN_PHYSDEV}" + fi + ;; + + create) + if [ -d "/sys/class/net/${IFACE}" ]; then + iface_type=$(ip -d link show dev "${IFACE}" | head -n3 | tail -n1 | awk '{ print $1 }') + if [ "${iface_type}" != 'dummy' ]; then + echo "Interface ${IFACE} exists but is of type ${iface_type} instead of dummy" + exit 1 + fi + + exit 0 + fi + + # Input validation + if [ "${IF_VXLAN_REMOTE_IP}" -a "${IF_VXLAN_REMOTE_GROUP}" ]; then + echo "Error on ${IFACE} (vxlan): Only one of 'remote' and 'group' can be given!" >&2 + exit 1 + fi + + # Gather arguments + ARGS="" + [ "${IF_VXLAN_PHYSDEV}" ] && ARGS="${ARGS} dev ${IF_VXLAN_PHYSDEV}" + [ "${IF_VXLAN_LOCAL_IP}" ] && ARGS="${ARGS} local ${IF_VXLAN_LOCAL_IP}" + [ "${IF_VXLAN_REMOTE_IP}" ] && ARGS="${ARGS} remote ${IF_VXLAN_REMOTE_IP}" + [ "${IF_VXLAN_REMOTE_GROUP}" ] && ARGS="${ARGS} group ${IF_VXLAN_REMOTE_GROUP}" + [ "${IF_VXLAN_AGEING}" ] && ARGS="${ARGS} ageing ${IF_VXLAN_AGEING}" + + # Linux uses non-standard default port - WTF? + if [ "${IF_VXLAN_DSTPORT}" ]; then + ARGS="${ARGS} dstport ${IF_VXLAN_DSTPORT}" + else + ARGS="${ARGS} dstport 4789" + fi + + case "${IF_VXLAN_LEARNING}" in + on|yes) + ARGS="${ARGS} learning" + ;; + + off|no) + ARGS="${ARGS} nolearning" + ;; + esac + + ${MOCK} ip link add "${IFACE}" type vxlan id "${IF_VXLAN_ID}" ${ARGS} + ;; + + destroy) + if [ -z "${MOCK}" -a ! -d "/sys/class/net/${IFACE}" ]; then + exit 0 + fi + + ${MOCK} ip link del "${IFACE}" + ;; +esac diff --git a/libifupdown/interface-file.c b/libifupdown/interface-file.c index 31971aa..fbaaa96 100644 --- a/libifupdown/interface-file.c +++ b/libifupdown/interface-file.c @@ -88,6 +88,9 @@ static const struct remap_token tokens[] = { {"tx-offload", "ethtool-offload-tx"}, /* ifupdown2 */ {"ufo-offload", "ethtool-offload-ufo"}, /* ifupdown2 */ {"vrf", "vrf-member"}, /* ifupdown2 */ + {"vxlan-local-tunnelip", "vxlan-local-ip"}, /* ifupdown2 */ + {"vxlan-remoteip", "vxlan-remote-ip"}, /* ifupdown2 */ + {"vxlan-svcnodeip", "vxlan-remote-group"}, /* ifupdown2 */ }; static int