6

I wanted to see which driver was associated with some of the network interfaces listed by ip link. My first thought was to find the network interfaces in /dev and look at the device major and minor numbers to determine the associated driver. However, network interfaces don't appear under /dev.

I'm have a feeling I'm misunderstanding something fundamental about the Linux network stack (perhaps because multiple kernel modules can be involved because of netfilter/iptables/tc), so please address this if so. My naive questions are:

  • How do you determine which driver performs I/O for a particular network interface?
  • Why don't Linux network interfaces appear in /dev?

1 Answers1

11

I'm never quite sure if spelunking in sysfs is the best way to do things (am I supposed to use udevadm?), but at least it's discoverable

$ DEV=p8p1
$ readlink /sys/class/net/$DEV/device/driver
../../../../bus/pci/drivers/tg3

It won't work for devices like lo which are "virtual" (/sys/devices/virtual/). They don't have the link to an underlying device (e.g. on the pci bus), so you can't query the driver as above.


There's also a linux-specific tool ethtool. It uses an eponymous socket ioctl instead of reading sysfs. The ioctl is linux-specific; standard unix APIs don't tell you what the driver is called. ethtool gives the same result (it doesn't work for lo and the extra information is pointless).

$ ethtool -i p8p1
driver: tg3
version: 3.137
firmware-version: sb
bus-info: 0000:04:00.0
supports-statistics: yes
supports-test: yes
supports-eeprom-access: no
supports-register-dump: yes
supports-priv-flags: no
sourcejedi
  • 50,249