]> git.ipfire.org Git - network.git/commitdiff
ip-tunnel: choose the correct type based on the ip protocol
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Sun, 4 Mar 2018 18:24:59 +0000 (18:24 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 Mar 2018 20:20:49 +0000 (20:20 +0000)
IPv4 and IPv6 need different types for iproute2.
So in the _add function we have to determine the mode
based on the IP protocol of the ${remote_address}.

When we change ikey and okey we have to dertermine the mode the device
have currently.

Fixes: #11431
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.ip-tunnel

index 0a0c210c0169eb061fc39e3db598f53b66791477..3baf280f03d2e729e2f003560ef6bf004cc44422 100644 (file)
@@ -150,6 +150,9 @@ ip_tunnel_add() {
                cmd_args="${cmd_args} ikey ${ikey} okey ${okey}"
        fi
 
+       # Determine the mode based on the IP protocol
+       mode=$(ip_tunnel_convert_mode_to_iproute2_mode "${mode}" "${remote_address_protocol}")
+
        log DEBUG "Creating tunnel device '${device}' (mode=${mode})..."
 
        # Create the device.
@@ -208,8 +211,16 @@ ip_tunnel_change_keys() {
                return ${EXIT_ERROR}
        fi
 
+       # Determine the device type
+       local type="$(device_tunnel_get_type ${device})"
+
+       if ! isoneof "type" vti vti6; then
+               log ERROR "Device type '${type}' is invalid"
+               return ${EXIT_ERROR}
+       fi
+
        if ! cmd ip link change dev "${device}" \
-               type vti ikey "${ikey}" okey "${okey}"; then
+               type "${type}" ikey "${ikey}" okey "${okey}"; then
                log ERROR "Could not change keys of device ${device}"
                return ${EXIT_ERROR}
        fi