diff --git a/0216-cleancode-refactor-lwipsock.h.patch b/0216-cleancode-refactor-lwipsock.h.patch new file mode 100644 index 0000000000000000000000000000000000000000..1726808c26bb0975a2924d0dbdef7738450ec3ec --- /dev/null +++ b/0216-cleancode-refactor-lwipsock.h.patch @@ -0,0 +1,280 @@ +From 2f7ca29c8b7a93079a5579062fc6751a6be6fd0c Mon Sep 17 00:00:00 2001 +From: Lemmy Huang +Date: Wed, 10 Jul 2024 11:08:07 +0800 +Subject: [PATCH] cleancode: refactor lwipsock.h + +Signed-off-by: Lemmy Huang +--- + src/lstack/api/lstack_rtc_api.c | 7 +--- + src/lstack/api/lstack_wrap.c | 11 ++++-- + src/lstack/core/lstack_init.c | 3 -- + src/lstack/core/lstack_lwip.c | 45 ++++++++----------------- + src/lstack/core/lstack_protocol_stack.c | 26 ++++---------- + src/lstack/include/lstack_lwip.h | 7 ++-- + 6 files changed, 33 insertions(+), 66 deletions(-) + +diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c +index e77edec..57ff89f 100644 +--- a/src/lstack/api/lstack_rtc_api.c ++++ b/src/lstack/api/lstack_rtc_api.c +@@ -68,12 +68,7 @@ int rtc_close(int s) + return lstack_epoll_close(s); + } + +- lwip_close(s); +- if (sock != NULL) { +- list_del_node_null(&sock->event_list); +- } +- +- return posix_api->close_fn(s); ++ return lwip_close(s); + } + + int rtc_shutdown(int fd, int how) +diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c +index cf0d302..16fc876 100644 +--- a/src/lstack/api/lstack_wrap.c ++++ b/src/lstack/api/lstack_wrap.c +@@ -175,6 +175,8 @@ static inline int32_t do_accept(int32_t s, struct sockaddr *addr, socklen_t *add + + int32_t fd = g_wrap_api->accept_fn(s, addr, addrlen); + if (fd >= 0) { ++ struct lwip_sock *sock = get_socket(fd); ++ SET_CONN_TYPE_LIBOS(sock->conn); + return fd; + } + +@@ -193,6 +195,8 @@ static int32_t do_accept4(int32_t s, struct sockaddr *addr, socklen_t *addrlen, + + int32_t fd = g_wrap_api->accept4_fn(s, addr, addrlen, flags); + if (fd >= 0) { ++ struct lwip_sock *sock = get_socket(fd); ++ SET_CONN_TYPE_LIBOS(sock->conn); + return fd; + } + +@@ -452,10 +456,11 @@ static inline int32_t do_socket(int32_t domain, int32_t type, int32_t protocol) + } + + ret = g_wrap_api->socket_fn(domain, type, protocol); +- /* if udp_enable = 1 in lstack.conf, udp protocol must be in user path currently */ +- if ((ret >= 0) && (type & SOCK_DGRAM)) { ++ if (ret >= 0) { + struct lwip_sock *sock = get_socket(ret); +- if (sock != NULL && sock->conn != NULL) { ++ SET_CONN_TYPE_LIBOS_OR_HOST(sock->conn); ++ /* if udp_enable = 1 in lstack.conf, udp protocol must be in user path currently */ ++ if (type & SOCK_DGRAM) { + SET_CONN_TYPE_LIBOS(sock->conn); + } + } +diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c +index a5a4a4e..1b3882e 100644 +--- a/src/lstack/core/lstack_init.c ++++ b/src/lstack/core/lstack_init.c +@@ -313,9 +313,6 @@ __attribute__((constructor)) void gazelle_network_init(void) + } + } + +- /* lwip initialization */ +- lwip_sock_init(); +- + #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) + if (get_global_cfg_params()->kni_switch) { + set_kni_ip_mac(); +diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c +index 75ef5f6..6fe4055 100644 +--- a/src/lstack/core/lstack_lwip.c ++++ b/src/lstack/core/lstack_lwip.c +@@ -144,12 +144,12 @@ static bool replenish_send_idlembuf(struct protocol_stack *stack, struct lwip_so + return false; + } + +-void do_lwip_init_sock(int32_t fd) ++int do_lwip_init_sock(int32_t fd) + { + struct protocol_stack *stack = get_protocol_stack(); +- struct lwip_sock *sock = get_socket(fd); ++ struct lwip_sock *sock = get_socket_by_fd(fd); + if (sock == NULL) { +- return; ++ return -1; + } + + reset_sock_data(sock); +@@ -157,7 +157,7 @@ void do_lwip_init_sock(int32_t fd) + sock->recv_ring = gazelle_ring_create_fast("sock_recv", SOCK_RECV_RING_SIZE, RING_F_SP_ENQ | RING_F_SC_DEQ); + if (sock->recv_ring == NULL) { + LSTACK_LOG(ERR, LSTACK, "sock_recv create failed. errno: %d.\n", rte_errno); +- return; ++ return -1; + } + + sock->send_ring = gazelle_ring_create_fast("sock_send", +@@ -166,7 +166,7 @@ void do_lwip_init_sock(int32_t fd) + if (sock->send_ring == NULL) { + gazelle_ring_free_fast(sock->recv_ring); + LSTACK_LOG(ERR, LSTACK, "sock_send create failed. errno: %d.\n", rte_errno); +- return; ++ return -1; + } + (void)replenish_send_idlembuf(stack, sock); + +@@ -174,6 +174,7 @@ void do_lwip_init_sock(int32_t fd) + + init_list_node_null(&sock->recv_list); + init_list_node_null(&sock->event_list); ++ return 0; + } + + void do_lwip_clean_sock(int fd) +@@ -1237,32 +1238,6 @@ void do_lwip_clone_sockopt(struct lwip_sock *dst_sock, struct lwip_sock *src_soc + } + } + +-int do_lwip_close(int fd) +-{ +- int ret = lwip_close(fd); +- do_lwip_clean_sock(fd); +- posix_api->close_fn(fd); +- return ret; +-} +- +-int do_lwip_socket(int domain, int type, int protocol) +-{ +- int32_t fd = lwip_socket(domain, type, 0); +- if (fd < 0) { +- return fd; +- } +- +- do_lwip_init_sock(fd); +- +- struct lwip_sock *sock = get_socket(fd); +- if (sock == NULL || sock->stack == NULL) { +- do_lwip_close(fd); +- return -1; +- } +- +- return fd; +-} +- + uint32_t do_lwip_get_conntable(struct gazelle_stat_lstack_conn_info *conn, + uint32_t max_num) + { +@@ -1583,3 +1558,11 @@ err_t find_same_node_ring(struct tcp_pcb *npcb) + } + return 0; + } ++ ++unsigned same_node_ring_count(struct lwip_sock *sock) ++{ ++ const unsigned long long cur_begin = __atomic_load_n(&sock->same_node_rx_ring->sndbegin, __ATOMIC_RELAXED); ++ const unsigned long long cur_end = __atomic_load_n(&sock->same_node_rx_ring->sndend, __ATOMIC_RELAXED); ++ ++ return cur_end - cur_begin; ++} +diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c +index d8bdd3c..c6075d5 100644 +--- a/src/lstack/core/lstack_protocol_stack.c ++++ b/src/lstack/core/lstack_protocol_stack.c +@@ -424,11 +424,6 @@ static struct protocol_stack *stack_thread_init(void *arg) + } + RTE_PER_LCORE(_lcore_id) = stack->cpu_id; + +- if (hugepage_init() != 0) { +- LSTACK_LOG(ERR, LSTACK, "hugepage init failed\n"); +- goto END; +- } +- + tcpip_init(NULL, NULL); + + if (use_ltran()) { +@@ -714,12 +709,9 @@ void stack_arp(struct rpc_msg *msg) + + void stack_socket(struct rpc_msg *msg) + { +- msg->result = do_lwip_socket(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i); ++ msg->result = lwip_socket(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i); + if (msg->result < 0) { +- msg->result = do_lwip_socket(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i); +- if (msg->result < 0) { +- LSTACK_LOG(ERR, LSTACK, "tid %ld, %ld socket failed\n", get_stack_tid(), msg->result); +- } ++ LSTACK_LOG(ERR, LSTACK, "tid %ld, %ld socket failed\n", get_stack_tid(), msg->result); + } + } + +@@ -735,7 +727,7 @@ void stack_close(struct rpc_msg *msg) + return; + } + +- msg->result = do_lwip_close(fd); ++ msg->result = lwip_close(fd); + if (msg->result != 0) { + LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d failed %ld\n", get_stack_tid(), msg->args[MSG_ARG_0].i, msg->result); + } +@@ -803,7 +795,7 @@ void stack_accept(struct rpc_msg *msg) + + struct lwip_sock *sock = get_socket(accept_fd); + if (sock == NULL || sock->stack == NULL) { +- do_lwip_close(accept_fd); ++ lwip_close(accept_fd); + LSTACK_LOG(ERR, LSTACK, "fd %d ret %d\n", fd, accept_fd); + return; + } +@@ -1046,12 +1038,8 @@ void stack_create_shadow_fd(struct rpc_msg *msg) + } + + int domain = addr->sa_family; +- if (NETCONN_IS_UDP(sock)) { +- clone_fd = do_lwip_socket(domain, SOCK_DGRAM, 0); +- } else { +- clone_fd = do_lwip_socket(domain, SOCK_STREAM, 0); +- } +- ++ int type = NETCONN_IS_UDP(sock) ? SOCK_DGRAM : SOCK_STREAM; ++ clone_fd = lwip_socket(domain, type, 0); + if (clone_fd < 0) { + LSTACK_LOG(ERR, LSTACK, "clone socket failed clone_fd=%d errno=%d\n", clone_fd, errno); + msg->result = clone_fd; +@@ -1370,7 +1358,7 @@ static void stack_all_fds_close(void) + for (int i = 3; i < GAZELLE_MAX_CLIENTS + GAZELLE_RESERVED_CLIENTS; i++) { + struct lwip_sock *sock = get_socket(i); + if (sock && sock->stack == get_protocol_stack()) { +- do_lwip_close(i); ++ lwip_close(i); + } + } + } +diff --git a/src/lstack/include/lstack_lwip.h b/src/lstack/include/lstack_lwip.h +index 0b952ec..b972f11 100644 +--- a/src/lstack/include/lstack_lwip.h ++++ b/src/lstack/include/lstack_lwip.h +@@ -16,21 +16,20 @@ + + #include "common/gazelle_dfx_msg.h" + ++struct lwip_sock; ++unsigned same_node_ring_count(struct lwip_sock *sock); ++ + #define NETCONN_IS_ACCEPTIN(sock) (((sock)->conn->acceptmbox != NULL) && !sys_mbox_empty((sock)->conn->acceptmbox)) + #define NETCONN_IS_DATAIN(sock) ((gazelle_ring_readable_count((sock)->recv_ring) || (sock)->recv_lastdata) || (sock->same_node_rx_ring != NULL && same_node_ring_count(sock))) + #define NETCONN_IS_DATAOUT(sock) (gazelle_ring_readover_count((sock)->send_ring) || (sock)->send_pre_del) + #define NETCONN_IS_OUTIDLE(sock) gazelle_ring_readable_count((sock)->send_ring) + #define NETCONN_IS_UDP(sock) (NETCONNTYPE_GROUP(netconn_type((sock)->conn)) == NETCONN_UDP) + +-struct lwip_sock; + struct rte_mempool; + struct rpc_msg; + struct rte_mbuf; + struct protocol_stack; + +-int do_lwip_socket(int domain, int type, int protocol); +-int do_lwip_close(int32_t fd); +-void do_lwip_init_sock(int32_t fd); + void do_lwip_clone_sockopt(struct lwip_sock *dst_sock, struct lwip_sock *src_sock); + + struct pbuf *do_lwip_tcp_get_from_sendring(struct lwip_sock *sock, uint16_t remain_size); +-- +2.33.0 + diff --git a/0217-cleancode-refactor-posix-type-and-get_socket.patch b/0217-cleancode-refactor-posix-type-and-get_socket.patch new file mode 100644 index 0000000000000000000000000000000000000000..cbf98e2019607d37c577cecc289e523dd6e95ff4 --- /dev/null +++ b/0217-cleancode-refactor-posix-type-and-get_socket.patch @@ -0,0 +1,1047 @@ +From dcfb07a30a3e4f8eece68d1ad8c17cb8c2a58945 Mon Sep 17 00:00:00 2001 +From: Lemmy Huang +Date: Wed, 10 Jul 2024 16:37:01 +0800 +Subject: [PATCH] cleancode: refactor posix type and get_socket + + Changed: + get_socket_by_fd -> lwip_get_socket + get_socket + + SET_CONN_TYPE_LIBOS_OR_HOST -> POSIX_SET_TYPE + SET_CONN_TYPE_LIBOS + SET_CONN_TYPE_HOST + + CONN_TYPE_IS_LIBOS -> POSIX_IS_TYPE + CONN_TYPE_IS_HOST + + CONN_TYPE_HAS_LIBOS_AND_HOST -> POSIX_HAS_TYPE + CONN_TYPE_HAS_LIBOS + CONN_TYPE_HAS_HOST + +Signed-off-by: Lemmy Huang +--- + src/lstack/api/lstack_epoll.c | 34 ++++---- + src/lstack/api/lstack_rtc_api.c | 6 +- + src/lstack/api/lstack_rtw_api.c | 14 ++-- + src/lstack/api/lstack_wrap.c | 104 ++++++++++++------------ + src/lstack/core/lstack_lwip.c | 22 ++--- + src/lstack/core/lstack_preload.c | 44 +++++----- + src/lstack/core/lstack_protocol_stack.c | 40 ++++----- + src/lstack/core/lstack_stack_stat.c | 2 +- + src/lstack/core/lstack_thread_rpc.c | 4 +- + src/lstack/include/lstack_preload.h | 10 +-- + 10 files changed, 137 insertions(+), 143 deletions(-) + +diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c +index 7d00de7..8146b4f 100644 +--- a/src/lstack/api/lstack_epoll.c ++++ b/src/lstack/api/lstack_epoll.c +@@ -164,7 +164,7 @@ static uint32_t update_events(struct lwip_sock *sock) + + if ((sock->epoll_events & EPOLLOUT) && NETCONN_IS_OUTIDLE(sock)) { + /* lwip_netconn_do_connected set LIBOS FLAGS when connected */ +- if (sock->conn && CONN_TYPE_IS_LIBOS(sock->conn)) { ++ if (sock->conn && POSIX_IS_TYPE(sock, POSIX_LWIP)) { + event |= EPOLLOUT; + } + } +@@ -190,7 +190,7 @@ static void rtc_raise_pending_events(struct wakeup_poll *wakeup, struct lwip_soc + + if (sock->sendevent) { + /* lwip_netconn_do_connected set LIBOS FLAGS when connected */ +- if (sock->conn && CONN_TYPE_IS_LIBOS(sock->conn)) { ++ if (sock->conn && POSIX_IS_TYPE(sock, POSIX_LWIP)) { + event |= EPOLLOUT; + } + } +@@ -219,7 +219,7 @@ static void raise_pending_events(struct wakeup_poll *wakeup, struct lwip_sock *s + pthread_spin_lock(&wakeup->event_list_lock); + if (NETCONN_IS_OUTIDLE(sock)) { + /* lwip_netconn_do_connected set LIBOS FLAGS when connected */ +- if (sock->conn && CONN_TYPE_IS_LIBOS(sock->conn)) { ++ if (sock->conn && POSIX_IS_TYPE(sock, POSIX_LWIP)) { + event |= EPOLLOUT; + } + } +@@ -240,7 +240,7 @@ int32_t lstack_do_epoll_create(int32_t fd) + return fd; + } + +- struct lwip_sock *sock = get_socket_by_fd(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + if (sock == NULL) { + LSTACK_LOG(ERR, LSTACK, "fd=%d sock is NULL errno=%d\n", fd, errno); + posix_api->close_fn(fd); +@@ -307,7 +307,7 @@ int32_t lstack_epoll_create(int32_t flags) + + int32_t lstack_epoll_close(int32_t fd) + { +- struct lwip_sock *sock = get_socket_by_fd(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + if (sock == NULL) { + LSTACK_LOG(ERR, LSTACK, "fd=%d sock is NULL errno=%d\n", fd, errno); + GAZELLE_RETURN(EINVAL); +@@ -391,14 +391,14 @@ int32_t lstack_rtc_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_ + GAZELLE_RETURN(EINVAL); + } + +- struct lwip_sock *epoll_sock = get_socket_by_fd(epfd); ++ struct lwip_sock *epoll_sock = lwip_get_socket(epfd); + if (epoll_sock == NULL || epoll_sock->wakeup == NULL) { + return posix_api->epoll_ctl_fn(epfd, op, fd, event); + } + + struct wakeup_poll *wakeup = epoll_sock->wakeup; +- struct lwip_sock *sock = get_socket(fd); +- if (sock == NULL) { ++ struct lwip_sock *sock = lwip_get_socket(fd); ++ if (sock == NULL || sock->conn == NULL) { + return posix_api->epoll_ctl_fn(epfd, op, fd, event); + } + +@@ -431,18 +431,18 @@ int32_t lstack_rtw_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_ + GAZELLE_RETURN(EINVAL); + } + +- struct lwip_sock *epoll_sock = get_socket_by_fd(epfd); ++ struct lwip_sock *epoll_sock = lwip_get_socket(epfd); + if (epoll_sock == NULL || epoll_sock->wakeup == NULL) { + return posix_api->epoll_ctl_fn(epfd, op, fd, event); + } + + struct wakeup_poll *wakeup = epoll_sock->wakeup; +- struct lwip_sock *sock = get_socket(fd); +- if (sock == NULL) { ++ struct lwip_sock *sock = lwip_get_socket(fd); ++ if (sock == NULL || sock->conn == NULL) { + return posix_api->epoll_ctl_fn(epfd, op, fd, event); + } + +- if (CONN_TYPE_HAS_HOST(sock->conn)) { ++ if (POSIX_HAS_TYPE(sock, POSIX_KERNEL)) { + int32_t ret = posix_api->epoll_ctl_fn(epfd, op, fd, event); + if (ret < 0) { + LSTACK_LOG(ERR, LSTACK, "fd=%d epfd=%d op=%d errno=%d\n", fd, epfd, op, errno); +@@ -535,7 +535,7 @@ static int32_t poll_lwip_event(struct pollfd *fds, nfds_t nfds) + for (uint32_t i = 0; i < nfds; i++) { + /* sock->listen_next pointerto next stack listen */ + int32_t fd = fds[i].fd; +- struct lwip_sock *sock = get_socket_by_fd(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + while (sock && sock->conn) { + uint32_t events = update_events(sock); + if (events) { +@@ -624,7 +624,7 @@ int32_t lstack_block_wait(struct wakeup_poll *wakeup, int32_t timeout) + + int32_t lstack_rtc_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxevents, int32_t timeout) + { +- struct lwip_sock *sock = get_socket_by_fd(epfd); ++ struct lwip_sock *sock = lwip_get_socket(epfd); + + if (sock == NULL || sock->wakeup == NULL) { + return posix_api->epoll_wait_fn(epfd, events, maxevents, timeout); +@@ -673,7 +673,7 @@ int32_t lstack_rtc_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t + + int32_t lstack_rtw_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxevents, int32_t timeout) + { +- struct lwip_sock *sock = get_socket_by_fd(epfd); ++ struct lwip_sock *sock = lwip_get_socket(epfd); + if (sock == NULL || sock->wakeup == NULL) { + return posix_api->epoll_wait_fn(epfd, events, maxevents, timeout); + } +@@ -829,7 +829,7 @@ static void poll_init(struct wakeup_poll *wakeup, struct pollfd *fds, nfds_t nfd + for (uint32_t i = 0; i < nfds; i++) { + int32_t fd = fds[i].fd; + fds[i].revents = 0; +- struct lwip_sock *sock = get_socket_by_fd(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + + if (fd == wakeup->last_fds[i].fd && fds[i].events == wakeup->last_fds[i].events) { + /* fd close then socket may get same fd. */ +@@ -838,7 +838,7 @@ static void poll_init(struct wakeup_poll *wakeup, struct pollfd *fds, nfds_t nfd + } + } + +- if (sock == NULL || sock->conn == NULL || CONN_TYPE_HAS_HOST(sock->conn)) { ++ if (sock == NULL || sock->conn == NULL || POSIX_HAS_TYPE(sock, POSIX_KERNEL)) { + update_kernel_poll(wakeup, i, fds + i); + } + +diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c +index 57ff89f..97623b3 100644 +--- a/src/lstack/api/lstack_rtc_api.c ++++ b/src/lstack/api/lstack_rtc_api.c +@@ -50,8 +50,8 @@ int rtc_socket(int domain, int type, int protocol) + + /* need call stack thread init function */ + ret = lwip_socket(domain, type, protocol); +- struct lwip_sock *sock = get_socket(ret); +- if (sock != NULL) { ++ if (ret >= 0) { ++ struct lwip_sock *sock = lwip_get_socket(ret); + sock->stack = get_protocol_stack(); + sock->epoll_events = 0; + sock->events = 0; +@@ -63,7 +63,7 @@ int rtc_socket(int domain, int type, int protocol) + + int rtc_close(int s) + { +- struct lwip_sock *sock = get_socket(s); ++ struct lwip_sock *sock = lwip_get_socket(s); + if (sock != NULL && sock->wakeup != NULL && sock->wakeup->epollfd == s) { + return lstack_epoll_close(s); + } +diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c +index 0f23ffd..f59b0cd 100644 +--- a/src/lstack/api/lstack_rtw_api.c ++++ b/src/lstack/api/lstack_rtw_api.c +@@ -47,7 +47,7 @@ int rtw_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) + + int rtw_bind(int s, const struct sockaddr *name, socklen_t namelen) + { +- struct lwip_sock *sock = get_socket_by_fd(s); ++ struct lwip_sock *sock = lwip_get_socket(s); + + if (NETCONN_IS_UDP(sock) && get_global_cfg_params()->listen_shadow) { + return stack_broadcast_bind(s, name, namelen); +@@ -137,7 +137,7 @@ ssize_t rtw_write(int s, const void *mem, size_t size) + + ssize_t rtw_writev(int s, const struct iovec *iov, int iovcnt) + { +- struct lwip_sock *sock = get_socket_by_fd(s); ++ struct lwip_sock *sock = lwip_get_socket(s); + struct msghdr msg; + + msg.msg_name = NULL; +@@ -167,14 +167,14 @@ ssize_t rtw_recvmsg(int s, const struct msghdr *message, int flags) + + ssize_t rtw_sendmsg(int s, const struct msghdr *message, int flags) + { +- struct lwip_sock *sock = get_socket_by_fd(s); ++ struct lwip_sock *sock = lwip_get_socket(s); + return do_lwip_sendmsg_to_stack(sock, s, message, flags); + } + + static ssize_t rtw_udp_recvfrom(int sockfd, void *buf, size_t len, int flags, + struct sockaddr *addr, socklen_t *addrlen) + { +- struct lwip_sock *sock = get_socket_by_fd(sockfd); ++ struct lwip_sock *sock = lwip_get_socket(sockfd); + int ret; + + while (1) { +@@ -210,7 +210,7 @@ static inline ssize_t rtw_tcp_recvfrom(int sockfd, void *buf, size_t len, int fl + ssize_t rtw_recvfrom(int sockfd, void *buf, size_t len, int flags, + struct sockaddr *addr, socklen_t *addrlen) + { +- struct lwip_sock *sock = get_socket_by_fd(sockfd); ++ struct lwip_sock *sock = lwip_get_socket(sockfd); + if (NETCONN_IS_UDP(sock)) { + return rtw_udp_recvfrom(sockfd, buf, len, flags, addr, addrlen); + } else { +@@ -241,7 +241,7 @@ int rtw_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, s + + int rtw_close(int s) + { +- struct lwip_sock *sock = get_socket(s); ++ struct lwip_sock *sock = lwip_get_socket(s); + if (sock && sock->wakeup && sock->wakeup->epollfd == s) { + return lstack_epoll_close(s); + } +@@ -250,7 +250,7 @@ int rtw_close(int s) + + int rtw_shutdown(int fd, int how) + { +- struct lwip_sock *sock = get_socket_by_fd(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + if (sock && sock->wakeup && sock->wakeup->epollfd == fd) { + GAZELLE_RETURN(ENOTSOCK); + } +diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c +index 16fc876..d3e1027 100644 +--- a/src/lstack/api/lstack_wrap.c ++++ b/src/lstack/api/lstack_wrap.c +@@ -125,7 +125,7 @@ void wrap_api_set_dummy(void) + + static inline int32_t do_epoll_create1(int32_t flags) + { +- if (select_posix_path() == PATH_KERNEL) { ++ if (select_posix_path() == POSIX_KERNEL) { + return posix_api->epoll_create1_fn(flags); + } + +@@ -134,7 +134,7 @@ static inline int32_t do_epoll_create1(int32_t flags) + + static inline int32_t do_epoll_create(int32_t size) + { +- if (select_posix_path() == PATH_KERNEL) { ++ if (select_posix_path() == POSIX_KERNEL) { + return posix_api->epoll_create_fn(size); + } + +@@ -143,7 +143,7 @@ static inline int32_t do_epoll_create(int32_t size) + + static inline int32_t do_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_event* event) + { +- if (select_posix_path() == PATH_KERNEL) { ++ if (select_posix_path() == POSIX_KERNEL) { + return posix_api->epoll_ctl_fn(epfd, op, fd, event); + } + +@@ -152,7 +152,7 @@ static inline int32_t do_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct + + static inline int32_t do_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxevents, int32_t timeout) + { +- if (select_posix_path() == PATH_KERNEL) { ++ if (select_posix_path() == POSIX_KERNEL) { + return posix_api->epoll_wait_fn(epfd, events, maxevents, timeout); + } + +@@ -169,14 +169,14 @@ static inline int32_t do_epoll_wait(int32_t epfd, struct epoll_event* events, in + + static inline int32_t do_accept(int32_t s, struct sockaddr *addr, socklen_t *addrlen) + { +- if (select_fd_posix_path(s, NULL) == PATH_KERNEL) { ++ if (select_fd_posix_path(s, NULL) == POSIX_KERNEL) { + return posix_api->accept_fn(s, addr, addrlen); + } + + int32_t fd = g_wrap_api->accept_fn(s, addr, addrlen); + if (fd >= 0) { +- struct lwip_sock *sock = get_socket(fd); +- SET_CONN_TYPE_LIBOS(sock->conn); ++ struct lwip_sock *sock = lwip_get_socket(fd); ++ POSIX_SET_TYPE(sock, POSIX_LWIP); + return fd; + } + +@@ -189,14 +189,14 @@ static int32_t do_accept4(int32_t s, struct sockaddr *addr, socklen_t *addrlen, + GAZELLE_RETURN(EINVAL); + } + +- if (select_fd_posix_path(s, NULL) == PATH_KERNEL) { ++ if (select_fd_posix_path(s, NULL) == POSIX_KERNEL) { + return posix_api->accept4_fn(s, addr, addrlen, flags); + } + + int32_t fd = g_wrap_api->accept4_fn(s, addr, addrlen, flags); + if (fd >= 0) { +- struct lwip_sock *sock = get_socket(fd); +- SET_CONN_TYPE_LIBOS(sock->conn); ++ struct lwip_sock *sock = lwip_get_socket(fd); ++ POSIX_SET_TYPE(sock, POSIX_LWIP); + return fd; + } + +@@ -210,13 +210,13 @@ static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen + } + + struct lwip_sock *sock = NULL; +- if (select_fd_posix_path(s, &sock) == PATH_KERNEL) { ++ if (select_fd_posix_path(s, &sock) == POSIX_KERNEL) { + return posix_api->bind_fn(s, name, namelen); + } + + /* select user path when udp enable and ip addr is multicast */ + if (IN_MULTICAST(ntohl(((struct sockaddr_in *)name)->sin_addr.s_addr))) { +- SET_CONN_TYPE_LIBOS(sock->conn); ++ POSIX_SET_TYPE(sock, POSIX_LWIP); + return g_wrap_api->bind_fn(s, name, namelen); + } + +@@ -233,7 +233,7 @@ static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen + if (match_host_addr(&sock_addr)) { + /* maybe kni addr */ + if (posix_api->bind_fn(s, name, namelen) != 0) { +- SET_CONN_TYPE_LIBOS(sock->conn); ++ POSIX_SET_TYPE(sock, POSIX_LWIP); + } else { + /* reuse the port allocated by kernel when port == 0 */ + if (((struct sockaddr_in *)name)->sin_port == 0) { +@@ -248,7 +248,7 @@ static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen + } + return g_wrap_api->bind_fn(s, name, namelen); + } else { +- SET_CONN_TYPE_HOST(sock->conn); ++ POSIX_SET_TYPE(sock, POSIX_KERNEL); + return posix_api->bind_fn(s, name, namelen); + } + } +@@ -303,11 +303,11 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name + } + + struct lwip_sock *sock = NULL; +- if (select_fd_posix_path(s, &sock) == PATH_KERNEL) { ++ if (select_fd_posix_path(s, &sock) == POSIX_KERNEL) { + return posix_api->connect_fn(s, name, namelen); + } + +- sock = get_socket(s); ++ sock = lwip_get_socket(s); + if (sock == NULL) { + return posix_api->connect_fn(s, name, namelen); + } +@@ -323,10 +323,10 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name + "listen_rx_ring_%d", remote_port); + if (is_local && rte_ring_lookup(listen_ring_name) == NULL) { + ret = posix_api->connect_fn(s, name, namelen); +- SET_CONN_TYPE_HOST(sock->conn); ++ POSIX_SET_TYPE(sock, POSIX_KERNEL); + } else { + ret = g_wrap_api->connect_fn(s, name, namelen); +- SET_CONN_TYPE_LIBOS(sock->conn); ++ POSIX_SET_TYPE(sock, POSIX_LWIP); + } + + return ret; +@@ -334,7 +334,7 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name + + static inline int32_t do_listen(int32_t s, int32_t backlog) + { +- if (select_fd_posix_path(s, NULL) == PATH_KERNEL) { ++ if (select_fd_posix_path(s, NULL) == POSIX_KERNEL) { + return posix_api->listen_fn(s, backlog); + } + +@@ -352,7 +352,7 @@ static inline int32_t do_getpeername(int32_t s, struct sockaddr *name, socklen_t + GAZELLE_RETURN(EINVAL); + } + +- if (select_fd_posix_path(s, NULL) == PATH_LWIP) { ++ if (select_fd_posix_path(s, NULL) == POSIX_LWIP) { + return g_wrap_api->getpeername_fn(s, name, namelen); + } + +@@ -365,7 +365,7 @@ static inline int32_t do_getsockname(int32_t s, struct sockaddr *name, socklen_t + GAZELLE_RETURN(EINVAL); + } + +- if (select_fd_posix_path(s, NULL) == PATH_LWIP) { ++ if (select_fd_posix_path(s, NULL) == POSIX_LWIP) { + return g_wrap_api->getsockname_fn(s, name, namelen); + } + +@@ -422,7 +422,7 @@ static bool unsupport_optname(int32_t level, int32_t optname) + + static inline int32_t do_getsockopt(int32_t s, int32_t level, int32_t optname, void *optval, socklen_t *optlen) + { +- if (select_fd_posix_path(s, NULL) == PATH_LWIP && !unsupport_optname(level, optname)) { ++ if (select_fd_posix_path(s, NULL) == POSIX_LWIP && !unsupport_optname(level, optname)) { + return g_wrap_api->getsockopt_fn(s, level, optname, optval, optlen); + } + +@@ -431,7 +431,7 @@ static inline int32_t do_getsockopt(int32_t s, int32_t level, int32_t optname, v + + static inline int32_t do_setsockopt(int32_t s, int32_t level, int32_t optname, const void *optval, socklen_t optlen) + { +- if (select_fd_posix_path(s, NULL) == PATH_KERNEL || unsupport_optname(level, optname)) { ++ if (select_fd_posix_path(s, NULL) == POSIX_KERNEL || unsupport_optname(level, optname)) { + return posix_api->setsockopt_fn(s, level, optname, optval, optlen); + } + +@@ -445,7 +445,7 @@ static inline int32_t do_socket(int32_t domain, int32_t type, int32_t protocol) + { + int32_t ret; + /* process not init completed or not hajacking thread */ +- if (select_posix_path() == PATH_KERNEL) { ++ if (select_posix_path() == POSIX_KERNEL) { + return posix_api->socket_fn(domain, type, protocol); + } + +@@ -457,11 +457,11 @@ static inline int32_t do_socket(int32_t domain, int32_t type, int32_t protocol) + + ret = g_wrap_api->socket_fn(domain, type, protocol); + if (ret >= 0) { +- struct lwip_sock *sock = get_socket(ret); +- SET_CONN_TYPE_LIBOS_OR_HOST(sock->conn); ++ struct lwip_sock *sock = lwip_get_socket(ret); ++ POSIX_SET_TYPE(sock, POSIX_LWIP | POSIX_KERNEL); + /* if udp_enable = 1 in lstack.conf, udp protocol must be in user path currently */ + if (type & SOCK_DGRAM) { +- SET_CONN_TYPE_LIBOS(sock->conn); ++ POSIX_SET_TYPE(sock, POSIX_LWIP); + } + } + +@@ -478,8 +478,8 @@ static inline ssize_t do_recv(int32_t sockfd, void *buf, size_t len, int32_t fla + return 0; + } + +- if (select_posix_path() == PATH_KERNEL || // maybe fd is created by open before posix_api_init called +- select_fd_posix_path(sockfd, NULL) == PATH_KERNEL) { ++ if (select_posix_path() == POSIX_KERNEL || // maybe fd is created by open before posix_api_init called ++ select_fd_posix_path(sockfd, NULL) == POSIX_KERNEL) { + return posix_api->recv_fn(sockfd, buf, len, flags); + } + +@@ -496,8 +496,8 @@ static inline ssize_t do_read(int32_t s, void *mem, size_t len) + return 0; + } + +- if (select_posix_path() == PATH_KERNEL || +- select_fd_posix_path(s, NULL) == PATH_KERNEL) { ++ if (select_posix_path() == POSIX_KERNEL || ++ select_fd_posix_path(s, NULL) == POSIX_KERNEL) { + return posix_api->read_fn(s, mem, len); + } + +@@ -506,8 +506,8 @@ static inline ssize_t do_read(int32_t s, void *mem, size_t len) + + static inline ssize_t do_readv(int32_t s, const struct iovec *iov, int iovcnt) + { +- if (select_posix_path() == PATH_KERNEL || +- select_fd_posix_path(s, NULL) == PATH_KERNEL) { ++ if (select_posix_path() == POSIX_KERNEL || ++ select_fd_posix_path(s, NULL) == POSIX_KERNEL) { + return posix_api->readv_fn(s, iov, iovcnt); + } + +@@ -516,8 +516,8 @@ static inline ssize_t do_readv(int32_t s, const struct iovec *iov, int iovcnt) + + static inline ssize_t do_send(int32_t sockfd, const void *buf, size_t len, int32_t flags) + { +- if (select_posix_path() == PATH_KERNEL || +- select_fd_posix_path(sockfd, NULL) == PATH_KERNEL) { ++ if (select_posix_path() == POSIX_KERNEL || ++ select_fd_posix_path(sockfd, NULL) == POSIX_KERNEL) { + return posix_api->send_fn(sockfd, buf, len, flags); + } + +@@ -526,8 +526,8 @@ static inline ssize_t do_send(int32_t sockfd, const void *buf, size_t len, int32 + + static inline ssize_t do_write(int32_t s, const void *mem, size_t size) + { +- if (select_posix_path() == PATH_KERNEL || +- select_fd_posix_path(s, NULL) == PATH_KERNEL) { ++ if (select_posix_path() == POSIX_KERNEL || ++ select_fd_posix_path(s, NULL) == POSIX_KERNEL) { + return posix_api->write_fn(s, mem, size); + } + +@@ -537,8 +537,8 @@ static inline ssize_t do_write(int32_t s, const void *mem, size_t size) + static inline ssize_t do_writev(int32_t s, const struct iovec *iov, int iovcnt) + { + struct lwip_sock *sock; +- if (select_posix_path() == PATH_KERNEL || +- select_fd_posix_path(s, &sock) == PATH_KERNEL) { ++ if (select_posix_path() == POSIX_KERNEL || ++ select_fd_posix_path(s, &sock) == POSIX_KERNEL) { + return posix_api->writev_fn(s, iov, iovcnt); + } + +@@ -551,8 +551,8 @@ static inline ssize_t do_recvmsg(int32_t s, struct msghdr *message, int32_t flag + GAZELLE_RETURN(EINVAL); + } + +- if (select_posix_path() == PATH_KERNEL || +- select_fd_posix_path(s, NULL) == PATH_KERNEL) { ++ if (select_posix_path() == POSIX_KERNEL || ++ select_fd_posix_path(s, NULL) == POSIX_KERNEL) { + return posix_api->recv_msg(s, message, flags); + } + +@@ -566,8 +566,8 @@ static inline ssize_t do_sendmsg(int32_t s, const struct msghdr *message, int32_ + } + + struct lwip_sock *sock; +- if (select_posix_path() == PATH_KERNEL || +- select_fd_posix_path(s, &sock) == PATH_KERNEL) { ++ if (select_posix_path() == POSIX_KERNEL || ++ select_fd_posix_path(s, &sock) == POSIX_KERNEL) { + return posix_api->send_msg(s, message, flags); + } + +@@ -586,7 +586,7 @@ static inline ssize_t do_recvfrom(int32_t sockfd, void *buf, size_t len, int32_t + } + + struct lwip_sock *sock = NULL; +- if (select_fd_posix_path(sockfd, &sock) == PATH_LWIP) { ++ if (select_fd_posix_path(sockfd, &sock) == POSIX_LWIP) { + return g_wrap_api->recv_from(sockfd, buf, len, flags, addr, addrlen); + } + +@@ -597,7 +597,7 @@ static inline ssize_t do_sendto(int32_t sockfd, const void *buf, size_t len, int + const struct sockaddr *addr, socklen_t addrlen) + { + struct lwip_sock *sock = NULL; +- if (select_fd_posix_path(sockfd, &sock) != PATH_LWIP) { ++ if (select_fd_posix_path(sockfd, &sock) != POSIX_LWIP) { + return posix_api->send_to(sockfd, buf, len, flags, addr, addrlen); + } + +@@ -607,8 +607,8 @@ static inline ssize_t do_sendto(int32_t sockfd, const void *buf, size_t len, int + static inline int32_t do_close(int32_t s) + { + struct lwip_sock *sock = NULL; +- if (select_posix_path() == PATH_KERNEL || +- select_fd_posix_path(s, &sock) == PATH_KERNEL) { ++ if (select_posix_path() == POSIX_KERNEL || ++ select_fd_posix_path(s, &sock) == POSIX_KERNEL) { + /* we called lwip_socket, even if kernel fd */ + if (posix_api != NULL && !posix_api->ues_posix && + /* contain posix_api->close_fn if success */ +@@ -624,7 +624,7 @@ static inline int32_t do_close(int32_t s) + static int32_t do_shutdown(int fd, int how) + { + struct lwip_sock *sock = NULL; +- if (select_posix_path() == PATH_KERNEL || select_fd_posix_path(fd, &sock) == PATH_KERNEL) { ++ if (select_posix_path() == POSIX_KERNEL || select_fd_posix_path(fd, &sock) == POSIX_KERNEL) { + if (posix_api != NULL && !posix_api->ues_posix && g_wrap_api->shutdown_fn(fd, how) == 0) { + return 0; + } else { +@@ -637,7 +637,7 @@ static int32_t do_shutdown(int fd, int how) + + static int32_t do_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout) + { +- if ((select_posix_path() == PATH_KERNEL) || fds == NULL || nfds == 0) { ++ if ((select_posix_path() == POSIX_KERNEL) || fds == NULL || nfds == 0) { + return posix_api->poll_fn(fds, nfds, timeout); + } + +@@ -676,7 +676,7 @@ static int32_t do_sigaction(int32_t signum, const struct sigaction *act, struct + + static int32_t do_select(int32_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) + { +- if ((select_posix_path() == PATH_KERNEL) || !(readfds || writefds || exceptfds) || nfds == 0) { ++ if ((select_posix_path() == POSIX_KERNEL) || !(readfds || writefds || exceptfds) || nfds == 0) { + return posix_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); + } + +@@ -691,8 +691,8 @@ static int32_t do_select(int32_t nfds, fd_set *readfds, fd_set *writefds, fd_set + val = va_arg(ap, typeof(val)); \ + va_end(ap); \ + struct lwip_sock *sock = NULL; \ +- if (select_posix_path() == PATH_KERNEL || \ +- select_fd_posix_path(_fd, &sock) == PATH_KERNEL) \ ++ if (select_posix_path() == POSIX_KERNEL || \ ++ select_fd_posix_path(_fd, &sock) == POSIX_KERNEL) \ + return _fcntl_fn(_fd, _cmd, val); \ + int32_t ret1 = _fcntl_fn(_fd, _cmd, val); \ + if (ret1 == -1) { \ +diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c +index 6fe4055..84ef782 100644 +--- a/src/lstack/core/lstack_lwip.c ++++ b/src/lstack/core/lstack_lwip.c +@@ -147,7 +147,7 @@ static bool replenish_send_idlembuf(struct protocol_stack *stack, struct lwip_so + int do_lwip_init_sock(int32_t fd) + { + struct protocol_stack *stack = get_protocol_stack(); +- struct lwip_sock *sock = get_socket_by_fd(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + if (sock == NULL) { + return -1; + } +@@ -179,7 +179,7 @@ int do_lwip_init_sock(int32_t fd) + + void do_lwip_clean_sock(int fd) + { +- struct lwip_sock *sock = get_socket_by_fd(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + if (sock == NULL || sock->stack == NULL) { + return; + } +@@ -819,7 +819,7 @@ ssize_t do_lwip_send_to_stack(int32_t fd, const void *buf, size_t len, int32_t f + GAZELLE_RETURN(EINVAL); + } + +- struct lwip_sock *sock = get_socket_by_fd(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + if (len == 0 && !NETCONN_IS_UDP(sock)) { + return 0; + } +@@ -1059,7 +1059,7 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags + struct sockaddr *addr, socklen_t *addrlen) + { + ssize_t recvd = 0; +- struct lwip_sock *sock = get_socket_by_fd(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + bool noblock = (flags & MSG_DONTWAIT) || netconn_is_nonblocking(sock->conn); + + if (recv_break_for_err(sock)) { +@@ -1095,7 +1095,7 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags + + void do_lwip_add_recvlist(int32_t fd) + { +- struct lwip_sock *sock = get_socket_by_fd(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + + if (sock && sock->stack && list_is_null(&sock->recv_list)) { + list_add_node(&sock->stack->recv_list, &sock->recv_list); +@@ -1166,7 +1166,7 @@ void do_lwip_connected_callback(struct netconn *conn) + } + + int32_t fd = conn->callback_arg.socket; +- struct lwip_sock *sock = get_socket_by_fd(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + if (sock == NULL || sock->conn == NULL) { + return; + } +@@ -1177,7 +1177,7 @@ void do_lwip_connected_callback(struct netconn *conn) + + posix_api->shutdown_fn(fd, SHUT_RDWR); + +- SET_CONN_TYPE_LIBOS(conn); ++ POSIX_SET_TYPE(sock, POSIX_LWIP); + + add_sock_event(sock, EPOLLOUT); + } +@@ -1207,8 +1207,8 @@ static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const s + if (netconn != NULL) { + conn->fd = netconn->callback_arg.socket; + conn->recv_cnt = (netconn->recvmbox == NULL) ? 0 : rte_ring_count(netconn->recvmbox->ring); +- struct lwip_sock *sock = get_socket(netconn->callback_arg.socket); +- if (sock != NULL) { ++ struct lwip_sock *sock = lwip_get_socket(netconn->callback_arg.socket); ++ if (sock != NULL && sock->conn != NULL) { + conn->recv_ring_cnt = (sock->recv_ring == NULL) ? 0 : gazelle_ring_readable_count(sock->recv_ring); + conn->recv_ring_cnt += (sock->recv_lastdata) ? 1 : 0; + conn->send_ring_cnt = (sock->send_ring == NULL) ? 0 : gazelle_ring_readover_count(sock->send_ring); +@@ -1473,7 +1473,7 @@ err_t same_node_ring_create(struct rte_ring **ring, int size, int port, char *na + static void init_same_node_ring(struct tcp_pcb *pcb) + { + struct netconn *netconn = (struct netconn *)pcb->callback_arg; +- struct lwip_sock *sock = get_socket(netconn->callback_arg.socket); ++ struct lwip_sock *sock = lwip_get_socket(netconn->callback_arg.socket); + + pcb->client_rx_ring = NULL; + pcb->client_tx_ring = NULL; +@@ -1488,7 +1488,7 @@ static void init_same_node_ring(struct tcp_pcb *pcb) + err_t create_same_node_ring(struct tcp_pcb *pcb) + { + struct netconn *netconn = (struct netconn *)pcb->callback_arg; +- struct lwip_sock *sock = get_socket(netconn->callback_arg.socket); ++ struct lwip_sock *sock = lwip_get_socket(netconn->callback_arg.socket); + + if (same_node_ring_create(&pcb->client_rx_ring, CLIENT_RING_SIZE, pcb->local_port, "client", "rx") != 0) { + goto END; +diff --git a/src/lstack/core/lstack_preload.c b/src/lstack/core/lstack_preload.c +index 0974e9e..8cf4657 100644 +--- a/src/lstack/core/lstack_preload.c ++++ b/src/lstack/core/lstack_preload.c +@@ -30,7 +30,7 @@ + + #define EXCLUDE_THRD_CNT 1 + const static char *g_exclude_thread[EXCLUDE_THRD_CNT] = {"eal-intr-thread"}; +-static PER_THREAD enum KERNEL_LWIP_PATH g_preload_thrdpath = PATH_UNKNOW; ++static PER_THREAD enum posix_type g_preload_thrdpath = POSIX_ALL; + + struct lstack_preload { + int32_t preload_switch; +@@ -79,27 +79,27 @@ static void preload_get_thrdname(void) + LSTACK_PRE_LOG(LSTACK_INFO, "thread name=%s ok\n", g_preload_info.env_thrdname); + } + +-enum KERNEL_LWIP_PATH select_fd_posix_path(int32_t fd, struct lwip_sock **socket) ++enum posix_type select_fd_posix_path(int32_t fd, struct lwip_sock **socket) + { +- struct lwip_sock *sock = get_socket_by_fd(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + + /* AF_UNIX case */ +- if (!sock || !sock->conn || CONN_TYPE_IS_HOST(sock->conn)) { +- return PATH_KERNEL; ++ if (!sock || !sock->conn || POSIX_IS_TYPE(sock, POSIX_KERNEL)) { ++ return POSIX_KERNEL; + } + + if (socket) { + *socket = sock; + } + +- if (likely(CONN_TYPE_IS_LIBOS(sock->conn))) { +- return PATH_LWIP; ++ if (likely(POSIX_IS_TYPE(sock, POSIX_LWIP))) { ++ return POSIX_LWIP; + } + +- return PATH_UNKNOW; ++ return POSIX_ALL; + } + +-enum KERNEL_LWIP_PATH select_posix_path(void) ++enum posix_type select_posix_path(void) + { + if (unlikely(posix_api == NULL)) { + /* +@@ -109,14 +109,14 @@ enum KERNEL_LWIP_PATH select_posix_path(void) + if (posix_api_init() != 0) { + LSTACK_PRE_LOG(LSTACK_ERR, "posix_api_init failed\n"); + } +- return PATH_KERNEL; ++ return POSIX_KERNEL; + } + + if (unlikely(posix_api->ues_posix)) { +- return PATH_KERNEL; ++ return POSIX_KERNEL; + } + +- if (g_preload_thrdpath != PATH_UNKNOW) { ++ if (g_preload_thrdpath != POSIX_ALL) { + return g_preload_thrdpath; + } + +@@ -126,31 +126,31 @@ enum KERNEL_LWIP_PATH select_posix_path(void) + + char thread_name[PATH_MAX] = {0}; + if (pthread_getname_np(pthread_self(), thread_name, PATH_MAX) != 0) { +- g_preload_thrdpath = PATH_KERNEL; +- return PATH_KERNEL; ++ g_preload_thrdpath = POSIX_KERNEL; ++ return POSIX_KERNEL; + } + + /* exclude dpdk thread */ + for (int i = 0; i < EXCLUDE_THRD_CNT; i++) { + if (strstr(thread_name, g_exclude_thread[i]) != NULL) { +- g_preload_thrdpath = PATH_KERNEL; +- return PATH_KERNEL; ++ g_preload_thrdpath = POSIX_KERNEL; ++ return POSIX_KERNEL; + } + } + + /* not set GAZELLE_THREAD_NAME, select all thread */ + if (g_preload_info.env_thrdname[0] == '\0') { +- g_preload_thrdpath = PATH_LWIP; +- return PATH_LWIP; ++ g_preload_thrdpath = POSIX_LWIP; ++ return POSIX_LWIP; + } + + if (strstr(thread_name, g_preload_info.env_thrdname) == NULL) { +- g_preload_thrdpath = PATH_KERNEL; +- return PATH_KERNEL; ++ g_preload_thrdpath = POSIX_KERNEL; ++ return POSIX_KERNEL; + } + +- g_preload_thrdpath = PATH_LWIP; +- return PATH_LWIP; ++ g_preload_thrdpath = POSIX_LWIP; ++ return POSIX_LWIP; + } + + int preload_info_init(void) +diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c +index c6075d5..d17cb67 100644 +--- a/src/lstack/core/lstack_protocol_stack.c ++++ b/src/lstack/core/lstack_protocol_stack.c +@@ -126,8 +126,8 @@ struct protocol_stack *get_protocol_stack(void) + + struct protocol_stack *get_protocol_stack_by_fd(int32_t fd) + { +- struct lwip_sock *sock = get_socket(fd); +- if (sock == NULL) { ++ struct lwip_sock *sock = lwip_get_socket(fd); ++ if (sock == NULL || sock->conn == NULL) { + return NULL; + } + +@@ -719,7 +719,7 @@ void stack_close(struct rpc_msg *msg) + { + int32_t fd = msg->args[MSG_ARG_0].i; + struct protocol_stack *stack = get_protocol_stack_by_fd(fd); +- struct lwip_sock *sock = get_socket(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + + if (sock && __atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) > 0) { + msg->recall_flag = 1; +@@ -738,7 +738,7 @@ void stack_shutdown(struct rpc_msg *msg) + int fd = msg->args[MSG_ARG_0].i; + int how = msg->args[MSG_ARG_1].i; + struct protocol_stack *stack = get_protocol_stack_by_fd(fd); +- struct lwip_sock *sock = get_socket(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + + if (sock && __atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) > 0) { + msg->recall_flag = 1; +@@ -767,7 +767,7 @@ void stack_listen(struct rpc_msg *msg) + int32_t fd = msg->args[MSG_ARG_0].i; + int32_t backlog = msg->args[MSG_ARG_1].i; + +- struct lwip_sock *sock = get_socket_by_fd(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + if (sock == NULL) { + msg->result = -1; + return; +@@ -793,7 +793,7 @@ void stack_accept(struct rpc_msg *msg) + return; + } + +- struct lwip_sock *sock = get_socket(accept_fd); ++ struct lwip_sock *sock = lwip_get_socket(accept_fd); + if (sock == NULL || sock->stack == NULL) { + lwip_close(accept_fd); + LSTACK_LOG(ERR, LSTACK, "fd %d ret %d\n", fd, accept_fd); +@@ -880,7 +880,7 @@ void stack_tcp_send(struct rpc_msg *msg) + struct protocol_stack *stack = get_protocol_stack(); + int replenish_again; + +- struct lwip_sock *sock = get_socket(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + if (sock == NULL) { + msg->result = -1; + LSTACK_LOG(ERR, LSTACK, "get sock error! fd=%d, len=%ld\n", fd, len); +@@ -917,7 +917,7 @@ void stack_udp_send(struct rpc_msg *msg) + int replenish_again; + uint32_t call_num; + +- struct lwip_sock *sock = get_socket(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + if (sock == NULL) { + msg->result = -1; + LSTACK_LOG(ERR, LSTACK, "get sock error! fd=%d, len=%ld\n", fd, len); +@@ -1030,7 +1030,7 @@ void stack_create_shadow_fd(struct rpc_msg *msg) + socklen_t addr_len = msg->args[MSG_ARG_2].socklen; + + int32_t clone_fd = 0; +- struct lwip_sock *sock = get_socket_by_fd(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + if (sock == NULL) { + LSTACK_LOG(ERR, LSTACK, "get sock null fd=%d\n", fd); + msg->result = -1; +@@ -1046,7 +1046,7 @@ void stack_create_shadow_fd(struct rpc_msg *msg) + return; + } + +- struct lwip_sock *clone_sock = get_socket_by_fd(clone_fd); ++ struct lwip_sock *clone_sock = lwip_get_socket(clone_fd); + if (clone_sock == NULL) { + LSTACK_LOG(ERR, LSTACK, "get sock null fd=%d clone_fd=%d\n", fd, clone_fd); + msg->result = -1; +@@ -1114,7 +1114,7 @@ void stack_recvlist_count(struct rpc_msg *msg) + int32_t stack_broadcast_close(int32_t fd) + { + int32_t ret = 0; +- struct lwip_sock *sock = get_socket(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + struct protocol_stack *stack = get_protocol_stack_by_fd(fd); + if (sock == NULL) { + GAZELLE_RETURN(EBADF); +@@ -1139,7 +1139,7 @@ int32_t stack_broadcast_close(int32_t fd) + int stack_broadcast_shutdown(int fd, int how) + { + int32_t ret = 0; +- struct lwip_sock *sock = get_socket(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + struct protocol_stack *stack = get_protocol_stack_by_fd(fd); + if (sock == NULL) { + GAZELLE_RETURN(EBADF); +@@ -1186,7 +1186,7 @@ int32_t stack_broadcast_listen(int32_t fd, int32_t backlog) + socklen_t addr_len = sizeof(addr); + int32_t ret, clone_fd; + +- struct lwip_sock *sock = get_socket(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + if (sock == NULL || cur_stack == NULL) { + LSTACK_LOG(ERR, LSTACK, "tid %ld, %d get sock null or stack null\n", get_stack_tid(), fd); + GAZELLE_RETURN(EBADF); +@@ -1216,9 +1216,9 @@ int32_t stack_broadcast_listen(int32_t fd, int32_t backlog) + } + + if (min_conn_stk_idx == i) { +- get_socket_by_fd(clone_fd)->conn->is_master_fd = 1; ++ lwip_get_socket(clone_fd)->conn->is_master_fd = 1; + } else { +- get_socket_by_fd(clone_fd)->conn->is_master_fd = 0; ++ lwip_get_socket(clone_fd)->conn->is_master_fd = 0; + } + + ret = rpc_call_listen(&stack->rpc_queue, clone_fd, backlog); +@@ -1232,7 +1232,7 @@ int32_t stack_broadcast_listen(int32_t fd, int32_t backlog) + + static struct lwip_sock *get_min_accept_sock(int32_t fd) + { +- struct lwip_sock *sock = get_socket(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + struct lwip_sock *min_sock = NULL; + + while (sock) { +@@ -1282,7 +1282,7 @@ int32_t stack_broadcast_bind(int32_t fd, const struct sockaddr *name, socklen_t + struct protocol_stack *stack = NULL; + int32_t ret, clone_fd; + +- struct lwip_sock *sock = get_socket(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + if (sock == NULL || cur_stack == NULL) { + LSTACK_LOG(ERR, LSTACK, "tid %ld, %d get sock null or stack null\n", get_stack_tid(), fd); + GAZELLE_RETURN(EBADF); +@@ -1313,7 +1313,7 @@ int32_t stack_broadcast_accept4(int32_t fd, struct sockaddr *addr, socklen_t *ad + { + int32_t ret = -1; + struct lwip_sock *min_sock = NULL; +- struct lwip_sock *sock = get_socket(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + struct protocol_stack *stack = NULL; + if (sock == NULL) { + GAZELLE_RETURN(EBADF); +@@ -1356,8 +1356,8 @@ int32_t stack_broadcast_accept(int32_t fd, struct sockaddr *addr, socklen_t *add + static void stack_all_fds_close(void) + { + for (int i = 3; i < GAZELLE_MAX_CLIENTS + GAZELLE_RESERVED_CLIENTS; i++) { +- struct lwip_sock *sock = get_socket(i); +- if (sock && sock->stack == get_protocol_stack()) { ++ struct lwip_sock *sock = lwip_get_socket(i); ++ if (sock && sock->conn && sock->stack == get_protocol_stack()) { + lwip_close(i); + } + } +diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c +index e77f21a..e42efde 100644 +--- a/src/lstack/core/lstack_stack_stat.c ++++ b/src/lstack/core/lstack_stack_stat.c +@@ -81,7 +81,7 @@ void time_stamp_into_recvmbox(struct lwip_sock *sock) + + void time_stamp_record(int fd, struct pbuf *pbuf) + { +- struct lwip_sock *sock = get_socket_by_fd(fd); ++ struct lwip_sock *sock = lwip_get_socket(fd); + + if (get_protocol_stack_group()->latency_start && sock && pbuf) { + calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_INTO_MBOX, 0); +diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c +index a6d2dbf..8ac06cb 100644 +--- a/src/lstack/core/lstack_thread_rpc.c ++++ b/src/lstack/core/lstack_thread_rpc.c +@@ -474,7 +474,7 @@ int32_t rpc_call_tcp_send(rpc_queue *queue, int fd, size_t len, int flags) + } + + if (get_protocol_stack_group()->latency_start) { +- time_stamp_into_rpcmsg(get_socket_by_fd(fd)); ++ time_stamp_into_rpcmsg(lwip_get_socket(fd)); + } + + msg->args[MSG_ARG_0].i = fd; +@@ -495,7 +495,7 @@ int32_t rpc_call_udp_send(rpc_queue *queue, int fd, size_t len, int flags) + } + + if (get_protocol_stack_group()->latency_start) { +- time_stamp_into_rpcmsg(get_socket_by_fd(fd)); ++ time_stamp_into_rpcmsg(lwip_get_socket(fd)); + } + + msg->args[MSG_ARG_0].i = fd; +diff --git a/src/lstack/include/lstack_preload.h b/src/lstack/include/lstack_preload.h +index 0ad7877..c30736a 100644 +--- a/src/lstack/include/lstack_preload.h ++++ b/src/lstack/include/lstack_preload.h +@@ -13,13 +13,7 @@ + #define __LSTACK_PRELOAD_H__ + #include + +-enum KERNEL_LWIP_PATH { +- PATH_KERNEL = 0, +- PATH_LWIP, +- PATH_UNKNOW, +-}; +- +-enum KERNEL_LWIP_PATH select_posix_path(void); +-enum KERNEL_LWIP_PATH select_fd_posix_path(int32_t fd, struct lwip_sock **socket); ++enum posix_type select_posix_path(void); ++enum posix_type select_fd_posix_path(int32_t fd, struct lwip_sock **socket); + int preload_info_init(void); + #endif +-- +2.33.0 + diff --git a/0218-fix-some-error-of-NULL-pointer.patch b/0218-fix-some-error-of-NULL-pointer.patch new file mode 100644 index 0000000000000000000000000000000000000000..a49c79232e58f39dae3cacd365b7077353d1eece --- /dev/null +++ b/0218-fix-some-error-of-NULL-pointer.patch @@ -0,0 +1,198 @@ +From da10c78f9fa9b865ccc1a780a77f405dc093d04a Mon Sep 17 00:00:00 2001 +From: yinbin +Date: Mon, 15 Jul 2024 15:27:53 +0800 +Subject: [PATCH] fix some error of NULL pointer + +--- + src/lstack/api/lstack_epoll.c | 23 ++++++++++++++++++----- + src/lstack/core/lstack_lwip.c | 15 ++++++++------- + src/lstack/core/lstack_port_map.c | 2 +- + src/lstack/core/lstack_protocol_stack.c | 2 +- + src/lstack/netif/lstack_ethdev.c | 8 ++++++-- + src/lstack/netif/lstack_tx_cache.c | 1 + + 6 files changed, 35 insertions(+), 16 deletions(-) + +diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c +index 7d00de7..566443e 100644 +--- a/src/lstack/api/lstack_epoll.c ++++ b/src/lstack/api/lstack_epoll.c +@@ -740,6 +740,7 @@ static int32_t init_poll_wakeup_data(struct wakeup_poll *wakeup) + wakeup->events = calloc(POLL_KERNEL_EVENTS, sizeof(struct epoll_event)); + if (wakeup->events == NULL) { + free(wakeup->last_fds); ++ wakeup->last_fds = NULL; + GAZELLE_RETURN(EINVAL); + } + +@@ -760,7 +761,7 @@ static int32_t init_poll_wakeup_data(struct wakeup_poll *wakeup) + return 0; + } + +-static void resize_kernel_poll(struct wakeup_poll *wakeup, nfds_t nfds) ++static int resize_kernel_poll(struct wakeup_poll *wakeup, nfds_t nfds) + { + if (wakeup->last_fds) { + free(wakeup->last_fds); +@@ -768,6 +769,7 @@ static void resize_kernel_poll(struct wakeup_poll *wakeup, nfds_t nfds) + wakeup->last_fds = calloc(nfds, sizeof(struct pollfd)); + if (wakeup->last_fds == NULL) { + LSTACK_LOG(ERR, LSTACK, "calloc failed errno=%d\n", errno); ++ return -1; + } + + if (wakeup->events) { +@@ -776,9 +778,12 @@ static void resize_kernel_poll(struct wakeup_poll *wakeup, nfds_t nfds) + wakeup->events = calloc(nfds, sizeof(struct epoll_event)); + if (wakeup->events == NULL) { + LSTACK_LOG(ERR, LSTACK, "calloc failed errno=%d\n", errno); ++ free(wakeup->last_fds); ++ return -1; + } + + wakeup->last_max_nfds = nfds; ++ return 0; + } + + static void poll_bind_statck(struct wakeup_poll *wakeup, int32_t *stack_count) +@@ -811,14 +816,18 @@ static void update_kernel_poll(struct wakeup_poll *wakeup, uint32_t index, struc + } + } + +-static void poll_init(struct wakeup_poll *wakeup, struct pollfd *fds, nfds_t nfds) ++static int poll_init(struct wakeup_poll *wakeup, struct pollfd *fds, nfds_t nfds) + { + int32_t stack_count[PROTOCOL_STACK_MAX] = {0}; + int32_t poll_change = 0; ++ int ret = 0; + + /* poll fds num more, recalloc fds size */ + if (nfds > wakeup->last_max_nfds) { +- resize_kernel_poll(wakeup, nfds); ++ ret = resize_kernel_poll(wakeup, nfds); ++ if (ret < 0) { ++ return -1; ++ } + poll_change = 1; + } + +@@ -855,13 +864,14 @@ static void poll_init(struct wakeup_poll *wakeup, struct pollfd *fds, nfds_t nfd + } + + if (poll_change == 0) { +- return; ++ return 0; + } + wakeup->last_nfds = nfds; + + if (get_global_cfg_params()->app_bind_numa) { + poll_bind_statck(wakeup, stack_count); + } ++ return 0; + } + + int32_t lstack_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout) +@@ -880,7 +890,10 @@ int32_t lstack_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout) + } + } + +- poll_init(wakeup, fds, nfds); ++ if (poll_init(wakeup, fds, nfds) < 0) { ++ free(wakeup); ++ GAZELLE_RETURN(EINVAL); ++ } + + int32_t kernel_num = 0; + int32_t lwip_num = 0; +diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c +index 75ef5f6..4d73d44 100644 +--- a/src/lstack/core/lstack_lwip.c ++++ b/src/lstack/core/lstack_lwip.c +@@ -333,7 +333,7 @@ static ssize_t do_app_write(struct lwip_sock *sock, struct pbuf *pbufs[], void * + } + + /* reduce the branch in loop */ +- uint16_t copy_len = len - send_len; ++ size_t copy_len = len - send_len; + rte_memcpy((char *)pbufs[i]->payload, (char *)buf + send_len, copy_len); + pbufs[i]->tot_len = pbufs[i]->len = copy_len; + send_len += copy_len; +@@ -1358,12 +1358,13 @@ void netif_poll(struct netif *netif) + /* processes on same node handshake packet use this function */ + err_t netif_loop_output(struct netif *netif, struct pbuf *p) + { +- if (p != NULL) { +- const struct ip_hdr *iphdr; +- iphdr = (const struct ip_hdr *)p->payload; +- if (IPH_PROTO(iphdr) == IP_PROTO_UDP) { +- return udp_netif_loop_output(netif, p); +- } ++ if (!p) { ++ return ERR_ARG; ++ } ++ const struct ip_hdr *iphdr; ++ iphdr = (const struct ip_hdr *)p->payload; ++ if (IPH_PROTO(iphdr) == IP_PROTO_UDP) { ++ return udp_netif_loop_output(netif, p); + } + + struct tcp_pcb *pcb = p->pcb; +diff --git a/src/lstack/core/lstack_port_map.c b/src/lstack/core/lstack_port_map.c +index 5439394..ce9d8df 100644 +--- a/src/lstack/core/lstack_port_map.c ++++ b/src/lstack/core/lstack_port_map.c +@@ -39,4 +39,4 @@ uint16_t port_map_get(uint16_t port) + } + pthread_mutex_unlock(&g_rule_map_mutex); + return val; +-} +\ No newline at end of file ++} +diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c +index d8bdd3c..d1bbf9b 100644 +--- a/src/lstack/core/lstack_protocol_stack.c ++++ b/src/lstack/core/lstack_protocol_stack.c +@@ -1000,7 +1000,7 @@ void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack + return; + } + copy_mbuf(mbuf_copy, mbuf); +- virtio_tap_process_tx(stack->queue_id, mbuf_copy); ++ virtio_tap_process_tx(cur_stack->queue_id, mbuf_copy); + } + return; + } +diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c +index 5685d11..d4d0878 100644 +--- a/src/lstack/netif/lstack_ethdev.c ++++ b/src/lstack/netif/lstack_ethdev.c +@@ -319,10 +319,14 @@ static err_t eth_dev_init(struct netif *netif) + int32_t ethdev_init(struct protocol_stack *stack) + { + struct cfg_params *cfg = get_global_cfg_params(); +- ++ int ret = 0; ++ + vdev_dev_ops_init(&stack->dev_ops); + if (cfg->send_cache_mode) { +- tx_cache_init(stack->queue_id, stack, &stack->dev_ops); ++ ret = tx_cache_init(stack->queue_id, stack, &stack->dev_ops); ++ if (ret < 0) { ++ return ret; ++ } + } + + if (use_ltran()) { +diff --git a/src/lstack/netif/lstack_tx_cache.c b/src/lstack/netif/lstack_tx_cache.c +index cda0003..9a48307 100644 +--- a/src/lstack/netif/lstack_tx_cache.c ++++ b/src/lstack/netif/lstack_tx_cache.c +@@ -45,6 +45,7 @@ int tx_cache_init(uint16_t queue_id, void *priv, struct lstack_dev_ops *dev_ops) + struct tx_cache *tx_cache = calloc(1, sizeof(struct tx_cache)); + if (tx_cache == NULL) { + LSTACK_LOG(ERR, LSTACK, "queue(%d) tx cache init failed\n", queue_id); ++ return -1; + } + + tx_cache->queue_id = queue_id; +-- +2.33.0 + diff --git a/0219-cleancode-refactor-posix_api.patch b/0219-cleancode-refactor-posix_api.patch new file mode 100644 index 0000000000000000000000000000000000000000..776865fa405a9545614bc7d839bc41c361e44ecf --- /dev/null +++ b/0219-cleancode-refactor-posix_api.patch @@ -0,0 +1,775 @@ +From a1523d108581cfc8aaf89b1116dde071ca5656d8 Mon Sep 17 00:00:00 2001 +From: Lemmy Huang +Date: Wed, 10 Jul 2024 17:40:43 +0800 +Subject: [PATCH] cleancode: refactor posix_api + +Signed-off-by: Lemmy Huang +--- + src/lstack/api/lstack_epoll.c | 16 +- + src/lstack/api/lstack_fork.c | 3 +- + src/lstack/api/lstack_rtw_api.c | 2 +- + src/lstack/api/lstack_wrap.c | 234 ++++++++++-------------- + src/lstack/core/lstack_control_plane.c | 4 +- + src/lstack/core/lstack_init.c | 4 +- + src/lstack/core/lstack_lwip.c | 5 +- + src/lstack/core/lstack_preload.c | 23 ++- + src/lstack/core/lstack_protocol_stack.c | 8 +- + src/lstack/include/lstack_preload.h | 6 +- + src/lstack/netif/lstack_flow.c | 1 + + 11 files changed, 139 insertions(+), 167 deletions(-) + +diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c +index 8146b4f..f8fd6d4 100644 +--- a/src/lstack/api/lstack_epoll.c ++++ b/src/lstack/api/lstack_epoll.c +@@ -164,7 +164,7 @@ static uint32_t update_events(struct lwip_sock *sock) + + if ((sock->epoll_events & EPOLLOUT) && NETCONN_IS_OUTIDLE(sock)) { + /* lwip_netconn_do_connected set LIBOS FLAGS when connected */ +- if (sock->conn && POSIX_IS_TYPE(sock, POSIX_LWIP)) { ++ if (!POSIX_IS_CLOSED(sock) && POSIX_IS_TYPE(sock, POSIX_LWIP)) { + event |= EPOLLOUT; + } + } +@@ -190,7 +190,7 @@ static void rtc_raise_pending_events(struct wakeup_poll *wakeup, struct lwip_soc + + if (sock->sendevent) { + /* lwip_netconn_do_connected set LIBOS FLAGS when connected */ +- if (sock->conn && POSIX_IS_TYPE(sock, POSIX_LWIP)) { ++ if (!POSIX_IS_CLOSED(sock) && POSIX_IS_TYPE(sock, POSIX_LWIP)) { + event |= EPOLLOUT; + } + } +@@ -219,7 +219,7 @@ static void raise_pending_events(struct wakeup_poll *wakeup, struct lwip_sock *s + pthread_spin_lock(&wakeup->event_list_lock); + if (NETCONN_IS_OUTIDLE(sock)) { + /* lwip_netconn_do_connected set LIBOS FLAGS when connected */ +- if (sock->conn && POSIX_IS_TYPE(sock, POSIX_LWIP)) { ++ if (!POSIX_IS_CLOSED(sock) && POSIX_IS_TYPE(sock, POSIX_LWIP)) { + event |= EPOLLOUT; + } + } +@@ -398,7 +398,7 @@ int32_t lstack_rtc_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_ + + struct wakeup_poll *wakeup = epoll_sock->wakeup; + struct lwip_sock *sock = lwip_get_socket(fd); +- if (sock == NULL || sock->conn == NULL) { ++ if (POSIX_IS_CLOSED(sock)) { + return posix_api->epoll_ctl_fn(epfd, op, fd, event); + } + +@@ -438,7 +438,7 @@ int32_t lstack_rtw_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_ + + struct wakeup_poll *wakeup = epoll_sock->wakeup; + struct lwip_sock *sock = lwip_get_socket(fd); +- if (sock == NULL || sock->conn == NULL) { ++ if (POSIX_IS_CLOSED(sock)) { + return posix_api->epoll_ctl_fn(epfd, op, fd, event); + } + +@@ -536,7 +536,7 @@ static int32_t poll_lwip_event(struct pollfd *fds, nfds_t nfds) + /* sock->listen_next pointerto next stack listen */ + int32_t fd = fds[i].fd; + struct lwip_sock *sock = lwip_get_socket(fd); +- while (sock && sock->conn) { ++ while (!POSIX_IS_CLOSED(sock)) { + uint32_t events = update_events(sock); + if (events) { + fds[i].revents = events; +@@ -838,7 +838,7 @@ static void poll_init(struct wakeup_poll *wakeup, struct pollfd *fds, nfds_t nfd + } + } + +- if (sock == NULL || sock->conn == NULL || POSIX_HAS_TYPE(sock, POSIX_KERNEL)) { ++ if (POSIX_IS_CLOSED(sock) || POSIX_HAS_TYPE(sock, POSIX_KERNEL)) { + update_kernel_poll(wakeup, i, fds + i); + } + +@@ -846,7 +846,7 @@ static void poll_init(struct wakeup_poll *wakeup, struct pollfd *fds, nfds_t nfd + wakeup->last_fds[i].events = fds[i].events; + poll_change = 1; + +- while (sock && sock->conn) { ++ while (!POSIX_IS_CLOSED(sock)) { + sock->epoll_events = fds[i].events | POLLERR; + sock->wakeup = wakeup; + stack_count[sock->stack->stack_idx]++; +diff --git a/src/lstack/api/lstack_fork.c b/src/lstack/api/lstack_fork.c +index 5cddee2..f5d0e95 100644 +--- a/src/lstack/api/lstack_fork.c ++++ b/src/lstack/api/lstack_fork.c +@@ -20,8 +20,9 @@ pid_t lstack_fork(void) + pid_t pid; + + pid = posix_api->fork_fn(); ++ /* child not support lwip */ + if (pid == 0) { +- posix_api_fork(); ++ posix_api->use_kernel = 1; + } + return pid; + } +diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c +index f59b0cd..09c4e11 100644 +--- a/src/lstack/api/lstack_rtw_api.c ++++ b/src/lstack/api/lstack_rtw_api.c +@@ -186,7 +186,7 @@ static ssize_t rtw_udp_recvfrom(int sockfd, void *buf, size_t len, int flags, + return -1; + } + sock = sock->listen_next; +- if (sock != NULL && sock->conn != NULL) { ++ if (!POSIX_IS_CLOSED(sock)) { + sockfd = sock->conn->callback_arg.socket; + } else { + if (sock == NULL) { +diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c +index d3e1027..b19990e 100644 +--- a/src/lstack/api/lstack_wrap.c ++++ b/src/lstack/api/lstack_wrap.c +@@ -37,12 +37,8 @@ + #include "lstack_rtw_api.h" + #include "lstack_dummy_api.h" + +-#ifndef SOCK_TYPE_MASK +-#define SOCK_TYPE_MASK 0xf +-#endif +- +-posix_api_t g_wrap_api_value; +-posix_api_t *g_wrap_api; ++static posix_api_t g_wrap_api_value; ++static posix_api_t *g_wrap_api; + + void wrap_api_init(void) + { +@@ -68,10 +64,10 @@ void wrap_api_init(void) + g_wrap_api->writev_fn = lwip_writev; + g_wrap_api->recv_fn = lwip_recv; + g_wrap_api->send_fn = lwip_send; +- g_wrap_api->recv_msg = lwip_recvmsg; +- g_wrap_api->send_msg = lwip_sendmsg; +- g_wrap_api->recv_from = lwip_recvfrom; +- g_wrap_api->send_to = lwip_sendto; ++ g_wrap_api->recvmsg_fn = lwip_recvmsg; ++ g_wrap_api->sendmsg_fn = lwip_sendmsg; ++ g_wrap_api->recvfrom_fn = lwip_recvfrom; ++ g_wrap_api->sendto_fn = lwip_sendto; + g_wrap_api->epoll_wait_fn = rtc_epoll_wait; + g_wrap_api->poll_fn = rtc_poll; + g_wrap_api->close_fn = rtc_close; +@@ -97,10 +93,10 @@ void wrap_api_init(void) + g_wrap_api->writev_fn = rtw_writev; + g_wrap_api->recv_fn = rtw_recv; + g_wrap_api->send_fn = rtw_send; +- g_wrap_api->recv_msg = rtw_recvmsg; +- g_wrap_api->send_msg = rtw_sendmsg; +- g_wrap_api->recv_from = rtw_recvfrom; +- g_wrap_api->send_to = rtw_sendto; ++ g_wrap_api->recvmsg_fn = rtw_recvmsg; ++ g_wrap_api->sendmsg_fn = rtw_sendmsg; ++ g_wrap_api->recvfrom_fn = rtw_recvfrom; ++ g_wrap_api->sendto_fn = rtw_sendto; + g_wrap_api->epoll_wait_fn = rtw_epoll_wait; + g_wrap_api->poll_fn = rtw_poll; + g_wrap_api->close_fn = rtw_close; +@@ -118,8 +114,8 @@ void wrap_api_set_dummy(void) + g_wrap_api->send_fn = dummy_send; + g_wrap_api->write_fn = dummy_write; + g_wrap_api->writev_fn = dummy_writev; +- g_wrap_api->send_msg = dummy_sendmsg; +- g_wrap_api->send_to = dummy_sendto; ++ g_wrap_api->sendmsg_fn = dummy_sendmsg; ++ g_wrap_api->sendto_fn = dummy_sendto; + rte_wmb(); + } + +@@ -169,7 +165,7 @@ static inline int32_t do_epoll_wait(int32_t epfd, struct epoll_event* events, in + + static inline int32_t do_accept(int32_t s, struct sockaddr *addr, socklen_t *addrlen) + { +- if (select_fd_posix_path(s, NULL) == POSIX_KERNEL) { ++ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_KERNEL) { + return posix_api->accept_fn(s, addr, addrlen); + } + +@@ -189,7 +185,7 @@ static int32_t do_accept4(int32_t s, struct sockaddr *addr, socklen_t *addrlen, + GAZELLE_RETURN(EINVAL); + } + +- if (select_fd_posix_path(s, NULL) == POSIX_KERNEL) { ++ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_KERNEL) { + return posix_api->accept4_fn(s, addr, addrlen, flags); + } + +@@ -209,8 +205,8 @@ static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen + GAZELLE_RETURN(EINVAL); + } + +- struct lwip_sock *sock = NULL; +- if (select_fd_posix_path(s, &sock) == POSIX_KERNEL) { ++ struct lwip_sock *sock = lwip_get_socket(s); ++ if (select_sock_posix_path(sock) == POSIX_KERNEL) { + return posix_api->bind_fn(s, name, namelen); + } + +@@ -230,30 +226,31 @@ static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen + ((struct sockaddr_in6 *)name)->sin6_addr.s6_addr, IPV6_ADDR_LEN); + } + +- if (match_host_addr(&sock_addr)) { +- /* maybe kni addr */ +- if (posix_api->bind_fn(s, name, namelen) != 0) { +- POSIX_SET_TYPE(sock, POSIX_LWIP); +- } else { +- /* reuse the port allocated by kernel when port == 0 */ +- if (((struct sockaddr_in *)name)->sin_port == 0) { +- struct sockaddr_in kerneladdr; +- socklen_t len = sizeof(kerneladdr); +- if (posix_api->getsockname_fn(s, (struct sockaddr *)&kerneladdr, &len) < 0) { +- LSTACK_LOG(ERR, LSTACK, "kernel getsockname failed, fd=%d, errno=%d\n", s, errno); +- return -1; +- } +- ((struct sockaddr_in *)name)->sin_port = kerneladdr.sin_port; ++ if (!match_host_addr(&sock_addr)) { ++ POSIX_SET_TYPE(sock, POSIX_KERNEL); ++ return posix_api->bind_fn(s, name, namelen); ++ } ++ ++ /* maybe kni addr */ ++ if (posix_api->bind_fn(s, name, namelen) == 0) { ++ /* reuse the port allocated by kernel when port == 0 */ ++ if (((struct sockaddr_in *)name)->sin_port == 0) { ++ struct sockaddr_in kerneladdr; ++ socklen_t len = sizeof(kerneladdr); ++ if (posix_api->getsockname_fn(s, (struct sockaddr *)&kerneladdr, &len) < 0) { ++ LSTACK_LOG(ERR, LSTACK, "kernel getsockname failed, fd=%d, errno=%d\n", s, errno); ++ return -1; + } ++ ((struct sockaddr_in *)name)->sin_port = kerneladdr.sin_port; + } +- return g_wrap_api->bind_fn(s, name, namelen); ++ /* not sure POSIX_LWIP or POSIX_KERNEL */ + } else { +- POSIX_SET_TYPE(sock, POSIX_KERNEL); +- return posix_api->bind_fn(s, name, namelen); ++ POSIX_SET_TYPE(sock, POSIX_LWIP); + } ++ return g_wrap_api->bind_fn(s, name, namelen); + } + +-bool is_dst_ip_localhost(const struct sockaddr *addr) ++static bool is_dst_ip_localhost(const struct sockaddr *addr) + { + struct ifaddrs *ifap; + struct ifaddrs *ifa; +@@ -302,13 +299,8 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name + GAZELLE_RETURN(EINVAL); + } + +- struct lwip_sock *sock = NULL; +- if (select_fd_posix_path(s, &sock) == POSIX_KERNEL) { +- return posix_api->connect_fn(s, name, namelen); +- } +- +- sock = lwip_get_socket(s); +- if (sock == NULL) { ++ struct lwip_sock *sock = lwip_get_socket(s); ++ if (select_sock_posix_path(sock) == POSIX_KERNEL) { + return posix_api->connect_fn(s, name, namelen); + } + +@@ -334,7 +326,7 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name + + static inline int32_t do_listen(int32_t s, int32_t backlog) + { +- if (select_fd_posix_path(s, NULL) == POSIX_KERNEL) { ++ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_KERNEL) { + return posix_api->listen_fn(s, backlog); + } + +@@ -352,7 +344,7 @@ static inline int32_t do_getpeername(int32_t s, struct sockaddr *name, socklen_t + GAZELLE_RETURN(EINVAL); + } + +- if (select_fd_posix_path(s, NULL) == POSIX_LWIP) { ++ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { + return g_wrap_api->getpeername_fn(s, name, namelen); + } + +@@ -365,7 +357,7 @@ static inline int32_t do_getsockname(int32_t s, struct sockaddr *name, socklen_t + GAZELLE_RETURN(EINVAL); + } + +- if (select_fd_posix_path(s, NULL) == POSIX_LWIP) { ++ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { + return g_wrap_api->getsockname_fn(s, name, namelen); + } + +@@ -422,7 +414,7 @@ static bool unsupport_optname(int32_t level, int32_t optname) + + static inline int32_t do_getsockopt(int32_t s, int32_t level, int32_t optname, void *optval, socklen_t *optlen) + { +- if (select_fd_posix_path(s, NULL) == POSIX_LWIP && !unsupport_optname(level, optname)) { ++ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP && !unsupport_optname(level, optname)) { + return g_wrap_api->getsockopt_fn(s, level, optname, optval, optlen); + } + +@@ -431,7 +423,7 @@ static inline int32_t do_getsockopt(int32_t s, int32_t level, int32_t optname, v + + static inline int32_t do_setsockopt(int32_t s, int32_t level, int32_t optname, const void *optval, socklen_t optlen) + { +- if (select_fd_posix_path(s, NULL) == POSIX_KERNEL || unsupport_optname(level, optname)) { ++ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_KERNEL || unsupport_optname(level, optname)) { + return posix_api->setsockopt_fn(s, level, optname, optval, optlen); + } + +@@ -473,17 +465,14 @@ static inline ssize_t do_recv(int32_t sockfd, void *buf, size_t len, int32_t fla + if (buf == NULL) { + GAZELLE_RETURN(EINVAL); + } +- + if (len == 0) { + return 0; + } + +- if (select_posix_path() == POSIX_KERNEL || // maybe fd is created by open before posix_api_init called +- select_fd_posix_path(sockfd, NULL) == POSIX_KERNEL) { +- return posix_api->recv_fn(sockfd, buf, len, flags); ++ if (select_sock_posix_path(lwip_get_socket(sockfd)) == POSIX_LWIP) { ++ return g_wrap_api->recv_fn(sockfd, buf, len, flags); + } +- +- return g_wrap_api->recv_fn(sockfd, buf, len, flags); ++ return posix_api->recv_fn(sockfd, buf, len, flags); + } + + static inline ssize_t do_read(int32_t s, void *mem, size_t len) +@@ -491,58 +480,46 @@ static inline ssize_t do_read(int32_t s, void *mem, size_t len) + if (mem == NULL) { + GAZELLE_RETURN(EINVAL); + } +- + if (len == 0) { + return 0; + } + +- if (select_posix_path() == POSIX_KERNEL || +- select_fd_posix_path(s, NULL) == POSIX_KERNEL) { +- return posix_api->read_fn(s, mem, len); ++ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { ++ return g_wrap_api->read_fn(s, mem, len); + } +- +- return g_wrap_api->read_fn(s, mem, len); ++ return posix_api->read_fn(s, mem, len); + } + + static inline ssize_t do_readv(int32_t s, const struct iovec *iov, int iovcnt) + { +- if (select_posix_path() == POSIX_KERNEL || +- select_fd_posix_path(s, NULL) == POSIX_KERNEL) { +- return posix_api->readv_fn(s, iov, iovcnt); ++ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { ++ return g_wrap_api->readv_fn(s, iov, iovcnt); + } +- +- return g_wrap_api->readv_fn(s, iov, iovcnt); ++ return posix_api->readv_fn(s, iov, iovcnt); + } + + static inline ssize_t do_send(int32_t sockfd, const void *buf, size_t len, int32_t flags) + { +- if (select_posix_path() == POSIX_KERNEL || +- select_fd_posix_path(sockfd, NULL) == POSIX_KERNEL) { +- return posix_api->send_fn(sockfd, buf, len, flags); ++ if (select_sock_posix_path(lwip_get_socket(sockfd)) == POSIX_LWIP) { ++ return g_wrap_api->send_fn(sockfd, buf, len, flags); + } +- +- return g_wrap_api->send_fn(sockfd, buf, len, flags); ++ return posix_api->send_fn(sockfd, buf, len, flags); + } + + static inline ssize_t do_write(int32_t s, const void *mem, size_t size) + { +- if (select_posix_path() == POSIX_KERNEL || +- select_fd_posix_path(s, NULL) == POSIX_KERNEL) { +- return posix_api->write_fn(s, mem, size); ++ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { ++ return g_wrap_api->write_fn(s, mem, size); + } +- +- return g_wrap_api->write_fn(s, mem, size); ++ return posix_api->write_fn(s, mem, size); + } + + static inline ssize_t do_writev(int32_t s, const struct iovec *iov, int iovcnt) + { +- struct lwip_sock *sock; +- if (select_posix_path() == POSIX_KERNEL || +- select_fd_posix_path(s, &sock) == POSIX_KERNEL) { +- return posix_api->writev_fn(s, iov, iovcnt); ++ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { ++ return g_wrap_api->writev_fn(s, iov, iovcnt); + } +- +- return g_wrap_api->writev_fn(s, iov, iovcnt); ++ return posix_api->writev_fn(s, iov, iovcnt); + } + + static inline ssize_t do_recvmsg(int32_t s, struct msghdr *message, int32_t flags) +@@ -551,12 +528,10 @@ static inline ssize_t do_recvmsg(int32_t s, struct msghdr *message, int32_t flag + GAZELLE_RETURN(EINVAL); + } + +- if (select_posix_path() == POSIX_KERNEL || +- select_fd_posix_path(s, NULL) == POSIX_KERNEL) { +- return posix_api->recv_msg(s, message, flags); ++ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { ++ return g_wrap_api->recvmsg_fn(s, message, flags); + } +- +- return g_wrap_api->recv_msg(s, message, flags); ++ return posix_api->recvmsg_fn(s, message, flags); + } + + static inline ssize_t do_sendmsg(int32_t s, const struct msghdr *message, int32_t flags) +@@ -565,13 +540,10 @@ static inline ssize_t do_sendmsg(int32_t s, const struct msghdr *message, int32_ + GAZELLE_RETURN(EINVAL); + } + +- struct lwip_sock *sock; +- if (select_posix_path() == POSIX_KERNEL || +- select_fd_posix_path(s, &sock) == POSIX_KERNEL) { +- return posix_api->send_msg(s, message, flags); ++ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { ++ return g_wrap_api->sendmsg_fn(s, message, flags); + } +- +- return g_wrap_api->send_msg(s, message, flags); ++ return posix_api->sendmsg_fn(s, message, flags); + } + + static inline ssize_t do_recvfrom(int32_t sockfd, void *buf, size_t len, int32_t flags, +@@ -580,58 +552,48 @@ static inline ssize_t do_recvfrom(int32_t sockfd, void *buf, size_t len, int32_t + if (buf == NULL) { + GAZELLE_RETURN(EINVAL); + } +- + if (len == 0) { + return 0; + } + +- struct lwip_sock *sock = NULL; +- if (select_fd_posix_path(sockfd, &sock) == POSIX_LWIP) { +- return g_wrap_api->recv_from(sockfd, buf, len, flags, addr, addrlen); ++ if (select_sock_posix_path(lwip_get_socket(sockfd)) == POSIX_LWIP) { ++ return g_wrap_api->recvfrom_fn(sockfd, buf, len, flags, addr, addrlen); + } +- +- return posix_api->recv_from(sockfd, buf, len, flags, addr, addrlen); ++ return posix_api->recvfrom_fn(sockfd, buf, len, flags, addr, addrlen); + } + + static inline ssize_t do_sendto(int32_t sockfd, const void *buf, size_t len, int32_t flags, + const struct sockaddr *addr, socklen_t addrlen) + { +- struct lwip_sock *sock = NULL; +- if (select_fd_posix_path(sockfd, &sock) != POSIX_LWIP) { +- return posix_api->send_to(sockfd, buf, len, flags, addr, addrlen); ++ if (select_sock_posix_path(lwip_get_socket(sockfd)) == POSIX_LWIP) { ++ return g_wrap_api->sendto_fn(sockfd, buf, len, flags, addr, addrlen); + } +- +- return g_wrap_api->send_to(sockfd, buf, len, flags, addr, addrlen); ++ return posix_api->sendto_fn(sockfd, buf, len, flags, addr, addrlen); + } + +-static inline int32_t do_close(int32_t s) ++static inline int32_t do_close(int fd) + { +- struct lwip_sock *sock = NULL; ++ /* Can not use select_sock_posix_path() ! ++ * When fd created by lwip_stocket() set as POSIX_KERNEL, ++ * lwip_close() is still required. ++ */ + if (select_posix_path() == POSIX_KERNEL || +- select_fd_posix_path(s, &sock) == POSIX_KERNEL) { +- /* we called lwip_socket, even if kernel fd */ +- if (posix_api != NULL && !posix_api->ues_posix && +- /* contain posix_api->close_fn if success */ +- g_wrap_api->close_fn(s) == 0) { +- return 0; +- } else { +- return posix_api->close_fn(s); +- } ++ POSIX_IS_CLOSED(lwip_get_socket(fd))) { ++ return posix_api->close_fn(fd); + } +- return g_wrap_api->close_fn(s); ++ return g_wrap_api->close_fn(fd); + } + + static int32_t do_shutdown(int fd, int how) + { +- struct lwip_sock *sock = NULL; +- if (select_posix_path() == POSIX_KERNEL || select_fd_posix_path(fd, &sock) == POSIX_KERNEL) { +- if (posix_api != NULL && !posix_api->ues_posix && g_wrap_api->shutdown_fn(fd, how) == 0) { +- return 0; +- } else { +- return posix_api->shutdown_fn(fd, how); +- } ++ /* Can not use select_sock_posix_path() ! ++ * When fd created by lwip_stocket() set as POSIX_KERNEL, ++ * lwip_close() is still required. ++ */ ++ if (select_posix_path() == POSIX_KERNEL || ++ POSIX_IS_CLOSED(lwip_get_socket(fd))) { ++ return posix_api->shutdown_fn(fd, how); + } +- + return g_wrap_api->shutdown_fn(fd, how); + } + +@@ -660,15 +622,13 @@ static int32_t do_ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec * + return ready; + } + +-typedef int32_t (*sigaction_fn)(int32_t signum, const struct sigaction *act, struct sigaction *oldact); + static int32_t do_sigaction(int32_t signum, const struct sigaction *act, struct sigaction *oldact) + { +- if (posix_api == NULL) { +- sigaction_fn sf = (sigaction_fn)dlsym(RTLD_NEXT, "sigaction"); +- if (sf == NULL) { +- return -1; ++ if (unlikely(posix_api == NULL)) { ++ if (posix_api_init() != 0) { ++ GAZELLE_RETURN(EAGAIN); + } +- return sf(signum, act, oldact); ++ return posix_api->sigaction_fn(signum, act, oldact); + } + + return lstack_sigaction(signum, act, oldact); +@@ -676,10 +636,14 @@ static int32_t do_sigaction(int32_t signum, const struct sigaction *act, struct + + static int32_t do_select(int32_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) + { +- if ((select_posix_path() == POSIX_KERNEL) || !(readfds || writefds || exceptfds) || nfds == 0) { ++ if (nfds <= 0 || !(readfds || writefds || exceptfds)) { ++ GAZELLE_RETURN(EINVAL); ++ } ++ ++ if (select_posix_path() == POSIX_KERNEL) { + return posix_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); + } +- ++ + return g_wrap_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); + } + +@@ -690,9 +654,9 @@ static int32_t do_select(int32_t nfds, fd_set *readfds, fd_set *writefds, fd_set + va_start(ap, _cmd); \ + val = va_arg(ap, typeof(val)); \ + va_end(ap); \ +- struct lwip_sock *sock = NULL; \ ++ struct lwip_sock *sock = lwip_get_socket(_fd); \ + if (select_posix_path() == POSIX_KERNEL || \ +- select_fd_posix_path(_fd, &sock) == POSIX_KERNEL) \ ++ select_sock_posix_path(sock) == POSIX_KERNEL) \ + return _fcntl_fn(_fd, _cmd, val); \ + int32_t ret1 = _fcntl_fn(_fd, _cmd, val); \ + if (ret1 == -1) { \ +diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c +index 5545b9f..f1e3064 100644 +--- a/src/lstack/core/lstack_control_plane.c ++++ b/src/lstack/core/lstack_control_plane.c +@@ -764,7 +764,7 @@ void control_server_thread(void *arg) + struct epoll_event evt_array; + while (1) { + /* wait init finish */ +- if (posix_api->ues_posix) { ++ if (posix_api->use_kernel) { + usleep(GAZELLE_10MS); + continue; + } +@@ -813,7 +813,7 @@ void control_client_thread(void *arg) + + while (1) { + /* wait init finish */ +- if (posix_api->ues_posix) { ++ if (posix_api->use_kernel) { + usleep(GAZELLE_10MS); + continue; + } +diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c +index 1b3882e..54ee97e 100644 +--- a/src/lstack/core/lstack_init.c ++++ b/src/lstack/core/lstack_init.c +@@ -123,7 +123,7 @@ void gazelle_exit(void) + + __attribute__((destructor)) void gazelle_network_exit(void) + { +- if (posix_api != NULL && !posix_api->ues_posix) { ++ if (posix_api != NULL && !posix_api->use_kernel) { + lwip_exit(); + gazelle_exit(); + } +@@ -324,7 +324,7 @@ __attribute__((constructor)) void gazelle_network_init(void) + LSTACK_EXIT(1, "set_process_start_flag failed\n"); + } + +- posix_api->ues_posix = 0; ++ posix_api->use_kernel = 0; + LSTACK_LOG(INFO, LSTACK, "gazelle_network_init success\n"); + rte_smp_mb(); + } +diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c +index 84ef782..2b39d05 100644 +--- a/src/lstack/core/lstack_lwip.c ++++ b/src/lstack/core/lstack_lwip.c +@@ -79,6 +79,7 @@ static void reset_sock_data(struct lwip_sock *sock) + sock->send_pre_del = NULL; + } + ++ sock->type = 0; + sock->stack = NULL; + sock->wakeup = NULL; + sock->listen_next = NULL; +@@ -1167,7 +1168,7 @@ void do_lwip_connected_callback(struct netconn *conn) + + int32_t fd = conn->callback_arg.socket; + struct lwip_sock *sock = lwip_get_socket(fd); +- if (sock == NULL || sock->conn == NULL) { ++ if (POSIX_IS_CLOSED(sock)) { + return; + } + +@@ -1208,7 +1209,7 @@ static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const s + conn->fd = netconn->callback_arg.socket; + conn->recv_cnt = (netconn->recvmbox == NULL) ? 0 : rte_ring_count(netconn->recvmbox->ring); + struct lwip_sock *sock = lwip_get_socket(netconn->callback_arg.socket); +- if (sock != NULL && sock->conn != NULL) { ++ if (!POSIX_IS_CLOSED(sock)) { + conn->recv_ring_cnt = (sock->recv_ring == NULL) ? 0 : gazelle_ring_readable_count(sock->recv_ring); + conn->recv_ring_cnt += (sock->recv_lastdata) ? 1 : 0; + conn->send_ring_cnt = (sock->send_ring == NULL) ? 0 : gazelle_ring_readover_count(sock->send_ring); +diff --git a/src/lstack/core/lstack_preload.c b/src/lstack/core/lstack_preload.c +index 8cf4657..689d2bf 100644 +--- a/src/lstack/core/lstack_preload.c ++++ b/src/lstack/core/lstack_preload.c +@@ -79,17 +79,22 @@ static void preload_get_thrdname(void) + LSTACK_PRE_LOG(LSTACK_INFO, "thread name=%s ok\n", g_preload_info.env_thrdname); + } + +-enum posix_type select_fd_posix_path(int32_t fd, struct lwip_sock **socket) ++enum posix_type select_sock_posix_path(struct lwip_sock *sock) + { +- struct lwip_sock *sock = lwip_get_socket(fd); +- +- /* AF_UNIX case */ +- if (!sock || !sock->conn || POSIX_IS_TYPE(sock, POSIX_KERNEL)) { ++ if (unlikely(posix_api == NULL)) { ++ /* ++ * read/write/readv/writev may not be sockfd, ++ * posix api maybe not init. ++ */ ++ if (posix_api_init() != 0) { ++ LSTACK_PRE_LOG(LSTACK_ERR, "posix_api_init failed\n"); ++ } + return POSIX_KERNEL; + } + +- if (socket) { +- *socket = sock; ++ /* CLOSED means not sockfd, such as file fd or unix fd */ ++ if (POSIX_IS_CLOSED(sock) || POSIX_IS_TYPE(sock, POSIX_KERNEL)) { ++ return POSIX_KERNEL; + } + + if (likely(POSIX_IS_TYPE(sock, POSIX_LWIP))) { +@@ -112,11 +117,11 @@ enum posix_type select_posix_path(void) + return POSIX_KERNEL; + } + +- if (unlikely(posix_api->ues_posix)) { ++ if (unlikely(posix_api->use_kernel)) { + return POSIX_KERNEL; + } + +- if (g_preload_thrdpath != POSIX_ALL) { ++ if (likely(g_preload_thrdpath != POSIX_ALL)) { + return g_preload_thrdpath; + } + +diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c +index d17cb67..a809d8c 100644 +--- a/src/lstack/core/lstack_protocol_stack.c ++++ b/src/lstack/core/lstack_protocol_stack.c +@@ -127,7 +127,7 @@ struct protocol_stack *get_protocol_stack(void) + struct protocol_stack *get_protocol_stack_by_fd(int32_t fd) + { + struct lwip_sock *sock = lwip_get_socket(fd); +- if (sock == NULL || sock->conn == NULL) { ++ if (POSIX_IS_CLOSED(sock)) { + return NULL; + } + +@@ -1126,7 +1126,7 @@ int32_t stack_broadcast_close(int32_t fd) + ret = -1; + } + +- if (sock == NULL || sock->conn == NULL) { ++ if (POSIX_IS_CLOSED(sock)) { + break; + } + fd = sock->conn->callback_arg.socket; +@@ -1151,7 +1151,7 @@ int stack_broadcast_shutdown(int fd, int how) + ret = -1; + } + +- if (sock == NULL || sock->conn == NULL) { ++ if (POSIX_IS_CLOSED(sock)) { + break; + } + fd = sock->conn->callback_arg.socket; +@@ -1357,7 +1357,7 @@ static void stack_all_fds_close(void) + { + for (int i = 3; i < GAZELLE_MAX_CLIENTS + GAZELLE_RESERVED_CLIENTS; i++) { + struct lwip_sock *sock = lwip_get_socket(i); +- if (sock && sock->conn && sock->stack == get_protocol_stack()) { ++ if (!POSIX_IS_CLOSED(sock) && sock->stack == get_protocol_stack()) { + lwip_close(i); + } + } +diff --git a/src/lstack/include/lstack_preload.h b/src/lstack/include/lstack_preload.h +index c30736a..d4ad385 100644 +--- a/src/lstack/include/lstack_preload.h ++++ b/src/lstack/include/lstack_preload.h +@@ -11,9 +11,9 @@ + */ + #ifndef __LSTACK_PRELOAD_H__ + #define __LSTACK_PRELOAD_H__ +-#include + + enum posix_type select_posix_path(void); +-enum posix_type select_fd_posix_path(int32_t fd, struct lwip_sock **socket); ++enum posix_type select_sock_posix_path(struct lwip_sock *sock); + int preload_info_init(void); +-#endif ++ ++#endif /* __LSTACK_PRELOAD_H__ */ +diff --git a/src/lstack/netif/lstack_flow.c b/src/lstack/netif/lstack_flow.c +index 84c5c61..1ca3314 100644 +--- a/src/lstack/netif/lstack_flow.c ++++ b/src/lstack/netif/lstack_flow.c +@@ -19,6 +19,7 @@ + #include + + #include ++#include + #include + #include + +-- +2.33.0 + diff --git a/0220-cleancode-refactor-lwipgz_list.h.patch b/0220-cleancode-refactor-lwipgz_list.h.patch new file mode 100644 index 0000000000000000000000000000000000000000..64d79c410145a1f047347d1aabc19208d4609807 --- /dev/null +++ b/0220-cleancode-refactor-lwipgz_list.h.patch @@ -0,0 +1,445 @@ +From daacb87180fa9c98c53c001bb37929b9aaef46d9 Mon Sep 17 00:00:00 2001 +From: Lemmy Huang +Date: Mon, 15 Jul 2024 11:27:19 +0800 +Subject: [PATCH] cleancode: refactor lwipgz_list.h + + Changed: + list_is_empty -> list_head_empty + list_is_null -> list_node_null + + init_list_node -> list_init_head + init_list_node_null -> list_init_node + + list_add_node -> list_add_node + list_del_node_null -> list_del_node + list_del_node -> __list_del_node + list_for_each_safe -> list_for_each_node + Deprecated: + list_del_node_init + Added: + list_get_node_count + list_entry + +Signed-off-by: Lemmy Huang +--- + src/common/gazelle_base_func.h | 5 +- + src/lstack/api/lstack_epoll.c | 66 ++++++++++++------------- + src/lstack/api/lstack_rtc_api.c | 2 +- + src/lstack/core/lstack_lwip.c | 28 +++++------ + src/lstack/core/lstack_protocol_stack.c | 14 +++--- + src/lstack/core/lstack_stack_stat.c | 4 +- + 6 files changed, 60 insertions(+), 59 deletions(-) + +diff --git a/src/common/gazelle_base_func.h b/src/common/gazelle_base_func.h +index 2d629c1..be87ccd 100644 +--- a/src/common/gazelle_base_func.h ++++ b/src/common/gazelle_base_func.h +@@ -36,7 +36,8 @@ int32_t filename_check(const char* args); + + void gazelle_exit(void); + +-#undef container_of +-#define container_of(ptr, type, field) ((type *)(void*)(((char *)(ptr)) - offsetof(type, field))) ++/* Do not check if the type of ptr and type->member are the same */ ++#define container_of_uncheck_ptr(ptr, type, member) \ ++ ((type *)(void*)(((char *)(ptr)) - offsetof(type, member))) + + #endif /* ifndef __GAZELLE_BASE_FUNC_H__ */ +diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c +index 06c708b..2f48606 100644 +--- a/src/lstack/api/lstack_epoll.c ++++ b/src/lstack/api/lstack_epoll.c +@@ -49,8 +49,8 @@ static void change_epollfd_kernel_thread(struct wakeup_poll *wakeup, struct prot + + static inline void add_wakeup_to_stack_wakeuplist(struct wakeup_poll *wakeup, struct protocol_stack *stack) + { +- if (list_is_null(&wakeup->wakeup_list[stack->stack_idx])) { +- list_add_node(&stack->wakeup_list, &wakeup->wakeup_list[stack->stack_idx]); ++ if (list_node_null(&wakeup->wakeup_list[stack->stack_idx])) { ++ list_add_node(&wakeup->wakeup_list[stack->stack_idx], &stack->wakeup_list); + } + } + +@@ -73,8 +73,8 @@ void add_sock_event_nolock(struct lwip_sock *sock, uint32_t event) + } + + sock->events |= (event == EPOLLERR) ? (EPOLLIN | EPOLLERR) : (event & sock->epoll_events); +- if (list_is_null(&sock->event_list)) { +- list_add_node(&wakeup->event_list, &sock->event_list); ++ if (list_node_null(&sock->event_list)) { ++ list_add_node(&sock->event_list, &wakeup->event_list); + } + return; + } +@@ -111,7 +111,7 @@ void del_sock_event_nolock(struct lwip_sock *sock, uint32_t event) + } + + if (sock->events == 0) { +- list_del_node_null(&sock->event_list); ++ list_del_node(&sock->event_list); + } + return; + } +@@ -127,7 +127,7 @@ void wakeup_stack_epoll(struct protocol_stack *stack) + { + struct list_node *node, *temp; + +- list_for_each_safe(node, temp, &stack->wakeup_list) { ++ list_for_each_node(node, temp, &stack->wakeup_list) { + /* When temp is NULL, find the tail node in the wekeup_list and connect it to the back of the node */ + if (unlikely(temp == NULL)) { + struct list_node *nod = &stack->wakeup_list; +@@ -139,7 +139,7 @@ void wakeup_stack_epoll(struct protocol_stack *stack) + temp = nod; + } + +- struct wakeup_poll *wakeup = container_of((node - stack->stack_idx), struct wakeup_poll, wakeup_list); ++ struct wakeup_poll *wakeup = container_of_uncheck_ptr((node - stack->stack_idx), struct wakeup_poll, wakeup_list); + + if (__atomic_load_n(&wakeup->in_wait, __ATOMIC_ACQUIRE)) { + __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); +@@ -148,7 +148,7 @@ void wakeup_stack_epoll(struct protocol_stack *stack) + stack->stats.wakeup_events++; + } + +- list_del_node_null(&wakeup->wakeup_list[stack->stack_idx]); ++ list_del_node(&wakeup->wakeup_list[stack->stack_idx]); + } + } + +@@ -198,8 +198,8 @@ static void rtc_raise_pending_events(struct wakeup_poll *wakeup, struct lwip_soc + if (event) { + sock->events = event; + if (wakeup->type == WAKEUP_EPOLL && (sock->events & sock->epoll_events) && +- list_is_null(&sock->event_list)) { +- list_add_node(&wakeup->event_list, &sock->event_list); ++ list_node_null(&sock->event_list)) { ++ list_add_node(&sock->event_list, &wakeup->event_list); + } + } + } +@@ -227,8 +227,8 @@ static void raise_pending_events(struct wakeup_poll *wakeup, struct lwip_sock *s + if (event) { + sock->events = event; + if (wakeup->type == WAKEUP_EPOLL && (sock->events & sock->epoll_events) && +- list_is_null(&sock->event_list)) { +- list_add_node(&wakeup->event_list, &sock->event_list); ++ list_node_null(&sock->event_list)) { ++ list_add_node(&sock->event_list, &wakeup->event_list); + } + } + pthread_spin_unlock(&wakeup->event_list_lock); +@@ -255,7 +255,7 @@ int32_t lstack_do_epoll_create(int32_t fd) + } + + for (uint32_t i = 0; i < PROTOCOL_STACK_MAX; i++) { +- init_list_node_null(&wakeup->wakeup_list[i]); ++ list_init_node(&wakeup->wakeup_list[i]); + } + + if (sem_init(&wakeup->wait, 0, 0) != 0) { +@@ -266,12 +266,12 @@ int32_t lstack_do_epoll_create(int32_t fd) + __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); + + struct protocol_stack_group *stack_group = get_protocol_stack_group(); +- init_list_node_null(&wakeup->poll_list); ++ list_init_node(&wakeup->poll_list); + pthread_spin_lock(&stack_group->poll_list_lock); +- list_add_node(&stack_group->poll_list, &wakeup->poll_list); ++ list_add_node(&wakeup->poll_list, &stack_group->poll_list); + pthread_spin_unlock(&stack_group->poll_list_lock); + +- init_list_node(&wakeup->event_list); ++ list_init_head(&wakeup->event_list); + pthread_spin_init(&wakeup->event_list_lock, PTHREAD_PROCESS_PRIVATE); + + wakeup->type = WAKEUP_EPOLL; +@@ -327,15 +327,15 @@ int32_t lstack_epoll_close(int32_t fd) + + struct list_node *node, *temp; + pthread_spin_lock(&wakeup->event_list_lock); +- list_for_each_safe(node, temp, &wakeup->event_list) { +- struct lwip_sock *sock = container_of(node, struct lwip_sock, event_list); +- list_del_node_null(&sock->event_list); ++ list_for_each_node(node, temp, &wakeup->event_list) { ++ struct lwip_sock *sock = list_entry(node, struct lwip_sock, event_list); ++ list_del_node(&sock->event_list); + } + pthread_spin_unlock(&wakeup->event_list_lock); + pthread_spin_destroy(&wakeup->event_list_lock); + + pthread_spin_lock(&stack_group->poll_list_lock); +- list_del_node_null(&wakeup->poll_list); ++ list_del_node(&wakeup->poll_list); + pthread_spin_unlock(&stack_group->poll_list_lock); + + sem_destroy(&wakeup->wait); +@@ -413,7 +413,7 @@ int32_t lstack_rtc_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_ + break; + case EPOLL_CTL_DEL: + sock->epoll_events = 0; +- list_del_node_null(&sock->event_list); ++ list_del_node(&sock->event_list); + break; + default: + GAZELLE_RETURN(EINVAL); +@@ -464,7 +464,7 @@ int32_t lstack_rtw_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_ + sock->epoll_events = 0; + wakeup->stack_fd_cnt[sock->stack->stack_idx]--; + pthread_spin_lock(&wakeup->event_list_lock); +- list_del_node_null(&sock->event_list); ++ list_del_node(&sock->event_list); + pthread_spin_unlock(&wakeup->event_list_lock); + break; + default: +@@ -482,18 +482,18 @@ int32_t epoll_lwip_event_nolock(struct wakeup_poll *wakeup, struct epoll_event * + int32_t event_num = 0; + struct list_node *node, *temp; + +- list_for_each_safe(node, temp, &wakeup->event_list) { +- struct lwip_sock *sock = container_of(node, struct lwip_sock, event_list); ++ list_for_each_node(node, temp, &wakeup->event_list) { ++ struct lwip_sock *sock = list_entry(node, struct lwip_sock, event_list); + + if ((sock->epoll_events & sock->events) == 0) { +- list_del_node_null(node); ++ list_del_node(node); + continue; + } + + if (event_num >= maxevents) { + /* move list head after the current node, and start traversing from this node next time */ +- list_del_node_null(&wakeup->event_list); +- list_add_node(node, &wakeup->event_list); ++ list_del_node(&wakeup->event_list); ++ list_add_node(&wakeup->event_list, node); + break; + } + +@@ -502,14 +502,14 @@ int32_t epoll_lwip_event_nolock(struct wakeup_poll *wakeup, struct epoll_event * + event_num++; + + if (sock->epoll_events & EPOLLET) { +- list_del_node_null(node); ++ list_del_node(node); + sock->events = 0; + } + + /* EPOLLONESHOT: generate event after epoll_ctl add/mod event again + epoll_event set 0 avoid generating event util epoll_ctl reset epoll_event */ + if (sock->epoll_events & EPOLLONESHOT) { +- list_del_node_null(node); ++ list_del_node(node); + sock->epoll_events = 0; + } + } +@@ -654,7 +654,7 @@ int32_t lstack_rtc_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t + } + + loop_flag = false; +- if (!kernel_num && list_is_empty(&wakeup->event_list) && tmptimeout != 0) { ++ if (!kernel_num && list_head_empty(&wakeup->event_list) && tmptimeout != 0) { + loop_flag = true; + } + } while (loop_flag); +@@ -721,7 +721,7 @@ static int32_t init_poll_wakeup_data(struct wakeup_poll *wakeup) + __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); + + for (uint32_t i = 0; i < PROTOCOL_STACK_MAX; i++) { +- init_list_node_null(&wakeup->wakeup_list[i]); ++ list_init_node(&wakeup->wakeup_list[i]); + } + + wakeup->epollfd = posix_api->epoll_create_fn(POLL_KERNEL_EVENTS); +@@ -745,9 +745,9 @@ static int32_t init_poll_wakeup_data(struct wakeup_poll *wakeup) + } + + struct protocol_stack_group *stack_group = get_protocol_stack_group(); +- init_list_node_null(&wakeup->poll_list); ++ list_init_node(&wakeup->poll_list); + pthread_spin_lock(&stack_group->poll_list_lock); +- list_add_node(&stack_group->poll_list, &wakeup->poll_list); ++ list_add_node(&wakeup->poll_list, &stack_group->poll_list); + pthread_spin_unlock(&stack_group->poll_list_lock); + + int32_t stack_count[PROTOCOL_STACK_MAX] = {0}; +diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c +index 97623b3..ca0e7ec 100644 +--- a/src/lstack/api/lstack_rtc_api.c ++++ b/src/lstack/api/lstack_rtc_api.c +@@ -56,7 +56,7 @@ int rtc_socket(int domain, int type, int protocol) + sock->epoll_events = 0; + sock->events = 0; + sock->wakeup = NULL; +- init_list_node_null(&sock->event_list); ++ list_init_node(&sock->event_list); + } + return ret; + } +diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c +index f52f39f..c05a763 100644 +--- a/src/lstack/core/lstack_lwip.c ++++ b/src/lstack/core/lstack_lwip.c +@@ -173,8 +173,8 @@ int do_lwip_init_sock(int32_t fd) + + sock->stack = stack; + +- init_list_node_null(&sock->recv_list); +- init_list_node_null(&sock->event_list); ++ list_init_node(&sock->recv_list); ++ list_init_node(&sock->event_list); + return 0; + } + +@@ -187,7 +187,7 @@ void do_lwip_clean_sock(int fd) + + if (sock->wakeup && sock->wakeup->type == WAKEUP_EPOLL) { + pthread_spin_lock(&sock->wakeup->event_list_lock); +- list_del_node_null(&sock->event_list); ++ list_del_node(&sock->event_list); + pthread_spin_unlock(&sock->wakeup->event_list_lock); + } + +@@ -195,7 +195,7 @@ void do_lwip_clean_sock(int fd) + + reset_sock_data(sock); + +- list_del_node_null(&sock->recv_list); ++ list_del_node(&sock->recv_list); + } + + void do_lwip_free_pbuf(struct pbuf *pbuf) +@@ -1098,8 +1098,8 @@ void do_lwip_add_recvlist(int32_t fd) + { + struct lwip_sock *sock = lwip_get_socket(fd); + +- if (sock && sock->stack && list_is_null(&sock->recv_list)) { +- list_add_node(&sock->stack->recv_list, &sock->recv_list); ++ if (sock && sock->stack && list_node_null(&sock->recv_list)) { ++ list_add_node(&sock->recv_list, &sock->stack->recv_list); + } + } + +@@ -1109,8 +1109,8 @@ void read_same_node_recv_list(struct protocol_stack *stack) + struct list_node *node, *temp; + struct lwip_sock *sock; + +- list_for_each_safe(node, temp, list) { +- sock = container_of(node, struct lwip_sock, recv_list); ++ list_for_each_node(node, temp, list) { ++ sock = list_entry(node, struct lwip_sock, recv_list); + + if (sock->same_node_rx_ring != NULL && same_node_ring_count(sock)) { + add_sock_event(sock, EPOLLIN); +@@ -1125,18 +1125,18 @@ void do_lwip_read_recvlist(struct protocol_stack *stack, uint32_t max_num) + struct lwip_sock *sock; + uint32_t read_num = 0; + +- list_for_each_safe(node, temp, list) { +- sock = container_of(node, struct lwip_sock, recv_list); ++ list_for_each_node(node, temp, list) { ++ sock = list_entry(node, struct lwip_sock, recv_list); + + if (++read_num > max_num) { + /* list head move to next send */ + list_del_node(&stack->recv_list); +- list_add_node(&sock->recv_list, &stack->recv_list); ++ list_add_node(&stack->recv_list, &sock->recv_list); + break; + } + + if (sock->conn == NULL || sock->conn->recvmbox == NULL || rte_ring_count(sock->conn->recvmbox->ring) == 0) { +- list_del_node_null(&sock->recv_list); ++ list_del_node(&sock->recv_list); + continue; + } + +@@ -1215,7 +1215,7 @@ static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const s + conn->send_ring_cnt = (sock->send_ring == NULL) ? 0 : gazelle_ring_readover_count(sock->send_ring); + conn->events = sock->events; + conn->epoll_events = sock->epoll_events; +- conn->eventlist = !list_is_null(&sock->event_list); ++ conn->eventlist = !list_node_null(&sock->event_list); + } + } + } +@@ -1426,7 +1426,7 @@ err_t find_same_node_memzone(struct tcp_pcb *pcb, struct lwip_sock *nsock) + + /* rcvlink init in alloc_socket() */ + /* remove from g_rcv_process_list in free_socket */ +- list_add_node(&nsock->stack->same_node_recv_list, &nsock->recv_list); ++ list_add_node(&nsock->recv_list, &nsock->stack->same_node_recv_list); + return 0; + } + +diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c +index 4f5cfae..9bb1b6a 100644 +--- a/src/lstack/core/lstack_protocol_stack.c ++++ b/src/lstack/core/lstack_protocol_stack.c +@@ -328,9 +328,9 @@ static int32_t init_stack_value(struct protocol_stack *stack, void *arg) + stack->stack_idx = t_params->idx; + stack->lwip_stats = &lwip_stats; + +- init_list_node(&stack->recv_list); +- init_list_node(&stack->same_node_recv_list); +- init_list_node(&stack->wakeup_list); ++ list_init_head(&stack->recv_list); ++ list_init_head(&stack->same_node_recv_list); ++ list_init_head(&stack->wakeup_list); + + sys_calibrate_tsc(); + stack_stat_init(); +@@ -588,7 +588,7 @@ int32_t stack_group_init(void) + struct protocol_stack_group *stack_group = get_protocol_stack_group(); + stack_group->stack_num = 0; + +- init_list_node(&stack_group->poll_list); ++ list_init_head(&stack_group->poll_list); + pthread_spin_init(&stack_group->poll_list_lock, PTHREAD_PROCESS_PRIVATE); + pthread_spin_init(&stack_group->socket_lock, PTHREAD_PROCESS_PRIVATE); + if (sem_init(&stack_group->sem_stack_setup, 0, 0) < 0) { +@@ -1013,7 +1013,7 @@ void stack_clean_epoll(struct rpc_msg *msg) + struct protocol_stack *stack = get_protocol_stack(); + struct wakeup_poll *wakeup = (struct wakeup_poll *)msg->args[MSG_ARG_0].p; + +- list_del_node_null(&wakeup->wakeup_list[stack->stack_idx]); ++ list_del_node(&wakeup->wakeup_list[stack->stack_idx]); + } + + void stack_mempool_size(struct rpc_msg *msg) +@@ -1103,7 +1103,7 @@ void stack_recvlist_count(struct rpc_msg *msg) + struct list_node *node; + struct list_node *temp; + +- list_for_each_safe(node, temp, list) { ++ list_for_each_node(node, temp, list) { + count++; + } + +@@ -1258,7 +1258,7 @@ static void inline del_accept_in_event(struct lwip_sock *sock) + if (!NETCONN_IS_ACCEPTIN(sock)) { + sock->events &= ~EPOLLIN; + if (sock->events == 0) { +- list_del_node_null(&sock->event_list); ++ list_del_node(&sock->event_list); + } + } + +diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c +index e42efde..0411d9e 100644 +--- a/src/lstack/core/lstack_stack_stat.c ++++ b/src/lstack/core/lstack_stack_stat.c +@@ -230,8 +230,8 @@ static void get_wakeup_stat(struct protocol_stack_group *stack_group, struct pro + + pthread_spin_lock(&stack_group->poll_list_lock); + +- list_for_each_safe(node, temp, &stack_group->poll_list) { +- struct wakeup_poll *wakeup = container_of(node, struct wakeup_poll, poll_list); ++ list_for_each_node(node, temp, &stack_group->poll_list) { ++ struct wakeup_poll *wakeup = list_entry(node, struct wakeup_poll, poll_list); + + if (wakeup->bind_stack == stack) { + stat->kernel_events += wakeup->stat.kernel_events; +-- +2.33.0 + diff --git a/0221-fix-EPOLLIN-event-dropd.patch b/0221-fix-EPOLLIN-event-dropd.patch new file mode 100644 index 0000000000000000000000000000000000000000..87d1a34ed19f0826bcd9fb520289f26ce71380c9 --- /dev/null +++ b/0221-fix-EPOLLIN-event-dropd.patch @@ -0,0 +1,32 @@ +From 065b0fe7ac355ba741f7a2be96738c4792e13cfe Mon Sep 17 00:00:00 2001 +From: compile_success <980965867@qq.com> +Date: Thu, 18 Jul 2024 11:59:52 +0000 +Subject: [PATCH] fix EPOLLIN event dropd + +--- + src/lstack/api/lstack_epoll.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c +index 06c708b..ff80003 100644 +--- a/src/lstack/api/lstack_epoll.c ++++ b/src/lstack/api/lstack_epoll.c +@@ -208,6 +208,7 @@ static void raise_pending_events(struct wakeup_poll *wakeup, struct lwip_sock *s + { + uint32_t event = 0; + ++ pthread_spin_lock(&wakeup->event_list_lock); + if (NETCONN_IS_DATAIN(sock) || NETCONN_IS_ACCEPTIN(sock)) { + event |= EPOLLIN; + } +@@ -216,7 +217,6 @@ static void raise_pending_events(struct wakeup_poll *wakeup, struct lwip_sock *s + event |= EPOLLERR | EPOLLIN; + } + +- pthread_spin_lock(&wakeup->event_list_lock); + if (NETCONN_IS_OUTIDLE(sock)) { + /* lwip_netconn_do_connected set LIBOS FLAGS when connected */ + if (!POSIX_IS_CLOSED(sock) && POSIX_IS_TYPE(sock, POSIX_LWIP)) { +-- +2.33.0 + diff --git a/0222-cleancode-refactor-lwipgz_hlist.h.patch b/0222-cleancode-refactor-lwipgz_hlist.h.patch new file mode 100644 index 0000000000000000000000000000000000000000..9bd4e81918da9f692146dd14e5a687d42d181c2c --- /dev/null +++ b/0222-cleancode-refactor-lwipgz_hlist.h.patch @@ -0,0 +1,160 @@ +From 288f7301ecafb2c53ab4671361109803af118668 Mon Sep 17 00:00:00 2001 +From: Lemmy Huang +Date: Thu, 11 Jul 2024 16:04:00 +0800 +Subject: [PATCH] cleancode: refactor lwipgz_hlist.h + + Changed: + INIT_HLIST_HEAD -> hlist_init_head + INIT_HLIST_NODE -> hlist_init_node + hlist_empty -> hlist_head_empty + hlist_unhashed -> hlist_node_null + hlist_del_init -> hlist_del_node + Not changed: + hlist_add_head + hlist_add_before + hlist_add_after + Deprecated: + INIT_HLIST_CTRL + hlist_ctl_del + hlist_pop_tail + hlist_pop_head + hlist_ctl_add_tail + hlist_ctl_add_head + hlist_ctl_add_after + hlist_ctl_add_before + +Signed-off-by: Lemmy Huang +--- + src/ltran/ltran_stack.c | 6 +++--- + src/ltran/ltran_tcp_conn.c | 6 +++--- + src/ltran/ltran_tcp_sock.c | 6 +++--- + src/ltran/ltran_timer.c | 6 +++--- + 4 files changed, 12 insertions(+), 12 deletions(-) + +diff --git a/src/ltran/ltran_stack.c b/src/ltran/ltran_stack.c +index 299fb7a..737d883 100644 +--- a/src/ltran/ltran_stack.c ++++ b/src/ltran/ltran_stack.c +@@ -43,7 +43,7 @@ struct gazelle_stack_htable *gazelle_stack_htable_create(uint32_t max_stack_num) + } + + for (i = 0; i < GAZELLE_MAX_STACK_HTABLE_SIZE; i++) { +- INIT_HLIST_HEAD(&stack_htable->array[i].chain); ++ hlist_init_head(&stack_htable->array[i].chain); + stack_htable->array[i].chain_size = 0; + } + stack_htable->cur_stack_num = 0; +@@ -68,7 +68,7 @@ void gazelle_stack_htable_destroy(void) + while (node != NULL) { + stack = hlist_entry(node, typeof(*stack), stack_node); + node = node->next; +- hlist_del_init(&stack->stack_node); ++ hlist_del_node(&stack->stack_node); + free(stack); + } + } +@@ -181,7 +181,7 @@ void gazelle_stack_del_by_tid(struct gazelle_stack_htable *stack_htable, uint32_ + } + } + +- hlist_del_init(&stack->stack_node); ++ hlist_del_node(&stack->stack_node); + stack_htable->cur_stack_num--; + stack_hbucket->chain_size--; + +diff --git a/src/ltran/ltran_tcp_conn.c b/src/ltran/ltran_tcp_conn.c +index 026d22a..2c8f8ef 100644 +--- a/src/ltran/ltran_tcp_conn.c ++++ b/src/ltran/ltran_tcp_conn.c +@@ -40,7 +40,7 @@ struct gazelle_tcp_conn_htable *gazelle_tcp_conn_htable_create(uint32_t max_conn + } + + for (i = 0; i < GAZELLE_MAX_CONN_HTABLE_SIZE; i++) { +- INIT_HLIST_HEAD(&conn_htable->array[i].chain); ++ hlist_init_head(&conn_htable->array[i].chain); + conn_htable->array[i].chain_size = 0; + } + conn_htable->cur_conn_num = 0; +@@ -65,7 +65,7 @@ void gazelle_tcp_conn_htable_destroy(void) + while (node != NULL) { + conn = hlist_entry(node, typeof(*conn), conn_node); + node = node->next; +- hlist_del_init(&conn->conn_node); ++ hlist_del_node(&conn->conn_node); + rte_free(conn); + } + } +@@ -175,7 +175,7 @@ void gazelle_conn_del_by_quintuple(struct gazelle_tcp_conn_htable *conn_htable, + return; + } + +- hlist_del_init(&conn->conn_node); ++ hlist_del_node(&conn->conn_node); + rte_free(conn); + conn_htable->cur_conn_num--; + conn_hbucket->chain_size--; +diff --git a/src/ltran/ltran_tcp_sock.c b/src/ltran/ltran_tcp_sock.c +index eef2821..1e06bd7 100644 +--- a/src/ltran/ltran_tcp_sock.c ++++ b/src/ltran/ltran_tcp_sock.c +@@ -51,7 +51,7 @@ struct gazelle_tcp_sock_htable *gazelle_tcp_sock_htable_create(uint32_t max_tcp_ + } + + for (i = 0; i < GAZELLE_MAX_TCP_SOCK_HTABLE_SIZE; i++) { +- INIT_HLIST_HEAD(&tcp_sock_htable->array[i].chain); ++ hlist_init_head(&tcp_sock_htable->array[i].chain); + tcp_sock_htable->array[i].chain_size = 0; + } + tcp_sock_htable->cur_tcp_sock_num = 0; +@@ -77,7 +77,7 @@ void gazelle_tcp_sock_htable_destroy(void) + while (node != NULL) { + tcp_sock = hlist_entry(node, typeof(*tcp_sock), tcp_sock_node); + node = node->next; +- hlist_del_init(&tcp_sock->tcp_sock_node); ++ hlist_del_node(&tcp_sock->tcp_sock_node); + free(tcp_sock); + } + } +@@ -186,7 +186,7 @@ void gazelle_sock_del_by_ipporttid(struct gazelle_tcp_sock_htable *tcp_sock_htab + return; + } + +- hlist_del_init(&tcp_sock->tcp_sock_node); ++ hlist_del_node(&tcp_sock->tcp_sock_node); + free(tcp_sock); + tcp_sock_htable->cur_tcp_sock_num--; + tcp_sock_hbucket->chain_size--; +diff --git a/src/ltran/ltran_timer.c b/src/ltran/ltran_timer.c +index 87046cb..51d6544 100644 +--- a/src/ltran/ltran_timer.c ++++ b/src/ltran/ltran_timer.c +@@ -63,7 +63,7 @@ void gazelle_detect_sock_logout(struct gazelle_tcp_sock_htable *tcp_sock_htable) + tcp_sock = hlist_entry(node, typeof(*tcp_sock), tcp_sock_node); + node = node->next; + if (!INSTANCE_IS_ON(tcp_sock)) { +- hlist_del_init(&tcp_sock->tcp_sock_node); ++ hlist_del_node(&tcp_sock->tcp_sock_node); + tcp_sock_htable->cur_tcp_sock_num--; + tcp_sock_htable->array[i].chain_size--; + LTRAN_DEBUG("delete the tcp sock htable: tid %u ip %u port %u\n", +@@ -99,7 +99,7 @@ void gazelle_detect_conn_logout(struct gazelle_tcp_conn_htable *conn_htable) + conn = hlist_entry(node, typeof(*conn), conn_node); + node = node->next; + if (!INSTANCE_IS_ON(conn)) { +- hlist_del_init(&conn->conn_node); ++ hlist_del_node(&conn->conn_node); + conn_htable->cur_conn_num--; + conn_htable->array[i].chain_size--; + LTRAN_DEBUG("delete the tcp conn htable: tid %u quintuple[%u %u %u %u %u]\n", +@@ -146,7 +146,7 @@ void gazelle_delete_aging_conn(struct gazelle_tcp_conn_htable *conn_htable) + continue; + } + +- hlist_del_init(&conn->conn_node); ++ hlist_del_node(&conn->conn_node); + conn_htable->cur_conn_num--; + conn_htable->array[i].chain_size--; + if (conn->sock) { +-- +2.33.0 + diff --git a/0223-add-sem-post-when-update-event.patch b/0223-add-sem-post-when-update-event.patch new file mode 100644 index 0000000000000000000000000000000000000000..45a1a1c465c85218739e86a6eee55b1999814734 --- /dev/null +++ b/0223-add-sem-post-when-update-event.patch @@ -0,0 +1,24 @@ +From 2ad0be3590c8ac380c2b0e87f28653b994916c65 Mon Sep 17 00:00:00 2001 +From: compile_success <980965867@qq.com> +Date: Thu, 18 Jul 2024 13:40:15 +0000 +Subject: [PATCH] add sem post when update event + +--- + src/lstack/api/lstack_epoll.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c +index e92faac..417499b 100644 +--- a/src/lstack/api/lstack_epoll.c ++++ b/src/lstack/api/lstack_epoll.c +@@ -229,6 +229,7 @@ static void raise_pending_events(struct wakeup_poll *wakeup, struct lwip_sock *s + if (wakeup->type == WAKEUP_EPOLL && (sock->events & sock->epoll_events) && + list_node_null(&sock->event_list)) { + list_add_node(&sock->event_list, &wakeup->event_list); ++ sem_post(&wakeup->wait); + } + } + pthread_spin_unlock(&wakeup->event_list_lock); +-- +2.33.0 + diff --git a/0224-cleancode-refactor-sys_now-and-lwip_ioctl.patch b/0224-cleancode-refactor-sys_now-and-lwip_ioctl.patch new file mode 100644 index 0000000000000000000000000000000000000000..369aba087669a53c42210690cec170de260261a5 --- /dev/null +++ b/0224-cleancode-refactor-sys_now-and-lwip_ioctl.patch @@ -0,0 +1,673 @@ +From 107e0eda4e255dc93aa94a9ffa31427f912341f5 Mon Sep 17 00:00:00 2001 +From: Lemmy Huang +Date: Fri, 12 Jul 2024 11:02:59 +0800 +Subject: [PATCH] cleancode: refactor sys_now and lwip_ioctl + +Signed-off-by: Lemmy Huang +--- + src/common/gazelle_dfx_msg.h | 8 ++++- + src/lstack/api/lstack_epoll.c | 4 ++- + src/lstack/api/lstack_wrap.c | 47 +++++++++++-------------- + src/lstack/core/lstack_cfg.c | 1 - + src/lstack/core/lstack_control_plane.c | 21 ++++++----- + src/lstack/core/lstack_dpdk.c | 10 +++--- + src/lstack/core/lstack_init.c | 2 -- + src/lstack/core/lstack_lwip.c | 19 +++++----- + src/lstack/core/lstack_protocol_stack.c | 12 +++---- + src/lstack/core/lstack_stack_stat.c | 29 +++------------ + src/lstack/include/lstack_stack_stat.h | 1 - + src/lstack/include/lstack_thread_rpc.h | 1 - + src/lstack/netif/lstack_ethdev.c | 3 +- + src/ltran/ltran_forward.c | 10 +++--- + src/ltran/ltran_stat.c | 2 +- + src/ltran/ltran_stat.h | 6 ---- + src/ltran/ltran_timer.c | 14 +++----- + src/ltran/ltran_timer.h | 4 +-- + test/unitest/stub.c | 6 ---- + 19 files changed, 79 insertions(+), 121 deletions(-) + +diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h +index a2ec07b..8eb54ff 100644 +--- a/src/common/gazelle_dfx_msg.h ++++ b/src/common/gazelle_dfx_msg.h +@@ -87,6 +87,12 @@ enum GAZELLE_LATENCY_TYPE { + GAZELLE_LATENCY_MAX, + }; + ++enum GAZELLE_TCP_LIST_STATE { ++ GAZELLE_ACTIVE_LIST, ++ GAZELLE_LISTEN_LIST, ++ GAZELLE_TIME_WAIT_LIST, ++}; ++ + struct gazelle_stack_stat { + uint64_t wakeup_events; + uint64_t write_lwip_cnt; +@@ -240,7 +246,6 @@ struct gazelle_stat_lstack_proto { + }; + + +-/* same as define in lwip/tcp.h - struct tcp_pcb_dp */ + struct gazelle_stat_lstack_conn_info { + uint32_t state; + gz_addr_t rip; +@@ -252,6 +257,7 @@ struct gazelle_stat_lstack_conn_info { + uint32_t send_ring_cnt; + uint32_t recv_ring_cnt; + uint32_t tcp_sub_state; ++ + uint32_t cwn; + uint32_t rcv_wnd; + uint32_t snd_wnd; +diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c +index 2f48606..3ad22b9 100644 +--- a/src/lstack/api/lstack_epoll.c ++++ b/src/lstack/api/lstack_epoll.c +@@ -650,7 +650,9 @@ int32_t lstack_rtc_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t + } + } + if (tmptimeout > 0) { +- tmptimeout = update_timeout(tmptimeout, poll_ts); ++ if (tmptimeout <= sys_now() - poll_ts) { ++ tmptimeout = 0; ++ } + } + + loop_flag = false; +diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c +index b19990e..976a3f3 100644 +--- a/src/lstack/api/lstack_wrap.c ++++ b/src/lstack/api/lstack_wrap.c +@@ -647,36 +647,31 @@ static int32_t do_select(int32_t nfds, fd_set *readfds, fd_set *writefds, fd_set + return g_wrap_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); + } + +-#define WRAP_VA_PARAM(_fd, _cmd, _lwip_fcntl, _fcntl_fn) \ ++#define POSIX_VA_PARAM(fd, cmd, type, lwip_fn, kernel_fn) \ + do { \ +- unsigned long val; \ +- va_list ap; \ +- va_start(ap, _cmd); \ +- val = va_arg(ap, typeof(val)); \ +- va_end(ap); \ +- struct lwip_sock *sock = lwip_get_socket(_fd); \ +- if (select_posix_path() == POSIX_KERNEL || \ +- select_sock_posix_path(sock) == POSIX_KERNEL) \ +- return _fcntl_fn(_fd, _cmd, val); \ +- int32_t ret1 = _fcntl_fn(_fd, _cmd, val); \ +- if (ret1 == -1) { \ +- LSTACK_LOG(ERR, LSTACK, "fd(%d) kernel path call failed, errno is %d, maybe not error\n", \ +- _fd, errno); \ +- return ret1; \ ++ unsigned long __val; \ ++ va_list __ap; \ ++ va_start(__ap, cmd); \ ++ __val = va_arg(__ap, typeof(__val)); \ ++ va_end(__ap); \ ++ /* always try kernel */ \ ++ int __ret1 = kernel_fn(fd, cmd, __val); \ ++ if (__ret1 == -1 || select_sock_posix_path(lwip_get_socket(fd)) == POSIX_KERNEL) { \ ++ return __ret1; \ + } \ +- int32_t ret2 = _lwip_fcntl(_fd, _cmd, val); \ ++ int __ret2 = lwip_fn(fd, cmd, (type)__val); \ + /* + * if function not implemented, fcntl get/set context will not be modifyed by user path, + * return kernel path result + */ \ +- if (ret2 == -1) { \ ++ if (__ret2 == -1) { \ + if (errno == ENOSYS) { \ +- return ret1; \ ++ return __ret1; \ + } \ + LSTACK_LOG(ERR, LSTACK, "fd(%d) user path call failed, errno is %d, maybe not error\n", \ +- _fd, errno); \ ++ fd, errno); \ + } \ +- return ret2; \ ++ return __ret2; \ + } while (0) + + /* -------------------------------------------------------- +@@ -701,15 +696,15 @@ int32_t epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxevents, + } + int32_t fcntl64(int32_t s, int32_t cmd, ...) + { +- WRAP_VA_PARAM(s, cmd, lwip_fcntl, posix_api->fcntl64_fn); ++ POSIX_VA_PARAM(s, cmd, int, lwip_fcntl, posix_api->fcntl64_fn); + } + int32_t fcntl(int32_t s, int32_t cmd, ...) + { +- WRAP_VA_PARAM(s, cmd, lwip_fcntl, posix_api->fcntl_fn); ++ POSIX_VA_PARAM(s, cmd, int, lwip_fcntl, posix_api->fcntl_fn); + } + int32_t ioctl(int32_t s, int32_t cmd, ...) + { +- WRAP_VA_PARAM(s, cmd, lwip_ioctl, posix_api->ioctl_fn); ++ POSIX_VA_PARAM(s, cmd, void*, lwip_ioctl, posix_api->ioctl_fn); + } + int32_t accept(int32_t s, struct sockaddr *addr, socklen_t *addrlen) + { +@@ -853,15 +848,15 @@ int32_t __wrap_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxe + } + int32_t __wrap_fcntl64(int32_t s, int32_t cmd, ...) + { +- WRAP_VA_PARAM(s, cmd, lwip_fcntl, posix_api->fcntl64_fn); ++ POSIX_VA_PARAM(s, cmd, int, lwip_fcntl, posix_api->fcntl64_fn); + } + int32_t __wrap_fcntl(int32_t s, int32_t cmd, ...) + { +- WRAP_VA_PARAM(s, cmd, lwip_fcntl, posix_api->fcntl_fn); ++ POSIX_VA_PARAM(s, cmd, int, lwip_fcntl, posix_api->fcntl_fn); + } + int32_t __wrap_ioctl(int32_t s, int32_t cmd, ...) + { +- WRAP_VA_PARAM(s, cmd, lwip_ioctl, posix_api->ioctl_fn); ++ POSIX_VA_PARAM(s, cmd, void*, lwip_ioctl, posix_api->ioctl_fn); + } + + int32_t __wrap_accept(int32_t s, struct sockaddr *addr, socklen_t *addrlen) +diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c +index a1f6c2f..cd81edb 100644 +--- a/src/lstack/core/lstack_cfg.c ++++ b/src/lstack/core/lstack_cfg.c +@@ -25,7 +25,6 @@ + + #include + #include +-#include + #include + + #include "common/gazelle_reg_msg.h" +diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c +index f1e3064..11f5129 100644 +--- a/src/lstack/core/lstack_control_plane.c ++++ b/src/lstack/core/lstack_control_plane.c +@@ -18,11 +18,14 @@ + #include + #include + +-#include + #include + #include ++#include ++ ++#include + #include + #include ++#include + + #include "lstack_cfg.h" + #include "lstack_dpdk.h" +@@ -353,7 +356,7 @@ static int32_t client_reg_proc_attach(__attribute__((__unused__)) bool is_reconn + return 0; + } + +-static int32_t reg_conn(enum tcp_list_state table_state, enum reg_ring_type reg_type, ++static int32_t reg_conn(enum GAZELLE_TCP_LIST_STATE table_state, enum reg_ring_type reg_type, + const struct gazelle_stat_lstack_conn *conn) + { + struct gazelle_quintuple qtuple; +@@ -370,7 +373,7 @@ static int32_t reg_conn(enum tcp_list_state table_state, enum reg_ring_type reg_ + qtuple.dst_ip = conn->conn_list[i].rip; + qtuple.dst_port = lwip_htons(conn->conn_list[i].r_port); + +- if ((table_state == LISTEN_LIST) && (!match_host_addr((ip_addr_t *)&qtuple.src_ip))) { ++ if ((table_state == GAZELLE_LISTEN_LIST) && (!match_host_addr((ip_addr_t *)&qtuple.src_ip))) { + continue; + } + +@@ -398,16 +401,16 @@ void thread_register_phase1(struct rpc_msg *msg) + } + + struct gazelle_stat_lstack_conn *conn = (struct gazelle_stat_lstack_conn *)msg->args[MSG_ARG_0].p; +- ret = reg_conn(ACTIVE_LIST, REG_RING_TCP_CONNECT, conn); ++ ret = reg_conn(GAZELLE_ACTIVE_LIST, REG_RING_TCP_CONNECT, conn); + if (ret != 0) { +- LSTACK_LOG(ERR, LSTACK, "ACTIVE_LIST rereg conn fail ret=%d\n", ret); ++ LSTACK_LOG(ERR, LSTACK, "GAZELLE_ACTIVE_LIST rereg conn fail ret=%d\n", ret); + msg->result = ret; + return; + } + +- ret = reg_conn(TIME_WAIT_LIST, REG_RING_TCP_CONNECT, conn); ++ ret = reg_conn(GAZELLE_TIME_WAIT_LIST, REG_RING_TCP_CONNECT, conn); + if (ret != 0) { +- LSTACK_LOG(ERR, LSTACK, "TIME_WAIT_LIST rereg conn fail ret=%d\n", ret); ++ LSTACK_LOG(ERR, LSTACK, "GAZELLE_TIME_WAIT_LIST rereg conn fail ret=%d\n", ret); + } + msg->result = ret; + } +@@ -416,9 +419,9 @@ void thread_register_phase2(struct rpc_msg *msg) + { + struct gazelle_stat_lstack_conn *conn = (struct gazelle_stat_lstack_conn *)msg->args[MSG_ARG_0].p; + +- int32_t ret = reg_conn(LISTEN_LIST, REG_RING_TCP_LISTEN, conn); ++ int32_t ret = reg_conn(GAZELLE_LISTEN_LIST, REG_RING_TCP_LISTEN, conn); + if (ret != 0) { +- LSTACK_LOG(ERR, LSTACK, "LISTEN_LIST rereg conn fail ret=%d\n", ret); ++ LSTACK_LOG(ERR, LSTACK, "GAZELLE_LISTEN_LIST rereg conn fail ret=%d\n", ret); + } + + msg->result = ret; +diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c +index a095cbd..e17242c 100644 +--- a/src/lstack/core/lstack_dpdk.c ++++ b/src/lstack/core/lstack_dpdk.c +@@ -32,16 +32,14 @@ + #endif + #include + #include +-#include +-#include +-#include +-#include +-#include +- + #include + #include + #include + ++#include ++#include ++#include ++ + #include "lstack_log.h" + #include "common/dpdk_common.h" + #include "lstack_protocol_stack.h" +diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c +index 54ee97e..e89e19c 100644 +--- a/src/lstack/core/lstack_init.c ++++ b/src/lstack/core/lstack_init.c +@@ -29,8 +29,6 @@ + #include + #include + #include +-#include +-#include + #include + #include + +diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c +index c05a763..271e94f 100644 +--- a/src/lstack/core/lstack_lwip.c ++++ b/src/lstack/core/lstack_lwip.c +@@ -12,20 +12,21 @@ + + #include + #include ++#include ++ ++#include ++#include ++ + #include + #include + #include + #include +-#include + #include + #include + #include + #include + #include + #include +-#include +-#include +-#include + + #include "common/gazelle_base_func.h" + #include "lstack_ethdev.h" +@@ -355,7 +356,7 @@ static inline ssize_t app_buff_write(struct lwip_sock *sock, void *buf, size_t l + (void)gazelle_ring_read(sock->send_ring, (void **)pbufs, write_num); + + if (get_protocol_stack_group()->latency_start) { +- uint64_t time_stamp = get_current_time(); ++ uint64_t time_stamp = sys_now_us(); + time_stamp_into_pbuf(write_num, pbufs, time_stamp); + } + +@@ -912,7 +913,7 @@ static bool recv_break_for_err(struct lwip_sock *sock) + static int recv_ring_get_one(struct lwip_sock *sock, bool noblock, struct pbuf **pbuf) + { + int32_t expect = 1; // only get one pbuf +- uint64_t time_stamp = get_current_time(); ++ uint64_t time_stamp = sys_now_us(); + + if (sock->recv_lastdata != NULL) { + *pbuf = sock->recv_lastdata; +@@ -1250,20 +1251,20 @@ uint32_t do_lwip_get_conntable(struct gazelle_stat_lstack_conn_info *conn, + } + + for (pcb = tcp_active_pcbs; pcb != NULL && conn_num < max_num; pcb = pcb->next) { +- conn[conn_num].state = ACTIVE_LIST; ++ conn[conn_num].state = GAZELLE_ACTIVE_LIST; + copy_pcb_to_conn(conn + conn_num, pcb); + conn_num++; + } + + for (pcb = tcp_tw_pcbs; pcb != NULL && conn_num < max_num; pcb = pcb->next) { +- conn[conn_num].state = TIME_WAIT_LIST; ++ conn[conn_num].state = GAZELLE_TIME_WAIT_LIST; + copy_pcb_to_conn(conn + conn_num, pcb); + conn_num++; + } + + for (struct tcp_pcb_listen *pcbl = tcp_listen_pcbs.listen_pcbs; pcbl != NULL && conn_num < max_num; + pcbl = pcbl->next) { +- conn[conn_num].state = LISTEN_LIST; ++ conn[conn_num].state = GAZELLE_LISTEN_LIST; + conn[conn_num].lip = *((gz_addr_t *)&pcbl->local_ip); + conn[conn_num].l_port = pcbl->local_port; + conn[conn_num].tcp_sub_state = pcbl->state; +diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c +index 9bb1b6a..6f2e84e 100644 +--- a/src/lstack/core/lstack_protocol_stack.c ++++ b/src/lstack/core/lstack_protocol_stack.c +@@ -12,15 +12,14 @@ + + #include + #include ++#include ++#include + + #include +-#include ++#include + #include +-#include + #include + #include +-#include +-#include + + #include "common/gazelle_base_func.h" + #include "lstack_thread_rpc.h" +@@ -332,9 +331,6 @@ static int32_t init_stack_value(struct protocol_stack *stack, void *arg) + list_init_head(&stack->same_node_recv_list); + list_init_head(&stack->wakeup_list); + +- sys_calibrate_tsc(); +- stack_stat_init(); +- + stack_group->stacks[t_params->idx] = stack; + set_stack_idx(t_params->idx); + +@@ -424,7 +420,7 @@ static struct protocol_stack *stack_thread_init(void *arg) + } + RTE_PER_LCORE(_lcore_id) = stack->cpu_id; + +- tcpip_init(NULL, NULL); ++ lwip_init(); + + if (use_ltran()) { + if (client_reg_thrd_ring() != 0) { +diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c +index 0411d9e..91ca49a 100644 +--- a/src/lstack/core/lstack_stack_stat.c ++++ b/src/lstack/core/lstack_stack_stat.c +@@ -31,25 +31,6 @@ + #include "lstack_stack_stat.h" + #include "lstack_virtio.h" + +-#define US_PER_SEC 1000000 +- +-static uint64_t g_cycles_per_us; +- +-void stack_stat_init(void) +-{ +- uint64_t freq = rte_get_tsc_hz(); +- g_cycles_per_us = (freq + US_PER_SEC - 1) / US_PER_SEC; +-} +- +-uint64_t get_current_time(void) +-{ +- if (g_cycles_per_us == 0) { +- return 0; +- } +- +- return (rte_rdtsc() / g_cycles_per_us); +-} +- + void time_stamp_transfer_pbuf(struct pbuf *pbuf_old, struct pbuf *pbuf_new) + { + if (!get_protocol_stack_group()->latency_start) { +@@ -71,12 +52,12 @@ void time_stamp_transfer_pbuf(struct pbuf *pbuf_old, struct pbuf *pbuf_new) + + void time_stamp_into_rpcmsg(struct lwip_sock *sock) + { +- sock->stamp.rpc_time_stamp = get_current_time(); ++ sock->stamp.rpc_time_stamp = sys_now_us(); + } + + void time_stamp_into_recvmbox(struct lwip_sock *sock) + { +- sock->stamp.mbox_time_stamp = get_current_time(); ++ sock->stamp.mbox_time_stamp = sys_now_us(); + } + + void time_stamp_record(int fd, struct pbuf *pbuf) +@@ -108,7 +89,7 @@ void calculate_sock_latency(struct gazelle_stack_latency *stack_latency, struct + return; + } + +- latency = get_current_time() - stamp; ++ latency = sys_now_us() - stamp; + latency_stat = &stack_latency->latency[type]; + + latency_stat->latency_total += latency; +@@ -147,7 +128,7 @@ void calculate_lstack_latency(struct gazelle_stack_latency *stack_latency, const + } + + if (time_record == 0) { +- lt->stamp_seg[type] = get_current_time() - lt->stamp; ++ lt->stamp_seg[type] = sys_now_us() - lt->stamp; + } else { + lt->stamp_seg[type] = time_record > (lt->stamp_seg[type - 1] + lt->stamp) ? + (time_record - lt->stamp) : lt->stamp_seg[type - 1]; +@@ -212,7 +193,7 @@ static void set_latency_start_flag(bool start) + if (ret != 0) { + LSTACK_LOG(ERR, LSTACK, "memset_s faile\n"); + } +- stack->latency.start_time = get_current_time(); ++ stack->latency.start_time = sys_now_us(); + + for (uint32_t j = 0; j < GAZELLE_LATENCY_MAX; j++) { + stack->latency.latency[j].latency_min = ~((uint64_t)0); +diff --git a/src/lstack/include/lstack_stack_stat.h b/src/lstack/include/lstack_stack_stat.h +index 9fca04a..ef33365 100644 +--- a/src/lstack/include/lstack_stack_stat.h ++++ b/src/lstack/include/lstack_stack_stat.h +@@ -31,7 +31,6 @@ void calculate_sock_latency(struct gazelle_stack_latency *stack_latency, struct + void stack_stat_init(void); + int handle_stack_cmd(int fd, struct gazelle_stat_msg_request *msg); + int handle_dpdk_cmd(int fd, enum GAZELLE_STAT_MODE stat_mode); +-uint64_t get_current_time(void); + void lstack_get_low_power_info(struct gazelle_stat_low_power_info *low_power_info); + void unregister_wakeup(struct protocol_stack *stack, struct wakeup_poll *wakeup); + void lstack_calculate_aggregate(int type, uint32_t len); +diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h +index fa98b0c..d268366 100644 +--- a/src/lstack/include/lstack_thread_rpc.h ++++ b/src/lstack/include/lstack_thread_rpc.h +@@ -14,7 +14,6 @@ + #define __GAZELLE_THREAD_RPC_H__ + + #include +-#include + #include + + #include "lstack_lockless_queue.h" +diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c +index d4d0878..cf66e15 100644 +--- a/src/lstack/netif/lstack_ethdev.c ++++ b/src/lstack/netif/lstack_ethdev.c +@@ -21,6 +21,7 @@ + #include + #include + #include ++#include + + #include + +@@ -181,7 +182,7 @@ int32_t eth_dev_poll(void) + } + + if (!use_ltran() && get_protocol_stack_group()->latency_start) { +- uint64_t time_stamp = get_current_time(); ++ uint64_t time_stamp = sys_now_us(); + time_stamp_into_mbuf(nr_pkts, stack->pkts, time_stamp); + } + +diff --git a/src/ltran/ltran_forward.c b/src/ltran/ltran_forward.c +index c2f53d6..0de9c1c 100644 +--- a/src/ltran/ltran_forward.c ++++ b/src/ltran/ltran_forward.c +@@ -24,7 +24,6 @@ + #include + #include + #include +-#include + #include + #include + +@@ -70,7 +69,7 @@ static void calculate_ltran_latency(struct gazelle_stack *stack, const struct rt + return; + } + +- latency = get_current_time() - lt->stamp; ++ latency = gazelle_now_us() - lt->stamp; + + stack->stack_stats.latency_total += latency; + stack->stack_stats.latency_pkts++; +@@ -595,7 +594,7 @@ static __rte_always_inline void upstream_forward_loop(uint32_t port_id, uint32_t + struct rte_mbuf *buf[GAZELLE_PACKET_READ_SIZE] __rte_cache_aligned; + for (loop_cnt = 0; loop_cnt < UPSTREAM_LOOP_TIMES; loop_cnt++) { + if (get_start_latency_flag() == GAZELLE_ON) { +- time_stamp = get_current_time(); ++ time_stamp = gazelle_now_us(); + } + + rx_count = rte_eth_rx_burst(port_id, queue_id, buf, GAZELLE_PACKET_READ_SIZE); +@@ -657,9 +656,8 @@ void upstream_forward(const uint16_t *port) + uint32_t queue_num = get_ltran_config()->bond.rx_queue_num; + uint32_t port_id = get_bond_port()[g_port_index]; + unsigned long now_time; +- unsigned long last_time = get_current_time(); ++ unsigned long last_time = gazelle_now_us(); + unsigned long aging_conn_last_time = last_time; +- calibrate_time(); + + while (get_ltran_stop_flag() != GAZELLE_TRUE) { + for (queue_id = 0; queue_id < queue_num; queue_id++) { +@@ -673,7 +671,7 @@ void upstream_forward(const uint16_t *port) + } + #endif + +- now_time = get_current_time(); ++ now_time = gazelle_now_us(); + if (now_time - aging_conn_last_time > GAZELLE_CONN_INTERVAL) { + gazelle_delete_aging_conn(gazelle_get_tcp_conn_htable()); + aging_conn_last_time = now_time; +diff --git a/src/ltran/ltran_stat.c b/src/ltran/ltran_stat.c +index 0a8d75c..72de448 100644 +--- a/src/ltran/ltran_stat.c ++++ b/src/ltran/ltran_stat.c +@@ -75,7 +75,7 @@ void set_start_latency_flag(int32_t flag) + } + + g_start_latency = flag; +- g_start_time_stamp = get_current_time(); ++ g_start_time_stamp = gazelle_now_us(); + } + + int32_t get_start_latency_flag(void) +diff --git a/src/ltran/ltran_stat.h b/src/ltran/ltran_stat.h +index 75cb353..7945d67 100644 +--- a/src/ltran/ltran_stat.h ++++ b/src/ltran/ltran_stat.h +@@ -36,12 +36,6 @@ enum GAZELLE_CLIENT_STATE { + GAZELLE_CLIENT_STATE_MAX + }; + +-enum GAZELLE_TCP_LIST_STATE { +- GAZELLE_ACTIVE_LIST, +- GAZELLE_LISTEN_LIST, +- GAZELLE_TIME_WAIT_LIST, +-}; +- + enum GAZELLE_TCP_STATE { + GAZELLE_TCP_STATE_CLS, + GAZELLE_TCP_STATE_LSN, +diff --git a/src/ltran/ltran_timer.c b/src/ltran/ltran_timer.c +index 51d6544..f1c0e6e 100644 +--- a/src/ltran/ltran_timer.c ++++ b/src/ltran/ltran_timer.c +@@ -26,22 +26,16 @@ + #include "ltran_instance.h" + #include "ltran_timer.h" + +-static uint64_t g_cycles_per_us = 0; +- +-uint64_t get_current_time(void) ++uint64_t gazelle_now_us(void) + { +- if (g_cycles_per_us == 0) { +- return 0; ++ static uint64_t g_cycles_per_us = 0; ++ if (unlikely(g_cycles_per_us == 0)) { ++ g_cycles_per_us = (rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S; + } + + return (rte_rdtsc() / g_cycles_per_us); + } + +-void calibrate_time(void) +-{ +- g_cycles_per_us = (rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S; +-} +- + void gazelle_detect_sock_logout(struct gazelle_tcp_sock_htable *tcp_sock_htable) + { + uint32_t i; +diff --git a/src/ltran/ltran_timer.h b/src/ltran/ltran_timer.h +index abc08b9..6c7aeef 100644 +--- a/src/ltran/ltran_timer.h ++++ b/src/ltran/ltran_timer.h +@@ -13,11 +13,11 @@ + #ifndef __GAZELLE_TIMER_H__ + #define __GAZELLE_TIMER_H__ + ++uint64_t gazelle_now_us(void); ++ + struct gazelle_tcp_conn_htable; + struct gazelle_tcp_sock_htable; + +-unsigned long get_current_time(void); +-void calibrate_time(void); + void gazelle_detect_conn_logout(struct gazelle_tcp_conn_htable *conn_htable); + void gazelle_detect_sock_logout(struct gazelle_tcp_sock_htable *tcp_sock_htable); + void gazelle_delete_aging_conn(struct gazelle_tcp_conn_htable *conn_htable); +diff --git a/test/unitest/stub.c b/test/unitest/stub.c +index 8f37c90..8478b50 100644 +--- a/test/unitest/stub.c ++++ b/test/unitest/stub.c +@@ -10,14 +10,8 @@ + * See the Mulan PSL v2 for more details. + */ + +-#include + #include + +-uint64_t get_current_time(void) +-{ +- return 0; +-} +- + int rte_pdump_init(void) + { + return 0; +-- +2.33.0 + diff --git a/0225-temp-fix-select-disability.patch b/0225-temp-fix-select-disability.patch new file mode 100644 index 0000000000000000000000000000000000000000..a607a232bc16e5677bb3ce080b0dd679c09ccee2 --- /dev/null +++ b/0225-temp-fix-select-disability.patch @@ -0,0 +1,26 @@ +From 98ff2215a880512862baa2cc7b1a0277fa6526a8 Mon Sep 17 00:00:00 2001 +From: yinbin6 +Date: Sat, 20 Jul 2024 16:40:04 +0800 +Subject: [PATCH] temp: fix select disability + + +diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c +index 976a3f3..12bc660 100644 +--- a/src/lstack/api/lstack_wrap.c ++++ b/src/lstack/api/lstack_wrap.c +@@ -636,11 +636,7 @@ static int32_t do_sigaction(int32_t signum, const struct sigaction *act, struct + + static int32_t do_select(int32_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) + { +- if (nfds <= 0 || !(readfds || writefds || exceptfds)) { +- GAZELLE_RETURN(EINVAL); +- } +- +- if (select_posix_path() == POSIX_KERNEL) { ++ if (select_posix_path() == POSIX_KERNEL ||nfds <= 0 || !(readfds || writefds || exceptfds)) { + return posix_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); + } + +-- +2.33.0 + diff --git a/gazelle.spec b/gazelle.spec index 20c663f45f0232080dae088a4c0d5032ada7236a..f4bcefef934d29fc8d570391191ec26fbc81d704 100644 --- a/gazelle.spec +++ b/gazelle.spec @@ -2,7 +2,7 @@ Name: gazelle Version: 1.0.2 -Release: 50 +Release: 52 Summary: gazelle is a high performance user-mode stack License: MulanPSL-2.0 URL: https://gitee.com/openeuler/gazelle @@ -232,7 +232,16 @@ Patch9212: 0212-example-sync-example-update.patch Patch9213: 0213-cleancode-improving-makefile-readability.patch Patch9214: 0214-add-.gitignore.patch Patch9215: 0215-cleancode-rename-gazelle-files-in-lwip.patch - +Patch9216: 0216-cleancode-refactor-lwipsock.h.patch +Patch9217: 0217-cleancode-refactor-posix-type-and-get_socket.patch +Patch9218: 0218-fix-some-error-of-NULL-pointer.patch +Patch9219: 0219-cleancode-refactor-posix_api.patch +Patch9220: 0220-cleancode-refactor-lwipgz_list.h.patch +Patch9221: 0221-fix-EPOLLIN-event-dropd.patch +Patch9222: 0222-cleancode-refactor-lwipgz_hlist.h.patch +Patch9223: 0223-add-sem-post-when-update-event.patch +Patch9224: 0224-cleancode-refactor-sys_now-and-lwip_ioctl.patch +Patch9225: 0225-temp-fix-select-disability.patch %description %{name} is a high performance user-mode stack. @@ -273,6 +282,21 @@ install -Dpm 0640 %{_builddir}/%{name}-%{version}/src/ltran/ltran.conf %{b %config(noreplace) %{conf_path}/ltran.conf %changelog +* Fri Jul 19 2024 yinbin6 - 1.0.2-52 +- temp: fix select disability.patch + + +* Fri Jul 19 2024 yinbin6 - 1.0.2-51 +- cleancode: refactor sys_now and lwip_ioctl +- add sem post when update event +- cleancode: refactor lwipgz_hlist.h +- fix EPOLLIN event dropd +- cleancode: refactor lwipgz_list.h +- cleancode: refactor posix_api +- fix some error of NULL pointer +- cleancode: refactor posix type and get_socket +- cleancode: refactor lwipsock.h + * Thu Jul 11 2024 yinbin6 - 1.0.2-50 - cleancode: rename gazelle files in lwip - add .gitignore