ifunit and struct ifnet/ieee80211com

Brooks Davis brooks at one-eyed-alien.net
Thu Sep 23 22:46:36 PDT 2004

On Fri, Sep 24, 2004 at 03:23:21PM +1000, Phillip Crumpler wrote:
> Hi hackers,
> A few questions re. ifunit and struct ifnet/ieee80211com, if anyone can 
> help me out:
> I assume that for a wireless interface ifunit will return a pointer to a 
> struct ieee80211com. Is there any way to tell which of these I have, so 
> I don't try to access ieee80211com members in a struct that is actually 
> the smaller infet? Both ethernet and wireless ethernet seem to use 
> if_type == 6 (IFT_ETHER) and if_physical == 0. Can I distinguish which 
> type I have or should I just make sure I know beforehand?

You need to know that the struct ifnet is actually embeded in a struct
ieee80211com if you want to access the members.  In properly designed
code this won't generally be ambiguious.  If you some how manage to get
into a state where it is, if_dname is probably your best bet.  That sort
of thing is discouraged though.

> Also, what is the lifetime of the (struct ifnet *) that ifunit returns? 
> If an interface goes away is the ifnet freed, leaving me with a dangling 
> pointer, or is it kept but marked inactive in some way?

There is currently no assurance that a pointer to a struct ifnet is
valid.  If you're going to hold a pointer over anything but trivial
operations, don't.  Hold the index and us ifnet_byindex instead.
Currently that also dies since it returns NULL after attach, but I plan
to look in to returning a special dead_if to avoid crashes.

-- Brooks

Any statement of the form "X is the one, true Y" is FALSE.
PGP fingerprint 655D 519C 26A7 82E7 2529  9BF0 5D8E 8BE9 F238 1AD4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20040923/83798482/attachment.bin

More information about the freebsd-hackers mailing list