]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/hooks/ports/vlan
Convert HOOK_SETTINGS into an array
[people/ms/network.git] / src / hooks / ports / vlan
index 5457c54445f86565786297a6a36ef9ffac002906..e9aa5454848dc2e2ece6b8f97ab31954a2d0e54e 100644 (file)
 
 . /usr/lib/network/header-port
 
-HOOK_SETTINGS="HOOK ADDRESS PARENT_DEVICE TAG"
+HOOK_SETTINGS=(
+       "ADDRESS"
+       "PARENT_DEVICE"
+       "TAG"
+)
 
 PORT_PARENTS_VAR="PARENT"
 
-function hook_check() {
+hook_check_settings() {
        assert isset PARENT_DEVICE
        assert isinteger TAG
 
@@ -47,17 +51,17 @@ function hook_check() {
        done
 }
 
-function hook_create() {
+hook_new() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --parent-device=*)
-                               PARENT_DEVICE=$(cli_get_val ${1})
+                               PARENT_DEVICE=$(cli_get_val "${1}")
                                ;;
                        --address=*)
-                               ADDRESS=$(cli_get_val ${1})
+                               ADDRESS=$(cli_get_val "${1}")
                                ;;
                        --tag=*)
-                               TAG=$(cli_get_val ${1})
+                               TAG=$(cli_get_val "${1}")
                                ;;
                        *)
                                warning "Unknown argument '${1}'"
@@ -68,22 +72,22 @@ function hook_create() {
 
        local port="${PARENT_DEVICE}${VLAN_PORT_INTERFIX}${TAG}"
 
-       port_settings_write "${port}" ${HOOK_SETTINGS}
+       port_settings_write "${port}" ${HOOK_SETTINGS[*]}
 
        exit ${EXIT_OK}
 }
 
-function hook_edit() {
+hook_edit() {
        local port=${1}
        assert isset port
        shift
 
-       port_settings_read "${port}" ${HOOK_SETTINGS}
+       port_settings_read "${port}" ${HOOK_SETTINGS[*]}
 
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --address=*)
-                               ADDRESS=$(cli_get_val ${1})
+                               ADDRESS=$(cli_get_val "${1}")
                                ;;
                        *)
                                warning "Unknown argument '${1}'"
@@ -92,42 +96,33 @@ function hook_edit() {
                shift
        done
 
-       port_settings_write "${port}" ${HOOK_SETTINGS}
+       port_settings_write "${port}" ${HOOK_SETTINGS[*]}
 
        exit ${EXIT_OK} 
 }
 
-function hook_up() {
-       local port=${1}
+hook_create() {
+       local port="${1}"
        assert isset port
 
-       if ! device_exists ${port}; then
-               # Read configuration file.
-               port_settings_read "${port}" ${HOOK_SETTINGS}
+       device_exists "${port}" && exit ${EXIT_OK}
 
-               vlan_create ${port} ${PARENT_DEVICE} ${TAG} ${ADDRESS}
-       fi
+       # Read configruation
+       port_settings_read "${port}" ${HOOK_SETTINGS[*]}
 
-       # Bring up the device.
-       device_set_up ${port}
+       # Create the VLAN device
+       vlan_create "${port}" "${PARENT_DEVICE}" "${TAG}" "${ADDRESS}"
 
        exit ${EXIT_OK}
 }
 
-function hook_down() {
-       local port=${1}
+hook_remove() {
+       local port="${1}"
        assert isset port
 
-       # Exit, if the port does not exist.
-       if ! device_exists ${port}; then
-               exit ${EXIT_OK}
+       if device_exists "${port}"; then
+               vlan_remove "${port}"
        fi
 
-       # Tear down the port.
-       device_set_down ${port}
-
-       # Remove the port.
-       vlan_remove ${port}
-
        exit ${EXIT_OK}
 }