1From ed999b65aac44fcb68fc533e8bd5a23cf2d09e7c Mon Sep 17 00:00:00 2001 2From: wuchangsheng <wuchangsheng2@huawei.com> 3Date: Wed, 26 May 2021 19:09:41 +0800 4Subject: [PATCH] fix-error-of-deleting-conn-table-in-connect 5 6--- 7 src/include/lwip/priv/tcp_priv.h | 42 ++++++++++++++++++++++++++------ 8 1 file changed, 34 insertions(+), 8 deletions(-) 9 10diff --git a/src/include/lwip/priv/tcp_priv.h b/src/include/lwip/priv/tcp_priv.h 11index 192edc4..599289f 100644 12--- a/src/include/lwip/priv/tcp_priv.h 13+++ b/src/include/lwip/priv/tcp_priv.h 14@@ -358,6 +358,28 @@ static inline int vdev_reg_done(enum reg_ring_type reg_type, const struct tcp_pc 15 16 return vdev_reg_xmit(reg_type, &qtuple); 17 } 18+ 19+/* TCP_RMV pcb whether to call vdev_reg_xmit to reg conn-sock table. 20+ fix the error of adding conn table in connect func and deleting conn table 21+ when moving pcb from tcp_bound_pcbs to tcp_listen_pcbs */ 22+static inline int need_vdev_reg(struct tcp_pcb *pcb_list, const struct tcp_pcb *pcb) 23+{ 24+ /* tw_pcbs_list and tcp_listen_pcbs will not change pcb to other list always reg */ 25+ if ((pcb_list == tcp_tw_pcbs) || (pcb_list == tcp_listen_pcbs.pcbs)) { 26+ return 1; 27+ } 28+ 29+ /* tcp_active_pcbs in FIN_WAIT_1,FIN_WAIT_2,CLOSING state will change pcb to tw_pcbs_list don't reg. 30+ detail info see func tcp_process in tcp_in.c */ 31+ if (pcb_list == tcp_active_pcbs) { 32+ if ((pcb->state != FIN_WAIT_1) && (pcb->state != FIN_WAIT_2) && (pcb->state != CLOSING)) { 33+ return 1; 34+ } 35+ } 36+ 37+ /* tcp_bound_pcbs and others don't reg */ 38+ return 0; 39+} 40 #endif 41 42 /* Axioms about the above lists: 43@@ -392,10 +414,12 @@ static inline int vdev_reg_done(enum reg_ring_type reg_type, const struct tcp_pc 44 tcp_timer_needed(); \ 45 } while(0) 46 #define TCP_RMV(pcbs, npcb) do { \ 47- if (pcb->state == LISTEN) \ 48- vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, npcb); \ 49- else \ 50- vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, npcb);\ 51+ if (need_vdev_reg(*pcbs, npcb)) { \ 52+ if (npcb->state == LISTEN) \ 53+ vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, npcb); \ 54+ else \ 55+ vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, npcb); \ 56+ } \ 57 struct tcp_pcb *tcp_tmp_pcb; \ 58 LWIP_ASSERT("TCP_RMV: pcbs != NULL", *(pcbs) != NULL); \ 59 LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", (npcb), *(pcbs))); \ 60@@ -488,10 +512,12 @@ static inline int vdev_reg_done(enum reg_ring_type reg_type, const struct tcp_pc 61 62 #define TCP_RMV(pcbs, npcb) \ 63 do { \ 64- if (pcb->state == LISTEN) \ 65- vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, npcb); \ 66- else \ 67- vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, npcb);\ 68+ if (need_vdev_reg(*pcbs, npcb)) { \ 69+ if (npcb->state == LISTEN) \ 70+ vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, npcb); \ 71+ else \ 72+ vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, npcb);\ 73+ } \ 74 if(*(pcbs) == (npcb)) { \ 75 (*(pcbs)) = (*pcbs)->next; \ 76 if (*pcbs) \ 77-- 782.23.0 79 80