All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul LeoNerd Evans <leonerd@leonerd.org.uk>
To: Jon Zhou <Jon.Zhou@jdsu.com>, netdev@vger.kernel.org
Subject: Re: can multi app capture on same NIC?(use packet_mmap)
Date: Tue, 22 Jun 2010 19:31:41 +0100	[thread overview]
Message-ID: <20100622183141.GQ11110@cel.leo> (raw)
In-Reply-To: <4A6A2125329CFD4D8CC40C9E8ABCAB9F24985FE8F8@MILEXCH2.ds.jdsu.net>

[-- Attachment #1: Type: text/plain, Size: 1884 bytes --]

On Tue, Jun 22, 2010 at 02:40:13AM -0700, Jon Zhou wrote:
> I'd like to know multi-app can work with packet_mmap (or traditional AF_PACKET system call)?
> i.e.
> app1 & app2 capture on the same NIC
> 
> will both of them receive the same packet? 
> 
> Or this situation will happen?
> 
> 1.app1 start to receive a packet#1
> 2.app1 complete receiving, then set the packet_status->TP_STATUS_KERNEL
> 3.how about app2 at this time? Will it see packet_status=KERNEL, then packet#1 got lost?

Sure; each PF_PACKET socket gets its own memory buffer.

> I tried to find the relevant code in af_packet.c, seems it doesn't guarantee multi-app capture on same NIC?
> Can someone help to point it out?

That's because af_packet.c doesn't need to care. All the relevant code
is found in net/core/dev.c

PF_PACKET sockets get installed into the ptype_all list:

  void dev_add_pack(struct packet_type *pt)
  {
          int hash;

          spin_lock_bh(&ptype_lock);
          if (pt->type == htons(ETH_P_ALL))
                  list_add_rcu(&pt->list, &ptype_all);
  ...

Thereafter, every packet that's received is delivered, individually, to
every handler in that list:

  int netif_receive_skb(struct sk_buff *skb)
  {
  ...
          list_for_each_entry_rcu(ptype, &ptype_all, list) {
                  if (ptype->dev == null_or_orig || ptype->dev == skb->dev ||
                      ptype->dev == orig_dev) {
                          if (pt_prev)
                                  ret = deliver_skb(skb, pt_prev, orig_dev);
  ...

Finally, in net/packet/af_packet.c, each PF_PACKET socket gets a copy of
this skb anyway; look for the call to skb_copy_bits() in the function
tpacket_rcv()

Hope that helps,

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk
ICQ# 4135350       |  Registered Linux# 179460
http://www.leonerd.org.uk/

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 190 bytes --]

      reply	other threads:[~2010-06-22 18:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-22  9:40 can multi app capture on same NIC?(use packet_mmap) Jon Zhou
2010-06-22 18:31 ` Paul LeoNerd Evans [this message]

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=20100622183141.GQ11110@cel.leo \
    --to=leonerd@leonerd.org.uk \
    --cc=Jon.Zhou@jdsu.com \
    --cc=netdev@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.