root/net/ipv4/bpfilter/sockopt.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. bpfilter_umh_cleanup
  2. bpfilter_mbox_request
  3. bpfilter_ip_set_sockopt
  4. bpfilter_ip_get_sockopt
  5. bpfilter_sockopt_init

   1 // SPDX-License-Identifier: GPL-2.0
   2 #include <linux/init.h>
   3 #include <linux/module.h>
   4 #include <linux/uaccess.h>
   5 #include <linux/bpfilter.h>
   6 #include <uapi/linux/bpf.h>
   7 #include <linux/wait.h>
   8 #include <linux/kmod.h>
   9 #include <linux/fs.h>
  10 #include <linux/file.h>
  11 
  12 struct bpfilter_umh_ops bpfilter_ops;
  13 EXPORT_SYMBOL_GPL(bpfilter_ops);
  14 
  15 static void bpfilter_umh_cleanup(struct umh_info *info)
  16 {
  17         mutex_lock(&bpfilter_ops.lock);
  18         bpfilter_ops.stop = true;
  19         fput(info->pipe_to_umh);
  20         fput(info->pipe_from_umh);
  21         info->pid = 0;
  22         mutex_unlock(&bpfilter_ops.lock);
  23 }
  24 
  25 static int bpfilter_mbox_request(struct sock *sk, int optname,
  26                                  char __user *optval,
  27                                  unsigned int optlen, bool is_set)
  28 {
  29         int err;
  30         mutex_lock(&bpfilter_ops.lock);
  31         if (!bpfilter_ops.sockopt) {
  32                 mutex_unlock(&bpfilter_ops.lock);
  33                 request_module("bpfilter");
  34                 mutex_lock(&bpfilter_ops.lock);
  35 
  36                 if (!bpfilter_ops.sockopt) {
  37                         err = -ENOPROTOOPT;
  38                         goto out;
  39                 }
  40         }
  41         if (bpfilter_ops.stop) {
  42                 err = bpfilter_ops.start();
  43                 if (err)
  44                         goto out;
  45         }
  46         err = bpfilter_ops.sockopt(sk, optname, optval, optlen, is_set);
  47 out:
  48         mutex_unlock(&bpfilter_ops.lock);
  49         return err;
  50 }
  51 
  52 int bpfilter_ip_set_sockopt(struct sock *sk, int optname, char __user *optval,
  53                             unsigned int optlen)
  54 {
  55         return bpfilter_mbox_request(sk, optname, optval, optlen, true);
  56 }
  57 
  58 int bpfilter_ip_get_sockopt(struct sock *sk, int optname, char __user *optval,
  59                             int __user *optlen)
  60 {
  61         int len;
  62 
  63         if (get_user(len, optlen))
  64                 return -EFAULT;
  65 
  66         return bpfilter_mbox_request(sk, optname, optval, len, false);
  67 }
  68 
  69 static int __init bpfilter_sockopt_init(void)
  70 {
  71         mutex_init(&bpfilter_ops.lock);
  72         bpfilter_ops.stop = true;
  73         bpfilter_ops.info.cmdline = "bpfilter_umh";
  74         bpfilter_ops.info.cleanup = &bpfilter_umh_cleanup;
  75 
  76         return 0;
  77 }
  78 device_initcall(bpfilter_sockopt_init);

/* [<][>][^][v][top][bottom][index][help] */