| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# This executor is responsible for setting up the Virtual Extensible LAN (VXLAN) overlay interfaces. |
| 4 |
# |
| 5 |
# Fri, 02 Oct 2020 01:10:29 +0200 |
| 6 |
# -- Maximilian Wilhelm <[email protected]> |
| 7 |
# |
| 8 |
# Known options for the main interface are: |
| 9 |
# |
| 10 |
# IF_VXLAN_ID The VXLAN Network Identifier (VNI) |
| 11 |
# IF_VXLAN_PHYSDEV Specifies the physical device to use for tunnel endpoint communication |
| 12 |
# IF_VXLAN_LOCAL_IP Specifies the source IP address to use in outgoing packets |
| 13 |
# IF_VXLAN_PEER_IPS Space separated list of IPs of the remote VTEP endpoint (for ptp/ptmp mode with ingress replication) |
| 14 |
# IF_VXLAN_PEER_GROUP Multicast group to use for this VNI (for ptmp mode with multicast) |
| 15 |
# IF_VXLAN_LEARNING Wether to activate MAC learning on this instance (on/off) |
| 16 |
# IF_VXLAN_AGEING Specifies the lifetime in seconds of FDB entries learnt by the kernel |
| 17 |
# IF_VXLAN_DSTPORT UDP destination port to communicate to the remote VXLAN tunnel endpoint (default 4789) |
| 18 |
# |
| 19 |
[ -n "$VERBOSE" ] && set -x |
| 20 |
|
| 21 |
# No VNI, nuthin' to do for us |
| 22 |
if [ ! "${IF_VXLAN_ID}" ]; then |
| 23 |
exit 0 |
| 24 |
fi |
| 25 |
|
| 26 |
case "$PHASE" in |
| 27 |
depend) |
| 28 |
if [ "${IF_VXLAN_PHYSDEV}" ]; then |
| 29 |
echo "${IF_VXLAN_PHYSDEV}" |
| 30 |
fi |
| 31 |
;; |
| 32 |
|
| 33 |
create) |
| 34 |
if [ -d "/sys/class/net/${IFACE}" ]; then |
| 35 |
exit 0 |
| 36 |
fi |
| 37 |
|
| 38 |
# Input validation |
| 39 |
if [ "${IF_VXLAN_PEER_IPS}" -a "${IF_VXLAN_PEER_GROUP}" ]; then |
| 40 |
echo "Error on ${IFACE} (vxlan): Only one of 'vxlan-peer-ips' and 'vxlan-peer-group' can be used!" >&2 |
| 41 |
exit 1 |
| 42 |
fi |
| 43 |
|
| 44 |
# Check if we should operate in unicast ptp or ptmp mode |
| 45 |
if [ "${IF_VXLAN_PEER_IPS}" ]; then |
| 46 |
# If it's only one thing which looks like an IPv4/IPv6 address we assume it's ptp |
| 47 |
if echo "${IF_VXLAN_PEER_IPS}" | grep -q '^[[:space:]]*[[:xdigit:].:]\+[[:space:]]*$'; then |
| 48 |
UCAST_MODE="ptp" |
| 49 |
else |
| 50 |
UCAST_MODE="ptmp" |
| 51 |
fi |
| 52 |
fi |
| 53 |
|
| 54 |
# Gather arguments |
| 55 |
ARGS="" |
| 56 |
[ "${IF_VXLAN_PHYSDEV}" ] && ARGS="${ARGS} dev ${IF_VXLAN_PHYSDEV}" |
| 57 |
[ "${IF_VXLAN_LOCAL_IP}" ] && ARGS="${ARGS} local ${IF_VXLAN_LOCAL_IP}" |
| 58 |
[ "${UCAST_MODE}" = "ptp" ] && ARGS="${ARGS} remote ${IF_VXLAN_PEER_IPS}" |
| 59 |
[ "${IF_VXLAN_PEER_GROUP}" ] && ARGS="${ARGS} group ${IF_VXLAN_PEER_GROUP}" |
| 60 |
[ "${IF_VXLAN_AGEING}" ] && ARGS="${ARGS} ageing ${IF_VXLAN_AGEING}" |
| 61 |
|
| 62 |
# Linux uses non-standard default port - WTF? |
| 63 |
if [ "${IF_VXLAN_DSTPORT}" ]; then |
| 64 |
ARGS="${ARGS} dstport ${IF_VXLAN_DSTPORT}" |
| 65 |
else |
| 66 |
ARGS="${ARGS} dstport 4789" |
| 67 |
fi |
| 68 |
|
| 69 |
case "${IF_VXLAN_LEARNING}" in |
| 70 |
on|yes) |
| 71 |
ARGS="${ARGS} learning" |
| 72 |
;; |
| 73 |
|
| 74 |
off|no) |
| 75 |
ARGS="${ARGS} nolearning" |
| 76 |
;; |
| 77 |
esac |
| 78 |
|
| 79 |
${MOCK} ip link add "${IFACE}" type vxlan id "${IF_VXLAN_ID}" ${ARGS} |
| 80 |
|
| 81 |
# Set up FDB entries for peer VTEPs |
| 82 |
if [ "${UCAST_MODE}" = "ptmp" ]; then |
| 83 |
for peer in ${IF_VXLAN_PEER_IPS}; do |
| 84 |
${MOCK} bridge fdb append 00:00:00:00:00:00 dev "${IFACE}" dst "${peer}" self permanent |
| 85 |
done |
| 86 |
fi |
| 87 |
;; |
| 88 |
|
| 89 |
destroy) |
| 90 |
if [ -z "${MOCK}" -a ! -d "/sys/class/net/${IFACE}" ]; then |
| 91 |
exit 0 |
| 92 |
fi |
| 93 |
|
| 94 |
${MOCK} ip link del "${IFACE}" |
| 95 |
;; |
| 96 |
esac |