tcp_bpf_sock_is_readable() is pretty much generic, we can extract it and reuse it for non-TCP sockets.
Unified · Split
| @@ -128,6 +128,7 @@ int sk_msg_memcopy_from_iter(struct sock *sk, struct iov_iter *from, · 127 unmodified lines | ||
| 128 | 128 | struct sk_msg *msg, u32 bytes); |
| 129 | 129 | int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg, |
| 130 | 130 | int len, int flags); |
| 131 | +bool sk_msg_is_readable(struct sock *sk); | |
| 131 | 132 | |
| 132 | 133 | static inline void sk_msg_check_to_free(struct sk_msg *msg, u32 i, u32 bytes) |
| 133 | 134 | { |
| @@ -474,6 +474,20 @@ int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg, · 473 unmodified lines | ||
| 474 | 474 | } |
| 475 | 475 | EXPORT_SYMBOL_GPL(sk_msg_recvmsg); |
| 476 | 476 | |
| 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 | + | |
| 477 | 491 | static struct sk_msg *sk_psock_create_ingress_msg(struct sock *sk, |
| 478 | 492 | struct sk_buff *skb) |
| 479 | 493 | { |
| @@ -150,19 +150,6 @@ int tcp_bpf_sendmsg_redir(struct sock *sk, struct sk_msg *msg, · 149 unmodified lines | ||
| 150 | 150 | EXPORT_SYMBOL_GPL(tcp_bpf_sendmsg_redir); |
| 151 | 151 | |
| 152 | 152 | #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 | − | |
| 166 | 153 | static int tcp_msg_wait_data(struct sock *sk, struct sk_psock *psock, |
| 167 | 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 | 478 | prot[TCP_BPF_BASE].unhash = sock_map_unhash; |
| 492 | 479 | prot[TCP_BPF_BASE].close = sock_map_close; |
| 493 | 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 | 483 | prot[TCP_BPF_TX] = prot[TCP_BPF_BASE]; |
| 497 | 484 | prot[TCP_BPF_TX].sendmsg = tcp_bpf_sendmsg; |