• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From 70a1cdd2618f117c9f7da17b111a6c51db242f4b Mon Sep 17 00:00:00 2001
2From: wuchangsheng <wuchangsheng2@huawei.com>
3Date: Tue, 3 Aug 2021 11:23:10 +0800
4Subject: [PATCH] fix-the-incomplete-release-of-the-conntable
5
6---
7 src/core/tcp.c                   | 12 +++++++++++
8 src/include/lwip/priv/tcp_priv.h | 37 ++++++--------------------------
9 2 files changed, 19 insertions(+), 30 deletions(-)
10
11diff --git a/src/core/tcp.c b/src/core/tcp.c
12index 0aafa9b..2cfbce2 100644
13--- a/src/core/tcp.c
14+++ b/src/core/tcp.c
15@@ -235,6 +235,9 @@ tcp_init(void)
16 void
17 tcp_free(struct tcp_pcb *pcb)
18 {
19+#if USE_LIBOS
20+  vdev_unreg_done(pcb);
21+#endif
22   LWIP_ASSERT("tcp_free: LISTEN", pcb->state != LISTEN);
23 #if LWIP_TCP_PCB_NUM_EXT_ARGS
24   tcp_ext_arg_invoke_callbacks_destroyed(pcb->ext_args);
25@@ -943,6 +946,11 @@ tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u8_t backlog, err_t *err)
26 #if LWIP_TCP_PCB_NUM_EXT_ARGS
27   /* copy over ext_args to listening pcb  */
28   memcpy(&lpcb->ext_args, &pcb->ext_args, sizeof(pcb->ext_args));
29+#endif
30+#if USE_LIBOS
31+  /* pcb transfer to lpcb and reg into tcp_listen_pcbs. freeing pcb shouldn't release sock table in here.
32+   * local_port=0 avoid to release sock table in tcp_free */
33+  pcb->local_port = 0;
34 #endif
35   tcp_free(pcb);
36 #if LWIP_CALLBACK_API
37@@ -2263,6 +2271,10 @@ tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb)
38   LWIP_ASSERT("tcp_pcb_remove: invalid pcb", pcb != NULL);
39   LWIP_ASSERT("tcp_pcb_remove: invalid pcblist", pcblist != NULL);
40
41+#if USE_LIBOS
42+  vdev_unreg_done(pcb);
43+#endif
44+
45   TCP_RMV(pcblist, pcb);
46
47   tcp_pcb_purge(pcb);
48diff --git a/src/include/lwip/priv/tcp_priv.h b/src/include/lwip/priv/tcp_priv.h
49index 599289f..f771725 100644
50--- a/src/include/lwip/priv/tcp_priv.h
51+++ b/src/include/lwip/priv/tcp_priv.h
52@@ -358,27 +358,16 @@ static inline int vdev_reg_done(enum reg_ring_type reg_type, const struct tcp_pc
53
54   return vdev_reg_xmit(reg_type, &qtuple);
55 }
56-
57-/* TCP_RMV pcb whether to call vdev_reg_xmit to reg conn-sock table.
58-   fix the error of adding conn table in connect func and deleting conn table
59-   when moving pcb from tcp_bound_pcbs to tcp_listen_pcbs  */
60-static inline int need_vdev_reg(struct tcp_pcb *pcb_list, const struct tcp_pcb *pcb)
61+static inline void vdev_unreg_done(const struct tcp_pcb *pcb)
62 {
63-  /* tw_pcbs_list and tcp_listen_pcbs will not change pcb to other list always reg */
64-  if ((pcb_list == tcp_tw_pcbs) || (pcb_list == tcp_listen_pcbs.pcbs)) {
65-    return 1;
66+  if (pcb->local_port == 0) {
67+    return;
68   }
69-
70-  /* tcp_active_pcbs in FIN_WAIT_1,FIN_WAIT_2,CLOSING state will change pcb to tw_pcbs_list don't reg.
71-     detail info see func tcp_process in tcp_in.c */
72-  if (pcb_list == tcp_active_pcbs) {
73-    if ((pcb->state != FIN_WAIT_1) && (pcb->state != FIN_WAIT_2) && (pcb->state != CLOSING)) {
74-      return 1;
75-    }
76+  if (pcb->state == LISTEN) {
77+    vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, pcb);
78+  } else {
79+    vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, pcb);
80   }
81-
82-  /* tcp_bound_pcbs and others don't reg */
83-  return 0;
84 }
85 #endif
86
87@@ -414,12 +403,6 @@ static inline int need_vdev_reg(struct tcp_pcb *pcb_list, const struct tcp_pcb *
88               tcp_timer_needed(); \
89                             } while(0)
90 #define TCP_RMV(pcbs, npcb) do { \
91-                            if (need_vdev_reg(*pcbs, npcb)) {               \
92-                              if (npcb->state == LISTEN)                    \
93-                                vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, npcb);  \
94-                              else                                          \
95-                                vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, npcb); \
96-                            }                                               \
97                             struct tcp_pcb *tcp_tmp_pcb; \
98                             LWIP_ASSERT("TCP_RMV: pcbs != NULL", *(pcbs) != NULL); \
99                             LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", (npcb), *(pcbs))); \
100@@ -512,12 +495,6 @@ static inline int need_vdev_reg(struct tcp_pcb *pcb_list, const struct tcp_pcb *
101
102 #define TCP_RMV(pcbs, npcb)                        \
103   do {                                             \
104-    if (need_vdev_reg(*pcbs, npcb)) {              \
105-      if (npcb->state == LISTEN)                   \
106-        vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, npcb); \
107-      else                                         \
108-        vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, npcb);\
109-    }                                              \
110     if(*(pcbs) == (npcb)) {                        \
111       (*(pcbs)) = (*pcbs)->next;                   \
112       if (*pcbs)                                   \
113--
1142.23.0
115
116