]> git.ipfire.org Git - people/stevee/network.git/blobdiff - functions.zone
Don't use connection tracking for loopback traffic.
[people/stevee/network.git] / functions.zone
index 3cac124b83175c0e735394fafee768f2122c96d6..3a5c60fb75e59282f3195bcae646c2a78672e280 100644 (file)
 function zone_dir() {
        local zone=${1}
 
-       #assert isset zone
-
-       echo "${ZONE_DIR}/zones/${zone}"
+       echo "${NETWORK_ZONE_DIR}/zones/${zone}"
 }
 
 function zone_exists() {
        local zone=${1}
-
        assert isset zone
 
        [ -d "$(zone_dir ${zone})" ]
@@ -49,7 +46,8 @@ function zone_match() {
 function zone_name_is_valid() {
        local zone=${1}
 
-       assert isset zone
+       # Don't accept empty strings.
+       [ -z "${zone}" ] && return ${EXIT_FALSE}
 
        [[ ${zone} =~ $(zone_match) ]]
 }
@@ -68,7 +66,6 @@ function zone_is_nonlocal() {
 
 function zone_get_hook() {
        local zone=${1}
-
        assert isset zone
 
        config_get_hook $(zone_dir ${zone})/settings
@@ -81,7 +78,7 @@ function zone_start() {
        local zone=${1}
        assert zone_exists ${zone}
 
-       service_start "network@${zone}"
+       service_start "network@${zone}.service"
 }
 
 function zone_stop() {
@@ -91,7 +88,7 @@ function zone_stop() {
        local zone=${1}
        assert zone_exists ${zone}
 
-       service_stop "network@${zone}"
+       service_stop "network@${zone}.service"
 }
 
 function zone_create() {
@@ -125,7 +122,7 @@ function zone_create() {
        # Maybe the zone create hook did not exit correctly.
        # If this is the case we remove the created zone immediately.
        if [ "${ret}" = "${EXIT_ERROR}" ]; then
-               zone_remove ${zone}
+               zone_remove_now ${zone}
        fi
 }
 
@@ -138,6 +135,12 @@ function zone_edit() {
                return ${EXIT_ERROR}
        fi
 
+       # Check if the zone is tagged for removal.
+       if zone_has_remove_tag ${zone}; then
+               error "You cannot edit a zone that is tagged for removal."
+               return ${EXIT_ERROR}
+       fi
+
        local hook=$(config_get_hook $(zone_dir ${zone})/settings)
 
        if [ -z "${hook}" ]; then
@@ -153,16 +156,35 @@ function zone_edit() {
        hook_zone_exec ${hook} edit ${zone} $@
 }
 
+
 function zone_remove() {
        local zone=${1}
-       shift
+       assert zone_exists ${zone}
 
-       if ! zone_exists ${zone}; then
-               error "Zone '${zone}' does not exist."
-               return ${EXIT_ERROR}
-       fi
+       # Make the zone for removal.
+       touch $(zone_dir ${zone})/.remove
 
-       # XXX Tear this down here?
+       log INFO "Zone '${zone}' has been tagged for removal."
+}
+
+function zone_has_remove_tag() {
+       local zone=${1}
+       assert zone_exists ${zone}
+
+       [ -e "$(zone_dir ${zone})/.remove" ]
+}
+
+# This function will remove the given zone
+# RIGHT NOW. Use zone_remove to remove it
+# at the next status change.
+function zone_remove_now() {
+       local zone=${1}
+       assert zone_exists ${zone}
+
+       log INFO "Removing zone '${zone}' right now."
+
+       # Force the zone down.
+       zone_is_up ${zone} && zone_set_down ${zone}
 
        rm -rf $(zone_dir ${zone})
 }
@@ -176,6 +198,12 @@ function zone_up() {
                return ${EXIT_ERROR}
        fi
 
+       # Check if a zone has got the remove tag.
+       if zone_has_remove_tag ${zone}; then
+               error "Cannot bring up any zone which is to be removed."
+               return ${EXIT_ERROR}
+       fi
+
        local hook=$(config_get_hook $(zone_dir ${zone})/settings)
 
        if [ -z "${hook}" ]; then
@@ -221,6 +249,11 @@ function zone_down() {
        hook_zone_exec ${hook} down ${zone} $@
 
        zone_db ${zone} stopped
+
+       # Remove the zone, if it has got a remove tag.
+       if zone_has_remove_tag ${zone}; then
+               zone_remove_now ${zone}
+       fi
 }
 
 function zone_status() {
@@ -245,6 +278,11 @@ function zone_status() {
        fi
 
        hook_zone_exec ${hook} status ${zone} $@
+
+       # Show that the zone it to be removed soon.
+       if zone_has_remove_tag ${zone}; then
+               warning "This zone is tagged for removal."
+       fi
 }
 
 function zone_port() {
@@ -311,8 +349,6 @@ function zone_port_cmd() {
        assert isset hook_zone
        assert isset hook_port
 
-       assert hook_zone_port_exists ${hook_zone} ${hook_port}
-
        hook_zone_port_exec ${hook_zone} ${hook_port} ${cmd} ${zone} ${port} $@
 }
 
@@ -550,7 +586,6 @@ function zone_ports_cmd() {
 
        local port
        for port in $(zone_get_ports ${zone}); do
-               #zone_port_cmd ${cmd} ${zone} ${port} $@
                hook_zone_exec ${hook} ${cmd} ${zone} ${port} $@
        done
 }
@@ -574,7 +609,7 @@ function zone_configs_list() {
        for config in $(zone_dir ${zone})/configs/*; do
                [ -e "${config}" ] || continue
 
-               echo $(basename ${config})
+               basename ${config}
        done
 }
 
@@ -661,7 +696,13 @@ function zone_config_read() {
 
        assert isset zone
 
+       # Save the HOOK variable.
+       local hook="${HOOK}"
+
        config_read $(zone_file ${zone})
+
+       # Restore hook.
+       HOOK="${hook}"
 }
 
 function zone_config_write() {