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/net: allow filtering on IORING_OP_SOCKET data

Example population method for the BPF based opcode filtering. This
exposes the socket family, type, and protocol to a registered BPF
filter. This in turn enables the filter to make decisions based on
what was passed in to the IORING_OP_SOCKET request type.

Signed-off-by: Jens Axboe <axboe@kernel.dk>

+33
+7
include/uapi/linux/io_uring/bpf_filter.h
··· 16 16 __u8 sqe_flags; 17 17 __u8 pdu_size; /* size of aux data for filter */ 18 18 __u8 pad[5]; 19 + union { 20 + struct { 21 + __u32 family; 22 + __u32 type; 23 + __u32 protocol; 24 + } socket; 25 + }; 19 26 }; 20 27 21 28 enum {
+11
io_uring/bpf_filter.c
··· 30 30 /* clear residual, anything from pdu_size and below */ 31 31 memset((void *) bctx + offsetof(struct io_uring_bpf_ctx, pdu_size), 0, 32 32 sizeof(*bctx) - offsetof(struct io_uring_bpf_ctx, pdu_size)); 33 + 34 + /* 35 + * Opcodes can provide a handler fo populating more data into bctx, 36 + * for filters to use. 37 + */ 38 + switch (req->opcode) { 39 + case IORING_OP_SOCKET: 40 + bctx->pdu_size = sizeof(bctx->socket); 41 + io_socket_bpf_populate(bctx, req); 42 + break; 43 + } 33 44 } 34 45 35 46 /*
+9
io_uring/net.c
··· 1699 1699 return IOU_COMPLETE; 1700 1700 } 1701 1701 1702 + void io_socket_bpf_populate(struct io_uring_bpf_ctx *bctx, struct io_kiocb *req) 1703 + { 1704 + struct io_socket *sock = io_kiocb_to_cmd(req, struct io_socket); 1705 + 1706 + bctx->socket.family = sock->domain; 1707 + bctx->socket.type = sock->type; 1708 + bctx->socket.protocol = sock->protocol; 1709 + } 1710 + 1702 1711 int io_socket_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 1703 1712 { 1704 1713 struct io_socket *sock = io_kiocb_to_cmd(req, struct io_socket);
+6
io_uring/net.h
··· 3 3 #include <linux/net.h> 4 4 #include <linux/uio.h> 5 5 #include <linux/io_uring_types.h> 6 + #include <uapi/linux/io_uring/bpf_filter.h> 6 7 7 8 struct io_async_msghdr { 8 9 #if defined(CONFIG_NET) ··· 45 44 46 45 int io_socket_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); 47 46 int io_socket(struct io_kiocb *req, unsigned int issue_flags); 47 + void io_socket_bpf_populate(struct io_uring_bpf_ctx *bctx, struct io_kiocb *req); 48 48 49 49 int io_connect_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); 50 50 int io_connect(struct io_kiocb *req, unsigned int issue_flags); ··· 64 62 void io_netmsg_cache_free(const void *entry); 65 63 #else 66 64 static inline void io_netmsg_cache_free(const void *entry) 65 + { 66 + } 67 + static inline void io_socket_bpf_populate(struct io_uring_bpf_ctx *bctx, 68 + struct io_kiocb *req) 67 69 { 68 70 } 69 71 #endif