Subject: Re: BPF support for writing raw IEEE 802.11 frames
To: None <>
From: David Young <>
List: tech-net
Date: 08/06/2006 11:51:47
On Tue, Aug 01, 2006 at 02:19:15PM -0400, Vivek raghunathan wrote:
> Option 1: When net80211 code registers DLT_IEEE802_11 with bpf using
> bpfattach, it also pass a callback to be invoked whenever a raw packet
> is written to the bpf device. This callback enqueues the raw 802.11
> frames in the management queue (ieee80211com->mgtq) (whose present
>          semantics are post-802.11 encap).
> Advantage: no changes to driver specific code
> Disadvantage: won't work with drivers that don't poll the management
> queue (e.g., dev/ic/an.c); hack.
> Details:
> a. net/bpf.c: Add a bpf_output function pointer to struct
> bpf_if, and a bpfattach3 function, which is basically bpfattach2 with
> an additional bpf_output parameter that is used to set bpf_output in
> the bpf_if structure.
> b. net/bpf.c: bpf_write - On the bpf_write path,
>     if(bpf_d->bd_bif->bpf_output), call it instead of calling
>     bpf_d->bd_bif->bif_ifp->if_output.
> c. net80211/ieee80211.c:ieee80211_ifattach - use bpfattach3 to install
> DLT_IEEE802_11
> d. (HACK) net80211/ieee80211_output.c: ieee80211_bpf_output - simply
> enqueues the raw frame in the management queue (ic->mgtq), and does
> ifp->if_start
> The hack ensures that we do not need to change each driver's foo_start
> function.

In some work for a client, took almost the identical approach to Option
1, adding bpfattach3(..., callback).  I modified bpfattach2() so that it
calls bpfattach3(, ifp->if_output).  In this way, bpf_write can always
call bpf_d->bd_bif->bif_output.

I do not have an opinion one way or another whether the ieee80211com
should grow an rawq member.  It sounds like the principal difference
between the approaches is that you will modify every WLAN driver's
if_start routine for rawq, or only a few for mgtq.

I favor Option 1 or Option 2 over Option 3.  I will say this
about BIOCSHDRCMPLT, though: it helps application programmers if
ieee80211_bpf_output fills out the source/destination/bssid on injected
DLT_IEEE802_11 frames when BIOCSHDRCMPLT is "off". :-)


David Young             OJC Technologies      Urbana, IL * (217) 278-3933