1195972f6Sopenharmony_ciFrom ed999b65aac44fcb68fc533e8bd5a23cf2d09e7c Mon Sep 17 00:00:00 2001 2195972f6Sopenharmony_ciFrom: wuchangsheng <wuchangsheng2@huawei.com> 3195972f6Sopenharmony_ciDate: Wed, 26 May 2021 19:09:41 +0800 4195972f6Sopenharmony_ciSubject: [PATCH] fix-error-of-deleting-conn-table-in-connect 5195972f6Sopenharmony_ci 6195972f6Sopenharmony_ci--- 7195972f6Sopenharmony_ci src/include/lwip/priv/tcp_priv.h | 42 ++++++++++++++++++++++++++------ 8195972f6Sopenharmony_ci 1 file changed, 34 insertions(+), 8 deletions(-) 9195972f6Sopenharmony_ci 10195972f6Sopenharmony_cidiff --git a/src/include/lwip/priv/tcp_priv.h b/src/include/lwip/priv/tcp_priv.h 11195972f6Sopenharmony_ciindex 192edc4..599289f 100644 12195972f6Sopenharmony_ci--- a/src/include/lwip/priv/tcp_priv.h 13195972f6Sopenharmony_ci+++ b/src/include/lwip/priv/tcp_priv.h 14195972f6Sopenharmony_ci@@ -358,6 +358,28 @@ static inline int vdev_reg_done(enum reg_ring_type reg_type, const struct tcp_pc 15195972f6Sopenharmony_ci 16195972f6Sopenharmony_ci return vdev_reg_xmit(reg_type, &qtuple); 17195972f6Sopenharmony_ci } 18195972f6Sopenharmony_ci+ 19195972f6Sopenharmony_ci+/* TCP_RMV pcb whether to call vdev_reg_xmit to reg conn-sock table. 20195972f6Sopenharmony_ci+ fix the error of adding conn table in connect func and deleting conn table 21195972f6Sopenharmony_ci+ when moving pcb from tcp_bound_pcbs to tcp_listen_pcbs */ 22195972f6Sopenharmony_ci+static inline int need_vdev_reg(struct tcp_pcb *pcb_list, const struct tcp_pcb *pcb) 23195972f6Sopenharmony_ci+{ 24195972f6Sopenharmony_ci+ /* tw_pcbs_list and tcp_listen_pcbs will not change pcb to other list always reg */ 25195972f6Sopenharmony_ci+ if ((pcb_list == tcp_tw_pcbs) || (pcb_list == tcp_listen_pcbs.pcbs)) { 26195972f6Sopenharmony_ci+ return 1; 27195972f6Sopenharmony_ci+ } 28195972f6Sopenharmony_ci+ 29195972f6Sopenharmony_ci+ /* tcp_active_pcbs in FIN_WAIT_1,FIN_WAIT_2,CLOSING state will change pcb to tw_pcbs_list don't reg. 30195972f6Sopenharmony_ci+ detail info see func tcp_process in tcp_in.c */ 31195972f6Sopenharmony_ci+ if (pcb_list == tcp_active_pcbs) { 32195972f6Sopenharmony_ci+ if ((pcb->state != FIN_WAIT_1) && (pcb->state != FIN_WAIT_2) && (pcb->state != CLOSING)) { 33195972f6Sopenharmony_ci+ return 1; 34195972f6Sopenharmony_ci+ } 35195972f6Sopenharmony_ci+ } 36195972f6Sopenharmony_ci+ 37195972f6Sopenharmony_ci+ /* tcp_bound_pcbs and others don't reg */ 38195972f6Sopenharmony_ci+ return 0; 39195972f6Sopenharmony_ci+} 40195972f6Sopenharmony_ci #endif 41195972f6Sopenharmony_ci 42195972f6Sopenharmony_ci /* Axioms about the above lists: 43195972f6Sopenharmony_ci@@ -392,10 +414,12 @@ static inline int vdev_reg_done(enum reg_ring_type reg_type, const struct tcp_pc 44195972f6Sopenharmony_ci tcp_timer_needed(); \ 45195972f6Sopenharmony_ci } while(0) 46195972f6Sopenharmony_ci #define TCP_RMV(pcbs, npcb) do { \ 47195972f6Sopenharmony_ci- if (pcb->state == LISTEN) \ 48195972f6Sopenharmony_ci- vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, npcb); \ 49195972f6Sopenharmony_ci- else \ 50195972f6Sopenharmony_ci- vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, npcb);\ 51195972f6Sopenharmony_ci+ if (need_vdev_reg(*pcbs, npcb)) { \ 52195972f6Sopenharmony_ci+ if (npcb->state == LISTEN) \ 53195972f6Sopenharmony_ci+ vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, npcb); \ 54195972f6Sopenharmony_ci+ else \ 55195972f6Sopenharmony_ci+ vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, npcb); \ 56195972f6Sopenharmony_ci+ } \ 57195972f6Sopenharmony_ci struct tcp_pcb *tcp_tmp_pcb; \ 58195972f6Sopenharmony_ci LWIP_ASSERT("TCP_RMV: pcbs != NULL", *(pcbs) != NULL); \ 59195972f6Sopenharmony_ci LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", (npcb), *(pcbs))); \ 60195972f6Sopenharmony_ci@@ -488,10 +512,12 @@ static inline int vdev_reg_done(enum reg_ring_type reg_type, const struct tcp_pc 61195972f6Sopenharmony_ci 62195972f6Sopenharmony_ci #define TCP_RMV(pcbs, npcb) \ 63195972f6Sopenharmony_ci do { \ 64195972f6Sopenharmony_ci- if (pcb->state == LISTEN) \ 65195972f6Sopenharmony_ci- vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, npcb); \ 66195972f6Sopenharmony_ci- else \ 67195972f6Sopenharmony_ci- vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, npcb);\ 68195972f6Sopenharmony_ci+ if (need_vdev_reg(*pcbs, npcb)) { \ 69195972f6Sopenharmony_ci+ if (npcb->state == LISTEN) \ 70195972f6Sopenharmony_ci+ vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, npcb); \ 71195972f6Sopenharmony_ci+ else \ 72195972f6Sopenharmony_ci+ vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, npcb);\ 73195972f6Sopenharmony_ci+ } \ 74195972f6Sopenharmony_ci if(*(pcbs) == (npcb)) { \ 75195972f6Sopenharmony_ci (*(pcbs)) = (*pcbs)->next; \ 76195972f6Sopenharmony_ci if (*pcbs) \ 77195972f6Sopenharmony_ci-- 78195972f6Sopenharmony_ci2.23.0 79195972f6Sopenharmony_ci 80