BONDING_MASTERS="/sys/class/net/bonding_masters"
function bonding_init() {
- if ! grep -q "^bonding" /proc/modules; then
- modprobe bonding
-
- bonding_remove bond0
- fi
+ module_load "bonding"
}
function bonding_create() {
bonding_init
# Create the bonding device.
- print "+${device}" > ${BONDING_MASTERS}
+ fwrite "${BONDING_MASTERS}" "+${device}"
local ret=$?
if [ ${ret} -eq ${EXIT_OK} ]; then
fi
# Set the mode of the bonding device.
- print "${mode}" > ${SYS_CLASS_NET}/${device}/bonding/mode
- local ret=$?
-
- if [ ${ret} -ne ${EXIT_OK} ]; then
- log ERROR "Could not set mode of bonding device '${device}': ${Mmode}"
- return ${EXIT_ERROR}
- fi
+ bonding_set_mode "${device}" "${mode}"
if isset address; then
- device_set_address ${device} ${address}
+ device_set_address "${device}" "${address}"
fi
return ${EXIT_OK}
device_set_down ${device}
# Remove the device.
- print "-${device}" > ${BONDING_MASTERS}
+ fwrite "${BONDING_MASTERS}" "-${device}"
local ret=$?
if [ ${ret} -eq ${EXIT_OK} ]; then
print "${mode}"
}
+function bonding_set_mode() {
+ assert [ $# -eq 2 ]
+
+ local device="${1}"
+ local mode="${2}"
+
+ if fwrite "${SYS_CLASS_NET}/${device}/bonding/mode" "${mode}"; then
+ log DEBUG "Set mode of bond '${device}' to '${mode}'"
+ else
+ log ERROR "Could not set mode of bond '${device}' to '${mode}'"
+ return ${EXIT_ERROR}
+ fi
+
+ return ${EXIT_OK}
+}
+
function bonding_enslave_device() {
local device=${1}
assert isset device
fi
# Add it.
- print "+${slave}" > ${SYS_CLASS_NET}/${device}/bonding/slaves
+ fwrite "${SYS_CLASS_NET}/${device}/bonding/slaves" "+${slave}"
local ret=$?
if [ ${ret} -eq ${EXIT_OK} ]; then
- log DEBUG "Successfully enslaved '${slave}' to '${device}'."
+ log DEBUG "Successfully enslaved '${slave}' to '${device}'"
else
- log ERROR "Could not enslave '${slave}' to '${device}'."
+ log ERROR "Could not enslave '${slave}' to '${device}'"
return ${EXIT_ERROR}
fi
# Check, if the device is a physical network interface and
# if we can handle it.
if device_exists ${INTERFACE}; then
- if ! device_is_ethernet ${INTERFACE}; then
- log DEBUG "Called for interface '${INTERFACE}' which is a virtual interface. Exiting."
- exit ${EXIT_OK}
- fi
+ type="$(device_get_type "${INTERFACE}")"
+ case "${type}" in
+ # Remove automatically created bonding interface without any configuration
+ bonding)
+ port_exists "${INTERFACE}" || bonding_remove "${INTERFACE}"
+ exit ${EXIT_OK}
+ ;;
+ ethernet)
+ log DEBUG "Called for interface '${INTERFACE}' which is a virtual interface. Exiting."
+ exit ${EXIT_OK}
+ ;;
+ esac
fi
case "${ACTION}" in