diff -u -p busybox-1.00/networking/libiproute/ll_map.c-old busybox-1.00/networking/libiproute/ll_map.c --- busybox-1.00/networking/libiproute/ll_map.c-old 2005-06-02 12:00:30.000000000 -0700 +++ busybox-1.00/networking/libiproute/ll_map.c 2005-06-02 11:59:12.000000000 -0700 @@ -17,6 +17,10 @@ #include "libnetlink.h" +#include /* socket() */ +#include /* struct ifreq and co. */ +#include /* ioctl() & SIOCGIFINDEX */ + struct idxmap { struct idxmap * next; @@ -131,6 +135,7 @@ int ll_name_to_index(char *name) static char ncache[16]; static int icache; struct idxmap *im; + int sock_fd; int i; if (name == NULL) @@ -146,6 +151,28 @@ int ll_name_to_index(char *name) } } } + /* We have not found the interface in our cache, but the kernel + * may still know about it. One reason is that we may be using + * module on-demand loading, which means that the kernel will + * load the module and make the interface exist only when + * we explicitely request it (check for dev_load() in net/core/dev.c). + * I can think of other similar scenario, but they are less common... + * Jean II */ + sock_fd = socket(AF_INET, SOCK_DGRAM, 0); + if(sock_fd) { + struct ifreq ifr; + int ret; + strncpy(ifr.ifr_name, name, IFNAMSIZ); + ifr.ifr_ifindex = -1; + ret = ioctl(sock_fd, SIOCGIFINDEX, &ifr); + close(sock_fd); + if(ret >= 0) + /* In theory, we should redump the interface list + * to update our cache, this is left as an exercise + * to the reader... Jean II */ + return ifr.ifr_ifindex; + } + return 0; }