From: Nikolay Aleksandrov <razor@blackwall.org>
To: bpf@vger.kernel.org
Cc: Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Stanislav Fomichev <sdf.kernel@gmail.com>,
Nikolay Aleksandrov <razor@blackwall.org>
Subject: [PATCH RFC bpf-next 0/4] bpf: add bpf_sk_assign support on netkit egress
Date: Tue, 24 Nov 2026 17:12:40 +0200 [thread overview]
Message-ID: <20261124151244.1423343-1-razor@blackwall.org> (raw)
Hi,
This RFC narrows the earlier egress series [1] to netkit's transmit
path. NETKIT_PASS queues the assigned skb directly to the peer's
receive backlog. NETKIT_REDIRECT clears the assignment before forwarding.
General TC egress support would require changes across the networking
stack. Many transmit paths rely on skb->sk and skb->destructor for
send-side ownership and socket write-memory accounting, and would need
to handle an assigned socket reference in place of the transmit owner.
There is a new sk_assign_skb added to bpf_net_context that is used to
record the exact skb netkit is running BPF on, bpf_sk_assign uses that
identity to allow egress assignment for that skb. It is valid only when
the new kern_flags bit is set, that is used to avoid always initializing
it to NULL in bpf_net_ctx_set.
A nested tc egress program running on a clone still gets -EOPNOTSUPP.
This series builds on Daniel's work [2] to steer netkit traffic to a
transparent proxy in the receiving namespace. The receive backlog can
outlive the transmit path's RCU read-side section, so the skb takes its
own socket reference even for SOCK_RCU_FREE listeners.
The selftests exercise the new netkit sk assign for both IPv4/IPv6 and
TCP/UDP.
Feedback is most welcome, more importantly if the approach taken in
patch 03 is acceptable.
Changes since the original posting:
- Use a new approach to limit the egress sk assign only to netkit
- Reduce the number of selftests
- Drop some unnecessary fixes of pre-existing problems
Pre-existing problems found during reviews that will be dealt with
separately:
- Receive lookup could use a prefetched socket whose protocol, family
or network namespace did not match the packet
- GRO via gro_cells can merge an assigned skb after tunnel
decapsulation and discard its socket reference without calling the
destructor
- When a reuseport program rejects an assigned UDP socket, receive can
report an error pointer as rx_sk to the kfree_skb tracepoint
- A generic XDP program, an rx_handler or a classic mirred action on
the receiving device can forward the assigned skb to another network
namespace. Generic XDP can also drop the assignment when it copies
the skb, so the packet falls back to normal socket lookup
- nsim_forward_skb() queues the skb for napi_gro_receive() without
orphaning it. GRO can discard its socket reference when merging it
Thanks,
Nik
[1] https://lore.kernel.org/bpf/20261119142231.2612515-1-razor@blackwall.org/
[2] https://github.com/cilium/linux/commits/pr/bpf-tproxy
Nikolay Aleksandrov (4):
net: track references owned by prefetched socket assignments
bpf: preserve owned socket assignments on ingress redirects
bpf: support bpf_sk_assign in netkit tx path
selftests/bpf: test netkit socket assignment to a transparent proxy
drivers/net/netkit.c | 10 +
include/linux/filter.h | 4 +
include/net/inet6_hashtables.h | 10 +-
include/net/inet_hashtables.h | 10 +-
include/net/netkit.h | 15 ++
include/net/request_sock.h | 10 +-
include/net/sock.h | 4 +-
include/uapi/linux/bpf.h | 9 +-
net/core/filter.c | 50 ++++-
net/core/sock.c | 7 +
net/netfilter/nf_queue.c | 16 +-
tools/include/uapi/linux/bpf.h | 9 +-
.../bpf/prog_tests/sk_assign_netkit.c | 189 ++++++++++++++++++
.../selftests/bpf/progs/sk_assign_netkit.c | 95 +++++++++
14 files changed, 412 insertions(+), 26 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/sk_assign_netkit.c
create mode 100644 tools/testing/selftests/bpf/progs/sk_assign_netkit.c
--
2.47.3
next reply other threads:[~2026-11-24 15:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 15:12 Nikolay Aleksandrov [this message]
2026-11-24 15:12 ` [PATCH RFC bpf-next 1/4] net: track references owned by prefetched socket assignments Nikolay Aleksandrov
2026-11-24 15:12 ` [PATCH RFC bpf-next 2/4] bpf: preserve owned socket assignments on ingress redirects Nikolay Aleksandrov
2026-11-24 15:12 ` [PATCH RFC bpf-next 3/4] bpf: support bpf_sk_assign in netkit tx path Nikolay Aleksandrov
2026-11-24 15:12 ` [PATCH RFC bpf-next 4/4] selftests/bpf: test netkit socket assignment to a transparent proxy Nikolay Aleksandrov
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=20261124151244.1423343-1-razor@blackwall.org \
--to=razor@blackwall.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf.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