]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/hooks/ports/vlan
vlan: Add support for 802.1ad (QinQ)
[people/ms/network.git] / src / hooks / ports / vlan
index 7f99dbcdcf421a89b684515fd3b884baeb7b215d..af563eed4bfa7b3ce9df31dd2c555411dba4de4b 100644 (file)
@@ -25,14 +25,21 @@ HOOK_SETTINGS=(
        "ADDRESS"
        "ID"
        "PARENT_PORT"
+       "PROTOCOL"
 )
 
+# Set the default to 802.1Q
+DEFAULT_PROTOCOL="${VLAN_SUPPORTED_PROTOCOLS[0]}"
+
 PORT_PARENTS_VAR="PARENT_PORT"
 
 hook_check_settings() {
        assert ismac ADDRESS
        assert isset PARENT_PORT
 
+       assert isset PROTOCOL
+       assert vlan_supported_protocol "${PROTOCOL}"
+
        assert isinteger ID
        assert vlan_valid_id "${ID}"
 }
@@ -74,6 +81,16 @@ hook_parse_cmdline() {
                                        return ${EXIT_CONF_ERROR}
                                fi
                                ;;
+                       --protocol=*)
+                               PROTOCOL="$(cli_get_val "${1}")"
+
+                               # Check if PROTOCOL is supported
+                               if ! vlan_supported_protocol "${PROTOCOL}"; then
+                                       error "Protocol '${PROTOCOL}' is not supported"
+                                       error "Choose one of ${VLAN_SUPPORTED_PROTOCOLS[*]}"
+                                       return ${EXIT_CONF_ERROR}
+                               fi
+                               ;;
                        *)
                                error "Unknown argument '${1}'"
                                return ${EXIT_CONF_ERROR}
@@ -114,8 +131,9 @@ hook_create() {
        # Create the VLAN device
        if ! vlan_create "${port}" \
                        --address="${ADDRESS}" \
-                       --id="${id}" \
-                       --parent="${PARENT_PORT}"; then
+                       --id="${ID}" \
+                       --parent="${PARENT_PORT}" \
+                       --protocol="${PROTOCOL}"; then
                error "Could not create port: ${port}"
                return ${EXIT_ERROR}
        fi