From: Bobby Eshleman <bobbyeshleman@gmail.com>
To: Wei Wang <weibunny@fb.com>
Cc: netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,
Daniel Zahka <daniel.zahka@gmail.com>,
Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
David Wei <dw@davidwei.uk>, Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>
Subject: Re: [PATCH net-next 8/9] selftests/net: Add bpf skb forwarding program
Date: Tue, 24 Feb 2026 10:56:56 -0800 [thread overview]
Message-ID: <aZ30eP/ZCm7NJXVh@devvm11784.nha0.facebook.com> (raw)
In-Reply-To: <20260224002410.1553838-9-weibunny@fb.com>
On Mon, Feb 23, 2026 at 04:24:08PM -0800, Wei Wang wrote:
> Add nk_redirect.bpf.c, a BPF program that forwards skbs matching some IPv6
> prefix received on eth0 ifindex to a specified dev ifindex.
> bpf_redirect_neigh() is used to make sure neighbor lookup is performed
> and proper MAC addr is being used.
>
> Signed-off-by: Wei Wang <weibunny@fb.com>
> ---
> .../drivers/net/hw/nk_redirect.bpf.c | 60 +++++++++++++++++++
> 1 file changed, 60 insertions(+)
> create mode 100644 tools/testing/selftests/drivers/net/hw/nk_redirect.bpf.c
>
> diff --git a/tools/testing/selftests/drivers/net/hw/nk_redirect.bpf.c b/tools/testing/selftests/drivers/net/hw/nk_redirect.bpf.c
> new file mode 100644
> index 000000000000..7ac9ffd50f15
> --- /dev/null
> +++ b/tools/testing/selftests/drivers/net/hw/nk_redirect.bpf.c
> @@ -0,0 +1,60 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * BPF program for redirecting traffic using bpf_redirect_neigh().
> + * Unlike bpf_redirect() which preserves L2 headers, bpf_redirect_neigh()
> + * performs neighbor lookup and fills in the correct L2 addresses for the
> + * target interface. This is necessary when redirecting across different
> + * device types (e.g., from netdevsim to netkit).
> + */
> +#include <linux/bpf.h>
> +#include <linux/pkt_cls.h>
> +#include <linux/if_ether.h>
> +#include <linux/ipv6.h>
> +#include <linux/in6.h>
> +#include <bpf/bpf_endian.h>
> +#include <bpf/bpf_helpers.h>
> +
> +#define TC_ACT_OK 0
> +#define ETH_P_IPV6 0x86DD
> +
> +#define ctx_ptr(field) ((void *)(long)(field))
> +
> +#define v6_p64_equal(a, b) (a.s6_addr32[0] == b.s6_addr32[0] && \
> + a.s6_addr32[1] == b.s6_addr32[1])
> +
> +volatile __u32 redirect_ifindex;
> +volatile __u8 ipv6_prefix[16];
> +
> +SEC("tc/ingress")
> +int tc_redirect(struct __sk_buff *skb)
> +{
> + void *data_end = ctx_ptr(skb->data_end);
> + void *data = ctx_ptr(skb->data);
> + struct in6_addr *match_prefix;
> + struct ipv6hdr *ip6h;
> + struct ethhdr *eth;
> +
> + match_prefix = (struct in6_addr *)ipv6_prefix;
> +
> + if (skb->protocol != bpf_htons(ETH_P_IPV6))
> + return TC_ACT_OK;
> +
> + eth = data;
> + if ((void *)(eth + 1) > data_end)
> + return TC_ACT_OK;
> +
> + ip6h = data + sizeof(struct ethhdr);
> + if ((void *)(ip6h + 1) > data_end)
> + return TC_ACT_OK;
> +
> + if (!v6_p64_equal(ip6h->daddr, (*match_prefix)))
> + return TC_ACT_OK;
> +
> + /*
> + * Use bpf_redirect_neigh() to perform neighbor lookup and fill in
> + * correct L2 addresses for the target interface.
> + */
> + return bpf_redirect_neigh(redirect_ifindex, NULL, 0, 0);
> +}
> +
> +char __license[] SEC("license") = "GPL";
> --
> 2.47.3
>
Reviewed-by: Bobby Eshleman <bobbyeshleman@meta.com>
Tested-by: Bobby Eshleman <bobbyeshleman@meta.com>
next prev parent reply other threads:[~2026-02-24 18:56 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-24 0:24 [PATCH net-next 0/9] psp: Add support for dev-assoc/disassoc Wei Wang
2026-02-24 0:24 ` [PATCH net-next 2/9] selftests/net: Export Netlink class via lib.py Wei Wang
2026-02-24 0:24 ` [PATCH net-next 3/9] selftests/net: Add env for container based tests Wei Wang
2026-02-24 18:10 ` Bobby Eshleman
2026-02-28 2:30 ` Jakub Kicinski
2026-03-01 4:15 ` David Wei
2026-03-01 4:17 ` David Wei
2026-03-01 4:18 ` David Wei
2026-02-24 0:24 ` [PATCH net-next 4/9] selftests/net: Add netkit container ping test Wei Wang
2026-02-24 0:24 ` [PATCH net-next 5/9] psp: add unprivileged version of psp_device_get_locked Wei Wang
2026-02-24 0:24 ` [PATCH net-next 6/9] psp: Add new netlink cmd for dev-assoc and dev-disassoc Wei Wang
2026-02-24 0:24 ` [PATCH net-next 7/9] psp: add a new netdev event for dev unregister Wei Wang
2026-02-24 0:24 ` [PATCH net-next 8/9] selftests/net: Add bpf skb forwarding program Wei Wang
2026-02-24 18:56 ` Bobby Eshleman [this message]
2026-02-24 0:24 ` [PATCH net-next 9/9] selftest/net: psp: Add test for dev-assoc/disassoc Wei Wang
2026-02-28 2:33 ` Jakub Kicinski
[not found] ` <20260224002410.1553838-2-weibunny@fb.com>
2026-02-28 2:34 ` [PATCH net-next 1/9] selftests/net: Add bpf skb forwarding program Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aZ30eP/ZCm7NJXVh@devvm11784.nha0.facebook.com \
--to=bobbyeshleman@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=daniel.zahka@gmail.com \
--cc=davem@davemloft.net \
--cc=dw@davidwei.uk \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=weibunny@fb.com \
--cc=willemdebruijn.kernel@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox