AM335x running Arago from TI SDK 7.0 (NFS).
Any time I connect or disconnect from an Ethernet interface, I get an update in the terminal indicating that the link was connected or disconnected. What I'd like to know is how that message is getting posted. More specifically, I want to hook into the mechanism that is posting that message so I can run my own script any time an Ethernet connection is connected or disconnected (specifically only on eth0). However I'm not finding a way to do this.
Note, I have discovered that I can use ethtool to determine the interface state. And I also found the interface in /sys/class/net/eth0 that will let me query the driver for various status info. But I don't want to poll for interface status. I want to do one of the following:
- Run a script/program when a specific network interface goes up or down and preferably only on a specific interface (eth0).
- Register to receive a signal that a network interface (preferably eth0) has changed connection state.
- Register a callback function pointer and have the OS notify my program of change of state
The simplest for my purposes is to simply have a shell script run when the Ethernet link goes up or down where arguments to the script indicate the state. However even if arguments are not passed in, I can query for the state via /sys/class/net/eth0/operstate to determine the current state. I'd just prefer an event-based execution/notification rather than a polling method.
Doing research on google, it seems using the netlink (libnl) library is how I would write a program to do this, But I'm not finding any examples on the Internet that describes doing what I'm wanting. So if anybody has suggestions, that would help out a lot.