]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/hooks/configs/ipv4-static
config hook: prevent two hooks with the same settings
[people/ms/network.git] / src / hooks / configs / ipv4-static
index 72b748c777054c232436981b0de765d813f75b3f..ef74991ec44de20def2a80d3956ce41481bb3029 100644 (file)
@@ -35,12 +35,9 @@ hook_check_config_settings() {
        fi
 }
 
-hook_new() {
-       local zone="${1}"
-       assert zone_exists "${zone}"
-       shift
-
+hook_parse_cmdline() {
        local arg
+
        while read -r arg; do
                local key="$(cli_get_key "${arg}")"
                local val="$(cli_get_val "${arg}")"
@@ -102,12 +99,28 @@ hook_new() {
                exit ${EXIT_CONF_ERROR}
        fi
 
+       if zone_config_check_same_setting "${zone}" "ipv4-static" "ADDRESS" "${ADDRESS}"; then
+               error "An ipv4-static config with the same IPv4 address is already configured"
+               exit ${EXIT_CONF_ERROR}
+       fi
+
        if ! isset GATEWAY && zone_is_nonlocal "${zone}"; then
                warning "You did not configure a gateway for a non-local zone"
        fi
+}
+
+hook_new() {
+       local zone="${1}"
+       shift
+
+       assert zone_exists "${zone}"
+
+       if ! hook_parse_cmdline $@; then
+               # Return an error if the parsing of the cmd line fails
+               return ${EXIT_ERROR}
+       fi
 
-       # XXX maybe we can add some hashing to identify a configuration again
-       zone_config_settings_write "${zone}" "${HOOK}.$(uuid)"
+       zone_config_settings_write "${zone}" "${HOOK}"
 
        exit ${EXIT_OK}
 }
@@ -147,7 +160,10 @@ hook_down() {
                error "Zone '${zone}' doesn't exist."
                exit ${EXIT_ERROR}
        fi
-       
+
+       # Remove routing information from database.
+       db_delete "${zone}/ipv4"
+
        zone_config_settings_read "${zone}" "${config}"
 
        ip_address_del ${zone} ${ADDRESS}/${PREFIX}