From 9be44d8301599c259f460c5441919c166a46375e Mon Sep 17 00:00:00 2001 From: jiangheng12 Date: Tue, 6 Jun 2023 20:21:21 +0800 Subject: [PATCH] revert cleancode series patches --- ...ncode-improving-makefile-readability.patch | 172 --- ...tbuf-in-recv_udp-to-fix-mem-overflow.patch | 0 0063-cleancode-remove-perf.patch | 780 -------------- ...eancode-rename-gazelle-files-in-lwip.patch | 476 --------- 0065-cleancode-refactor-lwipsock.h.patch | 979 ------------------ ...eancode-refactor-gazelle_posix_api.h.patch | 247 ----- 0067-cleancode-refactor-gazelle_list.h.patch | 158 --- 0068-cleancode-refactor-gazelle_hlist.h.patch | 389 ------- 0069-cleancode-refactor-options-define.patch | 404 -------- ...ancode-refactor-GAZELLE_TCP_PCB_HASH.patch | 752 -------------- ...code-refactor-sys_now-and-lwip_ioctl.patch | 462 --------- ...or-OFFLOAD_CHECKSUM-GAZELLE_TCP_DATA.patch | 812 --------------- 0073-cleancode-refactor-memp.patch | 598 ----------- lwip.spec | 29 +- 14 files changed, 4 insertions(+), 6254 deletions(-) delete mode 100644 0062-cleancode-improving-makefile-readability.patch rename 0074-drop-netbuf-in-recv_udp-to-fix-mem-overflow.patch => 0062-drop-netbuf-in-recv_udp-to-fix-mem-overflow.patch (100%) delete mode 100644 0063-cleancode-remove-perf.patch delete mode 100644 0064-cleancode-rename-gazelle-files-in-lwip.patch delete mode 100644 0065-cleancode-refactor-lwipsock.h.patch delete mode 100644 0066-cleancode-refactor-gazelle_posix_api.h.patch delete mode 100644 0067-cleancode-refactor-gazelle_list.h.patch delete mode 100644 0068-cleancode-refactor-gazelle_hlist.h.patch delete mode 100644 0069-cleancode-refactor-options-define.patch delete mode 100644 0070-cleancode-refactor-GAZELLE_TCP_PCB_HASH.patch delete mode 100644 0071-cleancode-refactor-sys_now-and-lwip_ioctl.patch delete mode 100644 0072-cleancode-refactor-OFFLOAD_CHECKSUM-GAZELLE_TCP_DATA.patch delete mode 100644 0073-cleancode-refactor-memp.patch diff --git a/0062-cleancode-improving-makefile-readability.patch b/0062-cleancode-improving-makefile-readability.patch deleted file mode 100644 index eb34963..0000000 --- a/0062-cleancode-improving-makefile-readability.patch +++ /dev/null @@ -1,172 +0,0 @@ -From be14782607ce761736ba5188a8c03aa1e84ff45f Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Thu, 18 May 2023 21:07:28 +0800 -Subject: [PATCH] cleancode: improving makefile readability - -Signed-off-by: Lemmy Huang ---- - src/Makefile | 53 +++++++++++++++------------- - src/Printlog.mk | 15 ++++++++ - src/api/{dir.mk => gazelle_dir.mk} | 0 - src/api/posix_api.c | 1 - - src/api/sys_arch.c | 1 - - src/core/{dir.mk => gazelle_dir.mk} | 0 - src/netif/{dir.mk => gazelle_dir.mk} | 0 - 7 files changed, 44 insertions(+), 26 deletions(-) - create mode 100644 src/Printlog.mk - rename src/api/{dir.mk => gazelle_dir.mk} (100%) - rename src/core/{dir.mk => gazelle_dir.mk} (100%) - rename src/netif/{dir.mk => gazelle_dir.mk} (100%) - -diff --git a/src/Makefile b/src/Makefile -index f445601..943ad30 100644 ---- a/src/Makefile -+++ b/src/Makefile -@@ -4,22 +4,28 @@ ROOT_DIR := $(dir $(abspath $(LWIP_DIR))) - LWIP_INC = $(LWIP_DIR)/include - DPDK_INCLUDE_FILE ?= /usr/include/dpdk - --SEC_FLAGS = -fstack-protector-strong -Werror -Wall -Wl,-z,relro,-z,now -Wl,-z,noexecstack -Wtrampolines -fPIC -D_FORTIRY_SOURCE=2 -O2 -+include $(LWIP_DIR)/Printlog.mk - - CC = gcc - AR = ar --OPTIMIZATION = -O3 --INC = -I$(LWIP_DIR) \ -- -I$(LWIP_INC) \ -- -I$(DPDK_INCLUDE_FILE) -- --CFLAGS = -g $(OPTIMIZATION) $(INC) $(SEC_FLAGS) -+OPTIMIZATION = -O2 - ARFLAGS = crDP - -+SEC_FLAGS = -fstack-protector-strong -Werror -Wall -Wl,-z,relro,-z,now -Wl,-z,noexecstack -Wtrampolines -fPIC -D_FORTIRY_SOURCE=2 -+CFLAGS = $(OPTIMIZATION) $(SEC_FLAGS) -+CFLAGS += -D__USE_GNU=1 -D_GNU_SOURCE=1 -DRTE_FORCE_INTRINSICS=1 -+ - ifeq ($(shell $(CC) -dumpmachine | cut -d"-" -f1), x86_64) - CFLAGS += -mssse3 - endif - -+INC = -I$(LWIP_DIR) \ -+ -I$(LWIP_INC) \ -+ -I$(DPDK_INCLUDE_FILE) -+ -+$(info $(CC):$(CFLAGS)) -+CFLAGS += $(INC) -+ - SRCS = - DIRS = api core netif - -@@ -27,35 +33,34 @@ define register_dir - SRCS += $(patsubst %, $(1)/%, $(2)) - endef - --include $(patsubst %, %/dir.mk, $(DIRS)) -+include $(patsubst %, %/gazelle_dir.mk, $(DIRS)) - - OBJS = $(subst .c,.o,$(SRCS)) --TMPS := $(subst .c,.s,$(SRCS)) --TMPS += $(subst .c,.i,$(SRCS)) - - LWIP_LIB = liblwip.a - - INSTALL_LIB = $(DESTDIR)/usr/lib64 - INSTALL_INC = $(DESTDIR)/usr/include/lwip - --.PHONY: all -+.PHONY: all install clean - all: $(LWIP_LIB) - --.depend: $(SRCS) -- rm -f ./.depend -- $(foreach SRC,$(SRCS),$(CC) $(CFLAGS) -MM -MT $(SRC:.c=.o) $(SRC) >> .depend;) -- ---include .depend -- - $(LWIP_LIB): $(OBJS) -- $(AR) $(ARFLAGS) $@ $(OBJS) -+ $(call printlog, BUILD, $@) -+ $(QUIET) $(AR) $(ARFLAGS) $@ $(OBJS) -+ -+%.o: %.c -+ $(call printlog, BUILD, $@) -+ $(QUIET) $(CC) $(CFLAGS) -c $(filter %.c,$^) -o $@ - --.PHONY: install - install: -- install -dp $(INSTALL_LIB) $(INSTALL_INC) -- install -Dp $(LWIP_DIR)/$(LWIP_LIB) $(INSTALL_LIB) -- cp -pr $(LWIP_INC)/* $(INSTALL_INC)/ -+ $(QUIET) install -dp $(INSTALL_LIB) $(INSTALL_INC) -+ $(call printlog, INSTALL, $(INSTALL_LIB)/$(LWIP_LIB)) -+ $(QUIET) install -Dp $(LWIP_DIR)/$(LWIP_LIB) $(INSTALL_LIB) -+ $(call printlog, INSTALL, $(INSTALL_INC)) -+ $(QUIET) cp -pr $(LWIP_INC)/* $(INSTALL_INC)/ -+ $(QUIET) cp -p Printlog.mk $(INSTALL_INC)/ - --.PHONY: clean - clean: -- $(RM) $(LWIP_LIB) $(OBJS) $(TMPS) .depend -+ $(call printlog, CLEAN, $(LWIP_LIB)) -+ $(QUIET) $(RM) $(LWIP_LIB) $(OBJS) -diff --git a/src/Printlog.mk b/src/Printlog.mk -new file mode 100644 -index 0000000..740035c ---- /dev/null -+++ b/src/Printlog.mk -@@ -0,0 +1,15 @@ -+ -+ROOT_DIR ?= $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) -+ -+ifeq ($(V),1) -+ QUIET = -+ printlog = -+else -+ QUIET = @ -+ printlog = @printf ' %-8s %s%s\n' \ -+ "$(1)" \ -+ "$(patsubst $(ROOT_DIR)/%,%,$(2))" \ -+ "$(if $(3), $(3))"; -+ MAKEFLAGS += --no-print-directory -+endif -+ -diff --git a/src/api/dir.mk b/src/api/gazelle_dir.mk -similarity index 100% -rename from src/api/dir.mk -rename to src/api/gazelle_dir.mk -diff --git a/src/api/posix_api.c b/src/api/posix_api.c -index b7334da..d9b983c 100644 ---- a/src/api/posix_api.c -+++ b/src/api/posix_api.c -@@ -30,7 +30,6 @@ - * - */ - --#define _GNU_SOURCE - #include - #include - #include -diff --git a/src/api/sys_arch.c b/src/api/sys_arch.c -index f93a00e..d143a73 100644 ---- a/src/api/sys_arch.c -+++ b/src/api/sys_arch.c -@@ -30,7 +30,6 @@ - * - */ - --#define _GNU_SOURCE - #include - #include - #include -diff --git a/src/core/dir.mk b/src/core/gazelle_dir.mk -similarity index 100% -rename from src/core/dir.mk -rename to src/core/gazelle_dir.mk -diff --git a/src/netif/dir.mk b/src/netif/gazelle_dir.mk -similarity index 100% -rename from src/netif/dir.mk -rename to src/netif/gazelle_dir.mk --- -2.22.0.windows.1 - diff --git a/0074-drop-netbuf-in-recv_udp-to-fix-mem-overflow.patch b/0062-drop-netbuf-in-recv_udp-to-fix-mem-overflow.patch similarity index 100% rename from 0074-drop-netbuf-in-recv_udp-to-fix-mem-overflow.patch rename to 0062-drop-netbuf-in-recv_udp-to-fix-mem-overflow.patch diff --git a/0063-cleancode-remove-perf.patch b/0063-cleancode-remove-perf.patch deleted file mode 100644 index 84343c3..0000000 --- a/0063-cleancode-remove-perf.patch +++ /dev/null @@ -1,780 +0,0 @@ -From 55cc351cc1b0e1fa021b410913e8876024a66c4b Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 19 May 2023 08:59:43 +0800 -Subject: [PATCH 1/3] cleancode: remove perf - -Signed-off-by: Lemmy Huang ---- - src/api/api_lib.c | 2 - - src/api/api_msg.c | 3 - - src/api/gazelle_dir.mk | 2 +- - src/api/perf.c | 182 ---------------------------------------- - src/core/ipv4/ip4.c | 14 ---- - src/core/ipv6/ip6.c | 10 --- - src/core/pbuf.c | 4 - - src/core/tcp.c | 1 - - src/core/tcp_in.c | 24 ------ - src/core/tcp_out.c | 21 ----- - src/core/udp.c | 21 +---- - src/include/arch/perf.h | 155 ---------------------------------- - src/include/lwipopts.h | 3 +- - 13 files changed, 5 insertions(+), 437 deletions(-) - delete mode 100644 src/api/perf.c - delete mode 100644 src/include/arch/perf.h - -diff --git a/src/api/api_lib.c b/src/api/api_lib.c -index ba9f3c5..ffa14d6 100644 ---- a/src/api/api_lib.c -+++ b/src/api/api_lib.c -@@ -1061,9 +1061,7 @@ netconn_write_vectors_partly(struct netconn *conn, struct netvector *vectors, u1 - /* For locking the core: this _can_ be delayed on low memory/low send buffer, - but if it is, this is done inside api_msg.c:do_write(), so we can use the - non-blocking version here. */ -- PERF_START(PERF_LAYER_TCP, PERF_POINT_TCP_DATA_SEND); - err = netconn_apimsg(lwip_netconn_do_write, &API_MSG_VAR_REF(msg)); -- PERF_STOP_INCREASE_COUNT("lwip_netconn_do_write", PERF_LAYER_TCP); - if (err == ERR_OK) { - if (bytes_written != NULL) { - *bytes_written = API_MSG_VAR_REF(msg).msg.w.offset; -diff --git a/src/api/api_msg.c b/src/api/api_msg.c -index 0287c06..f0572af 100644 ---- a/src/api/api_msg.c -+++ b/src/api/api_msg.c -@@ -1400,7 +1400,6 @@ lwip_netconn_do_connect(void *m) - #endif /* LWIP_UDP */ - #if LWIP_TCP - case NETCONN_TCP: -- PERF_START(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_SEND); - /* Prevent connect while doing any other action. */ - if (msg->conn->state == NETCONN_CONNECT) { - err = ERR_ALREADY; -@@ -1418,7 +1417,6 @@ lwip_netconn_do_connect(void *m) - err = ERR_INPROGRESS; - } else { - msg->conn->current_msg = msg; -- PERF_STOP_INCREASE_COUNT("lwip_netconn_do_connect", PERF_LAYER_TCP); - /* sys_sem_signal() is called from lwip_netconn_do_connected (or err_tcp()), - when the connection is established! */ - #if LWIP_TCPIP_CORE_LOCKING -@@ -1432,7 +1430,6 @@ lwip_netconn_do_connect(void *m) - } - } - } -- PERF_STOP_INCREASE_COUNT("lwip_netconn_do_connect", PERF_LAYER_TCP); - break; - #endif /* LWIP_TCP */ - default: -diff --git a/src/api/gazelle_dir.mk b/src/api/gazelle_dir.mk -index afbf863..c069a29 100644 ---- a/src/api/gazelle_dir.mk -+++ b/src/api/gazelle_dir.mk -@@ -1,3 +1,3 @@ --SRC = api_lib.c api_msg.c err.c netbuf.c netdb.c netifapi.c sockets.c tcpip.c perf.c posix_api.c sys_arch.c -+SRC = api_lib.c api_msg.c err.c netbuf.c netdb.c netifapi.c sockets.c tcpip.c posix_api.c sys_arch.c - - $(eval $(call register_dir, api, $(SRC))) -diff --git a/src/api/perf.c b/src/api/perf.c -deleted file mode 100644 -index 1c2a273..0000000 ---- a/src/api/perf.c -+++ /dev/null -@@ -1,182 +0,0 @@ --/* -- * Copyright (c) 2001-2004 Swedish Institute of Computer Science. -- * All rights reserved. -- * -- * Redistribution and use in source and binary forms, with or without modification, -- * are permitted provided that the following conditions are met: -- * -- * 1. Redistributions of source code must retain the above copyright notice, -- * this list of conditions and the following disclaimer. -- * 2. Redistributions in binary form must reproduce the above copyright notice, -- * this list of conditions and the following disclaimer in the documentation -- * and/or other materials provided with the distribution. -- * 3. The name of the author may not be used to endorse or promote products -- * derived from this software without specific prior written permission. -- * -- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED -- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT -- * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT -- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY -- * OF SUCH DAMAGE. -- * -- * This file is part of the lwIP TCP/IP stack. -- * -- * Author: Huawei Technologies -- * -- */ -- --#include "arch/perf.h" -- --#include -- --#include -- --#if LWIP_RECORD_PERF -- --#define SIG_FUNC_NUM 3 -- --#define SIG_STATS_DISPLAY 38 --#define SIG_PERF_BEGIN 39 --#define SIG_PERF_END 40 -- --typedef void (*pSignalFunc) (int); --static void signal_stats_display(int s); --static void signal_perf_begin(int s); --static void signal_perf_end(int s); -- --uint32_t g_record_perf; --__thread uint64_t g_timeTaken[PERF_POINT_END]; --__thread int g_perfPoint[PERF_LAYER_END]; --__thread struct timespec tvStart[PERF_LAYER_END]; --volatile uint64_t g_perfMaxtime[PERF_POINT_END]; --volatile uint64_t g_astPacketCnt[PERF_POINT_END]; --volatile uint64_t g_astPacketProcTime[PERF_POINT_END]; -- --char *g_ppLayerName[PERF_POINT_END] = { -- "IP_RECV", -- "TCP_DATA_RECV", -- "UDP_PARTIAL", -- "TCP_SYN_RECV", -- "TCP_SYN_ACK_SEND", -- "TCP_ACK_RECV", -- "TCP_SYN_SEND", -- "TCP_SYN_ACK_RECV", -- "TCP_ACK_SEND", -- "TCP_DATA_SEND", -- "IP_SEND" --}; -- --static int gsig_arr[SIG_FUNC_NUM] = { -- SIG_STATS_DISPLAY, -- SIG_PERF_BEGIN, -- SIG_PERF_END --}; -- --static pSignalFunc g_Funcs[SIG_FUNC_NUM] = { -- signal_stats_display, -- signal_perf_begin, -- signal_perf_end, --}; -- --static void print_perf_data_and_reset() --{ -- int i; -- printf("\n********* PERF DATA START*************\n"); -- for (i = 0; i < PERF_POINT_END; i++) { -- printf("%-20s Total: PacketProcTime: %-15"PRIu64", Maxtime: %-15"PRIu64", packetCnt: %-15"PRIu64"\n", -- g_ppLayerName[i], __sync_fetch_and_or(&g_astPacketProcTime[i], 0), -- __sync_fetch_and_or(&g_perfMaxtime[i], 0), -- __sync_fetch_and_or(&g_astPacketCnt[i], 0)); -- -- if (__sync_fetch_and_or(&g_astPacketProcTime[i], 0) && __sync_fetch_and_or(&g_astPacketCnt[i], 0)) { -- printf("%-20s Average: PacketProcTime: %-15lf, MaxTime: %-15"PRIu64"\n", g_ppLayerName[i], -- (double)__sync_fetch_and_or(&g_astPacketProcTime[i], 0) / (double)__sync_fetch_and_or(&g_astPacketCnt[i], 0), -- __sync_or_and_fetch(&g_perfMaxtime[i], 0)); -- } -- -- __sync_fetch_and_and (&g_astPacketProcTime[i], 0); -- __sync_fetch_and_and (&g_astPacketCnt[i], 0); -- __sync_fetch_and_and (&g_perfMaxtime[i], 0); -- } -- printf("\n********* PERF DATA END*************\n"); --} -- --static void signal_stats_display(int s) --{ -- struct sigaction s_test; -- printf("Received signal %d, stats display.\n", s); -- stats_display(); -- s_test.sa_handler = (void *) signal_stats_display; -- if (sigemptyset(&s_test.sa_mask) != 0) { -- printf("sigemptyset failed.\n"); -- } -- s_test.sa_flags = SA_RESETHAND; -- if (sigaction(s, &s_test, NULL) != 0) { -- printf("Could not register %d signal handler.\n", s); -- } --} -- --static void signal_perf_begin(int s) --{ -- struct sigaction s_test; -- printf("Received signal %d, perf_begin.\n", s); -- g_record_perf = 1; -- s_test.sa_handler = (void *) signal_perf_begin; -- if (sigemptyset(&s_test.sa_mask) != 0) { -- printf("sigemptyset failed.\n"); -- } -- s_test.sa_flags = SA_RESETHAND; -- if (sigaction(s, &s_test, NULL) != 0) { -- printf("Could not register %d signal handler.\n", s); -- } --} -- --static void signal_perf_end(int s) --{ -- struct sigaction s_test; -- printf("Received signal %d, perf_end\n", s); -- g_record_perf = 0; -- print_perf_data_and_reset(); -- s_test.sa_handler = (void *) signal_perf_end; -- if (sigemptyset(&s_test.sa_mask) != 0) { -- printf("sigemptyset failed.\n"); -- } -- s_test.sa_flags = SA_RESETHAND; -- if (sigaction(s, &s_test, NULL) != 0) { -- printf("Could not register %d signal handler.\n", s); -- } --} -- --int check_layer_point(int layer, int point) --{ -- if (point == g_perfPoint[layer]) { -- return 1; -- } -- return 0; --} -- --int perf_init(void) --{ -- int i; -- struct sigaction s_test; -- for (i = 0; i < SIG_FUNC_NUM; i++) { -- s_test.sa_handler = (void *) g_Funcs[i]; -- if (sigemptyset(&s_test.sa_mask) != 0) { -- printf("sigemptyset failed.\n"); -- return 1; -- } -- -- s_test.sa_flags = SA_RESETHAND; -- if (sigaction(gsig_arr[i], &s_test, NULL) != 0) { -- printf("Could not register %d signal handler.\n", gsig_arr[i]); -- return 1; -- } -- } -- return 0; --} --#endif -diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c -index 1b70bb5..1496289 100644 ---- a/src/core/ipv4/ip4.c -+++ b/src/core/ipv4/ip4.c -@@ -286,9 +286,7 @@ ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp) - { - struct netif *netif; - --#ifndef LWIP_PERF - PERF_START; --#endif - LWIP_UNUSED_ARG(inp); - - if (!ip4_canforward(p)) { -@@ -350,9 +348,7 @@ ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp) - MIB2_STATS_INC(mib2.ipforwdatagrams); - IP_STATS_INC(ip.xmit); - --#ifndef LWIP_PERF - PERF_STOP("ip4_forward"); --#endif - /* don't fragment if interface has mtu set to 0 [loopif] */ - if (netif->mtu && (p->tot_len > netif->mtu)) { - if ((IPH_OFFSET(iphdr) & PP_NTOHS(IP_DF)) == 0) { -@@ -446,8 +442,6 @@ ip4_input(struct pbuf *p, struct netif *inp) - - LWIP_ASSERT_CORE_LOCKED(); - -- PERF_START(PERF_LAYER_IP, PERF_POINT_IP_RECV); -- - IP_STATS_INC(ip.recv); - MIB2_STATS_INC(mib2.ipinreceives); - -@@ -719,19 +713,13 @@ ip4_input(struct pbuf *p, struct netif *inp) - case IP_PROTO_UDPLITE: - #endif /* LWIP_UDPLITE */ - MIB2_STATS_INC(mib2.ipindelivers); -- PERF_PAUSE(PERF_LAYER_IP); - udp_input(p, inp); -- PERF_RESUME(PERF_LAYER_IP, PERF_POINT_IP_RECV); - break; - #endif /* LWIP_UDP */ - #if LWIP_TCP - case IP_PROTO_TCP: - MIB2_STATS_INC(mib2.ipindelivers); -- PERF_PAUSE(PERF_LAYER_IP); -- PERF_START(PERF_LAYER_TCP, PERF_POINT_TCP_RECV); - tcp_input(p, inp); -- PERF_STOP_INCREASE_COUNT("tcp_input", PERF_LAYER_TCP); -- PERF_RESUME(PERF_LAYER_IP, PERF_POINT_IP_RECV); - break; - #endif /* LWIP_TCP */ - #if LWIP_ICMP -@@ -780,8 +768,6 @@ ip4_input(struct pbuf *p, struct netif *inp) - ip4_addr_set_any(ip4_current_src_addr()); - ip4_addr_set_any(ip4_current_dest_addr()); - -- PERF_STOP_INCREASE_COUNT("ip4_input", PERF_LAYER_IP); -- - return ERR_OK; - } - -diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c -index 9d904ec..060d5f3 100644 ---- a/src/core/ipv6/ip6.c -+++ b/src/core/ipv6/ip6.c -@@ -522,8 +522,6 @@ ip6_input(struct pbuf *p, struct netif *inp) - - LWIP_ASSERT_CORE_LOCKED(); - -- PERF_START(PERF_LAYER_IP, PERF_POINT_IP_RECV); -- - IP6_STATS_INC(ip6.recv); - - /* identify the IP header */ -@@ -1071,18 +1069,12 @@ options_done: - #if LWIP_UDPLITE - case IP6_NEXTH_UDPLITE: - #endif /* LWIP_UDPLITE */ -- PERF_PAUSE(PERF_LAYER_IP); - udp_input(p, inp); -- PERF_RESUME(PERF_LAYER_IP, PERF_POINT_IP_RECV); - break; - #endif /* LWIP_UDP */ - #if LWIP_TCP - case IP6_NEXTH_TCP: -- PERF_PAUSE(PERF_LAYER_IP); -- PERF_START(PERF_LAYER_TCP, PERF_POINT_TCP_RECV); - tcp_input(p, inp); -- PERF_STOP_INCREASE_COUNT("tcp_input", PERF_LAYER_TCP); -- PERF_RESUME(PERF_LAYER_IP, PERF_POINT_IP_RECV); - break; - #endif /* LWIP_TCP */ - #if LWIP_ICMP6 -@@ -1123,8 +1115,6 @@ ip6_input_cleanup: - ip6_addr_set_zero(ip6_current_src_addr()); - ip6_addr_set_zero(ip6_current_dest_addr()); - -- PERF_STOP_INCREASE_COUNT("ip6_input", PERF_LAYER_IP); -- - return ERR_OK; - } - -diff --git a/src/core/pbuf.c b/src/core/pbuf.c -index 2385e57..aae6008 100644 ---- a/src/core/pbuf.c -+++ b/src/core/pbuf.c -@@ -747,9 +747,7 @@ pbuf_free(struct pbuf *p) - } - LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free(%p)\n", (void *)p)); - --#ifndef LWIP_PERF - PERF_START; --#endif - - count = 0; - /* de-allocate all consecutive pbufs from the head of the chain that -@@ -814,9 +812,7 @@ pbuf_free(struct pbuf *p) - p = NULL; - } - } --#ifndef LWIP_PERF - PERF_STOP("pbuf_free"); --#endif - /* return number of de-allocated pbufs */ - return count; - } -diff --git a/src/core/tcp.c b/src/core/tcp.c -index 538a664..3abf63b 100644 ---- a/src/core/tcp.c -+++ b/src/core/tcp.c -@@ -558,7 +558,6 @@ tcp_close(struct tcp_pcb *pcb) - /* Set a flag not to receive any more data... */ - tcp_set_flags(pcb, TF_RXCLOSED); - } -- - /* ... and close */ - return tcp_close_shutdown(pcb, 1); - } -diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c -index 7e7d70a..3e635aa 100644 ---- a/src/core/tcp_in.c -+++ b/src/core/tcp_in.c -@@ -146,9 +146,7 @@ tcp_input(struct pbuf *p, struct netif *inp) - LWIP_ASSERT_CORE_LOCKED(); - LWIP_ASSERT("tcp_input: invalid pbuf", p != NULL); - --#ifndef LWIP_PERF - PERF_START; --#endif - - TCP_STATS_INC(tcp.recv); - MIB2_STATS_INC(mib2.tcpinsegs); -@@ -637,19 +635,7 @@ tcp_input(struct pbuf *p, struct netif *inp) - goto aborted; - } - /* Try to send something out. */ --#if LWIP_RECORD_PERF -- if (check_layer_point(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_ACK_RECV)) { -- PERF_PAUSE(PERF_LAYER_TCP); -- PERF_START(PERF_LAYER_TCP, PERF_POINT_TCP_ACK_SEND); -- } --#endif - tcp_output(pcb); --#if LWIP_RECORD_PERF -- if (check_layer_point(PERF_LAYER_TCP, PERF_POINT_TCP_ACK_SEND)) { -- PERF_STOP_INCREASE_COUNT("tcp_in", PERF_LAYER_TCP); -- PERF_RESUME(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_ACK_RECV); -- } --#endif - #if TCP_INPUT_DEBUG - #if TCP_DEBUG - tcp_debug_print_state(pcb->state); -@@ -682,9 +668,7 @@ aborted: - } - - LWIP_ASSERT("tcp_input: tcp_pcbs_sane()", tcp_pcbs_sane()); --#ifndef LWIP_PERF - PERF_STOP("tcp_input"); --#endif - return; - dropped: - TCP_STATS_INC(tcp.drop); -@@ -753,7 +737,6 @@ tcp_listen_input(struct tcp_pcb_listen *pcb) - tcp_rst((const struct tcp_pcb *)pcb, ackno, seqno + tcplen, ip_current_dest_addr(), - ip_current_src_addr(), tcphdr->dest, tcphdr->src); - } else if (flags & TCP_SYN) { -- PERF_UPDATE_POINT(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_RECV); - LWIP_DEBUGF(TCP_DEBUG, ("TCP connection request %"U16_F" -> %"U16_F".\n", tcphdr->src, tcphdr->dest)); - #if TCP_LISTEN_BACKLOG - if (pcb->accepts_pending >= pcb->backlog) { -@@ -832,18 +815,13 @@ tcp_listen_input(struct tcp_pcb_listen *pcb) - } - #endif - -- PERF_PAUSE(PERF_LAYER_TCP); -- PERF_START(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_ACK_SEND); - /* Send a SYN|ACK together with the MSS option. */ - rc = tcp_enqueue_flags(npcb, TCP_SYN | TCP_ACK); - if (rc != ERR_OK) { - tcp_abandon(npcb, 0); -- PERF_RESUME(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_RECV); - return; - } - tcp_output(npcb); -- PERF_STOP_INCREASE_COUNT("tcp_output", PERF_LAYER_TCP); -- PERF_RESUME(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_RECV); - } - return; - } -@@ -987,7 +965,6 @@ tcp_process(struct tcp_pcb *pcb) - /* received SYN ACK with expected sequence number? */ - if ((flags & TCP_ACK) && (flags & TCP_SYN) - && (ackno == pcb->lastack + 1)) { -- PERF_UPDATE_POINT(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_ACK_RECV); - pcb->rcv_nxt = seqno + 1; - pcb->rcv_ann_right_edge = pcb->rcv_nxt; - pcb->lastack = ackno; -@@ -1066,7 +1043,6 @@ tcp_process(struct tcp_pcb *pcb) - /* expected ACK number? */ - if (TCP_SEQ_BETWEEN(ackno, pcb->lastack + 1, pcb->snd_nxt)) { - pcb->state = ESTABLISHED; -- PERF_UPDATE_POINT(PERF_LAYER_TCP, PERF_POINT_TCP_ACK_RECV); - LWIP_DEBUGF(TCP_DEBUG, ("TCP connection established %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); - #if LWIP_CALLBACK_API || TCP_LISTEN_BACKLOG - if (pcb->listener == NULL) { -diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c -index 6250e6b..ebbc417 100644 ---- a/src/core/tcp_out.c -+++ b/src/core/tcp_out.c -@@ -1708,11 +1708,6 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif - err_t err; - u16_t len; - u32_t *opts; -- --#if LWIP_RECORD_PERF -- int tmpPoint; --#endif -- - #if TCP_CHECKSUM_ON_COPY - int seg_chksum_was_swapped = 0; - #endif -@@ -1911,9 +1906,6 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif - #endif /* CHECKSUM_GEN_TCP */ - TCP_STATS_INC(tcp.xmit); - -- PERF_PAUSE_RETURN_POINT(PERF_LAYER_TCP, tmpPoint); -- PERF_START(PERF_LAYER_IP, PERF_POINT_IP_SEND); -- - NETIF_SET_HINTS(netif, &(pcb->netif_hints)); - - seg->p->pcb = pcb; -@@ -1930,9 +1922,6 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif - } - #endif - -- PERF_STOP_INCREASE_COUNT("ip_out", PERF_LAYER_IP); -- PERF_RESUME(PERF_LAYER_TCP, tmpPoint); -- - return err; - } - -@@ -2371,10 +2360,6 @@ tcp_send_empty_ack(struct tcp_pcb *pcb) - u8_t optlen, optflags = 0; - u8_t num_sacks = 0; - --#if LWIP_RECORD_PERF -- int tmpPoint; --#endif -- - LWIP_ASSERT("tcp_send_empty_ack: invalid pcb", pcb != NULL); - - #if LWIP_TCP_TIMESTAMPS -@@ -2391,9 +2376,6 @@ tcp_send_empty_ack(struct tcp_pcb *pcb) - } - #endif - -- PERF_PAUSE_RETURN_POINT(PERF_LAYER_TCP, tmpPoint); -- PERF_START(PERF_LAYER_IP, PERF_POINT_IP_SEND); -- - p = tcp_output_alloc_header(pcb, optlen, 0, lwip_htonl(pcb->snd_nxt)); - if (p == NULL) { - /* let tcp_fasttmr retry sending this ACK */ -@@ -2418,9 +2400,6 @@ tcp_send_empty_ack(struct tcp_pcb *pcb) - tcp_clear_flags(pcb, TF_ACK_DELAY | TF_ACK_NOW); - } - -- PERF_STOP_INCREASE_COUNT("ip_out", PERF_LAYER_IP); -- PERF_RESUME(PERF_LAYER_TCP, tmpPoint); -- - return err; - } - -diff --git a/src/core/udp.c b/src/core/udp.c -index 9c3cdaa..d632de8 100644 ---- a/src/core/udp.c -+++ b/src/core/udp.c -@@ -213,11 +213,7 @@ udp_input(struct pbuf *p, struct netif *inp) - LWIP_ASSERT("udp_input: invalid pbuf", p != NULL); - LWIP_ASSERT("udp_input: invalid netif", inp != NULL); - --#if LWIP_RECORD_PERF -- PERF_START(PERF_LAYER_UDP, PERF_POINT_UDP); --#else -- //PERF_START; --#endif -+ PERF_START; - - UDP_STATS_INC(udp.recv); - -@@ -438,12 +434,7 @@ udp_input(struct pbuf *p, struct netif *inp) - pbuf_free(p); - } - end: --#if LWIP_RECORD_PERF -- PERF_STOP_INCREASE_COUNT("udp_input", PERF_LAYER_UDP); --#else -- //PERF_STOP("udp_input"); --#endif -- -+ PERF_STOP("udp_input"); - return; - #if CHECKSUM_CHECK_UDP - chkerr: -@@ -453,13 +444,7 @@ chkerr: - UDP_STATS_INC(udp.drop); - MIB2_STATS_INC(mib2.udpinerrors); - pbuf_free(p); -- --#if LWIP_RECORD_PERF -- PERF_STOP_INCREASE_COUNT("udp_input", PERF_LAYER_UDP); --#else -- //PERF_STOP("udp_input"); --#endif -- -+ PERF_STOP("udp_input"); - #endif /* CHECKSUM_CHECK_UDP */ - } - -diff --git a/src/include/arch/perf.h b/src/include/arch/perf.h -deleted file mode 100644 -index e505da7..0000000 ---- a/src/include/arch/perf.h -+++ /dev/null -@@ -1,155 +0,0 @@ --/* -- * Copyright (c) 2001-2004 Swedish Institute of Computer Science. -- * All rights reserved. -- * -- * Redistribution and use in source and binary forms, with or without modification, -- * are permitted provided that the following conditions are met: -- * -- * 1. Redistributions of source code must retain the above copyright notice, -- * this list of conditions and the following disclaimer. -- * 2. Redistributions in binary form must reproduce the above copyright notice, -- * this list of conditions and the following disclaimer in the documentation -- * and/or other materials provided with the distribution. -- * 3. The name of the author may not be used to endorse or promote products -- * derived from this software without specific prior written permission. -- * -- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED -- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT -- * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT -- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY -- * OF SUCH DAMAGE. -- * -- * This file is part of the lwIP TCP/IP stack. -- * -- * Author: Huawei Technologies -- * -- */ -- --#ifndef LWIP_ARCH_PERF_H --#define LWIP_ARCH_PERF_H -- --#include -- --#include "lwip/debug.h" -- --#if LWIP_RECORD_PERF --enum PERF_POINT { -- PERF_POINT_IP_RECV, -- PERF_POINT_TCP_RECV, -- PERF_POINT_UDP, -- PERF_POINT_TCP_SYN_RECV, -- PERF_POINT_TCP_SYN_ACK_SEND, -- PERF_POINT_TCP_ACK_RECV, -- PERF_POINT_TCP_SYN_SEND, -- PERF_POINT_TCP_SYN_ACK_RECV, -- PERF_POINT_TCP_ACK_SEND, -- PERF_POINT_TCP_DATA_SEND, -- PERF_POINT_IP_SEND, -- PERF_POINT_END --}; -- --enum PERF_LAYER { -- PERF_LAYER_IP, -- PERF_LAYER_TCP, -- PERF_LAYER_UDP, -- PERF_LAYER_END --}; -- --extern uint32_t g_record_perf; -- --extern __thread uint64_t g_timeTaken[PERF_POINT_END]; --extern __thread int g_perfPoint[PERF_LAYER_END]; --extern __thread struct timespec tvStart[PERF_LAYER_END]; -- --extern char *g_ppLayerName[PERF_POINT_END]; --extern volatile uint64_t g_perfMaxtime[PERF_POINT_END]; --extern volatile uint64_t g_astPacketCnt[PERF_POINT_END]; --extern volatile uint64_t g_astPacketProcTime[PERF_POINT_END]; -- --#define PERF_START(layer, point) do {\ -- g_perfPoint[(layer)] = (point);\ -- LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("set point %d:%s\n", layer, g_ppLayerName[g_perfPoint[(layer)]]));\ -- clock_gettime(CLOCK_MONOTONIC, &tvStart[(layer)]);\ -- g_timeTaken[(point)] = 0;\ --} while (0) -- --#define PERF_UPDATE_POINT(layer, point) do {\ -- LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("old point %d:%s\n", layer, g_ppLayerName[g_perfPoint[(layer)]]));\ -- g_timeTaken[(point)] = g_timeTaken[g_perfPoint[(layer)]];\ -- g_timeTaken[g_perfPoint[(layer)]] = 0;\ -- g_perfPoint[(layer)] = (point);\ -- LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("new point %d:%s\n", layer, g_ppLayerName[g_perfPoint[(layer)]]));\ --} while (0) -- --#define PERF_PAUSE(layer) do {\ -- struct timespec tvEnd;\ -- clock_gettime(CLOCK_MONOTONIC, &tvEnd);\ -- LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("perf pause layer%d\n", layer));\ -- g_timeTaken[g_perfPoint[(layer)]] += ((tvEnd.tv_sec - tvStart[(layer)].tv_sec) \ -- * (1000000000UL) + (tvEnd.tv_nsec - tvStart[(layer)].tv_nsec));\ --} while (0) -- --#define PERF_PAUSE_RETURN_POINT(layer, pause_point) do {\ -- struct timespec tvEnd;\ -- clock_gettime(CLOCK_MONOTONIC, &tvEnd);\ -- g_timeTaken[g_perfPoint[(layer)]] += ((tvEnd.tv_sec - tvStart[(layer)].tv_sec) \ -- * (1000000000UL) + (tvEnd.tv_nsec - tvStart[(layer)].tv_nsec));\ -- LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("perf pause point %d:%s\n", layer, g_ppLayerName[g_perfPoint[(layer)]]));\ -- (pause_point) = g_perfPoint[(layer)];\ --} while (0) -- -- --#define PERF_RESUME(layer, point) do {\ -- LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("perf resule point %d:%s\n", layer, g_ppLayerName[point]));\ -- clock_gettime(CLOCK_MONOTONIC, &tvStart[(layer)]);\ -- g_perfPoint[(layer)] = (point);\ --} while (0) -- -- --/* x is a prompt */ --#define PERF_STOP_INCREASE_COUNT(x, layer) do {\ -- if (g_record_perf)\ -- {\ -- struct timespec tvEnd;\ -- int i = 2;\ -- uint32_t oldValue = 0;\ -- clock_gettime(CLOCK_MONOTONIC, &tvEnd);\ -- g_timeTaken[g_perfPoint[(layer)]] += ((tvEnd.tv_sec - tvStart[(layer)].tv_sec) \ -- * (1000000000UL) + (tvEnd.tv_nsec - tvStart[(layer)].tv_nsec));\ -- while (i && !oldValue)\ -- {\ -- oldValue = __sync_or_and_fetch(&g_perfMaxtime[g_perfPoint[(layer)]], 0);\ -- if (oldValue >= g_timeTaken[g_perfPoint[(layer)]])\ -- {\ -- break;\ -- }\ -- oldValue = __sync_val_compare_and_swap(&g_perfMaxtime[g_perfPoint[(layer)]],\ -- oldValue, g_timeTaken[g_perfPoint[(layer)]]);\ -- i--;\ -- }\ -- __sync_fetch_and_add(&g_astPacketCnt[g_perfPoint[(layer)]], 1);\ -- __sync_fetch_and_add(&g_astPacketProcTime[g_perfPoint[(layer)]], g_timeTaken[g_perfPoint[(layer)]]);\ -- LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("Time for %s is: %ld\n",\ -- g_ppLayerName[g_perfPoint[(layer)]], g_timeTaken[g_perfPoint[(layer)]]));\ -- }\ --} while (0) -- -- --int check_layer_point(int layer, int point); --int perf_init(); -- --#else --#define PERF_START(layer, point) do { } while (0) --#define PERF_UPDATE_POINT(layer, point) do { } while (0) --#define PERF_PAUSE(layer) do { } while (0) --#define PERF_PAUSE_RETURN_POINT(layer, pause_point) do { } while (0) --#define PERF_RESUME(layer, point) do { } while (0) --#define PERF_STOP_INCREASE_COUNT(x, layer) do { } while (0) --#endif -- --#endif /* LWIP_ARCH_PERF_H */ -diff --git a/src/include/lwipopts.h b/src/include/lwipopts.h -index bcb0879..828a2d1 100644 ---- a/src/include/lwipopts.h -+++ b/src/include/lwipopts.h -@@ -38,8 +38,7 @@ - ---------- gazelle options ---------- - ------------------------------------- - */ --#define LWIP_PERF 1 --#define LWIP_RECORD_PERF 0 -+#define LWIP_PERF 0 - - //#define LWIP_DEBUG 1 - #define GAZELLE_USE_DPDK_LOG 1 --- -2.22.0.windows.1 - diff --git a/0064-cleancode-rename-gazelle-files-in-lwip.patch b/0064-cleancode-rename-gazelle-files-in-lwip.patch deleted file mode 100644 index e2c8ea7..0000000 --- a/0064-cleancode-rename-gazelle-files-in-lwip.patch +++ /dev/null @@ -1,476 +0,0 @@ -From d41efd0c2f8f899daed9acfac86ac57738994bf1 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 19 May 2023 09:39:16 +0800 -Subject: [PATCH 2/3] cleancode: rename gazelle files in lwip - -Signed-off-by: Lemmy Huang ---- - src/api/api_msg.c | 2 +- - src/api/gazelle_dir.mk | 2 +- - src/api/{posix_api.c => gazelle_posix_api.c} | 2 +- - src/api/sockets.c | 2 +- - src/core/ipv4/icmp.c | 2 +- - src/core/ipv4/ip4.c | 2 +- - src/core/ipv4/ip4_frag.c | 2 +- - src/core/tcp_in.c | 2 +- - src/core/tcp_out.c | 2 +- - src/core/udp.c | 2 +- - src/include/arch/cc.h | 6 +++--- - src/include/arch/sys_arch.h | 6 +++--- - src/include/{dpdk_cksum.h => gazelle_dpdk_offload.h} | 6 +++--- - src/include/{eventpoll.h => gazelle_event.h} | 8 ++++---- - src/include/{hlist.h => gazelle_hlist.h} | 8 ++++---- - src/include/{list.h => gazelle_list.h} | 6 +++--- - src/include/{posix_api.h => gazelle_posix_api.h} | 6 +++--- - src/include/{reg_sock.h => gazelle_tcp_reg.h} | 6 +++--- - src/include/lwip/priv/tcp_priv.h | 2 +- - src/include/lwip/tcp.h | 2 +- - src/include/lwiplog.h | 6 +++--- - src/include/lwipopts.h | 6 +++--- - src/include/lwipsock.h | 8 ++++---- - src/netif/ethernet.c | 2 +- - 24 files changed, 49 insertions(+), 49 deletions(-) - rename src/api/{posix_api.c => gazelle_posix_api.c} (99%) - rename src/include/{dpdk_cksum.h => gazelle_dpdk_offload.h} (97%) - rename src/include/{eventpoll.h => gazelle_event.h} (95%) - rename src/include/{hlist.h => gazelle_hlist.h} (98%) - rename src/include/{list.h => gazelle_list.h} (97%) - rename src/include/{posix_api.h => gazelle_posix_api.h} (97%) - rename src/include/{reg_sock.h => gazelle_tcp_reg.h} (96%) - -diff --git a/src/api/api_msg.c b/src/api/api_msg.c -index f0572af..18f33ef 100644 ---- a/src/api/api_msg.c -+++ b/src/api/api_msg.c -@@ -57,7 +57,7 @@ - #if GAZELLE_ENABLE - #include "lwip/sockets.h" - #include "lwipsock.h" --#include "posix_api.h" -+#include "gazelle_posix_api.h" - #endif - - #include -diff --git a/src/api/gazelle_dir.mk b/src/api/gazelle_dir.mk -index c069a29..d51ad43 100644 ---- a/src/api/gazelle_dir.mk -+++ b/src/api/gazelle_dir.mk -@@ -1,3 +1,3 @@ --SRC = api_lib.c api_msg.c err.c netbuf.c netdb.c netifapi.c sockets.c tcpip.c posix_api.c sys_arch.c -+SRC = api_lib.c api_msg.c err.c netbuf.c netdb.c netifapi.c sockets.c tcpip.c sys_arch.c gazelle_posix_api.c - - $(eval $(call register_dir, api, $(SRC))) -diff --git a/src/api/posix_api.c b/src/api/gazelle_posix_api.c -similarity index 99% -rename from src/api/posix_api.c -rename to src/api/gazelle_posix_api.c -index d9b983c..8bd4ce0 100644 ---- a/src/api/posix_api.c -+++ b/src/api/gazelle_posix_api.c -@@ -41,7 +41,7 @@ - - #include "lwip/err.h" - #include "lwipsock.h" --#include "posix_api.h" -+#include "gazelle_posix_api.h" - - posix_api_t *posix_api; - posix_api_t posix_api_val; -diff --git a/src/api/sockets.c b/src/api/sockets.c -index a0f9d50..f402db8 100644 ---- a/src/api/sockets.c -+++ b/src/api/sockets.c -@@ -66,7 +66,7 @@ - #if GAZELLE_ENABLE - #include - #include "lwipsock.h" --#include "posix_api.h" -+#include "gazelle_posix_api.h" - #endif - - #include -diff --git a/src/core/ipv4/icmp.c b/src/core/ipv4/icmp.c -index 402ba69..2b15ed4 100644 ---- a/src/core/ipv4/icmp.c -+++ b/src/core/ipv4/icmp.c -@@ -52,7 +52,7 @@ - #include - - #if GAZELLE_ENABLE && CHECKSUM_GEN_IP_HW --#include "dpdk_cksum.h" -+#include "gazelle_dpdk_offload.h" - #endif - - #ifdef LWIP_HOOK_FILENAME -diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c -index 1496289..079716d 100644 ---- a/src/core/ipv4/ip4.c -+++ b/src/core/ipv4/ip4.c -@@ -60,7 +60,7 @@ - #include - - #if GAZELLE_ENABLE && (CHECKSUM_CHECK_IP_HW || CHECKSUM_GEN_IP_HW) --#include "dpdk_cksum.h" -+#include "gazelle_dpdk_offload.h" - #endif - - #ifdef LWIP_HOOK_FILENAME -diff --git a/src/core/ipv4/ip4_frag.c b/src/core/ipv4/ip4_frag.c -index e01ea51..4d697c8 100644 ---- a/src/core/ipv4/ip4_frag.c -+++ b/src/core/ipv4/ip4_frag.c -@@ -52,7 +52,7 @@ - #include - - #if GAZELLE_ENABLE && CHECKSUM_GEN_IP_HW --#include "dpdk_cksum.h" -+#include "gazelle_dpdk_offload.h" - #endif - - #if IP_REASSEMBLY -diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c -index 3e635aa..9585965 100644 ---- a/src/core/tcp_in.c -+++ b/src/core/tcp_in.c -@@ -66,7 +66,7 @@ - #include - - #if GAZELLE_ENABLE && CHECKSUM_CHECK_TCP_HW --#include -+#include - #endif /* CHECKSUM_CHECK_TCP_HW */ - - #ifdef LWIP_HOOK_FILENAME -diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c -index ebbc417..fde3b8f 100644 ---- a/src/core/tcp_out.c -+++ b/src/core/tcp_out.c -@@ -84,7 +84,7 @@ - #include "lwipsock.h" - #include - #if CHECKSUM_GEN_TCP_HW --#include "dpdk_cksum.h" -+#include "gazelle_dpdk_offload.h" - #endif - #endif - -diff --git a/src/core/udp.c b/src/core/udp.c -index d632de8..fc86ac5 100644 ---- a/src/core/udp.c -+++ b/src/core/udp.c -@@ -68,7 +68,7 @@ - #if GAZELLE_ENABLE - #include "lwipsock.h" - #include --#include "dpdk_cksum.h" -+#include "gazelle_dpdk_offload.h" - #endif - - #ifndef UDP_LOCAL_PORT_RANGE_START -diff --git a/src/include/arch/cc.h b/src/include/arch/cc.h -index 10d667b..0b454bb 100644 ---- a/src/include/arch/cc.h -+++ b/src/include/arch/cc.h -@@ -30,8 +30,8 @@ - * - */ - --#ifndef LWIP_ARCH_CC_H --#define LWIP_ARCH_CC_H -+#ifndef _LWIP_ARCH_CC_H_ -+#define _LWIP_ARCH_CC_H_ - - #include - #include -@@ -78,4 +78,4 @@ void alloc_memory_##variable_name(void) \ - sys_hugepage_malloc(mpname, LWIP_MEM_ALIGN_BUFFER(size)); \ - } - --#endif /* LWIP_ARCH_CC_H */ -+#endif /* _LWIP_ARCH_CC_H_ */ -diff --git a/src/include/arch/sys_arch.h b/src/include/arch/sys_arch.h -index 04e3192..907c116 100644 ---- a/src/include/arch/sys_arch.h -+++ b/src/include/arch/sys_arch.h -@@ -30,8 +30,8 @@ - * - */ - --#ifndef LWIP_ARCH_SYS_ARCH_H --#define LWIP_ARCH_SYS_ARCH_H -+#ifndef _LWIP_ARCH_SYS_ARCH_H_ -+#define _LWIP_ARCH_SYS_ARCH_H_ - - #include - #include -@@ -136,4 +136,4 @@ __attribute__((always_inline)) inline int update_timeout(int timeout, uint32_t p - } - } - --#endif /* LWIP_ARCH_SYS_ARCH_H */ -+#endif /* _LWIP_ARCH_SYS_ARCH_H_ */ -diff --git a/src/include/dpdk_cksum.h b/src/include/gazelle_dpdk_offload.h -similarity index 97% -rename from src/include/dpdk_cksum.h -rename to src/include/gazelle_dpdk_offload.h -index e41644b..0548258 100644 ---- a/src/include/dpdk_cksum.h -+++ b/src/include/gazelle_dpdk_offload.h -@@ -30,8 +30,8 @@ - * - */ - --#ifndef __DPDK_CKSUM_H__ --#define __DPDK_CKSUM_H__ -+#ifndef _GAZELLE_DPDK_OFFLOAD_H_ -+#define _GAZELLE_DPDK_OFFLOAD_H_ - - #include "lwipopts.h" - #if GAZELLE_ENABLE -@@ -108,4 +108,4 @@ static inline u16_t ip_chksum_pseudo_offload(u8_t proto, u16_t proto_len, - #endif /* CHECKSUM_GEN_TCP_HW */ - - #endif /* GAZELLE_ENABLE */ --#endif /* __DPDK_CKSUM_H__ */ -+#endif /* _GAZELLE_DPDK_OFFLOAD_H_ */ -diff --git a/src/include/eventpoll.h b/src/include/gazelle_event.h -similarity index 95% -rename from src/include/eventpoll.h -rename to src/include/gazelle_event.h -index a10c84b..e31ec4b 100644 ---- a/src/include/eventpoll.h -+++ b/src/include/gazelle_event.h -@@ -30,13 +30,13 @@ - * - */ - --#ifndef __EVENTPOLL_H__ --#define __EVENTPOLL_H__ -+#ifndef _GAZELLE_EVENT_H_ -+#define _GAZELLE_EVENT_H_ - - #include - - #include "lwip/api.h" --#include "list.h" -+#include "gazelle_list.h" - - #define MAX_EPOLLFDS 32 - -@@ -67,4 +67,4 @@ struct lwip_sock; - extern void add_sock_event(struct lwip_sock *sock, uint32_t event); - extern int32_t lstack_epoll_close(int32_t); - --#endif /* __EVENTPOLL_H__ */ -+#endif /* _GAZELLE_EVENT_H_ */ -diff --git a/src/include/hlist.h b/src/include/gazelle_hlist.h -similarity index 98% -rename from src/include/hlist.h -rename to src/include/gazelle_hlist.h -index 988b017..86b5c6d 100644 ---- a/src/include/hlist.h -+++ b/src/include/gazelle_hlist.h -@@ -30,10 +30,10 @@ - * - */ - --#ifndef __HLIST_H__ --#define __HLIST_H__ -+#ifndef _GAZELLE_HLIST_H_ -+#define _GAZELLE_HLIST_H_ - --#include "list.h" -+#include "gazelle_list.h" - - //#if GAZELLE_TCP_PCB_HASH - struct hlist_node { -@@ -230,4 +230,4 @@ static inline void hlist_ctl_add_after(struct hlist_node *n, struct hlist_node * - } - //#endif /* GAZELLE_TCP_PCB_HASH */ - --#endif /* __HLIST_H__ */ -+#endif /* _GAZELLE_HLIST_H_ */ -diff --git a/src/include/list.h b/src/include/gazelle_list.h -similarity index 97% -rename from src/include/list.h -rename to src/include/gazelle_list.h -index 11f94c2..a40c17f 100644 ---- a/src/include/list.h -+++ b/src/include/gazelle_list.h -@@ -30,8 +30,8 @@ - * - */ - --#ifndef __LIST_H__ --#define __LIST_H__ -+#ifndef _GAZELLE_LIST_H_ -+#define _GAZELLE_LIST_H_ - - #ifndef NULL - #ifdef __cplusplus -@@ -107,4 +107,4 @@ static inline int list_is_empty(const struct list_node *h) - (type *)((char *)__mptr - offsetof(type,member));}) - #endif /* container_of */ - --#endif /* __LIST_H__ */ -+#endif /* _GAZELLE_LIST_H_ */ -diff --git a/src/include/posix_api.h b/src/include/gazelle_posix_api.h -similarity index 97% -rename from src/include/posix_api.h -rename to src/include/gazelle_posix_api.h -index a73e2ec..0bed1de 100644 ---- a/src/include/posix_api.h -+++ b/src/include/gazelle_posix_api.h -@@ -30,8 +30,8 @@ - * - */ - --#ifndef __POSIX_API_H__ --#define __POSIX_API_H__ -+#ifndef _GAZELLE_POSIX_API_H_ -+#define _GAZELLE_POSIX_API_H_ - - #include - #include -@@ -88,4 +88,4 @@ int posix_api_init(void); - void posix_api_free(void); - void posix_api_fork(void); - --#endif /* __POSIX_API_H__ */ -+#endif /* _GAZELLE_POSIX_API_H_ */ -diff --git a/src/include/reg_sock.h b/src/include/gazelle_tcp_reg.h -similarity index 96% -rename from src/include/reg_sock.h -rename to src/include/gazelle_tcp_reg.h -index e349e85..6a9f5f9 100644 ---- a/src/include/reg_sock.h -+++ b/src/include/gazelle_tcp_reg.h -@@ -30,8 +30,8 @@ - * - */ - --#ifndef __REG_SOCK_H__ --#define __REG_SOCK_H__ -+#ifndef _GAZELLE_TCP_REG_ -+#define _GAZELLE_TCP_REG_ - - enum reg_ring_type { - REG_RING_TCP_LISTEN = 0, -@@ -60,4 +60,4 @@ struct reg_ring_msg { - extern int vdev_reg_xmit(enum reg_ring_type type, struct gazelle_quintuple *qtuple); - extern bool port_in_stack_queue(uint32_t src_ip, uint32_t dst_ip, uint16_t src_port, uint16_t dst_port); - --#endif /* __REG_SOCK_H__ */ -+#endif /* _GAZELLE_TCP_REG_ */ -diff --git a/src/include/lwip/priv/tcp_priv.h b/src/include/lwip/priv/tcp_priv.h -index ddae3fd..44200ff 100644 ---- a/src/include/lwip/priv/tcp_priv.h -+++ b/src/include/lwip/priv/tcp_priv.h -@@ -341,7 +341,7 @@ extern PER_THREAD struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in T - extern PER_THREAD struct tcp_pcb ** tcp_pcb_lists[NUM_TCP_PCB_LISTS]; - - #if GAZELLE_ENABLE --#include "reg_sock.h" -+#include "gazelle_tcp_reg.h" - static inline int vdev_reg_done(enum reg_ring_type reg_type, const struct tcp_pcb *pcb) - { - LWIP_ASSERT("Invalid parameter", pcb != NULL); -diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h -index e13099c..11ddd25 100644 ---- a/src/include/lwip/tcp.h -+++ b/src/include/lwip/tcp.h -@@ -53,7 +53,7 @@ - - #if GAZELLE_TCP_PCB_HASH - #include "lwip/sys.h" --#include "hlist.h" -+#include "gazelle_hlist.h" - #endif - - #ifdef __cplusplus -diff --git a/src/include/lwiplog.h b/src/include/lwiplog.h -index f278ff4..2cf68f9 100644 ---- a/src/include/lwiplog.h -+++ b/src/include/lwiplog.h -@@ -30,8 +30,8 @@ - * - */ - --#ifndef __LWIPLOG_H__ --#define __LWIPLOG_H__ -+#ifndef _LWIPLOG_H_ -+#define _LWIPLOG_H_ - - #include - #include -@@ -77,4 +77,4 @@ do { LWIP_PLATFORM_LOG(LWIP_LOG_FATAL, "Assertion \"%s\" failed at line %d in %s - - #endif /* GAZELLE_USE_DPDK_LOG */ - --#endif /* __LWIPLOG_H__ */ -+#endif /* _LWIPLOG_H_ */ -diff --git a/src/include/lwipopts.h b/src/include/lwipopts.h -index 828a2d1..bc85eae 100644 ---- a/src/include/lwipopts.h -+++ b/src/include/lwipopts.h -@@ -30,8 +30,8 @@ - * - */ - --#ifndef __LWIPOPTS_H__ --#define __LWIPOPTS_H__ -+#ifndef _LWIPOPTS_H_ -+#define _LWIPOPTS_H_ - - /* - ------------------------------------- -@@ -241,4 +241,4 @@ - */ - #define LWIP_NETIF_LOOPBACK 1 - --#endif /* __LWIPOPTS_H__ */ -+#endif /* _LWIPOPTS_H_ */ -diff --git a/src/include/lwipsock.h b/src/include/lwipsock.h -index f8480c5..1814f76 100644 ---- a/src/include/lwipsock.h -+++ b/src/include/lwipsock.h -@@ -30,14 +30,14 @@ - * - */ - --#ifndef __LWIPSOCK_H__ --#define __LWIPSOCK_H__ -+#ifndef _LWIPSOCK_H_ -+#define _LWIPSOCK_H_ - - #include - #include "lwip/opt.h" - #include "lwip/api.h" - --#include "eventpoll.h" -+#include "gazelle_event.h" - - /* move some definitions to the lwipsock.h for libnet to use, and - * at the same time avoid conflict between lwip/sockets.h and sys/socket.h -@@ -187,4 +187,4 @@ struct lwip_sock *get_socket_by_fd(int s); - void lwip_sock_init(void); - void lwip_exit(void); - --#endif /* __LWIPSOCK_H__ */ -+#endif /* _LWIPSOCK_H_ */ -diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c -index fd13f00..deddf3f 100644 ---- a/src/netif/ethernet.c -+++ b/src/netif/ethernet.c -@@ -57,7 +57,7 @@ - #endif /* PPPOE_SUPPORT */ - - #if GAZELLE_ENABLE && (CHECKSUM_GEN_TCP_HW || CHECKSUM_GEN_IP_HW) --#include "dpdk_cksum.h" -+#include "gazelle_dpdk_offload.h" - #endif - - #ifdef LWIP_HOOK_FILENAME --- -2.22.0.windows.1 - diff --git a/0065-cleancode-refactor-lwipsock.h.patch b/0065-cleancode-refactor-lwipsock.h.patch deleted file mode 100644 index fe87db5..0000000 --- a/0065-cleancode-refactor-lwipsock.h.patch +++ /dev/null @@ -1,979 +0,0 @@ -From 09b9d85b915c5a9d52c624f9a155d20eab564e82 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 19 May 2023 10:52:49 +0800 -Subject: [PATCH 3/3] cleancode: refactor lwipsock.h - -Signed-off-by: Lemmy Huang ---- - src/api/api_msg.c | 5 +- - src/api/gazelle_dir.mk | 2 +- - src/api/gazelle_posix_api.c | 10 -- - src/api/gazelle_sock.c | 134 ++++++++++++++++ - src/api/sockets.c | 226 ++++++--------------------- - src/core/pbuf.c | 1 + - src/core/tcp.c | 2 +- - src/include/gazelle_posix_api.h | 2 - - src/include/lwip/api.h | 35 ----- - src/include/lwip/priv/sockets_priv.h | 2 +- - src/include/lwipsock.h | 128 +++++++-------- - 11 files changed, 250 insertions(+), 297 deletions(-) - create mode 100644 src/api/gazelle_sock.c - -diff --git a/src/api/api_msg.c b/src/api/api_msg.c -index 18f33ef..b4333f5 100644 ---- a/src/api/api_msg.c -+++ b/src/api/api_msg.c -@@ -58,6 +58,7 @@ - #include "lwip/sockets.h" - #include "lwipsock.h" - #include "gazelle_posix_api.h" -+extern void gazelle_connected_callback(struct netconn *conn); - #endif - - #include -@@ -614,10 +615,6 @@ accept_function(void *arg, struct tcp_pcb *newpcb, err_t err) - API_EVENT(conn, NETCONN_EVT_RCVPLUS, 0); - } - --#if GAZELLE_ENABLE -- LWIP_DEBUGF(API_MSG_DEBUG, ("libos incoming connection established\n")); -- SET_CONN_TYPE_LIBOS(newconn); --#endif - return ERR_OK; - } - #endif /* LWIP_TCP */ -diff --git a/src/api/gazelle_dir.mk b/src/api/gazelle_dir.mk -index d51ad43..38daa53 100644 ---- a/src/api/gazelle_dir.mk -+++ b/src/api/gazelle_dir.mk -@@ -1,3 +1,3 @@ --SRC = api_lib.c api_msg.c err.c netbuf.c netdb.c netifapi.c sockets.c tcpip.c sys_arch.c gazelle_posix_api.c -+SRC = api_lib.c api_msg.c err.c netbuf.c netdb.c netifapi.c sockets.c tcpip.c sys_arch.c gazelle_posix_api.c gazelle_sock.c - - $(eval $(call register_dir, api, $(SRC))) -diff --git a/src/api/gazelle_posix_api.c b/src/api/gazelle_posix_api.c -index 8bd4ce0..219769a 100644 ---- a/src/api/gazelle_posix_api.c -+++ b/src/api/gazelle_posix_api.c -@@ -51,17 +51,11 @@ static int chld_is_epfd(int fd) - return 0; - } - --static struct lwip_sock *chld_get_socket(int fd) --{ -- return NULL; --} -- - void posix_api_fork(void) - { - /* lstack helper api */ - posix_api->ues_posix = 1; - posix_api->is_epfd = chld_is_epfd; -- posix_api->get_socket = chld_get_socket; - } - - -@@ -114,10 +108,6 @@ int posix_api_init(void) - CHECK_DLSYM_RET_RETURN(posix_api->poll_fn = dlsym(handle, "poll")); - CHECK_DLSYM_RET_RETURN(posix_api->ioctl_fn = dlsym(handle, "ioctl")); - -- /* lstack helper api */ -- posix_api->get_socket = get_socket; -- posix_api->epoll_close_fn = lstack_epoll_close; -- - /* support fork */ - posix_api->ues_posix = 1; - return ERR_OK; -diff --git a/src/api/gazelle_sock.c b/src/api/gazelle_sock.c -new file mode 100644 -index 0000000..1164485 ---- /dev/null -+++ b/src/api/gazelle_sock.c -@@ -0,0 +1,134 @@ -+/* -+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science. -+ * All rights reserved. -+ * -+ * Redistribution and use in source and binary forms, with or without modification, -+ * are permitted provided that the following conditions are met: -+ * -+ * 1. Redistributions of source code must retain the above copyright notice, -+ * this list of conditions and the following disclaimer. -+ * 2. Redistributions in binary form must reproduce the above copyright notice, -+ * this list of conditions and the following disclaimer in the documentation -+ * and/or other materials provided with the distribution. -+ * 3. The name of the author may not be used to endorse or promote products -+ * derived from this software without specific prior written permission. -+ * -+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED -+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT -+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT -+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY -+ * OF SUCH DAMAGE. -+ * -+ * This file is part of the lwIP TCP/IP stack. -+ * -+ * Author: Huawei Technologies -+ * -+ */ -+ -+#include -+ -+#include "lwipsock.h" -+#include "gazelle_posix_api.h" -+#include "lwip/tcp.h" -+ -+extern struct lwip_sock *sockets[MEMP_NUM_NETCONN]; // NUM_SOCKETS -+ -+extern void gazelle_init_sock(int32_t fd); -+extern void gazelle_clean_sock(int32_t fd); -+ -+static int socket_sys_type(enum netconn_type type) -+{ -+ int sys_type; -+ switch (NETCONNTYPE_GROUP(type)) { -+ case NETCONN_RAW: -+ sys_type = SOCK_RAW; -+ break; -+ case NETCONN_UDPLITE: -+ case NETCONN_UDP: -+ sys_type = SOCK_DGRAM; -+ break; -+ case NETCONN_TCP: -+ sys_type = SOCK_STREAM; -+ break; -+ default: -+ sys_type = -1; -+ break; -+ } -+ return sys_type; -+} -+ -+static int socket_new_sysfd(struct netconn *newconn, int accepted, int flags) -+{ -+ int domain = AF_INET; -+ int protocol = 0; -+ /*add SOCK_CLOEXEC OR SOCK_NONBLOCK OR NONE*/ -+ int type = socket_sys_type(newconn->type) | flags; -+ -+ return posix_api->socket_fn(domain, type, protocol); -+} -+ -+static struct lwip_sock *socket_new_sock(int fd) -+{ -+ struct lwip_sock *sock; -+ -+ sock = lwip_get_socket_nouse(fd); -+ gazelle_init_sock(fd); -+ return sock; -+} -+ -+/* reference tag: alloc_socket() */ -+int gazelle_alloc_socket(struct netconn *newconn, int accepted, int flags) -+{ -+ int fd; -+ struct lwip_sock *sock; -+ -+ fd = socket_new_sysfd(newconn, accepted, flags); -+ if (fd < 0) { -+ return -1; -+ } -+ sock = socket_new_sock(fd); -+ if (sock == NULL) { -+ return -1; -+ } -+ netconn_set_nonblocking(newconn, flags & SOCK_NONBLOCK); -+ -+ sock->conn = newconn; -+ sock->lastdata.pbuf = NULL; -+#if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL -+ LWIP_ASSERT("sock->select_waiting == 0", sock->select_waiting == 0); -+ sock->rcvevent = 0; -+ /* TCP sendbuf is empty, but the socket is not yet writable until connected -+ * (unless it has been created by accept()). */ -+ sock->sendevent = (NETCONNTYPE_GROUP(newconn->type) == NETCONN_TCP ? (accepted != 0) : 1); -+ sock->errevent = 0; -+#endif /* LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL */ -+ -+ return fd; -+} -+ -+/* reference tag: free_socket() */ -+void gazelle_free_socket(struct lwip_sock *sock, int fd) -+{ -+ /* remove sock from same_node_recv_lit */ -+ list_del_node_null(&sock->recv_list); -+ gazelle_clean_sock(fd); -+ posix_api->close_fn(fd); -+} -+ -+void lwip_exit(void) -+{ -+ /* -+ * LwIP has the following two parts of memory application, but -+ * it is unnecessary to release all memory in sequentially, -+ * which increases complexity. Therefore, we rely on the process -+ * reclamation mechanism of the system to release memory. -+ * 1. a sockets table of the process. -+ * 2. a batch of hugepage memory of each thread. -+ */ -+ return; -+} -diff --git a/src/api/sockets.c b/src/api/sockets.c -index f402db8..8a7b9b8 100644 ---- a/src/api/sockets.c -+++ b/src/api/sockets.c -@@ -54,7 +54,6 @@ - #include "lwip/netif.h" - #include "lwip/priv/tcpip_priv.h" - #include "lwip/mld6.h" --#include "lwip/api.h" - #if LWIP_CHECKSUM_ON_COPY - #include "lwip/inet_chksum.h" - #endif -@@ -64,7 +63,6 @@ - #endif - - #if GAZELLE_ENABLE --#include - #include "lwipsock.h" - #include "gazelle_posix_api.h" - #endif -@@ -93,15 +91,16 @@ - #define API_SELECT_CB_VAR_FREE(name) API_VAR_FREE(MEMP_SELECT_CB, name) - - #if LWIP_IPV4 --#if GAZELLE_ENABLE -+#if !GAZELLE_ENABLE -+/* Consistent with kernel definitions */ - #define IP4ADDR_PORT_TO_SOCKADDR(sin, ipaddr, port) do { \ -+ (sin)->sin_len = sizeof(struct sockaddr_in); \ - (sin)->sin_family = AF_INET; \ - (sin)->sin_port = lwip_htons((port)); \ - inet_addr_from_ip4addr(&(sin)->sin_addr, ipaddr); \ - memset((sin)->sin_zero, 0, SIN_ZERO_LEN); }while(0) --#else -+#else /* GAZELLE_ENABLE */ - #define IP4ADDR_PORT_TO_SOCKADDR(sin, ipaddr, port) do { \ -- (sin)->sin_len = sizeof(struct sockaddr_in); \ - (sin)->sin_family = AF_INET; \ - (sin)->sin_port = lwip_htons((port)); \ - inet_addr_from_ip4addr(&(sin)->sin_addr, ipaddr); \ -@@ -272,11 +271,10 @@ static void lwip_socket_drop_registered_mld6_memberships(int s); - #endif /* LWIP_IPV6_MLD */ - - /** The global array of available sockets */ --#if GAZELLE_ENABLE --uint32_t sockets_num; --struct lwip_sock *sockets; --#else -+#if !GAZELLE_ENABLE - static struct lwip_sock sockets[NUM_SOCKETS]; -+#else /* GAZELLE_ENABLE */ -+struct lwip_sock sockets[NUM_SOCKETS]; - #endif /* GAZELLE_ENABLE */ - - #if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL -@@ -305,7 +303,7 @@ static struct lwip_select_cb *select_cb_list; - - /* Forward declaration of some functions */ - #if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL --void event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len); -+static void event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len); - #define DEFAULT_SOCKET_EVENTCB event_callback - static void select_check_waiters(int s, int has_recvevent, int has_sendevent, int has_errevent); - #else -@@ -431,19 +429,20 @@ static struct lwip_sock * - tryget_socket_unconn_nouse(int fd) - { - int s = fd - LWIP_SOCKET_OFFSET; -- --#if GAZELLE_ENABLE -- if ((s < 0) || (s >= sockets_num)) --#else -- if ((s < 0) || (s >= NUM_SOCKETS)) --#endif /* GAZELLE_ENABLE */ -- { -+ if ((s < 0) || (s >= NUM_SOCKETS)) { - LWIP_DEBUGF(SOCKETS_DEBUG, ("tryget_socket_unconn(%d): invalid\n", fd)); - return NULL; - } - return &sockets[s]; - } - -+#if GAZELLE_ENABLE -+struct lwip_sock *lwip_get_socket_nouse(int fd) -+{ -+ return tryget_socket_unconn_nouse(fd); -+} -+#endif /* GAZELLE_ENABLE */ -+ - struct lwip_sock * - lwip_socket_dbg_get_socket(int fd) - { -@@ -501,13 +500,8 @@ tryget_socket(int fd) - * @param fd externally used socket index - * @return struct lwip_sock for the socket or NULL if not found - */ --#if GAZELLE_ENABLE --struct lwip_sock * --get_socket(int fd) --#else - static struct lwip_sock * - get_socket(int fd) --#endif /* GAZELLE_ENABLE */ - { - struct lwip_sock *sock = tryget_socket(fd); - if (!sock) { -@@ -520,108 +514,22 @@ get_socket(int fd) - return sock; - } - --#if GAZELLE_ENABLE --/** -- * Map a externally used socket index to the internal socket representation. -- * -- * @param s externally used socket index -- * @return struct lwip_sock for the socket or NULL if not found without -- * checking. -- */ --struct lwip_sock * --get_socket_by_fd(int fd) --{ -- if ((fd < LWIP_SOCKET_OFFSET) || (fd >= sockets_num + LWIP_SOCKET_OFFSET)) { -- return NULL; -- } -- return &sockets[fd - LWIP_SOCKET_OFFSET]; --} --#endif /* GAZELLE_ENABLE */ -- - /** - * Allocate a new socket for a given netconn. - * - * @param newconn the netconn for which to allocate a socket - * @param accepted 1 if socket has been created by accept(), - * 0 if socket has been created by socket() -- * @param flags only support SOCK_CLOEXEC and SOCK_NONBLOCK - * @return the index of the new socket; -1 on error - */ -+#if !GAZELLE_ENABLE - static int --alloc_socket(struct netconn *newconn, int accepted, int flags) -+alloc_socket(struct netconn *newconn, int accepted) - { - int i; - SYS_ARCH_DECL_PROTECT(lev); - LWIP_UNUSED_ARG(accepted); - --#if GAZELLE_ENABLE -- int type, protocol = 0, domain = AF_INET; -- switch (NETCONNTYPE_GROUP(newconn->type)) { -- case NETCONN_RAW: -- type = SOCK_RAW; -- break; -- case NETCONN_UDPLITE: -- case NETCONN_UDP: -- type = SOCK_DGRAM; -- break; -- case NETCONN_TCP: -- type = SOCK_STREAM; -- break; -- default: -- type = -1; -- break; -- } -- -- /*add CLOEXEC OR NONBLOCK OR NONE*/ -- type |= flags; -- -- SYS_ARCH_PROTECT(lev); -- i = posix_api->socket_fn(domain, type, protocol); -- if (i == -1) { -- goto err; -- } -- -- if ((flags & O_NONBLOCK) != 0){ -- netconn_set_nonblocking(newconn, flags & O_NONBLOCK); -- } -- -- if ((i < LWIP_SOCKET_OFFSET) || (i >= sockets_num + LWIP_SOCKET_OFFSET)) { -- goto err; -- } -- -- if (!sockets[i].conn && (sockets[i].select_waiting == 0)) { -- /*initialize state as NETCONN_HOST | NETCONN_LIBOS, -- *if connection accepted and alloc_socket called, it can be only NETCONN_LIBOS*/ -- if (accepted) -- SET_CONN_TYPE_LIBOS(newconn); -- else -- SET_CONN_TYPE_LIBOS_OR_HOST(newconn); -- sockets[i].conn = newconn; -- /* The socket is not yet known to anyone, so no need to protect -- after having marked it as used. */ -- SYS_ARCH_UNPROTECT(lev); -- sockets[i].lastdata.pbuf = NULL; -- sockets[i].rcvevent = 0; -- /* TCP sendbuf is empty, but the socket is not yet writable until connected -- * (unless it has been created by accept()). */ -- sockets[i].sendevent = (NETCONNTYPE_GROUP(newconn->type) == NETCONN_TCP ? (accepted != 0) : 1); -- sockets[i].errevent = 0; -- sockets[i].same_node_rx_ring = NULL; -- sockets[i].same_node_rx_ring_mz = NULL; -- sockets[i].same_node_tx_ring = NULL; -- sockets[i].same_node_tx_ring_mz = NULL; -- return i + LWIP_SOCKET_OFFSET; -- } else { -- lwip_close(i); -- gazelle_clean_sock(i); -- } -- --err: -- posix_api->close_fn(i); -- SYS_ARCH_UNPROTECT(lev); -- return -1; --#else /* GAZELLE_ENABLE */ -- - /* allocate a new socket identifier */ - for (i = 0; i < NUM_SOCKETS; ++i) { - /* Protect socket array */ -@@ -653,9 +561,8 @@ err: - SYS_ARCH_UNPROTECT(lev); - } - return -1; -- --#endif /* GAZELLE_ENABLE */ - } -+#endif /* GAZELLE_ENABLE */ - - /** Free a socket (under lock) - * -@@ -721,11 +628,6 @@ free_socket(struct lwip_sock *sock, int is_tcp) - /* Protect socket array */ - SYS_ARCH_PROTECT(lev); - --#if GAZELLE_ENABLE -- /* remove sock from same_node_recv_lit */ -- list_del_node_null(&sock->recv_list); --#endif -- - freed = free_socket_locked(sock, is_tcp, &conn, &lastdata); - SYS_ARCH_UNPROTECT(lev); - /* don't use 'sock' after this line, as another task might have allocated it */ -@@ -754,7 +656,6 @@ lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) - SYS_ARCH_DECL_PROTECT(lev); - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d)...\n", s)); -- - sock = get_socket(s); - if (!sock) { - return -1; -@@ -776,21 +677,19 @@ lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) - } - LWIP_ASSERT("newconn != NULL", newconn != NULL); - -- newsock = alloc_socket(newconn, 1, flags); -+#if !GAZELLE_ENABLE -+ newsock = alloc_socket(newconn, 1); -+#else -+ newsock = gazelle_alloc_socket(newconn, 1, flags); -+#endif - if (newsock == -1) { - netconn_delete(newconn); - sock_set_errno(sock, ENFILE); - done_socket(sock); - return -1; - } --#if GAZELLE_ENABLE -- LWIP_ASSERT("invalid socket index", (newsock >= LWIP_SOCKET_OFFSET) && (newsock < sockets_num + LWIP_SOCKET_OFFSET)); -- gazelle_init_sock(newsock); --#else - LWIP_ASSERT("invalid socket index", (newsock >= LWIP_SOCKET_OFFSET) && (newsock < NUM_SOCKETS + LWIP_SOCKET_OFFSET)); --#endif /* GAZELLE_ENABLE */ - nsock = &sockets[newsock - LWIP_SOCKET_OFFSET]; --#if GAZELLE_ENABLE - struct tcp_pcb *pcb = newconn->pcb.tcp; - if (pcb->client_rx_ring != NULL && pcb->client_tx_ring != NULL) { - if (find_same_node_memzone(pcb, nsock) != 0) { -@@ -801,7 +700,6 @@ lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) - return -1; - } - } --#endif - - /* See event_callback: If data comes in right away after an accept, even - * though the server task might not have created a new socket yet. -@@ -832,6 +730,9 @@ lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) - if (err != ERR_OK) { - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d): netconn_peer failed, err=%d\n", s, err)); - free_socket(nsock, 1); -+#if GAZELLE_ENABLE -+ gazelle_free_socket(nsock, newsock); -+#endif /* GAZELLE_ENABLE */ - sock_set_errno(sock, err_to_errno(err)); - done_socket(sock); - return -1; -@@ -843,7 +744,7 @@ lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) - *addrlen = tempaddr.sa.sa_len; - } - #else -- *addrlen = LWIP_MIN(*addrlen, sizeof(tempaddr)); -+ *addrlen = LWIP_MIN(*addrlen, sizeof(tempaddr)); - #endif /* GAZELLE_ENABLE */ - MEMCPY(addr, &tempaddr, *addrlen); - -@@ -854,6 +755,9 @@ lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d) returning new sock=%d", s, newsock)); - } - -+#if GAZELLE_ENABLE -+ POSIX_SET_TYPE(nsock, POSIX_LWIP); -+#endif /* GAZELLE_ENABLE */ - sock_set_errno(sock, 0); - done_socket(sock); - done_socket(nsock); -@@ -957,6 +861,9 @@ lwip_close(int s) - } - - free_socket(sock, is_tcp); -+#if GAZELLE_ENABLE -+ gazelle_free_socket(sock, s); -+#endif /* GAZELLE_ENABLE */ - set_errno(0); - return 0; - } -@@ -1016,8 +923,7 @@ lwip_connect(int s, const struct sockaddr *name, socklen_t namelen) - } - - #if GAZELLE_ENABLE -- LWIP_DEBUGF(SOCKETS_DEBUG, ("libos connect succeed fd=%d\n",s)); -- SET_CONN_TYPE_LIBOS(sock->conn); -+ POSIX_SET_TYPE(sock, POSIX_LWIP); - #endif /* GAZELLE_ENABLE */ - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d) succeeded\n", s)); -@@ -1166,7 +1072,6 @@ lwip_recv_tcp(struct lwip_sock *sock, void *mem, size_t len, int flags) - apiflags |= NETCONN_DONTBLOCK | NETCONN_NOFIN; - /* @todo: do we need to support peeking more than one pbuf? */ - } while ((recv_left > 0) && !(flags & MSG_PEEK)); -- - lwip_recv_tcp_done: - #else /* GAZELLE_ENABLE */ - LWIP_UNUSED_ARG(recv_left); -@@ -1181,7 +1086,6 @@ lwip_recv_tcp_done: - netconn_tcp_recvd(sock->conn, (size_t)recvd); - } - } -- - sock_set_errno(sock, 0); - return recvd; - } -@@ -1423,7 +1327,6 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags, - done_socket(sock); - return -1; - } -- - ret = (ssize_t)LWIP_MIN(LWIP_MIN(len, datagram_len), SSIZE_MAX); - if (fromlen) { - *fromlen = msg.msg_namelen; -@@ -1876,12 +1779,8 @@ lwip_socket(int domain, int type, int protocol) - - LWIP_UNUSED_ARG(domain); /* @todo: check this */ - -- int flags = type & ~SOCK_TYPE_MASK; -- type &= SOCK_TYPE_MASK; -- -- - /* create a netconn */ -- switch (type) { -+ switch (type & SOCK_TYPE_MASK) { - case SOCK_RAW: - conn = netconn_new_with_proto_and_callback(DOMAIN_TO_NETCONN_TYPE(domain, NETCONN_RAW), - (u8_t)protocol, DEFAULT_SOCKET_EVENTCB); -@@ -1919,15 +1818,11 @@ lwip_socket(int domain, int type, int protocol) - return -1; - } - -- if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK)){ -- set_errno(EINVAL); -- return -1; -- } -- -- if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK)) -- flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK; -- -- i = alloc_socket(conn, 0, flags); -+#if !GAZELLE_ENABLE -+ i = alloc_socket(conn, 0); -+#else -+ i = gazelle_alloc_socket(conn, 0, type); -+#endif - - if (i == -1) { - netconn_delete(conn); -@@ -2679,7 +2574,7 @@ lwip_poll_should_wake(const struct lwip_select_cb *scb, int fd, int has_recveven - * NETCONN_EVT_ERROR - * This requirement will be asserted in select_check_waiters() - */ --void -+static void - event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len) - { - int s, check_waiters; -@@ -2977,13 +2872,12 @@ int - lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) - { - int err; -+ struct lwip_sock *sock = get_socket(s); - #if !LWIP_TCPIP_CORE_LOCKING - err_t cberr; - LWIP_SETGETSOCKOPT_DATA_VAR_DECLARE(data); - #endif /* !LWIP_TCPIP_CORE_LOCKING */ - -- struct lwip_sock *sock = get_socket(s); -- - if (!sock) { - return -1; - } -@@ -3428,13 +3322,12 @@ int - lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) - { - int err = 0; -+ struct lwip_sock *sock = get_socket(s); - #if !LWIP_TCPIP_CORE_LOCKING - err_t cberr; - LWIP_SETGETSOCKOPT_DATA_VAR_DECLARE(data); - #endif /* !LWIP_TCPIP_CORE_LOCKING */ - -- struct lwip_sock *sock = get_socket(s); -- - if (!sock) { - return -1; - } -@@ -3968,7 +3861,7 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_ - int - lwip_ioctl(int s, long cmd, ...) - { -- struct lwip_sock *sock = posix_api->get_socket(s); -+ struct lwip_sock *sock = get_socket(s); - u8_t val; - - #if LWIP_SO_RCVBUF -@@ -3986,7 +3879,7 @@ lwip_ioctl(int s, long cmd, ...) - if (!sock) { - return posix_api->ioctl_fn(s, cmd, argp); - } -- if (CONN_TYPE_HAS_HOST(sock->conn)) { -+ if (POSIX_HAS_TYPE(sock, POSIX_KERNEL)) { - if ((ret = posix_api->ioctl_fn(s, cmd, argp)) == -1) - return ret; - } -@@ -4415,31 +4308,4 @@ lwip_socket_drop_registered_mld6_memberships(int s) - } - #endif /* LWIP_IPV6_MLD */ - --#if GAZELLE_ENABLE --void lwip_sock_init(void) --{ -- if (sockets_num == 0) { -- sockets_num = NUM_SOCKETS; -- sockets = calloc(sockets_num, sizeof(struct lwip_sock)); -- LWIP_ASSERT("sockets != NULL", sockets != NULL); -- memset(sockets, 0, sockets_num * sizeof(struct lwip_sock)); -- } -- return; --} -- --void lwip_exit(void) --{ -- /* -- * LwIP has the following two parts of memory application, but -- * it is unnecessary to release all memory in sequentially, -- * which increases complexity. Therefore, we rely on the process -- * reclamation mechanism of the system to release memory. -- * 1. a sockets table of the process. -- * 2. a batch of hugepage memory of each thread. -- */ -- return; --} -- --#endif /* GAZELLE_ENABLE */ -- - #endif /* LWIP_SOCKET */ -diff --git a/src/core/pbuf.c b/src/core/pbuf.c -index aae6008..16615c6 100644 ---- a/src/core/pbuf.c -+++ b/src/core/pbuf.c -@@ -86,6 +86,7 @@ - #endif - #if GAZELLE_ENABLE - #include -+extern void gazelle_free_pbuf(struct pbuf *pbuf); - #endif - - #include -diff --git a/src/core/tcp.c b/src/core/tcp.c -index 3abf63b..6a9c9fe 100644 ---- a/src/core/tcp.c -+++ b/src/core/tcp.c -@@ -258,7 +258,7 @@ tcp_free(struct tcp_pcb *pcb) - rte_ring_free(pcb->client_rx_ring); - rte_ring_free(pcb->client_tx_ring); - netconn = (struct netconn *)pcb->callback_arg; -- sock = get_socket(netconn->socket); -+ sock = lwip_get_socket_nouse(netconn->socket); - rte_memzone_free(sock->same_node_rx_ring->mz); - rte_memzone_free(sock->same_node_rx_ring_mz); - rte_memzone_free(sock->same_node_tx_ring->mz); -diff --git a/src/include/gazelle_posix_api.h b/src/include/gazelle_posix_api.h -index 0bed1de..6df414b 100644 ---- a/src/include/gazelle_posix_api.h -+++ b/src/include/gazelle_posix_api.h -@@ -71,10 +71,8 @@ typedef struct { - int (*epoll_create1_fn)(int size); - int (*epoll_ctl_fn)(int epfd, int op, int fd, struct epoll_event *event); - int (*epoll_wait_fn)(int epfd, struct epoll_event *events, int maxevents, int timeout); -- int (*epoll_close_fn)(int epfd); - int (*eventfd_fn)(unsigned int initval, int flags); - int (*is_epfd)(int fd); -- struct lwip_sock* (*get_socket)(int fd); - int (*sigaction_fn)(int signum, const struct sigaction *act, struct sigaction *oldact); - int (*poll_fn)(struct pollfd *fds, nfds_t nfds, int timeout); - int (*ioctl_fn)(int fd, int cmd, ...); -diff --git a/src/include/lwip/api.h b/src/include/lwip/api.h -index 197faef..d3c4f02 100644 ---- a/src/include/lwip/api.h -+++ b/src/include/lwip/api.h -@@ -140,43 +140,8 @@ enum netconn_type { - /** Raw connection IPv6 (dual-stack by default, unless you call @ref netconn_set_ipv6only) */ - , NETCONN_RAW_IPV6 = NETCONN_RAW | NETCONN_TYPE_IPV6 /* 0x48 */ - #endif /* LWIP_IPV6 */ -- --#if GAZELLE_ENABLE -- /*here must bigger than 0xff, because (type & 0xff) is for lwip inner use*/ -- , NETCONN_LIBOS = 0x100 -- , NETCONN_HOST = 0x200 -- , NETCONN_INPRG = 0x400 -- , NETCONN_STACK = NETCONN_LIBOS | NETCONN_HOST | NETCONN_INPRG --#endif /* GAZELLE_ENABLE */ - }; - --#ifdef GAZELLE_ENABLE --#define SET_CONN_TYPE_LIBOS_OR_HOST(conn) do { \ -- conn->type &= ~(NETCONN_STACK); \ -- conn->type |= (NETCONN_LIBOS | NETCONN_HOST); } while (0) --#define SET_CONN_TYPE_LIBOS(conn) do { \ -- conn->type &= ~(NETCONN_STACK); \ -- conn->type |= NETCONN_LIBOS; } while (0) --#define SET_CONN_TYPE_HOST(conn) do { \ -- conn->type &= ~(NETCONN_STACK); \ -- conn->type |= NETCONN_HOST; } while (0) --#define ADD_CONN_TYPE_INPRG(conn) do { \ -- conn->type |= NETCONN_INPRG; } while(0) --#define CONN_TYPE_HAS_LIBOS_AND_HOST(conn) ((conn->type & (NETCONN_LIBOS | NETCONN_HOST)) == (NETCONN_LIBOS | NETCONN_HOST)) --#define CONN_TYPE_HAS_LIBOS(conn) (conn->type & NETCONN_LIBOS) --#define CONN_TYPE_HAS_HOST(conn) (conn->type & NETCONN_HOST) --#define CONN_TYPE_HAS_INPRG(conn) (!!(conn->type & NETCONN_INPRG)) --#define CONN_TYPE_IS_LIBOS(conn) (!!(NETCONN_LIBOS == (conn->type & NETCONN_STACK))) --#define CONN_TYPE_IS_HOST(conn) (!!(NETCONN_HOST == (conn->type & NETCONN_STACK))) --#else --#define SET_CONN_TYPE_LIBOS_OR_HOST(conn) do {} while (0) --#define SET_CONN_TYPE_LIBOS(conn) do {} while (0) --#define SET_CONN_TYPE_HOST(conn) do {} while (0) --#define CONN_TYPE_HAS_LIBOS_AND_HOST(conn) (0) --#define CONN_TYPE_HAS_LIBOS(conn) (0) --#define CONN_TYPE_HAS_HOST(conn) (0) --#endif /* GAZELLE_ENABLE */ -- - /** Current state of the netconn. Non-TCP netconns are always - * in state NETCONN_NONE! */ - enum netconn_state { -diff --git a/src/include/lwip/priv/sockets_priv.h b/src/include/lwip/priv/sockets_priv.h -index 7268a17..4b85935 100644 ---- a/src/include/lwip/priv/sockets_priv.h -+++ b/src/include/lwip/priv/sockets_priv.h -@@ -45,7 +45,7 @@ - #include "lwip/sockets.h" - #include "lwip/sys.h" - --/* move some definitions to the lwipsock.h for libnet to use, and -+/* move some definitions to the lwipsock.h for `gazelle` to use, and - * at the same time avoid conflict between lwip/sockets.h and sys/socket.h - */ - #include "lwipsock.h" -diff --git a/src/include/lwipsock.h b/src/include/lwipsock.h -index 1814f76..32ec721 100644 ---- a/src/include/lwipsock.h -+++ b/src/include/lwipsock.h -@@ -33,13 +33,73 @@ - #ifndef _LWIPSOCK_H_ - #define _LWIPSOCK_H_ - --#include - #include "lwip/opt.h" - #include "lwip/api.h" - -+#if GAZELLE_ENABLE -+#include -+#include -+#include - #include "gazelle_event.h" - --/* move some definitions to the lwipsock.h for libnet to use, and -+#define set_errno(err) do { errno = (err); } while(0) -+ -+enum posix_type { -+ POSIX_KERNEL = 0x100, -+ POSIX_LWIP = 0x200, -+ POSIX_EPOLL = 0x400, -+ POSIX_ALL = POSIX_KERNEL | POSIX_LWIP | POSIX_EPOLL, -+ POSIX_LWIP_OR_KERNEL = POSIX_LWIP | POSIX_KERNEL, -+}; -+ -+#define POSIX_SET_TYPE(sock, posix_type) do { \ -+ (sock)->type &= ~(POSIX_ALL); \ -+ (sock)->type |= (posix_type); } while (0) -+ -+#define POSIX_HAS_TYPE(sock, posix_type) \ -+ ((sock)->type & (posix_type)) -+ -+#define POSIX_IS_TYPE(sock, posix_type) \ -+ (((sock)->type & POSIX_ALL) == (posix_type)) -+ -+struct lwip_sock *lwip_get_socket_nouse(int fd); -+int gazelle_alloc_socket(struct netconn *newconn, int accepted, int flags); -+void gazelle_free_socket(struct lwip_sock *sock, int fd); -+void lwip_exit(void); -+ -+struct protocol_stack; -+struct wakeup_poll; -+ -+extern void add_recv_list(int32_t fd); -+extern ssize_t read_lwip_data(struct lwip_sock *sock, int32_t flags, u8_t apiflags); -+extern struct pbuf *write_lwip_data(struct lwip_sock *sock, uint16_t remain_size, uint8_t *apiflags); -+extern void write_lwip_over(struct lwip_sock *sock); -+extern void lstack_calculate_aggregate(int type, uint32_t len); -+ -+extern void netif_poll(struct netif *netif); -+extern err_t netif_loop_output(struct netif *netif, struct pbuf *p); -+ -+ -+// 8M -+#define SAME_NODE_RING_LEN (unsigned long long)(8388608) -+#define SAME_NODE_RING_MASK (unsigned long long)(8388608 - 1) -+#define RING_NAME_LEN 32 -+struct same_node_ring { -+ const struct rte_memzone *mz; -+ unsigned long long sndbegin; -+ unsigned long long sndend; -+}; -+ -+extern err_t find_same_node_memzone(struct tcp_pcb *pcb, struct lwip_sock *nsock); -+extern err_t same_node_memzone_create(const struct rte_memzone **zone, int size, int port, char *name, char *); -+extern err_t same_node_ring_create(struct rte_ring **ring, int size, int port, char *name, char *rx); -+extern err_t create_same_node_ring(struct tcp_pcb *pcb); -+extern err_t find_same_node_ring(struct tcp_pcb *pcb); -+ -+#endif /* GAZELLE_ENABLE */ -+ -+ -+/* move some definitions to the lwipsock.h for `gazelle` to use, and - * at the same time avoid conflict between lwip/sockets.h and sys/socket.h - */ - -@@ -60,24 +120,6 @@ union lwip_sock_lastdata { - struct pbuf *pbuf; - }; - --#if GAZELLE_ENABLE --struct protocol_stack; --struct wakeup_poll; --struct rte_ring; --#include --#include -- --// 8M --#define SAME_NODE_RING_LEN (unsigned long long)(8388608) --#define SAME_NODE_RING_MASK (unsigned long long)(8388608 - 1) --#define RING_NAME_LEN 32 --struct same_node_ring { -- const struct rte_memzone *mz; -- unsigned long long sndbegin; -- unsigned long long sndend; --}; --#endif -- - /** Contains all internal pointers and states used for a socket */ - struct lwip_sock { - /** sockets currently are built on netconns, each socket has one netconn */ -@@ -126,10 +168,11 @@ struct lwip_sock { - - char pad3 __rte_cache_aligned; - /* nerver change */ -- struct wakeup_poll *wakeup; -- epoll_data_t ep_data; -+ enum posix_type type; - struct lwip_sock *listen_next; /* listenfd list */ - struct protocol_stack *stack; -+ struct wakeup_poll *wakeup; -+ epoll_data_t ep_data; - struct rte_ring *recv_ring; - struct rte_ring *send_ring; - -@@ -142,49 +185,8 @@ struct lwip_sock { - #endif - }; - --#if GAZELLE_ENABLE --static inline 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; --} --#endif -- - #ifndef set_errno - #define set_errno(err) do { if (err) { errno = (err); } } while(0) - #endif - -- --/* -------------------------------------------------- -- * --------------- LIBNET references ---------------- -- * -------------------------------------------------- -- */ --#if GAZELLE_ENABLE --extern uint32_t sockets_num; --extern struct lwip_sock *sockets; --extern void gazelle_connected_callback(struct netconn *conn); --extern void add_recv_list(int32_t fd); --extern ssize_t read_lwip_data(struct lwip_sock *sock, int32_t flags, u8_t apiflags); --extern struct pbuf *write_lwip_data(struct lwip_sock *sock, uint16_t remain_size, uint8_t *apiflags); --extern void gazelle_init_sock(int32_t fd); --extern void gazelle_clean_sock(int32_t fd); --extern void write_lwip_over(struct lwip_sock *sock); --extern void netif_poll(struct netif *netif); --extern err_t netif_loop_output(struct netif *netif, struct pbuf *p); --extern err_t find_same_node_memzone(struct tcp_pcb *pcb, struct lwip_sock *nsock); --extern err_t same_node_memzone_create(const struct rte_memzone **zone, int size, int port, char *name, char *); --extern err_t same_node_ring_create(struct rte_ring **ring, int size, int port, char *name, char *rx); --extern err_t create_same_node_ring(struct tcp_pcb *pcb); --extern err_t find_same_node_ring(struct tcp_pcb *pcb); --extern void gazelle_free_pbuf(struct pbuf *pbuf); --extern void lstack_calculate_aggregate(int type, uint32_t len); --#endif /* GAZELLE_ENABLE */ -- --struct lwip_sock *get_socket(int s); --struct lwip_sock *get_socket_by_fd(int s); --void lwip_sock_init(void); --void lwip_exit(void); -- - #endif /* _LWIPSOCK_H_ */ --- -2.22.0.windows.1 - diff --git a/0066-cleancode-refactor-gazelle_posix_api.h.patch b/0066-cleancode-refactor-gazelle_posix_api.h.patch deleted file mode 100644 index 6bf1a1b..0000000 --- a/0066-cleancode-refactor-gazelle_posix_api.h.patch +++ /dev/null @@ -1,247 +0,0 @@ -From fd9219c855b9f9286c2412deba3dbedd7c3e96e3 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Mon, 22 May 2023 14:37:14 +0800 -Subject: [PATCH] cleancode: refactor gazelle_posix_api.h - -Signed-off-by: Lemmy Huang ---- - src/api/gazelle_posix_api.c | 106 +++++++++++++++----------------- - src/include/gazelle_posix_api.h | 63 ++++++++++--------- - 2 files changed, 81 insertions(+), 88 deletions(-) - -diff --git a/src/api/gazelle_posix_api.c b/src/api/gazelle_posix_api.c -index 219769a..1bff6d9 100644 ---- a/src/api/gazelle_posix_api.c -+++ b/src/api/gazelle_posix_api.c -@@ -31,38 +31,24 @@ - */ - - #include --#include --#include -+// #include -+// #include -+// #include - #include --#include --#include -- --#include -- --#include "lwip/err.h" --#include "lwipsock.h" - #include "gazelle_posix_api.h" - --posix_api_t *posix_api; --posix_api_t posix_api_val; -- --static int chld_is_epfd(int fd) --{ -- return 0; --} -+posix_api_t *posix_api = NULL; -+static posix_api_t posix_api_val; - - void posix_api_fork(void) - { - /* lstack helper api */ -- posix_api->ues_posix = 1; -- posix_api->is_epfd = chld_is_epfd; -+ posix_api->use_kernel = 1; - } - -- - int posix_api_init(void) - { --/* the symbol we use here won't be NULL, so we don't need dlerror() -- to test error */ -+/* the symbol we use here won't be NULL, so we don't need dlerror() to test error */ - #define CHECK_DLSYM_RET_RETURN(ret) do { \ - if ((ret) == NULL) \ - goto err_out; \ -@@ -73,46 +59,50 @@ int posix_api_init(void) - void *__restrict handle = RTLD_NEXT; - - /* glibc standard api */ -- CHECK_DLSYM_RET_RETURN(posix_api->socket_fn = dlsym(handle, "socket")); -- CHECK_DLSYM_RET_RETURN(posix_api->accept_fn = dlsym(handle, "accept")); -- CHECK_DLSYM_RET_RETURN(posix_api->accept4_fn = dlsym(handle, "accept4")); -- CHECK_DLSYM_RET_RETURN(posix_api->bind_fn = dlsym(handle, "bind")); -- CHECK_DLSYM_RET_RETURN(posix_api->listen_fn = dlsym(handle, "listen")); -- CHECK_DLSYM_RET_RETURN(posix_api->connect_fn = dlsym(handle, "connect")); -- CHECK_DLSYM_RET_RETURN(posix_api->setsockopt_fn = dlsym(handle, "setsockopt")); -- CHECK_DLSYM_RET_RETURN(posix_api->getsockopt_fn = dlsym(handle, "getsockopt")); -- CHECK_DLSYM_RET_RETURN(posix_api->getpeername_fn = dlsym(handle, "getpeername")); -- CHECK_DLSYM_RET_RETURN(posix_api->getsockname_fn = dlsym(handle, "getsockname")); -- CHECK_DLSYM_RET_RETURN(posix_api->shutdown_fn = dlsym(handle, "shutdown")); -- CHECK_DLSYM_RET_RETURN(posix_api->close_fn = dlsym(handle, "close")); -- CHECK_DLSYM_RET_RETURN(posix_api->read_fn = dlsym(handle, "read")); -- CHECK_DLSYM_RET_RETURN(posix_api->readv_fn = dlsym(handle, "readv")); -- CHECK_DLSYM_RET_RETURN(posix_api->write_fn = dlsym(handle, "write")); -- CHECK_DLSYM_RET_RETURN(posix_api->writev_fn = dlsym(handle, "writev")); -- CHECK_DLSYM_RET_RETURN(posix_api->recv_fn = dlsym(handle, "recv")); -- CHECK_DLSYM_RET_RETURN(posix_api->send_fn = dlsym(handle, "send")); -- CHECK_DLSYM_RET_RETURN(posix_api->recv_msg = dlsym(handle, "recvmsg")); -- CHECK_DLSYM_RET_RETURN(posix_api->send_msg = dlsym(handle, "sendmsg")); -- CHECK_DLSYM_RET_RETURN(posix_api->recv_from = dlsym(handle, "recvfrom")); -- CHECK_DLSYM_RET_RETURN(posix_api->send_to = dlsym(handle, "sendto")); -- CHECK_DLSYM_RET_RETURN(posix_api->fcntl_fn = dlsym(handle, "fcntl")); -- CHECK_DLSYM_RET_RETURN(posix_api->fcntl64_fn = dlsym(handle, "fcntl64")); -- CHECK_DLSYM_RET_RETURN(posix_api->pipe_fn = dlsym(handle, "pipe")); -- CHECK_DLSYM_RET_RETURN(posix_api->epoll_create_fn = dlsym(handle, "epoll_create")); -- CHECK_DLSYM_RET_RETURN(posix_api->epoll_create1_fn = dlsym(handle, "epoll_create1")); -- CHECK_DLSYM_RET_RETURN(posix_api->epoll_ctl_fn = dlsym(handle, "epoll_ctl")); -- CHECK_DLSYM_RET_RETURN(posix_api->epoll_wait_fn = dlsym(handle, "epoll_wait")); -- CHECK_DLSYM_RET_RETURN(posix_api->fork_fn = dlsym(handle, "fork")); -- CHECK_DLSYM_RET_RETURN(posix_api->eventfd_fn = dlsym(handle, "eventfd")); -- CHECK_DLSYM_RET_RETURN(posix_api->sigaction_fn = dlsym(handle, "sigaction")); -- CHECK_DLSYM_RET_RETURN(posix_api->poll_fn = dlsym(handle, "poll")); -- CHECK_DLSYM_RET_RETURN(posix_api->ioctl_fn = dlsym(handle, "ioctl")); -+ CHECK_DLSYM_RET_RETURN(posix_api->shutdown_fn = dlsym(handle, "shutdown")); -+ CHECK_DLSYM_RET_RETURN(posix_api->close_fn = dlsym(handle, "close")); -+ CHECK_DLSYM_RET_RETURN(posix_api->socket_fn = dlsym(handle, "socket")); -+ CHECK_DLSYM_RET_RETURN(posix_api->connect_fn = dlsym(handle, "connect")); -+ CHECK_DLSYM_RET_RETURN(posix_api->bind_fn = dlsym(handle, "bind")); -+ CHECK_DLSYM_RET_RETURN(posix_api->listen_fn = dlsym(handle, "listen")); -+ CHECK_DLSYM_RET_RETURN(posix_api->accept_fn = dlsym(handle, "accept")); -+ CHECK_DLSYM_RET_RETURN(posix_api->accept4_fn = dlsym(handle, "accept4")); -+ -+ CHECK_DLSYM_RET_RETURN(posix_api->getpeername_fn = dlsym(handle, "getpeername")); -+ CHECK_DLSYM_RET_RETURN(posix_api->getsockname_fn = dlsym(handle, "getsockname")); -+ CHECK_DLSYM_RET_RETURN(posix_api->getsockopt_fn = dlsym(handle, "getsockopt")); -+ CHECK_DLSYM_RET_RETURN(posix_api->setsockopt_fn = dlsym(handle, "setsockopt")); -+ -+ CHECK_DLSYM_RET_RETURN(posix_api->read_fn = dlsym(handle, "read")); -+ CHECK_DLSYM_RET_RETURN(posix_api->write_fn = dlsym(handle, "write")); -+ CHECK_DLSYM_RET_RETURN(posix_api->readv_fn = dlsym(handle, "readv")); -+ CHECK_DLSYM_RET_RETURN(posix_api->writev_fn = dlsym(handle, "writev")); -+ CHECK_DLSYM_RET_RETURN(posix_api->recv_fn = dlsym(handle, "recv")); -+ CHECK_DLSYM_RET_RETURN(posix_api->send_fn = dlsym(handle, "send")); -+ CHECK_DLSYM_RET_RETURN(posix_api->recvmsg_fn = dlsym(handle, "recvmsg")); -+ CHECK_DLSYM_RET_RETURN(posix_api->sendmsg_fn = dlsym(handle, "sendmsg")); -+ CHECK_DLSYM_RET_RETURN(posix_api->recvfrom_fn = dlsym(handle, "recvfrom")); -+ CHECK_DLSYM_RET_RETURN(posix_api->sendto_fn = dlsym(handle, "sendto")); -+ -+ CHECK_DLSYM_RET_RETURN(posix_api->poll_fn = dlsym(handle, "poll")); -+ CHECK_DLSYM_RET_RETURN(posix_api->epoll_create_fn = dlsym(handle, "epoll_create")); -+ CHECK_DLSYM_RET_RETURN(posix_api->epoll_create1_fn = dlsym(handle, "epoll_create1")); -+ CHECK_DLSYM_RET_RETURN(posix_api->epoll_ctl_fn = dlsym(handle, "epoll_ctl")); -+ CHECK_DLSYM_RET_RETURN(posix_api->epoll_wait_fn = dlsym(handle, "epoll_wait")); -+ CHECK_DLSYM_RET_RETURN(posix_api->eventfd_fn = dlsym(handle, "eventfd")); -+ -+ CHECK_DLSYM_RET_RETURN(posix_api->ioctl_fn = dlsym(handle, "ioctl")); -+ CHECK_DLSYM_RET_RETURN(posix_api->fcntl_fn = dlsym(handle, "fcntl")); -+ CHECK_DLSYM_RET_RETURN(posix_api->fcntl64_fn = dlsym(handle, "fcntl64")); -+ -+ CHECK_DLSYM_RET_RETURN(posix_api->sigaction_fn = dlsym(handle, "sigaction")); -+ CHECK_DLSYM_RET_RETURN(posix_api->fork_fn = dlsym(handle, "fork")); - - /* support fork */ -- posix_api->ues_posix = 1; -- return ERR_OK; -+ posix_api->use_kernel = 1; -+ return 0; - - err_out: -- return ERR_MEM; -+ return -1; - #undef CHECK_DLSYM_RET_RETURN - } -diff --git a/src/include/gazelle_posix_api.h b/src/include/gazelle_posix_api.h -index 6df414b..e9a7633 100644 ---- a/src/include/gazelle_posix_api.h -+++ b/src/include/gazelle_posix_api.h -@@ -33,57 +33,60 @@ - #ifndef _GAZELLE_POSIX_API_H_ - #define _GAZELLE_POSIX_API_H_ - -+#include - #include - #include - #include - #include -+// #include - - typedef struct { -- void *handle; -- int (*socket_fn)(int domain, int type, int protocol); -- int (*accept_fn)(int s, struct sockaddr*, socklen_t*); -- int (*accept4_fn)(int s, struct sockaddr *addr, socklen_t *addrlen, int flags); -- int (*bind_fn)(int s, const struct sockaddr*, socklen_t); -- int (*listen_fn)(int s, int backlog); -- int (*connect_fn)(int s, const struct sockaddr *name, socklen_t namelen); -- int (*getpeername_fn)(int s, struct sockaddr *name, socklen_t *namelen); -- int (*getsockname_fn)(int s, struct sockaddr *name, socklen_t *namelen); -- int (*setsockopt_fn)(int s, int level, int optname, const void *optval, socklen_t optlen); -- int (*getsockopt_fn)(int s, int level, int optname, void *optval, socklen_t *optlen); -- int (*shutdown_fn)(int s, int how); -+ int (*shutdown_fn)(int fd, int how); - int (*close_fn)(int fd); -- pid_t (*fork_fn)(void); -+ int (*socket_fn)(int domain, int type, int protocol); -+ int (*connect_fn)(int fd, const struct sockaddr *name, socklen_t namelen); -+ int (*bind_fn)(int fd, const struct sockaddr*, socklen_t); -+ int (*listen_fn)(int fd, int backlog); -+ int (*accept_fn)(int fd, struct sockaddr*, socklen_t*); -+ int (*accept4_fn)(int fd, struct sockaddr *addr, socklen_t *addrlen, int flags); -+ -+ int (*getpeername_fn)(int fd, struct sockaddr *name, socklen_t *namelen); -+ int (*getsockname_fn)(int fd, struct sockaddr *name, socklen_t *namelen); -+ int (*getsockopt_fn)(int fd, int level, int optname, void *optval, socklen_t *optlen); -+ int (*setsockopt_fn)(int fd, int level, int optname, const void *optval, socklen_t optlen); -+ - ssize_t (*read_fn)(int fd, void *mem, size_t len); -- ssize_t (*readv_fn)(int s, const struct iovec *iov, int iovcnt); - ssize_t (*write_fn)(int fd, const void *data, size_t len); -- ssize_t (*writev_fn)(int s, const struct iovec *iov, int iovcnt); -- ssize_t (*recv_fn)(int sockfd, void *buf, size_t len, int flags); -- ssize_t (*send_fn)(int sockfd, const void *buf, size_t len, int flags); -- ssize_t (*recv_msg)(int sockfd, const struct msghdr *msg, int flags); -- ssize_t (*send_msg)(int sockfd, const struct msghdr *msg, int flags); -- ssize_t (*recv_from)(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen); -- ssize_t (*send_to)(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, -- socklen_t addrlen); -- int (*fcntl_fn)(int fd, int cmd, ...); -- int (*fcntl64_fn)(int fd, int cmd, ...); -- int (*pipe_fn)(int pipefd[2]); -+ ssize_t (*readv_fn)(int fd, const struct iovec *iov, int iovcnt); -+ ssize_t (*writev_fn)(int fd, const struct iovec *iov, int iovcnt); -+ ssize_t (*recv_fn)(int fd, void *buf, size_t len, int flags); -+ ssize_t (*send_fn)(int fd, const void *buf, size_t len, int flags); -+ ssize_t (*recvmsg_fn)(int fd, const struct msghdr *msg, int flags); -+ ssize_t (*sendmsg_fn)(int fd, const struct msghdr *msg, int flags); -+ ssize_t (*recvfrom_fn)(int fd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen); -+ ssize_t (*sendto_fn)(int fd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen); -+ -+ int (*poll_fn)(struct pollfd *fds, nfds_t nfds, int timeout); - int (*epoll_create_fn)(int size); - int (*epoll_create1_fn)(int size); - int (*epoll_ctl_fn)(int epfd, int op, int fd, struct epoll_event *event); - int (*epoll_wait_fn)(int epfd, struct epoll_event *events, int maxevents, int timeout); -+ int (*epoll_close_fn)(int epfd); - int (*eventfd_fn)(unsigned int initval, int flags); -- int (*is_epfd)(int fd); -- int (*sigaction_fn)(int signum, const struct sigaction *act, struct sigaction *oldact); -- int (*poll_fn)(struct pollfd *fds, nfds_t nfds, int timeout); -+ - int (*ioctl_fn)(int fd, int cmd, ...); -+ int (*fcntl_fn)(int fd, int cmd, ...); -+ int (*fcntl64_fn)(int fd, int cmd, ...); -+ -+ int (*sigaction_fn)(int signum, const struct sigaction *act, struct sigaction *oldact); -+ pid_t (*fork_fn)(void); - -- int ues_posix; -+ int use_kernel; - } posix_api_t; - - extern posix_api_t *posix_api; - - int posix_api_init(void); --void posix_api_free(void); - void posix_api_fork(void); - - #endif /* _GAZELLE_POSIX_API_H_ */ --- -2.22.0.windows.1 - diff --git a/0067-cleancode-refactor-gazelle_list.h.patch b/0067-cleancode-refactor-gazelle_list.h.patch deleted file mode 100644 index 6e0d12b..0000000 --- a/0067-cleancode-refactor-gazelle_list.h.patch +++ /dev/null @@ -1,158 +0,0 @@ -From 3a69e52c7b1e256274ee0d852543e2f89bd7b902 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Mon, 22 May 2023 21:00:28 +0800 -Subject: [PATCH 1/2] cleancode: refactor gazelle_list.h - -Signed-off-by: Lemmy Huang ---- - src/api/gazelle_sock.c | 2 - - src/include/gazelle_list.h | 93 ++++++++++++++++++++------------------ - 2 files changed, 48 insertions(+), 47 deletions(-) - -diff --git a/src/api/gazelle_sock.c b/src/api/gazelle_sock.c -index 1164485..3d3d65f 100644 ---- a/src/api/gazelle_sock.c -+++ b/src/api/gazelle_sock.c -@@ -114,8 +114,6 @@ int gazelle_alloc_socket(struct netconn *newconn, int accepted, int flags) - /* reference tag: free_socket() */ - void gazelle_free_socket(struct lwip_sock *sock, int fd) - { -- /* remove sock from same_node_recv_lit */ -- list_del_node_null(&sock->recv_list); - gazelle_clean_sock(fd); - posix_api->close_fn(fd); - } -diff --git a/src/include/gazelle_list.h b/src/include/gazelle_list.h -index a40c17f..a9ed235 100644 ---- a/src/include/gazelle_list.h -+++ b/src/include/gazelle_list.h -@@ -33,78 +33,81 @@ - #ifndef _GAZELLE_LIST_H_ - #define _GAZELLE_LIST_H_ - --#ifndef NULL --#ifdef __cplusplus --#define NULL 0 --#else --#define NULL ((void *)0) --#endif --#endif -- -+/* double circular linked list */ - struct list_node { - struct list_node *prev; - struct list_node *next; - }; - --static inline void init_list_node_null(struct list_node *n) -+#ifndef container_of -+#define container_of(ptr, type, member) ({ \ -+ typeof( ((type *)0)->member ) *__mptr = (ptr); \ -+ (type *)((char *)__mptr - offsetof(type,member)); }) -+#endif /* container_of */ -+ -+#define list_entry(ptr, type, member) \ -+ container_of(ptr, type, member) -+ -+#define list_for_each_node(node, n, head) \ -+ for (node = (head)->next, n = (node)->next; \ -+ node != (head); \ -+ node = n, n = (node)->next) -+ -+static inline unsigned list_get_count(const struct list_node *h) - { -- n->prev = NULL; -- n->next = NULL; -+ const struct list_node *node, *n; -+ unsigned count = 0; -+ list_for_each_node(node, n, h) { -+ ++count; -+ } -+ return count; - } - --static inline void init_list_node(struct list_node *n) -+static inline int list_node_null(const struct list_node *n) - { -- n->prev = n; -- n->next = n; -+ return (n->prev == NULL) || (n->next == NULL); - } - --static inline void list_add_node(struct list_node *h, struct list_node *n) -+static inline int list_head_empty(const struct list_node *h) - { -- n->next = h; -- n->prev = h->prev; -- h->prev->next = n; -- h->prev = n; -+ return h == h->next; - } - --static inline void list_del_node(struct list_node *n) -+static inline void list_init_head(struct list_node *n) - { -- struct list_node *prev = n->prev; -- struct list_node *next = n->next; -- next->prev = prev; -- prev->next = next; -+ n->prev = n; -+ n->next = n; - } - --static inline void list_del_node_init(struct list_node *n) -+static inline void list_init_node(struct list_node *n) - { -- list_del_node(n); -- init_list_node(n); -+ n->prev = NULL; -+ n->next = NULL; - } - --static inline void list_del_node_null(struct list_node *n) -+/* add node befor head, means at tail */ -+static inline void list_add_node(struct list_node *n, struct list_node *head) - { -- if ((n->next) && (n->prev)) { -- list_del_node(n); -- } -- init_list_node_null(n); -+ n->next = head; -+ n->prev = head->prev; -+ head->prev->next = n; -+ head->prev = n; - } - --static inline int list_is_null(const struct list_node *n) -+static inline void __list_del_node(struct list_node *n) - { -- return (n->prev == NULL) && (n->next == NULL); -+ struct list_node *prev = n->prev; -+ struct list_node *next = n->next; -+ next->prev = prev; -+ prev->next = next; - } - --static inline int list_is_empty(const struct list_node *h) -+static inline void list_del_node(struct list_node *n) - { -- return h == h->next; -+ if (!list_node_null(n)) { -+ __list_del_node(n); -+ } -+ list_init_node(n); - } - --#define list_for_each_safe(pos, n, head) \ -- for (pos = (head)->next, n = (pos)->next; pos != (head); pos = n, n = (pos)->next) -- --#ifndef container_of --#define container_of(ptr, type, member) ({ \ -- typeof( ((type *)0)->member ) *__mptr = (ptr); \ -- (type *)((char *)__mptr - offsetof(type,member));}) --#endif /* container_of */ -- - #endif /* _GAZELLE_LIST_H_ */ --- -2.22.0.windows.1 - diff --git a/0068-cleancode-refactor-gazelle_hlist.h.patch b/0068-cleancode-refactor-gazelle_hlist.h.patch deleted file mode 100644 index 9606522..0000000 --- a/0068-cleancode-refactor-gazelle_hlist.h.patch +++ /dev/null @@ -1,389 +0,0 @@ -From 323644a66afbf4a9ca079aef0bc1cbd463b2d33d Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Tue, 23 May 2023 22:25:09 +0800 -Subject: [PATCH 2/2] cleancode: refactor gazelle_hlist.h - -Signed-off-by: Lemmy Huang ---- - src/core/tcp.c | 2 +- - src/core/tcp_in.c | 3 +- - src/include/gazelle_hlist.h | 239 ++++++++++++++----------------- - src/include/lwip/priv/tcp_priv.h | 2 +- - src/include/lwip/tcp.h | 3 - - 5 files changed, 110 insertions(+), 139 deletions(-) - -diff --git a/src/core/tcp.c b/src/core/tcp.c -index 6a9c9fe..439f4f9 100644 ---- a/src/core/tcp.c -+++ b/src/core/tcp.c -@@ -193,7 +193,7 @@ PER_THREAD struct tcp_pcb ** tcp_pcb_lists[NUM_TCP_PCB_LISTS] = {NULL, NULL, NUL - for (_i = 0; _i < TCP_HTABLE_SIZE; ++_i) { \ - if (sys_mutex_new(&(ht_ptr)->array[_i].mutex) != ERR_OK) \ - LWIP_ASSERT("failed to create ht->array[].mutex", 0);\ -- INIT_HLIST_HEAD(&(ht_ptr)->array[_i].chain); \ -+ hlist_init_head(&(ht_ptr)->array[_i].chain); \ - }\ - } while (0) - -diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c -index 9585965..0d5af43 100644 ---- a/src/core/tcp_in.c -+++ b/src/core/tcp_in.c -@@ -138,7 +138,6 @@ tcp_input(struct pbuf *p, struct netif *inp) - #if GAZELLE_TCP_PCB_HASH - u32_t idx; - struct hlist_head *head; -- struct hlist_node *node; - pcb = NULL; - #endif - -@@ -281,7 +280,7 @@ tcp_input(struct pbuf *p, struct netif *inp) - ip_current_src_addr()->addr, tcphdr->src) & - (tcp_active_htable->size - 1); - head = &tcp_active_htable->array[idx].chain; -- tcppcb_hlist_for_each(pcb, node, head) { -+ hlist_for_each_entry(pcb, head, tcp_node) { - #else - for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) { - #endif -diff --git a/src/include/gazelle_hlist.h b/src/include/gazelle_hlist.h -index 86b5c6d..945df60 100644 ---- a/src/include/gazelle_hlist.h -+++ b/src/include/gazelle_hlist.h -@@ -35,199 +35,174 @@ - - #include "gazelle_list.h" - --//#if GAZELLE_TCP_PCB_HASH -+#define HLIST_QUICKLY_FIND 0 -+ - struct hlist_node { - /** - * @pprev: point the previous node's next pointer - */ - struct hlist_node *next; - struct hlist_node **pprev; -+ -+#if HLIST_QUICKLY_FIND -+ /* quickly find the hlist_head */ -+ struct hlist_head *head; -+#endif /* HLIST_QUICKLY_FIND */ - }; - - struct hlist_head { - struct hlist_node *first; -+#if HLIST_QUICKLY_FIND -+ struct hlist_node *tail; -+#endif /* HLIST_QUICKLY_FIND */ - }; - --struct hlist_tail { -- struct hlist_node *end; --}; -- --struct hlist_ctl { -- struct hlist_head head; -- struct hlist_tail tail; --}; -- --#define INIT_HLIST_CTRL(ptr) {(ptr)->head.first = NULL; (ptr)->tail.end = NULL;} --#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL) --#define INIT_HLIST_NODE(ptr) {(ptr)->next = NULL; (ptr)->pprev = NULL;} -+/** -+ * hlist_entry - iterate over list of given type -+ * @ptr: the &hlist_node within the struct. -+ * @type: the struct type. -+ * @member: the name of the hlist_node within the struct. -+ */ - #define hlist_entry(ptr, type, member) \ - container_of(ptr, type, member) - - /** -- * hlist_for_each_entry - iterate over list of given type -- * @tpos: the type * to use as a loop cursor. -- * @pos: the &struct hlist_node to use as a loop cursor. -- * @head: the head for your list. -- * @member: the name of the hlist_node within the struct. -+ * hlist_for_each_entry - iterate over list of given type -+ * @pos: the type * to use as a loop cursor. -+ * @head: the head for your list. -+ * @member: the name of the hlist_node within the struct. - */ --#define hlist_for_each_entry(tpos, pos, head, member) \ -- for (pos = (head)->first; \ -- pos && ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1; }); \ -- pos = (pos)->next) -+#define hlist_for_each_entry(pos, head, member) \ -+ for (struct hlist_node *__node = (head)->first; \ -+ __node && ({ pos = hlist_entry(__node, typeof(*pos), member); 1; }); \ -+ __node = (__node)->next) - --/** -- * next must be != NULL -- * add n node before next node -- * -- * @n: new node -- * @next: node in the hlist -- */ --static inline void hlist_add_before(struct hlist_node *n, struct hlist_node *next) -+static inline void hlist_init_head(struct hlist_head *h) - { -- n->pprev = next->pprev; -- n->next = next; -- next->pprev = &n->next; -- *(n->pprev) = n; -+ h->first = NULL; -+#if HLIST_QUICKLY_FIND -+ h->tail = NULL; -+#endif /* HLIST_QUICKLY_FIND */ - } - --static inline int hlist_empty(const struct hlist_head *h) -+static inline void hlist_init_node(struct hlist_node *n) - { -- return !h->first; -+ n->next = NULL; -+ n->pprev = NULL; -+#if HLIST_QUICKLY_FIND -+ n->head = NULL; -+#endif /* HLIST_QUICKLY_FIND */ - } - --static inline int hlist_unhashed(const struct hlist_node *h) -+static inline int hlist_head_empty(const struct hlist_head *h) - { -- return !h->pprev; -+ return h->first == NULL; - } - --static inline void hlist_del_init(struct hlist_node *n) -+static inline int hlist_node_null(const struct hlist_node *n) - { -- struct hlist_node *next = n->next; -- struct hlist_node **pprev = n->pprev; -- -- if (pprev == NULL) { -- return; -- } -- -- *pprev = next; -- if (next != NULL) { -- next->pprev = pprev; -- } -- -- n->next = NULL; -- n->pprev = NULL; -+ return n->pprev == NULL; - } - --static inline void hlist_ctl_del(struct hlist_ctl *ctl, struct hlist_node *n) -+static inline void hlist_del_node(struct hlist_node *n) - { -- if (ctl->head.first == ctl->tail.end) { -- ctl->head.first = NULL; -- ctl->tail.end = NULL; -+ if (hlist_node_null(n)) { - return; - } - -- if (ctl->tail.end == n) { -- ctl->tail.end = (struct hlist_node *)n->pprev; -- } -- -- hlist_del_init(n); --} -+ struct hlist_node *next = n->next; -+ struct hlist_node **pprev = n->pprev; - --static inline struct hlist_node *hlist_pop_tail(struct hlist_ctl *ctl) --{ -- if (hlist_empty(&ctl->head)) { -- return NULL; -+#if HLIST_QUICKLY_FIND -+ if (n->head->tail == n) { -+ if (n->head->first == n) { -+ n->head->tail = NULL; -+ } else { -+ n->head->tail = hlist_entry(pprev, struct hlist_node, next); -+ } - } -+#endif /* HLIST_QUICKLY_FIND */ - -- if (ctl->head.first == ctl->tail.end) { -- struct hlist_node *ret = ctl->tail.end; -- ctl->tail.end = NULL; -- ctl->head.first = NULL; -- return ret; -+ *pprev = next; -+ if (next != NULL) { -+ next->pprev = pprev; - } - -- struct hlist_node *temp = ctl->tail.end; -- -- struct hlist_node **ptailPrev = ctl->tail.end->pprev; -- *ptailPrev = NULL; -- -- ctl->tail.end = (struct hlist_node *)ptailPrev; -- temp->pprev = NULL; -- return temp; --} -- --static inline void hlist_add_after(struct hlist_node *n, struct hlist_node *next) --{ -- next->next = n->next; -- n->next = next; -- next->pprev = &n->next; -- if (next->next) { -- next->next->pprev = &next->next; -- } -+ hlist_init_node(n); - } - --static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h) -+/** -+ * hlist_add_head - add node at the beginning of the hlist -+ * @n: new node -+ * @head: hlist head to add it after -+ */ -+static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *head) - { -- struct hlist_node *first = h->first; -+ struct hlist_node *first = head->first; - - n->next = first; - if (first != NULL) { - first->pprev = &n->next; - } - -- h->first = n; -- n->pprev = &h->first; --} -- --static inline struct hlist_node *hlist_pop_head(struct hlist_ctl *ctl) --{ -- if (hlist_empty(&ctl->head)) { -- return NULL; -- } -+ head->first = n; -+ n->pprev = &head->first; - -- struct hlist_node *temp = ctl->head.first; -- hlist_ctl_del(ctl, temp); -- return temp; -+#if HLIST_QUICKLY_FIND -+ n->head = head; -+ if (head->tail == NULL) -+ head->tail = n; -+#endif /* HLIST_QUICKLY_FIND */ - } - --static inline void hlist_ctl_add_tail(struct hlist_ctl *ctl, struct hlist_node *node) -+/** -+ * hlist_add_before - add node before next node -+ * @n: new node -+ * @next: node in the hlist -+ */ -+static inline void hlist_add_before(struct hlist_node *n, struct hlist_node *next) - { -- if (hlist_empty(&ctl->head)) { -- hlist_add_head(node, &ctl->head); -- ctl->tail.end = ctl->head.first; -- return; -- } -- -- ctl->tail.end->next = node; -+ n->pprev = next->pprev; -+ n->next = next; -+ next->pprev = &n->next; -+ *(n->pprev) = n; - -- node->pprev = &(ctl->tail.end->next); -- node->next = NULL; -- ctl->tail.end = node; -+#if HLIST_QUICKLY_FIND -+ n->head = next->head; -+#endif /* HLIST_QUICKLY_FIND */ - } - --static inline void hlist_ctl_add_head(struct hlist_node *node, struct hlist_ctl *ctl) -+/** -+ * hlist_add_after - add node after prev node -+ * @n: new node -+ * @prev: node in the hlist -+ */ -+static inline void hlist_add_after(struct hlist_node *n, struct hlist_node *prev) - { -- hlist_add_head(node, &ctl->head); -- if (ctl->tail.end == NULL) { -- ctl->tail.end = ctl->head.first; -+ n->next = prev->next; -+ prev->next = n; -+ n->pprev = &prev->next; -+ if (n->next != NULL) { -+ n->next->pprev = &n->next; - } --} - --static inline void hlist_ctl_add_before(struct hlist_node *n, struct hlist_node *next, struct hlist_ctl *ctl) --{ -- hlist_add_before(n, next); -- if (next == ctl->head.first) { -- ctl->head.first = n; -- } -+#if HLIST_QUICKLY_FIND -+ n->head = prev->head; -+ if (prev->head->tail == prev) -+ prev->head->tail = n; -+#endif /* HLIST_QUICKLY_FIND */ - } - --static inline void hlist_ctl_add_after(struct hlist_node *n, struct hlist_node *next, struct hlist_ctl *ctl) -+#if HLIST_QUICKLY_FIND -+/** -+ * hlist_add_tail - add node at the tail of the hlist -+ * @n: new node -+ * @head: hlist head to add it tail -+ */ -+static inline void hlist_add_tail(struct hlist_node *n, struct hlist_head *head) - { -- hlist_add_after(n, next); -- if (n == ctl->tail.end) { -- ctl->tail.end = next; -- } -+ hlist_add_after(n, head->tail); - } --//#endif /* GAZELLE_TCP_PCB_HASH */ -+#endif /* HLIST_QUICKLY_FIND */ - - #endif /* _GAZELLE_HLIST_H_ */ -diff --git a/src/include/lwip/priv/tcp_priv.h b/src/include/lwip/priv/tcp_priv.h -index 44200ff..6a9d3d9 100644 ---- a/src/include/lwip/priv/tcp_priv.h -+++ b/src/include/lwip/priv/tcp_priv.h -@@ -494,7 +494,7 @@ static inline void vdev_unreg_done(const struct tcp_pcb *pcb) - - #define TCP_RMV_HASH(pcbs, npcb) \ - do { \ -- hlist_del_init(&(npcb)->tcp_node); \ -+ hlist_del_node(&(npcb)->tcp_node); \ - } while (0) - #endif /* GAZELLE_TCP_PCB_HASH */ - -diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h -index 11ddd25..afe2cd1 100644 ---- a/src/include/lwip/tcp.h -+++ b/src/include/lwip/tcp.h -@@ -478,9 +478,6 @@ static inline unsigned int jhash_3words(unsigned int a, unsigned int b, unsigned - - #define TUPLE4_HASH_FN(laddr, lport, faddr, fport) jhash_3words(laddr, faddr,lport|(fport<<16)) - --#define tcppcb_hlist_for_each(tcppcb, node, list) \ -- hlist_for_each_entry(tcppcb, node, list, tcp_node) -- - #endif /* GAZELLE_TCP_PCB_HASH */ - - #if LWIP_EVENT_API --- -2.22.0.windows.1 - diff --git a/0069-cleancode-refactor-options-define.patch b/0069-cleancode-refactor-options-define.patch deleted file mode 100644 index 48876e8..0000000 --- a/0069-cleancode-refactor-options-define.patch +++ /dev/null @@ -1,404 +0,0 @@ -From af6f1d199a462c9097a3564070a91e9c90a7b525 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 26 May 2023 14:29:01 +0800 -Subject: [PATCH 1/5] cleancode: refactor options define - -Signed-off-by: Lemmy Huang ---- - src/core/stats.c | 11 ------ - src/include/lwip/def.h | 2 + - src/include/lwip/ip.h | 6 --- - src/include/lwip/opt.h | 73 +++---------------------------------- - src/include/lwip/prot/ip4.h | 2 + - src/include/lwip/sockets.h | 48 ++++-------------------- - src/include/lwip/stats.h | 2 - - src/include/lwipopts.h | 9 +++++ - 8 files changed, 27 insertions(+), 126 deletions(-) - -diff --git a/src/core/stats.c b/src/core/stats.c -index f7e0604..afa7012 100644 ---- a/src/core/stats.c -+++ b/src/core/stats.c -@@ -59,17 +59,6 @@ stats_init(void) - #endif /* LWIP_DEBUG */ - } - --int get_mib2_stats(char *buf) --{ -- int len = 0; --#if MIB2_STATS -- len = (long)&((struct stats_mib2 *)0)->udpindatagrams; -- /* we just need the ip&tcp, others not needed. */ -- memcpy(buf, &lwip_stats.mib2, len); --#endif -- return len; --} -- - #if LWIP_STATS_DISPLAY - void - stats_display_proto(struct stats_proto *proto, const char *name) -diff --git a/src/include/lwip/def.h b/src/include/lwip/def.h -index fea7187..91cc6b9 100644 ---- a/src/include/lwip/def.h -+++ b/src/include/lwip/def.h -@@ -117,6 +117,7 @@ u32_t lwip_htonl(u32_t x); - /* Provide usual function names as macros for users, but this can be turned off */ - #ifndef LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS - -+#if GAZELLE_ENABLE - /* avoid conflicts with netinet/in.h */ - #ifdef htons - #undef htons -@@ -130,6 +131,7 @@ u32_t lwip_htonl(u32_t x); - #ifdef ntohl - #undef ntohl - #endif -+#endif /* GAZELLE_ENABLE */ - - #define htons(x) lwip_htons(x) - #define ntohs(x) lwip_ntohs(x) -diff --git a/src/include/lwip/ip.h b/src/include/lwip/ip.h -index 1c6988b..27bd99e 100644 ---- a/src/include/lwip/ip.h -+++ b/src/include/lwip/ip.h -@@ -97,15 +97,9 @@ struct ip_pcb { - /* - * Option flags per-socket. These are the same like SO_XXX in sockets.h - */ --#if GAZELLE_ENABLE --#define SOF_REUSEADDR 0x02U /* allow local address reuse */ --#define SOF_KEEPALIVE 0x09U /* keep connections alive */ --#define SOF_BROADCAST 0x06U /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */ --#else - #define SOF_REUSEADDR 0x04U /* allow local address reuse */ - #define SOF_KEEPALIVE 0x08U /* keep connections alive */ - #define SOF_BROADCAST 0x20U /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */ --#endif /* GAZELLE_ENABLE */ - - /* These flags are inherited (e.g. from a listen-pcb to a connection-pcb): */ - #define SOF_INHERITED (SOF_REUSEADDR|SOF_KEEPALIVE) -diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h -index 38c6e9b..d8c82d1 100644 ---- a/src/include/lwip/opt.h -+++ b/src/include/lwip/opt.h -@@ -133,7 +133,6 @@ - * MEMCPY: override this if you have a faster implementation at hand than the - * one included in your C library - */ --//#include - #if !defined MEMCPY || defined __DOXYGEN__ - #define MEMCPY(dst,src,len) memcpy(dst,src,len) - #endif -@@ -533,22 +532,6 @@ - #define MEMP_NUM_NETCONN 4 - #endif - --/** -- * MEMP_NUM_SYS_SEM: the number of struct sys_sems. -- * (only needed if you use the sequential API, like api_lib.c) -- */ --#if !defined MEMP_NUM_SYS_SEM || defined __DOXYGEN__ --#define MEMP_NUM_SYS_SEM 128 --#endif -- --/** -- * MEMP_NUM_SYS_MBOX: the number of struct sys_sems. -- * (only needed if you use the sequential API, like api_lib.c) -- */ --#if !defined MEMP_NUM_SYS_MBOX || defined __DOXYGEN__ --#define MEMP_NUM_SYS_MBOX 128 --#endif -- - /** - * MEMP_NUM_SELECT_CB: the number of struct lwip_select_cb. - * (Only needed if you have LWIP_MPU_COMPATIBLE==1 and use the socket API. -@@ -1084,7 +1067,7 @@ - * LWIP_IGMP==1: Turn on IGMP module. - */ - #if !defined LWIP_IGMP || defined __DOXYGEN__ --#define LWIP_IGMP 1 -+#define LWIP_IGMP 0 - #endif - #if !LWIP_IPV4 - #undef LWIP_IGMP -@@ -1282,7 +1265,7 @@ - * LWIP_TCP_SACK_OUT==1: TCP will support sending selective acknowledgements (SACKs). - */ - #if !defined LWIP_TCP_SACK_OUT || defined __DOXYGEN__ --#define LWIP_TCP_SACK_OUT 1 -+#define LWIP_TCP_SACK_OUT 0 - #endif - - /** -@@ -1483,8 +1466,8 @@ - * send window while having a small receive window only. - */ - #if !defined LWIP_WND_SCALE || defined __DOXYGEN__ --#define LWIP_WND_SCALE 1 --#define TCP_RCV_SCALE 6 -+#define LWIP_WND_SCALE 0 -+#define TCP_RCV_SCALE 0 - #endif - - /** -@@ -2031,7 +2014,7 @@ - * LWIP_SO_RCVBUF==1: Enable SO_RCVBUF processing. - */ - #if !defined LWIP_SO_RCVBUF || defined __DOXYGEN__ --#define LWIP_SO_RCVBUF 1 -+#define LWIP_SO_RCVBUF 0 - #endif - - /** -@@ -2249,7 +2232,7 @@ - * MIB2_STATS==1: Stats for SNMP MIB2. - */ - #if !defined MIB2_STATS || defined __DOXYGEN__ --#define MIB2_STATS 1 -+#define MIB2_STATS 0 - #endif - - #else -@@ -3439,10 +3422,6 @@ - #define TCP_OUTPUT_DEBUG LWIP_DBG_OFF - #endif - --#ifndef PERF_OUTPUT_DEBUG -- #define PERF_OUTPUT_DEBUG LWIP_DBG_OFF --#endif -- - /** - * TCP_RST_DEBUG: Enable debugging for TCP with the RST message. - */ -@@ -3523,46 +3502,6 @@ - #define LWIP_TESTMODE 0 - #endif - --/** -- * EPOLL_DEBUG: Enable debugging in epoll.c. -- */ --#if !defined EPOLL_DEBUG || defined __DOXYGEN__ && GAZELLE_ENABLE --#define EPOLL_DEBUG LWIP_DBG_OFF --#endif --/** -- * @} -- */ -- --/** -- * ETHDEV_DEBUG: Enable debugging in ethdev.c. -- */ --#if !defined ETHDEV_DEBUG || defined __DOXYGEN__ && GAZELLE_ENABLE --#define ETHDEV_DEBUG LWIP_DBG_OFF --#endif --/** -- * @} -- */ -- --/** -- * ETHDEV_DEBUG: Enable debugging in ethdev.c. -- */ --#if !defined SYSCALL_DEBUG || defined __DOXYGEN__ && GAZELLE_ENABLE --#define SYSCALL_DEBUG LWIP_DBG_OFF --#endif --/** -- * @} -- */ -- --/** -- * CONTROL_DEBUG: Enable debugging in control_plane.c. -- */ --#if !defined CONTROL_DEBUG || defined __DOXYGEN__ && GAZELLE_ENABLE --#define CONTROL_DEBUG LWIP_DBG_ON --#endif --/** -- * @} -- */ -- - /* - -------------------------------------------------- - ---------- Performance tracking options ---------- -diff --git a/src/include/lwip/prot/ip4.h b/src/include/lwip/prot/ip4.h -index c9ad89c..5f863a2 100644 ---- a/src/include/lwip/prot/ip4.h -+++ b/src/include/lwip/prot/ip4.h -@@ -82,6 +82,7 @@ struct ip_hdr { - /* fragment offset field */ - PACK_STRUCT_FIELD(u16_t _offset); - -+#if GAZELLE_ENABLE - /* avoid conflicts with netinet/ip.h */ - #ifdef IP_RF - #undef IP_RF -@@ -95,6 +96,7 @@ struct ip_hdr { - #ifdef IP_OFFMASK - #undef IP_OFFMASK - #endif -+#endif /* GAZELLE_ENABLE */ - - #define IP_RF 0x8000U /* reserved fragment flag */ - #define IP_DF 0x4000U /* don't fragment flag */ -diff --git a/src/include/lwip/sockets.h b/src/include/lwip/sockets.h -index 36a47eb..e59fdf4 100644 ---- a/src/include/lwip/sockets.h -+++ b/src/include/lwip/sockets.h -@@ -60,7 +60,7 @@ extern "C" { - to prevent this code from redefining it. */ - #if GAZELLE_ENABLE - #define SA_FAMILY_T_DEFINED -- typedef u16_t sa_family_t; -+typedef u16_t sa_family_t; - #endif - - #if !defined(sa_family_t) && !defined(SA_FAMILY_T_DEFINED) -@@ -200,6 +200,11 @@ struct ifreq { - #define SOCK_RAW 3 - - #if GAZELLE_ENABLE -+#define O_CLOEXEC 02000000 /* same as define in asm-generic/fcntl.h */ -+#define SOCK_CLOEXEC O_CLOEXEC -+#define SOCK_NONBLOCK O_NONBLOCK -+#define SOCK_TYPE_MASK 0xf -+ - #include - #else - /* -@@ -298,6 +303,7 @@ struct linger { - #define TCP_KEEPINTVL 0x05 /* set pcb->keep_intvl - Use seconds for get/setsockopt */ - #define TCP_KEEPCNT 0x06 /* set pcb->keep_cnt - Use number of probes sent for get/setsockopt */ - #else /* GAZELLE_ENABLE */ -+ - #define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */ - #define TCP_KEEPALIVE 0x02 /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */ - #define TCP_KEEPIDLE 0x03 /* set pcb->keep_idle - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */ -@@ -523,24 +529,7 @@ typedef struct fd_set - #define LWIP_SELECT_MAXNFDS FD_SETSIZE - #endif /* FD_SET */ - --#if GAZELLE_ENABLE --#if !defined(POLLIN) && !defined(POLLOUT) --/* come from bits/poll.h */ --#define POLLIN 0x001 --#define POLLOUT 0x004 --#define POLLERR 0x008 --#define POLLNVAL 0x020 --/* Below values are unimplemented */ --#define POLLRDNORM 0x040 --#define POLLRDBAND 0x080 --#define POLLPRI 0x002 --#define POLLWRNORM 0x100 --#define POLLWRBAND 0x200 --#define POLLHUP 0x010 --#endif --#endif /* GAZELLE_ENABLE */ -- --#if LWIP_SOCKET_POLL -+#if LWIP_SOCKET_POLL && !GAZELLE_ENABLE - /* poll-related defines and types */ - /* @todo: find a better way to guard the definition of these defines and types if already defined */ - #if !defined(POLLIN) && !defined(POLLOUT) -@@ -585,7 +574,6 @@ void lwip_socket_thread_cleanup(void); /* LWIP_NETCONN_SEM_PER_THREAD==1: destro - #if LWIP_COMPAT_SOCKETS == 2 - /* This helps code parsers/code completion by not having the COMPAT functions as defines */ - #define lwip_accept accept --#define lwip_accept4 accept4 - #define lwip_bind bind - #define lwip_shutdown shutdown - #define lwip_getpeername getpeername -@@ -627,23 +615,6 @@ int fcntl(int s, int cmd, ...); - #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */ - #endif /* LWIP_COMPAT_SOCKETS == 2 */ - --#ifndef O_CLOEXEC --#define O_CLOEXEC 02000000 --#endif -- --#ifndef SOCK_TYPE_MASK --#define SOCK_TYPE_MASK 0xf --#endif -- --#ifndef SOCK_CLOEXEC --#define SOCK_CLOEXEC O_CLOEXEC --#endif -- --#ifndef SOCK_NONBLOCK --#define SOCK_NONBLOCK O_NONBLOCK --#endif -- -- - int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen); - int lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags); - int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen); -@@ -668,7 +639,6 @@ ssize_t lwip_sendto(int s, const void *dataptr, size_t size, int flags, - int lwip_socket(int domain, int type, int protocol); - ssize_t lwip_write(int s, const void *dataptr, size_t size); - ssize_t lwip_writev(int s, const struct iovec *iov, int iovcnt); -- - #if LWIP_SOCKET_SELECT - int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, - struct timeval *timeout); -@@ -695,8 +665,6 @@ int lwip_inet_pton(int af, const char *src, void *dst); - /** @ingroup socket */ - #define accept(s,addr,addrlen) lwip_accept(s,addr,addrlen) - /** @ingroup socket */ --#define accept4(s,addr,addrlen,flags) lwip_accept4(s,addr,addrlen,flags) --/** @ingroup socket */ - #define bind(s,name,namelen) lwip_bind(s,name,namelen) - /** @ingroup socket */ - #define shutdown(s,how) lwip_shutdown(s,how) -diff --git a/src/include/lwip/stats.h b/src/include/lwip/stats.h -index 4470531..4cad603 100644 ---- a/src/include/lwip/stats.h -+++ b/src/include/lwip/stats.h -@@ -467,8 +467,6 @@ void stats_init(void); - #define MIB2_STATS_INC(x) - #endif - --int get_mib2_stats(char *buf); -- - /* Display of statistics */ - #if LWIP_STATS_DISPLAY - void stats_display(void); -diff --git a/src/include/lwipopts.h b/src/include/lwipopts.h -index bc85eae..4a93923 100644 ---- a/src/include/lwipopts.h -+++ b/src/include/lwipopts.h -@@ -99,6 +99,8 @@ - - #define LWIP_STATS_DISPLAY 1 - -+#define MIB2_STATS 1 -+ - #define LWIP_TIMERS 1 - - #define LWIP_TIMEVAL_PRIVATE 0 -@@ -154,6 +156,7 @@ - - #define ETHARP_SUPPORT_STATIC_ENTRIES 1 - -+#define LWIP_IGMP 1 - - /* - --------------------------------- -@@ -209,6 +212,10 @@ - - #define LWIP_TCP_KEEPALIVE 1 - -+#define LWIP_TCP_SACK_OUT 1 -+#define LWIP_WND_SCALE 1 -+#define TCP_RCV_SCALE 6 -+ - #define GAZELLE_TCP_MAX_CONN_PER_THREAD 65535 - #define GAZELLE_TCP_REUSE_IPPORT 1 - -@@ -226,6 +233,8 @@ - - #define LWIP_SO_LINGER 0 - -+#define LWIP_SO_RCVBUF 1 -+ - #define SO_REUSE 1 - - #define FIONBIO 0x5421 /* same as define in asm-generic/ioctls.h */ --- -2.22.0.windows.1 - diff --git a/0070-cleancode-refactor-GAZELLE_TCP_PCB_HASH.patch b/0070-cleancode-refactor-GAZELLE_TCP_PCB_HASH.patch deleted file mode 100644 index ac4e1ec..0000000 --- a/0070-cleancode-refactor-GAZELLE_TCP_PCB_HASH.patch +++ /dev/null @@ -1,752 +0,0 @@ -From cdca621d7ae0fc353abe9127e92e4787c3c54d23 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 26 May 2023 16:19:14 +0800 -Subject: [PATCH 2/5] cleancode: refactor GAZELLE_TCP_PCB_HASH - -Signed-off-by: Lemmy Huang ---- - src/core/tcp.c | 79 ++++++---------- - src/core/tcp_in.c | 27 +----- - src/include/gazelle_tcp_priv.h | 155 +++++++++++++++++++++++++++++++ - src/include/lwip/priv/tcp_priv.h | 137 ++------------------------- - src/include/lwip/tcp.h | 78 ++-------------- - src/include/lwipopts.h | 7 +- - 6 files changed, 205 insertions(+), 278 deletions(-) - create mode 100644 src/include/gazelle_tcp_priv.h - -diff --git a/src/core/tcp.c b/src/core/tcp.c -index 439f4f9..caba39d 100644 ---- a/src/core/tcp.c -+++ b/src/core/tcp.c -@@ -161,7 +161,6 @@ static const char *const tcp_state_str[] = { - - /* last local TCP port */ - static u16_t tcp_port = TCP_LOCAL_PORT_RANGE_START; --static pthread_mutex_t g_tcp_port_mutex = PTHREAD_MUTEX_INITIALIZER; - - /* Incremented every coarse grained timer shot (typically every 500 ms). */ - PER_THREAD u32_t tcp_ticks; -@@ -185,21 +184,6 @@ PER_THREAD struct tcp_pcb *tcp_tw_pcbs; - /** An array with all (non-temporary) PCB lists, mainly used for smaller code size */ - PER_THREAD struct tcp_pcb ** tcp_pcb_lists[NUM_TCP_PCB_LISTS] = {NULL, NULL, NULL, NULL}; - --#if GAZELLE_TCP_PCB_HASH --#define INIT_TCP_HTABLE(ht_ptr) \ -- do { \ -- int _i; \ -- (ht_ptr)->size = TCP_HTABLE_SIZE; \ -- for (_i = 0; _i < TCP_HTABLE_SIZE; ++_i) { \ -- if (sys_mutex_new(&(ht_ptr)->array[_i].mutex) != ERR_OK) \ -- LWIP_ASSERT("failed to create ht->array[].mutex", 0);\ -- hlist_init_head(&(ht_ptr)->array[_i].chain); \ -- }\ -- } while (0) -- --PER_THREAD struct tcp_hash_table *tcp_active_htable; /* key: lport/fport/lip/fip */ --#endif -- - PER_THREAD u8_t tcp_active_pcbs_changed; - - /** Timer counter to handle calling slow-timer from tcp_tmr() */ -@@ -207,16 +191,7 @@ static PER_THREAD u8_t tcp_timer; - static PER_THREAD u8_t tcp_timer_ctr; - #if GAZELLE_ENABLE - static u16_t tcp_new_port(struct tcp_pcb *pcb); --#else --static u16_t tcp_new_port(void); --#endif -- --static err_t tcp_close_shutdown_fin(struct tcp_pcb *pcb); --#if LWIP_TCP_PCB_NUM_EXT_ARGS --static void tcp_ext_arg_invoke_callbacks_destroyed(struct tcp_pcb_ext_args *ext_args); --#endif -- --#if GAZELLE_ENABLE -+static pthread_mutex_t g_tcp_port_mutex = PTHREAD_MUTEX_INITIALIZER; - static u8_t port_state[TCP_LOCAL_PORT_RANGE_END - TCP_LOCAL_PORT_RANGE_START + 1] = {0}; - void release_port(u16_t port) - { -@@ -224,7 +199,19 @@ void release_port(u16_t port) - port_state[port - TCP_LOCAL_PORT_RANGE_START] = 0; - } - } -+#else /* GAZELLE_ENABLE */ -+static u16_t tcp_new_port(void); -+#endif /* GAZELLE_ENABLE */ -+ -+#if GAZELLE_TCP_PCB_HASH -+PER_THREAD struct tcp_hash_table *tcp_active_htable; /* key: lport/fport/lip/fip */ -+#endif /* GAZELLE_TCP_PCB_HASH */ -+ -+static err_t tcp_close_shutdown_fin(struct tcp_pcb *pcb); -+#if LWIP_TCP_PCB_NUM_EXT_ARGS -+static void tcp_ext_arg_invoke_callbacks_destroyed(struct tcp_pcb_ext_args *ext_args); - #endif -+ - /** - * Initialize this module. - */ -@@ -236,15 +223,18 @@ tcp_init(void) - tcp_pcb_lists[2] = &tcp_active_pcbs; - tcp_pcb_lists[3] = &tcp_tw_pcbs; - --#ifdef LWIP_RAND -- tcp_port = TCP_ENSURE_LOCAL_PORT_RANGE(LWIP_RAND()); --#endif /* LWIP_RAND */ -- - #if GAZELLE_TCP_PCB_HASH - tcp_active_htable = (struct tcp_hash_table*)mem_malloc(sizeof(struct tcp_hash_table)); - LWIP_ASSERT("malloc tcp_active_htable mem failed.", tcp_active_htable != NULL); -- INIT_TCP_HTABLE(tcp_active_htable); --#endif -+ tcp_active_htable->size = GAZELLE_TCP_ACTIVE_HTABLE_SIZE; -+ for (int i = 0; i < tcp_active_htable->size; ++i) { -+ hlist_init_head(&tcp_active_htable->array[i].chain); -+ } -+#endif /* GAZELLE_TCP_PCB_HASH */ -+ -+#ifdef LWIP_RAND -+ tcp_port = TCP_ENSURE_LOCAL_PORT_RANGE(LWIP_RAND()); -+#endif /* LWIP_RAND */ - } - - /** Free a tcp pcb */ -@@ -419,9 +409,6 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data) - pcb->local_port, pcb->remote_port); - - tcp_pcb_purge(pcb); --#if GAZELLE_TCP_PCB_HASH -- TCP_RMV_ACTIVE_HASH(pcb); --#endif - TCP_RMV_ACTIVE(pcb); - /* Deallocate the pcb since we already sent a RST for it */ - if (tcp_input_pcb == pcb) { -@@ -456,9 +443,6 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data) - tcp_free_listen(pcb); - break; - case SYN_SENT: --#if GAZELLE_TCP_PCB_HASH -- TCP_PCB_REMOVE_ACTIVE_HASH(pcb); --#endif - TCP_PCB_REMOVE_ACTIVE(pcb); - tcp_free(pcb); - MIB2_STATS_INC(mib2.tcpattemptfails); -@@ -663,9 +647,6 @@ tcp_abandon(struct tcp_pcb *pcb, int reset) - } else { - send_rst = reset; - local_port = pcb->local_port; --#if GAZELLE_TCP_PCB_HASH -- TCP_PCB_REMOVE_ACTIVE_HASH(pcb); --#endif - TCP_PCB_REMOVE_ACTIVE(pcb); - } - if (pcb->unacked != NULL) { -@@ -1330,9 +1311,6 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port, - if (old_local_port != 0) { - TCP_RMV(&tcp_bound_pcbs, pcb); - } --#if GAZELLE_TCP_PCB_HASH -- TCP_REG_ACTIVE_HASH(pcb); --#endif - TCP_REG_ACTIVE(pcb); - MIB2_STATS_INC(mib2.tcpactiveopens); - -@@ -2389,6 +2367,11 @@ tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb) - LWIP_ASSERT("tcp_pcb_remove: invalid pcb", pcb != NULL); - LWIP_ASSERT("tcp_pcb_remove: invalid pcblist", pcblist != NULL); - -+#if GAZELLE_TCP_PCB_HASH -+ if (pcblist == &tcp_active_pcbs) { -+ TCP_RMV_ACTIVE_HASH(pcb); -+ } -+#endif /* GAZELLE_TCP_PCB_HASH */ - TCP_RMV(pcblist, pcb); - - tcp_pcb_purge(pcb); -@@ -2421,14 +2404,6 @@ tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb) - LWIP_ASSERT("tcp_pcb_remove: tcp_pcbs_sane()", tcp_pcbs_sane()); - } - --#if GAZELLE_TCP_PCB_HASH --void --tcp_pcb_remove_hash(struct tcp_hash_table *htb, struct tcp_pcb *pcb) --{ -- TCP_RMV_HASH(htb, pcb); --} --#endif /* GAZELLE_TCP_PCB_HASH */ -- - /** - * Calculates a new initial sequence number for new connections. - * -diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c -index 0d5af43..575bf05 100644 ---- a/src/core/tcp_in.c -+++ b/src/core/tcp_in.c -@@ -135,12 +135,6 @@ tcp_input(struct pbuf *p, struct netif *inp) - u8_t hdrlen_bytes; - err_t err; - --#if GAZELLE_TCP_PCB_HASH -- u32_t idx; -- struct hlist_head *head; -- pcb = NULL; --#endif -- - LWIP_UNUSED_ARG(inp); - LWIP_ASSERT_CORE_LOCKED(); - LWIP_ASSERT("tcp_input: invalid pbuf", p != NULL); -@@ -276,6 +270,9 @@ tcp_input(struct pbuf *p, struct netif *inp) - prev = NULL; - - #if GAZELLE_TCP_PCB_HASH -+ pcb = NULL; -+ u32_t idx; -+ struct hlist_head *head; - idx = TUPLE4_HASH_FN( ip_current_dest_addr()->addr, tcphdr->dest, - ip_current_src_addr()->addr, tcphdr->src) & - (tcp_active_htable->size - 1); -@@ -526,9 +523,6 @@ tcp_input(struct pbuf *p, struct netif *inp) - application that the connection is dead before we - deallocate the PCB. */ - TCP_EVENT_ERR(pcb->state, pcb->errf, pcb->callback_arg, ERR_RST); --#if GAZELLE_TCP_PCB_HASH -- tcp_pcb_remove_hash(tcp_active_htable, pcb); --#endif - tcp_pcb_remove(&tcp_active_pcbs, pcb); - tcp_free(pcb); - } else { -@@ -694,9 +688,6 @@ tcp_input_delayed_close(struct tcp_pcb *pcb) - ensure the application doesn't continue using the PCB. */ - TCP_EVENT_ERR(pcb->state, pcb->errf, pcb->callback_arg, ERR_CLSD); - } --#if GAZELLE_TCP_PCB_HASH -- tcp_pcb_remove_hash(tcp_active_htable, pcb); --#endif - tcp_pcb_remove(&tcp_active_pcbs, pcb); - tcp_free(pcb); - return 1; -@@ -782,9 +773,6 @@ tcp_listen_input(struct tcp_pcb_listen *pcb) - npcb->netif_idx = pcb->netif_idx; - /* Register the new PCB so that we can begin receiving segments - for it. */ --#if GAZELLE_TCP_PCB_HASH -- TCP_REG_ACTIVE_HASH(npcb); --#endif - TCP_REG_ACTIVE(npcb); - - #if GAZELLE_ENABLE -@@ -1115,9 +1103,6 @@ tcp_process(struct tcp_pcb *pcb) - ("TCP connection closed: FIN_WAIT_1 %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); - tcp_ack_now(pcb); - tcp_pcb_purge(pcb); --#if GAZELLE_TCP_PCB_HASH -- TCP_RMV_ACTIVE_HASH(pcb); --#endif - TCP_RMV_ACTIVE(pcb); - pcb->state = TIME_WAIT; - TCP_REG(&tcp_tw_pcbs, pcb); -@@ -1136,9 +1121,6 @@ tcp_process(struct tcp_pcb *pcb) - LWIP_DEBUGF(TCP_DEBUG, ("TCP connection closed: FIN_WAIT_2 %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); - tcp_ack_now(pcb); - tcp_pcb_purge(pcb); --#if GAZELLE_TCP_PCB_HASH -- TCP_RMV_ACTIVE_HASH(pcb); --#endif - TCP_RMV_ACTIVE(pcb); - pcb->state = TIME_WAIT; - TCP_REG(&tcp_tw_pcbs, pcb); -@@ -1149,9 +1131,6 @@ tcp_process(struct tcp_pcb *pcb) - if ((flags & TCP_ACK) && ackno == pcb->snd_nxt && pcb->unsent == NULL) { - LWIP_DEBUGF(TCP_DEBUG, ("TCP connection closed: CLOSING %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); - tcp_pcb_purge(pcb); --#if GAZELLE_TCP_PCB_HASH -- TCP_RMV_ACTIVE_HASH(pcb); --#endif - TCP_RMV_ACTIVE(pcb); - pcb->state = TIME_WAIT; - TCP_REG(&tcp_tw_pcbs, pcb); -diff --git a/src/include/gazelle_tcp_priv.h b/src/include/gazelle_tcp_priv.h -new file mode 100644 -index 0000000..01d4953 ---- /dev/null -+++ b/src/include/gazelle_tcp_priv.h -@@ -0,0 +1,155 @@ -+/* -+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science. -+ * All rights reserved. -+ * -+ * Redistribution and use in source and binary forms, with or without modification, -+ * are permitted provided that the following conditions are met: -+ * -+ * 1. Redistributions of source code must retain the above copyright notice, -+ * this list of conditions and the following disclaimer. -+ * 2. Redistributions in binary form must reproduce the above copyright notice, -+ * this list of conditions and the following disclaimer in the documentation -+ * and/or other materials provided with the distribution. -+ * 3. The name of the author may not be used to endorse or promote products -+ * derived from this software without specific prior written permission. -+ * -+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED -+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT -+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT -+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY -+ * OF SUCH DAMAGE. -+ * -+ * This file is part of the lwIP TCP/IP stack. -+ * -+ * Author: Huawei Technologies -+ * -+ */ -+ -+#ifndef __GAZELLE_TCP_PRIV_H__ -+#define __GAZELLE_TCP_PRIV_H__ -+ -+#include "lwip/opt.h" -+#include "lwip/sys.h" -+#include "gazelle_hlist.h" -+ -+#define __TCP_REG(pcbs, npcb) \ -+ do { \ -+ if (*pcbs) \ -+ (*pcbs)->prev = npcb; \ -+ (npcb)->prev = NULL; \ -+ (npcb)->next = *pcbs; \ -+ *(pcbs) = (npcb); \ -+ tcp_timer_needed(); \ -+ } while (0) -+ -+#define __TCP_RMV(pcbs, npcb) \ -+ do { \ -+ if(*(pcbs) == (npcb)) { \ -+ *(pcbs) = (*pcbs)->next; \ -+ if (*pcbs) \ -+ (*pcbs)->prev = NULL; \ -+ } else { \ -+ struct tcp_pcb *prev, *next; \ -+ prev = npcb->prev; \ -+ next = npcb->next; \ -+ if (prev) \ -+ prev->next = next; \ -+ if (next) \ -+ next->prev = prev; \ -+ } \ -+ (npcb)->prev = NULL; \ -+ (npcb)->next = NULL; \ -+ } while(0) -+ -+#if TCP_DEBUG_PCB_LISTS -+#define TCP_REG(pcbs, npcb) do {\ -+ struct tcp_pcb *tcp_tmp_pcb; \ -+ LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %"U16_F"\n", (void *)(npcb), (npcb)->local_port)); \ -+ for (tcp_tmp_pcb = *(pcbs); \ -+ tcp_tmp_pcb != NULL; \ -+ tcp_tmp_pcb = tcp_tmp_pcb->next) { \ -+ LWIP_ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != (npcb)); \ -+ } \ -+ LWIP_ASSERT("TCP_REG: pcb->state != CLOSED", ((pcbs) == &tcp_bound_pcbs) || ((npcb)->state != CLOSED)); \ -+ __TCP_REG(pcbs, npcb); \ -+ LWIP_ASSERT("TCP_REG: tcp_pcbs sane", tcp_pcbs_sane()); \ -+ } while(0) -+#define TCP_RMV(pcbs, npcb) do { \ -+ struct tcp_pcb *tcp_tmp_pcb; \ -+ LWIP_ASSERT("TCP_RMV: pcbs != NULL", *(pcbs) != NULL); \ -+ LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", (void *)(npcb), (void *)(*(pcbs)))); \ -+ __TCP_RMV(pcbs, npcb); \ -+ LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ -+ LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", (void *)(npcb), (void *)(*(pcbs)))); \ -+ } while(0) -+ -+#else /* LWIP_DEBUG */ -+ -+#define TCP_REG(pcbs, npcb) __TCP_REG(pcbs, npcb) -+#define TCP_RMV(pcbs, npcb) __TCP_RMV(pcbs, npcb) -+ -+#endif /* LWIP_DEBUG */ -+ -+#if GAZELLE_TCP_PCB_HASH -+struct tcp_hashbucket { -+ sys_mutex_t mutex; -+ struct hlist_head chain; -+}; -+struct tcp_hash_table { -+ u32_t size; -+ struct tcp_hashbucket array[GAZELLE_TCP_ACTIVE_HTABLE_SIZE]; -+}; -+extern PER_THREAD struct tcp_hash_table *tcp_active_htable; /* key: lport/fport/lip/fip */ -+ -+#include -+#define TUPLE4_HASH_FN(laddr, lport, faddr, fport) rte_jhash_3words(laddr, faddr, lport|(fport<<16), 0) -+ -+#define TCP_REG_HASH(pcbs, npcb) \ -+ do { \ -+ struct hlist_head *head; \ -+ struct tcp_hash_table *htb = pcbs; \ -+ u32_t idx = TUPLE4_HASH_FN((npcb)->local_ip.addr, (npcb)->local_port, \ -+ (npcb)->remote_ip.addr, (npcb)->remote_port) & \ -+ (htb->size - 1); \ -+ head = &htb->array[idx].chain; \ -+ hlist_add_head(&(npcb)->tcp_node, head); \ -+ tcp_timer_needed(); \ -+ } while (0) -+ -+#define TCP_RMV_HASH(pcbs, npcb) \ -+ do { \ -+ hlist_del_node(&(npcb)->tcp_node); \ -+ } while (0) -+ -+#define TCP_REG_ACTIVE_HASH(npcb) \ -+ do { \ -+ TCP_REG_HASH(tcp_active_htable, npcb); \ -+ tcp_active_pcbs_changed = 1; \ -+ } while (0) -+ -+#define TCP_RMV_ACTIVE_HASH(npcb) \ -+ do { \ -+ TCP_RMV_HASH(tcp_active_htable, npcb); \ -+ tcp_active_pcbs_changed = 1; \ -+ } while (0) -+ -+#endif /* GAZELLE_TCP_PCB_HASH */ -+ -+#if GAZELLE_TCP_REUSE_IPPORT -+#define TCP_REG_SAMEPORT(first_pcb, lpcb) \ -+ do { \ -+ struct tcp_pcb_listen *tmp_pcb = first_pcb; \ -+ while (tmp_pcb->next_same_port_pcb != NULL) { \ -+ tmp_pcb = tmp_pcb->next_same_port_pcb; \ -+ }; \ -+ tmp_pcb->next_same_port_pcb = lpcb; \ -+ tcp_timer_needed(); \ -+ } while (0) -+#endif /* GAZELLE_TCP_REUSE_IPPORT */ -+ -+#endif /* __GAZELLE_TCP_PRIV_H__ */ -\ No newline at end of file -diff --git a/src/include/lwip/priv/tcp_priv.h b/src/include/lwip/priv/tcp_priv.h -index 6a9d3d9..7a04c99 100644 ---- a/src/include/lwip/priv/tcp_priv.h -+++ b/src/include/lwip/priv/tcp_priv.h -@@ -388,51 +388,12 @@ static inline void vdev_unreg_done(const struct tcp_pcb *pcb) - #ifndef TCP_DEBUG_PCB_LISTS - #define TCP_DEBUG_PCB_LISTS 0 - #endif --#if TCP_DEBUG_PCB_LISTS --#if GAZELLE_ENABLE --#define TCP_REG(pcbs, npcb) do {\ -- struct tcp_pcb *tcp_tmp_pcb; \ -- LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", (npcb), (npcb)->local_port)); \ -- for (tcp_tmp_pcb = *(pcbs); \ -- tcp_tmp_pcb != NULL; \ -- tcp_tmp_pcb = tcp_tmp_pcb->next) { \ -- LWIP_ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != (npcb)); \ -- } \ -- LWIP_ASSERT("TCP_REG: pcb->state != CLOSED", ((pcbs) == &tcp_bound_pcbs) || ((npcb)->state != CLOSED)); \ -- if (*pcbs) \ -- (*pcbs)->prev = npcb; \ -- (npcb)->prev = NULL; \ -- (npcb)->next = *(pcbs); \ -- LWIP_ASSERT("TCP_REG: npcb->next != npcb", (npcb)->next != (npcb)); \ -- *(pcbs) = (npcb); \ -- LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ -- tcp_timer_needed(); \ -- } while(0) --#define TCP_RMV(pcbs, npcb) do { \ -- struct tcp_pcb *tcp_tmp_pcb; \ -- LWIP_ASSERT("TCP_RMV: pcbs != NULL", *(pcbs) != NULL); \ -- LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", (npcb), *(pcbs))); \ -- if(*(pcbs) == (npcb)) { \ -- *(pcbs) = (*pcbs)->next; \ -- if (*pcbs) \ -- (*pcbs)->prev = NULL; \ -- } else { \ -- struct tcp_pcb *prev, *next; \ -- prev = npcb->prev; \ -- next = npcb->next; \ -- if (prev) \ -- prev->next = next; \ -- if (next) \ -- next->prev = prev; \ -- } \ -- } \ -- (npcb)->prev = NULL; \ -- (npcb)->next = NULL; \ -- LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ -- LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", (npcb), *(pcbs))); \ -- } while(0) - --#else /* GAZELLE_ENABLE */ -+#if GAZELLE_TCP_PCB_HASH -+#include "gazelle_tcp_priv.h" -+#else /* GAZELLE_TCP_PCB_HASH */ -+ -+#if TCP_DEBUG_PCB_LISTS - #define TCP_REG(pcbs, npcb) do {\ - struct tcp_pcb *tcp_tmp_pcb; \ - LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %"U16_F"\n", (void *)(npcb), (npcb)->local_port)); \ -@@ -465,71 +426,8 @@ static inline void vdev_unreg_done(const struct tcp_pcb *pcb) - LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", (void *)(npcb), (void *)(*(pcbs)))); \ - } while(0) - --#endif /* GAZELLE_ENABLE */ - #else /* LWIP_DEBUG */ - --#if GAZELLE_TCP_PCB_HASH --#define TCP_REG_HASH(pcbs, npcb) \ -- do { \ -- u32_t idx; \ -- struct hlist_head *hd; \ -- struct tcp_hash_table *htb = pcbs; \ -- idx = TUPLE4_HASH_FN((npcb)->local_ip.addr, (npcb)->local_port, \ -- (npcb)->remote_ip.addr, (npcb)->remote_port) & \ -- (htb->size - 1); \ -- hd = &htb->array[idx].chain; \ -- hlist_add_head(&(npcb)->tcp_node, hd); \ -- tcp_timer_needed(); \ -- } while (0) -- --#define TCP_REG_SAMEPORT(first_pcb, lpcb) \ -- do { \ -- struct tcp_pcb_listen *tmp_pcb = first_pcb; \ -- while (tmp_pcb->next_same_port_pcb != NULL) { \ -- tmp_pcb = tmp_pcb->next_same_port_pcb; \ -- }; \ -- tmp_pcb->next_same_port_pcb = lpcb; \ -- tcp_timer_needed(); \ -- } while (0) -- --#define TCP_RMV_HASH(pcbs, npcb) \ -- do { \ -- hlist_del_node(&(npcb)->tcp_node); \ -- } while (0) --#endif /* GAZELLE_TCP_PCB_HASH */ -- --#if GAZELLE_ENABLE --#define TCP_REG(pcbs, npcb) \ -- do { \ -- if (*pcbs) \ -- (*pcbs)->prev = npcb; \ -- (npcb)->prev = NULL; \ -- (npcb)->next = *pcbs; \ -- *(pcbs) = (npcb); \ -- tcp_timer_needed(); \ -- } while (0) -- --#define TCP_RMV(pcbs, npcb) \ -- do { \ -- if(*(pcbs) == (npcb)) { \ -- (*(pcbs)) = (*pcbs)->next; \ -- if (*pcbs) \ -- (*pcbs)->prev = NULL; \ -- } \ -- else { \ -- struct tcp_pcb *prev, *next; \ -- prev = npcb->prev; \ -- next = npcb->next; \ -- if (prev) \ -- prev->next = next; \ -- if (next) \ -- next->prev = prev; \ -- } \ -- (npcb)->prev = NULL; \ -- (npcb)->next = NULL; \ -- } while(0) -- --#else /* GAZELLE_ENABLE */ - #define TCP_REG(pcbs, npcb) \ - do { \ - (npcb)->next = *pcbs; \ -@@ -556,40 +454,19 @@ static inline void vdev_unreg_done(const struct tcp_pcb *pcb) - (npcb)->next = NULL; \ - } while(0) - --#endif /* GAZELLE_ENABLE */ - #endif /* LWIP_DEBUG */ -- -- --#if GAZELLE_TCP_PCB_HASH --#define TCP_REG_ACTIVE_HASH(npcb) \ -- do { \ -- TCP_REG_HASH(tcp_active_htable, npcb); \ -- tcp_active_pcbs_changed = 1; \ -- } while (0) -- --#define TCP_RMV_ACTIVE_HASH(npcb) \ -- do { \ -- TCP_RMV_HASH(tcp_active_htable, npcb); \ -- tcp_active_pcbs_changed = 1; \ -- } while (0) -- --#define TCP_PCB_REMOVE_ACTIVE_HASH(pcb) \ -- do { \ -- tcp_pcb_remove_hash(tcp_active_htable, pcb); \ -- tcp_active_pcbs_changed = 1; \ -- } while (0) -- --void tcp_pcb_remove_hash(struct tcp_hash_table *htb, struct tcp_pcb *pcb); - #endif /* GAZELLE_TCP_PCB_HASH */ - - #define TCP_REG_ACTIVE(npcb) \ - do { \ -+ TCP_REG_ACTIVE_HASH(npcb); \ - TCP_REG(&tcp_active_pcbs, npcb); \ - tcp_active_pcbs_changed = 1; \ - } while (0) - - #define TCP_RMV_ACTIVE(npcb) \ - do { \ -+ TCP_RMV_ACTIVE_HASH(npcb); \ - TCP_RMV(&tcp_active_pcbs, npcb); \ - tcp_active_pcbs_changed = 1; \ - } while (0) -diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h -index afe2cd1..b093baa 100644 ---- a/src/include/lwip/tcp.h -+++ b/src/include/lwip/tcp.h -@@ -51,11 +51,6 @@ - #include "lwip/ip6.h" - #include "lwip/ip6_addr.h" - --#if GAZELLE_TCP_PCB_HASH --#include "lwip/sys.h" --#include "gazelle_hlist.h" --#endif -- - #ifdef __cplusplus - extern "C" { - #endif -@@ -215,18 +210,15 @@ typedef u16_t tcpflags_t; - * members common to struct tcp_pcb and struct tcp_listen_pcb - */ - #if GAZELLE_ENABLE -+#include "gazelle_hlist.h" -+#define LWIP_TCP_PCB_CUSTOM_DATA(type) \ -+ /* GAZELLE_TCP_PCB_HASH */ \ -+ struct hlist_node tcp_node; \ -+ type *prev; /* for the linked list */ -+#endif /* GAZELLE_ENABLE */ -+ - #define TCP_PCB_COMMON(type) \ -- type *next; /* for the linked list */ \ -- type *prev; /* for the linked list */ \ -- void *callback_arg; \ -- TCP_PCB_EXTARGS \ -- enum tcp_state state; /* TCP state */ \ -- u8_t prio; \ -- /* ports are in host byte order */ \ -- u16_t local_port -- --#else /* GAZELLE_ENABLE */ --#define TCP_PCB_COMMON(type) \ -+ LWIP_TCP_PCB_CUSTOM_DATA(type) \ - type *next; /* for the linked list */ \ - void *callback_arg; \ - TCP_PCB_EXTARGS \ -@@ -234,7 +226,7 @@ typedef u16_t tcpflags_t; - u8_t prio; \ - /* ports are in host byte order */ \ - u16_t local_port --#endif /* GAZELLE_ENABLE */ -+ - - /** the TCP protocol control block for listening pcbs */ - struct tcp_pcb_listen { -@@ -272,9 +264,6 @@ struct tcp_pcb { - IP_PCB; - /** protocol specific PCB members */ - TCP_PCB_COMMON(struct tcp_pcb); --#if GAZELLE_TCP_PCB_HASH -- struct hlist_node tcp_node; --#endif - - /* ports are in host byte order */ - u16_t remote_port; -@@ -431,55 +420,6 @@ struct tcp_pcb { - u8_t need_tso_send; - }; - --#if GAZELLE_TCP_PCB_HASH --#define TCP_HTABLE_SIZE MEMP_NUM_NETCONN*12 -- --struct tcp_hashbucket --{ -- sys_mutex_t mutex; -- struct hlist_head chain; --}; -- --struct tcp_hash_table --{ -- u32_t size; -- struct tcp_hashbucket array[TCP_HTABLE_SIZE]; --}; -- --extern PER_THREAD struct tcp_hash_table *tcp_active_htable; /* key: lport/fport/lip/fip */ -- --#define JHASH_INITVAL 0xdeadbeef -- --static inline unsigned int rol32(unsigned int word, unsigned int shift) --{ -- return (word << shift) | (word >> (32 - shift)); --} -- --#define __jhash_final(a, b, c) \ --{ \ -- c ^= b; c -= rol32(b, 14); \ -- a ^= c; a -= rol32(c, 11); \ -- b ^= a; b -= rol32(a, 25); \ -- c ^= b; c -= rol32(b, 16); \ -- a ^= c; a -= rol32(c, 4); \ -- b ^= a; b -= rol32(a, 14); \ -- c ^= b; c -= rol32(b, 24); \ --} -- --static inline unsigned int jhash_3words(unsigned int a, unsigned int b, unsigned int c) --{ -- a += JHASH_INITVAL; -- b += JHASH_INITVAL;; -- -- __jhash_final(a, b, c); -- -- return c; --} -- --#define TUPLE4_HASH_FN(laddr, lport, faddr, fport) jhash_3words(laddr, faddr,lport|(fport<<16)) -- --#endif /* GAZELLE_TCP_PCB_HASH */ -- - #if LWIP_EVENT_API - - enum lwip_event { -diff --git a/src/include/lwipopts.h b/src/include/lwipopts.h -index 4a93923..f39386f 100644 ---- a/src/include/lwipopts.h -+++ b/src/include/lwipopts.h -@@ -48,7 +48,11 @@ - - #define FRAME_MTU 1500 - -+#define GAZELLE_MAX_CLIENTS (20000) -+#define GAZELLE_RESERVED_CLIENTS (2000) -+ - #define GAZELLE_TCP_PCB_HASH 1 -+#define GAZELLE_TCP_ACTIVE_HTABLE_SIZE (GAZELLE_MAX_CLIENTS >> 1) - - #define GAZELLE_TCP_MAX_DATA_ACK_NUM 256 - -@@ -111,9 +115,6 @@ - ---------- Internal Memory Pool Sizes ---------- - ------------------------------------------------ - */ --#define GAZELLE_MAX_CLIENTS (20000) --#define GAZELLE_RESERVED_CLIENTS (2000) -- - #define LWIP_SUPPORT_CUSTOM_PBUF 1 - - #define MEMP_MEM_MALLOC 0 --- -2.22.0.windows.1 - diff --git a/0071-cleancode-refactor-sys_now-and-lwip_ioctl.patch b/0071-cleancode-refactor-sys_now-and-lwip_ioctl.patch deleted file mode 100644 index 9d7e97b..0000000 --- a/0071-cleancode-refactor-sys_now-and-lwip_ioctl.patch +++ /dev/null @@ -1,462 +0,0 @@ -From 877f1062b9f96a0f5f1aa39ee556f65d0b298aec Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Sat, 27 May 2023 10:59:48 +0800 -Subject: [PATCH 3/5] cleancode: refactor sys_now and lwip_ioctl - -Signed-off-by: Lemmy Huang ---- - src/api/api_msg.c | 2 -- - src/api/sockets.c | 33 ++-------------------- - src/api/sys_arch.c | 55 +++++++++++++++++++++---------------- - src/api/tcpip.c | 34 +++-------------------- - src/core/timeouts.c | 12 -------- - src/include/arch/sys_arch.h | 16 +++-------- - src/include/lwip/sockets.h | 21 +++----------- - src/include/lwip/tcp.h | 17 ------------ - src/include/lwip/tcpip.h | 2 +- - src/include/lwip/timeouts.h | 4 --- - 10 files changed, 46 insertions(+), 150 deletions(-) - -diff --git a/src/api/api_msg.c b/src/api/api_msg.c -index b4333f5..30929be 100644 ---- a/src/api/api_msg.c -+++ b/src/api/api_msg.c -@@ -55,9 +55,7 @@ - #include "lwip/priv/tcpip_priv.h" - - #if GAZELLE_ENABLE --#include "lwip/sockets.h" - #include "lwipsock.h" --#include "gazelle_posix_api.h" - extern void gazelle_connected_callback(struct netconn *conn); - #endif - -diff --git a/src/api/sockets.c b/src/api/sockets.c -index 8a7b9b8..dee9230 100644 ---- a/src/api/sockets.c -+++ b/src/api/sockets.c -@@ -3857,33 +3857,6 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_ - return err; - } - --#if GAZELLE_ENABLE --int --lwip_ioctl(int s, long cmd, ...) --{ -- struct lwip_sock *sock = get_socket(s); -- u8_t val; -- --#if LWIP_SO_RCVBUF -- int recv_avail; --#endif /* LWIP_SO_RCVBUF */ -- -- int ret = -1; -- void *argp; -- va_list ap; -- -- va_start(ap, cmd); -- argp = va_arg(ap, void *); -- va_end(ap); -- -- if (!sock) { -- return posix_api->ioctl_fn(s, cmd, argp); -- } -- if (POSIX_HAS_TYPE(sock, POSIX_KERNEL)) { -- if ((ret = posix_api->ioctl_fn(s, cmd, argp)) == -1) -- return ret; -- } --#else - int - lwip_ioctl(int s, long cmd, void *argp) - { -@@ -3896,7 +3869,6 @@ lwip_ioctl(int s, long cmd, void *argp) - if (!sock) { - return -1; - } --#endif /* GAZELLE_ENABLE */ - - switch (cmd) { - #if LWIP_SO_RCVBUF || LWIP_FIONREAD_LINUXMODE -@@ -4040,12 +4012,11 @@ lwip_fcntl(int s, int cmd, int val) - break; - default: - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_fcntl(%d, UNIMPL: %d, %d)\n", s, cmd, val)); -+ sock_set_errno(sock, ENOSYS); /* not yet implemented */ - #if GAZELLE_ENABLE - sock_set_errno(sock, 0); /* not yet implemented, but we return 0 for compatilbe with app */ - ret = 0; --#else -- sock_set_errno(sock, ENOSYS); /* not yet implemented */ --#endif -+#endif /* GAZELLE_ENABLE */ - break; - } - done_socket(sock); -diff --git a/src/api/sys_arch.c b/src/api/sys_arch.c -index d143a73..9b75391 100644 ---- a/src/api/sys_arch.c -+++ b/src/api/sys_arch.c -@@ -36,15 +36,45 @@ - #include - - #include -+#include - - #include "lwip/err.h" --#include "lwip/mem.h" - #include "lwip/memp.h" - #include "lwip/opt.h" - #include "lwip/sys.h" - #include "lwip/timeouts.h" - #include "arch/sys_arch.h" - -+#define SEC_TO_MSEC 1000 -+static u64_t g_sys_cycles_per_ms = 0; -+ -+/* -+ * Timer -+ * */ -+void sys_timer_init(void) -+{ -+ u64_t freq = rte_get_tsc_hz(); -+ if (g_sys_cycles_per_ms == 0) { -+ g_sys_cycles_per_ms = (freq + SEC_TO_MSEC - 1) / SEC_TO_MSEC; -+ } -+} -+ -+u32_t sys_now(void) -+{ -+ return (u32_t)(rte_rdtsc() / g_sys_cycles_per_ms); -+} -+ -+void sys_timer_run(void) -+{ -+ u32_t sleeptime; -+ -+ sleeptime = sys_timeouts_sleeptime(); -+ if (sleeptime == 0) { -+ sys_check_timeouts(); -+ } -+} -+ -+ - struct sys_mutex { - volatile unsigned int m; - }; -@@ -74,9 +104,6 @@ struct sys_mem_stats { - - static PER_THREAD struct sys_mem_stats hugepage_stats; - --static uint64_t cycles_per_ms __attribute__((aligned(64))); --static uint64_t sys_start_ms __attribute__((aligned(64))); -- - /* - * Mailbox - * */ -@@ -329,26 +356,6 @@ void sys_mutex_free(struct sys_mutex **mutex) - { - } - --/* Timer from DPDK */ --void sys_calibrate_tsc(void) --{ --#define MS_PER_SEC 1E3 -- uint64_t freq = rte_get_tsc_hz(); -- -- if (cycles_per_ms == 0) { -- cycles_per_ms = (freq + MS_PER_SEC - 1) / MS_PER_SEC; -- } -- if (sys_start_ms == 0) { -- sys_start_ms = rte_rdtsc() / cycles_per_ms; -- } --} -- --uint32_t sys_now(void) --{ -- uint64_t cur_ms = rte_rdtsc() / cycles_per_ms; -- return (uint32_t)(cur_ms - sys_start_ms); --} -- - /* - * Critical section - * */ -diff --git a/src/api/tcpip.c b/src/api/tcpip.c -index fe7a7bd..a7e312a 100644 ---- a/src/api/tcpip.c -+++ b/src/api/tcpip.c -@@ -56,13 +56,13 @@ - #define TCPIP_MSG_VAR_FREE(name) API_VAR_FREE(MEMP_TCPIP_MSG_API, name) - - /* global variables */ --static PER_THREAD tcpip_init_done_fn tcpip_init_done; --static PER_THREAD void *tcpip_init_done_arg; --static PER_THREAD sys_mbox_t tcpip_mbox; -+static tcpip_init_done_fn tcpip_init_done; -+static void *tcpip_init_done_arg; -+static sys_mbox_t tcpip_mbox; - - #if LWIP_TCPIP_CORE_LOCKING - /** The global semaphore to lock the stack. */ --PER_THREAD sys_mutex_t lock_tcpip_core; -+sys_mutex_t lock_tcpip_core; - #endif /* LWIP_TCPIP_CORE_LOCKING */ - - static void tcpip_thread_handle_msg(struct tcpip_msg *msg); -@@ -123,13 +123,8 @@ again: - * - * @param arg unused argument - */ --#if GAZELLE_ENABLE --__attribute__((unused)) static void --tcpip_thread(void *arg) --#else - static void - tcpip_thread(void *arg) --#endif /* GAZELLE_ENABLE */ - { - struct tcpip_msg *msg; - LWIP_UNUSED_ARG(arg); -@@ -247,9 +242,6 @@ tcpip_inpkt(struct pbuf *p, struct netif *inp, netif_input_fn input_fn) - #if LWIP_TCPIP_CORE_LOCKING_INPUT - err_t ret; - LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_inpkt: PACKET %p/%p\n", (void *)p, (void *)inp)); --#if GAZELLE_ENABLE && LWIP_TIMERS -- sys_timer_run(); --#endif - LOCK_TCPIP_CORE(); - ret = input_fn(p, inp); - UNLOCK_TCPIP_CORE(); -@@ -329,9 +321,6 @@ tcpip_callback(tcpip_callback_fn function, void *ctx) - msg->msg.cb.function = function; - msg->msg.cb.ctx = ctx; - --#if GAZELLE_ENABLE && LWIP_TIMER -- sys_timer_run(); --#endif - sys_mbox_post(&tcpip_mbox, msg); - return ERR_OK; - } -@@ -368,9 +357,6 @@ tcpip_try_callback(tcpip_callback_fn function, void *ctx) - msg->msg.cb.function = function; - msg->msg.cb.ctx = ctx; - --#if GAZELLE_ENABLE && LWIP_TIMER -- sys_timer_run(); --#endif - if (sys_mbox_trypost(&tcpip_mbox, msg) != ERR_OK) { - memp_free(MEMP_TCPIP_MSG_API, msg); - return ERR_MEM; -@@ -452,9 +438,6 @@ tcpip_send_msg_wait_sem(tcpip_callback_fn fn, void *apimsg, sys_sem_t *sem) - { - #if LWIP_TCPIP_CORE_LOCKING - LWIP_UNUSED_ARG(sem); --#if GAZELLE_ENABLE && LWIP_TIMERS -- sys_timer_run(); --#endif - LOCK_TCPIP_CORE(); - fn(apimsg); - UNLOCK_TCPIP_CORE(); -@@ -492,9 +475,6 @@ tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call_data *call) - #if LWIP_TCPIP_CORE_LOCKING - err_t err; - LOCK_TCPIP_CORE(); --#if GAZELLE_ENABLE && LWIP_TIMERS -- sys_timer_run(); --#endif - err = fn(call); - UNLOCK_TCPIP_CORE(); - return err; -@@ -557,10 +537,6 @@ tcpip_callbackmsg_new(tcpip_callback_fn function, void *ctx) - msg->type = TCPIP_MSG_CALLBACK_STATIC; - msg->msg.cb.function = function; - msg->msg.cb.ctx = ctx; -- --#if GAZELLE_ENABLE && LWIP_TIMER -- sys_timer_run(); --#endif - return (struct tcpip_callback_msg *)msg; - } - -@@ -638,9 +614,7 @@ tcpip_init(tcpip_init_done_fn initfunc, void *arg) - } - #endif /* LWIP_TCPIP_CORE_LOCKING */ - --#if !GAZELLE_ENABLE - sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO); --#endif - } - - /** -diff --git a/src/core/timeouts.c b/src/core/timeouts.c -index 2b80b0a..9d0c23e 100644 ---- a/src/core/timeouts.c -+++ b/src/core/timeouts.c -@@ -442,18 +442,6 @@ sys_timeouts_sleeptime(void) - } - } - --#if GAZELLE_ENABLE --void sys_timer_run(void) --{ -- u32_t sleeptime; -- -- sleeptime = sys_timeouts_sleeptime(); -- if (sleeptime == 0) { -- sys_check_timeouts(); -- } --} --#endif /* GAZELLE_ENABLE */ -- - #else /* LWIP_TIMERS && !LWIP_TIMERS_CUSTOM */ - /* Satisfy the TCP code which calls this function */ - void -diff --git a/src/include/arch/sys_arch.h b/src/include/arch/sys_arch.h -index 907c116..f2a0a49 100644 ---- a/src/include/arch/sys_arch.h -+++ b/src/include/arch/sys_arch.h -@@ -76,6 +76,10 @@ int sys_mbox_empty(struct sys_mbox *); - struct sys_thread; - typedef struct sys_thread *sys_thread_t; - -+void sys_timer_init(void); -+void sys_timer_run(void); -+u32_t sys_now(void); -+ - #if GAZELLE_ENABLE - extern int eth_dev_poll(void); - #include -@@ -124,16 +128,4 @@ static __rte_always_inline uint32_t gazelle_st_ring_dequeue_burst(struct rte_rin - } - #endif - --void sys_calibrate_tsc(void); --uint32_t sys_now(void); --__attribute__((always_inline)) inline int update_timeout(int timeout, uint32_t poll_ts) --{ -- uint32_t used_ms = sys_now() - poll_ts; -- if (timeout > 0 && used_ms < timeout) { -- return timeout; -- } else { -- return 0; -- } --} -- - #endif /* _LWIP_ARCH_SYS_ARCH_H_ */ -diff --git a/src/include/lwip/sockets.h b/src/include/lwip/sockets.h -index e59fdf4..643093a 100644 ---- a/src/include/lwip/sockets.h -+++ b/src/include/lwip/sockets.h -@@ -552,7 +552,7 @@ struct pollfd - short revents; - }; - #endif --#endif /* LWIP_SOCKET_POLL */ -+#endif /* GAZELLE_ENABLE */ - - /** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided - * by your system, set this to 0 and include in cc.h */ -@@ -615,6 +615,9 @@ int fcntl(int s, int cmd, ...); - #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */ - #endif /* LWIP_COMPAT_SOCKETS == 2 */ - -+int lwip_sock_make_addr(struct netconn *conn, ip_addr_t *fromaddr, u16_t port, -+ struct sockaddr *from, socklen_t *fromlen); -+ - int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen); - int lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags); - int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen); -@@ -646,17 +649,8 @@ int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptse - #if LWIP_SOCKET_POLL - int lwip_poll(struct pollfd *fds, nfds_t nfds, int timeout); - #endif -- --#if GAZELLE_ENABLE --int lwip_ioctl(int s, long cmd, ...); --int lwip_fcntl(int s, int cmd, int val); --int lwip_sock_make_addr(struct netconn *conn, ip_addr_t *fromaddr, u16_t port, -- struct sockaddr *from, socklen_t *fromlen); --#else - int lwip_ioctl(int s, long cmd, void *argp); - int lwip_fcntl(int s, int cmd, int val); --#endif /* GAZELLE_ENABLE */ -- - const char *lwip_inet_ntop(int af, const void *src, char *dst, socklen_t size); - int lwip_inet_pton(int af, const char *src, void *dst); - -@@ -722,17 +716,10 @@ int lwip_inet_pton(int af, const char *src, void *dst); - #define writev(s,iov,iovcnt) lwip_writev(s,iov,iovcnt) - /** @ingroup socket */ - #define close(s) lwip_close(s) -- --#if GAZELLE_ENABLE --#define fcntl(s,cmd...) lwip_fcntl(s,cmd) --#define ioctl(s,cmd...) lwip_ioctl(s,cmd) --#else - /** @ingroup socket */ - #define fcntl(s,cmd,val) lwip_fcntl(s,cmd,val) - /** @ingroup socket */ - #define ioctl(s,cmd,argp) lwip_ioctl(s,cmd,argp) --#endif /* GAZELLE_ENABLE */ -- - #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */ - #endif /* LWIP_COMPAT_SOCKETS != 2 */ - -diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h -index b093baa..432282f 100644 ---- a/src/include/lwip/tcp.h -+++ b/src/include/lwip/tcp.h -@@ -513,23 +513,6 @@ err_t tcp_tcp_get_tcp_addrinfo(struct tcp_pcb *pcb, int local, ip_add - - #define tcp_dbg_get_tcp_state(pcb) ((pcb)->state) - --enum tcp_list_state { -- ACTIVE_LIST, -- LISTEN_LIST, -- TIME_WAIT_LIST, --}; -- --struct tcp_pcb_dp { -- uint32_t state; -- uint32_t lip; -- uint32_t rip; -- uint16_t l_port; -- uint16_t r_port; -- uint32_t r_next; -- uint32_t s_next; -- uint32_t tcp_sub_state; --}; -- - /* for compatibility with older implementation */ - #define tcp_new_ip6() tcp_new_ip_type(IPADDR_TYPE_V6) - -diff --git a/src/include/lwip/tcpip.h b/src/include/lwip/tcpip.h -index d2c2440..0b8880a 100644 ---- a/src/include/lwip/tcpip.h -+++ b/src/include/lwip/tcpip.h -@@ -51,7 +51,7 @@ extern "C" { - - #if LWIP_TCPIP_CORE_LOCKING - /** The global semaphore to lock the stack. */ --extern PER_THREAD sys_mutex_t lock_tcpip_core; -+extern sys_mutex_t lock_tcpip_core; - #if !defined LOCK_TCPIP_CORE || defined __DOXYGEN__ - /** Lock lwIP core mutex (needs @ref LWIP_TCPIP_CORE_LOCKING 1) */ - #define LOCK_TCPIP_CORE() sys_mutex_lock(&lock_tcpip_core) -diff --git a/src/include/lwip/timeouts.h b/src/include/lwip/timeouts.h -index f7ffc5e..b601f9e 100644 ---- a/src/include/lwip/timeouts.h -+++ b/src/include/lwip/timeouts.h -@@ -119,10 +119,6 @@ struct sys_timeo** sys_timeouts_get_next_timeout(void); - void lwip_cyclic_timer(void *arg); - #endif - --#if GAZELLE_ENABLE --void sys_timer_run(void); --#endif /* GAZELLE_ENABLE */ -- - #endif /* LWIP_TIMERS */ - - #ifdef __cplusplus --- -2.22.0.windows.1 - diff --git a/0072-cleancode-refactor-OFFLOAD_CHECKSUM-GAZELLE_TCP_DATA.patch b/0072-cleancode-refactor-OFFLOAD_CHECKSUM-GAZELLE_TCP_DATA.patch deleted file mode 100644 index 079c578..0000000 --- a/0072-cleancode-refactor-OFFLOAD_CHECKSUM-GAZELLE_TCP_DATA.patch +++ /dev/null @@ -1,812 +0,0 @@ -From 04b8cb3f4577cd7bf62bc831ca32cdc8229ee5b8 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Sat, 27 May 2023 16:14:06 +0800 -Subject: [PATCH 4/5] cleancode: refactor OFFLOAD_CHECKSUM - GAZELLE_TCP_DATAACKS_REXMIT GAZELLE_TCP_NEW_PORT - -Signed-off-by: Lemmy Huang ---- - src/core/ipv4/icmp.c | 8 ++-- - src/core/ipv4/ip4.c | 12 +++--- - src/core/ipv4/ip4_frag.c | 14 +++---- - src/core/pbuf.c | 2 +- - src/core/tcp.c | 61 +++++++++++++++++++++--------- - src/core/tcp_in.c | 54 +++++++++++++------------- - src/core/tcp_out.c | 16 ++++---- - src/core/udp.c | 2 +- - src/include/gazelle_dpdk_offload.h | 43 ++++++++++----------- - src/include/gazelle_tcp_priv.h | 53 ++++++++++++++++++++++---- - src/include/lwip/pbuf.h | 2 +- - src/include/lwip/priv/tcp_priv.h | 37 ------------------ - src/include/lwip/tcp.h | 4 +- - src/include/lwipopts.h | 27 ++++++------- - src/netif/ethernet.c | 6 +-- - 15 files changed, 183 insertions(+), 158 deletions(-) - -diff --git a/src/core/ipv4/icmp.c b/src/core/ipv4/icmp.c -index 2b15ed4..9da81d9 100644 ---- a/src/core/ipv4/icmp.c -+++ b/src/core/ipv4/icmp.c -@@ -51,7 +51,7 @@ - - #include - --#if GAZELLE_ENABLE && CHECKSUM_GEN_IP_HW -+#if GAZELLE_ENABLE && OFFLOAD_CHECKSUM_GEN_IP - #include "gazelle_dpdk_offload.h" - #endif - -@@ -240,11 +240,11 @@ icmp_input(struct pbuf *p, struct netif *inp) - IPH_CHKSUM_SET(iphdr, 0); - #if CHECKSUM_GEN_IP - IF__NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_GEN_IP) { --#if CHECKSUM_GEN_IP_HW -+#if OFFLOAD_CHECKSUM_GEN_IP - if (get_eth_params_tx_ol() & DEV_TX_OFFLOAD_IPV4_CKSUM) { -- iph_cksum_set(p, hlen, 1); -+ ol_chksum_gen_ip(p, hlen, 1); - } else { -- iph_cksum_set(p, hlen, 0); -+ ol_chksum_gen_ip(p, hlen, 0); - IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, hlen)); - } - #else -diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c -index 079716d..444f496 100644 ---- a/src/core/ipv4/ip4.c -+++ b/src/core/ipv4/ip4.c -@@ -59,7 +59,7 @@ - - #include - --#if GAZELLE_ENABLE && (CHECKSUM_CHECK_IP_HW || CHECKSUM_GEN_IP_HW) -+#if GAZELLE_ENABLE && (OFFLOAD_CHECKSUM_CHECK_IP || OFFLOAD_CHECKSUM_GEN_IP) - #include "gazelle_dpdk_offload.h" - #endif - -@@ -501,10 +501,10 @@ ip4_input(struct pbuf *p, struct netif *inp) - /* verify checksum */ - #if CHECKSUM_CHECK_IP - IF__NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_CHECK_IP) { --#if CHECKSUM_CHECK_IP_HW -+#if OFFLOAD_CHECKSUM_CHECK_IP - u64_t ret; - if (get_eth_params_rx_ol() & DEV_RX_OFFLOAD_IPV4_CKSUM) { -- ret = is_cksum_ipbad(p); -+ ret = ol_chksum_check_ip(p); - } else { - ret = (u64_t)inet_chksum(iphdr, iphdr_hlen); - } -@@ -971,11 +971,11 @@ ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *d - IPH_CHKSUM_SET(iphdr, 0); - #if CHECKSUM_GEN_IP - IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_IP) { --#if CHECKSUM_GEN_IP_HW -+#if OFFLOAD_CHECKSUM_GEN_IP - if (get_eth_params_tx_ol() & DEV_TX_OFFLOAD_IPV4_CKSUM) { -- iph_cksum_set(p, ip_hlen, 1); -+ ol_chksum_gen_ip(p, ip_hlen, 1); - } else { -- iph_cksum_set(p, ip_hlen, 0); -+ ol_chksum_gen_ip(p, ip_hlen, 0); - IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, ip_hlen)); - } - #else -diff --git a/src/core/ipv4/ip4_frag.c b/src/core/ipv4/ip4_frag.c -index 4d697c8..4cc48e8 100644 ---- a/src/core/ipv4/ip4_frag.c -+++ b/src/core/ipv4/ip4_frag.c -@@ -51,7 +51,7 @@ - - #include - --#if GAZELLE_ENABLE && CHECKSUM_GEN_IP_HW -+#if GAZELLE_ENABLE && OFFLOAD_CHECKSUM_GEN_IP - #include "gazelle_dpdk_offload.h" - #endif - -@@ -641,11 +641,11 @@ ip4_reass(struct pbuf *p) - /* @todo: do we need to set/calculate the correct checksum? */ - #if CHECKSUM_GEN_IP - IF__NETIF_CHECKSUM_ENABLED(ip_current_input_netif(), NETIF_CHECKSUM_GEN_IP) { --#if CHECKSUM_GEN_IP_HW -+#if OFFLOAD_CHECKSUM_GEN_IP - if (get_eth_params_tx_ol() & DEV_TX_OFFLOAD_IPV4_CKSUM) { -- iph_cksum_set(p, IP_HLEN, 1); -+ ol_chksum_gen_ip(p, IP_HLEN, 1); - } else { -- iph_cksum_set(p, IP_HLEN, 0); -+ ol_chksum_gen_ip(p, IP_HLEN, 0); - IPH_CHKSUM_SET(fraghdr, inet_chksum(fraghdr, IP_HLEN)); - } - #else -@@ -884,11 +884,11 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) - IPH_CHKSUM_SET(iphdr, 0); - #if CHECKSUM_GEN_IP - IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_IP) { --#if CHECKSUM_GEN_IP_HW -+#if OFFLOAD_CHECKSUM_GEN_IP - if (get_eth_params_tx_ol() & DEV_TX_OFFLOAD_IPV4_CKSUM) { -- iph_cksum_set(p, IP_HLEN, 1); -+ ol_chksum_gen_ip(p, IP_HLEN, 1); - } else { -- iph_cksum_set(p, IP_HLEN, 0); -+ ol_chksum_gen_ip(p, IP_HLEN, 0); - IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, IP_HLEN)); - } - -diff --git a/src/core/pbuf.c b/src/core/pbuf.c -index 16615c6..bc629b4 100644 ---- a/src/core/pbuf.c -+++ b/src/core/pbuf.c -@@ -1030,7 +1030,7 @@ pbuf_copy_partial_pbuf(struct pbuf *p_to, const struct pbuf *p_from, u16_t copy_ - len_calc = p_to->len - offset_to; - } - --#if GAZELLE_ENABLE && (CHECKSUM_GEN_IP_HW || CHECKSUM_GEN_TCP_HW) -+#if GAZELLE_ENABLE && (OFFLOAD_CHECKSUM_GEN_IP || OFFLOAD_CHECKSUM_GEN_TCP) - p_to->l2_len = p_from->l2_len; - p_to->l3_len = p_from->l3_len; - p_to->ol_flags = p_from->ol_flags; -diff --git a/src/core/tcp.c b/src/core/tcp.c -index caba39d..e3355dc 100644 ---- a/src/core/tcp.c -+++ b/src/core/tcp.c -@@ -189,19 +189,21 @@ PER_THREAD u8_t tcp_active_pcbs_changed; - /** Timer counter to handle calling slow-timer from tcp_tmr() */ - static PER_THREAD u8_t tcp_timer; - static PER_THREAD u8_t tcp_timer_ctr; --#if GAZELLE_ENABLE -+ -+#if GAZELLE_TCP_NEW_PORT - static u16_t tcp_new_port(struct tcp_pcb *pcb); - static pthread_mutex_t g_tcp_port_mutex = PTHREAD_MUTEX_INITIALIZER; - static u8_t port_state[TCP_LOCAL_PORT_RANGE_END - TCP_LOCAL_PORT_RANGE_START + 1] = {0}; -+ - void release_port(u16_t port) - { - if (port >= TCP_LOCAL_PORT_RANGE_START && port <= TCP_LOCAL_PORT_RANGE_END) { - port_state[port - TCP_LOCAL_PORT_RANGE_START] = 0; - } - } --#else /* GAZELLE_ENABLE */ -+#else /* GAZELLE_TCP_NEW_PORT */ - static u16_t tcp_new_port(void); --#endif /* GAZELLE_ENABLE */ -+#endif /* GAZELLE_TCP_NEW_PORT */ - - #if GAZELLE_TCP_PCB_HASH - PER_THREAD struct tcp_hash_table *tcp_active_htable; /* key: lport/fport/lip/fip */ -@@ -255,6 +257,8 @@ tcp_free(struct tcp_pcb *pcb) - rte_memzone_free(sock->same_node_tx_ring_mz); - } - vdev_unreg_done(pcb); -+#endif -+#if GAZELLE_TCP_NEW_PORT - release_port(pcb->local_port); - #endif - LWIP_ASSERT("tcp_free: LISTEN", pcb->state != LISTEN); -@@ -755,7 +759,7 @@ tcp_bind(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) - #endif /* LWIP_IPV6 && LWIP_IPV6_SCOPES */ - - if (port == 0) { --#if GAZELLE_ENABLE -+#if GAZELLE_TCP_NEW_PORT - port = tcp_new_port(pcb); - #else - port = tcp_new_port(); -@@ -986,11 +990,12 @@ tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u8_t backlog, err_t *err) - /* copy over ext_args to listening pcb */ - memcpy(&lpcb->ext_args, &pcb->ext_args, sizeof(pcb->ext_args)); - #endif --#if GAZELLE_ENABLE -+#if GAZELLE_TCP_NEW_PORT - /* pcb transfer to lpcb and reg into tcp_listen_pcbs. freeing pcb shouldn't release sock table in here. - * local_port=0 avoid to release sock table in tcp_free */ - pcb->local_port = 0; -- -+#endif /* GAZELLE_TCP_NEW_PORT */ -+#if GAZELLE_ENABLE - char name[RING_NAME_LEN]; - snprintf(name, sizeof(name), "listen_rx_ring_%u", lpcb->local_port); - if (rte_ring_lookup(name) != NULL) { -@@ -999,7 +1004,7 @@ tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u8_t backlog, err_t *err) - } else { - same_node_ring_create(&lpcb->listen_rx_ring, SAME_NODE_RING_SIZE, lpcb->local_port, "listen", "rx"); - } --#endif -+#endif /* GAZELLE_ENABLE */ - tcp_free(pcb); - #if LWIP_CALLBACK_API - lpcb->accept = tcp_accept_null; -@@ -1112,13 +1117,9 @@ tcp_recved(struct tcp_pcb *pcb, u16_t len) - * - * @return a new (free) local TCP port number - */ --#if GAZELLE_ENABLE -+#if GAZELLE_TCP_NEW_PORT - static u16_t - tcp_new_port(struct tcp_pcb *pcb) --#else --static u16_t --tcp_new_port(void) --#endif - { - u16_t n = 0; - u16_t tmp_port = 0; -@@ -1131,16 +1132,11 @@ tcp_new_port(void) - } - - if (__atomic_load_n(&port_state[tcp_port - TCP_LOCAL_PORT_RANGE_START], __ATOMIC_ACQUIRE) == 0) { --#if GAZELLE_ENABLE - if (port_in_stack_queue(pcb->remote_ip.addr, pcb->local_ip.addr, pcb->remote_port, tcp_port)) { - tmp_port = tcp_port; - __atomic_store_n(&port_state[tcp_port - TCP_LOCAL_PORT_RANGE_START], 1, __ATOMIC_RELEASE); - break; - } --#else -- __atomic_store_n(&port_state[tcp_port - TCP_LOCAL_PORT_RANGE_START], 1, __ATOMIC_RELEASE); -- break; --#endif - } - - n++; -@@ -1154,6 +1150,35 @@ tcp_new_port(void) - return tmp_port; - } - -+#else /* GAZELLE_TCP_NEW_PORT */ -+static u16_t -+tcp_new_port(void) -+{ -+ u8_t i; -+ u16_t n = 0; -+ struct tcp_pcb *pcb; -+ -+again: -+ tcp_port++; -+ if (tcp_port == TCP_LOCAL_PORT_RANGE_END) { -+ tcp_port = TCP_LOCAL_PORT_RANGE_START; -+ } -+ /* Check all PCB lists. */ -+ for (i = 0; i < NUM_TCP_PCB_LISTS; i++) { -+ for (pcb = *tcp_pcb_lists[i]; pcb != NULL; pcb = pcb->next) { -+ if (pcb->local_port == tcp_port) { -+ n++; -+ if (n > (TCP_LOCAL_PORT_RANGE_END - TCP_LOCAL_PORT_RANGE_START)) { -+ return 0; -+ } -+ goto again; -+ } -+ } -+ } -+ return tcp_port; -+} -+#endif /* GAZELLE_TCP_NEW_PORT */ -+ - /** - * @ingroup tcp_raw - * Connects to another host. The function given as the "connected" -@@ -1234,7 +1259,7 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port, - - old_local_port = pcb->local_port; - if (pcb->local_port == 0) { --#if GAZELLE_ENABLE -+#if GAZELLE_TCP_NEW_PORT - pcb->local_port = tcp_new_port(pcb); - #else - pcb->local_port = tcp_new_port(); -diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c -index 575bf05..70c125a 100644 ---- a/src/core/tcp_in.c -+++ b/src/core/tcp_in.c -@@ -65,9 +65,9 @@ - - #include - --#if GAZELLE_ENABLE && CHECKSUM_CHECK_TCP_HW -+#if GAZELLE_ENABLE && OFFLOAD_CHECKSUM_CHECK_TCP - #include --#endif /* CHECKSUM_CHECK_TCP_HW */ -+#endif /* OFFLOAD_CHECKSUM_CHECK_TCP */ - - #ifdef LWIP_HOOK_FILENAME - #include LWIP_HOOK_FILENAME -@@ -168,10 +168,10 @@ tcp_input(struct pbuf *p, struct netif *inp) - #if CHECKSUM_CHECK_TCP - IF__NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_CHECK_TCP) { - /* Verify TCP checksum. */ --#if CHECKSUM_CHECK_TCP_HW -+#if OFFLOAD_CHECKSUM_CHECK_TCP - u64_t ret; - if (get_eth_params_rx_ol() & DEV_RX_OFFLOAD_TCP_CKSUM) { -- ret = is_cksum_tcpbad(p); -+ ret = ol_chksum_check_tcp(p); - } else { - ret = (u64_t)ip_chksum_pseudo(p, IP_PROTO_TCP, p->tot_len, - ip_current_src_addr(), ip_current_dest_addr()); -@@ -271,12 +271,9 @@ tcp_input(struct pbuf *p, struct netif *inp) - - #if GAZELLE_TCP_PCB_HASH - pcb = NULL; -- u32_t idx; - struct hlist_head *head; -- idx = TUPLE4_HASH_FN( ip_current_dest_addr()->addr, tcphdr->dest, -- ip_current_src_addr()->addr, tcphdr->src) & -- (tcp_active_htable->size - 1); -- head = &tcp_active_htable->array[idx].chain; -+ u32_t idx = tcp_hash_tuple4_fn(ip_current_dest_addr()->addr, tcphdr->dest, ip_current_src_addr()->addr, tcphdr->src); -+ head = &tcp_active_htable->array[idx & (tcp_active_htable->size - 1)].chain; - hlist_for_each_entry(pcb, head, tcp_node) { - #else - for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) { -@@ -1252,7 +1249,6 @@ tcp_receive(struct tcp_pcb *pcb) - s16_t m; - u32_t right_wnd_edge; - int found_dupack = 0; -- int found_dataack = 0; - - LWIP_ASSERT("tcp_receive: invalid pcb", pcb != NULL); - LWIP_ASSERT("tcp_receive: wrong state", pcb->state >= ESTABLISHED); -@@ -1329,33 +1325,37 @@ tcp_receive(struct tcp_pcb *pcb) - } - } - } -- } else { -- /* fast rexmit when receive too many acks with data */ -- if (TCP_SEQ_LT(ackno + 1, pcb->snd_nxt)) { -- if (pcb->snd_wl2 + pcb->snd_wnd == right_wnd_edge) { -- if (pcb->rtime >= 0) { -- if (pcb->lastack == ackno) { -- found_dataack = 1; -- ++pcb->dataacks; -- if ((pcb->dataacks > GAZELLE_TCP_MAX_DATA_ACK_NUM) && (pcb->nrtx < (TCP_MAXRTX / 2))) { -- if (tcp_rexmit(pcb) == ERR_OK) { -- pcb->rtime = 0; -- pcb->dataacks = 0; -- } -+ } -+#if GAZELLE_TCP_DATAACKS_REXMIT -+ /* fast rexmit when receive too many acks with data */ -+ /* if (tcplen != 0) */ -+ /* and skip (ackno + 1 == pcb->snd_nxt) */ -+ else if (TCP_SEQ_LT(ackno + 1, pcb->snd_nxt)) { -+ int found_dataack = 0; -+ if (pcb->snd_wl2 + pcb->snd_wnd == right_wnd_edge) { -+ if (pcb->rtime >= 0) { -+ if (pcb->lastack == ackno) { -+ found_dataack = 1; -+ ++pcb->dataacks; -+ if ((pcb->dataacks > GAZELLE_TCP_DATAACKS_NUM) && (pcb->nrtx < (TCP_MAXRTX / 2))) { -+ if (tcp_rexmit(pcb) == ERR_OK) { -+ pcb->rtime = 0; -+ pcb->dataacks = 0; - } - } - } - } - } -+ if (!found_dataack) { -+ pcb->dataacks = 0; -+ } - } -+#endif /* GAZELLE_TCP_DATAACKS_REXMIT */ - /* If Clause (1) or more is true, but not a duplicate ack, reset - * count of consecutive duplicate acks */ - if (!found_dupack) { - pcb->dupacks = 0; - } -- if (!found_dataack) { -- pcb->dataacks = 0; -- } - } else if (TCP_SEQ_BETWEEN(ackno, pcb->lastack + 1, pcb->snd_nxt)) { - /* We come here when the ACK acknowledges new data. */ - tcpwnd_size_t acked; -@@ -1381,7 +1381,9 @@ tcp_receive(struct tcp_pcb *pcb) - /* Reset the fast retransmit variables. */ - pcb->dupacks = 0; - pcb->lastack = ackno; -+#if GAZELLE_TCP_DATAACKS_REXMIT - pcb->dataacks = 0; -+#endif - - /* Update the congestion control variables (cwnd and - ssthresh). */ -diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c -index fde3b8f..08859f5 100644 ---- a/src/core/tcp_out.c -+++ b/src/core/tcp_out.c -@@ -83,7 +83,7 @@ - #if GAZELLE_ENABLE - #include "lwipsock.h" - #include --#if CHECKSUM_GEN_TCP_HW -+#if OFFLOAD_CHECKSUM_GEN_TCP - #include "gazelle_dpdk_offload.h" - #endif - #endif -@@ -1825,10 +1825,10 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif - - #if CHECKSUM_GEN_TCP - IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_TCP) { --#if CHECKSUM_GEN_TCP_HW -+#if OFFLOAD_CHECKSUM_GEN_TCP - if (get_eth_params_tx_ol() & DEV_TX_OFFLOAD_TCP_CKSUM) { -- tcph_cksum_set(seg->p, TCPH_HDRLEN_BYTES(seg->tcphdr)); -- seg->tcphdr->chksum = ip_chksum_pseudo_offload(IP_PROTO_TCP,seg->p->tot_len, &pcb->local_ip, &pcb->remote_ip); -+ ol_chksum_gen_tcp(seg->p, TCPH_HDRLEN_BYTES(seg->tcphdr)); -+ seg->tcphdr->chksum = ol_ip_chksum_pseudo(IP_PROTO_TCP,seg->p->tot_len, &pcb->local_ip, &pcb->remote_ip); - } else { - #if TCP_CHECKSUM_ON_COPY - u32_t acc; -@@ -1901,7 +1901,7 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif - seg->tcphdr->chksum = ip_chksum_pseudo(seg->p, IP_PROTO_TCP, - seg->p->tot_len, &pcb->local_ip, &pcb->remote_ip); - #endif /* TCP_CHECKSUM_ON_COPY */ --#endif /* CHECKSUM_GEN_TCP_HW */ -+#endif /* OFFLOAD_CHECKSUM_GEN_TCP */ - } - #endif /* CHECKSUM_GEN_TCP */ - TCP_STATS_INC(tcp.xmit); -@@ -2261,10 +2261,10 @@ tcp_output_control_segment(struct tcp_pcb *pcb, struct pbuf *p, - #if CHECKSUM_GEN_TCP - IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_TCP) { - struct tcp_hdr *tcphdr = (struct tcp_hdr *)p->payload; --#if CHECKSUM_GEN_TCP_HW -+#if OFFLOAD_CHECKSUM_GEN_TCP - if (get_eth_params_tx_ol() & DEV_TX_OFFLOAD_TCP_CKSUM) { -- tcph_cksum_set(p, TCPH_HDRLEN_BYTES(tcphdr)); -- tcphdr->chksum = ip_chksum_pseudo_offload(IP_PROTO_TCP, p->tot_len, src, dst); -+ ol_chksum_gen_tcp(p, TCPH_HDRLEN_BYTES(tcphdr)); -+ tcphdr->chksum = ol_ip_chksum_pseudo(IP_PROTO_TCP, p->tot_len, src, dst); - } else { - tcphdr->chksum = ip_chksum_pseudo(p, IP_PROTO_TCP, p->tot_len, - src, dst); -diff --git a/src/core/udp.c b/src/core/udp.c -index fc86ac5..170c911 100644 ---- a/src/core/udp.c -+++ b/src/core/udp.c -@@ -911,7 +911,7 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d - LWIP_DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,0x%02"X16_F",)\n", (u16_t)ip_proto)); - /* output to IP */ - NETIF_SET_HINTS(netif, &(pcb->netif_hints)); -- udph_cksum_set(q, UDP_HLEN); -+ ol_chksum_gen_udp(q, UDP_HLEN); - err = ip_output_if_src(q, src_ip, dst_ip, ttl, pcb->tos, ip_proto, netif); - NETIF_RESET_HINTS(netif); - -diff --git a/src/include/gazelle_dpdk_offload.h b/src/include/gazelle_dpdk_offload.h -index 0548258..c905a31 100644 ---- a/src/include/gazelle_dpdk_offload.h -+++ b/src/include/gazelle_dpdk_offload.h -@@ -34,60 +34,59 @@ - #define _GAZELLE_DPDK_OFFLOAD_H_ - - #include "lwipopts.h" -+ - #if GAZELLE_ENABLE - #include -- --#if CHECKSUM_OFFLOAD_ALL - #include - #include "lwip/pbuf.h" --#endif - - extern uint64_t get_eth_params_rx_ol(void); - extern uint64_t get_eth_params_tx_ol(void); --#if CHECKSUM_CHECK_IP_HW --// for ip4_input --static inline u64_t is_cksum_ipbad(struct pbuf *p) { -+ -+#if OFFLOAD_CHECKSUM_CHECK_IP -+// replaces inet_chksum() for ip4_input -+static inline u64_t ol_chksum_check_ip(struct pbuf *p) { - return p->ol_flags & (RTE_MBUF_F_RX_IP_CKSUM_BAD); - } --#endif /* CHECKSUM_CHECK_IP_HW */ -+#endif /* OFFLOAD_CHECKSUM_CHECK_IP */ - --#if CHECKSUM_CHECK_TCP_HW --// for tcp_input --static inline u64_t is_cksum_tcpbad(struct pbuf *p) { -+#if OFFLOAD_CHECKSUM_CHECK_TCP -+// replace ip_chksum_pseudo() for tcp_input -+static inline u64_t ol_chksum_check_tcp(struct pbuf *p) { - return p->ol_flags & (RTE_MBUF_F_RX_L4_CKSUM_BAD); - } --#endif /* CHECKSUM_CHECK_TCP_HW */ -+#endif /* OFFLOAD_CHECKSUM_CHECK_TCP */ - --#if CHECKSUM_GEN_IP_HW --static inline void ethh_cksum_set(struct pbuf *p, u16_t len) { -+#if OFFLOAD_CHECKSUM_GEN_IP -+static inline void ol_chksum_gen_eth(struct pbuf *p, u16_t len) { - p->l2_len = len; - } - --// replaces IPH_CHKSUM_SET --static inline void iph_cksum_set(struct pbuf *p, u16_t len, bool do_ipcksum) { -+// replaces inet_chksum() for ip4_output -+static inline void ol_chksum_gen_ip(struct pbuf *p, u16_t len, bool do_ipcksum) { - p->ol_flags |= RTE_MBUF_F_TX_IPV4; - if (do_ipcksum) { - p->ol_flags |= RTE_MBUF_F_TX_IP_CKSUM; - } - p->l3_len = len; - } --#endif /* CHECKSUM_GEN_IP_HW */ -+#endif /* OFFLOAD_CHECKSUM_GEN_IP */ - - // replace ip_chksum_pseudo --#if CHECKSUM_GEN_TCP_HW -+#if OFFLOAD_CHECKSUM_GEN_TCP - #include - --static inline void tcph_cksum_set(struct pbuf *p, u16_t len) { -+// replace ip_chksum_pseudo() for tcp_output -+static inline void ol_chksum_gen_tcp(struct pbuf *p, u16_t len) { - p->l4_len = len; - p->ol_flags |= RTE_MBUF_F_TX_TCP_CKSUM; - } - --static inline void udph_cksum_set(struct pbuf *p, u16_t len) { -+static inline void ol_chksum_gen_udp(struct pbuf *p, u16_t len) { - p->l4_len = len; - } - --static inline u16_t ip_chksum_pseudo_offload(u8_t proto, u16_t proto_len, -- const ip_addr_t *src, const ip_addr_t *dst) -+static inline u16_t ol_ip_chksum_pseudo(u8_t proto, u16_t proto_len, const ip_addr_t *src, const ip_addr_t *dst) - { - struct ipv4_psd_header { - uint32_t src_addr; /* IP address of source host. */ -@@ -105,7 +104,7 @@ static inline u16_t ip_chksum_pseudo_offload(u8_t proto, u16_t proto_len, - - return rte_raw_cksum(&psd_hdr, sizeof(psd_hdr)); - } --#endif /* CHECKSUM_GEN_TCP_HW */ -+#endif /* OFFLOAD_CHECKSUM_GEN_TCP */ - - #endif /* GAZELLE_ENABLE */ - #endif /* _GAZELLE_DPDK_OFFLOAD_H_ */ -diff --git a/src/include/gazelle_tcp_priv.h b/src/include/gazelle_tcp_priv.h -index 01d4953..fee9a0a 100644 ---- a/src/include/gazelle_tcp_priv.h -+++ b/src/include/gazelle_tcp_priv.h -@@ -35,7 +35,6 @@ - - #include "lwip/opt.h" - #include "lwip/sys.h" --#include "gazelle_hlist.h" - - #define __TCP_REG(pcbs, npcb) \ - do { \ -@@ -96,6 +95,10 @@ - #endif /* LWIP_DEBUG */ - - #if GAZELLE_TCP_PCB_HASH -+#include "gazelle_hlist.h" -+#include -+#define tcp_hash_tuple4_fn(lip, lport, rip, rport) rte_jhash_3words(lip, rip, lport|(rport<<16), 0) -+ - struct tcp_hashbucket { - sys_mutex_t mutex; - struct hlist_head chain; -@@ -106,17 +109,13 @@ struct tcp_hash_table { - }; - extern PER_THREAD struct tcp_hash_table *tcp_active_htable; /* key: lport/fport/lip/fip */ - --#include --#define TUPLE4_HASH_FN(laddr, lport, faddr, fport) rte_jhash_3words(laddr, faddr, lport|(fport<<16), 0) -- - #define TCP_REG_HASH(pcbs, npcb) \ - do { \ - struct hlist_head *head; \ - struct tcp_hash_table *htb = pcbs; \ -- u32_t idx = TUPLE4_HASH_FN((npcb)->local_ip.addr, (npcb)->local_port, \ -- (npcb)->remote_ip.addr, (npcb)->remote_port) & \ -- (htb->size - 1); \ -- head = &htb->array[idx].chain; \ -+ u32_t idx = tcp_hash_tuple4_fn((npcb)->local_ip.addr, (npcb)->local_port, \ -+ (npcb)->remote_ip.addr, (npcb)->remote_port); \ -+ head = &htb->array[idx & (htb->size - 1)].chain; \ - hlist_add_head(&(npcb)->tcp_node, head); \ - tcp_timer_needed(); \ - } while (0) -@@ -152,4 +151,42 @@ extern PER_THREAD struct tcp_hash_table *tcp_active_htable; /* key: lport/fport/ - } while (0) - #endif /* GAZELLE_TCP_REUSE_IPPORT */ - -+ -+#if GAZELLE_ENABLE -+#include "gazelle_tcp_reg.h" -+static inline int vdev_reg_done(enum reg_ring_type reg_type, const struct tcp_pcb *pcb) -+{ -+ LWIP_ASSERT("Invalid parameter", pcb != NULL); -+ -+ struct gazelle_quintuple qtuple; -+ qtuple.protocol = 0; -+ qtuple.src_ip = pcb->local_ip.addr; -+ qtuple.src_port = lwip_htons(pcb->local_port); -+ qtuple.dst_ip = pcb->remote_ip.addr; -+ qtuple.dst_port = lwip_htons(pcb->remote_port); -+ -+#if GAZELLE_TCP_REUSE_IPPORT -+ if (reg_type == REG_RING_TCP_CONNECT_CLOSE) { -+ struct tcp_pcb_listen* lpcb = pcb->listener; -+ if (lpcb != NULL) { -+ lpcb->connect_num--; -+ } -+ } -+#endif -+ -+ return vdev_reg_xmit(reg_type, &qtuple); -+} -+static inline void vdev_unreg_done(const struct tcp_pcb *pcb) -+{ -+ if (pcb->local_port == 0) { -+ return; -+ } -+ if (pcb->state == LISTEN) { -+ vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, pcb); -+ } else { -+ vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, pcb); -+ } -+} -+#endif -+ - #endif /* __GAZELLE_TCP_PRIV_H__ */ -\ No newline at end of file -diff --git a/src/include/lwip/pbuf.h b/src/include/lwip/pbuf.h -index fb21134..728c5e4 100644 ---- a/src/include/lwip/pbuf.h -+++ b/src/include/lwip/pbuf.h -@@ -222,7 +222,7 @@ struct pbuf { - /** For incoming packets, this contains the input netif's index */ - u8_t if_idx; - --#if GAZELLE_ENABLE && CHECKSUM_OFFLOAD_ALL -+#if GAZELLE_ENABLE && OFFLOAD_CHECKSUM_ENABLE - /** checksum offload ol_flags */ - u64_t ol_flags; - /* < L2 (MAC) Header Length for non-tunneling pkt. */ -diff --git a/src/include/lwip/priv/tcp_priv.h b/src/include/lwip/priv/tcp_priv.h -index 7a04c99..074528e 100644 ---- a/src/include/lwip/priv/tcp_priv.h -+++ b/src/include/lwip/priv/tcp_priv.h -@@ -340,43 +340,6 @@ extern PER_THREAD struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in T - #define NUM_TCP_PCB_LISTS 4 - extern PER_THREAD struct tcp_pcb ** tcp_pcb_lists[NUM_TCP_PCB_LISTS]; - --#if GAZELLE_ENABLE --#include "gazelle_tcp_reg.h" --static inline int vdev_reg_done(enum reg_ring_type reg_type, const struct tcp_pcb *pcb) --{ -- LWIP_ASSERT("Invalid parameter", pcb != NULL); -- -- struct gazelle_quintuple qtuple; -- qtuple.protocol = 0; -- qtuple.src_ip = pcb->local_ip.addr; -- qtuple.src_port = lwip_htons(pcb->local_port); -- qtuple.dst_ip = pcb->remote_ip.addr; -- qtuple.dst_port = lwip_htons(pcb->remote_port); -- --#if GAZELLE_TCP_REUSE_IPPORT -- if (reg_type == REG_RING_TCP_CONNECT_CLOSE) { -- struct tcp_pcb_listen* lpcb = pcb->listener; -- if (lpcb != NULL) { -- lpcb->connect_num--; -- } -- } --#endif -- -- return vdev_reg_xmit(reg_type, &qtuple); --} --static inline void vdev_unreg_done(const struct tcp_pcb *pcb) --{ -- if (pcb->local_port == 0) { -- return; -- } -- if (pcb->state == LISTEN) { -- vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, pcb); -- } else { -- vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, pcb); -- } --} --#endif -- - /* Axioms about the above lists: - 1) Every TCP PCB that is not CLOSED is in one of the lists. - 2) A PCB is only in one of the lists. -diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h -index 432282f..ef51895 100644 ---- a/src/include/lwip/tcp.h -+++ b/src/include/lwip/tcp.h -@@ -326,8 +326,10 @@ struct tcp_pcb { - - /* fast retransmit/recovery */ - u8_t dupacks; -- u32_t dataacks; - u32_t lastack; /* Highest acknowledged seqno. */ -+#if GAZELLE_TCP_DATAACKS_REXMIT -+ u32_t dataacks; -+#endif - - /* congestion avoidance/control variables */ - tcpwnd_size_t cwnd; -diff --git a/src/include/lwipopts.h b/src/include/lwipopts.h -index f39386f..6b5a2d1 100644 ---- a/src/include/lwipopts.h -+++ b/src/include/lwipopts.h -@@ -52,9 +52,12 @@ - #define GAZELLE_RESERVED_CLIENTS (2000) - - #define GAZELLE_TCP_PCB_HASH 1 --#define GAZELLE_TCP_ACTIVE_HTABLE_SIZE (GAZELLE_MAX_CLIENTS >> 1) -+#define GAZELLE_TCP_ACTIVE_HTABLE_SIZE 32768 - --#define GAZELLE_TCP_MAX_DATA_ACK_NUM 256 -+#define GAZELLE_TCP_NEW_PORT 1 -+ -+#define GAZELLE_TCP_DATAACKS_REXMIT 1 -+#define GAZELLE_TCP_DATAACKS_NUM 256 - - #define GAZELLE_TCP_MAX_PBUF_CHAIN_LEN 40 - -@@ -67,22 +70,16 @@ - */ - #define LWIP_CHECKSUM_CTRL_PER_NETIF 1 /* checksum ability check before checksum*/ - --// rx cksum --#define CHECKSUM_CHECK_IP 1 /* master switch */ --#define CHECKSUM_CHECK_TCP 1 /* master switch */ --// tx cksum --#define CHECKSUM_GEN_IP 1 /* master switch */ --#define CHECKSUM_GEN_TCP 1 /* master switch */ -- - // rx offload cksum --#define CHECKSUM_CHECK_IP_HW (1 && CHECKSUM_CHECK_IP) /* hardware switch */ --#define CHECKSUM_CHECK_TCP_HW (1 && CHECKSUM_CHECK_TCP) /* hardware switch */ -+#define OFFLOAD_CHECKSUM_CHECK_IP (1 && CHECKSUM_CHECK_IP) /* hardware switch */ -+#define OFFLOAD_CHECKSUM_CHECK_TCP (1 && CHECKSUM_CHECK_TCP) /* hardware switch */ - // tx offload cksum --#define CHECKSUM_GEN_IP_HW (1 && CHECKSUM_GEN_IP) /* hardware switch */ --#define CHECKSUM_GEN_TCP_HW (1 && CHECKSUM_GEN_TCP) /* hardware switch */ -- --#define CHECKSUM_OFFLOAD_ALL (CHECKSUM_GEN_IP_HW || CHECKSUM_GEN_TCP_HW || CHECKSUM_CHECK_IP_HW || CHECKSUM_CHECK_TCP_HW) -+#define OFFLOAD_CHECKSUM_GEN_IP (1 && CHECKSUM_GEN_IP) /* hardware switch */ -+#define OFFLOAD_CHECKSUM_GEN_TCP (1 && CHECKSUM_GEN_TCP) /* hardware switch */ - -+#define OFFLOAD_CHECKSUM_ENABLE \ -+ (OFFLOAD_CHECKSUM_CHECK_IP || OFFLOAD_CHECKSUM_CHECK_TCP || \ -+ OFFLOAD_CHECKSUM_GEN_IP || OFFLOAD_CHECKSUM_GEN_TCP) - - /* - --------------------------------------- -diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c -index deddf3f..8310485 100644 ---- a/src/netif/ethernet.c -+++ b/src/netif/ethernet.c -@@ -56,7 +56,7 @@ - #include "netif/ppp/pppoe.h" - #endif /* PPPOE_SUPPORT */ - --#if GAZELLE_ENABLE && (CHECKSUM_GEN_TCP_HW || CHECKSUM_GEN_IP_HW) -+#if GAZELLE_ENABLE && (OFFLOAD_CHECKSUM_GEN_TCP || OFFLOAD_CHECKSUM_GEN_IP) - #include "gazelle_dpdk_offload.h" - #endif - -@@ -312,8 +312,8 @@ ethernet_output(struct netif * netif, struct pbuf * p, - LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, - ("ethernet_output: sending packet %p\n", (void *)p)); - --#if CHECKSUM_GEN_IP_HW || CHECKSUM_GEN_TCP_HW -- ethh_cksum_set(p, sizeof(*ethhdr)); -+#if OFFLOAD_CHECKSUM_GEN_IP || OFFLOAD_CHECKSUM_GEN_TCP -+ ol_chksum_gen_eth(p, sizeof(*ethhdr)); - #endif - - /* send the packet */ --- -2.22.0.windows.1 - diff --git a/0073-cleancode-refactor-memp.patch b/0073-cleancode-refactor-memp.patch deleted file mode 100644 index ea57006..0000000 --- a/0073-cleancode-refactor-memp.patch +++ /dev/null @@ -1,598 +0,0 @@ -From 83add6124dba70b56b6d8ac1ce0b790d5ac4b230 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Mon, 29 May 2023 10:08:56 +0800 -Subject: [PATCH 5/5] cleancode: refactor memp - -Signed-off-by: Lemmy Huang ---- - src/api/sys_arch.c | 152 ++++++++++++++++++++---------------- - src/core/init.c | 4 +- - src/core/mem.c | 5 ++ - src/core/memp.c | 7 +- - src/include/arch/cc.h | 64 ++++++--------- - src/include/arch/sys_arch.h | 59 ++++++++------ - src/include/lwip/memp.h | 19 +---- - src/include/memp_def.h | 66 ---------------- - 8 files changed, 163 insertions(+), 213 deletions(-) - delete mode 100644 src/include/memp_def.h - -diff --git a/src/api/sys_arch.c b/src/api/sys_arch.c -index 9b75391..928dee0 100644 ---- a/src/api/sys_arch.c -+++ b/src/api/sys_arch.c -@@ -39,19 +39,21 @@ - #include - - #include "lwip/err.h" --#include "lwip/memp.h" - #include "lwip/opt.h" - #include "lwip/sys.h" - #include "lwip/timeouts.h" - #include "arch/sys_arch.h" - -+#define MBOX_NAME_PREFIX "_mbox_0x" -+#define MAX_MBOX_NAME_LEN (sizeof(MBOX_NAME_PREFIX) + 32) // log(UINT64_MAX) < 32 -+ - #define SEC_TO_MSEC 1000 - static u64_t g_sys_cycles_per_ms = 0; - - /* - * Timer - * */ --void sys_timer_init(void) -+static void sys_timer_init(void) - { - u64_t freq = rte_get_tsc_hz(); - if (g_sys_cycles_per_ms == 0) { -@@ -66,47 +68,68 @@ u32_t sys_now(void) - - void sys_timer_run(void) - { -- u32_t sleeptime; -+ u32_t sleeptime; - -- sleeptime = sys_timeouts_sleeptime(); -- if (sleeptime == 0) { -- sys_check_timeouts(); -- } -+ sleeptime = sys_timeouts_sleeptime(); -+ if (sleeptime == 0) { -+ sys_check_timeouts(); -+ } - } - -+void sys_nameid(const char *name, unsigned id, char *nameid, unsigned size) -+{ -+ int ret = snprintf(nameid, size, "%s_%02hu", name, id); -+ if (ret < 0) { -+ LWIP_DEBUGF(SYS_DEBUG, ("sys_nameid: sprintf nameid failed\n")); -+ rte_exit(EXIT_FAILURE, "sprintf nameid failed\n"); -+ } -+} - --struct sys_mutex { -- volatile unsigned int m; --}; -+/* -+ * Threads -+ * */ -+void thread_create(const char *name, unsigned id, thread_fn func, void *arg) -+{ -+ int ret; -+ pthread_t tid; -+ char thread_name[SYS_NAME_LEN]; - --struct sys_mutex lstack_mutex; -+ ret = pthread_create(&tid, NULL, func, arg); -+ if (ret != 0) { -+ LWIP_DEBUGF(SYS_DEBUG, ("thread_create: pthread_create failed\n")); -+ rte_exit(EXIT_FAILURE, "pthread_create failed\n"); -+ } - --struct sys_sem lstack_sem; -+ sys_nameid(name, id, thread_name, sizeof(thread_name)); -+ ret = pthread_setname_np(tid, thread_name); -+ if (ret != 0) { -+ LWIP_DEBUGF(SYS_DEBUG, ("thread_create: pthread_setname_np %s failed\n", thread_name)); -+ } -+} - --#define MAX_THREAD_NAME 64 --#define MBOX_NAME_PREFIX "_mbox_0x" --#define MAX_MBOX_NAME_LEN (sizeof(MBOX_NAME_PREFIX) + 32) // log(UINT64_MAX) < 32 -+sys_thread_t sys_thread_new(const char *name, lwip_thread_fn function, void *arg, int stacksize, int prio) -+{ -+ sys_thread_t thread; - --struct sys_thread { -- struct sys_thread *next; -- char name[MAX_THREAD_NAME]; -- lwip_thread_fn fn; -- void *arg; -- int stacksize; -- int prio; -- pthread_t tid; --}; -+ thread = (sys_thread_t)malloc(sizeof(*thread)); -+ if (thread == NULL) { -+ LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: malloc sys_thread failed\n")); -+ rte_exit(EXIT_FAILURE, "malloc sys_thread failed\n"); -+ } - -+ thread_create(name, 0, (thread_fn)function, arg); - --struct sys_mem_stats { -- uint32_t tot_len; --}; -+ snprintf(thread->name, sizeof(thread->name), "%s", name); -+ thread->stacksize = stacksize; -+ thread->prio = prio; - --static PER_THREAD struct sys_mem_stats hugepage_stats; -+ return thread; -+} - - /* - * Mailbox - * */ -+extern int eth_dev_poll(void); - static int mbox_wait_func(void) - { - #if LWIP_TIMERS -@@ -230,38 +253,6 @@ int sys_mbox_empty(struct sys_mbox *mb) - return rte_ring_count(mb->ring) == 0; - } - --/* -- * Threads -- * */ --sys_thread_t sys_thread_new(const char *name, lwip_thread_fn function, void *arg, int stacksize, int prio) --{ -- int err; -- pthread_t tid; -- struct sys_thread *thread; -- -- thread = (struct sys_thread *)malloc(sizeof(struct sys_thread)); -- if (thread == NULL) { -- LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: malloc sys_thread failed\n")); -- rte_exit(EXIT_FAILURE, "malloc sys_thread failed\n"); -- } -- -- err = pthread_create(&tid, NULL, (void*(*)(void *))function, arg); -- if (err > 0) { -- LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: pthread_create failed\n")); -- rte_exit(EXIT_FAILURE, "pthread_create failed\n"); -- } -- -- err = pthread_setname_np(tid, name); -- if (err > 0) { -- LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: pthread_setname_np failed\n")); -- } -- thread->tid = tid; -- thread->stacksize = stacksize; -- thread->prio = prio; -- -- return thread; --} -- - /* - * Semaphore - * */ -@@ -332,7 +323,7 @@ uint32_t sys_arch_sem_wait(struct sys_sem **s, uint32_t timeout) - - void sys_sem_free(struct sys_sem **s) - { -- if ((s != NULL) && (*s != SYS_SEM_NULL)) -+ if ((s != NULL) && (*s != NULL)) - memp_free(MEMP_SYS_SEM, *s); - } - -@@ -369,20 +360,49 @@ void sys_arch_unprotect(sys_prot_t pval) - } - - /* -- * Hugepage memory manager -+ * Memory - * */ --uint8_t *sys_hugepage_malloc(const char *name, uint32_t size) -+u8_t *sys_hugepage_malloc(const char *name, unsigned size) - { - const struct rte_memzone *mz; -+ char memname[PATH_MAX]; - -- mz = rte_memzone_reserve(name, size, rte_socket_id(), 0); -+ sys_nameid(name, rte_gettid(), memname, sizeof(memname)); -+ mz = rte_memzone_reserve(memname, size, rte_socket_id(), 0); - if (mz == NULL) { - rte_exit(EXIT_FAILURE, "failed to reserver memory for mempool[%s]\n", name); - return NULL; - } - - memset(mz->addr, 0, mz->len); -- hugepage_stats.tot_len += mz->len; -- - return (uint8_t*)mz->addr; - } -+ -+void sys_mempool_var_init(struct memp_desc *memp, char *desc, u16_t size, u16_t num, -+ u8_t *base, struct memp **tab, struct stats_mem *stats) -+{ -+ LWIP_DEBUGF(SYS_DEBUG, ("[tid %u] %s: memp %p desc %s size %u num %u base %p\n", -+ rte_gettid(), __FUNCTION__, memp, desc, size, num, base)); -+ -+#if defined(LWIP_DEBUG) || MEMP_OVERFLOW_CHECK || LWIP_STATS_DISPLAY -+ memp->desc = desc; -+#endif /* LWIP_DEBUG || MEMP_OVERFLOW_CHECK || LWIP_STATS_DISPLAY */ -+#if MEMP_STATS -+ LWIP_ASSERT("stats != NULL", stats != NULL); -+ memp->stats = stats; -+#endif -+ -+ memp->size = size; -+ -+#if !MEMP_MEM_MALLOC -+ LWIP_ASSERT("base != NULL", base != NULL); -+ memp->num = num; -+ memp->base = base; -+ memp->tab = tab; -+#endif /* MEMP_MEM_MALLOC */ -+} -+ -+void sys_init(void) -+{ -+ sys_timer_init(); -+} -diff --git a/src/core/init.c b/src/core/init.c -index 7b6214f..a03b1d5 100644 ---- a/src/core/init.c -+++ b/src/core/init.c -@@ -343,7 +343,9 @@ lwip_init(void) - - /* Modules initialization */ - stats_init(); -- -+#if !NO_SYS -+ sys_init(); -+#endif /* !NO_SYS */ - mem_init(); - memp_init(); - pbuf_init(); -diff --git a/src/core/mem.c b/src/core/mem.c -index 84b3fcc..3701cae 100644 ---- a/src/core/mem.c -+++ b/src/core/mem.c -@@ -515,6 +515,11 @@ plug_holes(struct mem *mem) - void - mem_init(void) - { -+#if GAZELLE_ENABLE -+ /* see LWIP_RAM_HEAP_POINTER */ -+ LWIP_MEMORY_INIT_VAR(LWIP_RAM_HEAP_POINTER, MEM_SIZE_ALIGNED + (2U * SIZEOF_STRUCT_MEM)); -+#endif /* GAZELLE_ENABLE */ -+ - struct mem *mem; - - LWIP_ASSERT("Sanity check alignment", -diff --git a/src/core/memp.c b/src/core/memp.c -index fca1b0c..afcef93 100644 ---- a/src/core/memp.c -+++ b/src/core/memp.c -@@ -80,7 +80,7 @@ - - #if GAZELLE_ENABLE - PER_THREAD struct memp_desc* memp_pools[MEMP_MAX] = {NULL}; --#else -+#else /* GAZELLE_ENABLE */ - const struct memp_desc *const memp_pools[MEMP_MAX] = { - #define LWIP_MEMPOOL(name,num,size,desc) &memp_ ## name, - #include "lwip/priv/memp_std.h" -@@ -227,6 +227,11 @@ memp_init_pool(const struct memp_desc *desc) - void - memp_init(void) - { -+#if GAZELLE_ENABLE -+#define LWIP_MEMPOOL(name,num,size,desc) LWIP_MEMPOOL_INIT_VAR(name,num,size,desc) -+#include "lwip/priv/memp_std.h" -+#endif /* GAZELLE_ENABLE */ -+ - u16_t i; - - /* for every pool: */ -diff --git a/src/include/arch/cc.h b/src/include/arch/cc.h -index 0b454bb..3bfe6cd 100644 ---- a/src/include/arch/cc.h -+++ b/src/include/arch/cc.h -@@ -30,52 +30,36 @@ - * - */ - --#ifndef _LWIP_ARCH_CC_H_ --#define _LWIP_ARCH_CC_H_ -+#ifndef __LWIP_ARCH_CC_H__ -+#define __LWIP_ARCH_CC_H__ - --#include --#include --#include --#include -- --#include "lwiplog.h" -+#ifndef LWIP_RAND -+#define LWIP_RAND() ((uint32_t)rand()) -+#endif - - #define LWIP_NOASSERT -- - #define LWIP_ERRNO_STDINCLUDE 1 --#define MEMP_MEMORY_BASE_PLACEHOLDER 0 --#define MEMZONE_NAMESIZE 32 - --#define LWIP_RAND() ((uint32_t)rand()) -+#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) static PER_THREAD u8_t *variable_name; -+ -+#define LWIP_MEMORY_INIT_VAR(name, size) \ -+ name = sys_hugepage_malloc(#name, size); - --extern uint8_t *sys_hugepage_malloc(const char *name, uint32_t size); - --#define LWIP_DECLARE_MEMP_BASE_ALIGNED(name, __size)\ --PER_THREAD uint8_t *memp_memory_##name##_base; \ --void alloc_memp_##name##_base(void) \ --{ \ -- memp_ ## name.desc = memp_desc_ ## name; \ -- memp_ ## name.stats = &memp_stat ## name; \ -- memp_ ## name.size = memp_size ## name; \ -- memp_ ## name.num = memp_num ## name; \ -- memp_ ## name.tab = &memp_tab_ ## name; \ -- memp_pools[MEMP_##name] = &memp_ ## name; \ -- \ -- char mpname[MEMZONE_NAMESIZE] = {0}; \ -- snprintf(mpname, MEMZONE_NAMESIZE, "%d_%s", (int)syscall(SYS_gettid), #name); \ -- memp_memory_##name##_base = \ -- sys_hugepage_malloc(mpname, LWIP_MEM_ALIGN_BUFFER(__size)); \ -- memp_pools[MEMP_##name]->base = memp_memory_##name##_base; \ --} -+#define LWIP_MEMPOOL_DECLARE(name,num,size,desc) \ -+ LWIP_DECLARE_MEMORY_ALIGNED(memp_memory_ ## name ## _base, 0); \ -+ static PER_THREAD struct stats_mem memp_stat_ ## name; \ -+ static PER_THREAD struct memp *memp_tab_ ## name; \ -+ \ -+ PER_THREAD struct memp_desc memp_ ## name; - --#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) \ --PER_THREAD uint8_t *variable_name; \ --void alloc_memory_##variable_name(void) \ --{ \ -- char mpname[MEMZONE_NAMESIZE] = {0}; \ -- snprintf(mpname, MEMZONE_NAMESIZE, "%d_%s", (int)syscall(SYS_gettid), #variable_name); \ -- (variable_name) = \ -- sys_hugepage_malloc(mpname, LWIP_MEM_ALIGN_BUFFER(size)); \ --} -+#define LWIP_MEMPOOL_INIT_VAR(name,num,size,desc) \ -+ memp_memory_ ## name ## _base = sys_hugepage_malloc(#name, LWIP_MEM_ALIGN_BUFFER((num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size)))); \ -+ sys_mempool_var_init(&memp_ ## name, \ -+ desc, size, num, \ -+ memp_memory_ ## name ## _base, \ -+ &memp_tab_ ## name, \ -+ &memp_stat_ ## name); \ -+ memp_pools[MEMP_ ## name] = &memp_ ## name; - --#endif /* _LWIP_ARCH_CC_H_ */ -+#endif /* __LWIP_ARCH_CC_H__ */ -\ No newline at end of file -diff --git a/src/include/arch/sys_arch.h b/src/include/arch/sys_arch.h -index f2a0a49..7befc92 100644 ---- a/src/include/arch/sys_arch.h -+++ b/src/include/arch/sys_arch.h -@@ -33,55 +33,66 @@ - #ifndef _LWIP_ARCH_SYS_ARCH_H_ - #define _LWIP_ARCH_SYS_ARCH_H_ - --#include --#include -+#include "lwip/memp.h" - --#define SYS_MBOX_NULL NULL --#define SYS_SEM_NULL NULL --typedef uint32_t sys_prot_t; -+#define SYS_NAME_LEN 64 - --struct sys_sem { -- volatile unsigned int c; -- int (*wait_fn)(void); -+struct sys_thread { -+ struct sys_thread *next; -+ char name[SYS_NAME_LEN]; -+ void *arg; -+ int stacksize; -+ int prio; - }; -+typedef struct sys_thread *sys_thread_t; -+typedef void *(*thread_fn)(void *arg); -+void thread_create(const char *name, unsigned id, thread_fn func, void *arg); - --#define MBOX_NAME_LEN 64 --struct sys_mbox { -- struct rte_ring *ring; -- char name[MBOX_NAME_LEN]; -- int size; -- int socket_id; -- unsigned flags; -+ -+struct sys_sem { -+ volatile unsigned int c; - int (*wait_fn)(void); - }; -- - typedef struct sys_sem *sys_sem_t; - #define sys_sem_valid(sem) (((sem) != NULL) && (*(sem) != NULL)) --#define sys_sem_valid_val(sem) ((sem) != NULL) - #define sys_sem_set_invalid(sem) do { if ((sem) != NULL) { *(sem) = NULL; }} while(0) --#define sys_sem_set_invalid_val(sem) do { (sem) = NULL; } while(0) - -+ -+struct sys_mutex { -+ volatile unsigned int m; -+}; - struct sys_mutex; - typedef struct sys_mutex *sys_mutex_t; - #define sys_mutex_valid(mutex) sys_sem_valid(mutex) - #define sys_mutex_set_invalid(mutex) sys_sem_set_invalid(mutex) - -+ -+struct sys_mbox { -+ char name[SYS_NAME_LEN]; -+ int size; -+ int socket_id; -+ unsigned flags; -+ struct rte_ring *ring; -+ int (*wait_fn)(void); -+}; - typedef struct sys_mbox *sys_mbox_t; - #define sys_mbox_valid(mbox) sys_sem_valid(mbox) --#define sys_mbox_valid_val(mbox) sys_sem_valid_val(mbox) - #define sys_mbox_set_invalid(mbox) sys_sem_set_invalid(mbox) --#define sys_mbox_set_invalid_val(mbox) sys_sem_set_invalid_val(mbox) - int sys_mbox_empty(struct sys_mbox *); - --struct sys_thread; --typedef struct sys_thread *sys_thread_t; -+typedef uint32_t sys_prot_t; -+ -+ -+void sys_nameid(const char *name, unsigned id, char *nameid, unsigned size); -+u8_t *sys_hugepage_malloc(const char *name, unsigned size); -+void sys_mempool_var_init(struct memp_desc *memp, char *desc, u16_t size, u16_t num, -+ u8_t *base, struct memp **tab, struct stats_mem *stats); - --void sys_timer_init(void); - void sys_timer_run(void); - u32_t sys_now(void); - -+ - #if GAZELLE_ENABLE --extern int eth_dev_poll(void); - #include - - /* -diff --git a/src/include/lwip/memp.h b/src/include/lwip/memp.h -index 1763836..d660e9f 100644 ---- a/src/include/lwip/memp.h -+++ b/src/include/lwip/memp.h -@@ -60,9 +60,10 @@ typedef enum { - - #if GAZELLE_ENABLE - extern PER_THREAD struct memp_desc* memp_pools[MEMP_MAX]; --#else -+#include "arch/cc.h" -+#else /* GAZELLE_ENABLE */ -+ - extern const struct memp_desc* const memp_pools[MEMP_MAX]; --#endif /* GAZELLE_ENABLE */ - - /** - * @ingroup mempool -@@ -96,18 +97,6 @@ extern const struct memp_desc* const memp_pools[MEMP_MAX]; - * To relocate a pool, declare it as extern in cc.h. Example for GCC: - * extern u8_t \_\_attribute\_\_((section(".onchip_mem"))) memp_memory_my_private_pool_base[]; - */ --#if GAZELLE_ENABLE --#define LWIP_MEMPOOL_DECLARE(name,num,size,desc) \ -- PER_THREAD struct memp_desc memp_ ## name = {0}; \ -- PER_THREAD char memp_desc_ ## name[] = desc; \ -- PER_THREAD struct stats_mem memp_stat ## name = {0}; \ -- PER_THREAD u16_t memp_size ## name = size; \ -- PER_THREAD u16_t memp_num ## name = num; \ -- PER_THREAD struct memp *memp_tab_ ## name = NULL; \ -- LWIP_DECLARE_MEMP_BASE_ALIGNED(name, ((num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size)))); -- --#else /* GAZELLE_ENABLE */ -- - #define LWIP_MEMPOOL_DECLARE(name,num,size,desc) \ - LWIP_DECLARE_MEMORY_ALIGNED(memp_memory_ ## name ## _base, ((num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size)))); \ - \ -@@ -124,8 +113,8 @@ extern const struct memp_desc* const memp_pools[MEMP_MAX]; - &memp_tab_ ## name \ - }; - --#endif /* GAZELLE_ENABLE */ - #endif /* MEMP_MEM_MALLOC */ -+#endif /* GAZELLE_ENABLE */ - - /** - * @ingroup mempool -diff --git a/src/include/memp_def.h b/src/include/memp_def.h -deleted file mode 100644 -index 082f685..0000000 ---- a/src/include/memp_def.h -+++ /dev/null -@@ -1,66 +0,0 @@ --/* -- * Copyright (c) 2001-2004 Swedish Institute of Computer Science. -- * All rights reserved. -- * -- * Redistribution and use in source and binary forms, with or without modification, -- * are permitted provided that the following conditions are met: -- * -- * 1. Redistributions of source code must retain the above copyright notice, -- * this list of conditions and the following disclaimer. -- * 2. Redistributions in binary form must reproduce the above copyright notice, -- * this list of conditions and the following disclaimer in the documentation -- * and/or other materials provided with the distribution. -- * 3. The name of the author may not be used to endorse or promote products -- * derived from this software without specific prior written permission. -- * -- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED -- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT -- * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT -- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY -- * OF SUCH DAMAGE. -- * -- * This file is part of the lwIP TCP/IP stack. -- * -- * Author: Huawei Technologies -- * -- */ -- --#ifndef __MEMP_DEF_H__ --#define __MEMP_DEF_H__ -- --#include "lwip/opt.h" --#include "arch/cc.h" -- --#define LWIP_MEMPOOL_BASE_DECLARE(name) \ -- extern void alloc_memp_##name##_base(void); -- --#define LWIP_MEM_MEMORY_DECLARE(name) \ -- extern void alloc_memory_##name(void); -- --#define LWIP_MEMPOOL_BASE_INIT(name) \ -- alloc_memp_##name##_base(); -- --#define LWIP_MEM_MEMORY_INIT(name) \ -- alloc_memory_##name(); -- --#define LWIP_MEMPOOL(name, num, size, desc) LWIP_MEMPOOL_BASE_DECLARE(name) --#include --#undef LWIP_MEMPOOL -- --static inline void hugepage_init(void) --{ --#define LWIP_MEMPOOL(name,num,size,desc) LWIP_MEMPOOL_BASE_INIT(name) --#include "lwip/priv/memp_std.h" -- --#if !MEM_LIBC_MALLOC -- LWIP_MEM_MEMORY_DECLARE(ram_heap) -- LWIP_MEM_MEMORY_INIT(ram_heap) --#endif /* MEM_LIBC_MALLOC */ --} -- --#endif /* __MEMP_DEF_H__ */ --- -2.22.0.windows.1 - diff --git a/lwip.spec b/lwip.spec index 881194f..c788d4d 100644 --- a/lwip.spec +++ b/lwip.spec @@ -73,19 +73,7 @@ Patch9057: 0058-lwip-send-recv-thread-bind-numa.patch Patch9058: 0059-fix-last_unsent-last_unacked.patch Patch9059: 0060-lwip-add-udp-multicast.patch Patch9060: 0061-fix-pbuf-leak-in-udp-connection.patch -Patch9061: 0062-cleancode-improving-makefile-readability.patch -Patch9062: 0063-cleancode-remove-perf.patch -Patch9063: 0064-cleancode-rename-gazelle-files-in-lwip.patch -Patch9064: 0065-cleancode-refactor-lwipsock.h.patch -Patch9065: 0066-cleancode-refactor-gazelle_posix_api.h.patch -Patch9066: 0067-cleancode-refactor-gazelle_list.h.patch -Patch9067: 0068-cleancode-refactor-gazelle_hlist.h.patch -Patch9068: 0069-cleancode-refactor-options-define.patch -Patch9069: 0070-cleancode-refactor-GAZELLE_TCP_PCB_HASH.patch -Patch9070: 0071-cleancode-refactor-sys_now-and-lwip_ioctl.patch -Patch9071: 0072-cleancode-refactor-OFFLOAD_CHECKSUM-GAZELLE_TCP_DATA.patch -Patch9072: 0073-cleancode-refactor-memp.patch -Patch9073: 0074-drop-netbuf-in-recv_udp-to-fix-mem-overflow.patch +Patch9061: 0062-drop-netbuf-in-recv_udp-to-fix-mem-overflow.patch BuildRequires: gcc-c++ dos2unix dpdk-devel @@ -164,18 +152,6 @@ find %{_builddir}/%{name}-%{version} -type f -exec dos2unix -q {} \; %patch9059 -p1 %patch9060 -p1 %patch9061 -p1 -%patch9062 -p1 -%patch9063 -p1 -%patch9064 -p1 -%patch9065 -p1 -%patch9066 -p1 -%patch9067 -p1 -%patch9068 -p1 -%patch9069 -p1 -%patch9070 -p1 -%patch9071 -p1 -%patch9072 -p1 -%patch9073 -p1 %build cd %{_builddir}/%{name}-%{version}/src @@ -191,6 +167,9 @@ cd %{_builddir}/%{name}-%{version}/src %{_libdir}/liblwip.a %changelog +* Tue Jun 06 2023 jiangheng - 2.1.3-66 +- revert cleancode series patches + * Mon May 29 2023 kircher - 2.1.3-65 - drop netbuf in recv_udp to fix mem overflow