From owner-freebsd-hackers Fri Aug 24 5:53:17 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from mailhub.fokus.gmd.de (mailhub.fokus.gmd.de [193.174.154.14]) by hub.freebsd.org (Postfix) with ESMTP id C67A037B405 for ; Fri, 24 Aug 2001 05:53:09 -0700 (PDT) (envelope-from brandt@fokus.gmd.de) Received: from beagle (beagle [193.175.132.100]) by mailhub.fokus.gmd.de (8.8.8/8.8.8) with ESMTP id OAA03305 for ; Fri, 24 Aug 2001 14:53:08 +0200 (MET DST) Date: Fri, 24 Aug 2001 14:53:08 +0200 (CEST) From: Harti Brandt To: Subject: bug in net.link.generic handling Message-ID: <20010824144023.K70036-100000@beagle.fokus.gmd.de> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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.... 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