!16 [sync] PR-11: adapt to lstack

From: @openeuler-sync-bot 
Reviewed-by: @LemmyHuang 
Signed-off-by: @LemmyHuang
This commit is contained in:
openeuler-ci-bot 2022-02-25 03:46:57 +00:00 committed by Gitee
commit 4e4e45bdea
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
15 changed files with 6470 additions and 6 deletions

5569
0002-adapt-lstack.patch Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,63 @@
From 0d5070b4a40912a7921e0101461a9c7d61919acd Mon Sep 17 00:00:00 2001
From: HuangLiming <huangliming5@huawei.com>
Date: Tue, 25 May 2021 03:08:33 -0400
Subject: [PATCH] fix the occasional coredump when the lwip exits
Signed-off-by: HuangLiming <huangliming5@huawei.com>
---
src/api/sockets.c | 37 +++++++++----------------------------
1 file changed, 9 insertions(+), 28 deletions(-)
diff --git a/src/api/sockets.c b/src/api/sockets.c
index d62e55b..658f762 100644
--- a/src/api/sockets.c
+++ b/src/api/sockets.c
@@ -4655,36 +4655,17 @@ void lwip_sock_init(void)
return;
}
-//modify from lwip_close
void lwip_exit(void)
{
- int i, is_tcp;
- struct lwip_sock *sock;
-
- if (memp_pools[MEMP_SYS_MBOX] == NULL) {
- return;
- }
-
- for (i = 0; i < sockets_num; i++) {
- sock = &sockets[i];
- if (!sock->conn)
- continue;
-#if LWIP_IGMP
- /* drop all possibly joined IGMP memberships */
- lwip_socket_drop_registered_memberships(i);
-#endif /* LWIP_IGMP */
- /*
- * process is exiting, call netconn_delete to
- * close tcp connection, and ignore the return value
- */
- is_tcp = NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP;
- netconn_delete(sock->conn);
- free_socket(sock, is_tcp);
- }
-
- free(sockets);
- sockets = NULL;
- sockets_num = 0;
+ /*
+ * LwIP has the following two parts of memory application, but
+ * it is unnecessary to release all memory in sequentially,
+ * which increases complexity. Therefore, we rely on the process
+ * reclamation mechanism of the system to release memory.
+ * 1. a sockets table of the process.
+ * 2. a batch of hugepage memory of each thread.
+ */
+ return;
}
#endif /* USE_LIBOS */
--
2.23.0

View File

@ -0,0 +1,79 @@
From ed999b65aac44fcb68fc533e8bd5a23cf2d09e7c Mon Sep 17 00:00:00 2001
From: wuchangsheng <wuchangsheng2@huawei.com>
Date: Wed, 26 May 2021 19:09:41 +0800
Subject: [PATCH] fix-error-of-deleting-conn-table-in-connect
---
src/include/lwip/priv/tcp_priv.h | 42 ++++++++++++++++++++++++++------
1 file changed, 34 insertions(+), 8 deletions(-)
diff --git a/src/include/lwip/priv/tcp_priv.h b/src/include/lwip/priv/tcp_priv.h
index 192edc4..599289f 100644
--- a/src/include/lwip/priv/tcp_priv.h
+++ b/src/include/lwip/priv/tcp_priv.h
@@ -358,6 +358,28 @@ static inline int vdev_reg_done(enum reg_ring_type reg_type, const struct tcp_pc
return vdev_reg_xmit(reg_type, &qtuple);
}
+
+/* TCP_RMV pcb whether to call vdev_reg_xmit to reg conn-sock table.
+ fix the error of adding conn table in connect func and deleting conn table
+ when moving pcb from tcp_bound_pcbs to tcp_listen_pcbs */
+static inline int need_vdev_reg(struct tcp_pcb *pcb_list, const struct tcp_pcb *pcb)
+{
+ /* tw_pcbs_list and tcp_listen_pcbs will not change pcb to other list always reg */
+ if ((pcb_list == tcp_tw_pcbs) || (pcb_list == tcp_listen_pcbs.pcbs)) {
+ return 1;
+ }
+
+ /* tcp_active_pcbs in FIN_WAIT_1,FIN_WAIT_2,CLOSING state will change pcb to tw_pcbs_list don't reg.
+ detail info see func tcp_process in tcp_in.c */
+ if (pcb_list == tcp_active_pcbs) {
+ if ((pcb->state != FIN_WAIT_1) && (pcb->state != FIN_WAIT_2) && (pcb->state != CLOSING)) {
+ return 1;
+ }
+ }
+
+ /* tcp_bound_pcbs and others don't reg */
+ return 0;
+}
#endif
/* Axioms about the above lists:
@@ -392,10 +414,12 @@ static inline int vdev_reg_done(enum reg_ring_type reg_type, const struct tcp_pc
tcp_timer_needed(); \
} while(0)
#define TCP_RMV(pcbs, npcb) do { \
- if (pcb->state == LISTEN) \
- vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, npcb); \
- else \
- vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, npcb);\
+ if (need_vdev_reg(*pcbs, npcb)) { \
+ if (npcb->state == LISTEN) \
+ vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, npcb); \
+ else \
+ vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, npcb); \
+ } \
struct tcp_pcb *tcp_tmp_pcb; \
LWIP_ASSERT("TCP_RMV: pcbs != NULL", *(pcbs) != NULL); \
LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", (npcb), *(pcbs))); \
@@ -488,10 +512,12 @@ static inline int vdev_reg_done(enum reg_ring_type reg_type, const struct tcp_pc
#define TCP_RMV(pcbs, npcb) \
do { \
- if (pcb->state == LISTEN) \
- vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, npcb); \
- else \
- vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, npcb);\
+ if (need_vdev_reg(*pcbs, npcb)) { \
+ if (npcb->state == LISTEN) \
+ vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, npcb); \
+ else \
+ vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, npcb);\
+ } \
if(*(pcbs) == (npcb)) { \
(*(pcbs)) = (*pcbs)->next; \
if (*pcbs) \
--
2.23.0

View File

@ -0,0 +1,27 @@
From 19c51d7baf7eeeae72525f6b716253557be2b31c Mon Sep 17 00:00:00 2001
From: wuchangsheng <wuchangsheng2@huawei.com>
Date: Tue, 29 Jun 2021 14:12:25 +0800
Subject: [PATCH] add-conn-check
---
src/core/tcp_in.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c
index c3d1f54..57186c7 100644
--- a/src/core/tcp_in.c
+++ b/src/core/tcp_in.c
@@ -752,6 +752,10 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
#endif
TCP_REG_ACTIVE(npcb);
+#if USE_LIBOS
+ vdev_reg_done(REG_RING_TCP_CONNECT, npcb);
+#endif
+
/* Parse any options in the SYN. */
tcp_parseopt(npcb);
npcb->snd_wnd = tcphdr->wnd;
--
2.23.0

View File

@ -0,0 +1,29 @@
From a066306d783693d3f78b9c5e84feca7d690cf27a Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng12@huawei.com>
Date: Fri, 2 Jul 2021 16:54:43 +0800
Subject: [PATCH] fix coredump in etharp
---
src/core/ipv4/etharp.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/core/ipv4/etharp.c b/src/core/ipv4/etharp.c
index c3a5a10..effb7db 100644
--- a/src/core/ipv4/etharp.c
+++ b/src/core/ipv4/etharp.c
@@ -102,10 +102,10 @@ struct etharp_entry {
u8_t state;
};
-static struct etharp_entry arp_table[ARP_TABLE_SIZE];
+static PER_THREAD struct etharp_entry arp_table[ARP_TABLE_SIZE];
#if !LWIP_NETIF_HWADDRHINT
-static netif_addr_idx_t etharp_cached_entry;
+static PER_THREAD netif_addr_idx_t etharp_cached_entry;
#endif /* !LWIP_NETIF_HWADDRHINT */
/** Try hard to create a new entry - we want the IP address to appear in
--
2.23.0

View File

@ -0,0 +1,102 @@
From b867f6901773def31884a9ae527a1282d274a85d Mon Sep 17 00:00:00 2001
From: wuchangsheng <wuchangsheng2@huawei.com>
Date: Sat, 10 Jul 2021 22:27:19 +0800
Subject: [PATCH] fix epoll_ctl EPOLLET mode error
---
src/api/sockets.c | 33 +++++++++++++++++++++++----------
1 file changed, 23 insertions(+), 10 deletions(-)
diff --git a/src/api/sockets.c b/src/api/sockets.c
index 658f762..eccc7f9 100644
--- a/src/api/sockets.c
+++ b/src/api/sockets.c
@@ -714,6 +714,13 @@ free_socket(struct lwip_sock *sock, int is_tcp)
/* Protect socket array */
SYS_ARCH_PROTECT(lev);
+#if USE_LIBOS
+ sock->epoll = LIBOS_EPOLLNONE;
+ sock->events = 0;
+ sock->epoll_data = NULL;
+ list_del_node_null(&sock->list);
+#endif
+
freed = free_socket_locked(sock, is_tcp, &conn, &lastdata);
SYS_ARCH_UNPROTECT(lev);
/* don't use 'sock' after this line, as another task might have allocated it */
@@ -1003,13 +1010,6 @@ lwip_close(int s)
return -1;
}
-#if USE_LIBOS
- sock->epoll = LIBOS_EPOLLNONE;
- sock->events = 0;
- sock->epoll_data = NULL;
- list_del_node_null(&sock->list);
-#endif
-
free_socket(sock, is_tcp);
set_errno(0);
return 0;
@@ -1191,7 +1191,7 @@ lwip_recv_tcp(struct lwip_sock *sock, void *mem, size_t len, int flags)
if (sock->lastdata.pbuf) {
p = sock->lastdata.pbuf;
#if USE_LIBOS
- if ((flags & MSG_PEEK) == 0) {
+ if (((flags & MSG_PEEK) == 0) && ((sock->epoll & EPOLLET) == 0)) {
if ((NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP)) {
del_epoll_event(sock->conn, EPOLLIN);
}
@@ -2889,6 +2889,9 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
check_waiters = 0;
}
#if USE_LIBOS
+ if (sock->epoll & EPOLLET) {
+ list_del_node_null(&sock->list);
+ }
add_epoll_event(conn, EPOLLIN);
#endif
break;
@@ -2896,7 +2899,9 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
sock->rcvevent--;
check_waiters = 0;
#if USE_LIBOS
- del_epoll_event(conn, EPOLLIN);
+ if ((sock->epoll & EPOLLET) == 0) {
+ del_epoll_event(conn, EPOLLIN);
+ }
#endif
break;
case NETCONN_EVT_SENDPLUS:
@@ -2905,6 +2910,9 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
}
sock->sendevent = 1;
#if USE_LIBOS
+ if (sock->epoll & EPOLLET) {
+ list_del_node_null(&sock->list);
+ }
add_epoll_event(conn, EPOLLOUT);
#endif
break;
@@ -2912,12 +2920,17 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
sock->sendevent = 0;
check_waiters = 0;
#if USE_LIBOS
- del_epoll_event(conn, EPOLLOUT);
+ if ((sock->epoll & EPOLLET) == 0) {
+ del_epoll_event(conn, EPOLLOUT);
+ }
#endif
break;
case NETCONN_EVT_ERROR:
sock->errevent = 1;
#if USE_LIBOS
+ if (sock->epoll & EPOLLET) {
+ list_del_node_null(&sock->list);
+ }
add_epoll_event(conn, EPOLLERR);
#endif
break;
--
2.23.0

View File

@ -0,0 +1,25 @@
From bf1c7febb9f6c3a2336f18f658694393dea451ae Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng12@huawei.com>
Date: Fri, 16 Jul 2021 14:44:03 +0800
Subject: [PATCH] [Huawei]gazelle: fix lwip_accept memcpy sockaddr larger than
actual
---
src/api/sockets.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/api/sockets.c b/src/api/sockets.c
index eccc7f9..e640945 100644
--- a/src/api/sockets.c
+++ b/src/api/sockets.c
@@ -860,6 +860,8 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
if (*addrlen > tempaddr.sa.sa_len) {
*addrlen = tempaddr.sa.sa_len;
}
+#else
+ *addrlen = LWIP_MIN(*addrlen, sizeof(tempaddr));
#endif /* USE_LIBOS */
MEMCPY(addr, &tempaddr, *addrlen);
--
2.23.0

View File

@ -0,0 +1,35 @@
From d1f9ccd5da1712477f30bf2662e8888395ed95cd Mon Sep 17 00:00:00 2001
From: wuchangsheng <wuchangsheng2@huawei.com>
Date: Wed, 21 Jul 2021 20:01:47 +0800
Subject: [PATCH] fix stack-buffer-overflow in lwip_sock_make_addr and
lwip_getaddrname
---
src/api/sockets.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/api/sockets.c b/src/api/sockets.c
index e640945..7ce9378 100644
--- a/src/api/sockets.c
+++ b/src/api/sockets.c
@@ -1319,6 +1319,8 @@ lwip_sock_make_addr(struct netconn *conn, ip_addr_t *fromaddr, u16_t port,
} else if (*fromlen > saddr.sa.sa_len) {
*fromlen = saddr.sa.sa_len;
}
+#else
+ *fromlen = LWIP_MIN(*fromlen, sizeof(saddr));
#endif
MEMCPY(from, &saddr, *fromlen);
return truncated;
@@ -3133,6 +3135,8 @@ lwip_getaddrname(int s, struct sockaddr *name, socklen_t *namelen, u8_t local)
if (*namelen > saddr.sa.sa_len) {
*namelen = saddr.sa.sa_len;
}
+#else
+ *namelen = LWIP_MIN(*namelen, sizeof(saddr));
#endif
MEMCPY(name, &saddr, *namelen);
--
2.23.0

View File

@ -0,0 +1,115 @@
From 70a1cdd2618f117c9f7da17b111a6c51db242f4b Mon Sep 17 00:00:00 2001
From: wuchangsheng <wuchangsheng2@huawei.com>
Date: Tue, 3 Aug 2021 11:23:10 +0800
Subject: [PATCH] fix-the-incomplete-release-of-the-conntable
---
src/core/tcp.c | 12 +++++++++++
src/include/lwip/priv/tcp_priv.h | 37 ++++++--------------------------
2 files changed, 19 insertions(+), 30 deletions(-)
diff --git a/src/core/tcp.c b/src/core/tcp.c
index 0aafa9b..2cfbce2 100644
--- a/src/core/tcp.c
+++ b/src/core/tcp.c
@@ -235,6 +235,9 @@ tcp_init(void)
void
tcp_free(struct tcp_pcb *pcb)
{
+#if USE_LIBOS
+ vdev_unreg_done(pcb);
+#endif
LWIP_ASSERT("tcp_free: LISTEN", pcb->state != LISTEN);
#if LWIP_TCP_PCB_NUM_EXT_ARGS
tcp_ext_arg_invoke_callbacks_destroyed(pcb->ext_args);
@@ -943,6 +946,11 @@ tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u8_t backlog, err_t *err)
#if LWIP_TCP_PCB_NUM_EXT_ARGS
/* copy over ext_args to listening pcb */
memcpy(&lpcb->ext_args, &pcb->ext_args, sizeof(pcb->ext_args));
+#endif
+#if USE_LIBOS
+ /* pcb transfer to lpcb and reg into tcp_listen_pcbs. freeing pcb shouldn't release sock table in here.
+ * local_port=0 avoid to release sock table in tcp_free */
+ pcb->local_port = 0;
#endif
tcp_free(pcb);
#if LWIP_CALLBACK_API
@@ -2263,6 +2271,10 @@ tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb)
LWIP_ASSERT("tcp_pcb_remove: invalid pcb", pcb != NULL);
LWIP_ASSERT("tcp_pcb_remove: invalid pcblist", pcblist != NULL);
+#if USE_LIBOS
+ vdev_unreg_done(pcb);
+#endif
+
TCP_RMV(pcblist, pcb);
tcp_pcb_purge(pcb);
diff --git a/src/include/lwip/priv/tcp_priv.h b/src/include/lwip/priv/tcp_priv.h
index 599289f..f771725 100644
--- a/src/include/lwip/priv/tcp_priv.h
+++ b/src/include/lwip/priv/tcp_priv.h
@@ -358,27 +358,16 @@ static inline int vdev_reg_done(enum reg_ring_type reg_type, const struct tcp_pc
return vdev_reg_xmit(reg_type, &qtuple);
}
-
-/* TCP_RMV pcb whether to call vdev_reg_xmit to reg conn-sock table.
- fix the error of adding conn table in connect func and deleting conn table
- when moving pcb from tcp_bound_pcbs to tcp_listen_pcbs */
-static inline int need_vdev_reg(struct tcp_pcb *pcb_list, const struct tcp_pcb *pcb)
+static inline void vdev_unreg_done(const struct tcp_pcb *pcb)
{
- /* tw_pcbs_list and tcp_listen_pcbs will not change pcb to other list always reg */
- if ((pcb_list == tcp_tw_pcbs) || (pcb_list == tcp_listen_pcbs.pcbs)) {
- return 1;
+ if (pcb->local_port == 0) {
+ return;
}
-
- /* tcp_active_pcbs in FIN_WAIT_1,FIN_WAIT_2,CLOSING state will change pcb to tw_pcbs_list don't reg.
- detail info see func tcp_process in tcp_in.c */
- if (pcb_list == tcp_active_pcbs) {
- if ((pcb->state != FIN_WAIT_1) && (pcb->state != FIN_WAIT_2) && (pcb->state != CLOSING)) {
- return 1;
- }
+ if (pcb->state == LISTEN) {
+ vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, pcb);
+ } else {
+ vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, pcb);
}
-
- /* tcp_bound_pcbs and others don't reg */
- return 0;
}
#endif
@@ -414,12 +403,6 @@ static inline int need_vdev_reg(struct tcp_pcb *pcb_list, const struct tcp_pcb *
tcp_timer_needed(); \
} while(0)
#define TCP_RMV(pcbs, npcb) do { \
- if (need_vdev_reg(*pcbs, npcb)) { \
- if (npcb->state == LISTEN) \
- vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, npcb); \
- else \
- vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, npcb); \
- } \
struct tcp_pcb *tcp_tmp_pcb; \
LWIP_ASSERT("TCP_RMV: pcbs != NULL", *(pcbs) != NULL); \
LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", (npcb), *(pcbs))); \
@@ -512,12 +495,6 @@ static inline int need_vdev_reg(struct tcp_pcb *pcb_list, const struct tcp_pcb *
#define TCP_RMV(pcbs, npcb) \
do { \
- if (need_vdev_reg(*pcbs, npcb)) { \
- if (npcb->state == LISTEN) \
- vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, npcb); \
- else \
- vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, npcb);\
- } \
if(*(pcbs) == (npcb)) { \
(*(pcbs)) = (*pcbs)->next; \
if (*pcbs) \
--
2.23.0

View File

@ -0,0 +1,116 @@
From fdccb3a2c430c6270ff5272220cf471bf760fda7 Mon Sep 17 00:00:00 2001
From: wuchangsheng <wuchangsheng2@huawei.com>
Date: Sat, 21 Aug 2021 15:22:52 +0800
Subject: [PATCH] del tcp_conn
---
src/core/tcp.c | 78 ------------------------------------------
src/include/lwip/tcp.h | 3 --
2 files changed, 81 deletions(-)
diff --git a/src/core/tcp.c b/src/core/tcp.c
index 2cfbce2..0f3e830 100644
--- a/src/core/tcp.c
+++ b/src/core/tcp.c
@@ -2484,84 +2484,6 @@ tcp_tcp_get_tcp_addrinfo(struct tcp_pcb *pcb, int local, ip_addr_t *addr, u16_t
return ERR_VAL;
}
-uint32_t tcp_get_conn_num(void)
-{
- struct tcp_pcb *pcb = NULL;
- struct tcp_pcb_listen *pcbl = NULL;
- uint32_t conn_num = 0;
-
- for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
- conn_num++;
- }
-
- for (pcbl = tcp_listen_pcbs.listen_pcbs; pcbl != NULL; pcbl = pcbl->next) {
- conn_num++;
- }
-
- for (pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
- conn_num++;
- }
-
- return conn_num;
-}
-
-void tcp_get_conn(char *buf, int32_t len, uint32_t *conn_num)
-{
- int tmp_len = 0;
- char *tmp_buf = buf;
- struct tcp_pcb_dp tdp;
- struct tcp_pcb *pcb = NULL;
- struct tcp_pcb_listen *pcbl = NULL;
-
-#define COPY_TDP(b, l) \
- do { \
- if (l + sizeof(tdp) <= len) { \
- memcpy(b, &tdp, sizeof(tdp)); \
- b += sizeof(tdp); \
- l += sizeof(tdp); \
- *conn_num += 1; \
- } else \
- return; \
- } while(0);
-
- *conn_num = 0;
-
- for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
- tdp.state = ACTIVE_LIST;
- tdp.lip = pcb->local_ip.addr;
- tdp.rip = pcb->remote_ip.addr;
- tdp.l_port = pcb->local_port;
- tdp.r_port = pcb->remote_port;
- tdp.s_next = pcb->snd_queuelen;
- /* lwip not cache rcv buf. Set it to 0. */
- tdp.r_next = 0;
- tdp.tcp_sub_state = pcb->state;
- COPY_TDP(tmp_buf, tmp_len);
- }
-
- for (pcbl = tcp_listen_pcbs.listen_pcbs; pcbl != NULL; pcbl = pcbl->next) {
- tdp.state = LISTEN_LIST;
- tdp.lip = pcbl->local_ip.addr;
- tdp.rip = pcbl->remote_ip.addr;
- tdp.l_port = pcbl->local_port;
- tdp.tcp_sub_state = pcbl->state;
- COPY_TDP(tmp_buf, tmp_len);
- }
-
- for (pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
- tdp.state = TIME_WAIT_LIST;
- tdp.lip = pcb->local_ip.addr;
- tdp.rip = pcb->remote_ip.addr;
- tdp.l_port = pcb->local_port;
- tdp.r_port = pcb->remote_port;
- tdp.s_next = pcb->snd_queuelen;
- /* lwip not cache rcv buf. Set it to 0. */
- tdp.r_next = 0;
- tdp.tcp_sub_state = pcb->state;
- COPY_TDP(tmp_buf, tmp_len);
- }
-}
-
#if TCP_QUEUE_OOSEQ
/* Free all ooseq pbufs (and possibly reset SACK state) */
void
diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h
index 4f86b46..b36bf33 100644
--- a/src/include/lwip/tcp.h
+++ b/src/include/lwip/tcp.h
@@ -570,9 +570,6 @@ struct tcp_pcb_dp {
uint32_t tcp_sub_state;
};
-void tcp_get_conn(char *buf, int32_t len, uint32_t *conn_num);
-uint32_t tcp_get_conn_num(void);
-
/* for compatibility with older implementation */
#define tcp_new_ip6() tcp_new_ip_type(IPADDR_TYPE_V6)
--
2.23.0

View File

@ -0,0 +1,49 @@
From c5db70bef7f1ac6627b278fdf06be57bce0ef00b Mon Sep 17 00:00:00 2001
From: wuchangsheng <wuchangsheng2@huawei.com>
Date: Thu, 19 Aug 2021 14:53:14 +0800
Subject: [PATCH] fix event.data.ptr double free due to socket don't free in
lwip_close
---
src/api/sockets.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/api/sockets.c b/src/api/sockets.c
index 7ce9378..ac4cccb 100644
--- a/src/api/sockets.c
+++ b/src/api/sockets.c
@@ -963,18 +963,20 @@ lwip_close(int s)
struct lwip_sock *sock;
int is_tcp = 0;
err_t err;
+ int ret = 0;
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_close(%d)\n", s));
#if USE_LIBOS
- int ret;
if (posix_api->is_epfd(s)) {
return posix_api->epoll_close_fn(s);
}
+ /* No matter what the result of close, lwip_sock resources should release
+ * to prevent the potential double freee problem caused by reporting events after the close */
ret = posix_api->close_fn(s);
- if (ret < 0)
- return ret;
+ if ((ret < 0) && (errno == EINTR))
+ ret = posix_api->close_fn(s);
if (posix_api->is_chld == 0)
clean_host_fd(s);
@@ -1014,7 +1016,7 @@ lwip_close(int s)
free_socket(sock, is_tcp);
set_errno(0);
- return 0;
+ return ret;
}
int
--
2.23.0

View File

@ -0,0 +1,126 @@
From afd0d39d31196a74d6808120d1ca5664825d477c Mon Sep 17 00:00:00 2001
From: wuchangsheng <wuchangsheng2@huawei.com>
Date: Mon, 6 Sep 2021 22:52:41 +0800
Subject: [PATCH] aaa
---
src/api/sockets.c | 17 -----------------
src/include/eventpoll.h | 1 -
src/include/lwipopts.h | 17 -----------------
src/include/lwipsock.h | 5 -----
4 files changed, 40 deletions(-)
diff --git a/src/api/sockets.c b/src/api/sockets.c
index ac4cccb..8719568 100644
--- a/src/api/sockets.c
+++ b/src/api/sockets.c
@@ -755,10 +755,6 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
sock = posix_api->get_socket(s);
/*AF_UNIX case*/
if (!sock) {
- if (rearm_accept_fd(s) < 0) {
- LWIP_DEBUGF(SOCKETS_DEBUG,
- ("failed to rearm accept fd=%d errno=%d\n", s, errno));
- }
return posix_api->accept_fn(s, addr, addrlen);
}
@@ -769,11 +765,6 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
return -1;
}
- if (rearm_accept_fd(s) < 0) {
- LWIP_DEBUGF(SOCKETS_DEBUG,
- ("failed to rearm accept fd=%d errno=%d\n", s, errno));
- }
-
/* raise accept syscall in palce */
newsock = posix_api->accept_fn(s, addr, addrlen);
if (newsock >= 0) {
@@ -977,8 +968,6 @@ lwip_close(int s)
ret = posix_api->close_fn(s);
if ((ret < 0) && (errno == EINTR))
ret = posix_api->close_fn(s);
- if (posix_api->is_chld == 0)
- clean_host_fd(s);
sock = posix_api->get_socket(s);
/*AF_UNIX case*/
@@ -1481,9 +1470,6 @@ static inline enum KERNEL_LWIP_PATH select_path(int s)
sock = posix_api->get_socket(s);
/*AF_UNIX case*/
if (!sock) {
- if (rearm_host_fd(s) < 0) {
- LWIP_DEBUGF(SOCKETS_DEBUG, ("failed to rearm fd=%d errno=%d\n", s, errno));
- }
return PATH_KERNEL;
}
@@ -1494,9 +1480,6 @@ static inline enum KERNEL_LWIP_PATH select_path(int s)
/*for AF_INET, we can try erther linux or lwip*/
if (CONN_TYPE_IS_HOST(sock->conn)) {
- if (rearm_host_fd(s) < 0) {
- LWIP_DEBUGF(SOCKETS_DEBUG, ("failed to rearm read fd=%d errno=%d\n", s, errno));
- }
return PATH_KERNEL;
}
diff --git a/src/include/eventpoll.h b/src/include/eventpoll.h
index 01f8d64..f525bc2 100644
--- a/src/include/eventpoll.h
+++ b/src/include/eventpoll.h
@@ -57,7 +57,6 @@ struct event_array {
struct libos_epoll {
struct event_queue *libos_queue;
- struct event_array *host_queue;
int num_hostfds;
int hints;
int fd; /* self fd */
diff --git a/src/include/lwipopts.h b/src/include/lwipopts.h
index 8893a5f..e0364a2 100644
--- a/src/include/lwipopts.h
+++ b/src/include/lwipopts.h
@@ -177,23 +177,6 @@
#define ARP_TABLE_SIZE 512
-/*
- ---------------------------------------
- ------- Syscall thread options --------
- ---------------------------------------
-*/
-#define USE_SYSCALL_THREAD 1
-
-#define MAX_BLOCKING_ACCEPT_FD (100)
-
-#define MAX_BLOCKING_CONNECT_FD (100)
-
-#define MAX_BLOCKING_EPOLL_FD (100)
-
-#define MAX_SYSCALL_EVENTS (MAX_BLOCKING_ACCEPT_FD + MAX_BLOCKING_CONNECT_FD + MAX_BLOCKING_EPOLL_FD)
-
-#define MAX_HOST_FD (MAX_CLIENTS + RESERVED_CLIENTS)
-
#if USE_LIBOS
#define PER_THREAD __thread
#else
diff --git a/src/include/lwipsock.h b/src/include/lwipsock.h
index dbc67b9..e9ffbb1 100644
--- a/src/include/lwipsock.h
+++ b/src/include/lwipsock.h
@@ -146,10 +146,5 @@ void lwip_sock_init(void);
void lwip_exit(void);
extern int is_host_ipv4(uint32_t ipv4);
-extern int rearm_host_fd(int fd);
-extern int rearm_accept_fd(int fd);
-extern void unarm_host_fd(int fd);
-extern void clean_host_fd(int fd);
-extern int arm_host_fd(struct libos_epoll *ep, int op, int fd, struct epoll_event *event);
#endif /* __LWIPSOCK_H__ */
--
2.23.0

View File

@ -0,0 +1,62 @@
From 4970d00fecf52a472a28d55243f87142d3d08268 Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng12@huawei.com>
Date: Tue, 4 Jan 2022 17:23:03 +0800
Subject: [PATCH] fix some compile errors
---
src/include/arch/cc.h | 4 ++--
src/include/lwiplog.h | 2 +-
src/include/posix_api.h | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/include/arch/cc.h b/src/include/arch/cc.h
index 33c24b4..222b0c9 100644
--- a/src/include/arch/cc.h
+++ b/src/include/arch/cc.h
@@ -62,7 +62,7 @@ void alloc_memp_##name##_base(void) \
memp_pools[MEMP_##name] = &memp_ ## name; \
\
char mpname[MEMZONE_NAMESIZE] = {0}; \
- snprintf(mpname, MEMZONE_NAMESIZE, "%ld_%s", gettid(), #name); \
+ snprintf(mpname, MEMZONE_NAMESIZE, "%d_%s", gettid(), #name); \
memp_memory_##name##_base = \
sys_hugepage_malloc(mpname, LWIP_MEM_ALIGN_BUFFER(__size)); \
memp_pools[MEMP_##name]->base = memp_memory_##name##_base; \
@@ -73,7 +73,7 @@ PER_THREAD uint8_t *variable_name; \
void alloc_memory_##variable_name(void) \
{ \
char mpname[MEMZONE_NAMESIZE] = {0}; \
- snprintf(mpname, MEMZONE_NAMESIZE, "%ld_%s", gettid(), #variable_name); \
+ snprintf(mpname, MEMZONE_NAMESIZE, "%d_%s", gettid(), #variable_name); \
(variable_name) = \
sys_hugepage_malloc(mpname, LWIP_MEM_ALIGN_BUFFER(size)); \
}
diff --git a/src/include/lwiplog.h b/src/include/lwiplog.h
index 363e516..6fccac8 100644
--- a/src/include/lwiplog.h
+++ b/src/include/lwiplog.h
@@ -40,7 +40,7 @@
#include "lwipopts.h"
-#define gettid() syscall(__NR_gettid)
+extern int gettid(void);
#if USE_DPDK_LOG
diff --git a/src/include/posix_api.h b/src/include/posix_api.h
index 8aa8516..0dca8eb 100644
--- a/src/include/posix_api.h
+++ b/src/include/posix_api.h
@@ -79,7 +79,7 @@ typedef struct {
int is_chld;
} posix_api_t;
-posix_api_t *posix_api;
+extern posix_api_t *posix_api;
int posix_api_init(void);
void posix_api_free(void);
--
1.8.3.1

View File

@ -0,0 +1,36 @@
From bd0fdaf755544da1a276820a7cc3f664a2765194 Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng12@huawei.com>
Date: Tue, 18 Jan 2022 10:34:42 +0800
Subject: [PATCH] fix tcp port alloc issue
---
src/core/tcp.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/core/tcp.c b/src/core/tcp.c
index a9a91fd..b65ab33 100644
--- a/src/core/tcp.c
+++ b/src/core/tcp.c
@@ -1062,6 +1062,7 @@ tcp_new_port(void)
{
u8_t i;
u16_t n = 0;
+ u16_t tmp_port;
struct tcp_pcb *pcb;
pthread_mutex_lock(&g_tcp_port_mutex);
@@ -1082,9 +1083,10 @@ again:
}
}
}
+ tmp_port = tcp_port;
pthread_mutex_unlock(&g_tcp_port_mutex);
- return tcp_port;
+ return tmp_port;
}
/**
--
1.8.3.1

View File

@ -4,14 +4,28 @@
Summary: lwip is a small independent implementation of the TCP/IP protocol suite
Name: lwip
Version: 2.1.3
Release: 1
Release: 2
License: BSD
URL: http://savannah.nongnu.org/projects/lwip/
Source0: http://download.savannah.nongnu.org/releases/lwip/%{name}-%{version}.tar.gz
Patch0: 0001-add-makefile.patch
Patch9000: 0001-add-makefile.patch
Patch9001: 0002-adapt-lstack.patch
Patch9002: 0003-fix-the-occasional-coredump-when-the-lwip-exits.patch
Patch9003: 0004-fix-error-of-deleting-conn-table-in-connect.patch
Patch9004: 0005-syn-rcvd-state-reg-conn-into-conntable.patch
Patch9005: 0006-fix-coredump-in-etharp.patch
Patch9006: 0007-gazelle-fix-epoll_ctl-EPOLLET-mode-error.patch
Patch9007: 0008-gazelle-fix-lwip_accept-memcpy-sockaddr-large.patch
Patch9008: 0009-fix-stack-buffer-overflow-when-memcpy-addr.patch
Patch9009: 0010-fix-the-incomplete-release-of-the-conntable.patch
Patch9010: 0011-remove-gazelle-tcp-conn-func.patch
Patch9011: 0012-fix-incomplete-resource-release-in-lwip-close.patch
Patch9012: 0013-remove-gazelle-syscall-thread.patch
Patch9013: 0014-fix-some-compile-errors.patch
Patch9014: 0015-fix-tcp-port-alloc-issue.patch
BuildRequires: gcc-c++ dos2unix
BuildRequires: gcc-c++ dos2unix dpdk-devel
#Requires:
@ -24,7 +38,21 @@ lwip is a small independent implementation of the TCP/IP protocol suite.
%setup -n %{name}-%{version} -q
find %{_builddir}/%{name}-%{version} -type f -exec dos2unix -q {} \;
%patch0 -p1
%patch9000 -p1
%patch9001 -p1
%patch9002 -p1
%patch9003 -p1
%patch9004 -p1
%patch9005 -p1
%patch9006 -p1
%patch9007 -p1
%patch9008 -p1
%patch9009 -p1
%patch9010 -p1
%patch9011 -p1
%patch9012 -p1
%patch9013 -p1
%patch9014 -p1
%build
cd %{_builddir}/%{name}-%{version}/src
@ -40,10 +68,13 @@ cd %{_builddir}/%{name}-%{version}/src
%{_libdir}/liblwip.a
%changelog
* Fri Nov 26 2020 jiangheng<jiangheng12@huawei.com> - 2.1.3-1
* Fri Dec 31 2021 jiangheng<jiangheng12@huawei.com> - 2.1.3-2
- adapt to lstack
* Fri Nov 26 2021 jiangheng<jiangheng12@huawei.com> - 2.1.3-1
- update to 2.1.3
* Mon Sep 06 2020 jiangheng<jiangheng12@huawei.com> - 2.1.2-2
* Mon Sep 06 2021 jiangheng<jiangheng12@huawei.com> - 2.1.2-2
- backport some patches from community
* Mon Nov 30 2020 peanut_huang<huangliming5@huawei.com> - 2.1.2-1