AF_PACKET + PACKET_FANOUT: tx packet delivered back in rx
Subsystems (2)
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
David Miller
maintainerFrom: Aleksandr Kotov <[email protected]>
Date: Thu, 12 Jul 2012 12:30:17 +0400
Quoted 3 lines
I have a problem using
AF_PACKETsocket withPACKET_RX_RING,PACKET_TX_RINGandPACKET_FANOUToptions enabled.
I am seeing my TX packets get back to the same socket in RX ring. Socket is created and gets bind withETH_P_ALLprotocol type. The problem is in thefanout_addfunction which setsaf_packet_privto "match" variable, but not sk one describing socket and indev_queue_xmit_nitskb get bounced back to the socket despite the comment left in the function.
Eric Leblong is posting fixes for this problem recently: