From 175f3818dc8ea64b37c4aa804375ef1216601813 Mon Sep 17 00:00:00 2001
From: hantwofish <hankangkang5@huawei.com>
Date: Thu, 7 Dec 2023 00:38:00 +0800
Subject: [PATCH] gazellectl add connect para

---
 src/common/gazelle_dfx_msg.h  | 2 ++
 src/lstack/core/lstack_lwip.c | 2 ++
 src/ltran/ltran_dfx.c         | 8 +++++---
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h
index e2485ef..f91a661 100644
--- a/src/common/gazelle_dfx_msg.h
+++ b/src/common/gazelle_dfx_msg.h
@@ -194,6 +194,8 @@ struct gazelle_stat_lstack_conn_info {
     uint32_t events;
     uint32_t epoll_events;
     uint32_t eventlist;
+    uint32_t keepalive;
+    uint32_t keep_idle;
 };
 
 struct gazelle_stat_lstack_conn {
diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c
index 7fb164c..5a719ea 100644
--- a/src/lstack/core/lstack_lwip.c
+++ b/src/lstack/core/lstack_lwip.c
@@ -1148,6 +1148,8 @@ static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const s
     conn->lastack = pcb->lastack;
     conn->snd_nxt = pcb->snd_nxt;
     conn->rcv_nxt = pcb->rcv_nxt;
+    conn->keepalive = (ip_get_option(pcb, SOF_KEEPALIVE) != 0);
+    conn->keep_idle = pcb->keep_idle;
 
     if (netconn != NULL && netconn->recvmbox != NULL) {
         conn->recv_cnt = rte_ring_count(netconn->recvmbox->ring);
diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c
index b999d20..fcbe857 100644
--- a/src/ltran/ltran_dfx.c
+++ b/src/ltran/ltran_dfx.c
@@ -993,7 +993,8 @@ static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_
         printf("\n------ stack tid: %6u ------time=%lu\n", stat->tid, time.tv_sec * 1000000 + time.tv_usec);
         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\n");
+            "                                        Foreign Address                                      State"
+            "     keep-alive keep-idle\n");
         uint32_t unread_pkts = 0;
         uint32_t unsend_pkts = 0;
         for (i = 0; i < conn->conn_num && i < GAZELLE_LSTACK_MAX_CONN; i++) {
@@ -1009,11 +1010,12 @@ 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\n", i, conn_info->recv_cnt, conn_info->recv_ring_cnt, conn_info->in_send,
+                    "%-52s %-52s %s  %-5d %-9u\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));
+                    str_laddr, str_raddr, tcp_state_to_str(conn_info->tcp_sub_state),
+                    conn_info->keepalive, conn_info->keep_idle);
             } 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.27.0

