[3/5] device: add new function device_tunnel_get_type()

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

Commit Message

Jonatan Schlag March 5, 2018, 5:24 a.m. UTC
  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(+)
  

Patch

diff --git a/src/functions/functions.device b/src/functions/functions.device
index a04111e..0cd6e4e 100644
--- a/src/functions/functions.device
+++ b/src/functions/functions.device
@@ -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