1From 1aa27395a4c4b73b6db472c4ae75ed91637a11bf Mon Sep 17 00:00:00 2001 2From: kircher <majun65@huawei.com> 3Date: Wed, 21 Dec 2022 17:50:50 +0800 4Subject: [PATCH] add dataack when recv too many acks with data 5 6--- 7 src/core/tcp_in.c | 22 ++++++++++++++++++++++ 8 src/include/lwip/tcp.h | 1 + 9 src/include/lwipopts.h | 2 ++ 10 3 files changed, 25 insertions(+) 11 12diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c 13index 78954bd..35ec6d9 100644 14--- a/src/core/tcp_in.c 15+++ b/src/core/tcp_in.c 16@@ -1260,6 +1260,7 @@ tcp_receive(struct tcp_pcb *pcb) 17 s16_t m; 18 u32_t right_wnd_edge; 19 int found_dupack = 0; 20+ int found_dataack = 0; 21 22 LWIP_ASSERT("tcp_receive: invalid pcb", pcb != NULL); 23 LWIP_ASSERT("tcp_receive: wrong state", pcb->state >= ESTABLISHED); 24@@ -1337,11 +1338,31 @@ tcp_receive(struct tcp_pcb *pcb) 25 } 26 } 27 } 28+ /* fast rexmit when receive too many acks with data */ 29+ if (TCP_SEQ_LT(ackno + 1, pcb->snd_nxt)) { 30+ if (pcb->snd_wl2 + pcb->snd_wnd == right_wnd_edge) { 31+ if (pcb->rtime >= 0) { 32+ if (pcb->lastack == ackno) { 33+ found_dataack = 1; 34+ ++pcb->dataacks; 35+ if (pcb->dataacks > MAX_DATA_ACK_NUM) { 36+ if (tcp_rexmit(pcb) == ERR_OK) { 37+ pcb->rtime = 0; 38+ pcb->dataacks = 0; 39+ } 40+ } 41+ } 42+ } 43+ } 44+ } 45 /* If Clause (1) or more is true, but not a duplicate ack, reset 46 * count of consecutive duplicate acks */ 47 if (!found_dupack) { 48 pcb->dupacks = 0; 49 } 50+ if (!found_dataack) { 51+ pcb->dataacks = 0; 52+ } 53 } else if (TCP_SEQ_BETWEEN(ackno, pcb->lastack + 1, pcb->snd_nxt)) { 54 /* We come here when the ACK acknowledges new data. */ 55 tcpwnd_size_t acked; 56@@ -1367,6 +1388,7 @@ tcp_receive(struct tcp_pcb *pcb) 57 /* Reset the fast retransmit variables. */ 58 pcb->dupacks = 0; 59 pcb->lastack = ackno; 60+ pcb->dataacks = 0; 61 62 /* Update the congestion control variables (cwnd and 63 ssthresh). */ 64diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h 65index 2a61776..97cb882 100644 66--- a/src/include/lwip/tcp.h 67+++ b/src/include/lwip/tcp.h 68@@ -326,6 +326,7 @@ struct tcp_pcb { 69 70 /* fast retransmit/recovery */ 71 u8_t dupacks; 72+ u32_t dataacks; 73 u32_t lastack; /* Highest acknowledged seqno. */ 74 75 /* congestion avoidance/control variables */ 76diff --git a/src/include/lwipopts.h b/src/include/lwipopts.h 77index 907c630..405cf11 100644 78--- a/src/include/lwipopts.h 79+++ b/src/include/lwipopts.h 80@@ -177,6 +177,8 @@ 81 82 #define MIN_TSO_SEG_LEN 256 83 84+#define MAX_DATA_ACK_NUM 256 85+ 86 /* --------------------------------------- 87 * ------- NIC offloads -------- 88 * --------------------------------------- 89-- 902.33.0 91 92