|
33 | 33 | #endif |
34 | 34 | #include <linux/bpf-netns.h> |
35 | 35 |
|
36 | | -/* Protects updates to netns_bpf */ |
37 | | -DEFINE_MUTEX(netns_bpf_mutex); |
38 | | - |
39 | 36 | static void dissector_set_key(struct flow_dissector *flow_dissector, |
40 | 37 | enum flow_dissector_key_id key_id) |
41 | 38 | { |
@@ -72,52 +69,8 @@ void skb_flow_dissector_init(struct flow_dissector *flow_dissector, |
72 | 69 | } |
73 | 70 | EXPORT_SYMBOL(skb_flow_dissector_init); |
74 | 71 |
|
75 | | -int netns_bpf_prog_query(const union bpf_attr *attr, |
76 | | - union bpf_attr __user *uattr) |
77 | | -{ |
78 | | - __u32 __user *prog_ids = u64_to_user_ptr(attr->query.prog_ids); |
79 | | - u32 prog_id, prog_cnt = 0, flags = 0; |
80 | | - enum netns_bpf_attach_type type; |
81 | | - struct bpf_prog *attached; |
82 | | - struct net *net; |
83 | | - |
84 | | - if (attr->query.query_flags) |
85 | | - return -EINVAL; |
86 | | - |
87 | | - type = to_netns_bpf_attach_type(attr->query.attach_type); |
88 | | - if (type < 0) |
89 | | - return -EINVAL; |
90 | | - |
91 | | - net = get_net_ns_by_fd(attr->query.target_fd); |
92 | | - if (IS_ERR(net)) |
93 | | - return PTR_ERR(net); |
94 | | - |
95 | | - rcu_read_lock(); |
96 | | - attached = rcu_dereference(net->bpf.progs[type]); |
97 | | - if (attached) { |
98 | | - prog_cnt = 1; |
99 | | - prog_id = attached->aux->id; |
100 | | - } |
101 | | - rcu_read_unlock(); |
102 | | - |
103 | | - put_net(net); |
104 | | - |
105 | | - if (copy_to_user(&uattr->query.attach_flags, &flags, sizeof(flags))) |
106 | | - return -EFAULT; |
107 | | - if (copy_to_user(&uattr->query.prog_cnt, &prog_cnt, sizeof(prog_cnt))) |
108 | | - return -EFAULT; |
109 | | - |
110 | | - if (!attr->query.prog_cnt || !prog_ids || !prog_cnt) |
111 | | - return 0; |
112 | | - |
113 | | - if (copy_to_user(prog_ids, &prog_id, sizeof(u32))) |
114 | | - return -EFAULT; |
115 | | - |
116 | | - return 0; |
117 | | -} |
118 | | - |
119 | | -static int flow_dissector_bpf_prog_attach(struct net *net, |
120 | | - struct bpf_prog *prog) |
| 72 | +#ifdef CONFIG_BPF_SYSCALL |
| 73 | +int flow_dissector_bpf_prog_attach(struct net *net, struct bpf_prog *prog) |
121 | 74 | { |
122 | 75 | enum netns_bpf_attach_type type = NETNS_BPF_FLOW_DISSECTOR; |
123 | 76 | struct bpf_prog *attached; |
@@ -155,76 +108,7 @@ static int flow_dissector_bpf_prog_attach(struct net *net, |
155 | 108 | bpf_prog_put(attached); |
156 | 109 | return 0; |
157 | 110 | } |
158 | | - |
159 | | -int netns_bpf_prog_attach(const union bpf_attr *attr, struct bpf_prog *prog) |
160 | | -{ |
161 | | - enum netns_bpf_attach_type type; |
162 | | - struct net *net; |
163 | | - int ret; |
164 | | - |
165 | | - type = to_netns_bpf_attach_type(attr->attach_type); |
166 | | - if (type < 0) |
167 | | - return -EINVAL; |
168 | | - |
169 | | - net = current->nsproxy->net_ns; |
170 | | - mutex_lock(&netns_bpf_mutex); |
171 | | - switch (type) { |
172 | | - case NETNS_BPF_FLOW_DISSECTOR: |
173 | | - ret = flow_dissector_bpf_prog_attach(net, prog); |
174 | | - break; |
175 | | - default: |
176 | | - ret = -EINVAL; |
177 | | - break; |
178 | | - } |
179 | | - mutex_unlock(&netns_bpf_mutex); |
180 | | - |
181 | | - return ret; |
182 | | -} |
183 | | - |
184 | | -/* Must be called with netns_bpf_mutex held. */ |
185 | | -static int __netns_bpf_prog_detach(struct net *net, |
186 | | - enum netns_bpf_attach_type type) |
187 | | -{ |
188 | | - struct bpf_prog *attached; |
189 | | - |
190 | | - attached = rcu_dereference_protected(net->bpf.progs[type], |
191 | | - lockdep_is_held(&netns_bpf_mutex)); |
192 | | - if (!attached) |
193 | | - return -ENOENT; |
194 | | - RCU_INIT_POINTER(net->bpf.progs[type], NULL); |
195 | | - bpf_prog_put(attached); |
196 | | - return 0; |
197 | | -} |
198 | | - |
199 | | -int netns_bpf_prog_detach(const union bpf_attr *attr) |
200 | | -{ |
201 | | - enum netns_bpf_attach_type type; |
202 | | - int ret; |
203 | | - |
204 | | - type = to_netns_bpf_attach_type(attr->attach_type); |
205 | | - if (type < 0) |
206 | | - return -EINVAL; |
207 | | - |
208 | | - mutex_lock(&netns_bpf_mutex); |
209 | | - ret = __netns_bpf_prog_detach(current->nsproxy->net_ns, type); |
210 | | - mutex_unlock(&netns_bpf_mutex); |
211 | | - |
212 | | - return ret; |
213 | | -} |
214 | | - |
215 | | -static void __net_exit netns_bpf_pernet_pre_exit(struct net *net) |
216 | | -{ |
217 | | - enum netns_bpf_attach_type type; |
218 | | - |
219 | | - mutex_lock(&netns_bpf_mutex); |
220 | | - for (type = 0; type < MAX_NETNS_BPF_ATTACH_TYPE; type++) |
221 | | - __netns_bpf_prog_detach(net, type); |
222 | | - mutex_unlock(&netns_bpf_mutex); |
223 | | -} |
224 | | - |
225 | | -static struct pernet_operations netns_bpf_pernet_ops __net_initdata = { |
226 | | - .pre_exit = netns_bpf_pernet_pre_exit, |
227 | | -}; |
| 111 | +#endif /* CONFIG_BPF_SYSCALL */ |
228 | 112 |
|
229 | 113 | /** |
230 | 114 | * __skb_flow_get_ports - extract the upper layer ports and return them |
@@ -1902,7 +1786,6 @@ static int __init init_default_flow_dissectors(void) |
1902 | 1786 | skb_flow_dissector_init(&flow_keys_basic_dissector, |
1903 | 1787 | flow_keys_basic_dissector_keys, |
1904 | 1788 | ARRAY_SIZE(flow_keys_basic_dissector_keys)); |
1905 | | - |
1906 | | - return register_pernet_subsys(&netns_bpf_pernet_ops); |
| 1789 | + return 0; |
1907 | 1790 | } |
1908 | 1791 | core_initcall(init_default_flow_dissectors); |
0 commit comments