From: Vincent Whitchurch via B4 Relay <devnull+vincent.whitchurch.datadoghq.com@xxxxxxxxxx> Date: Thu, 06 Jun 2024 11:27:52 +0200 > From: Vincent Whitchurch <vincent.whitchurch@xxxxxxxxxxxxx> > > The TCP BPF code will need to override splice_read(), so add it to prot. > > Signed-off-by: Vincent Whitchurch <vincent.whitchurch@xxxxxxxxxxxxx> > --- > include/net/inet_common.h | 3 +++ > include/net/sock.h | 3 +++ > net/ipv4/af_inet.c | 18 +++++++++++++++++- > net/ipv4/tcp_ipv4.c | 1 + > net/ipv6/af_inet6.c | 2 +- > net/ipv6/tcp_ipv6.c | 1 + > 6 files changed, 26 insertions(+), 2 deletions(-) > > diff --git a/include/net/inet_common.h b/include/net/inet_common.h > index c17a6585d0b0..2a6480d0d575 100644 > --- a/include/net/inet_common.h > +++ b/include/net/inet_common.h > @@ -35,6 +35,9 @@ void __inet_accept(struct socket *sock, struct socket *newsock, > struct sock *newsk); > int inet_send_prepare(struct sock *sk); > int inet_sendmsg(struct socket *sock, struct msghdr *msg, size_t size); > +ssize_t inet_splice_read(struct socket *sk, loff_t *ppos, > + struct pipe_inode_info *pipe, size_t len, > + unsigned int flags); > void inet_splice_eof(struct socket *sock); > int inet_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, > int flags); > diff --git a/include/net/sock.h b/include/net/sock.h > index 5f4d0629348f..a152552a64a5 100644 > --- a/include/net/sock.h > +++ b/include/net/sock.h > @@ -1238,6 +1238,9 @@ struct proto { > size_t len); > int (*recvmsg)(struct sock *sk, struct msghdr *msg, > size_t len, int flags, int *addr_len); > + ssize_t (*splice_read)(struct socket *sock, loff_t *ppos, > + struct pipe_inode_info *pipe, size_t len, > + unsigned int flags); > void (*splice_eof)(struct socket *sock); > int (*bind)(struct sock *sk, > struct sockaddr *addr, int addr_len); > diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c > index e03ba4a21c39..c9a23296ac82 100644 > --- a/net/ipv4/af_inet.c > +++ b/net/ipv4/af_inet.c > @@ -870,6 +870,21 @@ void inet_splice_eof(struct socket *sock) > } > EXPORT_SYMBOL_GPL(inet_splice_eof); > > +ssize_t inet_splice_read(struct socket *sock, loff_t *ppos, > + struct pipe_inode_info *pipe, size_t len, > + unsigned int flags) > +{ > + const struct proto *prot; > + struct sock *sk = sock->sk; > + > + prot = READ_ONCE(sk->sk_prot); > + if (prot->splice_read) > + return prot->splice_read(sock, ppos, pipe, len, flags); INDIRECT_CALL_1() (or _2() in the next patch) can be used. > + > + return -EINVAL; > +} > +EXPORT_SYMBOL_GPL(inet_splice_read); > + > INDIRECT_CALLABLE_DECLARE(int udp_recvmsg(struct sock *, struct msghdr *, > size_t, int, int *)); > int inet_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, > @@ -1073,7 +1088,7 @@ const struct proto_ops inet_stream_ops = { > .mmap = tcp_mmap, > #endif > .splice_eof = inet_splice_eof, > - .splice_read = tcp_splice_read, > + .splice_read = inet_splice_read, > .set_peek_off = sk_set_peek_off, > .read_sock = tcp_read_sock, > .read_skb = tcp_read_skb, > @@ -1107,6 +1122,7 @@ const struct proto_ops inet_dgram_ops = { > .recvmsg = inet_recvmsg, > .mmap = sock_no_mmap, > .splice_eof = inet_splice_eof, > + .splice_read = inet_splice_read, Does SOCK_DGRAM need this change ? If no, inet_splice_read() can return splice_read() directly.