mailing list of musl libc
 help / color / mirror / code / Atom feed
* if_nameindex and getifaddrs
@ 2014-06-07 23:18 Rich Felker
  2014-06-08 10:03 ` Justin Cormack
  0 siblings, 1 reply; 2+ messages in thread
From: Rich Felker @ 2014-06-07 23:18 UTC (permalink / raw)
  To: musl

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: if_nameindex and getifaddrs
  2014-06-07 23:18 if_nameindex and getifaddrs Rich Felker
@ 2014-06-08 10:03 ` Justin Cormack
  0 siblings, 0 replies; 2+ messages in thread
From: Justin Cormack @ 2014-06-08 10:03 UTC (permalink / raw)
  To: musl

On Sun, Jun 8, 2014 at 12:18 AM, Rich Felker <dalias@libc.org> wrote:
> 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.

I only know a bit about the NetBSD Linux emulation, as I help out the
main developer with testing. It is currently not very complete in the
networking areas, but there are tests for some of it, and they will be
added eventually. Currently there isn't /proc/net/dev emulation in the
Linux /proc emulation. Not sure how complete the ioctl emulation is,
but at least it is easier to add than netlink. The alias interfaces
are another complexity, as I don;t think there has ever been an ipv4
alias equivalent in NetBSD so that would have to be emulated too.

I think most of the work is on their side; I can go and eg add tests
for all the ioctls in Musl.

Justin


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-06-08 10:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-07 23:18 if_nameindex and getifaddrs Rich Felker
2014-06-08 10:03 ` Justin Cormack

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).