[1/5] ip-tunnel: add new function
Commit Message
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>
---
src/functions/functions.ip-tunnel | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
@@ -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