File tree Expand file tree Collapse file tree 4 files changed +53
-0
lines changed Expand file tree Collapse file tree 4 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -257,6 +257,7 @@ enum io_uring_op {
257
257
IORING_OP_FUTEX_WAITV ,
258
258
IORING_OP_FIXED_FD_INSTALL ,
259
259
IORING_OP_FTRUNCATE ,
260
+ IORING_OP_BIND ,
260
261
261
262
/* this goes last, obviously */
262
263
IORING_OP_LAST ,
Original file line number Diff line number Diff line change @@ -51,6 +51,11 @@ struct io_connect {
51
51
bool seen_econnaborted ;
52
52
};
53
53
54
+ struct io_bind {
55
+ struct file * file ;
56
+ int addr_len ;
57
+ };
58
+
54
59
struct io_sr_msg {
55
60
struct file * file ;
56
61
union {
@@ -1715,6 +1720,37 @@ int io_connect(struct io_kiocb *req, unsigned int issue_flags)
1715
1720
return IOU_OK ;
1716
1721
}
1717
1722
1723
+ int io_bind_prep (struct io_kiocb * req , const struct io_uring_sqe * sqe )
1724
+ {
1725
+ struct io_bind * bind = io_kiocb_to_cmd (req , struct io_bind );
1726
+ struct sockaddr __user * uaddr ;
1727
+ struct io_async_msghdr * io ;
1728
+
1729
+ if (sqe -> len || sqe -> buf_index || sqe -> rw_flags || sqe -> splice_fd_in )
1730
+ return - EINVAL ;
1731
+
1732
+ uaddr = u64_to_user_ptr (READ_ONCE (sqe -> addr ));
1733
+ bind -> addr_len = READ_ONCE (sqe -> addr2 );
1734
+
1735
+ io = io_msg_alloc_async (req );
1736
+ if (unlikely (!io ))
1737
+ return - ENOMEM ;
1738
+ return move_addr_to_kernel (uaddr , bind -> addr_len , & io -> addr );
1739
+ }
1740
+
1741
+ int io_bind (struct io_kiocb * req , unsigned int issue_flags )
1742
+ {
1743
+ struct io_bind * bind = io_kiocb_to_cmd (req , struct io_bind );
1744
+ struct io_async_msghdr * io = req -> async_data ;
1745
+ int ret ;
1746
+
1747
+ ret = __sys_bind_socket (sock_from_file (req -> file ), & io -> addr , bind -> addr_len );
1748
+ if (ret < 0 )
1749
+ req_set_fail (req );
1750
+ io_req_set_res (req , ret , 0 );
1751
+ return 0 ;
1752
+ }
1753
+
1718
1754
void io_netmsg_cache_free (const void * entry )
1719
1755
{
1720
1756
struct io_async_msghdr * kmsg = (struct io_async_msghdr * ) entry ;
Original file line number Diff line number Diff line change @@ -49,6 +49,9 @@ int io_sendmsg_zc(struct io_kiocb *req, unsigned int issue_flags);
49
49
int io_send_zc_prep (struct io_kiocb * req , const struct io_uring_sqe * sqe );
50
50
void io_send_zc_cleanup (struct io_kiocb * req );
51
51
52
+ int io_bind_prep (struct io_kiocb * req , const struct io_uring_sqe * sqe );
53
+ int io_bind (struct io_kiocb * req , unsigned int issue_flags );
54
+
52
55
void io_netmsg_cache_free (const void * entry );
53
56
#else
54
57
static inline void io_netmsg_cache_free (const void * entry )
Original file line number Diff line number Diff line change @@ -495,6 +495,16 @@ const struct io_issue_def io_issue_defs[] = {
495
495
.prep = io_ftruncate_prep ,
496
496
.issue = io_ftruncate ,
497
497
},
498
+ [IORING_OP_BIND ] = {
499
+ #if defined(CONFIG_NET )
500
+ .needs_file = 1 ,
501
+ .prep = io_bind_prep ,
502
+ .issue = io_bind ,
503
+ .async_size = sizeof (struct io_async_msghdr ),
504
+ #else
505
+ .prep = io_eopnotsupp_prep ,
506
+ #endif
507
+ },
498
508
};
499
509
500
510
const struct io_cold_def io_cold_defs [] = {
@@ -716,6 +726,9 @@ const struct io_cold_def io_cold_defs[] = {
716
726
[IORING_OP_FTRUNCATE ] = {
717
727
.name = "FTRUNCATE" ,
718
728
},
729
+ [IORING_OP_BIND ] = {
730
+ .name = "BIND" ,
731
+ },
719
732
};
720
733
721
734
const char * io_uring_get_opcode (u8 opcode )
You can’t perform that action at this time.
0 commit comments