tech-net archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Patch to implement SIOCGIFINDEX

On Tue, Apr 02, 2013 at 01:02:28PM -0400, Ty Sarna wrote:
> On Apr 2, 2013, at 4:49 AM, Roy Marples <> wrote:
> > On 02/04/2013 0:13, Ty Sarna wrote:
> >> The following short patch implements SIOCGIFINDEX as found on Linux
> >> (and maybe elsewhere), which translates an interface name to its index.
> > 
> > Is there a reason why you cannot use if_nametoindex(3)?
> One could (Linux has it too), but in practice the socketcan examples
> don't, and so the code out there using socketcan doesn't either. Granted,
> there are already other changes one will have to make when porting
> (I drew the line at <linux/...> headers, for example!), but my
> preference is to make it easy to port.
> (Also, for what little it matters, SIOCGIFINDEX is more efficient than
> if_nametoindex, given that the latter makes multiple syscalls to suck
> the entire interface list from the kernel and then walks it.)

Years ago I was using sockaddr_snprintf(3) to prepare messages for the
diagnostic log of a routing daemon I was programming, and I found that
the if_indextoname(3) overhead was huge because of the syscalls that you
mention.  My solution was to modify the kernel and getifaddrs(3) so that
each process cached the interface list, and the kernel exported (through
a shared page) an interface-list generation number that getifaddrs(3)
used to invalidate its cache.  That sped things up considerably because
usually the system calls could be skipped!

I used an mmap-able character device to share the page between the
kernel and userland because I never found the time to switch to a
"commpage," but I think that a commpage is probably best.


David Young    Urbana, IL    (217) 721-9981

Home | Main Index | Thread Index | Old Index