Skip to content

bpf: Add socket destroy capability

Aditi Ghag bpf netdev 10 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v9 Latest9 patches 7 repliesApplied 9/9
  2. v810 patches 7 repliesSuperseded
  3. v710 patches 7 repliesSuperseded
Earlier versions · 7
VersionPostedPatchesRepliesStatus
v67 patches18 repliesSuperseded
v57 patches16 repliesSuperseded
v4 posting 2/24 patches24 repliesSuperseded
v4 posting 1/20 of 5 patches0 repliesSuperseded
v35 patches19 repliesSuperseded
v23 patches20 repliesSuperseded
v12 patches11 repliesSuperseded

v8 patch series - from the cover letter

Patches in v9 All 9 applied

#Subject and filesSizeRepliesApplied
1/9bpf: tcp: Avoid taking fast sock lock in iteratornet/ipv4/tcp_ipv4.c+2 -30 repliesApplied
2/9udp: seq_file: Helper function to match socket attributesnet/ipv4/udp.c+27 -70 repliesApplied
3/9bpf: udp: Encapsulate logic to get udp tablenet/ipv4/udp.c+12 -230 repliesApplied
4/9udp: seq_file: Remove bpf_seq_afinfo from udp_iter_stateinclude/net/udp.h net/ipv4/udp.c+7 -210 repliesApplied
5/9bpf: udp: Implement batching for sockets iteratornet/ipv4/udp.c+199 -67 repliesApplied
6/9bpf: Add kfunc filter function to 'struct btf_kfunc_id_set'include/linux/btf.h kernel/bpf/btf.c kernel/bpf/verifier.c+66 -200 repliesApplied
7/9bpf: Add bpf_sock_destroy kfuncnet/core/filter.c net/ipv4/tcp.c net/ipv4/tcp_ipv4.c +1 more+75 -70 repliesApplied
8/9selftests/bpf: Add helper to get port using getsocknametools/testing/selftests/bpf/network_helpers.c tools/testing/selftests/bpf/network_helpers.h+24 -00 repliesApplied
9/9selftests/bpf: Test bpf_sock_destroytools/testing/selftests/bpf/prog_tests/sock_destroy.c tools/testing/selftests/bpf/progs/sock_destroy_prog.c tools/testing/selftests/bpf/progs/sock_destroy_prog_fail.c+388 -00 repliesApplied

Reviews trailers per patch

1 of 9 patches has a Reviewed-by or Acked-by.

PatchYonghong SongStanislav Fomichev
1/9A-b A-b
2/9
3/9
4/9
5/9
6/9
7/9
8/9
9/9

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v9 thread

Cover letter [PATCH v9 bpf-next 0/9] bpf: Add socket destroy capability

This patch set adds the capability to destroy sockets in BPF. We plan to use the capability in Cilium to force client sockets to reconnect when their remote load-balancing backends are deleted. The other use case is on-the-fly policy enforcement where existing socket connections prevented by policies need to be terminated.

The use cases, and more details around
the selected approach were presented at LPC 2022 -
https://lpc.events/event/16/contributions/1358/.
RFC discussion -
https://lore.kernel.org/netdev/CABG=zsBEh-P4NXk23eBJw7eajB5YJeRS7oPXnTAzs=yob4EMoQ@mail.gmail.com/T/#u.
v8 patch series -
https://lore.kernel.org/bpf/[email protected]/

v9 highlights:
Address review comments:
Martin:
- Rearranged the kfunc filter patch, and added the missing break statement.
- Squashed the extended selftest/bpf patch.
Yonghong:
- Revised commit message for patch 1.

(Below notes are same as v8 patch series that are still relevant. Refer to earlier patch series versions for other notes.)
- I hit a snag while writing the kfunc where verifier complained about the sock_common type passed from TCP iterator. With kfuncs, there don't seem to be any options available to pass BTF type hints to the verifier (equivalent of ARG_PTR_TO_BTF_ID_SOCK_COMMON, as was the case with the helper). As a result, I changed the argument type of the sock_destory kfunc to sock_common.

Aditi Ghag (9):
bpf: tcp: Avoid taking fast sock lock in iterator
udp: seq_file: Helper function to match socket attributes
bpf: udp: Encapsulate logic to get udp table
udp: seq_file: Remove bpf_seq_afinfo from udp_iter_state
bpf: udp: Implement batching for sockets iterator
bpf: Add kfunc filter function to 'struct btf_kfunc_id_set'
bpf: Add bpf_sock_destroy kfunc
selftests/bpf: Add helper to get port using getsockname selftests/bpf: Test bpf_sock_destroy

 include/linux/btf.h                           |  18 +-
 include/net/udp.h                             |   1 -
 kernel/bpf/btf.c                              |  61 +++-
 kernel/bpf/verifier.c                         |   7 +-
 net/core/filter.c                             |  63 ++++
 net/ipv4/tcp.c                                |   9 +-
 net/ipv4/tcp_ipv4.c                           |   7 +-
 net/ipv4/udp.c                                | 291 +++++++++++++++---
 tools/testing/selftests/bpf/network_helpers.c |  23 ++
 tools/testing/selftests/bpf/network_helpers.h |   1 +
 .../selftests/bpf/prog_tests/sock_destroy.c   | 221 +++++++++++++
 .../selftests/bpf/progs/sock_destroy_prog.c   | 145 +++++++++
 .../bpf/progs/sock_destroy_prog_fail.c        |  22 ++
 13 files changed, 791 insertions(+), 78 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/sock_destroy.c
 create mode 100644 tools/testing/selftests/bpf/progs/sock_destroy_prog.c
 create mode 100644 tools/testing/selftests/bpf/progs/sock_destroy_prog_fail.c
Signature · 1 line
2.34.1