Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 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 | NETNS_BPF_SK_LOOKUP, |
| 12 | MAX_NETNS_BPF_ATTACH_TYPE |
| 13 | }; |
| 14 | |
| 15 | static inline enum netns_bpf_attach_type |
| 16 | to_netns_bpf_attach_type(enum bpf_attach_type attach_type) |
| 17 | { |
| 18 | switch (attach_type) { |
| 19 | case BPF_FLOW_DISSECTOR: |
| 20 | return NETNS_BPF_FLOW_DISSECTOR; |
| 21 | case BPF_SK_LOOKUP: |
| 22 | return NETNS_BPF_SK_LOOKUP; |
| 23 | default: |
| 24 | return NETNS_BPF_INVALID; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | /* Protects updates to netns_bpf */ |
| 29 | extern struct mutex netns_bpf_mutex; |
| 30 | |
| 31 | union bpf_attr; |
| 32 | struct bpf_prog; |
| 33 | |
| 34 | #ifdef CONFIG_NET |
| 35 | int netns_bpf_prog_query(const union bpf_attr *attr, |
| 36 | union bpf_attr __user *uattr); |
| 37 | int netns_bpf_prog_attach(const union bpf_attr *attr, |
| 38 | struct bpf_prog *prog); |
| 39 | int netns_bpf_prog_detach(const union bpf_attr *attr, enum bpf_prog_type ptype); |
| 40 | int netns_bpf_link_create(const union bpf_attr *attr, |
| 41 | struct bpf_prog *prog); |
| 42 | #else |
| 43 | static inline int netns_bpf_prog_query(const union bpf_attr *attr, |
| 44 | union bpf_attr __user *uattr) |
| 45 | { |
| 46 | return -EOPNOTSUPP; |
| 47 | } |
| 48 | |
| 49 | static inline int netns_bpf_prog_attach(const union bpf_attr *attr, |
| 50 | struct bpf_prog *prog) |
| 51 | { |
| 52 | return -EOPNOTSUPP; |
| 53 | } |
| 54 | |
| 55 | static inline int netns_bpf_prog_detach(const union bpf_attr *attr, |
| 56 | enum bpf_prog_type ptype) |
| 57 | { |
| 58 | return -EOPNOTSUPP; |
| 59 | } |
| 60 | |
| 61 | static inline int netns_bpf_link_create(const union bpf_attr *attr, |
| 62 | struct bpf_prog *prog) |
| 63 | { |
| 64 | return -EOPNOTSUPP; |
| 65 | } |
| 66 | #endif |
| 67 | |
| 68 | #endif /* _BPF_NETNS_H */ |