aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/bpf-cgroup.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/bpf-cgroup.h')
-rw-r--r--include/linux/bpf-cgroup.h54
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
9struct sock; 11struct sock;
10struct sockaddr; 12struct sockaddr;
11struct cgroup; 13struct cgroup;
12struct sk_buff; 14struct sk_buff;
15struct bpf_map;
16struct bpf_prog;
13struct bpf_sock_ops_kern; 17struct bpf_sock_ops_kern;
18struct bpf_cgroup_storage;
14 19
15#ifdef CONFIG_CGROUP_BPF 20#ifdef CONFIG_CGROUP_BPF
16 21
17extern struct static_key_false cgroup_bpf_enabled_key; 22extern 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
25DECLARE_PER_CPU(void*, bpf_cgroup_storage);
26
27struct bpf_cgroup_storage_map;
28
29struct bpf_storage_buffer {
30 struct rcu_head rcu;
31 char data[0];
32};
33
34struct 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
20struct bpf_prog_list { 43struct 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
25struct bpf_prog_array; 49struct bpf_prog_array;
@@ -77,6 +101,26 @@ int __cgroup_bpf_run_filter_sock_ops(struct sock *sk,
77int __cgroup_bpf_check_dev_permission(short dev_type, u32 major, u32 minor, 101int __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
104static 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
115struct bpf_cgroup_storage *bpf_cgroup_storage_alloc(struct bpf_prog *prog);
116void bpf_cgroup_storage_free(struct bpf_cgroup_storage *storage);
117void bpf_cgroup_storage_link(struct bpf_cgroup_storage *storage,
118 struct cgroup *cgroup,
119 enum bpf_attach_type type);
120void bpf_cgroup_storage_unlink(struct bpf_cgroup_storage *storage);
121int bpf_cgroup_storage_assign(struct bpf_prog *prog, struct bpf_map *map);
122void 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
268static inline void bpf_cgroup_storage_set(struct bpf_cgroup_storage *storage) {}
269static inline int bpf_cgroup_storage_assign(struct bpf_prog *prog,
270 struct bpf_map *map) { return 0; }
271static inline void bpf_cgroup_storage_release(struct bpf_prog *prog,
272 struct bpf_map *map) {}
273static inline struct bpf_cgroup_storage *bpf_cgroup_storage_alloc(
274 struct bpf_prog *prog) { return 0; }
275static 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; })