From: Michael Tremer Date: Sun, 21 Dec 2014 23:00:26 +0000 (+0000) Subject: Add function that returns a string about speed and duplex state of an interface X-Git-Tag: 007~62 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=657540d8c79f6811cc99b887cd40374b2578fd4c;p=network.git Add function that returns a string about speed and duplex state of an interface --- diff --git a/src/functions/functions.device b/src/functions/functions.device index 600dd837..f5c150dd 100644 --- a/src/functions/functions.device +++ b/src/functions/functions.device @@ -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}" +} diff --git a/src/network b/src/network index d6a0817f..1999c3d5 100644 --- a/src/network +++ b/src/network @@ -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})"