[5/5] ip-tunnel: choose the correct type based on the ip protocol

Message ID 1520187899-5759-5-git-send-email-jonatan.schlag@ipfire.org
State Accepted
Commit dff38496350dd5ceef6286aa4bff2cc49fae3669
Headers
Series [1/5] ip-tunnel: add new function |

Commit Message

Jonatan Schlag March 5, 2018, 5:24 a.m. UTC
  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>
---
 src/functions/functions.ip-tunnel | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
  

Patch

diff --git a/src/functions/functions.ip-tunnel b/src/functions/functions.ip-tunnel
index 0a0c210..3baf280 100644
--- a/src/functions/functions.ip-tunnel
+++ b/src/functions/functions.ip-tunnel
@@ -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