OpenWrt 21.02.1 ath79/generic -- how to poll physical port status

I want to check a physical ethernet port status on GL-Inet AR300M flashed with 21.02.1 and all the methods I've tried report that eth0 always has carrier even when nothing is plugged in:

  1. ethtool eth0 says Link detected: yes
  2. /sys/class/net/eth0/carrier is always 1
  3. ip link show never says NO-CARRIER for eth0
  4. ubus call network.device status '{ "name": "eth0" }' always reports "carrier": true,
  5. swconfig dev switch0 port 0 get link always reports port:0 link:up

Full disclosure I've merged both ports into LAN and deleted WAN:

# cat /etc/config/network

config interface 'loopback'
	option device 'lo'
	option proto 'static'
	option ipaddr ''
	option netmask ''

config device
	option name 'br-lan'
	option type 'bridge'
	list ports 'eth0'
	list ports 'eth1'

config interface 'lan'
	option device 'br-lan'
	option proto 'static'
	option netmask ''
	option ipaddr ''
	option ipv6 '0'

@alzhao @jow any ideas on how I can get an actual status of eth0 on this router on 21.02?

1 Like

are you at least getting a kernel message in console when you have link up and down?

Eth0 will always be up as it is an internal interface with the embedded switch. Until your device switches to DSA, which would expose external ports as local devices, you can poll using swconfig.

The reason to check port status is normally because you need to reload a DHCP cliente, for 3xample. This package brings down the local interface when all related external ports are down and reverse the process if one of them is up. Even if that is not what you need, you can check the script code

Btw, the Port to DSA is here

1 Like

That's exactly what vendor recommended, poll port 1 on switch to determine the status of LAN port and use ethtool to determine the status of WAN port.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.