Skip to content

bpf: Adds support for sock_ops

Lawrence Brakmo netdev 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v6 Latest16 patches 2 repliesIn review
  2. v516 patches 7 repliesSuperseded
  3. v416 patches 6 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v315 patches11 repliesSuperseded

Patches in v6 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/16bpf: BPF support for sock_opsinclude/linux/bpf-cgroup.h include/linux/bpf_types.h include/linux/filter.h +6 more+314 -30 replies
2/16bpf: program to load and attach sock_ops BPF progssamples/bpf/Makefile samples/bpf/load_sock_ops.c+100 -00 replies
3/16bpf: Support for per connection SYN/SYN-ACK RTOsinclude/net/tcp.h include/uapi/linux/bpf.h net/ipv4/tcp_input.c +1 more+17 -20 replies
4/16bpf: Sample bpf program to set SYN/SYN-ACK RTOssamples/bpf/Makefile samples/bpf/tcp_synrto_kern.c+70 -00 replies
5/16bpf: Support for setting initial receive windowinclude/net/tcp.h include/uapi/linux/bpf.h net/ipv4/tcp_minisocks.c +1 more+28 -20 replies
6/16bpf: Sample bpf program to set initial windowsamples/bpf/Makefile samples/bpf/tcp_rwnd_kern.c+70 -00 replies
7/16bpf: Add setsockopt helper function to bpfinclude/uapi/linux/bpf.h net/core/filter.c samples/bpf/bpf_helpers.h+94 -20 replies
8/16bpf: Add TCP connection BPF callbacksinclude/uapi/linux/bpf.h net/ipv4/tcp_fastopen.c net/ipv4/tcp_input.c +1 more+15 -10 replies
9/16bpf: Sample BPF program to set buffer sizessamples/bpf/Makefile samples/bpf/tcp_bufs_kern.c+87 -00 replies
10/16bpf: Add support for changing congestion controlinclude/net/tcp.h include/uapi/linux/bpf.h net/core/filter.c +4 more+58 -170 replies
11/16bpf: Sample BPF program to set congestion controlsamples/bpf/Makefile samples/bpf/tcp_cong_kern.c+84 -00 replies
12/16bpf: Adds support for setting initial cwndinclude/uapi/linux/bpf.h net/core/filter.c+19 -10 replies
13/16bpf: Sample BPF program to set initial cwndsamples/bpf/Makefile samples/bpf/tcp_iw_kern.c+89 -00 replies
14/16bpf: Adds support for setting sndcwnd clampinclude/uapi/linux/bpf.h net/core/filter.c+8 -00 replies
15/16bpf: Sample bpf program to set sndcwnd clampsamples/bpf/Makefile samples/bpf/tcp_clamp_kern.c+103 -00 replies
16/16bpf: update tools/include/uapi/linux/bpf.htools/include/uapi/linux/bpf.h+65 -10 replies

Reviews trailers per patch

4 of 16 patches have a Reviewed-by or Acked-by.

PatchDaniel BorkmannAlexei Starovoitov
1/16A-b A-b
2/16A-b
3/16
4/16A-b
5/16
6/16A-b
7/16
8/16
9/16
10/16
11/16
12/16
13/16
14/16
15/16
16/16

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

Read the v6 thread

Cover letter [PATCH net-next v6 00/16] bpf: Adds support for sock_ops

Created a new BPF program type, BPF_PROG_TYPE_SOCK_OPS, and a corresponding struct that allows BPF programs of this type to access some of the socket's fields (such as IP addresses, ports, etc.) and setting connection parameters such as buffer sizes, initial window, SYN/SYN-ACK RTOs, etc.

Unlike current BPF program types that expect to be called at a particular place in the network stack code, SOCK_OPS program can be called at different places and use an "op" field to indicate the context. There are currently two types of operations, those whose effect is through their return value and those whose effect is through the new bpf_setsocketop BPF helper function.

Example operands of the first type are:
BPF_SOCK_OPS_TIMEOUT_INIT
BPF_SOCK_OPS_RWND_INIT
BPF_SOCK_OPS_NEEDS_ECN

Example operands of the secont type are:
BPF_SOCK_OPS_TCP_CONNECT_CB
BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB
BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB

Current operands are only called during connection establishment so there should not be any BPF overheads after connection establishment. The main idea is to use connection information form both hosts, such as IP addresses and ports to allow setting of per connection parameters to optimize the connection's peformance.

Alghough there are already 3 mechanisms to set parameters (sysctls, route metrics and setsockopts), this new mechanism provides some disticnt advantages. Unlike sysctls, it can set parameters per connection. In contrast to route metrics, it can also use port numbers and information provided by a user level program. In addition, it could set parameters probabilistically for evaluation purposes (i.e. do something different on 10% of the flows and compare results with the other 90% of the flows). Also, in cases where IPv6 addresses contain geographic information, the rules to make changes based on the distance (or RTT) between the hosts are much easier than route metric rules and can be global. Finally, unlike setsockopt, it does not require application changes and it can be updated easily at any time.

It uses the existing bpf cgroups infrastructure so the programs can be attached per cgroup with full inheritance support. Although the bpf cgroup framework already contains a sock related program type (BPF_PROG_TYPE_CGROUP_SOCK), I created the new type (BPF_PROG_TYPE_SOCK_OPS) beccause the existing type expects to be called only once during the connections's lifetime. In contrast, the new program type will be called multiple times from different places in the network stack code. For example, before sending SYN and SYN-ACKs to set an appropriate timeout, when the connection is established to set congestion control, etc. As a result it has "op" field to specify the type of operation requested.

This patch set also includes sample BPF programs to demostrate the differnet features.

v2: Formatting changes, rebased to latest net-next

v3: Fixed build issues, changed socket_ops to sock_ops throught,
fixed formatting issues, removed the syscall to load sock_ops program and added functionality to use existing bpf attach and bpf detach system calls, removed reader/writer locks in sock_bpfops.c (used when saving sock_ops global program) and fixed missing module refcount increment.

v4: Removed global sock_ops program and instead used existing cgroup bpf
infrastructure to support a new BPF_CGROUP_ATTCH type.

v5: fixed kbuild warning happening in bpf-cgroup.h
removed automatic converstion to host byte order from some sock_ops
fields (ipv4 and ipv6 addresses, remote port)
Added conversion to host byte order in some of the sample programs Added to sample BPF program comments about using load_sock_ops to load Removed is_req_sock field from bpf_sock_ops_kern and related places,
using sk_fullsock() instead.

v6: fixes to BPF helper function setsockopt (possible NULL deferencing, etc.)

Consists of the following patches:

 include/linux/bpf-cgroup.h     |  18 +++
 include/linux/bpf_types.h      |   1 +
 include/linux/filter.h         |   9 ++
 include/net/tcp.h              |  66 ++++++++++-
 include/uapi/linux/bpf.h       |  68 +++++++++++-
 kernel/bpf/cgroup.c            |  37 ++++++
 kernel/bpf/syscall.c           |   5 +
 net/core/filter.c              | 284 +++++++++++++++++++++++++++++++++++++++++++++++
 net/ipv4/tcp.c                 |   2 +-
 net/ipv4/tcp_cong.c            |  32 ++++--
 net/ipv4/tcp_fastopen.c        |   1 +
 net/ipv4/tcp_input.c           |   9 +-
 net/ipv4/tcp_minisocks.c       |   9 +-
 net/ipv4/tcp_output.c          |  18 ++-
 samples/bpf/Makefile           |   9 ++
 samples/bpf/bpf_helpers.h      |   3 +
 samples/bpf/bpf_load.c         |  13 ++-
 samples/bpf/load_sock_ops.c    |  97 ++++++++++++++++                     
 samples/bpf/tcp_bufs_kern.c    |  86 ++++++++++++++
 samples/bpf/tcp_clamp_kern.c   | 102 +++++++++++++++++
 samples/bpf/tcp_cong_kern.c    |  83 ++++++++++++++
 samples/bpf/tcp_iw_kern.c      |  88 +++++++++++++++
 samples/bpf/tcp_rwnd_kern.c    |  69 ++++++++++++
 samples/bpf/tcp_synrto_kern.c  |  69 ++++++++++++
 tools/include/uapi/linux/bpf.h |  66 ++++++++++-
 25 files changed, 1218 insertions(+), 26 deletions(-)