Skip to content

Commit

Permalink
net: have do_accept() take a struct proto_accept_arg argument
Browse files Browse the repository at this point in the history
In preparation for passing in more information via this API, change
do_accept() to take a proto_accept_arg struct pointer rather than just
the file flags separately.

No functional changes in this patch.

Acked-by: Jakub Kicinski <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
axboe committed May 14, 2024
1 parent 92ef0fd commit 0645fbe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion include/linux/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct cred;
struct socket;
struct sock;
struct sk_buff;
struct proto_accept_arg;

#define __sockaddr_check_size(size) \
BUILD_BUG_ON(((size) > sizeof(struct __kernel_sockaddr_storage)))
Expand Down Expand Up @@ -433,7 +434,7 @@ extern int __sys_recvfrom(int fd, void __user *ubuf, size_t size,
extern int __sys_sendto(int fd, void __user *buff, size_t len,
unsigned int flags, struct sockaddr __user *addr,
int addr_len);
extern struct file *do_accept(struct file *file, unsigned file_flags,
extern struct file *do_accept(struct file *file, struct proto_accept_arg *arg,
struct sockaddr __user *upeer_sockaddr,
int __user *upeer_addrlen, int flags);
extern int __sys_accept4(int fd, struct sockaddr __user *upeer_sockaddr,
Expand Down
6 changes: 4 additions & 2 deletions io_uring/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -1528,8 +1528,10 @@ int io_accept(struct io_kiocb *req, unsigned int issue_flags)
{
struct io_accept *accept = io_kiocb_to_cmd(req, struct io_accept);
bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;
unsigned int file_flags = force_nonblock ? O_NONBLOCK : 0;
bool fixed = !!accept->file_slot;
struct proto_accept_arg arg = {
.flags = force_nonblock ? O_NONBLOCK : 0,
};
struct file *file;
int ret, fd;

Expand All @@ -1543,7 +1545,7 @@ int io_accept(struct io_kiocb *req, unsigned int issue_flags)
if (unlikely(fd < 0))
return fd;
}
file = do_accept(req->file, file_flags, accept->addr, accept->addr_len,
file = do_accept(req->file, &arg, accept->addr, accept->addr_len,
accept->flags);
if (IS_ERR(file)) {
if (!fixed)
Expand Down
12 changes: 5 additions & 7 deletions net/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1890,17 +1890,14 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
return __sys_listen(fd, backlog);
}

struct file *do_accept(struct file *file, unsigned file_flags,
struct file *do_accept(struct file *file, struct proto_accept_arg *arg,
struct sockaddr __user *upeer_sockaddr,
int __user *upeer_addrlen, int flags)
{
struct socket *sock, *newsock;
struct file *newfile;
int err, len;
struct sockaddr_storage address;
struct proto_accept_arg arg = {
.flags = file_flags,
};
const struct proto_ops *ops;

sock = sock_from_file(file);
Expand Down Expand Up @@ -1929,8 +1926,8 @@ struct file *do_accept(struct file *file, unsigned file_flags,
if (err)
goto out_fd;

arg.flags |= sock->file->f_flags;
err = ops->accept(sock, newsock, &arg);
arg->flags |= sock->file->f_flags;
err = ops->accept(sock, newsock, arg);
if (err < 0)
goto out_fd;

Expand All @@ -1956,6 +1953,7 @@ struct file *do_accept(struct file *file, unsigned file_flags,
static int __sys_accept4_file(struct file *file, struct sockaddr __user *upeer_sockaddr,
int __user *upeer_addrlen, int flags)
{
struct proto_accept_arg arg = { };
struct file *newfile;
int newfd;

Expand All @@ -1969,7 +1967,7 @@ static int __sys_accept4_file(struct file *file, struct sockaddr __user *upeer_s
if (unlikely(newfd < 0))
return newfd;

newfile = do_accept(file, 0, upeer_sockaddr, upeer_addrlen,
newfile = do_accept(file, &arg, upeer_sockaddr, upeer_addrlen,
flags);
if (IS_ERR(newfile)) {
put_unused_fd(newfd);
Expand Down

0 comments on commit 0645fbe

Please sign in to comment.