Skip to content

Commit 744380a

Browse files
shrek-wangkartben
authored andcommitted
net: tcp: Use correct seqnum for tcp_out and tcp_out_ext
Based on TCP Spec., the outgoing TCP packets shoud use SND.NXT as the seqnum. In Zephyr, the conn->seq works as the SND.UNA and the conn->seq + conn->unacked_len works as the SND.NXT. Currently, it uses SND.UNA in tcp_out() as the seqnum, which might get dropped as old packets and could not deliver the message to the peer. A few exceptions use SND.NXT - 1 as the seqnum are: keepalive, zero-window-probe, FIN/SYN retransmissions. And, for closing a connection, Zephyr won't send out FIN until all the data has been ACKed, so the conn->unacked_len is 0 and it is ok to use conn->seq as the SND.NXT. Signed-off-by: Shrek Wang <inet_eman@outlook.com>
1 parent 022043c commit 744380a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

subsys/net/ip/tcp.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ static int tcp_out_ext(struct tcp *conn, uint8_t flags, struct net_pkt *data,
16181618

16191619
static void tcp_out(struct tcp *conn, uint8_t flags)
16201620
{
1621-
(void)tcp_out_ext(conn, flags, NULL /* no data */, conn->seq);
1621+
(void)tcp_out_ext(conn, flags, NULL /* no data */, conn->seq + conn->unacked_len);
16221622
}
16231623

16241624
static int tcp_pkt_pull(struct net_pkt *pkt, size_t len)
@@ -2039,8 +2039,7 @@ static void tcp_send_keepalive_probe(struct k_work *work)
20392039
k_work_reschedule_for_queue(&tcp_work_q, &conn->keepalive_timer,
20402040
K_SECONDS(conn->keep_intvl));
20412041

2042-
2043-
(void)tcp_out_ext(conn, ACK, NULL, conn->seq - 1);
2042+
(void)tcp_out_ext(conn, ACK, NULL, conn->seq + conn->unacked_len - 1);
20442043
}
20452044
#endif /* CONFIG_NET_TCP_KEEPALIVE */
20462045

@@ -2051,7 +2050,7 @@ static void tcp_send_zwp(struct k_work *work)
20512050

20522051
k_mutex_lock(&conn->lock, K_FOREVER);
20532052

2054-
(void)tcp_out_ext(conn, ACK, NULL, conn->seq - 1);
2053+
(void)tcp_out_ext(conn, ACK, NULL, conn->seq + conn->unacked_len - 1);
20552054

20562055
tcp_derive_rto(conn);
20572056

0 commit comments

Comments
 (0)