2009-05-01 19:41:40 +05:30
|
|
|
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
|
2011-06-30 05:16:31 +05:30
|
|
|
# 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
|
2012-10-11 09:19:45 +05:30
|
|
|
program /sbin/ifconfig /bin/ifconfig
|
2012-10-11 09:24:32 +05:30
|
|
|
# If you do not have sysfs, you MUST have this binary instead for ioctl
|
|
|
|
# Also you will loose some functionality that cannot be done via sysfs:
|
|
|
|
if [ ! -d /sys/class/net ]; then
|
|
|
|
program /sbin/ifenslave
|
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
_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}
|
|
|
|
|
2012-10-11 09:19:45 +05:30
|
|
|
eval subsume="\$subsume_${IFVAR}"
|
|
|
|
unset subsume_${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
|
|
|
|
|
2012-10-11 09:24:32 +05:30
|
|
|
if [ ! -d /sys/class/net ]; then
|
|
|
|
ewarn "sysfs is not available! You will be unable to create new bonds, or change dynamic parameters!"
|
|
|
|
fi
|
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
# 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
|
2012-10-11 09:24:32 +05:30
|
|
|
[ -d /sys/class/net ] && for x in /sys/class/net/"${IFACE}"/bonding/mode; do
|
2010-11-01 03:10:54 +05:30
|
|
|
[ -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
|
2012-10-17 23:23:17 +05:30
|
|
|
# Configure link monitoring
|
|
|
|
for x in /sys/class/net/"${IFACE}"/bonding/miimon; 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
|
2010-11-01 03:10:54 +05:30
|
|
|
# Nice and dynamic for remaining options:)
|
2012-10-11 09:24:32 +05:30
|
|
|
[ -d /sys/class/net ] && for x in /sys/class/net/"${IFACE}"/bonding/*; do
|
2008-09-19 15:02:24 +05:30
|
|
|
[ -f "${x}" ] || continue
|
2010-03-25 02:11:18 +05:30
|
|
|
n=${x##*/}
|
|
|
|
eval s=\$${n}_${IFVAR}
|
2012-10-17 23:23:17 +05:30
|
|
|
[ "${n}" != "mode" -o "${n}" != "miimon" ] || 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
|
|
|
|
|
2012-10-11 09:19:45 +05:30
|
|
|
# Unless we are subsuming an existing interface (NFS root), we down
|
|
|
|
# slave interfaces to work around bugs supposedly in some chipsets
|
|
|
|
# that cause failure to enslave from other states.
|
|
|
|
if [ -z "${subsume}" ]; then
|
|
|
|
for IFACE in ${slaves}; do
|
|
|
|
_delete_addresses
|
|
|
|
_down
|
|
|
|
done
|
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
)
|
|
|
|
|
2012-10-11 09:19:45 +05:30
|
|
|
# Now force the master to up
|
|
|
|
# - First test for interface subsume request (required for NFS root)
|
|
|
|
if [ -n "${subsume}" ]; then
|
|
|
|
einfo "Subsuming ${subsume} interface characteristics."
|
|
|
|
eindent
|
|
|
|
local oiface=${IFACE}
|
|
|
|
IFACE=${subsume}
|
|
|
|
local addr="$(_get_inet_address)"
|
|
|
|
einfo "address: ${addr}"
|
|
|
|
IFACE=${oiface}
|
|
|
|
unset oiface
|
|
|
|
eoutdent
|
|
|
|
# subsume (presumably kernel auto-)configured IP
|
|
|
|
ifconfig ${IFACE} ${addr} up
|
|
|
|
else
|
|
|
|
# warn if root on nfs and no subsume interface supplied
|
|
|
|
local root_fs_type=$(mountinfo -s /)
|
2012-11-07 04:48:08 +05:30
|
|
|
if [ "${root_fs_type}" = "nfs" ]; then
|
2012-10-11 09:19:45 +05:30
|
|
|
warn_nfs=1
|
|
|
|
ewarn "NFS root detected!!!"
|
|
|
|
ewarn " If your system crashes here, /etc/conf.d/net needs"
|
|
|
|
ewarn " subsume_${IFACE}=\"<iface>\" ... where <iface> is the"
|
|
|
|
ewarn " existing, (usually kernel auto-)configured interface."
|
|
|
|
fi
|
|
|
|
# up the interface
|
|
|
|
_up
|
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# finally add in slaves
|
2011-12-13 07:42:35 +05:30
|
|
|
# things needed in the process, and if they are done by ifenslave, openrc, and/or the kernel.
|
|
|
|
# down new slave interface: ifenslave, openrc
|
|
|
|
# set mtu: ifenslave, kernel
|
|
|
|
# set slave MAC: ifenslave, kernel
|
2007-04-05 16:48:42 +05:30
|
|
|
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
|
2012-01-26 00:00:33 +05:30
|
|
|
local oiface
|
|
|
|
oiface=$IFACE
|
2010-08-14 03:02:31 +05:30
|
|
|
if [ -n "${primary}" ]; then
|
2012-01-27 01:17:46 +05:30
|
|
|
IFACE=$primary
|
2012-01-26 00:00:33 +05:30
|
|
|
_down
|
|
|
|
IFACE=$oiface
|
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
|
2012-01-27 01:17:46 +05:30
|
|
|
IFACE=$s
|
2012-01-26 00:00:33 +05:30
|
|
|
_down
|
|
|
|
IFACE=$oiface
|
2011-05-17 01:26:50 +05:30
|
|
|
echo "+${s}" >$sys_bonding_path/slaves
|
|
|
|
fi
|
2008-09-19 03:54:58 +05:30
|
|
|
done
|
|
|
|
else
|
2012-10-11 09:24:32 +05:30
|
|
|
ifenslave "${IFACE}" ${slaves} >/dev/null
|
2008-09-19 03:54:58 +05:30
|
|
|
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
|
|
|
|
2012-10-11 09:19:45 +05:30
|
|
|
# Wipe subsumed interface
|
|
|
|
if [ -n "${subsume}" ]; then
|
|
|
|
ifconfig ${subsume} 0.0.0.0
|
|
|
|
fi
|
|
|
|
|
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
|
2012-10-11 09:24:32 +05:30
|
|
|
ifenslave -d "${IFACE}" ${slaves}
|
2008-09-19 03:54:58 +05:30
|
|
|
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
|
|
|
|
}
|