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
128128 struct sk_msg *msg, u32 bytes);
129129 int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg,
130130 int len, int flags);
131+bool sk_msg_is_readable(struct sock *sk);
131132
132133 static inline void sk_msg_check_to_free(struct sk_msg *msg, u32 i, u32 bytes)
133134 {
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
474474 }
475475 EXPORT_SYMBOL_GPL(sk_msg_recvmsg);
476476
477+bool 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+}
489+EXPORT_SYMBOL_GPL(sk_msg_is_readable);
490+
477491 static struct sk_msg *sk_psock_create_ingress_msg(struct sock *sk,
478492 struct sk_buff *skb)
479493 {
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
150150 EXPORT_SYMBOL_GPL(tcp_bpf_sendmsg_redir);
151151
152152 #ifdef CONFIG_BPF_SYSCALL
153−static 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−
166153 static int tcp_msg_wait_data(struct sock *sk, struct sk_psock *psock,
167154 long timeo)
168155 {
@@ -491,7 +478,7 @@ static void tcp_bpf_rebuild_protos(struct proto prot[TCP_BPF_NUM_CFGS], · 322 unmodified lines
491478 prot[TCP_BPF_BASE].unhash = sock_map_unhash;
492479 prot[TCP_BPF_BASE].close = sock_map_close;
493480 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;
495482
496483 prot[TCP_BPF_TX] = prot[TCP_BPF_BASE];
497484 prot[TCP_BPF_TX].sendmsg = tcp_bpf_sendmsg;