From e9ab3adf2382d2bdc632274e7b6fab1944eacb8c Mon Sep 17 00:00:00 2001 From: Alexander Lunev Date: Sun, 2 Jan 2022 18:53:43 +0300 Subject: [PATCH] net/tcp(unbuffered): advance sndseq by +1 because SYN and FIN occupy one sequence number (RFC 793) --- net/tcp/tcp_input.c | 5 +++++ net/tcp/tcp_send.c | 19 +++++++++++++++++++ net/tcp/tcp_timer.c | 15 +++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/net/tcp/tcp_input.c b/net/tcp/tcp_input.c index 63b4d33c63..b5546dde60 100644 --- a/net/tcp/tcp_input.c +++ b/net/tcp/tcp_input.c @@ -870,6 +870,11 @@ found: if ((tcp->flags & TCP_CTL) == TCP_SYN) { +#if !defined(CONFIG_NET_TCP_WRITE_BUFFERS) + tcp_setsequence(conn->sndseq, conn->rexmit_seq); +#else + /* REVISIT for the buffered mode */ +#endif tcp_synack(dev, conn, TCP_ACK | TCP_SYN); return; } diff --git a/net/tcp/tcp_send.c b/net/tcp/tcp_send.c index fd7eca15c0..13b89b7a81 100644 --- a/net/tcp/tcp_send.c +++ b/net/tcp/tcp_send.c @@ -382,6 +382,25 @@ static void tcp_sendcommon(FAR struct net_driver_s *dev, /* Finish the IP portion of the message and calculate checksums */ tcp_sendcomplete(dev, tcp); + +#if !defined(CONFIG_NET_TCP_WRITE_BUFFERS) + if ((tcp->flags & (TCP_SYN | TCP_FIN)) != 0) + { + /* Remember sndseq that will be used in case of a possible + * SYN or FIN retransmission + */ + + conn->rexmit_seq = tcp_getsequence(conn->sndseq); + + /* Advance sndseq by +1 because SYN and FIN occupy + * one sequence number (RFC 793) + */ + + net_incr32(conn->sndseq, 1); + } +#else + /* REVISIT for the buffered mode */ +#endif } /**************************************************************************** diff --git a/net/tcp/tcp_timer.c b/net/tcp/tcp_timer.c index 7ecb987283..a206a0928d 100644 --- a/net/tcp/tcp_timer.c +++ b/net/tcp/tcp_timer.c @@ -317,6 +317,11 @@ void tcp_timer(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn, * SYNACK. */ +#if !defined(CONFIG_NET_TCP_WRITE_BUFFERS) + tcp_setsequence(conn->sndseq, conn->rexmit_seq); +#else + /* REVISIT for the buffered mode */ +#endif tcp_synack(dev, conn, TCP_ACK | TCP_SYN); goto done; @@ -324,6 +329,11 @@ void tcp_timer(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn, /* In the SYN_SENT state, we retransmit out SYN. */ +#if !defined(CONFIG_NET_TCP_WRITE_BUFFERS) + tcp_setsequence(conn->sndseq, conn->rexmit_seq); +#else + /* REVISIT for the buffered mode */ +#endif tcp_synack(dev, conn, TCP_SYN); goto done; @@ -344,6 +354,11 @@ void tcp_timer(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn, /* In all these states we should retransmit a FINACK. */ +#if !defined(CONFIG_NET_TCP_WRITE_BUFFERS) + tcp_setsequence(conn->sndseq, conn->rexmit_seq); +#else + /* REVISIT for the buffered mode */ +#endif tcp_send(dev, conn, TCP_FIN | TCP_ACK, hdrlen); goto done; }