BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bobby Eshleman" <bobbyeshleman@gmail.com>
Cc: linux-rdma@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH net-next v3 7/8] selftests: drv-net: add primary_rx_redirect support to NetDrvContEnv
Date: Fri, 30 Oct 2026 04:53:58 +0000	[thread overview]
Message-ID: <sashiko-outbox-190387@kernel.org> (raw)
In-Reply-To: <20260507-tcp-dm-netkit-v3-7-52821445867c@meta.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] Hardcoded little-endian byte order for BPF map values breaks tests on big-endian architectures.
- [Low] BPF program fails to account for IPv6 extension headers, potentially misrouting ICMPv6 packets.
- [Low] Unsafe dictionary access when parsing `tc filter show` output can lead to a `KeyError`.
--

commit 431500c080b55b59605689dc687523876de45d23
Author: Bobby Eshleman <bobbyeshleman@meta.com>

selftests: drv-net: add primary_rx_redirect support to NetDrvContEnv

This commit adds a BPF program and Python harness support to redirect RX
traffic from the host netkit interface to the physical NIC. It skips ICMPv6
packets so neighbor discovery continues to work locally. It also extracts map
ID lookups into a reusable helper.

> diff --git a/tools/testing/selftests/drivers/net/hw/nk_primary_rx_redirect.bpf.c b/tools/testing/selftests/drivers/net/hw/nk_primary_rx_redirect.bpf.c
> new file mode 100644
> --- /dev/null
> +++ b/tools/testing/selftests/drivers/net/hw/nk_primary_rx_redirect.bpf.c

[ ... ]

> +	ip6h = data + sizeof(struct ethhdr);
> +	if ((void *)(ip6h + 1) > data_end)
> +		return TC_ACT_OK;
> +
> +	if (ip6h->nexthdr == IPPROTO_ICMPV6)
> +		return TC_ACT_OK;

Will this check miss ICMPv6 packets if the IPv6 packet contains extension
headers?

For example, Multicast Listener Discovery packets use the Hop-by-Hop Options
header where nexthdr is 0. For these packets, ip6h->nexthdr won't equal
IPPROTO_ICMPV6 here, causing them to be incorrectly redirected to the
physical NIC instead of being processed by the host netkit interface.

> +
> +	return bpf_redirect_neigh(phys_ifindex, NULL, 0, 0);
> +}

[ ... ]

> diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py
> index 409b419222454..af8e1de8ed7b1 100644
> --- a/tools/testing/selftests/drivers/net/lib/py/env.py
> +++ b/tools/testing/selftests/drivers/net/lib/py/env.py

[ ... ]

> +    def _attach_primary_rx_redirect_bpf(self):
> +        """Attach BPF redirect program on the primary netkit ingress."""

[ ... ]

> +        filters = json.loads(
> +            cmd(f"tc -j filter show dev {self._nk_host_ifname} ingress").stdout)
> +        redirect_prog_id = None
> +        for bpf in filters:
> +            if 'options' not in bpf:
> +                continue
> +            if bpf['options']['bpf_name'].startswith('nk_primary_rx_redirect'):
> +                redirect_prog_id = bpf['options']['prog']['id']
> +                break

Could this throw a KeyError if a non-BPF filter is present on the interface?

Other filter types, such as u32 or matchall, might have an options dictionary
but lack the bpf_name key. Using .get('bpf_name', '') might be a safer way
to check the prefix.

> +        if redirect_prog_id is None:
> +            raise Exception("Failed to get primary RX redirect BPF prog ID")
> +
> +        bss_map_id = self._find_bss_map_id(redirect_prog_id)
> +        phys_ifindex_bytes = self.ifindex.to_bytes(4, byteorder='little')

Will hardcoding the byteorder to little break this test on big-endian
architectures?

BPF programs access memory using host-native byte order. Writing a
little-endian value via bpftool on a big-endian system like s390x might
cause the BPF program to read an incorrect ifindex, leading to a failure
in the bpf_redirect_neigh() call.

> +        value_hex = ' '.join(f'{b:02x}' for b in phys_ifindex_bytes)
> +        bpftool(f"map update id {bss_map_id} key hex 00 00 00 00 value hex {value_hex}")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260507-tcp-dm-netkit-v3-0-52821445867c@meta.com?part=7

  parent reply	other threads:[~2026-10-30  4:53 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-08  2:27 [PATCH net-next v3 0/8] net: devmem: support devmem with netkit devices Bobby Eshleman
2026-05-08  2:27 ` [PATCH net-next v3 1/8] net: convert netmem_tx flag to enum Bobby Eshleman
2026-05-08 14:56   ` Stanislav Fomichev
2026-05-08 16:11     ` Bobby Eshleman
2026-05-08  2:27 ` [PATCH net-next v3 2/8] net: netkit: declare NETMEM_TX_NO_DMA mode Bobby Eshleman
2026-05-08 14:57   ` Stanislav Fomichev
2026-05-08  2:27 ` [PATCH net-next v3 3/8] net: devmem: support TX over NETMEM_TX_NO_DMA devices Bobby Eshleman
2026-05-08 15:01   ` Stanislav Fomichev
2026-05-08 16:19     ` Bobby Eshleman
2026-05-08 20:44     ` Jakub Kicinski
2026-05-08 20:47   ` Jakub Kicinski
2026-05-08 21:28     ` Bobby Eshleman
2026-05-08 22:27       ` Jakub Kicinski
2026-05-08 23:03         ` Bobby Eshleman
2026-10-30  4:53   ` sashiko-bot
2026-05-08  2:27 ` [PATCH net-next v3 4/8] selftests: drv-net: ncdevmem: add -n flag to skip NIC configuration Bobby Eshleman
2026-05-08 15:01   ` Stanislav Fomichev
2026-05-08  2:27 ` [PATCH net-next v3 5/8] selftests: drv-net: make attr _nk_guest_ifname public Bobby Eshleman
2026-05-08 15:01   ` Stanislav Fomichev
2026-05-08  2:27 ` [PATCH net-next v3 6/8] selftests: drv-net: refactor devmem command builders into lib module Bobby Eshleman
2026-05-08 15:03   ` Stanislav Fomichev
2026-05-08 16:19     ` Bobby Eshleman
2026-05-08  2:27 ` [PATCH net-next v3 7/8] selftests: drv-net: add primary_rx_redirect support to NetDrvContEnv Bobby Eshleman
2026-05-08 15:03   ` Stanislav Fomichev
2026-10-30  4:53   ` sashiko-bot [this message]
2026-05-08  2:27 ` [PATCH net-next v3 8/8] selftests: drv-net: add netkit devmem tests Bobby Eshleman
2026-05-08 15:03   ` Stanislav Fomichev
2026-10-30  4:53   ` sashiko-bot
2026-05-10 20:33 ` [PATCH net-next v3 0/8] net: devmem: support devmem with netkit devices Zhu Yanjun
2026-05-11 17:01   ` Bobby Eshleman

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=sashiko-outbox-190387@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bobbyeshleman@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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