History

skmsg: Extract and reuse sk_msg_is_readable()

tcp_bpf_sock_is_readable() is pretty much generic, we can extract it and reuse it for non-TCP sockets.

Cong Wang committed 5 years ago

Commit fb4e0a51 parent 7b50ecf3 files · +16 −14Browse files

Unified · Split

3 files
  1. include/linux/skmsg.h +1 −0
  2. net/core/skmsg.c +14 −0
  3. net/ipv4/tcp_bpf.c +1 −14
include/linux/skmsg.h+1−0
@@ -128,6 +128,7 @@ int sk_msg_memcopy_from_iter(struct sock *sk, struct iov_iter *from, · 127 unmodified lines
128 struct sk_msg *msg, u32 bytes);128 struct sk_msg *msg, u32 bytes);
129int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg,129int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg,
130 int len, int flags);130 int len, int flags);
131bool sk_msg_is_readable(struct sock *sk);
131 132
132static inline void sk_msg_check_to_free(struct sk_msg *msg, u32 i, u32 bytes)133static inline void sk_msg_check_to_free(struct sk_msg *msg, u32 i, u32 bytes)
133{134{
net/core/skmsg.c+14−0
@@ -474,6 +474,20 @@ int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg, · 473 unmodified lines
474}474}
475EXPORT_SYMBOL_GPL(sk_msg_recvmsg);475EXPORT_SYMBOL_GPL(sk_msg_recvmsg);
476 476
477bool sk_msg_is_readable(struct sock *sk)
478{
479 struct sk_psock *psock;
480 bool empty = true;
481
482 rcu_read_lock();
483 psock = sk_psock(sk);
484 if (likely(psock))
485 empty = list_empty(&psock->ingress_msg);
486 rcu_read_unlock();
487 return !empty;
488}
489EXPORT_SYMBOL_GPL(sk_msg_is_readable);
490
477static struct sk_msg *sk_psock_create_ingress_msg(struct sock *sk,491static struct sk_msg *sk_psock_create_ingress_msg(struct sock *sk,
478 struct sk_buff *skb)492 struct sk_buff *skb)
479{493{
net/ipv4/tcp_bpf.c+1−14
@@ -150,19 +150,6 @@ int tcp_bpf_sendmsg_redir(struct sock *sk, struct sk_msg *msg, · 149 unmodified lines
150EXPORT_SYMBOL_GPL(tcp_bpf_sendmsg_redir);150EXPORT_SYMBOL_GPL(tcp_bpf_sendmsg_redir);
151 151
152#ifdef CONFIG_BPF_SYSCALL152#ifdef CONFIG_BPF_SYSCALL
153static bool tcp_bpf_sock_is_readable(struct sock *sk)
154{
155 struct sk_psock *psock;
156 bool empty = true;
157
158 rcu_read_lock();
159 psock = sk_psock(sk);
160 if (likely(psock))
161 empty = list_empty(&psock->ingress_msg);
162 rcu_read_unlock();
163 return !empty;
164}
165
166static int tcp_msg_wait_data(struct sock *sk, struct sk_psock *psock,153static int tcp_msg_wait_data(struct sock *sk, struct sk_psock *psock,
167 long timeo)154 long timeo)
168{155{
@@ -491,7 +478,7 @@ static void tcp_bpf_rebuild_protos(struct proto prot[TCP_BPF_NUM_CFGS], · 322 unmodified lines
491 prot[TCP_BPF_BASE].unhash = sock_map_unhash;478 prot[TCP_BPF_BASE].unhash = sock_map_unhash;
492 prot[TCP_BPF_BASE].close = sock_map_close;479 prot[TCP_BPF_BASE].close = sock_map_close;
493 prot[TCP_BPF_BASE].recvmsg = tcp_bpf_recvmsg;480 prot[TCP_BPF_BASE].recvmsg = tcp_bpf_recvmsg;
494 prot[TCP_BPF_BASE].sock_is_readable = tcp_bpf_sock_is_readable;481 prot[TCP_BPF_BASE].sock_is_readable = sk_msg_is_readable;
495 482
496 prot[TCP_BPF_TX] = prot[TCP_BPF_BASE];483 prot[TCP_BPF_TX] = prot[TCP_BPF_BASE];
497 prot[TCP_BPF_TX].sendmsg = tcp_bpf_sendmsg;484 prot[TCP_BPF_TX].sendmsg = tcp_bpf_sendmsg;