I'm creating a script for polling information about network interfaces. For this I get some data from /sysfs.

Everything went fine until I wanted to clarify all possible states of an interface (Which are they btw? I'm aware for now only about up, down and unknown). I went through /usr/src/linux/Documentation/sysfs-rules.txt and found this:

Accessing /sys/class/net/eth0/device is a bug in the application

Is there a reason for this? Could someone explain me if I'm doing something wrong by getting information from /sysfs?

I don't iterate through all interfaces in /sysfs but get all network interfaces with getifaddrs(3). Perhaps there is another method to get iface status? Thanks.


It's the device link in class directories that you aren't supposed to use. The idea is that /sys/class/net/eth0 is a symbolic link to somewhere under /sys/devices, and the device link merely links to a (grand-)*parent directory; instead of using the device link, you're supposed to walk back to a parent directory if needed.

Accessing files in /sys/class/net/eth0/ is fine.

If you're refering to the operational status found in /sys/class/net/eth0/operstate, there are a few more. The names are defined in net/core/net-sysfs.c and the constants in include/uapi/linux/if.h. They come from RFC 2863.

  • Thanks. I figures out about device link after I posted the question already, but still wanted to hear some thoughts about the rest. – UVV Aug 15 '14 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.