You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ma...@apache.org on 2021/06/30 02:52:16 UTC

[incubator-nuttx] branch master updated: tcp: always responds to keep-alive segments

This is an automated email from the ASF dual-hosted git repository.

masayuki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 98e7c69  tcp: always responds to keep-alive segments
98e7c69 is described below

commit 98e7c6924d387e7f00d57cb0c978a657bd9237a1
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Tue Jun 29 15:02:47 2021 +0900

    tcp: always responds to keep-alive segments
    
    * It doesn't make sense to have this conditional on our own
      SO_KEEPALIVE support. (CONFIG_NET_TCP_KEEPALIVE)
      Actually we don't have a control on the peer tcp stack,
      who decides to send us keep-alive probes.
    
    * We should respond them for non ESTABLISHED states. eg. FIN_WAIT_2
      See also:
      https://github.com/apache/incubator-nuttx/pull/3919#issuecomment-868248576
---
 net/tcp/tcp_input.c | 40 ++--------------------------------------
 1 file changed, 2 insertions(+), 38 deletions(-)

diff --git a/net/tcp/tcp_input.c b/net/tcp/tcp_input.c
index 24ec839..3aab9d2 100644
--- a/net/tcp/tcp_input.c
+++ b/net/tcp/tcp_input.c
@@ -516,42 +516,6 @@ found:
 
   dev->d_len -= (len + iplen);
 
-#ifdef CONFIG_NET_TCP_KEEPALIVE
-  /* Check for a to KeepAlive probes.  These packets have these properties:
-   *
-   *   - TCP_ACK flag is set.  SYN/FIN/RST never appear in a Keepalive probe.
-   *   - Sequence number is the sequence number of previously ACKed data,
-   *     i.e., the expected sequence number minus one.
-   *   - The data payload is one or two bytes.
-   *
-   * We would expect a KeepAlive only in the ESTABLISHED state and only after
-   * some time has elapsed with no network activity.  If there is un-ACKed
-   * data, then we will let the normal TCP re-transmission logic handle that
-   * case.
-   */
-
-  if ((tcp->flags & TCP_ACK) != 0 &&
-      (tcp->flags & (TCP_SYN | TCP_FIN | TCP_RST)) == 0 &&
-      (conn->tcpstateflags & TCP_STATE_MASK) == TCP_ESTABLISHED &&
-      (dev->d_len == 0 || dev->d_len == 1) &&
-      conn->tx_unacked <= 0)
-    {
-      uint32_t seq;
-      uint32_t rcvseq;
-
-      seq = tcp_getsequence(tcp->seqno);
-      rcvseq = tcp_getsequence(conn->rcvseq);
-
-      if (TCP_SEQ_LT(seq, rcvseq))
-        {
-          /* Send a "normal" acknowledgment of the KeepAlive probe */
-
-          tcp_send(dev, conn, TCP_ACK, tcpiplen);
-          return;
-        }
-    }
-#endif
-
   /* Check if the sequence number of the incoming packet is what we are
    * expecting next.  If not, we send out an ACK with the correct numbers
    * in, unless we are in the SYN_RCVD state and receive a SYN, in which
@@ -569,8 +533,7 @@ found:
       seq = tcp_getsequence(tcp->seqno);
       rcvseq = tcp_getsequence(conn->rcvseq);
 
-      if ((dev->d_len > 0 || ((tcp->flags & (TCP_SYN | TCP_FIN)) != 0)) &&
-          seq != rcvseq)
+      if (seq != rcvseq)
         {
           /* Trim the head of the segment */
 
@@ -582,6 +545,7 @@ found:
                 {
                   /* The segment was completely out of the window.
                    * E.g. a retransmit which was not necessary.
+                   * E.g. a keep-alive segment.
                    */
 
                   tcp_send(dev, conn, TCP_ACK, tcpiplen);