From: Michael Tremer Date: Sat, 6 Sep 2014 11:51:10 +0000 (+0200) Subject: bridge: Simplify the hook and make it more robust against missing ports X-Git-Tag: 007~83 X-Git-Url: http://git.ipfire.org/?p=people%2Fms%2Fnetwork.git;a=commitdiff_plain;h=3ee5ccb1733c162bc927302337675127813b085d bridge: Simplify the hook and make it more robust against missing ports --- diff --git a/src/functions/functions.bridge b/src/functions/functions.bridge index d5f4ad10..3f14e387 100644 --- a/src/functions/functions.bridge +++ b/src/functions/functions.bridge @@ -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=$? diff --git a/src/functions/functions.device b/src/functions/functions.device index 5890ff9a..4f47b7cd 100644 --- a/src/functions/functions.device +++ b/src/functions/functions.device @@ -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} diff --git a/src/hooks/ports/ethernet b/src/hooks/ports/ethernet index 35cc8eb3..d0288466 100644 --- a/src/hooks/ports/ethernet +++ b/src/hooks/ports/ethernet @@ -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} } diff --git a/src/hooks/zones/bridge b/src/hooks/zones/bridge index ed3fd42f..595d0d4e 100644 --- a/src/hooks/zones/bridge +++ b/src/hooks/zones/bridge @@ -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