bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next 00/13] implement bpf iterator for tcp and udp sockets
@ 2020-06-17 21:15 Yonghong Song
  2020-06-17 21:15 ` [PATCH bpf-next 01/13] bpf: add bpf_seq_afinfo in tcp_iter_state Yonghong Song
                   ` (12 more replies)
  0 siblings, 13 replies; 23+ messages in thread
From: Yonghong Song @ 2020-06-17 21:15 UTC (permalink / raw)
  To: bpf; +Cc: Alexei Starovoitov, Daniel Borkmann, kernel-team, Martin KaFai Lau

bpf iterator implments traversal of kernel data structures and these
data structures are passed to a bpf program for processing.
This gives great flexibility for users to examine kernel data
structure without using e.g. /proc/net which has limited and
fixed format.

Commit 138d0be35b14 ("net: bpf: Add netlink and ipv6_route bpf_iter targets")
implemented bpf iterators for netlink and ipv6_route.
This patch set intends to implement bpf iterators for tcp and udp.

Currently, /proc/net/tcp is used to print tcp4 stats and /proc/net/tcp6
is used to print tcp6 stats. /proc/net/udp[6] have similar usage model.
In contrast, only one tcp iterator is implemented and it is bpf program
resposibility to filter based on socket family. The same is for udp.
This will avoid another unnecessary traversal pass if users want
to check both tcp4 and tcp6.

Several helpers are also implemented in this patch
  bpf_skc_to_{tcp, tcp6, tcp_timewait, tcp_request, udp6}_sock
The argument for these helpers is not a fixed btf_id. For example,
  bpf_skc_to_tcp(struct sock_common *), or
  bpf_skc_to_tcp(struct sock *), or
  bpf_skc_to_tcp(struct inet_sock *), ...
are all valid. At runtime, the helper will check whether pointer cast
is legal or not. Please see Patch #5 for details.

Since btf_id's for both arguments and return value are known at
build time, the btf_id's are pre-computed once vmlinux btf becomes
valid. Jiri's "adding d_path helper" patch set
  https://lore.kernel.org/bpf/20200616100512.2168860-1-jolsa@kernel.org/T/
provides a way to pre-compute btf id during vmlinux build time.
This can be applied here as well. A followup patch can convert
to build time btf id computation after Jiri's patch landed.

Yonghong Song (13):
  bpf: add bpf_seq_afinfo in tcp_iter_state
  net: bpf: implement bpf iterator for tcp
  bpf: support 'X' in bpf_seq_printf() helper
  bpf: allow tracing programs to use bpf_jiffies64() helper
  bpf: add bpf_skc_to_tcp6_sock() helper
  bpf: add bpf_skc_to_{tcp,tcp_timewait,tcp_request}_sock() helpers
  bpf: add bpf_seq_afinfo in udp_iter_state
  net: bpf: implement bpf iterator for udp
  bpf: add bpf_skc_to_udp6_sock() helper
  bpf/selftests: move newer bpf_iter_* type redefining to a new header
    file
  tools/bpf: selftests: implement sample tcp/tcp6 bpf_iter programs
  tools/bpf: add udp4/udp6 bpf iterator
  bpf/selftests: add tcp/udp iterator programs to selftests

 include/linux/bpf.h                           |  14 +
 include/net/tcp.h                             |   1 +
 include/net/udp.h                             |   1 +
 include/uapi/linux/bpf.h                      |  37 ++-
 kernel/bpf/btf.c                              |  11 +
 kernel/bpf/verifier.c                         |  41 ++-
 kernel/trace/bpf_trace.c                      |  15 +-
 net/core/filter.c                             | 161 ++++++++++
 net/ipv4/tcp_ipv4.c                           | 153 +++++++++-
 net/ipv4/udp.c                                | 145 ++++++++-
 scripts/bpf_helpers_doc.py                    |  10 +
 tools/include/uapi/linux/bpf.h                |  37 ++-
 .../selftests/bpf/prog_tests/bpf_iter.c       |  68 +++++
 tools/testing/selftests/bpf/progs/bpf_iter.h  |  80 +++++
 .../selftests/bpf/progs/bpf_iter_bpf_map.c    |  18 +-
 .../selftests/bpf/progs/bpf_iter_ipv6_route.c |  18 +-
 .../selftests/bpf/progs/bpf_iter_netlink.c    |  18 +-
 .../selftests/bpf/progs/bpf_iter_task.c       |  18 +-
 .../selftests/bpf/progs/bpf_iter_task_file.c  |  20 +-
 .../selftests/bpf/progs/bpf_iter_tcp4.c       | 261 +++++++++++++++++
 .../selftests/bpf/progs/bpf_iter_tcp6.c       | 277 ++++++++++++++++++
 .../selftests/bpf/progs/bpf_iter_test_kern3.c |  17 +-
 .../selftests/bpf/progs/bpf_iter_test_kern4.c |  17 +-
 .../bpf/progs/bpf_iter_test_kern_common.h     |  18 +-
 .../selftests/bpf/progs/bpf_iter_udp4.c       |  81 +++++
 .../selftests/bpf/progs/bpf_iter_udp6.c       |  88 ++++++
 26 files changed, 1465 insertions(+), 160 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter.h
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_tcp4.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_tcp6.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_udp4.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_udp6.c

-- 
2.24.1


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

end of thread, other threads:[~2020-06-18 23:31 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-17 21:15 [PATCH bpf-next 00/13] implement bpf iterator for tcp and udp sockets Yonghong Song
2020-06-17 21:15 ` [PATCH bpf-next 01/13] bpf: add bpf_seq_afinfo in tcp_iter_state Yonghong Song
2020-06-18 18:09   ` Martin KaFai Lau
2020-06-17 21:15 ` [PATCH bpf-next 02/13] net: bpf: implement bpf iterator for tcp Yonghong Song
2020-06-18 18:52   ` Martin KaFai Lau
2020-06-17 21:15 ` [PATCH bpf-next 03/13] bpf: support 'X' in bpf_seq_printf() helper Yonghong Song
2020-06-18 18:55   ` Martin KaFai Lau
2020-06-17 21:15 ` [PATCH bpf-next 04/13] bpf: allow tracing programs to use bpf_jiffies64() helper Yonghong Song
2020-06-18 19:00   ` Martin KaFai Lau
2020-06-17 21:15 ` [PATCH bpf-next 05/13] bpf: add bpf_skc_to_tcp6_sock() helper Yonghong Song
2020-06-18 20:54   ` Martin KaFai Lau
2020-06-18 23:31     ` Yonghong Song
2020-06-17 21:15 ` [PATCH bpf-next 06/13] bpf: add bpf_skc_to_{tcp,tcp_timewait,tcp_request}_sock() helpers Yonghong Song
2020-06-17 21:15 ` [PATCH bpf-next 07/13] bpf: add bpf_seq_afinfo in udp_iter_state Yonghong Song
2020-06-17 21:15 ` [PATCH bpf-next 08/13] net: bpf: implement bpf iterator for udp Yonghong Song
2020-06-17 21:15 ` [PATCH bpf-next 09/13] bpf: add bpf_skc_to_udp6_sock() helper Yonghong Song
2020-06-17 21:15 ` [PATCH bpf-next 10/13] bpf/selftests: move newer bpf_iter_* type redefining to a new header file Yonghong Song
2020-06-17 22:47   ` Andrii Nakryiko
2020-06-17 21:15 ` [PATCH bpf-next 11/13] tools/bpf: selftests: implement sample tcp/tcp6 bpf_iter programs Yonghong Song
2020-06-17 22:51   ` Andrii Nakryiko
     [not found]     ` <ab5a131f-93c7-802b-49be-dd72085d8e56@fb.com>
2020-06-18  6:24       ` Andrii Nakryiko
2020-06-17 21:15 ` [PATCH bpf-next 12/13] tools/bpf: add udp4/udp6 bpf iterator Yonghong Song
2020-06-17 21:15 ` [PATCH bpf-next 13/13] bpf/selftests: add tcp/udp iterator programs to selftests Yonghong Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).