HOOK_SETTINGS=(
"ADDRESS"
- "PARENT_DEVICE"
+ "PARENT_PORT"
"TAG"
)
-PORT_PARENTS_VAR="PARENT"
+PORT_PARENTS_VAR="PARENT_PORT"
hook_check_settings() {
- assert isset PARENT_DEVICE
+ assert isset PARENT_PORT
assert isinteger TAG
if isset ADDRESS; then
}
hook_find_port_name() {
- assert isset PARENT_DEVICE
+ assert isset PARENT_PORT
assert isset TAG
- print "${PARENT_DEVICE}${VLAN_PORT_INTERFIX}${TAG}"
+ print "${PARENT_PORT}${VLAN_PORT_INTERFIX}${TAG}"
}
hook_parse_cmdline() {
while [ $# -gt 0 ]; do
case "${1}" in
- --parent-device=*)
- PARENT_DEVICE=$(cli_get_val "${1}")
- ;;
--address=*)
ADDRESS=$(cli_get_val "${1}")
+
+ # Validate address
+ if ! mac_is_valid "${ADDRESS}"; then
+ error "Invalid MAC address given: ${ADDRESS}"
+ return ${EXIT_CONF_ERROR}
+ fi
+ ;;
+ --port=*)
+ PARENT_PORT=$(cli_get_val "${1}")
+
+ # Check if PARENT_PORT exists
+ if ! port_exists "${PARENT_PORT}"; then
+ error "Port '${PARENT_PORT}' does not exist"
+ return ${EXIT_CONF_ERROR}
+ fi
;;
--tag=*)
TAG=$(cli_get_val "${1}")
;;
+ *)
+ error "Unknown argument '${1}'"
+ return ${EXIT_CONF_ERROR}
+ ;;
esac
shift
done
+
+ # Generate a random MAC address if none given
+ if ! isset ADDRESS; then
+ ADDRESS="$(mac_generate)"
+ fi
}
hook_create() {
device_exists "${port}" && exit ${EXIT_OK}
# Read configruation
- port_settings_read "${port}"
+ if ! port_settings_read "${port}"; then
+ return ${EXIT_ERROR}
+ fi
+
+ # Check if the parent port exists
+ if ! port_exists "${PARENT_PORT}"; then
+ error "Port '${PARENT_PORT}' does not exist"
+ return ${EXIT_ERROR}
+ fi
# Create the VLAN device
- vlan_create "${port}" "${PARENT_DEVICE}" "${TAG}" "${ADDRESS}"
+ if ! vlan_create "${port}" \
+ --address="${ADDRESS}" \
+ --parent="${PARENT_PORT}" \
+ --tag="${TAG}"; then
+ error "Could not create port: ${port}"
+ return ${EXIT_ERROR}
+ fi
- exit ${EXIT_OK}
+ return ${EXIT_OK}
}
hook_remove() {