]> git.ipfire.org Git - people/stevee/network.git/commitdiff
zone: Fix immediate attachment of ethernet ports to a bridge
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 12 Apr 2015 18:22:46 +0000 (18:22 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 12 Apr 2015 18:22:46 +0000 (18:22 +0000)
src/functions/functions.ports
src/functions/functions.zone

index cfe9b50e6d8e203ca19e7a40349a891bd768b59e..1edd1c30b24c11579e0a866282abd3e7d46d71ce 100644 (file)
@@ -151,6 +151,10 @@ function port_is_attached() {
        return ${EXIT_ERROR}
 }
 
+function port_is_up() {
+       device_is_up $@
+}
+
 function port_new() {
        #local port=${1}
        #shift
index e39248c6e597ebb0466c6cbc5ad87bf7dd510119..6373ec7cea1e39ca3f6ee25dd5b9c00253f4cc4c 100644 (file)
@@ -651,9 +651,7 @@ function zone_port_attach() {
                        log INFO "${port} has been attached to ${zone}"
 
                        # Automatically connect the port
-                       if zone_is_active "${zone}"; then
-                               zone_port_create "${zone}" "${port}"
-                       fi
+                       zone_port_start "${zone}" "${port}"
                        ;;
                *)
                        log CRITICAL "${port} could not be attached to ${zone}"
@@ -716,9 +714,7 @@ function zone_port_detach() {
                        log INFO "${port} has been detached from ${zone}"
 
                        # Bring down the port if needed
-                       if zone_is_active "${zone}"; then
-                               zone_port_remove "${zone}" "${port}"
-                       fi
+                       zone_port_stop "${zone}" "${port}"
                        ;;
                *)
                        log CRITICAL "${port} could not be detached from ${zone}"
@@ -763,6 +759,43 @@ function zone_port_down() {
        zone_port_cmd "port_down" $@
 }
 
+# The next two functions automagically bring up and down
+# port that are attached to a bridge or similar.
+# The problem that is tried to overcome here is that there
+# are ports which exist all the time (like ethernet ports)
+# and therefore do not dispatch a hotplug event when
+# port_create is called.
+
+function zone_port_start() {
+       local zone="${1}"
+       local port="${2}"
+
+       if zone_is_active "${zone}"; then
+               if device_exists "${port}"; then
+                       zone_port_up "${zone}" "${port}"
+                       return ${?}
+               else
+                       zone_port_create "${zone}" "${port}"
+                       return ${?}
+               fi
+       fi
+
+       return ${EXIT_OK}
+}
+
+function zone_port_stop() {
+       local zone="${1}"
+       local port="${2}"
+
+       # Shut down the port if necessary
+       if zone_is_active "${zone}" && port_is_up "${port}"; then
+               zone_port_down "${zone}" "${port}"
+       fi
+
+       # Remove the port
+       zone_port_remove "${zone}" "${port}"
+}
+
 function zone_port_status() {
        zone_port_cmd "port_status" $@
 }