Skip to content

Commit c9ffebd

Browse files
Christoph Hellwigdavem330
authored andcommitted
net/bpfilter: split __bpfilter_process_sockopt
Split __bpfilter_process_sockopt into a low-level send request routine and the actual setsockopt hook to split the init time ping from the actual setsockopt processing. Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e024e00 commit c9ffebd

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

net/bpfilter/bpfilter_kern.c

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,48 +31,51 @@ static void __stop_umh(void)
3131
shutdown_umh();
3232
}
3333

34-
static int __bpfilter_process_sockopt(struct sock *sk, int optname,
35-
char __user *optval,
36-
unsigned int optlen, bool is_set)
34+
static int bpfilter_send_req(struct mbox_request *req)
3735
{
38-
struct mbox_request req;
3936
struct mbox_reply reply;
4037
loff_t pos;
4138
ssize_t n;
42-
int ret = -EFAULT;
4339

44-
req.is_set = is_set;
45-
req.pid = current->pid;
46-
req.cmd = optname;
47-
req.addr = (uintptr_t)optval;
48-
req.len = optlen;
4940
if (!bpfilter_ops.info.tgid)
50-
goto out;
41+
return -EFAULT;
5142
pos = 0;
52-
n = kernel_write(bpfilter_ops.info.pipe_to_umh, &req, sizeof(req),
43+
n = kernel_write(bpfilter_ops.info.pipe_to_umh, req, sizeof(*req),
5344
&pos);
54-
if (n != sizeof(req)) {
45+
if (n != sizeof(*req)) {
5546
pr_err("write fail %zd\n", n);
56-
__stop_umh();
57-
ret = -EFAULT;
58-
goto out;
47+
goto stop;
5948
}
6049
pos = 0;
6150
n = kernel_read(bpfilter_ops.info.pipe_from_umh, &reply, sizeof(reply),
6251
&pos);
6352
if (n != sizeof(reply)) {
6453
pr_err("read fail %zd\n", n);
65-
__stop_umh();
66-
ret = -EFAULT;
67-
goto out;
54+
goto stop;
6855
}
69-
ret = reply.status;
70-
out:
71-
return ret;
56+
return reply.status;
57+
stop:
58+
__stop_umh();
59+
return -EFAULT;
60+
}
61+
62+
static int bpfilter_process_sockopt(struct sock *sk, int optname,
63+
char __user *optval, unsigned int optlen,
64+
bool is_set)
65+
{
66+
struct mbox_request req = {
67+
.is_set = is_set,
68+
.pid = current->pid,
69+
.cmd = optname,
70+
.addr = (uintptr_t)optval,
71+
.len = optlen,
72+
};
73+
return bpfilter_send_req(&req);
7274
}
7375

7476
static int start_umh(void)
7577
{
78+
struct mbox_request req = { .pid = current->pid };
7679
int err;
7780

7881
/* fork usermode process */
@@ -82,7 +85,7 @@ static int start_umh(void)
8285
pr_info("Loaded bpfilter_umh pid %d\n", pid_nr(bpfilter_ops.info.tgid));
8386

8487
/* health check that usermode process started correctly */
85-
if (__bpfilter_process_sockopt(NULL, 0, NULL, 0, 0) != 0) {
88+
if (bpfilter_send_req(&req) != 0) {
8689
shutdown_umh();
8790
return -EFAULT;
8891
}
@@ -103,7 +106,7 @@ static int __init load_umh(void)
103106
mutex_lock(&bpfilter_ops.lock);
104107
err = start_umh();
105108
if (!err && IS_ENABLED(CONFIG_INET)) {
106-
bpfilter_ops.sockopt = &__bpfilter_process_sockopt;
109+
bpfilter_ops.sockopt = &bpfilter_process_sockopt;
107110
bpfilter_ops.start = &start_umh;
108111
}
109112
mutex_unlock(&bpfilter_ops.lock);

0 commit comments

Comments
 (0)