Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _BPF_CGROUP_DEFS_H
0003 #define _BPF_CGROUP_DEFS_H
0004 
0005 #ifdef CONFIG_CGROUP_BPF
0006 
0007 #include <linux/list.h>
0008 #include <linux/percpu-refcount.h>
0009 #include <linux/workqueue.h>
0010 
0011 struct bpf_prog_array;
0012 
0013 #ifdef CONFIG_BPF_LSM
0014 /* Maximum number of concurrently attachable per-cgroup LSM hooks. */
0015 #define CGROUP_LSM_NUM 10
0016 #else
0017 #define CGROUP_LSM_NUM 0
0018 #endif
0019 
0020 enum cgroup_bpf_attach_type {
0021     CGROUP_BPF_ATTACH_TYPE_INVALID = -1,
0022     CGROUP_INET_INGRESS = 0,
0023     CGROUP_INET_EGRESS,
0024     CGROUP_INET_SOCK_CREATE,
0025     CGROUP_SOCK_OPS,
0026     CGROUP_DEVICE,
0027     CGROUP_INET4_BIND,
0028     CGROUP_INET6_BIND,
0029     CGROUP_INET4_CONNECT,
0030     CGROUP_INET6_CONNECT,
0031     CGROUP_INET4_POST_BIND,
0032     CGROUP_INET6_POST_BIND,
0033     CGROUP_UDP4_SENDMSG,
0034     CGROUP_UDP6_SENDMSG,
0035     CGROUP_SYSCTL,
0036     CGROUP_UDP4_RECVMSG,
0037     CGROUP_UDP6_RECVMSG,
0038     CGROUP_GETSOCKOPT,
0039     CGROUP_SETSOCKOPT,
0040     CGROUP_INET4_GETPEERNAME,
0041     CGROUP_INET6_GETPEERNAME,
0042     CGROUP_INET4_GETSOCKNAME,
0043     CGROUP_INET6_GETSOCKNAME,
0044     CGROUP_INET_SOCK_RELEASE,
0045     CGROUP_LSM_START,
0046     CGROUP_LSM_END = CGROUP_LSM_START + CGROUP_LSM_NUM - 1,
0047     MAX_CGROUP_BPF_ATTACH_TYPE
0048 };
0049 
0050 struct cgroup_bpf {
0051     /* array of effective progs in this cgroup */
0052     struct bpf_prog_array __rcu *effective[MAX_CGROUP_BPF_ATTACH_TYPE];
0053 
0054     /* attached progs to this cgroup and attach flags
0055      * when flags == 0 or BPF_F_ALLOW_OVERRIDE the progs list will
0056      * have either zero or one element
0057      * when BPF_F_ALLOW_MULTI the list can have up to BPF_CGROUP_MAX_PROGS
0058      */
0059     struct hlist_head progs[MAX_CGROUP_BPF_ATTACH_TYPE];
0060     u8 flags[MAX_CGROUP_BPF_ATTACH_TYPE];
0061 
0062     /* list of cgroup shared storages */
0063     struct list_head storages;
0064 
0065     /* temp storage for effective prog array used by prog_attach/detach */
0066     struct bpf_prog_array *inactive;
0067 
0068     /* reference counter used to detach bpf programs after cgroup removal */
0069     struct percpu_ref refcnt;
0070 
0071     /* cgroup_bpf is released using a work queue */
0072     struct work_struct release_work;
0073 };
0074 
0075 #else /* CONFIG_CGROUP_BPF */
0076 struct cgroup_bpf {};
0077 #endif /* CONFIG_CGROUP_BPF */
0078 
0079 #endif