1195972f6Sopenharmony_ciFrom 4ab4406f6e59ee09d893e31104236518fc81e991 Mon Sep 17 00:00:00 2001 2195972f6Sopenharmony_ciFrom: yangchen <yangchen145@huawei.com> 3195972f6Sopenharmony_ciDate: Tue, 28 Nov 2023 16:11:09 +0800 4195972f6Sopenharmony_ciSubject: [PATCH] add lwip log: tcp_rst & tcp_abandon & tcp_abort 5195972f6Sopenharmony_ci 6195972f6Sopenharmony_ci--- 7195972f6Sopenharmony_ci src/core/tcp.c | 24 ++++++++++++++++-------- 8195972f6Sopenharmony_ci src/core/tcp_in.c | 19 +++++++++++++++++-- 9195972f6Sopenharmony_ci src/include/lwip/debug.h | 4 ++-- 10195972f6Sopenharmony_ci 3 files changed, 35 insertions(+), 12 deletions(-) 11195972f6Sopenharmony_ci 12195972f6Sopenharmony_cidiff --git a/src/core/tcp.c b/src/core/tcp.c 13195972f6Sopenharmony_ciindex 963b8a4..a4f82a3 100644 14195972f6Sopenharmony_ci--- a/src/core/tcp.c 15195972f6Sopenharmony_ci+++ b/src/core/tcp.c 16195972f6Sopenharmony_ci@@ -415,6 +415,9 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data) 17195972f6Sopenharmony_ci 18195972f6Sopenharmony_ci /* don't call tcp_abort here: we must not deallocate the pcb since 19195972f6Sopenharmony_ci that might not be expected when calling tcp_close */ 20195972f6Sopenharmony_ci+ LWIP_DEBUGF(GAZELLE_DEBUG_SERIOUS, 21195972f6Sopenharmony_ci+ ("tcp_close_shutdown: Not all data received by app, send RST, local_port=%d, remote_port=%d\n", 22195972f6Sopenharmony_ci+ pcb->local_port, pcb->remote_port)); 23195972f6Sopenharmony_ci tcp_rst(pcb, pcb->snd_nxt, pcb->rcv_nxt, &pcb->local_ip, &pcb->remote_ip, 24195972f6Sopenharmony_ci pcb->local_port, pcb->remote_port); 25195972f6Sopenharmony_ci 26195972f6Sopenharmony_ci@@ -682,7 +685,8 @@ tcp_abandon(struct tcp_pcb *pcb, int reset) 27195972f6Sopenharmony_ci #endif /* TCP_QUEUE_OOSEQ */ 28195972f6Sopenharmony_ci tcp_backlog_accepted(pcb); 29195972f6Sopenharmony_ci if (send_rst) { 30195972f6Sopenharmony_ci- LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_abandon: sending RST\n")); 31195972f6Sopenharmony_ci+ LWIP_DEBUGF(TCP_RST_DEBUG | GAZELLE_DEBUG_SERIOUS, 32195972f6Sopenharmony_ci+ ("tcp_abandon: send RST, local port=%d, remote port=%d\n", local_port, pcb->remote_port)); 33195972f6Sopenharmony_ci tcp_rst(pcb, seqno, ackno, &pcb->local_ip, &pcb->remote_ip, local_port, pcb->remote_port); 34195972f6Sopenharmony_ci } 35195972f6Sopenharmony_ci last_state = pcb->state; 36195972f6Sopenharmony_ci@@ -1574,6 +1578,9 @@ tcp_slowtmr_start: 37195972f6Sopenharmony_ci #endif 38195972f6Sopenharmony_ci 39195972f6Sopenharmony_ci if (pcb_reset) { 40195972f6Sopenharmony_ci+ LWIP_DEBUGF(GAZELLE_DEBUG_SERIOUS, 41195972f6Sopenharmony_ci+ ("tcp_slowtmr: KEEPALIVE timeout, send RST, local port=%d, remote port=%d\n", 42195972f6Sopenharmony_ci+ pcb->local_port, pcb->remote_port)); 43195972f6Sopenharmony_ci tcp_rst(pcb, pcb->snd_nxt, pcb->rcv_nxt, &pcb->local_ip, &pcb->remote_ip, 44195972f6Sopenharmony_ci pcb->local_port, pcb->remote_port); 45195972f6Sopenharmony_ci } 46195972f6Sopenharmony_ci@@ -1941,8 +1948,8 @@ tcp_kill_prio(u8_t prio) 47195972f6Sopenharmony_ci } 48195972f6Sopenharmony_ci } 49195972f6Sopenharmony_ci if (inactive != NULL) { 50195972f6Sopenharmony_ci- LWIP_DEBUGF(TCP_DEBUG, ("tcp_kill_prio: killing oldest PCB %p (%"S32_F")\n", 51195972f6Sopenharmony_ci- (void *)inactive, inactivity)); 52195972f6Sopenharmony_ci+ LWIP_DEBUGF(TCP_DEBUG | GAZELLE_DEBUG_SERIOUS, 53195972f6Sopenharmony_ci+ ("tcp_kill_prio: killing oldest PCB (%"S32_F")\n", inactivity)); 54195972f6Sopenharmony_ci tcp_abort(inactive); 55195972f6Sopenharmony_ci } 56195972f6Sopenharmony_ci } 57195972f6Sopenharmony_ci@@ -1972,8 +1979,8 @@ tcp_kill_state(enum tcp_state state) 58195972f6Sopenharmony_ci } 59195972f6Sopenharmony_ci } 60195972f6Sopenharmony_ci if (inactive != NULL) { 61195972f6Sopenharmony_ci- LWIP_DEBUGF(TCP_DEBUG, ("tcp_kill_closing: killing oldest %s PCB %p (%"S32_F")\n", 62195972f6Sopenharmony_ci- tcp_state_str[state], (void *)inactive, inactivity)); 63195972f6Sopenharmony_ci+ LWIP_DEBUGF(TCP_DEBUG | GAZELLE_DEBUG_SERIOUS, 64195972f6Sopenharmony_ci+ ("tcp_kill_closing: killing oldest %s PCB (%"S32_F")\n", tcp_state_str[state], inactivity)); 65195972f6Sopenharmony_ci /* Don't send a RST, since no data is lost. */ 66195972f6Sopenharmony_ci tcp_abandon(inactive, 0); 67195972f6Sopenharmony_ci } 68195972f6Sopenharmony_ci@@ -1999,8 +2006,8 @@ tcp_kill_timewait(void) 69195972f6Sopenharmony_ci } 70195972f6Sopenharmony_ci } 71195972f6Sopenharmony_ci if (inactive != NULL) { 72195972f6Sopenharmony_ci- LWIP_DEBUGF(TCP_DEBUG, ("tcp_kill_timewait: killing oldest TIME-WAIT PCB %p (%"S32_F")\n", 73195972f6Sopenharmony_ci- (void *)inactive, inactivity)); 74195972f6Sopenharmony_ci+ LWIP_DEBUGF(TCP_DEBUG | GAZELLE_DEBUG_SERIOUS, 75195972f6Sopenharmony_ci+ ("tcp_kill_timewait: killing oldest TIME-WAIT PCB (%"S32_F")\n", inactivity)); 76195972f6Sopenharmony_ci tcp_abort(inactive); 77195972f6Sopenharmony_ci } 78195972f6Sopenharmony_ci } 79195972f6Sopenharmony_ci@@ -2540,7 +2547,8 @@ tcp_netif_ip_addr_changed_pcblist(const ip_addr_t *old_addr, struct tcp_pcb *pcb 80195972f6Sopenharmony_ci ) { 81195972f6Sopenharmony_ci /* this connection must be aborted */ 82195972f6Sopenharmony_ci struct tcp_pcb *next = pcb->next; 83195972f6Sopenharmony_ci- LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_set_ipaddr: aborting TCP pcb %p\n", (void *)pcb)); 84195972f6Sopenharmony_ci+ LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE | GAZELLE_DEBUG_SERIOUS, 85195972f6Sopenharmony_ci+ ("netif_set_ipaddr: aborting TCP\n")); 86195972f6Sopenharmony_ci tcp_abort(pcb); 87195972f6Sopenharmony_ci pcb = next; 88195972f6Sopenharmony_ci } else { 89195972f6Sopenharmony_cidiff --git a/src/core/tcp_in.c b/src/core/tcp_in.c 90195972f6Sopenharmony_ciindex 7154659..700a64c 100644 91195972f6Sopenharmony_ci--- a/src/core/tcp_in.c 92195972f6Sopenharmony_ci+++ b/src/core/tcp_in.c 93195972f6Sopenharmony_ci@@ -592,6 +592,7 @@ tcp_input(struct pbuf *p, struct netif *inp) 94195972f6Sopenharmony_ci pbuf_free(rest); 95195972f6Sopenharmony_ci } 96195972f6Sopenharmony_ci #endif /* TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */ 97195972f6Sopenharmony_ci+ LWIP_DEBUGF(GAZELLE_DEBUG_SERIOUS, ("tcp_input: received data although already closed, send RST\n")); 98195972f6Sopenharmony_ci tcp_abort(pcb); 99195972f6Sopenharmony_ci goto aborted; 100195972f6Sopenharmony_ci } 101195972f6Sopenharmony_ci@@ -683,10 +684,12 @@ aborted: 102195972f6Sopenharmony_ci } else { 103195972f6Sopenharmony_ci /* If no matching PCB was found, send a TCP RST (reset) to the 104195972f6Sopenharmony_ci sender. */ 105195972f6Sopenharmony_ci- LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_input: no PCB match found, resetting.\n")); 106195972f6Sopenharmony_ci if (!(TCPH_FLAGS(tcphdr) & TCP_RST)) { 107195972f6Sopenharmony_ci TCP_STATS_INC(tcp.proterr); 108195972f6Sopenharmony_ci TCP_STATS_INC(tcp.drop); 109195972f6Sopenharmony_ci+ LWIP_DEBUGF(TCP_RST_DEBUG | GAZELLE_DEBUG_SERIOUS, 110195972f6Sopenharmony_ci+ ("tcp_input: no PCB match found, send RST, dest port=%d, src port=%d\n", 111195972f6Sopenharmony_ci+ lwip_ntohs(tcphdr->dest), lwip_ntohs(tcphdr->src))); 112195972f6Sopenharmony_ci tcp_rst(NULL, ackno, seqno + tcplen, ip_current_dest_addr(), 113195972f6Sopenharmony_ci ip_current_src_addr(), tcphdr->dest, tcphdr->src); 114195972f6Sopenharmony_ci } 115195972f6Sopenharmony_ci@@ -761,7 +764,9 @@ tcp_listen_input(struct tcp_pcb_listen *pcb) 116195972f6Sopenharmony_ci if (flags & TCP_ACK) { 117195972f6Sopenharmony_ci /* For incoming segments with the ACK flag set, respond with a 118195972f6Sopenharmony_ci RST. */ 119195972f6Sopenharmony_ci- LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_listen_input: ACK in LISTEN, sending reset\n")); 120195972f6Sopenharmony_ci+ LWIP_DEBUGF(TCP_RST_DEBUG | GAZELLE_DEBUG_SERIOUS, 121195972f6Sopenharmony_ci+ ("tcp_listen_input: ACK in LISTEN, send reset, dest port=%d, src port=%d\n", 122195972f6Sopenharmony_ci+ lwip_ntohs(tcphdr->dest), lwip_ntohs(tcphdr->src))); 123195972f6Sopenharmony_ci tcp_rst((const struct tcp_pcb *)pcb, ackno, seqno + tcplen, ip_current_dest_addr(), 124195972f6Sopenharmony_ci ip_current_src_addr(), tcphdr->dest, tcphdr->src); 125195972f6Sopenharmony_ci } else if (flags & TCP_SYN) { 126195972f6Sopenharmony_ci@@ -852,6 +857,7 @@ tcp_listen_input(struct tcp_pcb_listen *pcb) 127195972f6Sopenharmony_ci /* Send a SYN|ACK together with the MSS option. */ 128195972f6Sopenharmony_ci rc = tcp_enqueue_flags(npcb, TCP_SYN | TCP_ACK); 129195972f6Sopenharmony_ci if (rc != ERR_OK) { 130195972f6Sopenharmony_ci+ LWIP_DEBUGF(GAZELLE_DEBUG_SERIOUS, ("tcp_listen_input: send SYN or ACK failed\n")); 131195972f6Sopenharmony_ci tcp_abandon(npcb, 0); 132195972f6Sopenharmony_ci PERF_RESUME(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_RECV); 133195972f6Sopenharmony_ci return; 134195972f6Sopenharmony_ci@@ -892,6 +898,9 @@ tcp_timewait_input(struct tcp_pcb *pcb) 135195972f6Sopenharmony_ci should be sent in reply */ 136195972f6Sopenharmony_ci if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt, pcb->rcv_nxt + pcb->rcv_wnd)) { 137195972f6Sopenharmony_ci /* If the SYN is in the window it is an error, send a reset */ 138195972f6Sopenharmony_ci+ LWIP_DEBUGF(GAZELLE_DEBUG_SERIOUS, 139195972f6Sopenharmony_ci+ ("tcp_timewait_input: SYN in TIME_WAIT, send RST, dest port=%d, src port=%d\n", 140195972f6Sopenharmony_ci+ lwip_ntohs(tcphdr->dest), lwip_ntohs(tcphdr->src))); 141195972f6Sopenharmony_ci tcp_rst(pcb, ackno, seqno + tcplen, ip_current_dest_addr(), 142195972f6Sopenharmony_ci ip_current_src_addr(), tcphdr->dest, tcphdr->src); 143195972f6Sopenharmony_ci return; 144195972f6Sopenharmony_ci@@ -1060,6 +1069,8 @@ tcp_process(struct tcp_pcb *pcb) 145195972f6Sopenharmony_ci /* received ACK? possibly a half-open connection */ 146195972f6Sopenharmony_ci else if (flags & TCP_ACK) { 147195972f6Sopenharmony_ci /* send a RST to bring the other side in a non-synchronized state. */ 148195972f6Sopenharmony_ci+ LWIP_DEBUGF(GAZELLE_DEBUG_SERIOUS, ("tcp_process: ACK in SYN_SENT, send RST, dest port=%d, src port=%d\n", 149195972f6Sopenharmony_ci+ lwip_ntohs(tcphdr->dest), lwip_ntohs(tcphdr->src))); 150195972f6Sopenharmony_ci tcp_rst(pcb, ackno, seqno + tcplen, ip_current_dest_addr(), 151195972f6Sopenharmony_ci ip_current_src_addr(), tcphdr->dest, tcphdr->src); 152195972f6Sopenharmony_ci /* Resend SYN immediately (don't wait for rto timeout) to establish 153195972f6Sopenharmony_ci@@ -1102,6 +1113,7 @@ tcp_process(struct tcp_pcb *pcb) 154195972f6Sopenharmony_ci * the connection. */ 155195972f6Sopenharmony_ci /* Already aborted? */ 156195972f6Sopenharmony_ci if (err != ERR_ABRT) { 157195972f6Sopenharmony_ci+ LWIP_DEBUGF(GAZELLE_DEBUG_SERIOUS, ("tcp_process: accept function returns with an error %d, send RST\n", err)); 158195972f6Sopenharmony_ci tcp_abort(pcb); 159195972f6Sopenharmony_ci } 160195972f6Sopenharmony_ci return ERR_ABRT; 161195972f6Sopenharmony_ci@@ -1129,6 +1141,9 @@ tcp_process(struct tcp_pcb *pcb) 162195972f6Sopenharmony_ci } 163195972f6Sopenharmony_ci } else { 164195972f6Sopenharmony_ci /* incorrect ACK number, send RST */ 165195972f6Sopenharmony_ci+ LWIP_DEBUGF(GAZELLE_DEBUG_SERIOUS, 166195972f6Sopenharmony_ci+ ("tcp_process: incorrect ACK number in SYN_RCVD, send RST, ackno=%d, lastack=%d, snd_nxt=%d, dest port=%d, src port=%d\n", 167195972f6Sopenharmony_ci+ ackno, pcb->lastack, pcb->snd_nxt, lwip_ntohs(tcphdr->dest), lwip_ntohs(tcphdr->src))); 168195972f6Sopenharmony_ci tcp_rst(pcb, ackno, seqno + tcplen, ip_current_dest_addr(), 169195972f6Sopenharmony_ci ip_current_src_addr(), tcphdr->dest, tcphdr->src); 170195972f6Sopenharmony_ci } 171195972f6Sopenharmony_cidiff --git a/src/include/lwip/debug.h b/src/include/lwip/debug.h 172195972f6Sopenharmony_ciindex f47cbfe..6abed9f 100644 173195972f6Sopenharmony_ci--- a/src/include/lwip/debug.h 174195972f6Sopenharmony_ci+++ b/src/include/lwip/debug.h 175195972f6Sopenharmony_ci@@ -56,12 +56,12 @@ 176195972f6Sopenharmony_ci /** Debug level: Serious. memory allocation failures, ... */ 177195972f6Sopenharmony_ci #define LWIP_DBG_LEVEL_SERIOUS 0x02 178195972f6Sopenharmony_ci /** Debug level: Severe */ 179195972f6Sopenharmony_ci-#define LWIP_DBG_LEVEL_SEVERE 0x03 180195972f6Sopenharmony_ci+#define LWIP_DBG_LEVEL_SEVERE 0x04 181195972f6Sopenharmony_ci /** 182195972f6Sopenharmony_ci * @} 183195972f6Sopenharmony_ci */ 184195972f6Sopenharmony_ci 185195972f6Sopenharmony_ci-#define LWIP_DBG_MASK_LEVEL 0x03 186195972f6Sopenharmony_ci+#define LWIP_DBG_MASK_LEVEL 0x07 187195972f6Sopenharmony_ci /* compatibility define only */ 188195972f6Sopenharmony_ci #define LWIP_DBG_LEVEL_OFF LWIP_DBG_LEVEL_ALL 189195972f6Sopenharmony_ci 190195972f6Sopenharmony_ci-- 191195972f6Sopenharmony_ci2.23.0 192195972f6Sopenharmony_ci 193