Skip to contentSkip to conversation

AF_PACKET + PACKET_FANOUT: tx packet delivered back in rx

DISCUSSION Aleksandr Kotov 2 participants 2 messages Jul 12, 2012 – Aug 16, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

I have a problem using AF_PACKET socket with PACKET_RX_RING, PACKET_TX_RING and PACKET_FANOUT options enabled.
I am seeing my TX packets get back to the same socket in RX ring. Socket is created and gets bind with ETH_P_ALL protocol type. The problem is in the fanout_add function which sets af_packet_priv to "match" variable, but not sk one describing socket and in dev_queue_xmit_nit skb get bounced back to the socket despite the comment left in the function.

fanout_add(struct sock *sk, u16 id, u16 type_flags)

    ....
     match->prot_hook.af_packet_priv = match;
    ....

dev_queue_xmit_nit

       list_for_each_entry_rcu(ptype, &ptype_all, list) {
                /* Never send packets back to the socket
                 * they originated from - MvS ([email protected])
                 */
                if ((ptype->dev == dev || !ptype->dev) &&
                    (ptype->af_packet_priv == NULL ||
                     (struct sock *)ptype->af_packet_priv != skb->sk)) {

As said in David Miller comment for PACKET_FANOUT patch:

"The implementation is agnostic to the type of AF_PACKET sockets in use. You can use _mmap_ based, and non-mmap based, AF_PACKET sockets. It simply doesn't care."
So I think it is legal to used mmaped AF_PACKET/.

Is there any way to use it correctly with packets not mirroring in rx?

Best regard, Aleksandr Kotov

maintainer
#1 lore raw

From: Aleksandr Kotov <[email protected]>
Date: Thu, 12 Jul 2012 12:30:17 +0400

Quoted 3 lines

I have a problem using AF_PACKET socket with PACKET_RX_RING, PACKET_TX_RING and PACKET_FANOUT options enabled.
I am seeing my TX packets get back to the same socket in RX ring. Socket is created and gets bind with ETH_P_ALL protocol type. The problem is in the fanout_add function which sets af_packet_priv to "match" variable, but not sk one describing socket and in dev_queue_xmit_nit skb get bounced back to the socket despite the comment left in the function.

Eric Leblong is posting fixes for this problem recently:

http://patchwork.ozlabs.org/patch/178044/