HOOK_MANPAGE="network-config-ipv4-static"
-HOOK_SETTINGS="HOOK ADDRESS PREFIX GATEWAY"
+HOOK_CONFIG_SETTINGS="HOOK ADDRESS PREFIX GATEWAY"
-hook_check() {
+hook_check_config_settings() {
assert isset ADDRESS
assert isinteger PREFIX
fi
}
-hook_create() {
- 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}")"
exit ${EXIT_CONF_ERROR}
;;
esac
- done <<< "$(args $@)"
+ done <<< "$(args "$@")"
if ! isset ADDRESS; then
error "You need to provide an IPv4 address"
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
+}
- # XXX maybe we can add some hashing to identify a configuration again
- zone_config_settings_write "${zone}" "${HOOK}.$(uuid)" ${HOOK_SETTINGS}
+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
+
+ zone_config_settings_write "${zone}" "${HOOK}"
exit ${EXIT_OK}
}
exit ${EXIT_ERROR}
fi
- zone_config_settings_read "${zone}" "${config}" ${HOOK_SETTINGS}
+ zone_config_settings_read "${zone}" "${config}"
ip_address_add ${zone} ${ADDRESS}/${PREFIX}
# Save configuration
- routing_db_set ${zone} ipv4 type "${HOOK}"
- routing_db_set ${zone} ipv4 local-ip-address "${ADDRESS}/${PREFIX}"
- routing_db_set ${zone} ipv4 remote-ip-address "${GATEWAY}"
- routing_db_set ${zone} ipv4 active 1
+ db_set "${zone}/ipv4/type" "${HOOK}"
+ db_set "${zone}/ipv4/local-ip-address" "${ADDRESS}/${PREFIX}"
+ db_set "${zone}/ipv4/remote-ip-address" "${GATEWAY}"
+ db_set "${zone}/ipv4/active" 1
routing_update ${zone} ipv4
routing_default_update
error "Zone '${zone}' doesn't exist."
exit ${EXIT_ERROR}
fi
-
- zone_config_settings_read "${zone}" "${config}" ${HOOK_SETTINGS}
+
+ # Remove routing information from database.
+ db_delete "${zone}/ipv4"
+
+ zone_config_settings_read "${zone}" "${config}"
ip_address_del ${zone} ${ADDRESS}/${PREFIX}
exit ${EXIT_ERROR}
fi
- zone_config_settings_read "${zone}" "${config}" ${HOOK_SETTINGS}
+ zone_config_settings_read "${zone}" "${config}"
local status
if zone_has_ip ${zone} ${ADDRESS}/${PREFIX}; then
exit ${EXIT_OK}
}
-