Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
30070984 DM |
2 | #ifndef _BPF_CGROUP_H |
3 | #define _BPF_CGROUP_H | |
4 | ||
8bad74f9 | 5 | #include <linux/bpf.h> |
f292b87d | 6 | #include <linux/errno.h> |
30070984 | 7 | #include <linux/jump_label.h> |
aa0ad5b0 | 8 | #include <linux/percpu.h> |
4bfc0bb2 | 9 | #include <linux/percpu-refcount.h> |
de9cbbaa | 10 | #include <linux/rbtree.h> |
30070984 DM |
11 | #include <uapi/linux/bpf.h> |
12 | ||
13 | struct sock; | |
4fbac77d | 14 | struct sockaddr; |
30070984 DM |
15 | struct cgroup; |
16 | struct sk_buff; | |
de9cbbaa RG |
17 | struct bpf_map; |
18 | struct bpf_prog; | |
40304b2a | 19 | struct bpf_sock_ops_kern; |
de9cbbaa | 20 | struct bpf_cgroup_storage; |
7b146ceb AI |
21 | struct ctl_table; |
22 | struct ctl_table_header; | |
30070984 DM |
23 | |
24 | #ifdef CONFIG_CGROUP_BPF | |
25 | ||
a9ed15da SF |
26 | extern struct static_key_false cgroup_bpf_enabled_key[MAX_BPF_ATTACH_TYPE]; |
27 | #define cgroup_bpf_enabled(type) static_branch_unlikely(&cgroup_bpf_enabled_key[type]) | |
30070984 | 28 | |
f294b37e RG |
29 | DECLARE_PER_CPU(struct bpf_cgroup_storage*, |
30 | bpf_cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE]); | |
8bad74f9 RG |
31 | |
32 | #define for_each_cgroup_storage_type(stype) \ | |
33 | for (stype = 0; stype < MAX_BPF_CGROUP_STORAGE_TYPE; stype++) | |
aa0ad5b0 | 34 | |
de9cbbaa RG |
35 | struct bpf_cgroup_storage_map; |
36 | ||
37 | struct bpf_storage_buffer { | |
38 | struct rcu_head rcu; | |
d7f10df8 | 39 | char data[]; |
de9cbbaa RG |
40 | }; |
41 | ||
42 | struct bpf_cgroup_storage { | |
b741f163 RG |
43 | union { |
44 | struct bpf_storage_buffer *buf; | |
45 | void __percpu *percpu_buf; | |
46 | }; | |
de9cbbaa RG |
47 | struct bpf_cgroup_storage_map *map; |
48 | struct bpf_cgroup_storage_key key; | |
7d9c3427 YZ |
49 | struct list_head list_map; |
50 | struct list_head list_cg; | |
de9cbbaa RG |
51 | struct rb_node node; |
52 | struct rcu_head rcu; | |
53 | }; | |
54 | ||
af6eea57 AN |
55 | struct bpf_cgroup_link { |
56 | struct bpf_link link; | |
57 | struct cgroup *cgroup; | |
58 | enum bpf_attach_type type; | |
59 | }; | |
60 | ||
324bda9e AS |
61 | struct bpf_prog_list { |
62 | struct list_head node; | |
63 | struct bpf_prog *prog; | |
af6eea57 | 64 | struct bpf_cgroup_link *link; |
8bad74f9 | 65 | struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE]; |
324bda9e AS |
66 | }; |
67 | ||
68 | struct bpf_prog_array; | |
69 | ||
30070984 | 70 | struct cgroup_bpf { |
324bda9e AS |
71 | /* array of effective progs in this cgroup */ |
72 | struct bpf_prog_array __rcu *effective[MAX_BPF_ATTACH_TYPE]; | |
73 | ||
74 | /* attached progs to this cgroup and attach flags | |
75 | * when flags == 0 or BPF_F_ALLOW_OVERRIDE the progs list will | |
76 | * have either zero or one element | |
77 | * when BPF_F_ALLOW_MULTI the list can have up to BPF_CGROUP_MAX_PROGS | |
30070984 | 78 | */ |
324bda9e AS |
79 | struct list_head progs[MAX_BPF_ATTACH_TYPE]; |
80 | u32 flags[MAX_BPF_ATTACH_TYPE]; | |
81 | ||
7d9c3427 YZ |
82 | /* list of cgroup shared storages */ |
83 | struct list_head storages; | |
84 | ||
324bda9e | 85 | /* temp storage for effective prog array used by prog_attach/detach */ |
dbcc1ba2 | 86 | struct bpf_prog_array *inactive; |
4bfc0bb2 RG |
87 | |
88 | /* reference counter used to detach bpf programs after cgroup removal */ | |
89 | struct percpu_ref refcnt; | |
90 | ||
91 | /* cgroup_bpf is released using a work queue */ | |
92 | struct work_struct release_work; | |
30070984 DM |
93 | }; |
94 | ||
324bda9e | 95 | int cgroup_bpf_inherit(struct cgroup *cgrp); |
4bfc0bb2 | 96 | void cgroup_bpf_offline(struct cgroup *cgrp); |
30070984 | 97 | |
af6eea57 AN |
98 | int __cgroup_bpf_attach(struct cgroup *cgrp, |
99 | struct bpf_prog *prog, struct bpf_prog *replace_prog, | |
100 | struct bpf_cgroup_link *link, | |
324bda9e AS |
101 | enum bpf_attach_type type, u32 flags); |
102 | int __cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog, | |
af6eea57 | 103 | struct bpf_cgroup_link *link, |
1832f4ef | 104 | enum bpf_attach_type type); |
468e2f64 AS |
105 | int __cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr, |
106 | union bpf_attr __user *uattr); | |
30070984 | 107 | |
324bda9e | 108 | /* Wrapper for __cgroup_bpf_*() protected by cgroup_mutex */ |
af6eea57 AN |
109 | int cgroup_bpf_attach(struct cgroup *cgrp, |
110 | struct bpf_prog *prog, struct bpf_prog *replace_prog, | |
111 | struct bpf_cgroup_link *link, enum bpf_attach_type type, | |
7dd68b32 | 112 | u32 flags); |
324bda9e | 113 | int cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog, |
af6eea57 | 114 | enum bpf_attach_type type); |
468e2f64 AS |
115 | int cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr, |
116 | union bpf_attr __user *uattr); | |
30070984 | 117 | |
b2cd1257 DA |
118 | int __cgroup_bpf_run_filter_skb(struct sock *sk, |
119 | struct sk_buff *skb, | |
120 | enum bpf_attach_type type); | |
121 | ||
61023658 DA |
122 | int __cgroup_bpf_run_filter_sk(struct sock *sk, |
123 | enum bpf_attach_type type); | |
124 | ||
4fbac77d AI |
125 | int __cgroup_bpf_run_filter_sock_addr(struct sock *sk, |
126 | struct sockaddr *uaddr, | |
1cedee13 AI |
127 | enum bpf_attach_type type, |
128 | void *t_ctx); | |
4fbac77d | 129 | |
40304b2a LB |
130 | int __cgroup_bpf_run_filter_sock_ops(struct sock *sk, |
131 | struct bpf_sock_ops_kern *sock_ops, | |
132 | enum bpf_attach_type type); | |
133 | ||
ebc614f6 RG |
134 | int __cgroup_bpf_check_dev_permission(short dev_type, u32 major, u32 minor, |
135 | short access, enum bpf_attach_type type); | |
136 | ||
7b146ceb AI |
137 | int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head, |
138 | struct ctl_table *table, int write, | |
4bd6a735 | 139 | char **buf, size_t *pcount, loff_t *ppos, |
e1550bfe | 140 | enum bpf_attach_type type); |
7b146ceb | 141 | |
0d01da6a SF |
142 | int __cgroup_bpf_run_filter_setsockopt(struct sock *sock, int *level, |
143 | int *optname, char __user *optval, | |
144 | int *optlen, char **kernel_optval); | |
145 | int __cgroup_bpf_run_filter_getsockopt(struct sock *sk, int level, | |
146 | int optname, char __user *optval, | |
147 | int __user *optlen, int max_optlen, | |
148 | int retval); | |
149 | ||
9cacf81f SF |
150 | int __cgroup_bpf_run_filter_getsockopt_kern(struct sock *sk, int level, |
151 | int optname, void *optval, | |
152 | int *optlen, int retval); | |
153 | ||
8bad74f9 RG |
154 | static inline enum bpf_cgroup_storage_type cgroup_storage_type( |
155 | struct bpf_map *map) | |
aa0ad5b0 | 156 | { |
b741f163 RG |
157 | if (map->map_type == BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE) |
158 | return BPF_CGROUP_STORAGE_PERCPU; | |
159 | ||
8bad74f9 RG |
160 | return BPF_CGROUP_STORAGE_SHARED; |
161 | } | |
162 | ||
163 | static inline void bpf_cgroup_storage_set(struct bpf_cgroup_storage | |
164 | *storage[MAX_BPF_CGROUP_STORAGE_TYPE]) | |
165 | { | |
166 | enum bpf_cgroup_storage_type stype; | |
aa0ad5b0 | 167 | |
f294b37e RG |
168 | for_each_cgroup_storage_type(stype) |
169 | this_cpu_write(bpf_cgroup_storage[stype], storage[stype]); | |
aa0ad5b0 RG |
170 | } |
171 | ||
7d9c3427 YZ |
172 | struct bpf_cgroup_storage * |
173 | cgroup_storage_lookup(struct bpf_cgroup_storage_map *map, | |
174 | void *key, bool locked); | |
8bad74f9 RG |
175 | struct bpf_cgroup_storage *bpf_cgroup_storage_alloc(struct bpf_prog *prog, |
176 | enum bpf_cgroup_storage_type stype); | |
de9cbbaa RG |
177 | void bpf_cgroup_storage_free(struct bpf_cgroup_storage *storage); |
178 | void bpf_cgroup_storage_link(struct bpf_cgroup_storage *storage, | |
179 | struct cgroup *cgroup, | |
180 | enum bpf_attach_type type); | |
181 | void bpf_cgroup_storage_unlink(struct bpf_cgroup_storage *storage); | |
e4730423 | 182 | int bpf_cgroup_storage_assign(struct bpf_prog_aux *aux, struct bpf_map *map); |
de9cbbaa | 183 | |
b741f163 RG |
184 | int bpf_percpu_cgroup_storage_copy(struct bpf_map *map, void *key, void *value); |
185 | int bpf_percpu_cgroup_storage_update(struct bpf_map *map, void *key, | |
186 | void *value, u64 flags); | |
187 | ||
b2cd1257 DA |
188 | /* Wrappers for __cgroup_bpf_run_filter_skb() guarded by cgroup_bpf_enabled. */ |
189 | #define BPF_CGROUP_RUN_PROG_INET_INGRESS(sk, skb) \ | |
190 | ({ \ | |
191 | int __ret = 0; \ | |
a9ed15da | 192 | if (cgroup_bpf_enabled(BPF_CGROUP_INET_INGRESS)) \ |
b2cd1257 DA |
193 | __ret = __cgroup_bpf_run_filter_skb(sk, skb, \ |
194 | BPF_CGROUP_INET_INGRESS); \ | |
195 | \ | |
196 | __ret; \ | |
30070984 DM |
197 | }) |
198 | ||
b2cd1257 DA |
199 | #define BPF_CGROUP_RUN_PROG_INET_EGRESS(sk, skb) \ |
200 | ({ \ | |
201 | int __ret = 0; \ | |
a9ed15da | 202 | if (cgroup_bpf_enabled(BPF_CGROUP_INET_EGRESS) && sk && sk == skb->sk) { \ |
b2cd1257 DA |
203 | typeof(sk) __sk = sk_to_full_sk(sk); \ |
204 | if (sk_fullsock(__sk)) \ | |
205 | __ret = __cgroup_bpf_run_filter_skb(__sk, skb, \ | |
206 | BPF_CGROUP_INET_EGRESS); \ | |
207 | } \ | |
208 | __ret; \ | |
30070984 DM |
209 | }) |
210 | ||
aac3fc32 | 211 | #define BPF_CGROUP_RUN_SK_PROG(sk, type) \ |
61023658 DA |
212 | ({ \ |
213 | int __ret = 0; \ | |
a9ed15da | 214 | if (cgroup_bpf_enabled(type)) { \ |
aac3fc32 | 215 | __ret = __cgroup_bpf_run_filter_sk(sk, type); \ |
61023658 DA |
216 | } \ |
217 | __ret; \ | |
218 | }) | |
219 | ||
aac3fc32 AI |
220 | #define BPF_CGROUP_RUN_PROG_INET_SOCK(sk) \ |
221 | BPF_CGROUP_RUN_SK_PROG(sk, BPF_CGROUP_INET_SOCK_CREATE) | |
222 | ||
f5836749 SF |
223 | #define BPF_CGROUP_RUN_PROG_INET_SOCK_RELEASE(sk) \ |
224 | BPF_CGROUP_RUN_SK_PROG(sk, BPF_CGROUP_INET_SOCK_RELEASE) | |
225 | ||
aac3fc32 AI |
226 | #define BPF_CGROUP_RUN_PROG_INET4_POST_BIND(sk) \ |
227 | BPF_CGROUP_RUN_SK_PROG(sk, BPF_CGROUP_INET4_POST_BIND) | |
228 | ||
229 | #define BPF_CGROUP_RUN_PROG_INET6_POST_BIND(sk) \ | |
230 | BPF_CGROUP_RUN_SK_PROG(sk, BPF_CGROUP_INET6_POST_BIND) | |
231 | ||
4fbac77d AI |
232 | #define BPF_CGROUP_RUN_SA_PROG(sk, uaddr, type) \ |
233 | ({ \ | |
234 | int __ret = 0; \ | |
a9ed15da | 235 | if (cgroup_bpf_enabled(type)) \ |
1cedee13 AI |
236 | __ret = __cgroup_bpf_run_filter_sock_addr(sk, uaddr, type, \ |
237 | NULL); \ | |
4fbac77d AI |
238 | __ret; \ |
239 | }) | |
240 | ||
1cedee13 | 241 | #define BPF_CGROUP_RUN_SA_PROG_LOCK(sk, uaddr, type, t_ctx) \ |
d74bad4e AI |
242 | ({ \ |
243 | int __ret = 0; \ | |
a9ed15da | 244 | if (cgroup_bpf_enabled(type)) { \ |
d74bad4e | 245 | lock_sock(sk); \ |
1cedee13 AI |
246 | __ret = __cgroup_bpf_run_filter_sock_addr(sk, uaddr, type, \ |
247 | t_ctx); \ | |
d74bad4e AI |
248 | release_sock(sk); \ |
249 | } \ | |
250 | __ret; \ | |
251 | }) | |
252 | ||
427167c0 SF |
253 | #define BPF_CGROUP_RUN_PROG_INET4_BIND_LOCK(sk, uaddr) \ |
254 | BPF_CGROUP_RUN_SA_PROG_LOCK(sk, uaddr, BPF_CGROUP_INET4_BIND, NULL) | |
4fbac77d | 255 | |
427167c0 SF |
256 | #define BPF_CGROUP_RUN_PROG_INET6_BIND_LOCK(sk, uaddr) \ |
257 | BPF_CGROUP_RUN_SA_PROG_LOCK(sk, uaddr, BPF_CGROUP_INET6_BIND, NULL) | |
4fbac77d | 258 | |
a9ed15da SF |
259 | #define BPF_CGROUP_PRE_CONNECT_ENABLED(sk) \ |
260 | ((cgroup_bpf_enabled(BPF_CGROUP_INET4_CONNECT) || \ | |
261 | cgroup_bpf_enabled(BPF_CGROUP_INET6_CONNECT)) && \ | |
262 | (sk)->sk_prot->pre_connect) | |
d74bad4e AI |
263 | |
264 | #define BPF_CGROUP_RUN_PROG_INET4_CONNECT(sk, uaddr) \ | |
265 | BPF_CGROUP_RUN_SA_PROG(sk, uaddr, BPF_CGROUP_INET4_CONNECT) | |
266 | ||
267 | #define BPF_CGROUP_RUN_PROG_INET6_CONNECT(sk, uaddr) \ | |
268 | BPF_CGROUP_RUN_SA_PROG(sk, uaddr, BPF_CGROUP_INET6_CONNECT) | |
269 | ||
270 | #define BPF_CGROUP_RUN_PROG_INET4_CONNECT_LOCK(sk, uaddr) \ | |
1cedee13 | 271 | BPF_CGROUP_RUN_SA_PROG_LOCK(sk, uaddr, BPF_CGROUP_INET4_CONNECT, NULL) |
d74bad4e AI |
272 | |
273 | #define BPF_CGROUP_RUN_PROG_INET6_CONNECT_LOCK(sk, uaddr) \ | |
1cedee13 AI |
274 | BPF_CGROUP_RUN_SA_PROG_LOCK(sk, uaddr, BPF_CGROUP_INET6_CONNECT, NULL) |
275 | ||
276 | #define BPF_CGROUP_RUN_PROG_UDP4_SENDMSG_LOCK(sk, uaddr, t_ctx) \ | |
277 | BPF_CGROUP_RUN_SA_PROG_LOCK(sk, uaddr, BPF_CGROUP_UDP4_SENDMSG, t_ctx) | |
278 | ||
279 | #define BPF_CGROUP_RUN_PROG_UDP6_SENDMSG_LOCK(sk, uaddr, t_ctx) \ | |
280 | BPF_CGROUP_RUN_SA_PROG_LOCK(sk, uaddr, BPF_CGROUP_UDP6_SENDMSG, t_ctx) | |
d74bad4e | 281 | |
983695fa DB |
282 | #define BPF_CGROUP_RUN_PROG_UDP4_RECVMSG_LOCK(sk, uaddr) \ |
283 | BPF_CGROUP_RUN_SA_PROG_LOCK(sk, uaddr, BPF_CGROUP_UDP4_RECVMSG, NULL) | |
284 | ||
285 | #define BPF_CGROUP_RUN_PROG_UDP6_RECVMSG_LOCK(sk, uaddr) \ | |
286 | BPF_CGROUP_RUN_SA_PROG_LOCK(sk, uaddr, BPF_CGROUP_UDP6_RECVMSG, NULL) | |
287 | ||
0813a841 MKL |
288 | /* The SOCK_OPS"_SK" macro should be used when sock_ops->sk is not a |
289 | * fullsock and its parent fullsock cannot be traced by | |
290 | * sk_to_full_sk(). | |
291 | * | |
292 | * e.g. sock_ops->sk is a request_sock and it is under syncookie mode. | |
293 | * Its listener-sk is not attached to the rsk_listener. | |
294 | * In this case, the caller holds the listener-sk (unlocked), | |
295 | * set its sock_ops->sk to req_sk, and call this SOCK_OPS"_SK" with | |
296 | * the listener-sk such that the cgroup-bpf-progs of the | |
297 | * listener-sk will be run. | |
298 | * | |
299 | * Regardless of syncookie mode or not, | |
300 | * calling bpf_setsockopt on listener-sk will not make sense anyway, | |
301 | * so passing 'sock_ops->sk == req_sk' to the bpf prog is appropriate here. | |
302 | */ | |
303 | #define BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(sock_ops, sk) \ | |
304 | ({ \ | |
305 | int __ret = 0; \ | |
a9ed15da | 306 | if (cgroup_bpf_enabled(BPF_CGROUP_SOCK_OPS)) \ |
0813a841 MKL |
307 | __ret = __cgroup_bpf_run_filter_sock_ops(sk, \ |
308 | sock_ops, \ | |
309 | BPF_CGROUP_SOCK_OPS); \ | |
310 | __ret; \ | |
311 | }) | |
312 | ||
40304b2a LB |
313 | #define BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) \ |
314 | ({ \ | |
315 | int __ret = 0; \ | |
a9ed15da | 316 | if (cgroup_bpf_enabled(BPF_CGROUP_SOCK_OPS) && (sock_ops)->sk) { \ |
40304b2a | 317 | typeof(sk) __sk = sk_to_full_sk((sock_ops)->sk); \ |
df39a9f1 | 318 | if (__sk && sk_fullsock(__sk)) \ |
40304b2a LB |
319 | __ret = __cgroup_bpf_run_filter_sock_ops(__sk, \ |
320 | sock_ops, \ | |
321 | BPF_CGROUP_SOCK_OPS); \ | |
322 | } \ | |
323 | __ret; \ | |
324 | }) | |
ebc614f6 RG |
325 | |
326 | #define BPF_CGROUP_RUN_PROG_DEVICE_CGROUP(type, major, minor, access) \ | |
327 | ({ \ | |
328 | int __ret = 0; \ | |
a9ed15da | 329 | if (cgroup_bpf_enabled(BPF_CGROUP_DEVICE)) \ |
ebc614f6 RG |
330 | __ret = __cgroup_bpf_check_dev_permission(type, major, minor, \ |
331 | access, \ | |
332 | BPF_CGROUP_DEVICE); \ | |
333 | \ | |
334 | __ret; \ | |
335 | }) | |
7b146ceb AI |
336 | |
337 | ||
32927393 | 338 | #define BPF_CGROUP_RUN_PROG_SYSCTL(head, table, write, buf, count, pos) \ |
7b146ceb AI |
339 | ({ \ |
340 | int __ret = 0; \ | |
a9ed15da | 341 | if (cgroup_bpf_enabled(BPF_CGROUP_SYSCTL)) \ |
7b146ceb | 342 | __ret = __cgroup_bpf_run_filter_sysctl(head, table, write, \ |
32927393 | 343 | buf, count, pos, \ |
7b146ceb AI |
344 | BPF_CGROUP_SYSCTL); \ |
345 | __ret; \ | |
346 | }) | |
347 | ||
0d01da6a SF |
348 | #define BPF_CGROUP_RUN_PROG_SETSOCKOPT(sock, level, optname, optval, optlen, \ |
349 | kernel_optval) \ | |
350 | ({ \ | |
351 | int __ret = 0; \ | |
a9ed15da | 352 | if (cgroup_bpf_enabled(BPF_CGROUP_SETSOCKOPT)) \ |
0d01da6a SF |
353 | __ret = __cgroup_bpf_run_filter_setsockopt(sock, level, \ |
354 | optname, optval, \ | |
355 | optlen, \ | |
356 | kernel_optval); \ | |
357 | __ret; \ | |
358 | }) | |
359 | ||
360 | #define BPF_CGROUP_GETSOCKOPT_MAX_OPTLEN(optlen) \ | |
361 | ({ \ | |
362 | int __ret = 0; \ | |
a9ed15da | 363 | if (cgroup_bpf_enabled(BPF_CGROUP_GETSOCKOPT)) \ |
0d01da6a SF |
364 | get_user(__ret, optlen); \ |
365 | __ret; \ | |
366 | }) | |
367 | ||
368 | #define BPF_CGROUP_RUN_PROG_GETSOCKOPT(sock, level, optname, optval, optlen, \ | |
369 | max_optlen, retval) \ | |
370 | ({ \ | |
371 | int __ret = retval; \ | |
a9ed15da | 372 | if (cgroup_bpf_enabled(BPF_CGROUP_GETSOCKOPT)) \ |
9cacf81f SF |
373 | if (!(sock)->sk_prot->bpf_bypass_getsockopt || \ |
374 | !INDIRECT_CALL_INET_1((sock)->sk_prot->bpf_bypass_getsockopt, \ | |
375 | tcp_bpf_bypass_getsockopt, \ | |
376 | level, optname)) \ | |
377 | __ret = __cgroup_bpf_run_filter_getsockopt( \ | |
378 | sock, level, optname, optval, optlen, \ | |
379 | max_optlen, retval); \ | |
380 | __ret; \ | |
381 | }) | |
382 | ||
383 | #define BPF_CGROUP_RUN_PROG_GETSOCKOPT_KERN(sock, level, optname, optval, \ | |
384 | optlen, retval) \ | |
385 | ({ \ | |
386 | int __ret = retval; \ | |
a9ed15da | 387 | if (cgroup_bpf_enabled(BPF_CGROUP_GETSOCKOPT)) \ |
9cacf81f SF |
388 | __ret = __cgroup_bpf_run_filter_getsockopt_kern( \ |
389 | sock, level, optname, optval, optlen, retval); \ | |
0d01da6a SF |
390 | __ret; \ |
391 | }) | |
392 | ||
fdb5c453 SY |
393 | int cgroup_bpf_prog_attach(const union bpf_attr *attr, |
394 | enum bpf_prog_type ptype, struct bpf_prog *prog); | |
395 | int cgroup_bpf_prog_detach(const union bpf_attr *attr, | |
396 | enum bpf_prog_type ptype); | |
af6eea57 | 397 | int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog); |
fdb5c453 SY |
398 | int cgroup_bpf_prog_query(const union bpf_attr *attr, |
399 | union bpf_attr __user *uattr); | |
30070984 DM |
400 | #else |
401 | ||
fdb5c453 | 402 | struct bpf_prog; |
30070984 | 403 | struct cgroup_bpf {}; |
324bda9e | 404 | static inline int cgroup_bpf_inherit(struct cgroup *cgrp) { return 0; } |
4bfc0bb2 | 405 | static inline void cgroup_bpf_offline(struct cgroup *cgrp) {} |
30070984 | 406 | |
fdb5c453 SY |
407 | static inline int cgroup_bpf_prog_attach(const union bpf_attr *attr, |
408 | enum bpf_prog_type ptype, | |
409 | struct bpf_prog *prog) | |
410 | { | |
411 | return -EINVAL; | |
412 | } | |
413 | ||
414 | static inline int cgroup_bpf_prog_detach(const union bpf_attr *attr, | |
415 | enum bpf_prog_type ptype) | |
416 | { | |
417 | return -EINVAL; | |
418 | } | |
419 | ||
af6eea57 AN |
420 | static inline int cgroup_bpf_link_attach(const union bpf_attr *attr, |
421 | struct bpf_prog *prog) | |
422 | { | |
423 | return -EINVAL; | |
424 | } | |
425 | ||
fdb5c453 SY |
426 | static inline int cgroup_bpf_prog_query(const union bpf_attr *attr, |
427 | union bpf_attr __user *uattr) | |
428 | { | |
429 | return -EINVAL; | |
430 | } | |
431 | ||
8bad74f9 RG |
432 | static inline void bpf_cgroup_storage_set( |
433 | struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE]) {} | |
e4730423 | 434 | static inline int bpf_cgroup_storage_assign(struct bpf_prog_aux *aux, |
de9cbbaa | 435 | struct bpf_map *map) { return 0; } |
de9cbbaa | 436 | static inline struct bpf_cgroup_storage *bpf_cgroup_storage_alloc( |
71b91a50 | 437 | struct bpf_prog *prog, enum bpf_cgroup_storage_type stype) { return NULL; } |
de9cbbaa RG |
438 | static inline void bpf_cgroup_storage_free( |
439 | struct bpf_cgroup_storage *storage) {} | |
b741f163 RG |
440 | static inline int bpf_percpu_cgroup_storage_copy(struct bpf_map *map, void *key, |
441 | void *value) { | |
442 | return 0; | |
443 | } | |
444 | static inline int bpf_percpu_cgroup_storage_update(struct bpf_map *map, | |
445 | void *key, void *value, u64 flags) { | |
446 | return 0; | |
447 | } | |
de9cbbaa | 448 | |
a9ed15da | 449 | #define cgroup_bpf_enabled(type) (0) |
1b66d253 | 450 | #define BPF_CGROUP_RUN_SA_PROG_LOCK(sk, uaddr, type, t_ctx) ({ 0; }) |
d74bad4e | 451 | #define BPF_CGROUP_PRE_CONNECT_ENABLED(sk) (0) |
30070984 DM |
452 | #define BPF_CGROUP_RUN_PROG_INET_INGRESS(sk,skb) ({ 0; }) |
453 | #define BPF_CGROUP_RUN_PROG_INET_EGRESS(sk,skb) ({ 0; }) | |
61023658 | 454 | #define BPF_CGROUP_RUN_PROG_INET_SOCK(sk) ({ 0; }) |
f5836749 | 455 | #define BPF_CGROUP_RUN_PROG_INET_SOCK_RELEASE(sk) ({ 0; }) |
427167c0 SF |
456 | #define BPF_CGROUP_RUN_PROG_INET4_BIND_LOCK(sk, uaddr) ({ 0; }) |
457 | #define BPF_CGROUP_RUN_PROG_INET6_BIND_LOCK(sk, uaddr) ({ 0; }) | |
aac3fc32 AI |
458 | #define BPF_CGROUP_RUN_PROG_INET4_POST_BIND(sk) ({ 0; }) |
459 | #define BPF_CGROUP_RUN_PROG_INET6_POST_BIND(sk) ({ 0; }) | |
d74bad4e AI |
460 | #define BPF_CGROUP_RUN_PROG_INET4_CONNECT(sk, uaddr) ({ 0; }) |
461 | #define BPF_CGROUP_RUN_PROG_INET4_CONNECT_LOCK(sk, uaddr) ({ 0; }) | |
462 | #define BPF_CGROUP_RUN_PROG_INET6_CONNECT(sk, uaddr) ({ 0; }) | |
463 | #define BPF_CGROUP_RUN_PROG_INET6_CONNECT_LOCK(sk, uaddr) ({ 0; }) | |
1cedee13 AI |
464 | #define BPF_CGROUP_RUN_PROG_UDP4_SENDMSG_LOCK(sk, uaddr, t_ctx) ({ 0; }) |
465 | #define BPF_CGROUP_RUN_PROG_UDP6_SENDMSG_LOCK(sk, uaddr, t_ctx) ({ 0; }) | |
983695fa DB |
466 | #define BPF_CGROUP_RUN_PROG_UDP4_RECVMSG_LOCK(sk, uaddr) ({ 0; }) |
467 | #define BPF_CGROUP_RUN_PROG_UDP6_RECVMSG_LOCK(sk, uaddr) ({ 0; }) | |
40304b2a | 468 | #define BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) ({ 0; }) |
ebc614f6 | 469 | #define BPF_CGROUP_RUN_PROG_DEVICE_CGROUP(type,major,minor,access) ({ 0; }) |
32927393 | 470 | #define BPF_CGROUP_RUN_PROG_SYSCTL(head,table,write,buf,count,pos) ({ 0; }) |
0d01da6a SF |
471 | #define BPF_CGROUP_GETSOCKOPT_MAX_OPTLEN(optlen) ({ 0; }) |
472 | #define BPF_CGROUP_RUN_PROG_GETSOCKOPT(sock, level, optname, optval, \ | |
473 | optlen, max_optlen, retval) ({ retval; }) | |
9cacf81f SF |
474 | #define BPF_CGROUP_RUN_PROG_GETSOCKOPT_KERN(sock, level, optname, optval, \ |
475 | optlen, retval) ({ retval; }) | |
0d01da6a SF |
476 | #define BPF_CGROUP_RUN_PROG_SETSOCKOPT(sock, level, optname, optval, optlen, \ |
477 | kernel_optval) ({ 0; }) | |
30070984 | 478 | |
8bad74f9 RG |
479 | #define for_each_cgroup_storage_type(stype) for (; false; ) |
480 | ||
30070984 DM |
481 | #endif /* CONFIG_CGROUP_BPF */ |
482 | ||
483 | #endif /* _BPF_CGROUP_H */ |