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

Bug#312554: marked as done (libc6: if_nameindex(3) returns broken list of network interfaces)



Your message dated Tue, 27 Dec 2005 09:26:51 +0000
with message-id <1135675611.3241.8.camel@mebius.reciva.com>
and subject line libc6: if_nameindex(3) returns broken list of network interfaces
has caused the attached Bug report to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Debian bug tracking system administrator
(administrator, Debian Bugs database)

--------------------------------------
Received: (at submit) by bugs.debian.org; 8 Jun 2005 18:33:17 +0000
>From debian@n-dimensional.de Wed Jun 08 11:33:17 2005
Return-path: <debian@n-dimensional.de>
Received: from bender.bawue.de [193.7.176.20] 
	by spohr.debian.org with esmtp (Exim 3.35 1 (Debian))
	id 1Dg5Ma-0004vX-00; Wed, 08 Jun 2005 11:33:17 -0700
Received: by bender.bawue.de (Postfix, from userid 10)
	id C8EA145637; Wed,  8 Jun 2005 20:33:13 +0200 (MEST)
Received: by mobile-mx.n-dimensional.de (Postfix, from userid 1001)
	id 4AE6771775; Wed,  8 Jun 2005 20:30:42 +0200 (CEST)
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
From: Hans Ulrich Niedermann <debian@n-dimensional.de>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: libc6: if_nameindex(3) returns broken list of network interfaces
X-Mailer: reportbug 3.8
Date: Wed, 08 Jun 2005 20:30:42 +0200
Message-Id: <20050608183042.4AE6771775@mobile-mx.n-dimensional.de>
Delivered-To: submit@bugs.debian.org
X-Spam-Checker-Version: SpamAssassin 2.60-bugs.debian.org_2005_01_02 
	(1.212-2003-09-23-exp) on spohr.debian.org
X-Spam-Status: No, hits=-8.0 required=4.0 tests=BAYES_00,HAS_PACKAGE 
	autolearn=no version=2.60-bugs.debian.org_2005_01_02
X-Spam-Level: 

Package: libc6
Version: 2.3.2.ds1-22
Severity: normal


if_nameindex(3) returns only a subset of all network interfaces, and
lists some of them multiple times. This contradicts the man page
if_nameindex(3posix) and the libc6.info docs which state

   NAME
       if_nameindex - return all network interface names and indexes

and

   -- Function: struct if_nameindex * if_nameindex (void)
        This function returns an array of `if_nameindex'
        structures, one for every interface that is present.

respectively.

The returned list

  - does not contain "all network interface names" like the man page says.
    It only includes those which have an IPv4 address configured on them.

  - does not contain "one [structure] for every interface present" like
    the libc6 info page says.
    It contains one if_nameindex structure for every IPv4 address
    configured on the interface.

According to empirical studies, the list returned by if_nameindex(3)
is determined according to this logic:

     return_list = []
     for interface in list_of_all_interfaces:
        if is_up(interface):
            for ipv4_addr in addr_list(interface, AF_INET):
                return_list.append(interface)
     return return_list
 
However, the if_nameindex documentation suggests that the list
should be created using this logic:
 
     return_list = []
     for interface in list_of_all_interfaces:
        if is_up(interface):
            return_list.append(interface)
     return return_list

I used this short test program:

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

int main(int argc, char *argv[])
{
	int i;
	struct if_nameindex *ifs = if_nameindex();
	if (ifs == NULL) {
		perror("could not run if_nameindex");
		return 1;
	}
	for (i=0; (i>=0) && 
		(ifs[i].if_index != 0) && (ifs[i].if_name != NULL);
		i++)
	{
		printf("%3d  %3d  %s\n", i, ifs[i].if_index, ifs[i].if_name);
	}
	if_freenameindex(ifs);
}

In my case, this program prints

  0    1  lo
  1    1  lo
  2   12  eth0
  3   12  eth0
  4   12  eth0

while I have an additional interface dummy0 which is up, but has no IPv4
addresses configured. The complete output of "ip addr" is as follows:

1: lo: <LOOPBACK,UP> mtu 16436 qdisc noqueue 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet 169.254.185.103/16 scope link lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
12: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether aa::bb:cc:dd:ee brd ff:ff:ff:ff:ff:ff
    inet 169.254.28.139/16 scope link eth0
    inet 192.168.1.2/24 brd 192.168.1.255 scope global eth0
    inet 192.168.1.1/24 scope global eth0
    inet6 2001:6f8:abcd:abcd::1007/64 scope global 
       valid_lft forever preferred_lft forever
    [ ... another 10 inet6 addrs deleted ... ]
13: dummy0: <BROADCAST,NOARP,UP> mtu 1500 qdisc noqueue 
    link/ether 56:b4:4e:e7:91:3a brd ff:ff:ff:ff:ff:ff
    inet6 2001:6f8:abcd:abce::1007/128 scope global 
       valid_lft forever preferred_lft forever
    [ ... another 10 inet6 addrs deleted ... ]

This behaviour plainly contradicts the documentation.

I suggest as solutions to either:

  a) simplify the logic behind if_nameindex(3) such that it lists all
     interfaces in state "up" regardless of any addresses possibly
     configured on them
  b) change the info documentation to actually describe the current
     behaviour of "List all interfaces with IPv4 addresses configured
     as many times as the number of IPv4 addresses on the interface.
     This violates the POSIX definition of if_nameindex." :-)

The described erroneous behaviour also occurs with the stock Debian
kernel from kernel-image-2.6.8-2-686 2.6.8-16, so this is not an
issue specific to a certain version of the Linux kernel.

-- System Information:
Debian Release: 3.1
  APT prefers unstable
  APT policy: (700, 'unstable'), (100, 'experimental')
Architecture: i386 (i686)
Kernel: Linux 2.6.11.10-swsusp2-ndim-2
Locale: LANG=C, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8)

Versions of packages libc6 depends on:
ii  libdb1-compat                 2.1.3-7    The Berkeley database routines [gl

-- no debconf information

---------------------------------------
Received: (at 312554-done) by bugs.debian.org; 27 Dec 2005 09:26:54 +0000
>From pb@reciva.com Tue Dec 27 01:26:54 2005
Return-path: <pb@reciva.com>
Received: from mail.nexus.co.uk ([82.70.217.43] helo=crown.nexus.co.uk)
	by spohr.debian.org with esmtp (Exim 4.50)
	id 1ErB6c-0004Eo-LB
	for 312554-done@bugs.debian.org; Tue, 27 Dec 2005 01:26:54 -0800
Received: from cpc1-cmbg6-5-0-cust20.cmbg.cable.ntl.com ([81.104.210.20] helo=[192.168.2.116])
	by crown.nexus.co.uk with esmtpsa (TLS-1.0:RSA_ARCFOUR_MD5:16)
	(Exim 4.50)
	id 1ErB6e-0008HQ-0R
	for 312554-done@bugs.debian.org; Tue, 27 Dec 2005 09:26:56 +0000
Subject: Re: libc6: if_nameindex(3) returns broken list of network
	interfaces
From: Phil Blundell <pb@reciva.com>
To: 312554-done@bugs.debian.org
Content-Type: text/plain
Date: Tue, 27 Dec 2005 09:26:51 +0000
Message-Id: <1135675611.3241.8.camel@mebius.reciva.com>
Mime-Version: 1.0
X-Mailer: Evolution 2.2.2 
Content-Transfer-Encoding: 7bit
X-Spam-Checker-Version: SpamAssassin 2.60-bugs.debian.org_2005_01_02 
	(1.212-2003-09-23-exp) on spohr.debian.org
X-Spam-Level: 
X-Spam-Status: No, hits=-2.5 required=4.0 tests=BAYES_00,RCVD_IN_SORBS 
	autolearn=no version=2.60-bugs.debian.org_2005_01_02

This bug seems to be fixed in glibc 2.3.5, which is in unstable now.

I ran your test program on my machine; the output was:

  0    1  lo
  1    3  eth0
  2    4  sit0
  3    5  dummy0

whereas "ip addr" shows:

1: lo: <LOOPBACK,UP> mtu 16436 qdisc noqueue
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
3: eth0: <BROADCAST,MULTICAST,ALLMULTI,UP> mtu 1500 qdisc pfifo_fast
qlen 1000
    link/ether 08:00:1f:06:09:3c brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.116/24 brd 192.168.2.255 scope global eth0
    inet 192.168.4.1/24 brd 192.168.4.255 scope global eth0:0
    inet6 2002:5168:d214:1:a00:1fff:fe06:93c/64 scope global deprecated
dynamic
       valid_lft 2591844sec preferred_lft -36sec
    inet6 fe80::a00:1fff:fe06:93c/64 scope link
       valid_lft forever preferred_lft forever
4: sit0: <NOARP> mtu 1480 qdisc noop
    link/sit 0.0.0.0 brd 0.0.0.0
5: dummy0: <BROADCAST,NOARP,UP> mtu 1500 qdisc noqueue
    link/ether f6:45:a7:d6:3f:4e brd ff:ff:ff:ff:ff:ff
    inet6 fe80::f445:a7ff:fed6:3f4e/64 scope link
       valid_lft forever preferred_lft forever

So, it appears that if_nameindex() is now operating correctly.  Please
re-open this bug if you are still having trouble.

p.



Reply to: