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

index a04111e169e22124481b1242ec356a7e7a8b6598..0cd6e4ea0cf3cc74f78077c1e118d3fc9206c7ad 100644 (file)
@@ -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