You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ar...@apache.org on 2021/08/25 12:56:15 UTC
[incubator-nuttx] branch master updated (af57d04 -> 42f1851)
This is an automated email from the ASF dual-hosted git repository.
archer pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git.
from af57d04 Revert "drivers: wireless: Fix ASSERT() in _read_data_len() in gs2200m.c"
new 1b82f1c tcp_input: snd_wnd processing
new 42f1851 tcp_send_buffered.c: Fix snd_wnd
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
net/tcp/tcp.h | 2 +
net/tcp/tcp_input.c | 93 ++++++++++++++++++++---
net/tcp/tcp_send_buffered.c | 175 ++++++++++++++++++++++++--------------------
3 files changed, 180 insertions(+), 90 deletions(-)
[incubator-nuttx] 01/02: tcp_input: snd_wnd processing
Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
archer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 1b82f1c749fe43335d8fad9685d64c0974a9f929
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Fri Jul 16 19:47:08 2021 +0900
tcp_input: snd_wnd processing
* Do not accept the window in old segments.
Implement SND.WL1/WL2 things in the RFC.
* Do not accept the window in the segment w/o ACK bit set.
The window is an offset from the ack seq.
(maybe it's simpler to just drop segments w/o ACK though)
* Subtract snd_wnd by the amount of the ack advancement.
---
net/tcp/tcp.h | 2 ++
net/tcp/tcp_input.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 86 insertions(+), 9 deletions(-)
diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h
index d80567c..f9e806c 100644
--- a/net/tcp/tcp.h
+++ b/net/tcp/tcp.h
@@ -202,6 +202,8 @@ struct tcp_conn_s
uint16_t snd_wnd; /* Sequence and acknowledgement numbers of last
* window update */
#endif
+ uint32_t snd_wl1;
+ uint32_t snd_wl2;
#if CONFIG_NET_RECV_BUFSIZE > 0
int32_t rcv_bufs; /* Maximum amount of bytes queued in recv */
#endif
diff --git a/net/tcp/tcp_input.c b/net/tcp/tcp_input.c
index 56edd7c..01b9968 100644
--- a/net/tcp/tcp_input.c
+++ b/net/tcp/tcp_input.c
@@ -190,6 +190,77 @@ static bool tcp_trim_head(FAR struct net_driver_s *dev,
return false;
}
+static void tcp_snd_wnd_init(FAR struct tcp_conn_s *conn,
+ FAR struct tcp_hdr_s *tcp)
+{
+ /* Just ensure that the next tcp_update_snd_wnd will be accepted. */
+
+ DEBUGASSERT((tcp->flags & TCP_ACK) != 0);
+ conn->snd_wl1 = TCP_SEQ_SUB(tcp_getsequence(tcp->seqno), 1);
+ conn->snd_wl2 = tcp_getsequence(tcp->ackno);
+ conn->snd_wnd = 0;
+ ninfo("snd_wnd init: wl1 %" PRIu32 "\n", conn->snd_wl1);
+}
+
+static void tcp_snd_wnd_update(FAR struct tcp_conn_s *conn,
+ FAR struct tcp_hdr_s *tcp)
+{
+ uint32_t ackseq = tcp_getsequence(tcp->ackno);
+ uint32_t seq = tcp_getsequence(tcp->seqno);
+ uint16_t unscaled_wnd = ((uint16_t)tcp->wnd[0] << 8) + tcp->wnd[1];
+#ifdef CONFIG_NET_TCP_WINDOW_SCALE
+ uint32_t wnd = (uint32_t)unscaled_wnd << conn->snd_scale;
+#else
+ uint16_t wnd = unscaled_wnd;
+#endif
+ uint32_t wl2 = conn->snd_wl2;
+
+ DEBUGASSERT((tcp->flags & TCP_ACK) != 0);
+
+ if (TCP_SEQ_LT(wl2, ackseq))
+ {
+ uint32_t nacked = TCP_SEQ_SUB(ackseq, wl2);
+
+ ninfo("snd_wnd acked: "
+ "wl2 %" PRIu32 " -> %" PRIu32 " subtracting wnd %" PRIu32
+ " by %" PRIu32 "\n",
+ wl2,
+ ackseq,
+ (uint32_t)conn->snd_wnd,
+ nacked);
+
+ if (nacked > conn->snd_wnd)
+ {
+ conn->snd_wnd = 0;
+ }
+ else
+ {
+ conn->snd_wnd -= nacked;
+ }
+
+ conn->snd_wl2 = ackseq;
+ }
+
+ if (TCP_SEQ_LT(conn->snd_wl1, seq) ||
+ (conn->snd_wl1 == seq && TCP_SEQ_LT(wl2, ackseq)) ||
+ (wl2 == ackseq && conn->snd_wnd < wnd))
+ {
+ ninfo("snd_wnd update: "
+ "wl1 %" PRIu32 " wl2 %" PRIu32 " wnd %" PRIu32 " -> "
+ "wl1 %" PRIu32 " wl2 %" PRIu32 " wnd %" PRIu32 "\n",
+ conn->snd_wl1,
+ wl2,
+ (uint32_t)conn->snd_wnd,
+ seq,
+ ackseq,
+ (uint32_t)wnd);
+
+ conn->snd_wl1 = seq;
+ conn->snd_wl2 = ackseq;
+ conn->snd_wnd = wnd;
+ }
+}
+
/****************************************************************************
* Name: tcp_input
*
@@ -447,15 +518,6 @@ reset:
found:
- /* Update the connection's window size */
-
-#ifdef CONFIG_NET_TCP_WINDOW_SCALE
- conn->snd_wnd = (((uint32_t)tcp->wnd[0] << 8) + (uint32_t)tcp->wnd[1]) <<
- conn->snd_scale;
-#else
- conn->snd_wnd = (((uint16_t)tcp->wnd[0] << 8) + (uint16_t)tcp->wnd[1]);
-#endif
-
flags = 0;
/* We do a very naive form of TCP reset processing; we just accept
@@ -680,6 +742,14 @@ found:
conn->timer = conn->rto;
}
+ /* Update the connection's window size */
+
+ if ((tcp->flags & TCP_ACK) != 0 &&
+ (conn->tcpstateflags & TCP_STATE_MASK) != TCP_SYN_RCVD)
+ {
+ tcp_snd_wnd_update(conn, tcp);
+ }
+
/* Do different things depending on in what state the connection is. */
switch (conn->tcpstateflags & TCP_STATE_MASK)
@@ -736,6 +806,9 @@ found:
conn->sndseq_max = 0;
#endif
conn->tx_unacked = 0;
+ tcp_snd_wnd_init(conn, tcp);
+ tcp_snd_wnd_update(conn, tcp);
+
flags = TCP_CONNECTED;
ninfo("TCP state: TCP_ESTABLISHED\n");
@@ -834,6 +907,8 @@ found:
conn->tcpstateflags = TCP_ESTABLISHED;
memcpy(conn->rcvseq, tcp->seqno, 4);
conn->rcv_adv = tcp_getsequence(conn->rcvseq);
+ tcp_snd_wnd_init(conn, tcp);
+ tcp_snd_wnd_update(conn, tcp);
net_incr32(conn->rcvseq, 1); /* ack SYN */
conn->tx_unacked = 0;
[incubator-nuttx] 02/02: tcp_send_buffered.c: Fix snd_wnd
Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
archer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 42f1851ca6f43f674871ce1dfd24b0e36a2732ad
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Mon Jul 19 11:24:06 2021 +0900
tcp_send_buffered.c: Fix snd_wnd
snd_wnd is an offset from the acked sequence number.
---
net/tcp/tcp_send_buffered.c | 175 ++++++++++++++++++++++++--------------------
1 file changed, 94 insertions(+), 81 deletions(-)
diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c
index ea3e975..b4102ba 100644
--- a/net/tcp/tcp_send_buffered.c
+++ b/net/tcp/tcp_send_buffered.c
@@ -781,6 +781,8 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
{
FAR struct tcp_wrbuffer_s *wrb;
uint32_t predicted_seqno;
+ uint32_t seq;
+ uint32_t snd_wnd_edge;
size_t sndlen;
/* Peek at the head of the write queue (but don't remove anything
@@ -791,28 +793,6 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
wrb = (FAR struct tcp_wrbuffer_s *)sq_peek(&conn->write_q);
DEBUGASSERT(wrb);
- /* Get the amount of data that we can send in the next packet.
- * We will send either the remaining data in the buffer I/O
- * buffer chain, or as much as will fit given the MSS and current
- * window size.
- */
-
- sndlen = TCP_WBPKTLEN(wrb) - TCP_WBSENT(wrb);
- if (sndlen > conn->mss)
- {
- sndlen = conn->mss;
- }
-
- if (sndlen > conn->snd_wnd)
- {
- sndlen = conn->snd_wnd;
- }
-
- ninfo("SEND: wrb=%p pktlen=%u sent=%u sndlen=%zu mss=%u "
- "snd_wnd=%u\n",
- wrb, TCP_WBPKTLEN(wrb), TCP_WBSENT(wrb), sndlen, conn->mss,
- conn->snd_wnd);
-
/* Set the sequence number for this segment. If we are
* retransmitting, then the sequence number will already
* be set for this write buffer.
@@ -823,88 +803,121 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
TCP_WBSEQNO(wrb) = conn->isn + conn->sent;
}
- /* The TCP stack updates sndseq on receipt of ACK *before*
- * this function is called. In that case sndseq will point
- * to the next unacknowledged byte (which might have already
- * been sent). We will overwrite the value of sndseq here
- * before the packet is sent.
+ /* Get the amount of data that we can send in the next packet.
+ * We will send either the remaining data in the buffer I/O
+ * buffer chain, or as much as will fit given the MSS and current
+ * window size.
*/
- tcp_setsequence(conn->sndseq, TCP_WBSEQNO(wrb) + TCP_WBSENT(wrb));
+ seq = TCP_WBSEQNO(wrb) + TCP_WBSENT(wrb);
+ snd_wnd_edge = conn->snd_wl2 + conn->snd_wnd;
+ if (TCP_SEQ_LT(seq, snd_wnd_edge))
+ {
+ uint32_t remaining_snd_wnd;
-#ifdef NEED_IPDOMAIN_SUPPORT
- /* If both IPv4 and IPv6 support are enabled, then we will need to
- * select which one to use when generating the outgoing packet.
- * If only one domain is selected, then the setup is already in
- * place and we need do nothing.
- */
+ sndlen = TCP_WBPKTLEN(wrb) - TCP_WBSENT(wrb);
+ if (sndlen > conn->mss)
+ {
+ sndlen = conn->mss;
+ }
- send_ipselect(dev, conn);
-#endif
- /* Then set-up to send that amount of data with the offset
- * corresponding to the amount of data already sent. (this
- * won't actually happen until the polling cycle completes).
- */
+ remaining_snd_wnd = TCP_SEQ_SUB(snd_wnd_edge, seq);
+ if (sndlen > remaining_snd_wnd)
+ {
+ sndlen = remaining_snd_wnd;
+ }
- devif_iob_send(dev, TCP_WBIOB(wrb), sndlen, TCP_WBSENT(wrb));
+ ninfo("SEND: wrb=%p seq=%" PRIu32 " pktlen=%u sent=%u sndlen=%zu "
+ "mss=%u snd_wnd=%u seq=%" PRIu32
+ " remaining_snd_wnd=%" PRIu32 "\n",
+ wrb, TCP_WBSEQNO(wrb), TCP_WBPKTLEN(wrb), TCP_WBSENT(wrb),
+ sndlen, conn->mss,
+ conn->snd_wnd, seq, remaining_snd_wnd);
+
+ /* The TCP stack updates sndseq on receipt of ACK *before*
+ * this function is called. In that case sndseq will point
+ * to the next unacknowledged byte (which might have already
+ * been sent). We will overwrite the value of sndseq here
+ * before the packet is sent.
+ */
- /* Remember how much data we send out now so that we know
- * when everything has been acknowledged. Just increment
- * the amount of data sent. This will be needed in sequence
- * number calculations.
- */
+ tcp_setsequence(conn->sndseq, TCP_WBSEQNO(wrb) + TCP_WBSENT(wrb));
- conn->tx_unacked += sndlen;
- conn->sent += sndlen;
+ #ifdef NEED_IPDOMAIN_SUPPORT
+ /* If both IPv4 and IPv6 support are enabled, then we will need to
+ * select which one to use when generating the outgoing packet.
+ * If only one domain is selected, then the setup is already in
+ * place and we need do nothing.
+ */
- /* Below prediction will become true,
- * unless retransmission occurrence
- */
+ send_ipselect(dev, conn);
+ #endif
+ /* Then set-up to send that amount of data with the offset
+ * corresponding to the amount of data already sent. (this
+ * won't actually happen until the polling cycle completes).
+ */
- predicted_seqno = tcp_getsequence(conn->sndseq) + sndlen;
+ devif_iob_send(dev, TCP_WBIOB(wrb), sndlen, TCP_WBSENT(wrb));
- if (TCP_SEQ_GT(predicted_seqno, conn->sndseq_max))
- {
- conn->sndseq_max = predicted_seqno;
- }
+ /* Remember how much data we send out now so that we know
+ * when everything has been acknowledged. Just increment
+ * the amount of data sent. This will be needed in sequence
+ * number calculations.
+ */
- ninfo("SEND: wrb=%p nrtx=%u tx_unacked=%" PRIu32 " sent=%" PRIu32 "\n",
- wrb, TCP_WBNRTX(wrb), conn->tx_unacked, conn->sent);
+ conn->tx_unacked += sndlen;
+ conn->sent += sndlen;
- /* Increment the count of bytes sent from this write buffer */
+ /* Below prediction will become true,
+ * unless retransmission occurrence
+ */
- TCP_WBSENT(wrb) += sndlen;
+ predicted_seqno = tcp_getsequence(conn->sndseq) + sndlen;
- ninfo("SEND: wrb=%p sent=%u pktlen=%u\n",
- wrb, TCP_WBSENT(wrb), TCP_WBPKTLEN(wrb));
+ if (TCP_SEQ_GT(predicted_seqno, conn->sndseq_max))
+ {
+ conn->sndseq_max = predicted_seqno;
+ }
- /* Remove the write buffer from the write queue if the
- * last of the data has been sent from the buffer.
- */
+ ninfo("SEND: wrb=%p nrtx=%u tx_unacked=%" PRIu32
+ " sent=%" PRIu32 "\n",
+ wrb, TCP_WBNRTX(wrb), conn->tx_unacked, conn->sent);
- DEBUGASSERT(TCP_WBSENT(wrb) <= TCP_WBPKTLEN(wrb));
- if (TCP_WBSENT(wrb) >= TCP_WBPKTLEN(wrb))
- {
- FAR struct tcp_wrbuffer_s *tmp;
+ /* Increment the count of bytes sent from this write buffer */
- ninfo("SEND: wrb=%p Move to unacked_q\n", wrb);
+ TCP_WBSENT(wrb) += sndlen;
- tmp = (FAR struct tcp_wrbuffer_s *)sq_remfirst(&conn->write_q);
- DEBUGASSERT(tmp == wrb);
- UNUSED(tmp);
+ ninfo("SEND: wrb=%p sent=%u pktlen=%u\n",
+ wrb, TCP_WBSENT(wrb), TCP_WBPKTLEN(wrb));
- /* Put the I/O buffer chain in the un-acked queue; the
- * segment is waiting for ACK again
+ /* Remove the write buffer from the write queue if the
+ * last of the data has been sent from the buffer.
*/
- psock_insert_segment(wrb, &conn->unacked_q);
- }
+ DEBUGASSERT(TCP_WBSENT(wrb) <= TCP_WBPKTLEN(wrb));
+ if (TCP_WBSENT(wrb) >= TCP_WBPKTLEN(wrb))
+ {
+ FAR struct tcp_wrbuffer_s *tmp;
- /* Only one data can be sent by low level driver at once,
- * tell the caller stop polling the other connection.
- */
+ ninfo("SEND: wrb=%p Move to unacked_q\n", wrb);
- flags &= ~TCP_POLL;
+ tmp = (FAR struct tcp_wrbuffer_s *)sq_remfirst(&conn->write_q);
+ DEBUGASSERT(tmp == wrb);
+ UNUSED(tmp);
+
+ /* Put the I/O buffer chain in the un-acked queue; the
+ * segment is waiting for ACK again
+ */
+
+ psock_insert_segment(wrb, &conn->unacked_q);
+ }
+
+ /* Only one data can be sent by low level driver at once,
+ * tell the caller stop polling the other connection.
+ */
+
+ flags &= ~TCP_POLL;
+ }
}
/* Continue waiting */