]> git.ipfire.org Git - people/stevee/network.git/commitdiff
Add function that returns a string about speed and duplex state of an interface
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 21 Dec 2014 23:00:26 +0000 (23:00 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 21 Dec 2014 23:00:26 +0000 (23:00 +0000)
src/functions/functions.device
src/network

index 600dd837c575f49016237765e357cfc69142b739..f5c150dd22cd0c120ee941a53266ce021bb16fc1 100644 (file)
@@ -797,3 +797,22 @@ function device_get_duplex() {
 
        __device_get_file ${device} duplex
 }
+
+function device_get_link_string() {
+       local device="${1}"
+       assert isset device
+
+       local s
+
+       local speed="$(device_get_speed "${device}")"
+       if isset speed; then
+               list_append s "${speed} MBit/s"
+       fi
+
+       local duplex="$(device_get_duplex "${device}")"
+       if isset duplex; then
+               list_append s "${duplex} duplex"
+       fi
+
+       print "${s}"
+}
index d6a0817ff3be746f354bf43346b331ff750fea17..1999c3d5dc62b874114805989b2c3dd2e8419647 100644 (file)
@@ -133,12 +133,10 @@ function cli_device_status() {
 
        # Print the link speed for ethernet devices.
        if device_is_up ${device} &>/dev/null; then
-               case "${type}" in
-                       ethernet)
-                               cli_print_fmt1 1 "Link" \
-                                       "$(device_get_speed ${device}) MBit/s $(device_get_duplex ${device}) duplex"
-                               ;;
-               esac
+               local link="$(device_get_link_string "${device}")"
+               if isset link; then
+                       cli_print_fmt1 1 "Link" "${link}"
+               fi
        fi
 
        cli_print_fmt1 1 "MTU"          "$(device_get_mtu ${device})"