1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/jump_label.h>
6 #include <uapi/linux/bpf.h>
11 struct bpf_sock_ops_kern
;
13 #ifdef CONFIG_CGROUP_BPF
15 extern struct static_key_false cgroup_bpf_enabled_key
;
16 #define cgroup_bpf_enabled static_branch_unlikely(&cgroup_bpf_enabled_key)
20 * Store two sets of bpf_prog pointers, one for programs that are
21 * pinned directly to this cgroup, and one for those that are effective
22 * when this cgroup is accessed.
24 struct bpf_prog
*prog
[MAX_BPF_ATTACH_TYPE
];
25 struct bpf_prog __rcu
*effective
[MAX_BPF_ATTACH_TYPE
];
26 bool disallow_override
[MAX_BPF_ATTACH_TYPE
];
29 void cgroup_bpf_put(struct cgroup
*cgrp
);
30 void cgroup_bpf_inherit(struct cgroup
*cgrp
, struct cgroup
*parent
);
32 int __cgroup_bpf_update(struct cgroup
*cgrp
, struct cgroup
*parent
,
33 struct bpf_prog
*prog
, enum bpf_attach_type type
,
36 /* Wrapper for __cgroup_bpf_update() protected by cgroup_mutex */
37 int cgroup_bpf_update(struct cgroup
*cgrp
, struct bpf_prog
*prog
,
38 enum bpf_attach_type type
, bool overridable
);
40 int __cgroup_bpf_run_filter_skb(struct sock
*sk
,
42 enum bpf_attach_type type
);
44 int __cgroup_bpf_run_filter_sk(struct sock
*sk
,
45 enum bpf_attach_type type
);
47 int __cgroup_bpf_run_filter_sock_ops(struct sock
*sk
,
48 struct bpf_sock_ops_kern
*sock_ops
,
49 enum bpf_attach_type type
);
51 /* Wrappers for __cgroup_bpf_run_filter_skb() guarded by cgroup_bpf_enabled. */
52 #define BPF_CGROUP_RUN_PROG_INET_INGRESS(sk, skb) \
55 if (cgroup_bpf_enabled) \
56 __ret = __cgroup_bpf_run_filter_skb(sk, skb, \
57 BPF_CGROUP_INET_INGRESS); \
62 #define BPF_CGROUP_RUN_PROG_INET_EGRESS(sk, skb) \
65 if (cgroup_bpf_enabled && sk && sk == skb->sk) { \
66 typeof(sk) __sk = sk_to_full_sk(sk); \
67 if (sk_fullsock(__sk)) \
68 __ret = __cgroup_bpf_run_filter_skb(__sk, skb, \
69 BPF_CGROUP_INET_EGRESS); \
74 #define BPF_CGROUP_RUN_PROG_INET_SOCK(sk) \
77 if (cgroup_bpf_enabled && sk) { \
78 __ret = __cgroup_bpf_run_filter_sk(sk, \
79 BPF_CGROUP_INET_SOCK_CREATE); \
84 #define BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) \
87 if (cgroup_bpf_enabled && (sock_ops)->sk) { \
88 typeof(sk) __sk = sk_to_full_sk((sock_ops)->sk); \
89 if (__sk && sk_fullsock(__sk)) \
90 __ret = __cgroup_bpf_run_filter_sock_ops(__sk, \
92 BPF_CGROUP_SOCK_OPS); \
99 static inline void cgroup_bpf_put(struct cgroup
*cgrp
) {}
100 static inline void cgroup_bpf_inherit(struct cgroup
*cgrp
,
101 struct cgroup
*parent
) {}
103 #define BPF_CGROUP_RUN_PROG_INET_INGRESS(sk,skb) ({ 0; })
104 #define BPF_CGROUP_RUN_PROG_INET_EGRESS(sk,skb) ({ 0; })
105 #define BPF_CGROUP_RUN_PROG_INET_SOCK(sk) ({ 0; })
106 #define BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) ({ 0; })
108 #endif /* CONFIG_CGROUP_BPF */
110 #endif /* _BPF_CGROUP_H */