]> git.ipfire.org Git - people/ms/network.git/commitdiff
Add support for VTI interfaces
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 21 Jul 2017 18:16:11 +0000 (20:16 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 21 Jul 2017 18:16:11 +0000 (20:16 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.device
src/functions/functions.ip-tunnel

index b33c8cd18505de4d452dd251903410af99c98e70..4c7f9788d9f25f8e9d31a2859483d7cd396287f1 100644 (file)
@@ -294,6 +294,14 @@ device_is_wireless() {
        [ -d "${SYS_CLASS_NET}/${device}/phy80211" ]
 }
 
+device_is_vti() {
+       local device=${1}
+
+       local type=$(__device_get_file ${device} type)
+
+       [ "${type}" = "768" ] && return ${EXIT_OK} || return ${EXIT_ERROR}
+}
+
 device_get_phy() {
        local device="${1}"
 
@@ -399,6 +407,9 @@ device_get_type() {
        elif device_is_phy ${device}; then
                echo "phy"
 
+       elif device_is_vti ${device}; then
+               echo "vti"
+
        else
                echo "unknown"
        fi
index 91af97f492256e7ee2eb2d47495e7954fd44212c..df59aadea2ae377783f0b1f4476727befc34144c 100644 (file)
 #                                                                             #
 ###############################################################################
 
-IP_TUNNEL_MODES="sit"
+IP_TUNNEL_MODES="sit vti"
 
 ip_tunnel_add() {
        local device=${1}
        shift
 
-       local mode="sit"
+       local mode
        local ttl
 
        local remote_address
        local local_address
 
+       local ikey
+       local okey
+
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --mode=*)
@@ -39,22 +42,45 @@ ip_tunnel_add() {
                        --ttl=*)
                                ttl="$(cli_get_val ${1})"
                                ;;
-
                        --remote-address=*)
                                remote_address="$(cli_get_val ${1})"
                                ;;
                        --local-address=*)
                                local_address="$(cli_get_val ${1})"
                                ;;
+
+                       # Keys for VTI
+                       --ikey=*)
+                               ikey="$(cli_get_val ${1})"
+                               ;;
+                       --okey=*)
+                               okey="$(cli_get_val ${1})"
+                               ;;
                esac
                shift
        done
 
-       assert isset mode
-       assert isoneof mode ${IP_TUNNEL_MODES}
+       if ! isset mode; then
+               error "--mode= is not set. Must be one of ${IP_TUNNEL_MODES}"
+               return ${EXIT_ERROR}
+       fi
+
+       if ! isoneof mode ${IP_TUNNEL_MODES}; then
+               error "Invalid mode: ${mode}"
+               return ${EXIT_ERROR}
+       fi
+
+       # ikey and okey must be set for VTI devices
+       if [ "${mode}" = "vti" ] && (! isset ikey || ! isset okey); then
+               error "--ikey= and --okey= must be set for VTI device"
+               return ${EXIT_ERROR}
+       fi
 
        # If TTL is set, make sure it is an integer.
-       isset ttl && assert isinteger ttl
+       if isset ttl && ! isinteger ttl; then
+               error "TTL must be an integer: ${ttl}"
+               return ${EXIT_ERROR}
+       fi
 
        assert isset local_address
 
@@ -70,12 +96,19 @@ ip_tunnel_add() {
                cmd_args="${cmd_args} remote ${remote_address}"
        fi
 
+       # Add ikey and okey for VTI devices
+       if [ "${mode}" = "vti" ]; then
+               cmd_args="${cmd_args} ikey ${ikey} okey ${okey}"
+       fi
+
        log DEBUG "Creating tunnel device '${device}' (mode=${mode})..."
 
        # Create the device.
-       cmd ip tunnel add ${device} mode ${mode} \
-               local ${local_address} ${cmd_args}
-       assert [ $? -eq 0 ]
+       if ! cmd ip tunnel add ${device} mode ${mode} \
+                       local ${local_address} ${cmd_args}; then
+               error "Could not create tunnel device ${device}"
+               return ${EXIT_ERROR}
+       fi
 }
 
 ip_tunnel_del() {