Skip to content

bpf: Allow bpf tcp iter to do bpf_(get|set)sockopt

Martin KaFai Lau bpf netdev 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest8 patches 12 repliesIn review
  2. v18 patches 7 repliesSuperseded

Changes in v2 from the cover letter

- Use __GFP_NOWARN in patch 6
- Add bpf_getsockopt() in patch 7 to give a symmetrical user experience. selftest in patch 8 is changed to also cover bpf_getsockopt().
- Remove CAP_NET_ADMIN check in patch 7. Tracing bpf prog has already required CAP_SYS_ADMIN or CAP_PERFMON.
- Move some def macros to bpf_tracing_net.h in patch 8

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/8tcp: seq_file: Avoid skipping sk during tcp_seek_last_posnet/ipv4/tcp_ipv4.c+3 -24 replies
2/8tcp: seq_file: Refactor net and family matchingnet/ipv4/tcp_ipv4.c+30 -380 replies
3/8bpf: tcp: seq_file: Remove bpf_seq_afinfo from tcp_iter_stateinclude/net/tcp.h net/ipv4/tcp_ipv4.c+5 -210 replies
4/8tcp: seq_file: Add listening_get_first()net/ipv4/tcp_ipv4.c+39 -200 replies
5/8tcp: seq_file: Replace listening_hash with lhash2include/net/inet_hashtables.h net/ipv4/tcp_ipv4.c+24 -170 replies
6/8bpf: tcp: bpf iter batching and lock_socknet/ipv4/tcp_ipv4.c+231 -60 replies
7/8bpf: tcp: Support bpf_(get|set)sockopt in bpf tcp iterinclude/linux/bpf.h kernel/bpf/bpf_iter.c kernel/trace/bpf_trace.c +2 more+85 -10 replies
8/8bpf: selftest: Test batching and bpf_(get|set)sockopt in bpf tcp itertools/testing/selftests/bpf/network_helpers.c tools/testing/selftests/bpf/network_helpers.h tools/testing/selftests/bpf/prog_tests/bpf_iter_setsockopt.c +2 more+384 -90 replies

Reviews trailers per patch

All 8 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchYonghong SongEric DumazetKuniyuki Iwashima
SeriesR-b A-b
1/8A-b
2/8A-b
3/8A-b
4/8A-b
5/8A-b
6/8A-b
7/8A-b
8/8A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v2 thread

Cover letter [PATCH v2 bpf-next 0/8] bpf: Allow bpf tcp iter to do bpf_(get|set)sockopt

This set is to allow bpf tcp iter to call bpf_(get|set)sockopt.

With bpf-tcp-cc, new algo rollout happens more often. Instead of restarting the applications to pick up the new tcp-cc, this set allows the bpf tcp iter to call bpf_(get|set)sockopt(TCP_CONGESTION). It is not limited to TCP_CONGESTION, the bpf tcp iter can call bpf_(get|set)sockopt() with other options. The bpf tcp iter can read into all the fields of a tcp_sock, so there is a lot of flexibility to select the desired sk to do setsockopt(), e.g. it can test for TCP_LISTEN only and leave the established connections untouched, or check the addr/port, or check the current tcp-cc name, ...etc.

Patch 1-4 are some cleanup and prep work in the tcp and bpf seq_file.

Patch 5 is to have the tcp seq_file iterate on the port+addr lhash2 instead of the port only listening_hash.

Patch 6 is to have the bpf tcp iter doing batching which then allows lock_sock. lock_sock is needed for setsockopt.

Patch 7 allows the bpf tcp iter to call bpf_(get|set)sockopt.

v2:
- Use __GFP_NOWARN in patch 6
- Add bpf_getsockopt() in patch 7 to give a symmetrical user experience. selftest in patch 8 is changed to also cover bpf_getsockopt().
- Remove CAP_NET_ADMIN check in patch 7. Tracing bpf prog has already required CAP_SYS_ADMIN or CAP_PERFMON.
- Move some def macros to bpf_tracing_net.h in patch 8

Martin KaFai Lau (8):
tcp: seq_file: Avoid skipping sk during tcp_seek_last_pos
tcp: seq_file: Refactor net and family matching
bpf: tcp: seq_file: Remove bpf_seq_afinfo from tcp_iter_state
tcp: seq_file: Add listening_get_first()
tcp: seq_file: Replace listening_hash with lhash2
bpf: tcp: bpf iter batching and lock_sock
bpf: tcp: Support bpf_(get|set)sockopt in bpf tcp iter
bpf: selftest: Test batching and bpf_(get|set)sockopt in bpf tcp iter

 include/linux/bpf.h                           |   8 +
 include/net/inet_hashtables.h                 |   6 +
 include/net/tcp.h                             |   1 -
 kernel/bpf/bpf_iter.c                         |  22 +
 kernel/trace/bpf_trace.c                      |   7 +-
 net/core/filter.c                             |  34 ++
 net/ipv4/tcp_ipv4.c                           | 410 ++++++++++++++----
 tools/testing/selftests/bpf/network_helpers.c |  85 +++-
 tools/testing/selftests/bpf/network_helpers.h |   4 +
 .../bpf/prog_tests/bpf_iter_setsockopt.c      | 226 ++++++++++
 .../selftests/bpf/progs/bpf_iter_setsockopt.c |  72 +++
 .../selftests/bpf/progs/bpf_tracing_net.h     |   6 +
 12 files changed, 784 insertions(+), 97 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_iter_setsockopt.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_setsockopt.c
Signature · 1 line
2.30.2