mbox series

[v9,bpf-next,0/9] bpf: Add socket destroy capability

Message ID 20230519225157.760788-1-aditi.ghag@isovalent.com (mailing list archive)
Headers show
Series bpf: Add socket destroy capability | expand

Message

Aditi Ghag May 19, 2023, 10:51 p.m. UTC
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/20230517175359.527917-1-aditi.ghag@isovalent.com/

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

Comments

patchwork-bot+netdevbpf@kernel.org May 20, 2023, 6 a.m. UTC | #1
Hello:

This series was applied to bpf/bpf-next.git (master)
by Martin KaFai Lau <martin.lau@kernel.org>:

On Fri, 19 May 2023 22:51:48 +0000 you wrote:
> 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/20230517175359.527917-1-aditi.ghag@isovalent.com/
> 
> [...]

Here is the summary with links:
  - [v9,bpf-next,1/9] bpf: tcp: Avoid taking fast sock lock in iterator
    https://git.kernel.org/bpf/bpf-next/c/9378096e8a65
  - [v9,bpf-next,2/9] udp: seq_file: Helper function to match socket attributes
    https://git.kernel.org/bpf/bpf-next/c/f44b1c515833
  - [v9,bpf-next,3/9] bpf: udp: Encapsulate logic to get udp table
    https://git.kernel.org/bpf/bpf-next/c/7625d2e9741c
  - [v9,bpf-next,4/9] udp: seq_file: Remove bpf_seq_afinfo from udp_iter_state
    https://git.kernel.org/bpf/bpf-next/c/e4fe1bf13e09
  - [v9,bpf-next,5/9] bpf: udp: Implement batching for sockets iterator
    https://git.kernel.org/bpf/bpf-next/c/c96dac8d369f
  - [v9,bpf-next,6/9] bpf: Add kfunc filter function to 'struct btf_kfunc_id_set'
    https://git.kernel.org/bpf/bpf-next/c/e924e80ee6a3
  - [v9,bpf-next,7/9] bpf: Add bpf_sock_destroy kfunc
    https://git.kernel.org/bpf/bpf-next/c/4ddbcb886268
  - [v9,bpf-next,8/9] selftests/bpf: Add helper to get port using getsockname
    https://git.kernel.org/bpf/bpf-next/c/176ba657e6aa
  - [v9,bpf-next,9/9] selftests/bpf: Test bpf_sock_destroy
    https://git.kernel.org/bpf/bpf-next/c/1a8bc2299f40

You are awesome, thank you!