mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-28 14:44:10 +08:00
net: Implement ->sock_is_readable() for UDP and AF_UNIX
Yucong noticed we can't poll() sockets in sockmap even when they are the destination sockets of redirections. This is because we never poll any psock queues in ->poll(), except for TCP. With ->sock_is_readable() now we can overwrite >sock_is_readable(), invoke and implement it for both UDP and AF_UNIX sockets. Reported-by: Yucong Sun <sunyucong@gmail.com> Signed-off-by: Cong Wang <cong.wang@bytedance.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20211008203306.37525-4-xiyou.wangcong@gmail.com
This commit is contained in:
parent
fb4e0a5e73
commit
af49338895
@ -2867,6 +2867,9 @@ __poll_t udp_poll(struct file *file, struct socket *sock, poll_table *wait)
|
|||||||
!(sk->sk_shutdown & RCV_SHUTDOWN) && first_packet_length(sk) == -1)
|
!(sk->sk_shutdown & RCV_SHUTDOWN) && first_packet_length(sk) == -1)
|
||||||
mask &= ~(EPOLLIN | EPOLLRDNORM);
|
mask &= ~(EPOLLIN | EPOLLRDNORM);
|
||||||
|
|
||||||
|
/* psock ingress_msg queue should not contain any bad checksum frames */
|
||||||
|
if (sk_is_readable(sk))
|
||||||
|
mask |= EPOLLIN | EPOLLRDNORM;
|
||||||
return mask;
|
return mask;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -114,6 +114,7 @@ static void udp_bpf_rebuild_protos(struct proto *prot, const struct proto *base)
|
|||||||
*prot = *base;
|
*prot = *base;
|
||||||
prot->close = sock_map_close;
|
prot->close = sock_map_close;
|
||||||
prot->recvmsg = udp_bpf_recvmsg;
|
prot->recvmsg = udp_bpf_recvmsg;
|
||||||
|
prot->sock_is_readable = sk_msg_is_readable;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void udp_bpf_check_v6_needs_rebuild(struct proto *ops)
|
static void udp_bpf_check_v6_needs_rebuild(struct proto *ops)
|
||||||
|
@ -3052,6 +3052,8 @@ static __poll_t unix_poll(struct file *file, struct socket *sock, poll_table *wa
|
|||||||
/* readable? */
|
/* readable? */
|
||||||
if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
|
if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
|
||||||
mask |= EPOLLIN | EPOLLRDNORM;
|
mask |= EPOLLIN | EPOLLRDNORM;
|
||||||
|
if (sk_is_readable(sk))
|
||||||
|
mask |= EPOLLIN | EPOLLRDNORM;
|
||||||
|
|
||||||
/* Connection-based need to check for termination and startup */
|
/* Connection-based need to check for termination and startup */
|
||||||
if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) &&
|
if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) &&
|
||||||
@ -3091,6 +3093,8 @@ static __poll_t unix_dgram_poll(struct file *file, struct socket *sock,
|
|||||||
/* readable? */
|
/* readable? */
|
||||||
if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
|
if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
|
||||||
mask |= EPOLLIN | EPOLLRDNORM;
|
mask |= EPOLLIN | EPOLLRDNORM;
|
||||||
|
if (sk_is_readable(sk))
|
||||||
|
mask |= EPOLLIN | EPOLLRDNORM;
|
||||||
|
|
||||||
/* Connection-based need to check for termination and startup */
|
/* Connection-based need to check for termination and startup */
|
||||||
if (sk->sk_type == SOCK_SEQPACKET) {
|
if (sk->sk_type == SOCK_SEQPACKET) {
|
||||||
|
@ -102,6 +102,7 @@ static void unix_dgram_bpf_rebuild_protos(struct proto *prot, const struct proto
|
|||||||
*prot = *base;
|
*prot = *base;
|
||||||
prot->close = sock_map_close;
|
prot->close = sock_map_close;
|
||||||
prot->recvmsg = unix_bpf_recvmsg;
|
prot->recvmsg = unix_bpf_recvmsg;
|
||||||
|
prot->sock_is_readable = sk_msg_is_readable;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void unix_stream_bpf_rebuild_protos(struct proto *prot,
|
static void unix_stream_bpf_rebuild_protos(struct proto *prot,
|
||||||
@ -110,6 +111,7 @@ static void unix_stream_bpf_rebuild_protos(struct proto *prot,
|
|||||||
*prot = *base;
|
*prot = *base;
|
||||||
prot->close = sock_map_close;
|
prot->close = sock_map_close;
|
||||||
prot->recvmsg = unix_bpf_recvmsg;
|
prot->recvmsg = unix_bpf_recvmsg;
|
||||||
|
prot->sock_is_readable = sk_msg_is_readable;
|
||||||
prot->unhash = sock_map_unhash;
|
prot->unhash = sock_map_unhash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user