1From 4ab4406f6e59ee09d893e31104236518fc81e991 Mon Sep 17 00:00:00 2001 2From: yangchen <yangchen145@huawei.com> 3Date: Tue, 28 Nov 2023 16:11:09 +0800 4Subject: [PATCH] add lwip log: tcp_rst & tcp_abandon & tcp_abort 5 6--- 7 src/core/tcp.c | 24 ++++++++++++++++-------- 8 src/core/tcp_in.c | 19 +++++++++++++++++-- 9 src/include/lwip/debug.h | 4 ++-- 10 3 files changed, 35 insertions(+), 12 deletions(-) 11 12diff --git a/src/core/tcp.c b/src/core/tcp.c 13index 963b8a4..a4f82a3 100644 14--- a/src/core/tcp.c 15+++ b/src/core/tcp.c 16@@ -415,6 +415,9 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data) 17 18 /* don't call tcp_abort here: we must not deallocate the pcb since 19 that might not be expected when calling tcp_close */ 20+ LWIP_DEBUGF(GAZELLE_DEBUG_SERIOUS, 21+ ("tcp_close_shutdown: Not all data received by app, send RST, local_port=%d, remote_port=%d\n", 22+ pcb->local_port, pcb->remote_port)); 23 tcp_rst(pcb, pcb->snd_nxt, pcb->rcv_nxt, &pcb->local_ip, &pcb->remote_ip, 24 pcb->local_port, pcb->remote_port); 25 26@@ -682,7 +685,8 @@ tcp_abandon(struct tcp_pcb *pcb, int reset) 27 #endif /* TCP_QUEUE_OOSEQ */ 28 tcp_backlog_accepted(pcb); 29 if (send_rst) { 30- LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_abandon: sending RST\n")); 31+ LWIP_DEBUGF(TCP_RST_DEBUG | GAZELLE_DEBUG_SERIOUS, 32+ ("tcp_abandon: send RST, local port=%d, remote port=%d\n", local_port, pcb->remote_port)); 33 tcp_rst(pcb, seqno, ackno, &pcb->local_ip, &pcb->remote_ip, local_port, pcb->remote_port); 34 } 35 last_state = pcb->state; 36@@ -1574,6 +1578,9 @@ tcp_slowtmr_start: 37 #endif 38 39 if (pcb_reset) { 40+ LWIP_DEBUGF(GAZELLE_DEBUG_SERIOUS, 41+ ("tcp_slowtmr: KEEPALIVE timeout, send RST, local port=%d, remote port=%d\n", 42+ pcb->local_port, pcb->remote_port)); 43 tcp_rst(pcb, pcb->snd_nxt, pcb->rcv_nxt, &pcb->local_ip, &pcb->remote_ip, 44 pcb->local_port, pcb->remote_port); 45 } 46@@ -1941,8 +1948,8 @@ tcp_kill_prio(u8_t prio) 47 } 48 } 49 if (inactive != NULL) { 50- LWIP_DEBUGF(TCP_DEBUG, ("tcp_kill_prio: killing oldest PCB %p (%"S32_F")\n", 51- (void *)inactive, inactivity)); 52+ LWIP_DEBUGF(TCP_DEBUG | GAZELLE_DEBUG_SERIOUS, 53+ ("tcp_kill_prio: killing oldest PCB (%"S32_F")\n", inactivity)); 54 tcp_abort(inactive); 55 } 56 } 57@@ -1972,8 +1979,8 @@ tcp_kill_state(enum tcp_state state) 58 } 59 } 60 if (inactive != NULL) { 61- LWIP_DEBUGF(TCP_DEBUG, ("tcp_kill_closing: killing oldest %s PCB %p (%"S32_F")\n", 62- tcp_state_str[state], (void *)inactive, inactivity)); 63+ LWIP_DEBUGF(TCP_DEBUG | GAZELLE_DEBUG_SERIOUS, 64+ ("tcp_kill_closing: killing oldest %s PCB (%"S32_F")\n", tcp_state_str[state], inactivity)); 65 /* Don't send a RST, since no data is lost. */ 66 tcp_abandon(inactive, 0); 67 } 68@@ -1999,8 +2006,8 @@ tcp_kill_timewait(void) 69 } 70 } 71 if (inactive != NULL) { 72- LWIP_DEBUGF(TCP_DEBUG, ("tcp_kill_timewait: killing oldest TIME-WAIT PCB %p (%"S32_F")\n", 73- (void *)inactive, inactivity)); 74+ LWIP_DEBUGF(TCP_DEBUG | GAZELLE_DEBUG_SERIOUS, 75+ ("tcp_kill_timewait: killing oldest TIME-WAIT PCB (%"S32_F")\n", inactivity)); 76 tcp_abort(inactive); 77 } 78 } 79@@ -2540,7 +2547,8 @@ tcp_netif_ip_addr_changed_pcblist(const ip_addr_t *old_addr, struct tcp_pcb *pcb 80 ) { 81 /* this connection must be aborted */ 82 struct tcp_pcb *next = pcb->next; 83- LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_set_ipaddr: aborting TCP pcb %p\n", (void *)pcb)); 84+ LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE | GAZELLE_DEBUG_SERIOUS, 85+ ("netif_set_ipaddr: aborting TCP\n")); 86 tcp_abort(pcb); 87 pcb = next; 88 } else { 89diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c 90index 7154659..700a64c 100644 91--- a/src/core/tcp_in.c 92+++ b/src/core/tcp_in.c 93@@ -592,6 +592,7 @@ tcp_input(struct pbuf *p, struct netif *inp) 94 pbuf_free(rest); 95 } 96 #endif /* TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */ 97+ LWIP_DEBUGF(GAZELLE_DEBUG_SERIOUS, ("tcp_input: received data although already closed, send RST\n")); 98 tcp_abort(pcb); 99 goto aborted; 100 } 101@@ -683,10 +684,12 @@ aborted: 102 } else { 103 /* If no matching PCB was found, send a TCP RST (reset) to the 104 sender. */ 105- LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_input: no PCB match found, resetting.\n")); 106 if (!(TCPH_FLAGS(tcphdr) & TCP_RST)) { 107 TCP_STATS_INC(tcp.proterr); 108 TCP_STATS_INC(tcp.drop); 109+ LWIP_DEBUGF(TCP_RST_DEBUG | GAZELLE_DEBUG_SERIOUS, 110+ ("tcp_input: no PCB match found, send RST, dest port=%d, src port=%d\n", 111+ lwip_ntohs(tcphdr->dest), lwip_ntohs(tcphdr->src))); 112 tcp_rst(NULL, ackno, seqno + tcplen, ip_current_dest_addr(), 113 ip_current_src_addr(), tcphdr->dest, tcphdr->src); 114 } 115@@ -761,7 +764,9 @@ tcp_listen_input(struct tcp_pcb_listen *pcb) 116 if (flags & TCP_ACK) { 117 /* For incoming segments with the ACK flag set, respond with a 118 RST. */ 119- LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_listen_input: ACK in LISTEN, sending reset\n")); 120+ LWIP_DEBUGF(TCP_RST_DEBUG | GAZELLE_DEBUG_SERIOUS, 121+ ("tcp_listen_input: ACK in LISTEN, send reset, dest port=%d, src port=%d\n", 122+ lwip_ntohs(tcphdr->dest), lwip_ntohs(tcphdr->src))); 123 tcp_rst((const struct tcp_pcb *)pcb, ackno, seqno + tcplen, ip_current_dest_addr(), 124 ip_current_src_addr(), tcphdr->dest, tcphdr->src); 125 } else if (flags & TCP_SYN) { 126@@ -852,6 +857,7 @@ tcp_listen_input(struct tcp_pcb_listen *pcb) 127 /* Send a SYN|ACK together with the MSS option. */ 128 rc = tcp_enqueue_flags(npcb, TCP_SYN | TCP_ACK); 129 if (rc != ERR_OK) { 130+ LWIP_DEBUGF(GAZELLE_DEBUG_SERIOUS, ("tcp_listen_input: send SYN or ACK failed\n")); 131 tcp_abandon(npcb, 0); 132 PERF_RESUME(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_RECV); 133 return; 134@@ -892,6 +898,9 @@ tcp_timewait_input(struct tcp_pcb *pcb) 135 should be sent in reply */ 136 if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt, pcb->rcv_nxt + pcb->rcv_wnd)) { 137 /* If the SYN is in the window it is an error, send a reset */ 138+ LWIP_DEBUGF(GAZELLE_DEBUG_SERIOUS, 139+ ("tcp_timewait_input: SYN in TIME_WAIT, send RST, dest port=%d, src port=%d\n", 140+ lwip_ntohs(tcphdr->dest), lwip_ntohs(tcphdr->src))); 141 tcp_rst(pcb, ackno, seqno + tcplen, ip_current_dest_addr(), 142 ip_current_src_addr(), tcphdr->dest, tcphdr->src); 143 return; 144@@ -1060,6 +1069,8 @@ tcp_process(struct tcp_pcb *pcb) 145 /* received ACK? possibly a half-open connection */ 146 else if (flags & TCP_ACK) { 147 /* send a RST to bring the other side in a non-synchronized state. */ 148+ LWIP_DEBUGF(GAZELLE_DEBUG_SERIOUS, ("tcp_process: ACK in SYN_SENT, send RST, dest port=%d, src port=%d\n", 149+ lwip_ntohs(tcphdr->dest), lwip_ntohs(tcphdr->src))); 150 tcp_rst(pcb, ackno, seqno + tcplen, ip_current_dest_addr(), 151 ip_current_src_addr(), tcphdr->dest, tcphdr->src); 152 /* Resend SYN immediately (don't wait for rto timeout) to establish 153@@ -1102,6 +1113,7 @@ tcp_process(struct tcp_pcb *pcb) 154 * the connection. */ 155 /* Already aborted? */ 156 if (err != ERR_ABRT) { 157+ LWIP_DEBUGF(GAZELLE_DEBUG_SERIOUS, ("tcp_process: accept function returns with an error %d, send RST\n", err)); 158 tcp_abort(pcb); 159 } 160 return ERR_ABRT; 161@@ -1129,6 +1141,9 @@ tcp_process(struct tcp_pcb *pcb) 162 } 163 } else { 164 /* incorrect ACK number, send RST */ 165+ LWIP_DEBUGF(GAZELLE_DEBUG_SERIOUS, 166+ ("tcp_process: incorrect ACK number in SYN_RCVD, send RST, ackno=%d, lastack=%d, snd_nxt=%d, dest port=%d, src port=%d\n", 167+ ackno, pcb->lastack, pcb->snd_nxt, lwip_ntohs(tcphdr->dest), lwip_ntohs(tcphdr->src))); 168 tcp_rst(pcb, ackno, seqno + tcplen, ip_current_dest_addr(), 169 ip_current_src_addr(), tcphdr->dest, tcphdr->src); 170 } 171diff --git a/src/include/lwip/debug.h b/src/include/lwip/debug.h 172index f47cbfe..6abed9f 100644 173--- a/src/include/lwip/debug.h 174+++ b/src/include/lwip/debug.h 175@@ -56,12 +56,12 @@ 176 /** Debug level: Serious. memory allocation failures, ... */ 177 #define LWIP_DBG_LEVEL_SERIOUS 0x02 178 /** Debug level: Severe */ 179-#define LWIP_DBG_LEVEL_SEVERE 0x03 180+#define LWIP_DBG_LEVEL_SEVERE 0x04 181 /** 182 * @} 183 */ 184 185-#define LWIP_DBG_MASK_LEVEL 0x03 186+#define LWIP_DBG_MASK_LEVEL 0x07 187 /* compatibility define only */ 188 #define LWIP_DBG_LEVEL_OFF LWIP_DBG_LEVEL_ALL 189 190-- 1912.23.0 192 193