libnetdevname - userspace library for mapping network device path names to kernel device names (c) 2009 Dell Inc. by Narendra K <narendra_k@dell.com> ================================================================================ What is libnetdevname? Libnetdevname is a library that maps a pathname like /dev/net/ethN to an interface name like ethN. The pathname can be a char device file like /dev/net/ethN or symbolic links to it based on MAC address (/dev/net/by-mac/xx:xx:xx:xx:xx:xx), chassis label on the motherboard etc. The library takes the pathname as an argument, "stat"s the pathname and retrieves the minor number which is the interface index. It then it maps this ifindex to a ethN name by making a netlink socket system call. If the argument given is not a pathname, then it just returns name as is and indicates success. Why libnetdevname? This is aimed at solving the NIC enumeration issue where add-in NICs get enumerated before LOMs which creates issues. For details, go to: http://linux.dell.com/libsmbios/download/libnetdevname/ Udev helper applications like biosdevname can be used to retreive smbios labels corresponding to LOMs and add-in NICs. Given the kernel name, it returns bios-given names of ethernet interfaces. The names it suggests depends on the "policy" argument which decides that userspace namespace that the suggested names will be in. For more details on biosdevname please see http://linux.dell.com/projects.shtml#biosdevname. For Example, if eth1 is marked NIC1 on the chassis: # /sbin/biosdevname --policy=smbios_names -I eth1 Embedded_NIC_1 With the help of biosdevname, symbolic links can be created to /dev/net/ethN. These symbolic links can look like: /dev/net/by-chassis-label/Embedded_NIC_1 -> ../eth1 /dev/net/by-chassis-label/Embedded_NIC_2 -> ../eth2 /dev/net/by-mac/00:01:02:03:04:05 -> ../eth1 Udev rules would dynamically create /dev/net/ethN nodes and symbolic links to it. The rules would look like: KERNEL=="eth*", NAME="net/%k", MODE="0666" SUBSYSTEM=="net", PROGRAM="/sbin/biosdevname -i %k --policy=smbios_names", SYMLINK+="net/by-chassis-id/%c" SUBSYSTEM=="net", SYMLINK+="net/by-mac/$attr(address)" Prerequirements for libnetdevname 1. You will require to patch the Linux kernel for it to create char device nodes for ethernet devices: http://marc.info/?l=linux-netdev&m=125070845830221&w=2 2. You will require to patch the system's udev rules to create the directories and symlinks in /dev/net: How can I use libnetdevname in my application? Userspace utilities that traditionally use ethN names, can be patched to resolve the pathnames to the device names by issuing a call to this library like this: char *devname; devname = argv[n]; if (netdev_pathname_to_name(devname) < 0) error(); If devname points to pathname, then library maps it to a "eth" name and devname would now point to an "eth" name and it return success as indicator. If devname points to a traditional "ethN" name, library does nothing and returns success. Since the ioctls would require the traditional names, call to this library should be issued before issuing these ioctls. Example usage of ifconfig # /sbin/ifconfig /dev/net/by-chassis-label/Embedded_NIC_1 # /usr/sbin/ethtool -p /dev/net/by-mac/00:01:02:03:04:05