• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From 212198780662639e0422419a25d28ff2bb0d421e Mon Sep 17 00:00:00 2001
2From: hantwofish <hankangkang5@huawei.com>
3Date: Mon, 25 Dec 2023 15:36:45 +0800
4Subject: [PATCH] Mod the issue that 2w connection unable to establish in
5 Redis.
6
7---
8 src/api/api_lib.c               |  2 +-
9 src/api/api_msg.c               |  2 +-
10 src/api/sockets.c               | 19 ++++++++++++-------
11 src/core/init.c                 |  4 ++--
12 src/core/tcp.c                  |  4 ++--
13 src/core/tcp_in.c               |  2 +-
14 src/include/lwip/api.h          |  2 +-
15 src/include/lwip/opt.h          |  2 +-
16 src/include/lwip/priv/api_msg.h |  2 +-
17 src/include/lwip/tcp.h          |  8 ++++----
18 src/include/lwipopts.h          |  4 ++--
19 11 files changed, 28 insertions(+), 23 deletions(-)
20
21diff --git a/src/api/api_lib.c b/src/api/api_lib.c
22index e73b81e..30e3422 100644
23--- a/src/api/api_lib.c
24+++ b/src/api/api_lib.c
25@@ -431,7 +431,7 @@ netconn_disconnect(struct netconn *conn)
26  *         don't return any error (yet?))
27  */
28 err_t
29-netconn_listen_with_backlog(struct netconn *conn, u8_t backlog)
30+netconn_listen_with_backlog(struct netconn *conn, u16_t backlog)
31 {
32 #if LWIP_TCP
33   API_MSG_VAR_DECLARE(msg);
34diff --git a/src/api/api_msg.c b/src/api/api_msg.c
35index 531da40..91b8590 100644
36--- a/src/api/api_msg.c
37+++ b/src/api/api_msg.c
38@@ -1499,7 +1499,7 @@ lwip_netconn_do_listen(void *m)
39           /* connection is not closed, cannot listen */
40           err = ERR_VAL;
41         } else {
42-          u8_t backlog;
43+          u16_t backlog;
44 #if TCP_LISTEN_BACKLOG
45           backlog = msg->msg.lb.backlog;
46 #else  /* TCP_LISTEN_BACKLOG */
47diff --git a/src/api/sockets.c b/src/api/sockets.c
48index f5b8ea6..b7ee304 100644
49--- a/src/api/sockets.c
50+++ b/src/api/sockets.c
51@@ -447,7 +447,7 @@ tryget_socket_unconn_nouse(int fd)
52   if ((s < 0) || (s >= NUM_SOCKETS))
53 #endif /* GAZELLE_ENABLE */
54   {
55-    LWIP_DEBUGF(SOCKETS_DEBUG, ("tryget_socket_unconn(%d): invalid\n", fd));
56+    LWIP_DEBUGF(SOCKETS_DEBUG | GAZELLE_DEBUG_SERIOUS, ("tryget_socket_unconn(%d): invalid\n", fd));
57     return NULL;
58   }
59   return &sockets[s];
60@@ -521,7 +521,7 @@ get_socket(int fd)
61   struct lwip_sock *sock = tryget_socket(fd);
62   if (!sock) {
63     if ((fd < LWIP_SOCKET_OFFSET) || (fd >= (LWIP_SOCKET_OFFSET + NUM_SOCKETS))) {
64-      LWIP_DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): invalid\n", fd));
65+      LWIP_DEBUGF(SOCKETS_DEBUG | GAZELLE_DEBUG_SERIOUS, ("get_socket(%d): invalid\n", fd));
66     }
67     set_errno(EBADF);
68     return NULL;
69@@ -588,6 +588,7 @@ alloc_socket(struct netconn *newconn, int accepted, int flags)
70   SYS_ARCH_PROTECT(lev);
71   i = posix_api->socket_fn(domain, type, protocol);
72   if (i == -1) {
73+    LWIP_DEBUGF(SOCKETS_DEBUG | GAZELLE_DEBUG_SERIOUS, ("posix_api->socket_fn fail socket is -1"));
74     goto err;
75   }
76
77@@ -596,6 +597,7 @@ alloc_socket(struct netconn *newconn, int accepted, int flags)
78   }
79
80   if ((i < LWIP_SOCKET_OFFSET) || (i >= sockets_num + LWIP_SOCKET_OFFSET)) {
81+    LWIP_DEBUGF(SOCKETS_DEBUG | GAZELLE_DEBUG_SERIOUS, ("posix_api->socket_fn  socket is %d, illegal\n", i));
82     goto err;
83   }
84
85@@ -767,13 +769,14 @@ lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags)
86
87   sock = get_socket(s);
88   if (!sock) {
89+    LWIP_DEBUGF(SOCKETS_DEBUG | GAZELLE_DEBUG_SERIOUS, ("get_socket sock is null\n"));
90     return -1;
91   }
92
93   /* wait for a new connection */
94   err = netconn_accept(sock->conn, &newconn);
95   if (err != ERR_OK) {
96-    LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d): netconn_acept failed, err=%d\n", s, err));
97+    LWIP_DEBUGF(SOCKETS_DEBUG | GAZELLE_DEBUG_SERIOUS, ("lwip_accept(%d): netconn_acept failed, err=%d\n", s, err));
98     if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) != NETCONN_TCP) {
99       sock_set_errno(sock, EOPNOTSUPP);
100     } else if (err == ERR_CLSD) {
101@@ -788,6 +791,7 @@ lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags)
102
103   newsock = alloc_socket(newconn, 1, flags);
104   if (newsock == -1) {
105+    LWIP_DEBUGF(SOCKETS_DEBUG | GAZELLE_DEBUG_SERIOUS, ("alloc_socket fail newsock is -1\n"));
106     netconn_delete(newconn);
107     sock_set_errno(sock, ENFILE);
108     done_socket(sock);
109@@ -807,6 +811,7 @@ lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags)
110     ret = find_same_node_memzone(pcb, nsock);
111   }
112   if (pcb == NULL || ret != 0) {
113+      LWIP_DEBUGF(SOCKETS_DEBUG | GAZELLE_DEBUG_SERIOUS, ("alloc_socket fail pcb null flag=%u, ret=%d \n", (pcb == NULL), ret));
114       netconn_delete(newconn);
115       free_socket(nsock, 1);
116       sock_set_errno(sock, ENOTCONN);
117@@ -842,7 +847,7 @@ lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags)
118     /* get the IP address and port of the remote host */
119     err = netconn_peer(newconn, &naddr, &port);
120     if (err != ERR_OK) {
121-      LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d): netconn_peer failed, err=%d\n", s, err));
122+      LWIP_DEBUGF(SOCKETS_DEBUG | GAZELLE_DEBUG_SERIOUS, ("lwip_accept(%d): netconn_peer failed, err=%d\n", s, err));
123       free_socket(nsock, 1);
124       sock_set_errno(sock, err_to_errno(err));
125       done_socket(sock);
126@@ -1059,10 +1064,10 @@ lwip_listen(int s, int backlog)
127     return -1;
128   }
129
130-  /* limit the "backlog" parameter to fit in an u8_t */
131-  backlog = LWIP_MIN(LWIP_MAX(backlog, 0), 0xff);
132+  /* limit the "backlog" parameter to fit in an u16_t */
133+  backlog = LWIP_MIN(LWIP_MAX(backlog, 0), 0xffff);
134
135-  err = netconn_listen_with_backlog(sock->conn, (u8_t)backlog);
136+  err = netconn_listen_with_backlog(sock->conn, (u16_t)backlog);
137
138   if (err != ERR_OK) {
139     LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_listen(%d) failed, err=%d\n", s, err));
140diff --git a/src/core/init.c b/src/core/init.c
141index 6880fd3..8c59a7c 100644
142--- a/src/core/init.c
143+++ b/src/core/init.c
144@@ -160,8 +160,8 @@ PACK_STRUCT_END
145 #if (LWIP_TCP && ((TCP_MAXRTX > 12) || (TCP_SYNMAXRTX > 12)))
146 #error "If you want to use TCP, TCP_MAXRTX and TCP_SYNMAXRTX must less or equal to 12 (due to tcp_backoff table), so, you have to reduce them in your lwipopts.h"
147 #endif
148-#if (LWIP_TCP && TCP_LISTEN_BACKLOG && ((TCP_DEFAULT_LISTEN_BACKLOG < 0) || (TCP_DEFAULT_LISTEN_BACKLOG > 0xff)))
149-#error "If you want to use TCP backlog, TCP_DEFAULT_LISTEN_BACKLOG must fit into an u8_t"
150+#if (LWIP_TCP && TCP_LISTEN_BACKLOG && ((TCP_DEFAULT_LISTEN_BACKLOG < 0) || (TCP_DEFAULT_LISTEN_BACKLOG > 0xffff)))
151+#error "If you want to use TCP backlog, TCP_DEFAULT_LISTEN_BACKLOG must fit into an u16_t"
152 #endif
153 #if (LWIP_TCP && LWIP_TCP_SACK_OUT && !TCP_QUEUE_OOSEQ)
154 #error "To use LWIP_TCP_SACK_OUT, TCP_QUEUE_OOSEQ needs to be enabled"
155diff --git a/src/core/tcp.c b/src/core/tcp.c
156index ca70a85..76f0ffd 100644
157--- a/src/core/tcp.c
158+++ b/src/core/tcp.c
159@@ -903,7 +903,7 @@ tcp_accept_null(void *arg, struct tcp_pcb *pcb, err_t err)
160  *             tpcb = tcp_listen_with_backlog(tpcb, backlog);
161  */
162 struct tcp_pcb *
163-tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog)
164+tcp_listen_with_backlog(struct tcp_pcb *pcb, u16_t backlog)
165 {
166   LWIP_ASSERT_CORE_LOCKED();
167   return tcp_listen_with_backlog_and_err(pcb, backlog, NULL);
168@@ -926,7 +926,7 @@ tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog)
169  *             tpcb = tcp_listen_with_backlog_and_err(tpcb, backlog, &err);
170  */
171 struct tcp_pcb *
172-tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u8_t backlog, err_t *err)
173+tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u16_t backlog, err_t *err)
174 {
175   struct tcp_pcb_listen *lpcb = NULL;
176   err_t res;
177diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c
178index c76c114..e9ab96f 100644
179--- a/src/core/tcp_in.c
180+++ b/src/core/tcp_in.c
181@@ -785,7 +785,7 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
182        SYN at a time when we have more memory available. */
183     if (npcb == NULL) {
184       err_t err;
185-      LWIP_DEBUGF(TCP_DEBUG, ("tcp_listen_input: could not allocate PCB\n"));
186+      LWIP_DEBUGF(TCP_DEBUG | GAZELLE_DEBUG_SERIOUS, ("tcp_listen_input: could not allocate PCB\n"));
187       TCP_STATS_INC(tcp.memerr);
188       TCP_EVENT_ACCEPT(pcb, NULL, pcb->callback_arg, ERR_MEM, err);
189       LWIP_UNUSED_ARG(err); /* err not useful here */
190diff --git a/src/include/lwip/api.h b/src/include/lwip/api.h
191index ed237c7..a986cd4 100644
192--- a/src/include/lwip/api.h
193+++ b/src/include/lwip/api.h
194@@ -366,7 +366,7 @@ err_t   netconn_bind(struct netconn *conn, const ip_addr_t *addr, u16_t port);
195 err_t   netconn_bind_if(struct netconn *conn, u8_t if_idx);
196 err_t   netconn_connect(struct netconn *conn, const ip_addr_t *addr, u16_t port);
197 err_t   netconn_disconnect (struct netconn *conn);
198-err_t   netconn_listen_with_backlog(struct netconn *conn, u8_t backlog);
199+err_t   netconn_listen_with_backlog(struct netconn *conn, u16_t backlog);
200 /** @ingroup netconn_tcp */
201 #define netconn_listen(conn) netconn_listen_with_backlog(conn, TCP_DEFAULT_LISTEN_BACKLOG)
202 err_t   netconn_accept(struct netconn *conn, struct netconn **new_conn);
203diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h
204index 57a1a53..6332d51 100644
205--- a/src/include/lwip/opt.h
206+++ b/src/include/lwip/opt.h
207@@ -1428,7 +1428,7 @@
208  * 0xff is the maximum (u8_t).
209  */
210 #if !defined TCP_DEFAULT_LISTEN_BACKLOG || defined __DOXYGEN__
211-#define TCP_DEFAULT_LISTEN_BACKLOG      0xff
212+#define TCP_DEFAULT_LISTEN_BACKLOG      0xffff
213 #endif
214
215 /**
216diff --git a/src/include/lwip/priv/api_msg.h b/src/include/lwip/priv/api_msg.h
217index 9e8ffc9..b36f00a 100644
218--- a/src/include/lwip/priv/api_msg.h
219+++ b/src/include/lwip/priv/api_msg.h
220@@ -145,7 +145,7 @@ struct api_msg {
221 #endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */
222 #if TCP_LISTEN_BACKLOG
223     struct {
224-      u8_t backlog;
225+      u16_t backlog;
226     } lb;
227 #endif /* TCP_LISTEN_BACKLOG */
228   } msg;
229diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h
230index 91a86c9..741e58f 100644
231--- a/src/include/lwip/tcp.h
232+++ b/src/include/lwip/tcp.h
233@@ -249,8 +249,8 @@ struct tcp_pcb_listen {
234 #endif /* LWIP_CALLBACK_API */
235
236 #if TCP_LISTEN_BACKLOG
237-  u8_t backlog;
238-  u8_t accepts_pending;
239+  u16_t backlog;
240+  u16_t accepts_pending;
241 #endif /* TCP_LISTEN_BACKLOG */
242
243 #if GAZELLE_TCP_REUSE_IPPORT
244@@ -575,8 +575,8 @@ void             tcp_bind_netif(struct tcp_pcb *pcb, const struct netif *netif);
245 err_t            tcp_connect (struct tcp_pcb *pcb, const ip_addr_t *ipaddr,
246                               u16_t port, tcp_connected_fn connected);
247
248-struct tcp_pcb * tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u8_t backlog, err_t *err);
249-struct tcp_pcb * tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog);
250+struct tcp_pcb * tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u16_t backlog, err_t *err);
251+struct tcp_pcb * tcp_listen_with_backlog(struct tcp_pcb *pcb, u16_t backlog);
252 /** @ingroup tcp_raw */
253 #define          tcp_listen(pcb) tcp_listen_with_backlog(pcb, TCP_DEFAULT_LISTEN_BACKLOG)
254
255diff --git a/src/include/lwipopts.h b/src/include/lwipopts.h
256index 82cf881..44ed80f 100644
257--- a/src/include/lwipopts.h
258+++ b/src/include/lwipopts.h
259@@ -210,11 +210,11 @@
260
261 #define TCP_HLEN 20
262
263-#define DEFAULT_ACCEPTMBOX_SIZE 1024
264+#define DEFAULT_ACCEPTMBOX_SIZE 4096
265 #define DEFAULT_TCP_RECVMBOX_SIZE 4096
266
267 #define TCP_LISTEN_BACKLOG 1
268-#define TCP_DEFAULT_LISTEN_BACKLOG 0xff
269+#define TCP_DEFAULT_LISTEN_BACKLOG 0xffff
270
271 #define TCP_OVERSIZE TCP_MSS
272 #define LWIP_NETIF_TX_SINGLE_PBUF 1
273--
2742.33.0
275
276