Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Aug 2001 14:53:08 +0200 (CEST)
From:      Harti Brandt <brandt@fokus.gmd.de>
To:        <hackers@freebsd.org>
Subject:   bug in net.link.generic handling
Message-ID:  <20010824144023.K70036-100000@beagle.fokus.gmd.de>

next in thread | raw e-mail | index | archive | help

Hello,

there seems to be a problem with the handling of the interfaces
subtree. In if_mib.c I see:

	if (name[0] <= 0 || name[0] > if_index)
		return ENOENT;

	ifp = ifnet_addrs[name[0] - 1]->ifa_ifp;

and after that 'ifp' is used to return information to the user. There
are, however, circumstances, where ifnet_addrs[i] may be NULL:

 1) in if_attach the allocation of the address may fail. In this case
    ifnet_addrs[i] remains NULL, but the interface is attached.

 2) an interface may be detached from the 'middle' of the current
    interface index range. If, for example, I have three interfaces
    with indexes 1, 2 and 3 and I unload the driver for interface 2,
    ifnet_addrs[1] will be zero, but if_index will remain 3.

If this happens the kernel will probably panic in sysctl_ifdata.

The fix is obvious:

Index: if_mib.c
===================================================================
RCS file: /usr/ncvs/src/sys/net/if_mib.c,v
retrieving revision 1.10
diff -r1.10 if_mib.c
86c86,87
< 	ifp = ifnet_addrs[name[0] - 1]->ifa_ifp;
---
> 	if ((ifp = ifnet_addrs[name[0] - 1]->ifa_ifp) == NULL)
> 		return (ENOENT);

A related problem is that net.link.generic.system.ifcount is not really
to number of interfaces, but rather the current maximum interface index.
These numbers may be different if there are holes in the index space. If
this part of the sysctl names space were be documented, this should probably
be mentioned :-)

Is there any way to access net.link.generic.<ifindex>... with
sysctl(8)?

Regards,
harti
-- 
harti brandt, http://www.fokus.gmd.de/research/cc/cats/employees/hartmut.brandt/private
              brandt@fokus.fhg.de


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010824144023.K70036-100000>