diff options
author | Andrii Nakryiko <andriin@fb.com> | 2020-03-29 20:00:01 -0700 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2020-03-30 17:36:41 -0700 |
commit | 7cccee42bf76efc9de69fa2e5b8dbe58bfc8ecdf (patch) | |
tree | 1d894047fd961e9736b3a45e3bca2da53ac7a5b5 /tools/testing/selftests/bpf/progs/test_cgroup_link.c | |
parent | cc4f864bb118e0ae7bf9f4e3418eaeb083aa34f2 (diff) |
selftests/bpf: Test FD-based cgroup attachment
Add selftests to exercise FD-based cgroup BPF program attachments and their
intermixing with legacy cgroup BPF attachments. Auto-detachment and program
replacement (both unconditional and cmpxchng-like) are tested as well.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200330030001.2312810-5-andriin@fb.com
Diffstat (limited to 'tools/testing/selftests/bpf/progs/test_cgroup_link.c')
-rw-r--r-- | tools/testing/selftests/bpf/progs/test_cgroup_link.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/test_cgroup_link.c b/tools/testing/selftests/bpf/progs/test_cgroup_link.c new file mode 100644 index 000000000000..77e47b9e4446 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/test_cgroup_link.c @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2020 Facebook +#include <linux/bpf.h> +#include <bpf/bpf_helpers.h> + +int calls = 0; +int alt_calls = 0; + +SEC("cgroup_skb/egress1") +int egress(struct __sk_buff *skb) +{ + __sync_fetch_and_add(&calls, 1); + return 1; +} + +SEC("cgroup_skb/egress2") +int egress_alt(struct __sk_buff *skb) +{ + __sync_fetch_and_add(&alt_calls, 1); + return 1; +} + +char _license[] SEC("license") = "GPL"; + |