Skip to contentSkip to conversation

samples/bpf: Fix MAC address swapping in xdp2_kern

PATCH Applied Gerhard Engleder 3 participants 3 messages Oct 15, 2022 – Oct 19, 2022

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

PATCH 1/1 samples/bpf: Fix MAC address swapping in xdp2_kern

xdp2_kern rewrites and forwards packets out on the same interface. Forwarding still works but rewrite got broken when xdp multibuffer support has been added.

With xdp multibuffer a local copy of the packet has been introduced. The MAC address is now swapped in the local copy, but the local copy in not written back.

Fix MAC address swapping be adding write back of modified packet.

Fixes 772251742262 ("samples/bpf: fixup some tools to be able to support xdp multibuffer")
---
 samples/bpf/xdp2_kern.c | 4 ++++
 1 file changed, 4 insertions(+)
samples/bpf/xdp2_kern.c +4 -0
index 3332ba6bb95f..67804ecf7ce3 100644
@@ -112,6 +112,10 @@ int xdp_prog1(struct xdp_md *ctx)
 
 	if (ipproto == IPPROTO_UDP) {
 		swap_src_dst_mac(data);
+
+		if (bpf_xdp_store_bytes(ctx, 0, pkt, sizeof(pkt)))
+			return rc;
+
 		rc = XDP_TX;
 	}
 
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Gerhard Engleder

xdp2_kern rewrites and forwards packets out on the same interface. Forwarding still works but rewrite got broken when xdp multibuffer support has been added.

With xdp multibuffer a local copy of the packet has been introduced. The MAC address is now swapped in the local copy, but the local copy in not written back.

Fix MAC address swapping be adding write back of modified packet.

Nice catch! Thanks for posting this.

Quoted 2 lines
Fixes 772251742262 ("samples/bpf: fixup some tools to be able to support xdp multibuffer")
Quoted 22 lines
---
 samples/bpf/xdp2_kern.c | 4 ++++
 1 file changed, 4 insertions(+)
samples/bpf/xdp2_kern.c +4 -0
index 3332ba6bb95f..67804ecf7ce3 100644
@@ -112,6 +112,10 @@ int xdp_prog1(struct xdp_md *ctx)
 
 	if (ipproto == IPPROTO_UDP) {
 		swap_src_dst_mac(data);
+
+		if (bpf_xdp_store_bytes(ctx, 0, pkt, sizeof(pkt)))
+			return rc;
+
 		rc = XDP_TX;
 	}
 
Signature · 1 line
2.30.2
#2 lore raw
In reply to Gerhard Engleder
This patch was applied to bpf/bpf-next.git (master) by Martin KaFai Lau <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Martin KaFai Lau <[email protected]>:

Quoted 9 lines · On Sat, 15 Oct 2022 23:30:50 +0200 you wrote:

xdp2_kern rewrites and forwards packets out on the same interface. Forwarding still works but rewrite got broken when xdp multibuffer support has been added.

With xdp multibuffer a local copy of the packet has been introduced. The MAC address is now swapped in the local copy, but the local copy in not written back.

[...]

Here is the summary with links:
- [net-next] samples/bpf: Fix MAC address swapping in xdp2_kern

    https://git.kernel.org/bpf/bpf-next/c/7a698edf954c

You are awesome, thank you!

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