]> git.ipfire.org Git - people/stevee/network.git/commitdiff
bonding: Improve robustness of the code
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 6 Sep 2014 13:24:07 +0000 (15:24 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 6 Sep 2014 13:24:07 +0000 (15:24 +0200)
src/functions/functions.bonding
src/udev/network-hotplug

index 247d37caa15d0f64f80a9196eef773f6b77a75a6..495ad3073d1b5233454e5a0cd2203ef09bebdedf 100644 (file)
@@ -24,11 +24,7 @@ BONDING_ALLOWED_MODES="balance-rr active-backup balance-xor broadcast 802.3ad \
 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() {
@@ -73,7 +69,7 @@ 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
@@ -84,16 +80,10 @@ function bonding_create() {
        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}
@@ -111,7 +101,7 @@ function bonding_remove() {
        device_set_down ${device}
 
        # Remove the device.
-       print "-${device}" > ${BONDING_MASTERS}
+       fwrite "${BONDING_MASTERS}" "-${device}"
        local ret=$?
 
        if [ ${ret} -eq ${EXIT_OK} ]; then
@@ -133,6 +123,22 @@ function bonding_get_mode() {
        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
@@ -151,13 +157,13 @@ function bonding_enslave_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
 
index a9787c4977690c4c8effb0b8518225d20af2323b..09ecc0c498ef86d73f8e137bc16e4c143836287b 100644 (file)
@@ -36,10 +36,18 @@ assert isset INTERFACE
 # 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