Subject: Re: struct ifnet's if_softc field?
To: None <thorpej@nas.nasa.gov>
From: Dave McConnell <davem@eastcoast.co.za>
List: tech-kern
Date: 05/16/1999 11:55:43
>
> > Why does "struct ifnet" have a "void *if_softc" as its first field. It
> > seems unnecessary...
>
> It's quite necessary, actually...
>
I saw that the "struct ifnet" documented in Wright/Stevens' Book
(TCP/IP illustrated Vol2) which deals with the 4.4BSD net-3 code,
doesn't have a "void* if_softc" anywhere in it which is why I asked.
I'm pretty new to this stuff and I'm really looking for insight.
> > Isn't ifnet always the first field in a network drivers softc structure?
>
> No, in fact, it's never the first field in a network driver's softc. A
> "struct device" is the first structure _always_ in a real device.
>
OK, once again, I was going by Wright/Steven's book (TCP/IP
Illustrated, Vol2, section 3.6, page 76) where he essentially states
that the network interface softc's always have a "struct ifnet" as the
first field (which he illustrates with the Lance ETHERNET (le_softc),
SLIP (sl_softc) and the (trivial) loopback case.
Subsequent to that I had looked quite carefully at the SLIP and
PPP code for NetBSD where indeed the sl_softc and ppp_softc are
headed by a "struct ifnet".
However, as you point out and UNLIKE in Wright/Steven's Lance
ethernet example, the "struct le_softc" in NetBSD begins with a
"struct device", followed by a struct ifnet(embedded in the struct
ethercom). I assume it is like this for all "real" network devices?
I expect that this way of doing things is one of the reasons for the
first field of "struct ifnet" being a "void *if_softc" ?
BTW is this a NetBSD specific way of doing things or do all the
BSD flavours do it like this?
Of course I now have a new problem. I can't fully rely on the
Wright/Stevens book anymore :-( :-(
Thanks for the help!
Dave