From: Jonatan Schlag Date: Sun, 4 Mar 2018 18:24:57 +0000 (+0000) Subject: device: add new function device_tunnel_get_type() X-Git-Tag: 010~147 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e173e612cc54378ad7059ae9e61dbdee1fdb07b7;p=network.git device: add new function device_tunnel_get_type() 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 Signed-off-by: Michael Tremer --- diff --git a/src/functions/functions.device b/src/functions/functions.device index a04111e1..0cd6e4ea 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