]> git.ipfire.org Git - people/stevee/network.git/blobdiff - src/functions/functions.zone
zone: Make zone_config_{read,write} behave the same as zone_port_{read,write} do
[people/stevee/network.git] / src / functions / functions.zone
index e39248c6e597ebb0466c6cbc5ad87bf7dd510119..4874f388dad7ac3584603316c32384fa4f724e21 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" $@
 }
@@ -975,25 +1008,38 @@ function zone_settings_get() {
 }
 
 function zone_config_settings_read() {
-       assert [ $# -gt 2 ]
+       assert [ $# -ge 2 ]
 
        local zone="${1}"
        local config="${2}"
        shift 2
 
+       local args
+       if [ $# -eq 0 ] && [ -n "${HOOK_CONFIG_SETTINGS}" ]; then
+               list_append args ${HOOK_CONFIG_SETTINGS}
+       else
+               list_append args $@
+       fi
+
        local path="$(zone_dir "${zone}")/configs/${config}"
-       settings_read "${path}" "$@"
+       settings_read "${path}" ${args}
 }
 
 function zone_config_settings_write() {
-       assert [ $# -gt 2 ]
+       assert [ $# -ge 2 ]
 
        local zone="${1}"
        local config="${2}"
        shift 2
 
+       local args
+       if function_exists "hook_check_config_settings"; then
+               list_append args "--check=\"hook_check_config_settings\""
+       fi
+       list_append args ${HOOK_CONFIG_SETTINGS}
+
        local path="$(zone_dir "${zone}")/configs/${config}"
-       settings_write "${path}" "$@"
+       settings_write "${path}" ${args}
 }
 
 function zone_port_settings_read() {