• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From b4a2b2799c199fb2955ecaae72e7b7dbe79e593b Mon Sep 17 00:00:00 2001
2From: jiangheng <jiangheng14@huawei.com>
3Date: Thu, 15 Jun 2023 21:42:04 +0800
4Subject: [PATCH] fix null pointer when all zero address listen
5
6---
7 src/core/tcp_in.c | 58 ++++++++++++++++++++++++++++-------------------
8 1 file changed, 35 insertions(+), 23 deletions(-)
9
10diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c
11index 0abee30..c20c9b5 100644
12--- a/src/core/tcp_in.c
13+++ b/src/core/tcp_in.c
14@@ -114,6 +114,36 @@ static void tcp_remove_sacks_gt(struct tcp_pcb *pcb, u32_t seq);
15 #endif /* TCP_OOSEQ_BYTES_LIMIT || TCP_OOSEQ_PBUFS_LIMIT */
16 #endif /* LWIP_TCP_SACK_OUT */
17
18+#if GAZELLE_TCP_REUSE_IPPORT
19+struct tcp_pcb_listen *min_cnts_lpcb_get(struct tcp_pcb_listen *lpcb)
20+{
21+  struct tcp_pcb_listen *min_cnts_lpcb;
22+  struct tcp_pcb_listen *tmp_lpcb = lpcb;
23+  u16_t min_conn_num = GAZELLE_TCP_MAX_CONN_PER_THREAD;
24+  u8_t have_master_fd = 0;
25+
26+  while (tmp_lpcb != NULL) {
27+    if (tmp_lpcb->master_lpcb) {
28+      have_master_fd = 1;
29+    }
30+    tmp_lpcb = tmp_lpcb->next_same_port_pcb;
31+  }
32+
33+  tmp_lpcb = lpcb;
34+  min_cnts_lpcb = lpcb;
35+  while (tmp_lpcb != NULL) {
36+    if (!have_master_fd || tmp_lpcb->master_lpcb) {
37+      if (tmp_lpcb->connect_num < min_conn_num) {
38+        min_cnts_lpcb = tmp_lpcb;
39+        min_conn_num = tmp_lpcb->connect_num;
40+      }
41+      tmp_lpcb = tmp_lpcb->next_same_port_pcb;
42+    }
43+  }
44+  return min_cnts_lpcb;
45+}
46+#endif
47+
48 /**
49  * The initial input processing of TCP. It verifies the TCP header, demultiplexes
50  * the segment between the PCBs and passes it on to tcp_process(), which implements
51@@ -384,33 +414,15 @@ tcp_input(struct pbuf *p, struct netif *inp)
52           if (ip_addr_cmp(&lpcb->local_ip, ip_current_dest_addr())) {
53             /* found an exact match */
54 #if GAZELLE_TCP_REUSE_IPPORT
55-            // check master fd
56-            struct tcp_pcb_listen *tmp_lpcb = lpcb;
57-            u8_t have_master_fd = 0;
58-            while (tmp_lpcb != NULL) {
59-              if (tmp_lpcb->master_lpcb) {
60-	        have_master_fd = 1;
61-	      }
62-              tmp_lpcb = tmp_lpcb->next_same_port_pcb;
63-	    }
64-
65-            tmp_lpcb = lpcb;
66-            min_cnts_lpcb = lpcb;
67-            u16_t min_conn_num = GAZELLE_TCP_MAX_CONN_PER_THREAD;
68-            while (tmp_lpcb != NULL) {
69-              if (!have_master_fd || tmp_lpcb->master_lpcb) {
70-                if (tmp_lpcb->connect_num < min_conn_num) {
71-                  min_cnts_lpcb = tmp_lpcb;
72-		  min_conn_num = tmp_lpcb->connect_num;
73-	        }
74-	      }
75-              tmp_lpcb = tmp_lpcb->next_same_port_pcb;
76-	    }
77+            min_cnts_lpcb = min_cnts_lpcb_get(lpcb);
78 #endif
79             break;
80           } else if (ip_addr_isany(&lpcb->local_ip)) {
81             /* found an ANY-match */
82 #if SO_REUSE
83+#if GAZELLE_TCP_REUSE_IPPORT
84+            min_cnts_lpcb = min_cnts_lpcb_get(lpcb);
85+#endif
86             lpcb_any = lpcb;
87             lpcb_prev = prev;
88 #else /* SO_REUSE */
89@@ -458,7 +470,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
90       {
91 #if GAZELLE_TCP_REUSE_IPPORT
92         tcp_listen_input(min_cnts_lpcb);
93-	min_cnts_lpcb->connect_num++;
94+        min_cnts_lpcb->connect_num++;
95 #else
96         tcp_listen_input(lpcb);
97 #endif
98--
992.27.0
100
101