]> git.baikalelectronics.ru Git - kernel.git/commit
samples: bpf: Refactor test_cgrp2_sock2 program with libbpf
authorDaniel T. Lee <danieltimlee@gmail.com>
Tue, 24 Nov 2020 09:03:05 +0000 (09:03 +0000)
committerAndrii Nakryiko <andrii@kernel.org>
Fri, 27 Nov 2020 03:33:35 +0000 (19:33 -0800)
commit5707ad9bad7634fac32b11ac9ed0a45fdb9ff97d
treec4563673da85cde8dde280a53c94fae4591c8fde
parente3277b7649d5daba8d70b0eb6fe9957c04d9e082
samples: bpf: Refactor test_cgrp2_sock2 program with libbpf

This commit refactors the existing cgroup program with libbpf bpf
loader. The original test_cgrp2_sock2 has keeped the bpf program
attached to the cgroup hierarchy even after the exit of user program.
To implement the same functionality with libbpf, this commit uses the
BPF_LINK_PINNING to pin the link attachment even after it is closed.

Since this uses LINK instead of ATTACH, detach of bpf program from
cgroup with 'test_cgrp2_sock' is not used anymore.

The code to mount the bpf was added to the .sh file in case the bpff
was not mounted on /sys/fs/bpf. Additionally, to fix the problem that
shell script cannot find the binary object from the current path,
relative path './' has been added in front of binary.

Fixes: 2f89fc8dbd7f6 ("samples/bpf: add userspace example for prohibiting sockets")
Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20201124090310.24374-3-danieltimlee@gmail.com
samples/bpf/Makefile
samples/bpf/test_cgrp2_sock2.c
samples/bpf/test_cgrp2_sock2.sh