]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/hooks/ports/vlan
vlan: Rename tag to id
[people/ms/network.git] / src / hooks / ports / vlan
index f19eda493aaaf2910a6b87de198923dcb3e931fb..97b69851742ea56c8cc9574a197d4f21e83395c4 100644 (file)
 
 HOOK_SETTINGS=(
        "ADDRESS"
+       "ID"
        "PARENT_PORT"
-       "TAG"
 )
 
 PORT_PARENTS_VAR="PARENT_PORT"
 
 hook_check_settings() {
        assert isset PARENT_PORT
-       assert isinteger TAG
+       assert isinteger ID
 
        if isset ADDRESS; then
                assert ismac ADDRESS
        fi
 
-       if [ ${TAG} -gt 4096 ]; then
-               error "TAG is greater than 4096."
+       if [ ${ID} -gt 4096 ]; then
+               error "ID is greater than 4096."
                exit ${EXIT_ERROR}
        fi
 
        local reserved
        for reserved in 0 4095; do
-               if [ "${TAG}" = "${reserved}" ]; then
-                       error "TAG=${reserved} is reserved."
+               if [ "${ID}" = "${reserved}" ]; then
+                       error "ID=${reserved} is reserved."
                        exit ${EXIT_ERROR}
                fi
        done
 }
 
 hook_find_port_name() {
+       assert isset ID
        assert isset PARENT_PORT
-       assert isset TAG
 
-       print "${PARENT_PORT}${VLAN_PORT_INTERFIX}${TAG}"
+       print "${PARENT_PORT}${VLAN_PORT_INTERFIX}${ID}"
 }
 
 hook_parse_cmdline() {
@@ -70,6 +70,9 @@ hook_parse_cmdline() {
                                        return ${EXIT_CONF_ERROR}
                                fi
                                ;;
+                       --id=*)
+                               ID=$(cli_get_val "${1}")
+                               ;;
                        --port=*)
                                PARENT_PORT=$(cli_get_val "${1}")
 
@@ -79,9 +82,6 @@ hook_parse_cmdline() {
                                        return ${EXIT_CONF_ERROR}
                                fi
                                ;;
-                       --tag=*)
-                               TAG=$(cli_get_val "${1}")
-                               ;;
                        *)
                                error "Unknown argument '${1}'"
                                return ${EXIT_CONF_ERROR}
@@ -103,12 +103,32 @@ 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 partent port first
+       if ! port_create "${PARENT_PORT}"; then
+               error "Could not bring up parent port: ${PARENT_PORT}"
+               return ${EXIT_ERROR}
+       fi
 
        # Create the VLAN device
-       vlan_create "${port}" "${PARENT_PORT}" "${TAG}" "${ADDRESS}"
+       if ! vlan_create "${port}" \
+                       --address="${ADDRESS}" \
+                       --id="${id}" \
+                       --parent="${PARENT_PORT}"; then
+               error "Could not create port: ${port}"
+               return ${EXIT_ERROR}
+       fi
 
-       exit ${EXIT_OK}
+       return ${EXIT_OK}
 }
 
 hook_remove() {