2009-05-01 19:41:40 +05:30
|
|
|
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
|
2008-01-11 21:01:10 +05:30
|
|
|
# All rights reserved. Released under the 2-clause BSD license.
|
2007-11-14 20:52:04 +05:30
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
bonding_depend()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
before interface macchanger
|
|
|
|
}
|
|
|
|
|
|
|
|
_config_vars="$_config_vars slaves"
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
_is_bond()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
[ -f "/proc/net/bonding/${IFACE}" ]
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
bonding_pre_start()
|
|
|
|
{
|
2010-08-14 03:02:31 +05:30
|
|
|
local x= s= n= slaves= primary=
|
|
|
|
|
|
|
|
slaves="$(_get_array "slaves_${IFVAR}")"
|
|
|
|
unset slaves_${IFVAR}
|
|
|
|
|
|
|
|
eval primary="\$primary_${IFVAR}"
|
|
|
|
unset primary_${IFVAR}
|
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-10-29 15:15:49 +05:30
|
|
|
[ -z "${slaves}" ] && return 0
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# Load the kernel module if required
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ ! -d /proc/net/bonding ]; then
|
|
|
|
if ! modprobe bonding; then
|
2007-04-05 16:48:42 +05:30
|
|
|
eerror "Cannot load the bonding module"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# We can create the interface name we like now, but this
|
|
|
|
# requires sysfs
|
2007-11-28 21:15:03 +05:30
|
|
|
if ! _exists && [ -d /sys/class/net ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
echo "+${IFACE}" > /sys/class/net/bonding_masters
|
|
|
|
fi
|
|
|
|
_exists true || return 1
|
|
|
|
|
2007-11-28 21:15:03 +05:30
|
|
|
if ! _is_bond; then
|
2007-04-05 16:48:42 +05:30
|
|
|
eerror "${IFACE} is not capable of bonding"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2010-11-01 03:10:54 +05:30
|
|
|
# Interface must be down in order to configure
|
|
|
|
_down
|
|
|
|
|
|
|
|
# Configure the bond mode, then we can reloop to ensure we configure
|
|
|
|
# All other options
|
|
|
|
for x in /sys/class/net/"${IFACE}"/bonding/mode; do
|
|
|
|
[ -f "${x}" ] || continue
|
|
|
|
n=${x##*/}
|
|
|
|
eval s=\$${n}_${IFVAR}
|
|
|
|
if [ -n "${s}" ]; then
|
|
|
|
einfo "Setting ${n}: ${s}"
|
|
|
|
echo "${s}" >"${x}" || \
|
|
|
|
eerror "Failed to configure $n (${n}_${IFVAR})"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# Nice and dynamic for remaining options:)
|
2008-09-19 15:02:24 +05:30
|
|
|
for x in /sys/class/net/"${IFACE}"/bonding/*; do
|
|
|
|
[ -f "${x}" ] || continue
|
2010-03-25 02:11:18 +05:30
|
|
|
n=${x##*/}
|
|
|
|
eval s=\$${n}_${IFVAR}
|
2010-11-01 03:10:54 +05:30
|
|
|
[ "${n}" != "mode" ] || continue
|
2008-09-19 15:02:24 +05:30
|
|
|
if [ -n "${s}" ]; then
|
2010-08-14 03:02:31 +05:30
|
|
|
einfo "Setting ${n}: ${s}"
|
2010-03-25 02:11:18 +05:30
|
|
|
echo "${s}" >"${x}" || \
|
|
|
|
eerror "Failed to configure $n (${n}_${IFVAR})"
|
2008-09-19 15:02:24 +05:30
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
ebegin "Adding slaves to ${IFACE}"
|
|
|
|
eindent
|
2007-10-29 15:15:49 +05:30
|
|
|
einfo "${slaves}"
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# Check that our slaves exist
|
|
|
|
(
|
2007-10-29 15:15:49 +05:30
|
|
|
for IFACE in ${slaves}; do
|
2007-04-05 16:48:42 +05:30
|
|
|
_exists true || return 1
|
|
|
|
done
|
|
|
|
|
|
|
|
# Must force the slaves to a particular state before adding them
|
2007-10-29 15:15:49 +05:30
|
|
|
for IFACE in ${slaves}; do
|
2007-04-05 16:48:42 +05:30
|
|
|
_delete_addresses
|
2008-09-19 03:54:58 +05:30
|
|
|
_down
|
2007-04-05 16:48:42 +05:30
|
|
|
done
|
|
|
|
)
|
|
|
|
|
|
|
|
# now force the master to up
|
|
|
|
_up
|
|
|
|
|
|
|
|
# finally add in slaves
|
|
|
|
eoutdent
|
2008-09-19 03:54:58 +05:30
|
|
|
if [ -d /sys/class/net ]; then
|
2011-05-16 18:51:18 +05:30
|
|
|
sys_bonding_path=/sys/class/net/"${IFACE}"/bonding
|
2010-08-14 03:02:31 +05:30
|
|
|
if [ -n "${primary}" ]; then
|
2011-05-16 18:51:18 +05:30
|
|
|
echo "+${primary}" >$sys_bonding_path/slaves
|
|
|
|
echo "${primary}" >$sys_bonding_path/primary
|
2010-08-14 03:02:31 +05:30
|
|
|
fi
|
2008-09-19 03:54:58 +05:30
|
|
|
for s in ${slaves}; do
|
2011-03-18 23:54:18 +05:30
|
|
|
[ "${s}" = "${primary}" ] && continue
|
2011-05-17 01:26:50 +05:30
|
|
|
if ! grep -q ${s} $sys_bonding_path/slaves; then
|
|
|
|
echo "+${s}" >$sys_bonding_path/slaves
|
|
|
|
fi
|
2008-09-19 03:54:58 +05:30
|
|
|
done
|
|
|
|
else
|
|
|
|
/sbin/ifenslave "${IFACE}" ${slaves} >/dev/null
|
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
eend $?
|
|
|
|
|
|
|
|
return 0 #important
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
bonding_stop()
|
|
|
|
{
|
2011-01-17 15:19:07 +05:30
|
|
|
_is_bond || return 0
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
local slaves= s=
|
|
|
|
slaves=$( \
|
|
|
|
sed -n -e 's/^Slave Interface: //p' "/proc/net/bonding/${IFACE}" \
|
|
|
|
| tr '\n' ' ' \
|
|
|
|
)
|
|
|
|
[ -z "${slaves}" ] && return 0
|
|
|
|
|
|
|
|
# remove all slaves
|
|
|
|
ebegin "Removing slaves from ${IFACE}"
|
|
|
|
eindent
|
|
|
|
einfo "${slaves}"
|
|
|
|
eoutdent
|
2008-09-19 03:54:58 +05:30
|
|
|
if [ -d /sys/class/net ]; then
|
|
|
|
for s in ${slaves}; do
|
|
|
|
echo -"${s}" > /sys/class/net/"${IFACE}"/bonding/slaves
|
|
|
|
done
|
|
|
|
else
|
|
|
|
/sbin/ifenslave -d "${IFACE}" ${slaves}
|
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# reset all slaves
|
|
|
|
(
|
|
|
|
for IFACE in ${slaves}; do
|
2007-11-28 21:15:03 +05:30
|
|
|
if _exists; then
|
2007-04-05 16:48:42 +05:30
|
|
|
_delete_addresses
|
|
|
|
_down
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
)
|
|
|
|
|
2010-08-14 03:12:23 +05:30
|
|
|
_down
|
|
|
|
|
|
|
|
if [ -d /sys/class/net ]; then
|
|
|
|
echo "-${IFACE}" > /sys/class/net/bonding_masters
|
|
|
|
fi
|
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
eend 0
|
|
|
|
return 0
|
|
|
|
}
|