1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BPF_CGROUP_DEFS_H
3 #define _BPF_CGROUP_DEFS_H
5 #ifdef CONFIG_CGROUP_BPF
7 #include <linux/list.h>
8 #include <linux/percpu-refcount.h>
9 #include <linux/workqueue.h>
11 struct bpf_prog_array;
13 enum cgroup_bpf_attach_type {
14 CGROUP_BPF_ATTACH_TYPE_INVALID = -1,
15 CGROUP_INET_INGRESS = 0,
17 CGROUP_INET_SOCK_CREATE,
24 CGROUP_INET4_POST_BIND,
25 CGROUP_INET6_POST_BIND,
33 CGROUP_INET4_GETPEERNAME,
34 CGROUP_INET6_GETPEERNAME,
35 CGROUP_INET4_GETSOCKNAME,
36 CGROUP_INET6_GETSOCKNAME,
37 CGROUP_INET_SOCK_RELEASE,
38 MAX_CGROUP_BPF_ATTACH_TYPE
42 /* array of effective progs in this cgroup */
43 struct bpf_prog_array __rcu *effective[MAX_CGROUP_BPF_ATTACH_TYPE];
45 /* attached progs to this cgroup and attach flags
46 * when flags == 0 or BPF_F_ALLOW_OVERRIDE the progs list will
47 * have either zero or one element
48 * when BPF_F_ALLOW_MULTI the list can have up to BPF_CGROUP_MAX_PROGS
50 struct list_head progs[MAX_CGROUP_BPF_ATTACH_TYPE];
51 u32 flags[MAX_CGROUP_BPF_ATTACH_TYPE];
53 /* list of cgroup shared storages */
54 struct list_head storages;
56 /* temp storage for effective prog array used by prog_attach/detach */
57 struct bpf_prog_array *inactive;
59 /* reference counter used to detach bpf programs after cgroup removal */
60 struct percpu_ref refcnt;
62 /* cgroup_bpf is released using a work queue */
63 struct work_struct release_work;
66 #else /* CONFIG_CGROUP_BPF */
68 #endif /* CONFIG_CGROUP_BPF */