Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 9 Apr 2014 09:55:56 +0200
From: Natanael Copa <ncopa@...inelinux.org>
To: musl@...ts.openwall.com
Cc: dalias@...ifal.cx, justin@...cialbusservice.com
Subject: Re: if_nameindex/getifaddrs and dhcpcd issue

On Tue, 8 Apr 2014 11:45:37 -0400
Rich Felker <dalias@...ifal.cx> wrote:

> > We should not be looking at dhcpd. It's the APIs musl implements:
> > getifaddrs() and if_nameindex() - they are not currently exposing all
> > the information they should.
> 
> One can argue about what if_nameindex should expose;

Yes. This is the real issue at hand. What dhcpcd does is not that
relevant here.

> for instance,
> should it expose all possible interface names the kernel could
> support, even with modules that haven't been loaded yet?

IMHO, no. I think it should only expose what you normally find
as /sys/class/net/* (you find same list in /proc/net/dev)

A use case if_nameindex() that I think would be valid is a network config ui.

Which interface do you want to configure? 
Presents a list of currently available network interfaces. (from if_nameindex)
It has a button 'Add virtual interface', which lets user configure
bonding/bridges/vlans etc.

(yes, no application should assume that the listed interface actually
works. I could select my USB ethernet dongle and before press 'ok' I
could pull out the USB ethernet...)

> The only
> thing a strictly conforming application can _DO_ with interface
> names/numbers is use them for link-local ipv6 scope ids (this is
> presumably why these functions were added to POSIX in the first
> place). So, from a conformance standpoint, only exposing ids that
> could actually appear on a link-local address (i.e. configured
> interfaces that have ipv6 link-local addresses) would be sufficient.

Then, from a conformance standpoint, the current musl if_nameindex
implementation is broken. It only lists interfaces with configured
ipv4 addresses.

To test yourself:

modprobe dummy
ip link set up dev dummy0
ip addr   #verify that dummy has ipv6 link-local

Then run the following testcase:

#include <net/if.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int
main(int argc, char *argv[])
{
    struct if_nameindex *if_ni, *i;

   if_ni = if_nameindex();
    if (if_ni == NULL) {
        perror("if_nameindex");
        exit(EXIT_FAILURE);
    }

   for (i = if_ni; ! (i->if_index == 0 && i->if_name == NULL); i++)
        printf("%u: %s\n", i->if_index, i->if_name);

   if_freenameindex(if_ni);

   exit(EXIT_SUCCESS);
}

The ipv6 link-local configured dummy0 interface will not be listed.



-nc

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.