|
@@ -1423,6 +1423,13 @@ static void tun_net_init(struct net_device *dev)
|
|
|
dev->max_mtu = MAX_MTU - dev->hard_header_len;
|
|
|
}
|
|
|
|
|
|
+static bool tun_sock_writeable(struct tun_struct *tun, struct tun_file *tfile)
|
|
|
+{
|
|
|
+ struct sock *sk = tfile->socket.sk;
|
|
|
+
|
|
|
+ return (tun->dev->flags & IFF_UP) && sock_writeable(sk);
|
|
|
+}
|
|
|
+
|
|
|
/* Character device part */
|
|
|
|
|
|
/* Poll */
|
|
@@ -1445,10 +1452,14 @@ static __poll_t tun_chr_poll(struct file *file, poll_table *wait)
|
|
|
if (!ptr_ring_empty(&tfile->tx_ring))
|
|
|
mask |= EPOLLIN | EPOLLRDNORM;
|
|
|
|
|
|
- if (tun->dev->flags & IFF_UP &&
|
|
|
- (sock_writeable(sk) ||
|
|
|
- (!test_and_set_bit(SOCKWQ_ASYNC_NOSPACE, &sk->sk_socket->flags) &&
|
|
|
- sock_writeable(sk))))
|
|
|
+ /* Make sure SOCKWQ_ASYNC_NOSPACE is set if not writable to
|
|
|
+ * guarantee EPOLLOUT to be raised by either here or
|
|
|
+ * tun_sock_write_space(). Then process could get notification
|
|
|
+ * after it writes to a down device and meets -EIO.
|
|
|
+ */
|
|
|
+ if (tun_sock_writeable(tun, tfile) ||
|
|
|
+ (!test_and_set_bit(SOCKWQ_ASYNC_NOSPACE, &sk->sk_socket->flags) &&
|
|
|
+ tun_sock_writeable(tun, tfile)))
|
|
|
mask |= EPOLLOUT | EPOLLWRNORM;
|
|
|
|
|
|
if (tun->dev->reg_state != NETREG_REGISTERED)
|