From 91de50cb376b2beca6fa5316efaae6686aafe9d1 Mon Sep 17 00:00:00 2001 From: Ravi kumar Veeramally Date: Fri, 24 Apr 2020 15:49:29 +0300 Subject: [PATCH] net: tcp2: Fix FIN+ACK retransmissions in ESTABLISHED In order to avoid retransmissions from the peer's side on full-close, handle states properly. Signed-off-by: Ravi kumar Veeramally --- subsys/net/ip/tcp2.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/subsys/net/ip/tcp2.c b/subsys/net/ip/tcp2.c index f6ef14d593c..3e5fbc82ab2 100644 --- a/subsys/net/ip/tcp2.c +++ b/subsys/net/ip/tcp2.c @@ -913,11 +913,17 @@ next_state: case TCP_ESTABLISHED: /* full-close */ if (th && FL(&fl, ==, (FIN | ACK), th_seq(th) == conn->ack)) { + conn_ack(conn, + 1); + tcp_out(conn, FIN | ACK); + next = TCP_LAST_ACK; + break; + } else if (th && FL(&fl, ==, FIN, th_seq(th) == conn->ack)) { conn_ack(conn, + 1); tcp_out(conn, ACK); next = TCP_CLOSE_WAIT; break; } + if (len) { if (th_seq(th) == conn->ack) { tcp_data_get(conn, pkt); @@ -927,13 +933,13 @@ next_state: tcp_out(conn, ACK); /* peer has resent */ } } - break; /* TODO: Catch all the rest here */ + break; case TCP_CLOSE_WAIT: - tcp_out(conn, FIN | ACK); + tcp_out(conn, FIN); next = TCP_LAST_ACK; break; case TCP_LAST_ACK: - if (FL(&fl, ==, ACK, th_seq(th) == conn->ack)) { + if (th && FL(&fl, ==, ACK, th_seq(th) == conn->ack)) { tcp_send_timer_cancel(conn); next = TCP_CLOSED; }