Debian Codegraph @

executor-scripts/linux/bond

raw
1 #!/bin/sh
2 #
3 # This executor is responsible for setting up bond/LAG interfaces.
4 #
5 # Sat, 03 Oct 2020 20:42:19 +0200
6 # -- Maximilian Wilhelm <[email protected]>
7 #
8 [ -n "$VERBOSE" ] && set -x
9
10 get_bond_options() {
11 # We only care for options of format IF_BOND_<OPTION_NAME>
12 env | grep '^IF_BOND_[A-Z0-9_]\+' | while IFS="=" read opt value; do
13 # Members are handled seperately
14 if [ "${opt}" = "IF_BOND_MEMBERS" ]; then
15 continue
16 fi
17
18 # Convert options for the actual name
19 real_opt=$(echo "${opt}" | sed -e 's/^IF_BOND_\([A-Z0-9_]\+\)/\1/' | tr '[A-Z]' '[a-z]')
20
21 echo -n " ${real_opt} ${value}"
22 done
23 }
24
25 case "$PHASE" in
26 depend)
27 echo "${IF_BOND_MEMBERS}"
28 ;;
29
30 create)
31 if [ -d "/sys/class/net/${IFACE}" ]; then
32 exit 0
33 fi
34
35 # Gather bonding options for this interface
36 options=$(get_bond_options)
37
38 # Create bond
39 ${MOCK} ip link add "${IFACE}" type bond ${options}
40
41 # Add members to bundle
42 for member_iface in ${IF_BOND_MEMBERS}; do
43 # Work around the current execution order
44 ${MOCK} ip link set "${member_iface}" down
45 ${MOCK} ip link set master "${IFACE}" "${member_iface}"
46 ${MOCK} ip link set "${member_iface}" up
47 done
48 ;;
49
50 destroy)
51 if [ -z "${MOCK}" -a ! -d "/sys/class/net/${IFACE}" ]; then
52 exit 0
53 fi
54
55 ${MOCK} ip link del "${IFACE}"
56 ;;
57 esac