]> git.ipfire.org Git - people/ms/network.git/commitdiff
vlan: Add support for 802.1ad (QinQ)
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 3 Jun 2019 11:17:06 +0000 (13:17 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 3 Jun 2019 11:17:06 +0000 (13:17 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.vlan
src/hooks/ports/vlan

index ee2fb3400062a62c49f35b49a73f5a4b563f3e1b..fbaa34fe723df075ecbb20446fa39596812d9c86 100644 (file)
 PROC_NET_VLAN="/proc/net/vlan"
 PROC_NET_VLAN_CONFIG="${PROC_NET_VLAN}/config"
 
+VLAN_SUPPORTED_PROTOCOLS=(
+       "802.1Q"        # default
+       "802.1ad"
+)
+
 VLAN_PORT_INTERFIX="v"
 
 vlan_valid_id() {
@@ -41,6 +46,13 @@ vlan_valid_id() {
        return ${EXIT_FALSE}
 }
 
+vlan_supported_protocol() {
+       local proto="${1}"
+       assert isset proto
+
+       list_match "${proto}" "${VLAN_SUPPORTED_PROTOCOLS[@]}"
+}
+
 vlan_create() {
        local device="${1}"
        shift
@@ -50,6 +62,7 @@ vlan_create() {
        local address
        local id=1
        local parent
+       local protocol="${VLAN_SUPPORTED_PROTOCOLS[0]}"
 
        # Parse command line arguments
        while [ $# -gt 0 ]; do
@@ -63,6 +76,9 @@ vlan_create() {
                        --parent=*)
                                parent=$(cli_get_val "${1}")
                                ;;
+                       --protocol=*)
+                               protocol=$(cli_get_val "${1}")
+                               ;;
                        *)
                                error "Unrecognized argument: ${1}"
                                return ${EXIT_ERROR}
@@ -82,6 +98,12 @@ vlan_create() {
                return ${EXIT_ERROR}
        fi
 
+       # Check protocol
+       if ! vlan_supported_protocol "${protocol}"; then
+               log ERROR "Invalid protocol: ${protocol}"
+               return ${EXIT_ERROR}
+       fi
+
        # Check VLAN ID
        if ! vlan_valid_id "${id}"; then
                log ERROR "Invalid VLAN ID: ${id}"
@@ -103,7 +125,7 @@ vlan_create() {
        # Make the command
        local command=(
                ip link add link "${parent}" name "${device}"
-                       address "${address}" type vlan id "${id}"
+                       address "${address}" type vlan proto "${protocol}" id "${id}"
        )
 
        # Run the command
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