| From: |
| Aditi Ghag <aditi.ghag-AT-isovalent.com> |
| To: |
| bpf-AT-vger.kernel.org |
| Subject: |
| [PATCH v7 bpf-next 00/10] bpf: Add socket destroy capability |
| Date: |
| Wed, 03 May 2023 22:53:41 +0000 |
| Message-ID: |
| <20230503225351.3700208-1-aditi.ghag@isovalent.com> |
| Cc: |
| kafai-AT-fb.com, sdf-AT-google.com, aditi.ghag-AT-isovalent.com |
| Archive-link: |
| Article |
This patch 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-P4NXk23eBJw7eaj...
v6 patch series -
https://lore.kernel.org/bpf/20230418153148.2231644-1-adit...
v7 highlights:
Address review comments:
Martin:
- Refactored logic to get udp table to a separate commit.
- Addressed nits in the batching and test commits.
- Applied patch to filter and restrict the kfunc, and added a test.
Stan:
- Addressed nits in the network helper commit.
Paolo/Yonghong:
- Extended the first commit that revises locking in BPF TCP iterator
with more details.
- Fixed comment formatting.
(Below notes are same as v6 patch series that are still relevant. Refer to
earlier patch series 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 (10):
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 bpf_sock_destroy kfunc
selftests/bpf: Add helper to get port using getsockname
selftests/bpf: Test bpf_sock_destroy
bpf: Add a kfunc filter function to 'struct btf_kfunc_id_set'
selftests/bpf: Extend bpf_sock_destroy tests
include/linux/btf.h | 18 +-
include/net/udp.h | 1 -
kernel/bpf/btf.c | 59 +++-
kernel/bpf/verifier.c | 7 +-
net/core/filter.c | 66 ++++
net/ipv4/tcp.c | 10 +-
net/ipv4/tcp_ipv4.c | 5 +-
net/ipv4/udp.c | 287 +++++++++++++++---
tools/testing/selftests/bpf/network_helpers.c | 23 ++
tools/testing/selftests/bpf/network_helpers.h | 1 +
.../selftests/bpf/prog_tests/sock_destroy.c | 217 +++++++++++++
.../selftests/bpf/progs/sock_destroy_prog.c | 145 +++++++++
.../bpf/progs/sock_destroy_prog_fail.c | 22 ++
13 files changed, 785 insertions(+), 76 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
--
2.34.1