]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/hooks/zones/bridge
Cleanup code that deletes ports/zones
[people/ms/network.git] / src / hooks / zones / bridge
index 245f4c1a21b59078421552d59c4ffb5e84d7d2a5..38b2b5f885c8aff7f50b0f28841624bf563cf02e 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,19 +132,36 @@ 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
-                               # Bring up the zone if it is enabled but not active, yet.
-                               if zone_is_enabled "${zone}" && ! zone_is_active "${zone}"; then
-                                       zone_start "${zone}"
+                       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}"
                                fi
-
-                               hook_port_up "${zone}" "${INTERFACE}"
                        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
                        ;;
@@ -268,7 +281,7 @@ hook_port_attach() {
                                PRIORITY="$(cli_get_val "${arg}")"
                                ;;
                esac
-       done <<< "$(args $@)"
+       done <<< "$(args "$@")"
 
        if ! zone_port_settings_write "${zone}" "${port}"; then
                exit ${EXIT_ERROR}
@@ -294,7 +307,7 @@ hook_port_detach() {
 }
 
 hook_port_edit() {
-       hook_port_attach $@
+       hook_port_attach "$@"
 }
 
 hook_port_up() {
@@ -310,12 +323,15 @@ hook_port_up() {
        if ! device_exists "${port}"; then
                port_create "${port}"
 
-               exit ${EXIT_OK}
+               return ${EXIT_OK}
        fi
 
        # Read configuration values
        zone_port_settings_read "${zone}" "${port}" ${HOOK_PORT_SETTINGS}
 
+       # Make sure that the port is up
+       port_up "${port}"
+
        # Attach the port to the bridge
        bridge_attach_device "${zone}" "${port}"
 
@@ -324,12 +340,11 @@ hook_port_up() {
                stp_port_set_cost "${zone}" "${port}" "${COST}"
        fi
 
-       # TODO Apply priority (#10609)
-
-       # Make sure that the port is up
-       port_up "${port}"
+       if isset PRIORITY; then
+               stp_port_set_priority "${zone}" "${port}" "${PRIORITY}"
+       fi
 
-       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() {