0

I was wondering if linux has some sort of interface to detect ethernet port state changes via /sys or some other way that is event driven.

What I mean by state changes is DISCONNECTED / 10mbit / 100mbit / etc.

We could just pool the status of the port every X ms, but I was hoping on using inotify to watch for something that changes on the filesystem and trigger our action based on that.

We are actually most interested in changes from 10mbit to 1gbit. So having something that only triggers on connected / disconnected would not be sufficient.

Any ideas?

anonymous-one
  • 1,018
  • 7
  • 27
  • 43
  • If it was just connection, I think there is both a dbus event and a systemd event. But if you want speed, I'm not sure... I poll the speed on one of my systems using ethtool and grep about once every 2-3 minutes. – user10489 Apr 02 '22 at 21:44
  • Thanks for the pointer... I need something more real time than 2-3 minutes... I'm debating watching dmesg and just parsing the log entry out of there if a match hits. Looks like this will probably be the solution I end up using. – anonymous-one Apr 03 '22 at 22:04
  • If a carrier down/up event always precedes a speed change, you just have to wait for such even (`ip monitor link dev eth0` or dbus, NM, systemd...) and then poll the speed. – A.B Apr 03 '22 at 22:05

0 Answers0