Merge tag 'block-5.8-2020-07-30' of git://git.kernel.dk/linux-block
[linux-2.6-microblaze.git] / include / linux / bpf-netns.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BPF_NETNS_H
3 #define _BPF_NETNS_H
4
5 #include <linux/mutex.h>
6 #include <uapi/linux/bpf.h>
7
8 enum netns_bpf_attach_type {
9         NETNS_BPF_INVALID = -1,
10         NETNS_BPF_FLOW_DISSECTOR = 0,
11         MAX_NETNS_BPF_ATTACH_TYPE
12 };
13
14 static inline enum netns_bpf_attach_type
15 to_netns_bpf_attach_type(enum bpf_attach_type attach_type)
16 {
17         switch (attach_type) {
18         case BPF_FLOW_DISSECTOR:
19                 return NETNS_BPF_FLOW_DISSECTOR;
20         default:
21                 return NETNS_BPF_INVALID;
22         }
23 }
24
25 /* Protects updates to netns_bpf */
26 extern struct mutex netns_bpf_mutex;
27
28 union bpf_attr;
29 struct bpf_prog;
30
31 #ifdef CONFIG_NET
32 int netns_bpf_prog_query(const union bpf_attr *attr,
33                          union bpf_attr __user *uattr);
34 int netns_bpf_prog_attach(const union bpf_attr *attr,
35                           struct bpf_prog *prog);
36 int netns_bpf_prog_detach(const union bpf_attr *attr, enum bpf_prog_type ptype);
37 int netns_bpf_link_create(const union bpf_attr *attr,
38                           struct bpf_prog *prog);
39 #else
40 static inline int netns_bpf_prog_query(const union bpf_attr *attr,
41                                        union bpf_attr __user *uattr)
42 {
43         return -EOPNOTSUPP;
44 }
45
46 static inline int netns_bpf_prog_attach(const union bpf_attr *attr,
47                                         struct bpf_prog *prog)
48 {
49         return -EOPNOTSUPP;
50 }
51
52 static inline int netns_bpf_prog_detach(const union bpf_attr *attr,
53                                         enum bpf_prog_type ptype)
54 {
55         return -EOPNOTSUPP;
56 }
57
58 static inline int netns_bpf_link_create(const union bpf_attr *attr,
59                                         struct bpf_prog *prog)
60 {
61         return -EOPNOTSUPP;
62 }
63 #endif
64
65 #endif /* _BPF_NETNS_H */