]> git.ipfire.org Git - people/ms/network.git/commitdiff
Show driver name in device status
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 22 Sep 2018 15:33:20 +0000 (16:33 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 22 Sep 2018 15:33:20 +0000 (16:33 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.device
src/functions/functions.phy
src/functions/functions.util
src/network

index 8b31434d12fef4ac8cded765986d7b4b53fcc337..10677716f11d5195dd9b21b672c93ba8f4057338 100644 (file)
@@ -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" ]
index 6ebfbb3012e383753c01a18abf7cf6b1b84fb6c1..a4067d4ebd8a9bfc252343b1c05275231fa98a31 100644 (file)
@@ -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
index 31c163198a8c2add6e327a9a1efa6608682d8429..0201d0286d41224b6275b833319150081428837c 100644 (file)
@@ -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}
+}
index d759700f3e3e405420d2136e381d29e56e47200c..506b1e0422d1ce1184aa42ec0117c4e053b95e17 100644 (file)
@@ -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}")"