linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Green <andy@warmcat.com>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: Michael Wu <flamingice@sourmilk.net>, linux-wireless@vger.kernel.org
Subject: Re: Filtering in Monitor Mode (was Question about PRISM2 header rate   field)
Date: Mon, 05 Mar 2007 13:18:33 +0000	[thread overview]
Message-ID: <45EC18A9.50003@warmcat.com> (raw)
In-Reply-To: <1173099910.6131.71.camel@johannes.berg>

Johannes Berg wrote:
> On Mon, 2007-03-05 at 13:00 +0000, Andy Green wrote:
> 
>> I used the libpcap filter stuff to limit what I saw to just the packets 
>> of interest.  This is the filtering that tcpdump uses to do the 
>> conditional filters like "port 22" or "host 192.168.0.1".  The filter 
>> uses something called BPF (Berkeley Packet Filter) which is done 
>> kernelside (at least libpcap is doing the filter install with ioctls in 
>> pcap-bpf.c).  So the cost of drinking from a Monitor firehose is much 
>> less than it sounds.
> 
> Actually, I think the cost can be significant, especially for embedded
> systems. You traverse into userspace for each packet at least once, and
> a management entity in userspace will not be concerned with data packets
> at all. Also, a monitor interface currently always disables power save
> mode for many drivers.

Not sure I explained well enough: looking at libpcap sources, it 
compiles the filter you request into a bytecode and then gives it to the 
kernelside using an ioctl.  When you recv() or select() on the monitor 
interface after that, you block until something matching your filter 
definition turns up.  Userspace doesn't hear about the rest of it.

Filter definitions include stuff like testing specific offsets of the 
header or payload and boolean operators.

pcap-bpf.c:

static int
pcap_setfilter_bpf(pcap_t *p, struct bpf_program *fp)
{
...
        /*
          * Try to install the kernel filter.
          */
         if (ioctl(p->fd, BIOCSETF, (caddr_t)fp) < 0) {
                 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCSETF: %s",
                     pcap_strerror(errno));
                 return (-1);
         }
         p->md.use_bpf = 1;      /* filtering in the kernel */
...
}

 From the README.linux on libpcap:

''In addition, there is an option that, in 2.2 and later kernels, will
allow packet capture filters specified to programs such as tcpdump to be
executed in the kernel, so that packets that don't pass the filter won't
be copied from the kernel to the program, rather than having all packets
copied to the program and libpcap doing the filtering in user mode.

Copying packets from the kernel to the program consumes a significant
amount of CPU, so filtering in the kernel can reduce the overhead of
capturing packets if a filter has been specified that discards a
significant number of packets.  (If no filter is specified, it makes no
difference whether the filtering isn't performed in the kernel or isn't
performed in user mode. :-))

The option for this is the CONFIG_FILTER option''

-Andy

  reply	other threads:[~2007-03-05 13:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-04 10:23 Question about PRISM2 header rate field Andy Green
2007-03-04 16:35 ` Andy Green
2007-03-05  0:15   ` Johannes Berg
2007-03-05  1:02     ` Andy Green
2007-03-05  3:10       ` Michael Wu
2007-03-05  8:10         ` Andy Green
2007-03-05 11:24         ` non-promisc monitor interfaces [was: Re: Question about PRISM2 header rate field] Johannes Berg
2007-03-05 11:34         ` Question about PRISM2 header rate field Johannes Berg
2007-03-05 13:00           ` Filtering in Monitor Mode (was Question about PRISM2 header rate field) Andy Green
2007-03-05 13:05             ` Johannes Berg
2007-03-05 13:18               ` Andy Green [this message]
2007-03-05 13:22                 ` Johannes Berg
2007-03-05 13:46                   ` Andy Green
2007-03-05 16:55           ` Question about PRISM2 header rate field Jouni Malinen
2007-03-05 20:39             ` Andy Green

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45EC18A9.50003@warmcat.com \
    --to=andy@warmcat.com \
    --cc=flamingice@sourmilk.net \
    --cc=johannes@sipsolutions.net \
    --cc=linux-wireless@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).