sockopt.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. int (*bpfilter_process_sockopt)(struct sock *sk, int optname,
  8. char __user *optval,
  9. unsigned int optlen, bool is_set);
  10. EXPORT_SYMBOL_GPL(bpfilter_process_sockopt);
  11. static int bpfilter_mbox_request(struct sock *sk, int optname,
  12. char __user *optval,
  13. unsigned int optlen, bool is_set)
  14. {
  15. if (!bpfilter_process_sockopt) {
  16. int err = request_module("bpfilter");
  17. if (err)
  18. return err;
  19. if (!bpfilter_process_sockopt)
  20. return -ECHILD;
  21. }
  22. return bpfilter_process_sockopt(sk, optname, optval, optlen, is_set);
  23. }
  24. int bpfilter_ip_set_sockopt(struct sock *sk, int optname, char __user *optval,
  25. unsigned int optlen)
  26. {
  27. return bpfilter_mbox_request(sk, optname, optval, optlen, true);
  28. }
  29. int bpfilter_ip_get_sockopt(struct sock *sk, int optname, char __user *optval,
  30. int __user *optlen)
  31. {
  32. int len;
  33. if (get_user(len, optlen))
  34. return -EFAULT;
  35. return bpfilter_mbox_request(sk, optname, optval, len, false);
  36. }