net: tcp: Do not send FIN when closing listening sockets

A net context in LISTENING mode waits for incoming connections, once
a new connection is established a new net context is spawned which
is responsible for handling the new connection.
Therefore when closing a LISTENING context it is not useful to send FIN
as it is never connected. Actually closing the connection would be done
by calling close on the spawned net context which is returned by the
accept call.

Signed-off-by: Léonard Bise <leonard.bise@gmail.com>
This commit is contained in:
Léonard Bise 2020-06-16 15:52:12 +02:00 committed by Jukka Rissanen
commit 14ced754f5

View file

@ -1507,8 +1507,7 @@ static void queue_fin(struct net_context *ctx)
int net_tcp_put(struct net_context *context)
{
if (net_context_get_ip_proto(context) == IPPROTO_TCP) {
if ((net_context_get_state(context) == NET_CONTEXT_CONNECTED ||
net_context_get_state(context) == NET_CONTEXT_LISTENING)
if (net_context_get_state(context) == NET_CONTEXT_CONNECTED
&& context->tcp
&& !context->tcp->fin_rcvd) {
NET_DBG("TCP connection in active close, not "
@ -1519,6 +1518,18 @@ int net_tcp_put(struct net_context *context)
return 0;
}
/* A listening context is only used to establish connections.
* Since once the connection is established it is not handled
* directly by the listening context but rather by the child it
* spawned, it is not needed to send FIN when closing such
* contexts.
*/
if (context->tcp &&
net_context_get_state(context) == NET_CONTEXT_LISTENING) {
net_context_unref(context);
return 0;
}
if (context->tcp &&
net_tcp_get_state(context->tcp) == NET_TCP_SYN_SENT) {
net_context_unref(context);