Skip to content

Commit

Permalink
samples/bpf: Fix MAC address swapping in xdp2_kern
Browse files Browse the repository at this point in the history
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: 7722517 ("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>
Link: https://lore.kernel.org/r/20221015213050.65222-1-gerhard@engleder-embedded.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
  • Loading branch information
Gerhard Engleder authored and Martin KaFai Lau committed Oct 19, 2022
1 parent 05ee658 commit 7a698ed
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions samples/bpf/xdp2_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 7a698ed

Please sign in to comment.