xref: /openbmc/linux/net/ipv4/bpfilter/sockopt.c (revision a86854d0)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/uaccess.h>
3 #include <linux/bpfilter.h>
4 #include <uapi/linux/bpf.h>
5 #include <linux/wait.h>
6 #include <linux/kmod.h>
7 
8 int (*bpfilter_process_sockopt)(struct sock *sk, int optname,
9 				char __user *optval,
10 				unsigned int optlen, bool is_set);
11 EXPORT_SYMBOL_GPL(bpfilter_process_sockopt);
12 
13 static int bpfilter_mbox_request(struct sock *sk, int optname,
14 				 char __user *optval,
15 				 unsigned int optlen, bool is_set)
16 {
17 	if (!bpfilter_process_sockopt) {
18 		int err = request_module("bpfilter");
19 
20 		if (err)
21 			return err;
22 		if (!bpfilter_process_sockopt)
23 			return -ECHILD;
24 	}
25 	return bpfilter_process_sockopt(sk, optname, optval, optlen, is_set);
26 }
27 
28 int bpfilter_ip_set_sockopt(struct sock *sk, int optname, char __user *optval,
29 			    unsigned int optlen)
30 {
31 	return bpfilter_mbox_request(sk, optname, optval, optlen, true);
32 }
33 
34 int bpfilter_ip_get_sockopt(struct sock *sk, int optname, char __user *optval,
35 			    int __user *optlen)
36 {
37 	int len;
38 
39 	if (get_user(len, optlen))
40 		return -EFAULT;
41 
42 	return bpfilter_mbox_request(sk, optname, optval, len, false);
43 }
44