]> git.ipfire.org Git - people/stevee/network.git/commitdiff
bridge: Simplify the hook and make it more robust against missing ports
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 6 Sep 2014 11:51:10 +0000 (13:51 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 6 Sep 2014 11:51:10 +0000 (13:51 +0200)
src/functions/functions.bridge
src/functions/functions.device
src/hooks/ports/ethernet
src/hooks/zones/bridge

index d5f4ad10d17282c445cdf6224d4186b1e60f5926..3f14e3879a6c6bea88569f85e95f064c83d5f849 100644 (file)
@@ -108,6 +108,10 @@ function bridge_attach_device() {
                return ${EXIT_OK}
        fi
 
+       # Make sure that the MTU of the device that is to be attached
+       # to the bridge matches the MTU of the bridge.
+       device_adjust_mtu "${device}" "${bridge}"
+
        # Actually connect bridge and device.
        cmd_quiet ip link set ${device} master ${bridge}
        local ret=$?
index 5890ff9a538fb5fb6be5d9eb4d01f95a1f0f5e9c..4f47b7cdad3e0a39bffea0fc0f651b3d14394718 100644 (file)
@@ -631,6 +631,16 @@ function device_set_mtu() {
        return ${ret}
 }
 
+function device_adjust_mtu() {
+       assert [ $# -eq 2 ]
+
+       local device="${1}"
+       local other_device="${2}"
+
+       local mtu="$(device_get_mtu "${other_device}")"
+       device_set_mtu "${device}" "${mtu}"
+}
+
 function device_discover() {
        local device=${1}
 
index 35cc8eb3b3a358e182b3567dde6ad1cac9ef15ba..d02884667325bc441f9b169a6870eec95e1a5416 100644 (file)
@@ -51,6 +51,11 @@ function hook_up() {
        local port=${1}
        assert isset port
 
+       if ! device_exists "${port}"; then
+               log WARNING "Cannot bring up port '${port}' which does not exist"
+               exit ${EXIT_OK}
+       fi
+
        # Read in the confguration file.
        port_settings_read "${port}" ${HOOK_SETTINGS}
 
@@ -60,7 +65,7 @@ function hook_up() {
        fi
 
        # Bring up the device.
-       device_set_up ${port}
+       device_set_up "${port}"
 
        exit ${EXIT_OK}
 }
index ed3fd42fd54fd028442eeca3c8c8069caeea7ed2..595d0d4e6d21847011adac26e9aac4609783744f 100644 (file)
@@ -283,15 +283,23 @@ function hook_port_up() {
        local zone="${1}"
        local port="${2}"
 
-       zone_port_settings_read "${zone}" "${port}" ${HOOK_PORT_SETTINGS}
-
+       # Try bringing up the port
        port_up "${port}"
 
-       # Set same MTU to device that the bridge has got
-       device_set_mtu "${port}" $(device_get_mtu "${zone}")
+       # If the port could not be brought up, we will
+       # log an error message and exit.
+       if ! device_exists "${port}"; then
+               log WARNING "Port '${port}' cannot be attached to zone '${zone}' as it does not exist"
+               exit ${EXIT_OK}
+       fi
+
+       # Read configuration values
+       zone_port_settings_read "${zone}" "${port}" ${HOOK_PORT_SETTINGS}
 
+       # Attach the port to the bridge
        bridge_attach_device "${zone}" "${port}"
 
+       # Set STP configuration
        if isset COST; then
                stp_port_set_cost "${zone}" "${port}" "${COST}"
        fi