]> git.ipfire.org Git - people/jschlag/network.git/commitdiff
ip-tunnel: add new function
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Sun, 4 Mar 2018 18:24:55 +0000 (18:24 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 Mar 2018 20:19:22 +0000 (20:19 +0000)
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 <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.ip-tunnel

index 7bb4e3f956f01a1c1ff65cd80192c62ba1441e7d..550b0b30b444abb0904147c9f5405cd78653a25c 100644 (file)
 
 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