Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20140607231820.GA12864@brightrain.aerifal.cx>
Date: Sat, 7 Jun 2014 19:18:20 -0400
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: if_nameindex and getifaddrs

One of the items on the agenda/roadmap for the next release cycles is
dealing with the if_nameindex/getifaddrs issue. The big problems with
the current implementations are:

1. if_nameindex fails to report interfaces which are unconfigured or
   which are configured for IPv6 only.

2. getifaddrs fails to report unconfigured interfaces as well as some
   additional information that glibc provides that some apps might
   want (I'm not clear on how important the latter is).

3. Heavy syscall overhead with huge numbers of interfaces:
   if_nameindex requires one ioctl per interface to lookup the number
   from the name, and getifaddrs requires quite a few to get all the
   properties it wants to return.

The basic strategy of our current implementations is to use
SIOCGIFCONF to list interfaces. (This actually lists configured IPv4
addresses, not interfaces, and for legacy ifconfig-style aliases, it
will list the alias names rather than the base interface name.)

There's a patch in Alpine Linux that overhauls both of these functions
to use the Linux netlink system:

http://git.alpinelinux.org/cgit/aports/tree/main/musl/1002-reimplement-if_nameindex-and-getifaddrs-using-netlin.patch?id=838bcec8e10868ef80df1b638d5c8650a7260e7b

However, there's been some concern that this code would not work for
users who are using musl on non-Linux kernels with a Linux syscall API
but not a netlink API (e.g. BSD Linux 'emulation'), and it's probably
also somewhat larger and less efficient with memory than it needs to
be.

Getting the full list of interfaces is definitely possible without
netlink: /proc/net/dev has all the real interface names and they're
trivial to parse without any fancy parser code. The list does not
contain legacy-style aliases (e.g. eth0:2) but these can be obtained
from SIOCGIFCONF if desired (as they are now). As far as I can tell,
legacy aliases are purely associated with a configured IPv4 address.
They simply do not exist with IPv6 interfaces or in an unconfigured
state (and they shate their interface index number with the underlying
base interface). So this method of listing interfaces would be
complete.

Of course I'm not convinced (despite the fact that I rather dislike
netlink) that it's any better than using netlink. It may at least
partially work on BSD via SIOCGIFCONF -- it seems (some?) BSD's might
support SIOCGIFCONF even for IPv6, but I'm not even clear if the ioctl
interface is really compatible or not.

If if_nameindex produced a complete list with unconfigured and v6-only
interfaces included (by whatever means) then the current getifaddrs
implementation would "work" in the sense of not omitting interfaces,
but it still might not produce as much output as some users want.

The above is a summary of my understanding of the situation and some
possible ways forward. I'd welcome some comments, particularly on
anything that would help us keep/improve BSD compatibility alongside
fixing the issues on Linux.

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.