diff mbox series

[net-next] samples/bpf: Fix MAC address swapping in xdp2_kern

Message ID 20221015213050.65222-1-gerhard@engleder-embedded.com (mailing list archive)
State Accepted
Commit 7a698edf954cb3f8b6e8dacdb77615355170420c
Delegated to: BPF
Headers show
Series [net-next] samples/bpf: Fix MAC address swapping in xdp2_kern | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers fail 1 blamed authors not CCed: lorenzo@kernel.org; 9 maintainers not CCed: sdf@google.com lorenzo@kernel.org andrii@kernel.org yhs@fb.com haoluo@google.com jolsa@kernel.org kpsingh@kernel.org song@kernel.org martin.lau@linux.dev
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 10 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-7 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-10 fail Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 fail Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-8 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-11 fail Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-14 fail Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-15 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-9 fail Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-12 fail Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-1 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-4 success Logs for llvm-toolchain
bpf/vmtest-bpf-next-VM_Test-5 success Logs for set-matrix

Commit Message

Gerhard Engleder Oct. 15, 2022, 9:30 p.m. UTC
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")
Signed-off-by: Gerhard Engleder <gerhard@engleder-embedded.com>
---
 samples/bpf/xdp2_kern.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Andy Gospodarek Oct. 17, 2022, 1:43 a.m. UTC | #1
On Sat, Oct 15, 2022 at 11:30:50PM +0200, Gerhard Engleder 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.
> 
> Fix MAC address swapping be adding write back of modified packet.
> 

Nice catch!  Thanks for posting this.

> Fixes: 772251742262 ("samples/bpf: fixup some tools to be able to support xdp multibuffer")
> Signed-off-by: Gerhard Engleder <gerhard@engleder-embedded.com>
Reviewed-by: Andy Gospodarek <gospo@broadcom.com>

> ---
>  samples/bpf/xdp2_kern.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/samples/bpf/xdp2_kern.c b/samples/bpf/xdp2_kern.c
> index 3332ba6bb95f..67804ecf7ce3 100644
> --- a/samples/bpf/xdp2_kern.c
> +++ b/samples/bpf/xdp2_kern.c
> @@ -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;
>  	}
>  
> -- 
> 2.30.2
>
patchwork-bot+netdevbpf@kernel.org Oct. 19, 2022, 6:20 p.m. UTC | #2
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Martin KaFai Lau <martin.lau@kernel.org>:

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!
diff mbox series

Patch

diff --git a/samples/bpf/xdp2_kern.c b/samples/bpf/xdp2_kern.c
index 3332ba6bb95f..67804ecf7ce3 100644
--- a/samples/bpf/xdp2_kern.c
+++ b/samples/bpf/xdp2_kern.c
@@ -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;
 	}