File: vxlan

package info (click to toggle)
ifupdown-ng 0.12.1-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 964 kB
  • sloc: ansic: 3,572; sh: 980; makefile: 233
file content (96 lines) | stat: -rwxr-xr-x 2,913 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/sh
#
# This executor is responsible for setting up the Virtual Extensible LAN (VXLAN) overlay interfaces.
#
# Fri, 02 Oct 2020 01:10:29 +0200
#  -- Maximilian Wilhelm <max@sdn.clinic>
#
# 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_PEER_IPS	Space separated list of IPs of the remote VTEP endpoint (for ptp/ptmp mode with ingress replication)
# IF_VXLAN_PEER_GROUP	Multicast group to use for this VNI (for ptmp mode with multicast)
# 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)
#
[ -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
			exit 0
		fi

		# Input validation
		if [ "${IF_VXLAN_PEER_IPS}" -a "${IF_VXLAN_PEER_GROUP}" ]; then
			echo "Error on ${IFACE} (vxlan): Only one of 'vxlan-peer-ips' and 'vxlan-peer-group' can be used!" >&2
			exit 1
		fi

		# Check if we should operate in unicast ptp or ptmp mode
		if [ "${IF_VXLAN_PEER_IPS}" ]; then
			# If it's only one thing which looks like an IPv4/IPv6 address we assume it's ptp
			if echo "${IF_VXLAN_PEER_IPS}" | grep -q '^[[:space:]]*[[:xdigit:].:]\+[[:space:]]*$'; then
				UCAST_MODE="ptp"
			else
				UCAST_MODE="ptmp"
			fi
		fi

		# Gather arguments
		ARGS=""
		[ "${IF_VXLAN_PHYSDEV}" ] && ARGS="${ARGS} dev ${IF_VXLAN_PHYSDEV}"
		[ "${IF_VXLAN_LOCAL_IP}" ] && ARGS="${ARGS} local ${IF_VXLAN_LOCAL_IP}"
		[ "${UCAST_MODE}" = "ptp" ] && ARGS="${ARGS} remote ${IF_VXLAN_PEER_IPS}"
		[ "${IF_VXLAN_PEER_GROUP}" ] && ARGS="${ARGS} group ${IF_VXLAN_PEER_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}

		# Set up FDB entries for peer VTEPs
		if [ "${UCAST_MODE}" = "ptmp" ]; then
			for peer in ${IF_VXLAN_PEER_IPS}; do
				${MOCK} bridge fdb append 00:00:00:00:00:00 dev "${IFACE}" dst "${peer}" self permanent
			done
		fi
		;;

	destroy)
		if [ -z "${MOCK}" -a ! -d "/sys/class/net/${IFACE}" ]; then
			exit 0
		fi

		${MOCK} ip link del "${IFACE}"
		;;
esac