From: Jonatan Schlag Date: Sun, 4 Mar 2018 18:24:55 +0000 (+0000) Subject: ip-tunnel: add new function X-Git-Tag: 010~149 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=376629dceea324fb713e957fabe57e3d69ca4c3b;p=network.git ip-tunnel: add new function To be undependent from the IP protocol we use, when we use tunnel modes in our code, this function converts the modes to the modes the iproute2 tool uses which often depend on the IP protocol version. Signed-off-by: Jonatan Schlag Signed-off-by: Michael Tremer --- diff --git a/src/functions/functions.ip-tunnel b/src/functions/functions.ip-tunnel index 7bb4e3f9..550b0b30 100644 --- a/src/functions/functions.ip-tunnel +++ b/src/functions/functions.ip-tunnel @@ -21,6 +21,34 @@ IP_TUNNEL_MODES="gre sit vti" +# This function converts our modes into the type +# the iproute2 tool uses +ip_tunnel_convert_mode_to_iproute2_mode() { + local mode=${1} + local protocol=${2} + + if ! isset mode || ! isset protocol; then + log ERROR "Did not get mode and/or protocol" + return ${EXIT_ERROR} + fi + + if [[ "${protocol}" = "ipv4" ]]; then + # When we use IPv4 we can use our modes + echo "${mode}" + fi + + if [[ "${protocol}" = "ipv6" ]]; then + # When we use IPv6 we have to convert + case "${mode}" in + "vti") + echo "vti6" + ;; + "gre") + echo "ip6gre" + esac + fi +} + ip_tunnel_add() { local device=${1} shift