Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring: Introduce getsockname io_uring cmd

Introduce a socket-specific io_uring_cmd to support
getsockname/getpeername via io_uring. I made this an io_uring_cmd
instead of a new operation to avoid polluting the command namespace with
what is exclusively a socket operation. In addition, since we don't
need to conform to existing interfaces, this merges the
getsockname/getpeername in a single operation, since the implementation
is pretty much the same.

This has been frequently requested, for instance at [1] and more
recently in the project Discord channel. The main use-case is to support
fixed socket file descriptors.

[1] https://github.com/axboe/liburing/issues/1356

Signed-off-by: Gabriel Krisman Bertazi <krisman@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Gabriel Krisman Bertazi and committed by
Jens Axboe
5d24321e d73c1677

+23
+1
include/uapi/linux/io_uring.h
··· 1009 1009 SOCKET_URING_OP_GETSOCKOPT, 1010 1010 SOCKET_URING_OP_SETSOCKOPT, 1011 1011 SOCKET_URING_OP_TX_TIMESTAMP, 1012 + SOCKET_URING_OP_GETSOCKNAME, 1012 1013 }; 1013 1014 1014 1015 /*
+22
io_uring/cmd_net.c
··· 132 132 return -EAGAIN; 133 133 } 134 134 135 + static int io_uring_cmd_getsockname(struct socket *sock, 136 + struct io_uring_cmd *cmd, 137 + unsigned int issue_flags) 138 + { 139 + const struct io_uring_sqe *sqe = cmd->sqe; 140 + struct sockaddr __user *uaddr; 141 + unsigned int peer; 142 + int __user *ulen; 143 + 144 + if (sqe->ioprio || sqe->__pad1 || sqe->len || sqe->rw_flags) 145 + return -EINVAL; 146 + 147 + uaddr = u64_to_user_ptr(READ_ONCE(sqe->addr)); 148 + ulen = u64_to_user_ptr(sqe->addr3); 149 + peer = READ_ONCE(sqe->optlen); 150 + if (peer > 1) 151 + return -EINVAL; 152 + return do_getsockname(sock, peer, uaddr, ulen); 153 + } 154 + 135 155 int io_uring_cmd_sock(struct io_uring_cmd *cmd, unsigned int issue_flags) 136 156 { 137 157 struct socket *sock = cmd->file->private_data; ··· 179 159 return io_uring_cmd_setsockopt(sock, cmd, issue_flags); 180 160 case SOCKET_URING_OP_TX_TIMESTAMP: 181 161 return io_uring_cmd_timestamp(sock, cmd, issue_flags); 162 + case SOCKET_URING_OP_GETSOCKNAME: 163 + return io_uring_cmd_getsockname(sock, cmd, issue_flags); 182 164 default: 183 165 return -EOPNOTSUPP; 184 166 }