All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] tcp: do not report TCP_CM_INQ of 0 for closed connections
@ 2019-03-06 18:01 Soheil Hassas Yeganeh
  2019-03-06 19:03 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Soheil Hassas Yeganeh @ 2019-03-06 18:01 UTC (permalink / raw)
  To: davem, netdev; +Cc: edumazet, ycheng, ncardwell, Soheil Hassas Yeganeh

From: Soheil Hassas Yeganeh <soheil@google.com>

Returning 0 as inq to userspace indicates there is no more data to
read, and the application needs to wait for EPOLLIN. For a connection
that has received FIN from the remote peer, however, the application
must continue reading until getting EOF (return value of 0
from tcp_recvmsg) or an error, if edge-triggered epoll (EPOLLET) is
being used. Otherwise, the application will never receive a new
EPOLLIN, since there is no epoll edge after the FIN.

Return 1 when there is no data left on the queue but the
connection has received FIN, so that the applications continue
reading.

Fixes: b75eba76d3d72 (tcp: send in-queue bytes in cmsg upon read)
Signed-off-by: Soheil Hassas Yeganeh <soheil@google.com>
Acked-by: Neal Cardwell <ncardwell@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Yuchung Cheng <ycheng@google.com>
---
 net/ipv4/tcp.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index ad07dd71063da..8b25017e0dc93 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1933,6 +1933,11 @@ static int tcp_inq_hint(struct sock *sk)
 		inq = tp->rcv_nxt - tp->copied_seq;
 		release_sock(sk);
 	}
+	/* After receiving a FIN, tell the user-space to continue reading
+	 * by returning a non-zero inq.
+	 */
+	if (inq == 0 && sock_flag(sk, SOCK_DONE))
+		inq = 1;
 	return inq;
 }
 
-- 
2.21.0.352.gf09ad66450-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] tcp: do not report TCP_CM_INQ of 0 for closed connections
  2019-03-06 18:01 [PATCH net] tcp: do not report TCP_CM_INQ of 0 for closed connections Soheil Hassas Yeganeh
@ 2019-03-06 19:03 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2019-03-06 19:03 UTC (permalink / raw)
  To: soheil.kdev; +Cc: netdev, edumazet, ycheng, ncardwell, soheil

From: Soheil Hassas Yeganeh <soheil.kdev@gmail.com>
Date: Wed,  6 Mar 2019 13:01:36 -0500

> From: Soheil Hassas Yeganeh <soheil@google.com>
> 
> Returning 0 as inq to userspace indicates there is no more data to
> read, and the application needs to wait for EPOLLIN. For a connection
> that has received FIN from the remote peer, however, the application
> must continue reading until getting EOF (return value of 0
> from tcp_recvmsg) or an error, if edge-triggered epoll (EPOLLET) is
> being used. Otherwise, the application will never receive a new
> EPOLLIN, since there is no epoll edge after the FIN.
> 
> Return 1 when there is no data left on the queue but the
> connection has received FIN, so that the applications continue
> reading.
> 
> Fixes: b75eba76d3d72 (tcp: send in-queue bytes in cmsg upon read)
> Signed-off-by: Soheil Hassas Yeganeh <soheil@google.com>
> Acked-by: Neal Cardwell <ncardwell@google.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Acked-by: Yuchung Cheng <ycheng@google.com>

Applied and queued up for -stable, thank you.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-03-06 19:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-06 18:01 [PATCH net] tcp: do not report TCP_CM_INQ of 0 for closed connections Soheil Hassas Yeganeh
2019-03-06 19:03 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.