mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 03:45:50 +08:00
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
This commit is contained in:
committed by
Masayuki Ishikawa
parent
4878b7729c
commit
98e7c6924d
+2
-38
@@ -516,42 +516,6 @@ found:
|
|||||||
|
|
||||||
dev->d_len -= (len + iplen);
|
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
|
/* 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
|
* 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
|
* 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);
|
seq = tcp_getsequence(tcp->seqno);
|
||||||
rcvseq = tcp_getsequence(conn->rcvseq);
|
rcvseq = tcp_getsequence(conn->rcvseq);
|
||||||
|
|
||||||
if ((dev->d_len > 0 || ((tcp->flags & (TCP_SYN | TCP_FIN)) != 0)) &&
|
if (seq != rcvseq)
|
||||||
seq != rcvseq)
|
|
||||||
{
|
{
|
||||||
/* Trim the head of the segment */
|
/* Trim the head of the segment */
|
||||||
|
|
||||||
@@ -582,6 +545,7 @@ found:
|
|||||||
{
|
{
|
||||||
/* The segment was completely out of the window.
|
/* The segment was completely out of the window.
|
||||||
* E.g. a retransmit which was not necessary.
|
* E.g. a retransmit which was not necessary.
|
||||||
|
* E.g. a keep-alive segment.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
tcp_send(dev, conn, TCP_ACK, tcpiplen);
|
tcp_send(dev, conn, TCP_ACK, tcpiplen);
|
||||||
|
|||||||
Reference in New Issue
Block a user