From c46244f54dba29e5a3c40ef276022994b7994f82 Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng14@huawei.com>
Date: Mon, 30 Sep 2024 18:13:21 +0800
Subject: [PATCH] pingpong: fix send dup ack

---
 src/core/tcp.c    | 11 ++++++-----
 src/core/tcp_in.c |  3 +--
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/core/tcp.c b/src/core/tcp.c
index 4a3c031..849a210 100644
--- a/src/core/tcp.c
+++ b/src/core/tcp.c
@@ -1702,13 +1702,14 @@ tcp_fasttmr_start:
     if (pcb->last_timer != tcp_timer_ctr) {
       struct tcp_pcb *next;
       pcb->last_timer = tcp_timer_ctr;
-#if !GAZELLE_TCP_PINGPONG_MODE
-      /* send delayed ACKs */
-      if (pcb->flags & TF_ACK_DELAY) {
-#else
-      if (!tcp_in_pingpong(pcb) || TIME_BEFORE(pcb->lrcvtime + TCP_ATO_MS, sys_now())) {
+#if GAZELLE_TCP_PINGPONG_MODE
+      if (tcp_in_pingpong(pcb) && TIME_BEFORE(pcb->lrcvtime + TCP_ATO_MS, sys_now())) {
         tcp_exit_pingpong(pcb);
+        tcp_set_flags(pcb, TF_ACK_DELAY);
+      }
 #endif
+      /* send delayed ACKs */
+      if (pcb->flags & TF_ACK_DELAY) {
         LWIP_DEBUGF(TCP_DEBUG, ("tcp_fasttmr: delayed ACK\n"));
         MIB2_STATS_INC(mib2.tcpdelayackcnt);
         tcp_ack_now(pcb);
diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c
index 1751561..fa2a88b 100644
--- a/src/core/tcp_in.c
+++ b/src/core/tcp_in.c
@@ -1767,8 +1767,7 @@ tcp_receive(struct tcp_pcb *pcb)
         /* Acknowledge the segment(s). */
 #if GAZELLE_TCP_PINGPONG_MODE
         if (tcp_in_pingpong(pcb)) {
-          tcp_clear_flags(pcb, TF_ACK_NOW);
-          tcp_set_flags(pcb, TF_ACK_DELAY);
+          tcp_clear_flags(pcb, TF_ACK_NOW | TF_ACK_DELAY);
         } else {
           tcp_ack(pcb);
         }
-- 
2.33.0

