[3/5] device: add new function device_tunnel_get_type()
 
Commit Message
  
  
If we already know that the device must be a ip-tunnel device
we can save time when we check just for the types
a ip-tunnel device can have.
To avoid code duplication we call this function from device_get_type()
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
 src/functions/functions.device | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
  
 
  
@@ -396,9 +396,27 @@  device_get_type() {
 	elif device_is_phy ${device}; then
 		echo "phy"
 
+	else
+		echo "$(device_tunnel_get_type "${device}")"
+	fi
+}
+
+# This function just checks the types a ip-tunnel device usually have
+# so when we know that the device is an ip-tunnel device we save time
+device_tunnel_get_type() {
+	local device=${1}
+
+	# If the device does not exist (happens on udev remove events),
+	# we do not bother to run all checks.
+	if ! device_exists "${device}"; then
+		echo "unknown"
+
 	elif device_is_vti ${device}; then
 		echo "vti"
 
+	elif device_is_vti6 ${device}; then
+		echo "vti6"
+
 	else
 		echo "unknown"
 	fi