Netdev List
 help / color / mirror / Atom feed
* [PATCH RFC bpf-next 0/4] bpf: add bpf_sk_assign support on netkit egress
@ 2026-11-24 15:12 Nikolay Aleksandrov
  2026-11-24 15:12 ` [PATCH RFC bpf-next 1/4] net: track references owned by prefetched socket assignments Nikolay Aleksandrov
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Nikolay Aleksandrov @ 2026-11-24 15:12 UTC (permalink / raw)
  To: bpf
  Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev,
	Alexei Starovoitov, Daniel Borkmann, Stanislav Fomichev,
	Nikolay Aleksandrov

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-24 15:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 15:12 [PATCH RFC bpf-next 0/4] bpf: add bpf_sk_assign support on netkit egress Nikolay Aleksandrov
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox