]> git.ipfire.org Git - people/stevee/network.git/commitdiff
hotplug: Let bridges create their ports in hotplug event
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 22 Sep 2018 12:47:44 +0000 (13:47 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 22 Sep 2018 12:47:44 +0000 (13:47 +0100)
This patch changes that all ports are being created in the
hotplug event and allows us to start bridges at any time
with ports existing or being added later.

Fixes: #11360
Signed-off-by: Arne Fitzenreiter <arne.fitzenreiter@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.hotplug
src/hooks/zones/bridge
src/udev/network-hotplug

index 8fccae4e7c6ef9f645cf4ebf02b8a262e25d9d69..f7a02ae4880f89ce17f9e8ae4d2f73ca6a3642ba 100644 (file)
@@ -70,6 +70,17 @@ hotplug_propagate_all_zones() {
        done
 }
 
+hotplug_event_interface_is_zone() {
+       hotplug_assert_in_hotplug_event
+
+       local zone="${1}"
+       assert isset zone
+
+       log DEBUG "${zone}= ${INTERFACE}?"
+
+       [ "${zone}" = "${INTERFACE}" ]
+}
+
 hotplug_event_port_is_interface() {
        hotplug_assert_in_hotplug_event
 
index 33d5378d9427de8cdc81c8c888119135aa0ba3c3..9226374110edf362a4298d489e0d60622651ef1c 100644 (file)
@@ -120,10 +120,6 @@ hook_up() {
        # set our bridges to promisc mode.
        device_set_promisc "${zone}" on
 
-       # Bring up all ports
-       zone_ports_create "${zone}"
-       zone_ports_up "${zone}"
-
        # Bring up all configurations
        zone_configs_up "${zone}"
 
@@ -136,8 +132,18 @@ hook_hotplug() {
 
        case "$(hotplug_action)" in
                add)
+                       # Attach all ports when zone is coming up
+                       if hotplug_event_interface_is_zone "${zone}"; then
+                               # Bring up all ports
+                               local port
+                               for port in $(zone_get_ports "${zone}"); do
+                                       log DEBUG "Trying to attach port ${port} to ${zone}"
+
+                                       hook_port_up "${zone}" "${port}"
+                               done
+
                        # Handle ports of this zone that have just been added
-                       if hotplug_event_interface_is_port_of_zone "${zone}"; then
+                       elif hotplug_event_interface_is_port_of_zone "${zone}"; then
                                # Attach the device if the parent bridge is up
                                if zone_is_active "${zone}"; then
                                        hook_port_up "${zone}" "${INTERFACE}"
@@ -145,8 +151,17 @@ hook_hotplug() {
                        fi
                        ;;
                remove)
+                       if hotplug_event_interface_is_zone "${zone}"; then
+                               # Bring down/destroy all ports
+                               local port
+                               for port in $(zone_get_ports "${zone}"); do
+                                       log DEBUG "Trying to detach port ${port} from ${zone}"
+
+                                       hook_port_down "${zone}" "${port}"
+                               done
+
                        # Handle ports of this zone that have just been removed
-                       if hotplug_event_interface_is_port_of_zone "${zone}"; then
+                       elif hotplug_event_interface_is_port_of_zone "${zone}"; then
                                hook_port_down "${zone}" "${INTERFACE}"
                        fi
                        ;;
@@ -308,7 +323,7 @@ hook_port_up() {
        if ! device_exists "${port}"; then
                port_create "${port}"
 
-               exit ${EXIT_OK}
+               return ${EXIT_OK}
        fi
 
        # Read configuration values
@@ -329,7 +344,7 @@ hook_port_up() {
        # Make sure that the port is up
        port_up "${port}"
 
-       exit ${EXIT_OK}
+       return ${EXIT_OK}
 }
 
 hook_port_down() {
@@ -344,7 +359,7 @@ hook_port_down() {
                port_down "${port}"
        fi
 
-       exit ${EXIT_OK}
+       return ${EXIT_OK}
 }
 
 hook_port_status() {
index af6c0df90e5173a6194488345f8e5a602a38a4a7..2a2d3e1fdc95720cea6b0c9ad0ce52b68667c08c 100644 (file)
@@ -63,12 +63,8 @@ case "${SUBSYSTEM}" in
        net)
                assert isset INTERFACE
 
-               # Don't do anything for zones
-               if zone_exists "${INTERFACE}"; then
-                       exit ${EXIT_OK}
-
                # Stop processing rules for the loopback device
-               elif device_is_loopback ${INTERFACE}; then
+               if device_is_loopback ${INTERFACE}; then
                        exit ${EXIT_OK}
 
                # Stop processing rules for wireless monitoring devices
@@ -77,7 +73,7 @@ case "${SUBSYSTEM}" in
                fi
 
                # Did we get called for a non-existing interface?
-               if ! port_exists "${INTERFACE}"; then
+               if ! zone_exists "${INTERFACE}" && ! port_exists "${INTERFACE}"; then
                        case "${ACTION}" in
                                add)
                                        log WARNING "Got to hotplug event for a port which does not exist: ${INTERFACE}"