diff options
Diffstat (limited to 'include/linux/bpf-cgroup.h')
| -rw-r--r-- | include/linux/bpf-cgroup.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h index d50c2f0a655a..f91b0f8ff3a9 100644 --- a/include/linux/bpf-cgroup.h +++ b/include/linux/bpf-cgroup.h | |||
| @@ -4,22 +4,46 @@ | |||
| 4 | 4 | ||
| 5 | #include <linux/errno.h> | 5 | #include <linux/errno.h> |
| 6 | #include <linux/jump_label.h> | 6 | #include <linux/jump_label.h> |
| 7 | #include <linux/percpu.h> | ||
| 8 | #include <linux/rbtree.h> | ||
| 7 | #include <uapi/linux/bpf.h> | 9 | #include <uapi/linux/bpf.h> |
| 8 | 10 | ||
| 9 | struct sock; | 11 | struct sock; |
| 10 | struct sockaddr; | 12 | struct sockaddr; |
| 11 | struct cgroup; | 13 | struct cgroup; |
| 12 | struct sk_buff; | 14 | struct sk_buff; |
| 15 | struct bpf_map; | ||
| 16 | struct bpf_prog; | ||
| 13 | struct bpf_sock_ops_kern; | 17 | struct bpf_sock_ops_kern; |
| 18 | struct bpf_cgroup_storage; | ||
| 14 | 19 | ||
| 15 | #ifdef CONFIG_CGROUP_BPF | 20 | #ifdef CONFIG_CGROUP_BPF |
| 16 | 21 | ||
| 17 | extern struct static_key_false cgroup_bpf_enabled_key; | 22 | extern struct static_key_false cgroup_bpf_enabled_key; |
| 18 | #define cgroup_bpf_enabled static_branch_unlikely(&cgroup_bpf_enabled_key) | 23 | #define cgroup_bpf_enabled static_branch_unlikely(&cgroup_bpf_enabled_key) |
| 19 | 24 | ||
| 25 | DECLARE_PER_CPU(void*, bpf_cgroup_storage); | ||
| 26 | |||
| 27 | struct bpf_cgroup_storage_map; | ||
| 28 | |||
| 29 | struct bpf_storage_buffer { | ||
| 30 | struct rcu_head rcu; | ||
| 31 | char data[0]; | ||
| 32 | }; | ||
| 33 | |||
| 34 | struct bpf_cgroup_storage { | ||
| 35 | struct bpf_storage_buffer *buf; | ||
| 36 | struct bpf_cgroup_storage_map *map; | ||
| 37 | struct bpf_cgroup_storage_key key; | ||
| 38 | struct list_head list; | ||
| 39 | struct rb_node node; | ||
| 40 | struct rcu_head rcu; | ||
| 41 | }; | ||
| 42 | |||
| 20 | struct bpf_prog_list { | 43 | struct bpf_prog_list { |
| 21 | struct list_head node; | 44 | struct list_head node; |
| 22 | struct bpf_prog *prog; | 45 | struct bpf_prog *prog; |
| 46 | struct bpf_cgroup_storage *storage; | ||
| 23 | }; | 47 | }; |
| 24 | 48 | ||
| 25 | struct bpf_prog_array; | 49 | struct bpf_prog_array; |
| @@ -77,6 +101,26 @@ int __cgroup_bpf_run_filter_sock_ops(struct sock *sk, | |||
| 77 | int __cgroup_bpf_check_dev_permission(short dev_type, u32 major, u32 minor, | 101 | int __cgroup_bpf_check_dev_permission(short dev_type, u32 major, u32 minor, |
| 78 | short access, enum bpf_attach_type type); | 102 | short access, enum bpf_attach_type type); |
| 79 | 103 | ||
| 104 | static inline void bpf_cgroup_storage_set(struct bpf_cgroup_storage *storage) | ||
| 105 | { | ||
| 106 | struct bpf_storage_buffer *buf; | ||
| 107 | |||
| 108 | if (!storage) | ||
| 109 | return; | ||
| 110 | |||
| 111 | buf = READ_ONCE(storage->buf); | ||
| 112 | this_cpu_write(bpf_cgroup_storage, &buf->data[0]); | ||
| 113 | } | ||
| 114 | |||
| 115 | struct bpf_cgroup_storage *bpf_cgroup_storage_alloc(struct bpf_prog *prog); | ||
| 116 | void bpf_cgroup_storage_free(struct bpf_cgroup_storage *storage); | ||
| 117 | void bpf_cgroup_storage_link(struct bpf_cgroup_storage *storage, | ||
| 118 | struct cgroup *cgroup, | ||
| 119 | enum bpf_attach_type type); | ||
| 120 | void bpf_cgroup_storage_unlink(struct bpf_cgroup_storage *storage); | ||
| 121 | int bpf_cgroup_storage_assign(struct bpf_prog *prog, struct bpf_map *map); | ||
| 122 | void bpf_cgroup_storage_release(struct bpf_prog *prog, struct bpf_map *map); | ||
| 123 | |||
| 80 | /* Wrappers for __cgroup_bpf_run_filter_skb() guarded by cgroup_bpf_enabled. */ | 124 | /* Wrappers for __cgroup_bpf_run_filter_skb() guarded by cgroup_bpf_enabled. */ |
| 81 | #define BPF_CGROUP_RUN_PROG_INET_INGRESS(sk, skb) \ | 125 | #define BPF_CGROUP_RUN_PROG_INET_INGRESS(sk, skb) \ |
| 82 | ({ \ | 126 | ({ \ |
| @@ -221,6 +265,16 @@ static inline int cgroup_bpf_prog_query(const union bpf_attr *attr, | |||
| 221 | return -EINVAL; | 265 | return -EINVAL; |
| 222 | } | 266 | } |
| 223 | 267 | ||
| 268 | static inline void bpf_cgroup_storage_set(struct bpf_cgroup_storage *storage) {} | ||
| 269 | static inline int bpf_cgroup_storage_assign(struct bpf_prog *prog, | ||
| 270 | struct bpf_map *map) { return 0; } | ||
| 271 | static inline void bpf_cgroup_storage_release(struct bpf_prog *prog, | ||
| 272 | struct bpf_map *map) {} | ||
| 273 | static inline struct bpf_cgroup_storage *bpf_cgroup_storage_alloc( | ||
| 274 | struct bpf_prog *prog) { return 0; } | ||
| 275 | static inline void bpf_cgroup_storage_free( | ||
| 276 | struct bpf_cgroup_storage *storage) {} | ||
| 277 | |||
| 224 | #define cgroup_bpf_enabled (0) | 278 | #define cgroup_bpf_enabled (0) |
| 225 | #define BPF_CGROUP_PRE_CONNECT_ENABLED(sk) (0) | 279 | #define BPF_CGROUP_PRE_CONNECT_ENABLED(sk) (0) |
| 226 | #define BPF_CGROUP_RUN_PROG_INET_INGRESS(sk,skb) ({ 0; }) | 280 | #define BPF_CGROUP_RUN_PROG_INET_INGRESS(sk,skb) ({ 0; }) |
