Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Daniel Mack | 3007098 | 2016-11-23 16:52:26 +0100 | [diff] [blame] | 2 | #ifndef _BPF_CGROUP_H |
| 3 | #define _BPF_CGROUP_H |
| 4 | |
Roman Gushchin | 8bad74f | 2018-09-28 14:45:36 +0000 | [diff] [blame] | 5 | #include <linux/bpf.h> |
Roman Gushchin | f292b87 | 2018-07-06 14:34:29 -0700 | [diff] [blame] | 6 | #include <linux/errno.h> |
Daniel Mack | 3007098 | 2016-11-23 16:52:26 +0100 | [diff] [blame] | 7 | #include <linux/jump_label.h> |
Roman Gushchin | aa0ad5b | 2018-08-02 14:27:19 -0700 | [diff] [blame] | 8 | #include <linux/percpu.h> |
Roman Gushchin | de9cbba | 2018-08-02 14:27:18 -0700 | [diff] [blame] | 9 | #include <linux/rbtree.h> |
Daniel Mack | 3007098 | 2016-11-23 16:52:26 +0100 | [diff] [blame] | 10 | #include <uapi/linux/bpf.h> |
| 11 | |
| 12 | struct sock; |
Andrey Ignatov | 4fbac77 | 2018-03-30 15:08:02 -0700 | [diff] [blame] | 13 | struct sockaddr; |
Daniel Mack | 3007098 | 2016-11-23 16:52:26 +0100 | [diff] [blame] | 14 | struct cgroup; |
| 15 | struct sk_buff; |
Roman Gushchin | de9cbba | 2018-08-02 14:27:18 -0700 | [diff] [blame] | 16 | struct bpf_map; |
| 17 | struct bpf_prog; |
Lawrence Brakmo | 40304b2 | 2017-06-30 20:02:40 -0700 | [diff] [blame] | 18 | struct bpf_sock_ops_kern; |
Roman Gushchin | de9cbba | 2018-08-02 14:27:18 -0700 | [diff] [blame] | 19 | struct bpf_cgroup_storage; |
Daniel Mack | 3007098 | 2016-11-23 16:52:26 +0100 | [diff] [blame] | 20 | |
| 21 | #ifdef CONFIG_CGROUP_BPF |
| 22 | |
| 23 | extern struct static_key_false cgroup_bpf_enabled_key; |
| 24 | #define cgroup_bpf_enabled static_branch_unlikely(&cgroup_bpf_enabled_key) |
| 25 | |
Roman Gushchin | f294b37 | 2018-09-28 14:45:40 +0000 | [diff] [blame] | 26 | DECLARE_PER_CPU(struct bpf_cgroup_storage*, |
| 27 | bpf_cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE]); |
Roman Gushchin | 8bad74f | 2018-09-28 14:45:36 +0000 | [diff] [blame] | 28 | |
| 29 | #define for_each_cgroup_storage_type(stype) \ |
| 30 | for (stype = 0; stype < MAX_BPF_CGROUP_STORAGE_TYPE; stype++) |
Roman Gushchin | aa0ad5b | 2018-08-02 14:27:19 -0700 | [diff] [blame] | 31 | |
Roman Gushchin | de9cbba | 2018-08-02 14:27:18 -0700 | [diff] [blame] | 32 | struct bpf_cgroup_storage_map; |
| 33 | |
| 34 | struct bpf_storage_buffer { |
| 35 | struct rcu_head rcu; |
| 36 | char data[0]; |
| 37 | }; |
| 38 | |
| 39 | struct bpf_cgroup_storage { |
Roman Gushchin | b741f16 | 2018-09-28 14:45:43 +0000 | [diff] [blame] | 40 | union { |
| 41 | struct bpf_storage_buffer *buf; |
| 42 | void __percpu *percpu_buf; |
| 43 | }; |
Roman Gushchin | de9cbba | 2018-08-02 14:27:18 -0700 | [diff] [blame] | 44 | struct bpf_cgroup_storage_map *map; |
| 45 | struct bpf_cgroup_storage_key key; |
| 46 | struct list_head list; |
| 47 | struct rb_node node; |
| 48 | struct rcu_head rcu; |
| 49 | }; |
| 50 | |
Alexei Starovoitov | 324bda9e6 | 2017-10-02 22:50:21 -0700 | [diff] [blame] | 51 | struct bpf_prog_list { |
| 52 | struct list_head node; |
| 53 | struct bpf_prog *prog; |
Roman Gushchin | 8bad74f | 2018-09-28 14:45:36 +0000 | [diff] [blame] | 54 | struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE]; |
Alexei Starovoitov | 324bda9e6 | 2017-10-02 22:50:21 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | struct bpf_prog_array; |
| 58 | |
Daniel Mack | 3007098 | 2016-11-23 16:52:26 +0100 | [diff] [blame] | 59 | struct cgroup_bpf { |
Alexei Starovoitov | 324bda9e6 | 2017-10-02 22:50:21 -0700 | [diff] [blame] | 60 | /* array of effective progs in this cgroup */ |
| 61 | struct bpf_prog_array __rcu *effective[MAX_BPF_ATTACH_TYPE]; |
| 62 | |
| 63 | /* attached progs to this cgroup and attach flags |
| 64 | * when flags == 0 or BPF_F_ALLOW_OVERRIDE the progs list will |
| 65 | * have either zero or one element |
| 66 | * when BPF_F_ALLOW_MULTI the list can have up to BPF_CGROUP_MAX_PROGS |
Daniel Mack | 3007098 | 2016-11-23 16:52:26 +0100 | [diff] [blame] | 67 | */ |
Alexei Starovoitov | 324bda9e6 | 2017-10-02 22:50:21 -0700 | [diff] [blame] | 68 | struct list_head progs[MAX_BPF_ATTACH_TYPE]; |
| 69 | u32 flags[MAX_BPF_ATTACH_TYPE]; |
| 70 | |
| 71 | /* temp storage for effective prog array used by prog_attach/detach */ |
| 72 | struct bpf_prog_array __rcu *inactive; |
Daniel Mack | 3007098 | 2016-11-23 16:52:26 +0100 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | void cgroup_bpf_put(struct cgroup *cgrp); |
Alexei Starovoitov | 324bda9e6 | 2017-10-02 22:50:21 -0700 | [diff] [blame] | 76 | int cgroup_bpf_inherit(struct cgroup *cgrp); |
Daniel Mack | 3007098 | 2016-11-23 16:52:26 +0100 | [diff] [blame] | 77 | |
Alexei Starovoitov | 324bda9e6 | 2017-10-02 22:50:21 -0700 | [diff] [blame] | 78 | int __cgroup_bpf_attach(struct cgroup *cgrp, struct bpf_prog *prog, |
| 79 | enum bpf_attach_type type, u32 flags); |
| 80 | int __cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog, |
Valdis Kletnieks | 1832f4e | 2019-01-29 01:47:06 -0500 | [diff] [blame] | 81 | enum bpf_attach_type type); |
Alexei Starovoitov | 468e2f6 | 2017-10-02 22:50:22 -0700 | [diff] [blame] | 82 | int __cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr, |
| 83 | union bpf_attr __user *uattr); |
Daniel Mack | 3007098 | 2016-11-23 16:52:26 +0100 | [diff] [blame] | 84 | |
Alexei Starovoitov | 324bda9e6 | 2017-10-02 22:50:21 -0700 | [diff] [blame] | 85 | /* Wrapper for __cgroup_bpf_*() protected by cgroup_mutex */ |
| 86 | int cgroup_bpf_attach(struct cgroup *cgrp, struct bpf_prog *prog, |
| 87 | enum bpf_attach_type type, u32 flags); |
| 88 | int cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog, |
| 89 | enum bpf_attach_type type, u32 flags); |
Alexei Starovoitov | 468e2f6 | 2017-10-02 22:50:22 -0700 | [diff] [blame] | 90 | int cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr, |
| 91 | union bpf_attr __user *uattr); |
Daniel Mack | 3007098 | 2016-11-23 16:52:26 +0100 | [diff] [blame] | 92 | |
David Ahern | b2cd125 | 2016-12-01 08:48:03 -0800 | [diff] [blame] | 93 | int __cgroup_bpf_run_filter_skb(struct sock *sk, |
| 94 | struct sk_buff *skb, |
| 95 | enum bpf_attach_type type); |
Daniel Mack | 3007098 | 2016-11-23 16:52:26 +0100 | [diff] [blame] | 96 | |
David Ahern | 61023658 | 2016-12-01 08:48:04 -0800 | [diff] [blame] | 97 | int __cgroup_bpf_run_filter_sk(struct sock *sk, |
| 98 | enum bpf_attach_type type); |
| 99 | |
Andrey Ignatov | 4fbac77 | 2018-03-30 15:08:02 -0700 | [diff] [blame] | 100 | int __cgroup_bpf_run_filter_sock_addr(struct sock *sk, |
| 101 | struct sockaddr *uaddr, |
Andrey Ignatov | 1cedee1 | 2018-05-25 08:55:23 -0700 | [diff] [blame] | 102 | enum bpf_attach_type type, |
| 103 | void *t_ctx); |
Andrey Ignatov | 4fbac77 | 2018-03-30 15:08:02 -0700 | [diff] [blame] | 104 | |
Lawrence Brakmo | 40304b2 | 2017-06-30 20:02:40 -0700 | [diff] [blame] | 105 | int __cgroup_bpf_run_filter_sock_ops(struct sock *sk, |
| 106 | struct bpf_sock_ops_kern *sock_ops, |
| 107 | enum bpf_attach_type type); |
| 108 | |
Roman Gushchin | ebc614f | 2017-11-05 08:15:32 -0500 | [diff] [blame] | 109 | int __cgroup_bpf_check_dev_permission(short dev_type, u32 major, u32 minor, |
| 110 | short access, enum bpf_attach_type type); |
| 111 | |
Roman Gushchin | 8bad74f | 2018-09-28 14:45:36 +0000 | [diff] [blame] | 112 | static inline enum bpf_cgroup_storage_type cgroup_storage_type( |
| 113 | struct bpf_map *map) |
Roman Gushchin | aa0ad5b | 2018-08-02 14:27:19 -0700 | [diff] [blame] | 114 | { |
Roman Gushchin | b741f16 | 2018-09-28 14:45:43 +0000 | [diff] [blame] | 115 | if (map->map_type == BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE) |
| 116 | return BPF_CGROUP_STORAGE_PERCPU; |
| 117 | |
Roman Gushchin | 8bad74f | 2018-09-28 14:45:36 +0000 | [diff] [blame] | 118 | return BPF_CGROUP_STORAGE_SHARED; |
Roman Gushchin | aa0ad5b | 2018-08-02 14:27:19 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Roman Gushchin | 8bad74f | 2018-09-28 14:45:36 +0000 | [diff] [blame] | 121 | static inline void bpf_cgroup_storage_set(struct bpf_cgroup_storage |
| 122 | *storage[MAX_BPF_CGROUP_STORAGE_TYPE]) |
| 123 | { |
| 124 | enum bpf_cgroup_storage_type stype; |
Roman Gushchin | 8bad74f | 2018-09-28 14:45:36 +0000 | [diff] [blame] | 125 | |
Roman Gushchin | f294b37 | 2018-09-28 14:45:40 +0000 | [diff] [blame] | 126 | for_each_cgroup_storage_type(stype) |
| 127 | this_cpu_write(bpf_cgroup_storage[stype], storage[stype]); |
Roman Gushchin | 8bad74f | 2018-09-28 14:45:36 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | struct bpf_cgroup_storage *bpf_cgroup_storage_alloc(struct bpf_prog *prog, |
| 131 | enum bpf_cgroup_storage_type stype); |
Roman Gushchin | de9cbba | 2018-08-02 14:27:18 -0700 | [diff] [blame] | 132 | void bpf_cgroup_storage_free(struct bpf_cgroup_storage *storage); |
| 133 | void bpf_cgroup_storage_link(struct bpf_cgroup_storage *storage, |
| 134 | struct cgroup *cgroup, |
| 135 | enum bpf_attach_type type); |
| 136 | void bpf_cgroup_storage_unlink(struct bpf_cgroup_storage *storage); |
| 137 | int bpf_cgroup_storage_assign(struct bpf_prog *prog, struct bpf_map *map); |
| 138 | void bpf_cgroup_storage_release(struct bpf_prog *prog, struct bpf_map *map); |
| 139 | |
Roman Gushchin | b741f16 | 2018-09-28 14:45:43 +0000 | [diff] [blame] | 140 | int bpf_percpu_cgroup_storage_copy(struct bpf_map *map, void *key, void *value); |
| 141 | int bpf_percpu_cgroup_storage_update(struct bpf_map *map, void *key, |
| 142 | void *value, u64 flags); |
| 143 | |
David Ahern | b2cd125 | 2016-12-01 08:48:03 -0800 | [diff] [blame] | 144 | /* Wrappers for __cgroup_bpf_run_filter_skb() guarded by cgroup_bpf_enabled. */ |
| 145 | #define BPF_CGROUP_RUN_PROG_INET_INGRESS(sk, skb) \ |
| 146 | ({ \ |
| 147 | int __ret = 0; \ |
| 148 | if (cgroup_bpf_enabled) \ |
| 149 | __ret = __cgroup_bpf_run_filter_skb(sk, skb, \ |
| 150 | BPF_CGROUP_INET_INGRESS); \ |
| 151 | \ |
| 152 | __ret; \ |
Daniel Mack | 3007098 | 2016-11-23 16:52:26 +0100 | [diff] [blame] | 153 | }) |
| 154 | |
David Ahern | b2cd125 | 2016-12-01 08:48:03 -0800 | [diff] [blame] | 155 | #define BPF_CGROUP_RUN_PROG_INET_EGRESS(sk, skb) \ |
| 156 | ({ \ |
| 157 | int __ret = 0; \ |
| 158 | if (cgroup_bpf_enabled && sk && sk == skb->sk) { \ |
| 159 | typeof(sk) __sk = sk_to_full_sk(sk); \ |
| 160 | if (sk_fullsock(__sk)) \ |
| 161 | __ret = __cgroup_bpf_run_filter_skb(__sk, skb, \ |
| 162 | BPF_CGROUP_INET_EGRESS); \ |
| 163 | } \ |
| 164 | __ret; \ |
Daniel Mack | 3007098 | 2016-11-23 16:52:26 +0100 | [diff] [blame] | 165 | }) |
| 166 | |
Andrey Ignatov | aac3fc3 | 2018-03-30 15:08:07 -0700 | [diff] [blame] | 167 | #define BPF_CGROUP_RUN_SK_PROG(sk, type) \ |
David Ahern | 61023658 | 2016-12-01 08:48:04 -0800 | [diff] [blame] | 168 | ({ \ |
| 169 | int __ret = 0; \ |
Yafang Shao | ee07862 | 2018-02-23 14:58:41 +0800 | [diff] [blame] | 170 | if (cgroup_bpf_enabled) { \ |
Andrey Ignatov | aac3fc3 | 2018-03-30 15:08:07 -0700 | [diff] [blame] | 171 | __ret = __cgroup_bpf_run_filter_sk(sk, type); \ |
David Ahern | 61023658 | 2016-12-01 08:48:04 -0800 | [diff] [blame] | 172 | } \ |
| 173 | __ret; \ |
| 174 | }) |
| 175 | |
Andrey Ignatov | aac3fc3 | 2018-03-30 15:08:07 -0700 | [diff] [blame] | 176 | #define BPF_CGROUP_RUN_PROG_INET_SOCK(sk) \ |
| 177 | BPF_CGROUP_RUN_SK_PROG(sk, BPF_CGROUP_INET_SOCK_CREATE) |
| 178 | |
| 179 | #define BPF_CGROUP_RUN_PROG_INET4_POST_BIND(sk) \ |
| 180 | BPF_CGROUP_RUN_SK_PROG(sk, BPF_CGROUP_INET4_POST_BIND) |
| 181 | |
| 182 | #define BPF_CGROUP_RUN_PROG_INET6_POST_BIND(sk) \ |
| 183 | BPF_CGROUP_RUN_SK_PROG(sk, BPF_CGROUP_INET6_POST_BIND) |
| 184 | |
Andrey Ignatov | 4fbac77 | 2018-03-30 15:08:02 -0700 | [diff] [blame] | 185 | #define BPF_CGROUP_RUN_SA_PROG(sk, uaddr, type) \ |
| 186 | ({ \ |
| 187 | int __ret = 0; \ |
| 188 | if (cgroup_bpf_enabled) \ |
Andrey Ignatov | 1cedee1 | 2018-05-25 08:55:23 -0700 | [diff] [blame] | 189 | __ret = __cgroup_bpf_run_filter_sock_addr(sk, uaddr, type, \ |
| 190 | NULL); \ |
Andrey Ignatov | 4fbac77 | 2018-03-30 15:08:02 -0700 | [diff] [blame] | 191 | __ret; \ |
| 192 | }) |
| 193 | |
Andrey Ignatov | 1cedee1 | 2018-05-25 08:55:23 -0700 | [diff] [blame] | 194 | #define BPF_CGROUP_RUN_SA_PROG_LOCK(sk, uaddr, type, t_ctx) \ |
Andrey Ignatov | d74bad4 | 2018-03-30 15:08:05 -0700 | [diff] [blame] | 195 | ({ \ |
| 196 | int __ret = 0; \ |
| 197 | if (cgroup_bpf_enabled) { \ |
| 198 | lock_sock(sk); \ |
Andrey Ignatov | 1cedee1 | 2018-05-25 08:55:23 -0700 | [diff] [blame] | 199 | __ret = __cgroup_bpf_run_filter_sock_addr(sk, uaddr, type, \ |
| 200 | t_ctx); \ |
Andrey Ignatov | d74bad4 | 2018-03-30 15:08:05 -0700 | [diff] [blame] | 201 | release_sock(sk); \ |
| 202 | } \ |
| 203 | __ret; \ |
| 204 | }) |
| 205 | |
Andrey Ignatov | 4fbac77 | 2018-03-30 15:08:02 -0700 | [diff] [blame] | 206 | #define BPF_CGROUP_RUN_PROG_INET4_BIND(sk, uaddr) \ |
| 207 | BPF_CGROUP_RUN_SA_PROG(sk, uaddr, BPF_CGROUP_INET4_BIND) |
| 208 | |
| 209 | #define BPF_CGROUP_RUN_PROG_INET6_BIND(sk, uaddr) \ |
| 210 | BPF_CGROUP_RUN_SA_PROG(sk, uaddr, BPF_CGROUP_INET6_BIND) |
| 211 | |
Andrey Ignatov | d74bad4 | 2018-03-30 15:08:05 -0700 | [diff] [blame] | 212 | #define BPF_CGROUP_PRE_CONNECT_ENABLED(sk) (cgroup_bpf_enabled && \ |
| 213 | sk->sk_prot->pre_connect) |
| 214 | |
| 215 | #define BPF_CGROUP_RUN_PROG_INET4_CONNECT(sk, uaddr) \ |
| 216 | BPF_CGROUP_RUN_SA_PROG(sk, uaddr, BPF_CGROUP_INET4_CONNECT) |
| 217 | |
| 218 | #define BPF_CGROUP_RUN_PROG_INET6_CONNECT(sk, uaddr) \ |
| 219 | BPF_CGROUP_RUN_SA_PROG(sk, uaddr, BPF_CGROUP_INET6_CONNECT) |
| 220 | |
| 221 | #define BPF_CGROUP_RUN_PROG_INET4_CONNECT_LOCK(sk, uaddr) \ |
Andrey Ignatov | 1cedee1 | 2018-05-25 08:55:23 -0700 | [diff] [blame] | 222 | BPF_CGROUP_RUN_SA_PROG_LOCK(sk, uaddr, BPF_CGROUP_INET4_CONNECT, NULL) |
Andrey Ignatov | d74bad4 | 2018-03-30 15:08:05 -0700 | [diff] [blame] | 223 | |
| 224 | #define BPF_CGROUP_RUN_PROG_INET6_CONNECT_LOCK(sk, uaddr) \ |
Andrey Ignatov | 1cedee1 | 2018-05-25 08:55:23 -0700 | [diff] [blame] | 225 | BPF_CGROUP_RUN_SA_PROG_LOCK(sk, uaddr, BPF_CGROUP_INET6_CONNECT, NULL) |
| 226 | |
| 227 | #define BPF_CGROUP_RUN_PROG_UDP4_SENDMSG_LOCK(sk, uaddr, t_ctx) \ |
| 228 | BPF_CGROUP_RUN_SA_PROG_LOCK(sk, uaddr, BPF_CGROUP_UDP4_SENDMSG, t_ctx) |
| 229 | |
| 230 | #define BPF_CGROUP_RUN_PROG_UDP6_SENDMSG_LOCK(sk, uaddr, t_ctx) \ |
| 231 | BPF_CGROUP_RUN_SA_PROG_LOCK(sk, uaddr, BPF_CGROUP_UDP6_SENDMSG, t_ctx) |
Andrey Ignatov | d74bad4 | 2018-03-30 15:08:05 -0700 | [diff] [blame] | 232 | |
Lawrence Brakmo | 40304b2 | 2017-06-30 20:02:40 -0700 | [diff] [blame] | 233 | #define BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) \ |
| 234 | ({ \ |
| 235 | int __ret = 0; \ |
| 236 | if (cgroup_bpf_enabled && (sock_ops)->sk) { \ |
| 237 | typeof(sk) __sk = sk_to_full_sk((sock_ops)->sk); \ |
WANG Cong | df39a9f | 2017-07-17 11:42:55 -0700 | [diff] [blame] | 238 | if (__sk && sk_fullsock(__sk)) \ |
Lawrence Brakmo | 40304b2 | 2017-06-30 20:02:40 -0700 | [diff] [blame] | 239 | __ret = __cgroup_bpf_run_filter_sock_ops(__sk, \ |
| 240 | sock_ops, \ |
| 241 | BPF_CGROUP_SOCK_OPS); \ |
| 242 | } \ |
| 243 | __ret; \ |
| 244 | }) |
Roman Gushchin | ebc614f | 2017-11-05 08:15:32 -0500 | [diff] [blame] | 245 | |
| 246 | #define BPF_CGROUP_RUN_PROG_DEVICE_CGROUP(type, major, minor, access) \ |
| 247 | ({ \ |
| 248 | int __ret = 0; \ |
| 249 | if (cgroup_bpf_enabled) \ |
| 250 | __ret = __cgroup_bpf_check_dev_permission(type, major, minor, \ |
| 251 | access, \ |
| 252 | BPF_CGROUP_DEVICE); \ |
| 253 | \ |
| 254 | __ret; \ |
| 255 | }) |
Sean Young | fdb5c45 | 2018-06-19 00:04:24 +0100 | [diff] [blame] | 256 | int cgroup_bpf_prog_attach(const union bpf_attr *attr, |
| 257 | enum bpf_prog_type ptype, struct bpf_prog *prog); |
| 258 | int cgroup_bpf_prog_detach(const union bpf_attr *attr, |
| 259 | enum bpf_prog_type ptype); |
| 260 | int cgroup_bpf_prog_query(const union bpf_attr *attr, |
| 261 | union bpf_attr __user *uattr); |
Daniel Mack | 3007098 | 2016-11-23 16:52:26 +0100 | [diff] [blame] | 262 | #else |
| 263 | |
Sean Young | fdb5c45 | 2018-06-19 00:04:24 +0100 | [diff] [blame] | 264 | struct bpf_prog; |
Daniel Mack | 3007098 | 2016-11-23 16:52:26 +0100 | [diff] [blame] | 265 | struct cgroup_bpf {}; |
| 266 | static inline void cgroup_bpf_put(struct cgroup *cgrp) {} |
Alexei Starovoitov | 324bda9e6 | 2017-10-02 22:50:21 -0700 | [diff] [blame] | 267 | static inline int cgroup_bpf_inherit(struct cgroup *cgrp) { return 0; } |
Daniel Mack | 3007098 | 2016-11-23 16:52:26 +0100 | [diff] [blame] | 268 | |
Sean Young | fdb5c45 | 2018-06-19 00:04:24 +0100 | [diff] [blame] | 269 | static inline int cgroup_bpf_prog_attach(const union bpf_attr *attr, |
| 270 | enum bpf_prog_type ptype, |
| 271 | struct bpf_prog *prog) |
| 272 | { |
| 273 | return -EINVAL; |
| 274 | } |
| 275 | |
| 276 | static inline int cgroup_bpf_prog_detach(const union bpf_attr *attr, |
| 277 | enum bpf_prog_type ptype) |
| 278 | { |
| 279 | return -EINVAL; |
| 280 | } |
| 281 | |
| 282 | static inline int cgroup_bpf_prog_query(const union bpf_attr *attr, |
| 283 | union bpf_attr __user *uattr) |
| 284 | { |
| 285 | return -EINVAL; |
| 286 | } |
| 287 | |
Roman Gushchin | 8bad74f | 2018-09-28 14:45:36 +0000 | [diff] [blame] | 288 | static inline void bpf_cgroup_storage_set( |
| 289 | struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE]) {} |
Roman Gushchin | de9cbba | 2018-08-02 14:27:18 -0700 | [diff] [blame] | 290 | static inline int bpf_cgroup_storage_assign(struct bpf_prog *prog, |
| 291 | struct bpf_map *map) { return 0; } |
| 292 | static inline void bpf_cgroup_storage_release(struct bpf_prog *prog, |
| 293 | struct bpf_map *map) {} |
| 294 | static inline struct bpf_cgroup_storage *bpf_cgroup_storage_alloc( |
Bo YU | 71b91a5 | 2019-03-08 01:45:51 -0500 | [diff] [blame^] | 295 | struct bpf_prog *prog, enum bpf_cgroup_storage_type stype) { return NULL; } |
Roman Gushchin | de9cbba | 2018-08-02 14:27:18 -0700 | [diff] [blame] | 296 | static inline void bpf_cgroup_storage_free( |
| 297 | struct bpf_cgroup_storage *storage) {} |
Roman Gushchin | b741f16 | 2018-09-28 14:45:43 +0000 | [diff] [blame] | 298 | static inline int bpf_percpu_cgroup_storage_copy(struct bpf_map *map, void *key, |
| 299 | void *value) { |
| 300 | return 0; |
| 301 | } |
| 302 | static inline int bpf_percpu_cgroup_storage_update(struct bpf_map *map, |
| 303 | void *key, void *value, u64 flags) { |
| 304 | return 0; |
| 305 | } |
Roman Gushchin | de9cbba | 2018-08-02 14:27:18 -0700 | [diff] [blame] | 306 | |
Andrey Ignatov | 13193b0 | 2018-05-25 08:55:22 -0700 | [diff] [blame] | 307 | #define cgroup_bpf_enabled (0) |
Andrey Ignatov | d74bad4 | 2018-03-30 15:08:05 -0700 | [diff] [blame] | 308 | #define BPF_CGROUP_PRE_CONNECT_ENABLED(sk) (0) |
Daniel Mack | 3007098 | 2016-11-23 16:52:26 +0100 | [diff] [blame] | 309 | #define BPF_CGROUP_RUN_PROG_INET_INGRESS(sk,skb) ({ 0; }) |
| 310 | #define BPF_CGROUP_RUN_PROG_INET_EGRESS(sk,skb) ({ 0; }) |
David Ahern | 61023658 | 2016-12-01 08:48:04 -0800 | [diff] [blame] | 311 | #define BPF_CGROUP_RUN_PROG_INET_SOCK(sk) ({ 0; }) |
Andrey Ignatov | 4fbac77 | 2018-03-30 15:08:02 -0700 | [diff] [blame] | 312 | #define BPF_CGROUP_RUN_PROG_INET4_BIND(sk, uaddr) ({ 0; }) |
| 313 | #define BPF_CGROUP_RUN_PROG_INET6_BIND(sk, uaddr) ({ 0; }) |
Andrey Ignatov | aac3fc3 | 2018-03-30 15:08:07 -0700 | [diff] [blame] | 314 | #define BPF_CGROUP_RUN_PROG_INET4_POST_BIND(sk) ({ 0; }) |
| 315 | #define BPF_CGROUP_RUN_PROG_INET6_POST_BIND(sk) ({ 0; }) |
Andrey Ignatov | d74bad4 | 2018-03-30 15:08:05 -0700 | [diff] [blame] | 316 | #define BPF_CGROUP_RUN_PROG_INET4_CONNECT(sk, uaddr) ({ 0; }) |
| 317 | #define BPF_CGROUP_RUN_PROG_INET4_CONNECT_LOCK(sk, uaddr) ({ 0; }) |
| 318 | #define BPF_CGROUP_RUN_PROG_INET6_CONNECT(sk, uaddr) ({ 0; }) |
| 319 | #define BPF_CGROUP_RUN_PROG_INET6_CONNECT_LOCK(sk, uaddr) ({ 0; }) |
Andrey Ignatov | 1cedee1 | 2018-05-25 08:55:23 -0700 | [diff] [blame] | 320 | #define BPF_CGROUP_RUN_PROG_UDP4_SENDMSG_LOCK(sk, uaddr, t_ctx) ({ 0; }) |
| 321 | #define BPF_CGROUP_RUN_PROG_UDP6_SENDMSG_LOCK(sk, uaddr, t_ctx) ({ 0; }) |
Lawrence Brakmo | 40304b2 | 2017-06-30 20:02:40 -0700 | [diff] [blame] | 322 | #define BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) ({ 0; }) |
Roman Gushchin | ebc614f | 2017-11-05 08:15:32 -0500 | [diff] [blame] | 323 | #define BPF_CGROUP_RUN_PROG_DEVICE_CGROUP(type,major,minor,access) ({ 0; }) |
Daniel Mack | 3007098 | 2016-11-23 16:52:26 +0100 | [diff] [blame] | 324 | |
Roman Gushchin | 8bad74f | 2018-09-28 14:45:36 +0000 | [diff] [blame] | 325 | #define for_each_cgroup_storage_type(stype) for (; false; ) |
| 326 | |
Daniel Mack | 3007098 | 2016-11-23 16:52:26 +0100 | [diff] [blame] | 327 | #endif /* CONFIG_CGROUP_BPF */ |
| 328 | |
| 329 | #endif /* _BPF_CGROUP_H */ |