Skip to contentSkip to conversation

net/packet: add PACKET_FANOUT_FLAG_IGNORE_OUTGOING

PATCH Applied Willem de Bruijn 3 participants 3 messages Oct 27, 2022 – Oct 29, 2022

Subsystems (3)
lore
Share & tools
lore

Willem de Bruijn

author maintainer
#0 lore raw

PATCH 1/1 net/packet: add PACKET_FANOUT_FLAG_IGNORE_OUTGOING

From: Willem de Bruijn <[email protected]>

Extend packet socket option PACKET_IGNORE_OUTGOING to fanout groups.

The socket option sets ptype.ignore_outgoing, which makes dev_queue_xmit_nit skip the socket.

When the socket joins a fanout group, the option is not reflected in the struct ptype of the group. dev_queue_xmit_nit only tests the fanout ptype, so the flag is ignored once a socket joins a fanout group.

Inheriting the option from a socket would change established behavior. Different sockets in the group can set different flags, and can also change them at runtime.

Testing in packet_rcv_fanout defeats the purpose of the original patch, which is to avoid skb_clone in dev_queue_xmit_nit (esp. for MSG_ZEROCOPY packets).

Instead, introduce a new fanout group flag with the same behavior.

Tested with https://github.com/wdebruij/kerneltools/blob/master/tests/test_psock_fanout_ignore_outgoing.c

---
 include/uapi/linux/if_packet.h | 1 +
 net/packet/af_packet.c         | 1 +
 2 files changed, 2 insertions(+)
include/uapi/linux/if_packet.h +1 -0
index c07caf7b40db6..a8516b3594a44 100644
@@ -70,6 +70,7 @@ struct sockaddr_ll {
 #define PACKET_FANOUT_EBPF		7
 #define PACKET_FANOUT_FLAG_ROLLOVER	0x1000
 #define PACKET_FANOUT_FLAG_UNIQUEID	0x2000
+#define PACKET_FANOUT_FLAG_IGNORE_OUTGOING     0x4000
 #define PACKET_FANOUT_FLAG_DEFRAG	0x8000
 
 struct tpacket_stats {
net/packet/af_packet.c +1 -0
index 8c5b3da0c29f6..44f20cf8a0c0e 100644
@@ -1777,6 +1777,7 @@ static int fanout_add(struct sock *sk, struct fanout_args *args)
 		match->prot_hook.af_packet_net = read_pnet(&match->net);
 		match->prot_hook.id_match = match_fanout_group;
 		match->max_num_members = args->max_num_members;
+		match->prot_hook.ignore_outgoing = type_flags & PACKET_FANOUT_FLAG_IGNORE_OUTGOING;
 		list_add(&match->list, &fanout_list);
 	}
 	err = -EINVAL;
Signature · 1 line
2.38.1.273.g43a17bfeac-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Willem de Bruijn

From: Willem de Bruijn <[email protected]>

Extend packet socket option PACKET_IGNORE_OUTGOING to fanout groups.

...

Quoted 5 lines

Instead, introduce a new fanout group flag with the same behavior.

Tested with https://github.com/wdebruij/kerneltools/blob/master/tests/test_psock_fanout_ignore_outgoing.c

SGTM, thanks.

#2 lore raw
In reply to Willem de Bruijn
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Thu, 27 Oct 2022 17:10:14 -0400 you wrote:

From: Willem de Bruijn <[email protected]>

Extend packet socket option PACKET_IGNORE_OUTGOING to fanout groups.

The socket option sets ptype.ignore_outgoing, which makes dev_queue_xmit_nit skip the socket.

[...]

Here is the summary with links:
- [net-next] net/packet: add PACKET_FANOUT_FLAG_IGNORE_OUTGOING

    https://git.kernel.org/netdev/net-next/c/58ba426388d9

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html