Skip to content

Conversation

@stklcode
Copy link
Contributor

@stklcode stklcode commented Dec 21, 2025

General information

ethtool is not default on most OpenWrt targets and these devices are typically found in networking environments, so missing interface speed is not the desired behavior.

My personal preference would be omitting ethtool completely here and only use the sysfs approach (see last paragraph).

Bug reports

On OpenWrt devices (way back, at least current versions 24.10, 25.12-rc, snapshot) the Checkmk agent scripts only reports interface speed, duplex and negotiation, if ethtool is in the executable path. This is typically not the case on many devices.

Hence interface speed is always "unknown" while this information is likely of interest on a network device like a switch, router or access point.

Proposed changes

Adapt fallback from Linux agent (a7d348e) and extract speed from sysfs (/sys/class/net/*) if ethtool is not available.

This will only provide the speed information - which is the only piece of information that is processed by default AFAIK.

Output Diff (DSA based device):

show
 [lo]
-        Link detected: yes
Address: 00:00:00:00:00:00
 [eth0]
-        Speed: Unknown!
-        Duplex: Half
-        Auto-negotiation: off
-        Link detected: no
 Address: aa:aa:aa:aa:aa:aa
 [eth1]
-        Speed: 10000Mb/s
+Speed: 10000Mb/s
-        Duplex: Full
-        Auto-negotiation: on
-        Link detected: yes
 Address: aa:aa:aa:aa:aa:ab
 [eth2]
-        Speed: 2500Mb/s
+Speed: 2500Mb/s
-        Duplex: Full
-        Auto-negotiation: on
-        Link detected: yes
 Address: aa:aa:aa:aa:aa:ac
 [lan0]
-        Speed: 10000Mb/s
+Speed: 10000Mb/s
-        Duplex: Full
-        Auto-negotiation: on
-        Link detected: yes
 Address: aa:aa:aa:aa:aa:ab
 [lan1]
-        Speed: 1000Mb/s
+Speed: 10000Mb/s
-        Duplex: Full
-        Auto-negotiation: on
-        Link detected: yes
 Address: aa:aa:aa:aa:aa:ab

Output Diff (swconfig based device):

show
 [lo]
-	Link detected: yes
 Address: 00:00:00:00:00:00
 [eth0]
-	Speed: 1000Mb/s
Speed: 1000Mb/s
-	Duplex: Full
-	Auto-negotiation: on
-	Link detected: yes
 Address: bb:bb:bb:bb:bb:bb
 [br-lan]
-	Speed: 1000Mb/s
+Speed: 1000Mb/s
-	Duplex: Unknown! (255)
-	Auto-negotiation: off
-	Link detected: yes
 Address: bb:bb:bb:bb:bb:bb
 [eth0.1]
-	Speed: 1000Mb/s
+Speed: 1000Mb/s
-	Duplex: Full
-	Auto-negotiation: on
-	Link detected: yes
 Address: bb:bb:bb:bb:bb:bb
 [eth0.3]
-	Speed: 1000Mb/s
+Speed: 1000Mb/s
-	Duplex: Full
-	Auto-negotiation: on
-	Link detected: yes
 Address: bb:bb:bb:bb:bb:bb

Alternative, more sophisticated approach that also detects status and duplex:

            echo "[${eth}]"
            speed=$(cat "/sys/class/net/${eth}/speed" 2>/dev/null || echo 'Unknown!')
            [ "${speed}" != 'Unknown!' ] && speed="${speed}Mb/s"
            duplex=$(cat "/sys/class/net/${eth}/duplex" 2>/dev/null || echo 'Unknown!')
            [ "$(cat "/sys/class/net/${eth}/carrier" 2>/dev/null || echo "0")" = "1" ] && link="yes" || link="no"
            echo "  Speed: ${speed}"
            echo "  Duplex: ${duplex}"
            echo "  Link detected: ${link}"
            echo "  Address: $(cat "/sys/class/net/${eth}/address")"
Example output
[lo]
  Link detected: yes
  Address: 00:00:00:00:00:00
[eth0]
  Link detected: no
  Address: aa:aa:aa:aa:aa:aa
[eth1]
  Speed: 10000Mb/s
  Duplex: full
  Link detected: yes
  Address: aa:aa:aa:aa:aa:ab
[eth2]
  Speed: 2500Mb/s
  Duplex: full
  Link detected: yes
  Address: aa:aa:aa:aa:aa:ac
[lan0]
  Speed: 10000Mb/s
  Duplex: full
  Link detected: yes
  Address: aa:aa:aa:aa:aa:ab
[lan1]
  Speed: 1000Mb/s
  Duplex: full
  Link detected: yes
  Address: aa:aa:aa:aa:aa:ab

ethtool is not default on most OpenWrt targets and these devices are
typically found in networking environments, so missing interface speed
is not the desired behavior.

Adapt fallback from Linux agent and extract speed from sysfs if ethtool
is not available.
@stklcode stklcode changed the title OpenWrt agent: get if speed from sysfs if ethtool is missing OpenWrt agent: get interface speed from sysfs if ethtool is missing Dec 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants