From owner-freebsd-net Tue Jul 16 18:28:52 2002 Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DD10F37B400 for ; Tue, 16 Jul 2002 18:28:49 -0700 (PDT) Received: from gateway.posi.net (adsl-63-201-92-2.dsl.snfc21.pacbell.net [63.201.92.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 371E143E3B for ; Tue, 16 Jul 2002 18:28:49 -0700 (PDT) (envelope-from kbyanc@posi.net) Received: from localhost (localhost [127.0.0.1]) by gateway.posi.net (8.12.3/8.12.3) with ESMTP id g6H1SkcT004773; Tue, 16 Jul 2002 18:28:47 -0700 (PDT) (envelope-from kbyanc@posi.net) Date: Tue, 16 Jul 2002 18:28:46 -0700 (PDT) From: Kelly Yancey To: Bill Baumann Cc: freebsd-net@FreeBSD.ORG Subject: Re: Inconsistency between net/if.c and several ethernet drivers In-Reply-To: Message-ID: <20020716180110.E4709-100000@gateway.posi.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org On Tue, 16 Jul 2002, Bill Baumann wrote: > > In net/if.c in a couple of places, the ethernet address is needed. This > is stored in the arpcom structure. A couple lines of code in if.c require > struct arpcom be at the very begining of device softc structures. Nearly > all drivers observe this. However, several do not. Sadly, this includes > the one I'm working on. > > net/if.c routines if_findindex() and if_setlladdr() gain access to the > ethernet address via the following expression: > > ((struct arpcom *)ifp->if_softc)->ac_enaddr > > The above code assumes that the if_softc pointer is equivalent to an > struct arpcom pointer. The awi, ray, lnc and pdq drivers have other > fields at the beginning of their softc structures. Attempts to set the > ethernet address of these devices may cause corruption. > > > Shouldn't access of arpcom be via ifp instead? > > ((struct arpcom *)ifp)->ac_enaddr > > > For example, if_ethersubr.c uses the following macro: > #define IFP2AC(IFP) ((struct arpcom *)IFP) > > It looked to me like the other code in net, like if_ethersubr.c use ifp > rather than if_softc to find struct arpcom. > > Bug? > Design. :) See page 77 of Stevens' TCP/IP Illustrated Volume 2. By putting the structures at the beginning of the softc, the networking code can access them without any explicit knowledge of the driver's softc itself (i.e. it can use the softc as an opaque encapsulated version of either the arpcom or ifnet structures). The bug, then, would seem to be in the network drivers that don't follow this convention. But I'm not familiar with those particular drivers, so I cannot comment on them; perhaps they employ some cleverness to circumvent the requirement (by why?). Anyway, it should be obvious that accessing the arpcom structure via casting from the ifnet structure or the softc structure are supposed to have the same results, so the code your quoted above is fine. Kelly -- Kelly Yancey -- kbyanc@{posi.net,FreeBSD.org} "The worst sin towards our fellow creatures is not to hate them, but to be indifferent to them; that's the essence of inhumanity." -- George Bernard Shaw To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message