File: bond

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 (57 lines) | stat: -rwxr-xr-x 1,297 bytes parent folder | download | duplicates (4)
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
#!/bin/sh
#
# This executor is responsible for setting up bond/LAG interfaces.
#
# Sat, 03 Oct 2020 20:42:19 +0200
#  -- Maximilian Wilhelm <max@sdn.clinic>
#
[ -n "$VERBOSE" ] && set -x

get_bond_options() {
	# We only care for options of format IF_BOND_<OPTION_NAME>
	env | grep '^IF_BOND_[A-Z0-9_]\+' | while IFS="=" read opt value; do
		# Members are handled seperately
		if [ "${opt}" = "IF_BOND_MEMBERS" ]; then
			continue
		fi

		# Convert options for the actual name
		real_opt=$(echo "${opt}" | sed -e 's/^IF_BOND_\([A-Z0-9_]\+\)/\1/' | tr '[A-Z]' '[a-z]')

		echo -n " ${real_opt} ${value}"
	done
}

case "$PHASE" in
	depend)
		echo "${IF_BOND_MEMBERS}"
		;;

	create)
		if [ -d "/sys/class/net/${IFACE}" ]; then
			exit 0
		fi

		# Gather bonding options for this interface
		options=$(get_bond_options)

		# Create bond
		${MOCK} ip link add "${IFACE}" type bond ${options}

		# Add members to bundle
		for member_iface in ${IF_BOND_MEMBERS}; do
			# Work around the current execution order
			${MOCK} ip link set "${member_iface}" down
			${MOCK} ip link set master "${IFACE}" "${member_iface}"
			${MOCK} ip link set "${member_iface}" up
		done
		;;

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

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