From 8de32dd108ac0666aabf01aa68b017389a390b26 Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng14@huawei.com>
Date: Fri, 27 Sep 2024 15:41:42 +0800
Subject: [PATCH] add pingpong dfx support

---
 src/common/gazelle_dfx_msg.h  | 1 +
 src/lstack/core/lstack_lwip.c | 1 +
 src/ltran/ltran_dfx.c         | 7 ++++---
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h
index 08f9df1..266c239 100644
--- a/src/common/gazelle_dfx_msg.h
+++ b/src/common/gazelle_dfx_msg.h
@@ -281,6 +281,7 @@ struct gazelle_stat_lstack_conn_info {
     uint32_t keep_idle;
     uint32_t keep_intvl;
     uint32_t keep_cnt;
+    uint8_t pingpong;
 };
 
 struct gazelle_stat_lstack_conn {
diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c
index 7677e46..2eb872c 100644
--- a/src/lstack/core/lstack_lwip.c
+++ b/src/lstack/core/lstack_lwip.c
@@ -1257,6 +1257,7 @@ static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const s
     conn->keep_idle = pcb->keep_idle;
     conn->keep_intvl = pcb->keep_intvl;
     conn->keep_cnt = pcb->keep_cnt;
+    conn->pingpong = tcp_in_pingpong(pcb);
 
     if (netconn != NULL) {
         conn->fd = netconn->callback_arg.socket;
diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c
index fc30054..7fa117a 100644
--- a/src/ltran/ltran_dfx.c
+++ b/src/ltran/ltran_dfx.c
@@ -1242,7 +1242,7 @@ static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_
         printf("No.   Proto lwip_recv recv_ring in_send send_ring cwn      rcv_wnd  snd_wnd   snd_buf   snd_nxt"
             "        lastack        rcv_nxt        events    epoll_ev  evlist fd     Local Address"
             "                                        Foreign Address                                      State"
-            "     keep-alive keep-alive(idle,intvl,cnt)\n");
+            "     keep-alive keep-alive(idle,intvl,cnt) pingpong\n");
         uint32_t unread_pkts = 0;
         uint32_t unsend_pkts = 0;
         for (i = 0; i < conn->conn_num && i < GAZELLE_LSTACK_MAX_CONN; i++) {
@@ -1261,12 +1261,13 @@ static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_
                 sprintf_s(str_laddr, sizeof(str_laddr), "%s:%hu", str_ip, conn_info->l_port);
                 sprintf_s(str_raddr, sizeof(str_raddr), "%s:%hu", str_rip, conn_info->r_port);
                 printf("%-6utcp   %-10u%-10u%-8u%-10u%-9d%-9d%-10d%-10d%-15u%-15u%-15u%-10x%-10x%-7d%-7d"
-                    "%-52s %-52s %s  %-5d %s\n", i, conn_info->recv_cnt, conn_info->recv_ring_cnt, conn_info->in_send,
+                    "%-52s %-52s %s  %-5d %s  %d\n",
+                    i, conn_info->recv_cnt, conn_info->recv_ring_cnt, conn_info->in_send,
                     conn_info->send_ring_cnt, conn_info->cwn, conn_info->rcv_wnd, conn_info->snd_wnd,
                     conn_info->snd_buf, conn_info->snd_nxt, conn_info->lastack, conn_info->rcv_nxt, conn_info->events,
                     conn_info->epoll_events, conn_info->eventlist, conn_info->fd,
                     str_laddr, str_raddr, tcp_state_to_str(conn_info->tcp_sub_state),
-                    conn_info->keepalive, keepalive_info_str);
+                    conn_info->keepalive, keepalive_info_str, conn_info->pingpong);
             } else if (conn_info->state == GAZELLE_LISTEN_LIST) {
                 inet_ntop(domain, lip, str_ip, sizeof(str_ip));
                 sprintf_s(str_laddr, sizeof(str_laddr), "%s:%hu", str_ip, conn_info->l_port);
-- 
2.33.0

