selftests/bpf: Add tests for {set|get} socket option from setsockopt BPF
authorPrankur Gupta <prankgup@fb.com>
Tue, 17 Aug 2021 22:42:21 +0000 (15:42 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 19 Aug 2021 23:10:01 +0000 (01:10 +0200)
commitf2a6ee924d26527dc55a745dc917a820f34e64e5
tree7d2492472f5309adea8622ef4bca5e33ccc657dd
parent2c531639deb5e3ddfd6e8123b82052b2d9fbc6e5
selftests/bpf: Add tests for {set|get} socket option from setsockopt BPF

Adding selftests for the newly added functionality to call bpf_setsockopt()
and bpf_getsockopt() from setsockopt BPF programs.

Test Details:

1. BPF Program

   Checks for changes in IPV6_TCLASS(SOL_IPV6) via setsockopt
   If the cca for the socket is not cubic do nothing
   If the newly set value for IPV6_TCLASS is 45 (0x2d) (as per our use-case)
   then change the cc from cubic to reno

2. User Space Program

   Creates an AF_INET6 socket and set the cca for that to be "cubic"
   Attach the program and set the IPV6_TCLASS to 0x2d using setsockopt
   Verify the cca for the socket changed to reno

Signed-off-by: Prankur Gupta <prankgup@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Song Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20210817224221.3257826-3-prankgup@fb.com
tools/testing/selftests/bpf/bpf_tcp_helpers.h
tools/testing/selftests/bpf/prog_tests/sockopt_qos_to_cc.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/sockopt_qos_to_cc.c [new file with mode: 0644]