From 4ad5981f1fc75e51d4648f3d7b8dc6e7fad47a7d Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 22 Sep 2018 16:33:20 +0100 Subject: [PATCH] Show driver name in device status Signed-off-by: Michael Tremer --- src/functions/functions.device | 7 +++++++ src/functions/functions.phy | 7 +++++++ src/functions/functions.util | 15 +++++++++++++++ src/network | 13 +++++++++++++ 4 files changed, 42 insertions(+) diff --git a/src/functions/functions.device b/src/functions/functions.device index 8b31434d..10677716 100644 --- a/src/functions/functions.device +++ b/src/functions/functions.device @@ -150,6 +150,13 @@ device_get_ifindex() { print "$(<${path})" } +device_get_driver() { + local device="${1}" + assert isset device + + get_driver_from_path "${SYS_CLASS_NET}/${device}/device/driver/module" +} + # Check if the device is a bonding device device_is_bonding() { [ -d "/sys/class/net/${1}/bonding" ] diff --git a/src/functions/functions.phy b/src/functions/functions.phy index 6ebfbb30..a4067d4e 100644 --- a/src/functions/functions.phy +++ b/src/functions/functions.phy @@ -85,6 +85,13 @@ phy_get_address() { print "$(<${path})" } +phy_get_driver() { + local phy="${1}" + assert isset phy + + get_driver_from_path "$(phy_dir "${phy}")/device/driver/module" +} + phy_get_devices() { local phy="${1}" assert isset phy diff --git a/src/functions/functions.util b/src/functions/functions.util index 31c16319..0201d028 100644 --- a/src/functions/functions.util +++ b/src/functions/functions.util @@ -884,3 +884,18 @@ normalize() { tr -sc [:alnum:] "-" < <(printf "%s" "${string,,}") } + +get_driver_from_path() { + local path="${1}" + + if file_exists "${path}"; then + # Resolve symlink + local driver="$(readlink "${path}")" + + # Print module name + basename "${driver}" + return ${EXIT_OK} + fi + + return ${EXIT_ERROR} +} diff --git a/src/network b/src/network index d759700f..506b1e04 100644 --- a/src/network +++ b/src/network @@ -148,6 +148,12 @@ cli_device_status() { cli_print_fmt1 1 "Status" "${status}" cli_print_fmt1 1 "Type" "${type}" + # Print the driver name + local driver="$(device_get_driver "${device}")" + if isset driver; then + cli_print_fmt1 1 "Driver" "${driver}" + fi + # Ethernet-compatible? device_is_ethernet_compatible "${device}" &>/dev/null cli_print_fmt1 1 "Ethernet-compatible" "$(cli_print_bool $?)" @@ -251,6 +257,13 @@ cli_device_status_phy() { local address="$(phy_get_address "${phy}")" cli_print_fmt1 1 "Address" "${address}" + + # Show kernel module + local driver="$(phy_get_driver "${phy}")" + if isset driver; then + cli_print_fmt1 1 "Driver" "${driver}" + fi + cli_space local devices="$(phy_get_devices "${phy}")" -- 2.47.2