gazelle/0241-cleancode-improving-makefile-readability.patch
jiangheng12 50b48909f3 sync drop netbuf in read_lwip_data to fix mem overflow
(cherry picked from commit 1aabf9e9472126c472a28577057044b4649bbe11)
2023-05-29 21:59:17 +08:00

907 lines
33 KiB
Diff

From 8e97abb619efd77fa3499bb2ab224d000b1173c4 Mon Sep 17 00:00:00 2001
From: Lemmy Huang <huangliming5@huawei.com>
Date: Thu, 18 May 2023 11:36:42 +0800
Subject: [PATCH] cleancode: improving makefile readability
Signed-off-by: Lemmy Huang <huangliming5@huawei.com>
---
src/common/dir.mk | 13 ----
src/lstack/Makefile | 62 +++++++---------
src/lstack/Printlog.mk | 14 ++++
src/lstack/api/dir.mk | 14 ----
src/lstack/api/lstack_epoll.c | 4 +-
src/lstack/api/lstack_signal.c | 2 +-
src/lstack/api/lstack_wrap.c | 3 +-
src/lstack/core/dir.mk | 13 ----
src/lstack/core/lstack_cfg.c | 5 +-
src/lstack/core/lstack_control_plane.c | 4 +-
src/lstack/core/lstack_dpdk.c | 3 +-
src/lstack/core/lstack_init.c | 5 +-
src/lstack/core/lstack_lwip.c | 4 +-
src/lstack/core/lstack_protocol_stack.c | 6 +-
src/lstack/core/lstack_stack_stat.c | 4 +-
src/lstack/core/lstack_thread_rpc.c | 2 +-
src/lstack/include/lstack_cfg.h | 2 +-
src/lstack/include/lstack_dpdk.h | 4 +-
src/lstack/include/lstack_protocol_stack.h | 4 +-
src/lstack/include/posix/lstack_epoll.h | 4 +-
src/lstack/netif/dir.mk | 12 ---
src/lstack/netif/lstack_ethdev.c | 2 +-
src/lstack/netif/lstack_vdev.c | 4 +-
src/ltran/CMakeLists.txt | 86 ++++++++++++++--------
src/ltran/ltran_base.h | 2 +-
src/ltran/ltran_dfx.c | 2 +-
src/ltran/ltran_ethdev.c | 6 +-
src/ltran/ltran_ethdev.h | 2 +-
src/ltran/ltran_forward.c | 2 +-
src/ltran/ltran_instance.c | 6 +-
src/ltran/ltran_instance.h | 4 +-
src/ltran/ltran_monitor.c | 4 +-
src/ltran/ltran_param.c | 4 +-
src/ltran/ltran_param.h | 2 +-
src/ltran/ltran_stack.c | 2 +-
src/ltran/ltran_stat.c | 4 +-
src/ltran/ltran_stat.h | 2 +-
src/ltran/ltran_tcp_conn.h | 2 +-
src/ltran/ltran_tcp_sock.c | 2 +-
src/ltran/ltran_tcp_sock.h | 2 +-
src/ltran/main.c | 2 +-
41 files changed, 149 insertions(+), 177 deletions(-)
delete mode 100644 src/common/dir.mk
create mode 100644 src/lstack/Printlog.mk
delete mode 100644 src/lstack/api/dir.mk
delete mode 100644 src/lstack/core/dir.mk
delete mode 100644 src/lstack/netif/dir.mk
diff --git a/src/common/dir.mk b/src/common/dir.mk
deleted file mode 100644
index 68a2b72..0000000
--- a/src/common/dir.mk
+++ /dev/null
@@ -1,13 +0,0 @@
-# Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
-# gazelle is licensed under the Mulan PSL v2.
-# You can use this software according to the terms and conditions of the Mulan PSL v2.
-# You may obtain a copy of Mulan PSL v2 at:
-# http://license.coscl.org.cn/MulanPSL2
-# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
-# PURPOSE.
-# See the Mulan PSL v2 for more details.
-
-SRC = dpdk_common.c gazelle_parse_config.c
-$(eval $(call register_dir, ../common, $(SRC)))
-
diff --git a/src/lstack/Makefile b/src/lstack/Makefile
index ab039ec..86a9c1e 100644
--- a/src/lstack/Makefile
+++ b/src/lstack/Makefile
@@ -8,31 +8,21 @@
# PURPOSE.
# See the Mulan PSL v2 for more details.
-LSTACK_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
-ROOT_DIR := $(dir $(abspath $(LSTACK_DIR)))
+ROOT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
-LWIP_INCLUDE_FILE ?= /usr/include/lwip
LIB_PATH ?= /usr/lib64
+LWIP_INCLUDE_FILE ?= /usr/include/lwip
+
+include $(ROOT_DIR)/Printlog.mk
AR = ar
ARFLAGS = crDP
CC ?= gcc
-OPTIMIZATION = -O2 -g
RM = rm -f
+OPTIMIZATION = -O2 -g
LDFLAGS = -shared -ldl -lm -lpthread -lrt -lnuma -lconfig -lboundscheck
-
-ifneq ($(CC),clang)
- SEC_FLAGS = -fstack-protector-strong -Werror -Wall -Wl,-z,relro, -Wl,-z,now -Wl,-z,noexecstack -Wtrampolines -fPIC -D_FORTIFY_SOURCE=2
-else
- SEC_FLAGS = -fstack-protector-strong -Werror -Wall -fPIC
-endif
-$(info $(CC):$(SEC_FLAGS))
-
-INC = -I$(LSTACK_DIR)/include \
- -I$(LSTACK_DIR)/../common \
- -I$(LWIP_INCLUDE_FILE)
-
-CFLAGS = $(OPTIMIZATION) -fno-strict-aliasing $(INC)
+CFLAGS = $(OPTIMIZATION) -fno-strict-aliasing
+CFLAGS += -D__USE_GNU=1 -D_GNU_SOURCE=1
ifeq ($(GAZELLE_COVERAGE_ENABLE), 1)
LDFLAGS += -fprofile-arcs -ftest-coverage
@@ -43,17 +33,21 @@ ifeq ($(shell $(CC) -dumpmachine | cut -d"-" -f1), x86_64)
CFLAGS += -mssse3
endif
+ifneq ($(CC),clang)
+ SEC_FLAGS = -fstack-protector-strong -Werror -Wall -Wl,-z,relro, -Wl,-z,now -Wl,-z,noexecstack -Wtrampolines -fPIC -D_FORTIFY_SOURCE=2
+else
+ SEC_FLAGS = -fstack-protector-strong -Werror -Wall -fPIC
+endif
CFLAGS += $(SEC_FLAGS)
-SRCS =
-DIRS = core netif api ../common
-
-define register_dir
-SRCS += $(patsubst %, $(1)/%, $(2))
-endef
+INC = -I$(ROOT_DIR)/include \
+ -I$(ROOT_DIR)/../ \
+ -I$(LWIP_INCLUDE_FILE)
-include $(patsubst %, %/dir.mk, $(DIRS))
+$(info $(CC):$(CFLAGS))
+CFLAGS += $(INC)
+SRCS = $(wildcard ./api/*.c ./core/*.c ./netif/*.c ../common/*.c)
# Linking object and library
OBJS = $(subst .c,.o,$(SRCS))
@@ -96,19 +90,17 @@ LDFLAGS += -Wl,--whole-archive $(DEP_LIBS) $(OBJS) -Wl,--no-whole-archive
LSTACK_SHARED_LIB = liblstack.so
LSTACK_STATIC_LIB = liblstack.a
-.PHONY: all
+.PHONY: all clean
all: $(LSTACK_SHARED_LIB)
-depend: .depend
-
-.depend: $(SRCS)
- rm -f ./.depend
- $(foreach SRC,$(SRCS),$(CC) $(CFLAGS) -MM -MT $(SRC:.c=.o) $(SRC) >> .depend;)
-
--include .depend
-
$(LSTACK_SHARED_LIB): $(OBJS)
- $(CC) $(LDFLAGS) -Wl,--whole-archive -Wl,--no-whole-archive -o $@
+ $(call printlog, BUILD, $@)
+ $(QUIET) $(CC) $(LDFLAGS) -Wl,--whole-archive -Wl,--no-whole-archive -o $@
+
+%.o: %.c
+ $(call printlog, BUILD, $@)
+ $(QUIET) $(CC) $(CFLAGS) -c $(filter %.c,$^) -o $@
clean:
- $(RM) $(LSTACK_SHARED_LIB) $(OBJS) .depend
+ $(call printlog, CLEAN, $(LSTACK_SHARED_LIB))
+ $(QUIET) $(RM) $(LSTACK_SHARED_LIB) $(OBJS)
diff --git a/src/lstack/Printlog.mk b/src/lstack/Printlog.mk
new file mode 100644
index 0000000..7604851
--- /dev/null
+++ b/src/lstack/Printlog.mk
@@ -0,0 +1,14 @@
+
+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/lstack/api/dir.mk b/src/lstack/api/dir.mk
deleted file mode 100644
index f5370a2..0000000
--- a/src/lstack/api/dir.mk
+++ /dev/null
@@ -1,14 +0,0 @@
-# Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
-# gazelle is licensed under the Mulan PSL v2.
-# You can use this software according to the terms and conditions of the Mulan PSL v2.
-# You may obtain a copy of Mulan PSL v2 at:
-# http://license.coscl.org.cn/MulanPSL2
-# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
-# PURPOSE.
-# See the Mulan PSL v2 for more details.
-
-SRC = lstack_epoll.c lstack_signal.c lstack_fork.c lstack_wrap.c
-
-$(eval $(call register_dir, api, $(SRC)))
-
diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c
index 06bd71b..888552c 100644
--- a/src/lstack/api/lstack_epoll.c
+++ b/src/lstack/api/lstack_epoll.c
@@ -30,8 +30,8 @@
#include "lstack_stack_stat.h"
#include "lstack_cfg.h"
#include "lstack_log.h"
-#include "dpdk_common.h"
-#include "gazelle_base_func.h"
+#include "common/dpdk_common.h"
+#include "common/gazelle_base_func.h"
#include "lstack_lwip.h"
#include "lstack_protocol_stack.h"
#include "posix/lstack_epoll.h"
diff --git a/src/lstack/api/lstack_signal.c b/src/lstack/api/lstack_signal.c
index 03118f5..0c0ed1f 100644
--- a/src/lstack/api/lstack_signal.c
+++ b/src/lstack/api/lstack_signal.c
@@ -19,7 +19,7 @@
#include <lwip/posix_api.h>
#include "lstack_cfg.h"
-#include "dpdk_common.h"
+#include "common/dpdk_common.h"
#include "lstack_log.h"
#include "lstack_control_plane.h"
diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c
index 505e33d..b3afa73 100644
--- a/src/lstack/api/lstack_wrap.c
+++ b/src/lstack/api/lstack_wrap.c
@@ -10,7 +10,6 @@
* See the Mulan PSL v2 for more details.
*/
-#define _GNU_SOURCE
#include <dlfcn.h>
#include <string.h>
@@ -37,7 +36,7 @@
#include "lstack_cfg.h"
#include "lstack_lwip.h"
#include "lstack_protocol_stack.h"
-#include "gazelle_base_func.h"
+#include "common/gazelle_base_func.h"
#include "lstack_thread_rpc.h"
#ifndef SOCK_TYPE_MASK
diff --git a/src/lstack/core/dir.mk b/src/lstack/core/dir.mk
deleted file mode 100644
index 88c1e08..0000000
--- a/src/lstack/core/dir.mk
+++ /dev/null
@@ -1,13 +0,0 @@
-# Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
-# gazelle is licensed under the Mulan PSL v2.
-# You can use this software according to the terms and conditions of the Mulan PSL v2.
-# You may obtain a copy of Mulan PSL v2 at:
-# http://license.coscl.org.cn/MulanPSL2
-# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
-# PURPOSE.
-# See the Mulan PSL v2 for more details.
-
-SRC = lstack_init.c lstack_cfg.c lstack_dpdk.c lstack_control_plane.c lstack_stack_stat.c lstack_lwip.c lstack_protocol_stack.c lstack_thread_rpc.c
-$(eval $(call register_dir, core, $(SRC)))
-
diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c
index a21992e..66399db 100644
--- a/src/lstack/core/lstack_cfg.c
+++ b/src/lstack/core/lstack_cfg.c
@@ -10,7 +10,6 @@
* See the Mulan PSL v2 for more details.
*/
-#define _GNU_SOURCE
#include <stdlib.h>
#include <getopt.h>
#include <stdio.h>
@@ -28,9 +27,9 @@
#include <lwip/posix_api.h>
#include <lwip/inet.h>
-#include "gazelle_reg_msg.h"
+#include "common/gazelle_reg_msg.h"
#include "lstack_log.h"
-#include "gazelle_base_func.h"
+#include "common/gazelle_base_func.h"
#include "lstack_protocol_stack.h"
#include "lstack_cfg.h"
diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c
index be156dc..3dfe622 100644
--- a/src/lstack/core/lstack_control_plane.c
+++ b/src/lstack/core/lstack_control_plane.c
@@ -26,8 +26,8 @@
#include "lstack_cfg.h"
#include "lstack_dpdk.h"
-#include "gazelle_reg_msg.h"
-#include "gazelle_base_func.h"
+#include "common/gazelle_reg_msg.h"
+#include "common/gazelle_base_func.h"
#include "lstack_stack_stat.h"
#include "lstack_log.h"
#include "lstack_thread_rpc.h"
diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c
index b321c18..fa33ff8 100644
--- a/src/lstack/core/lstack_dpdk.c
+++ b/src/lstack/core/lstack_dpdk.c
@@ -10,7 +10,6 @@
* See the Mulan PSL v2 for more details.
*/
-#define _GNU_SOURCE
#include <sched.h>
#include <stdbool.h>
#include <securec.h>
@@ -40,7 +39,7 @@
#include <rte_ethdev.h>
#include "lstack_log.h"
-#include "dpdk_common.h"
+#include "common/dpdk_common.h"
#include "lstack_lockless_queue.h"
#include "lstack_protocol_stack.h"
#include "lstack_thread_rpc.h"
diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c
index 4fbbc14..7d4edd4 100644
--- a/src/lstack/core/lstack_init.c
+++ b/src/lstack/core/lstack_init.c
@@ -10,7 +10,6 @@
* See the Mulan PSL v2 for more details.
*/
-#define _GNU_SOURCE
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
@@ -41,10 +40,10 @@
#include "lstack_dpdk.h"
#include "lstack_stack_stat.h"
#include "lstack_log.h"
-#include "dpdk_common.h"
+#include "common/dpdk_common.h"
#include "posix/lstack_epoll.h"
#include "posix/lstack_unistd.h"
-#include "gazelle_base_func.h"
+#include "common/gazelle_base_func.h"
#include "lstack_protocol_stack.h"
#define LSTACK_PRELOAD_ENV_SYS "LD_PRELOAD"
diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c
index 12c2aa6..09c5261 100644
--- a/src/lstack/core/lstack_lwip.c
+++ b/src/lstack/core/lstack_lwip.c
@@ -26,7 +26,7 @@
#include <rte_errno.h>
#include <rte_malloc.h>
-#include "gazelle_base_func.h"
+#include "common/gazelle_base_func.h"
#include "lstack_ethdev.h"
#include "lstack_protocol_stack.h"
#include "lstack_log.h"
@@ -34,7 +34,7 @@
#include "lstack_stack_stat.h"
#include "posix/lstack_epoll.h"
#include "lstack_thread_rpc.h"
-#include "dpdk_common.h"
+#include "common/dpdk_common.h"
#include "lstack_cfg.h"
#include "lstack_lwip.h"
diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c
index d5523df..2f71f97 100644
--- a/src/lstack/core/lstack_protocol_stack.c
+++ b/src/lstack/core/lstack_protocol_stack.c
@@ -9,7 +9,7 @@
* PURPOSE.
* See the Mulan PSL v2 for more details.
*/
-#define _GNU_SOURCE
+
#include <pthread.h>
#include <stdatomic.h>
@@ -24,9 +24,9 @@
#include <securec.h>
#include <numa.h>
-#include "gazelle_base_func.h"
+#include "common/gazelle_base_func.h"
#include "lstack_thread_rpc.h"
-#include "dpdk_common.h"
+#include "common/dpdk_common.h"
#include "lstack_log.h"
#include "lstack_dpdk.h"
#include "lstack_ethdev.h"
diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c
index 60832b4..8c4f298 100644
--- a/src/lstack/core/lstack_stack_stat.c
+++ b/src/lstack/core/lstack_stack_stat.c
@@ -21,8 +21,8 @@
#include "posix_api.h"
#include "lstack_control_plane.h"
#include "lstack_log.h"
-#include "dpdk_common.h"
-#include "gazelle_dfx_msg.h"
+#include "common/dpdk_common.h"
+#include "common/gazelle_dfx_msg.h"
#include "lstack_thread_rpc.h"
#include "lstack_protocol_stack.h"
#include "posix/lstack_epoll.h"
diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c
index fe3b757..a4b2a51 100644
--- a/src/lstack/core/lstack_thread_rpc.c
+++ b/src/lstack/core/lstack_thread_rpc.c
@@ -19,7 +19,7 @@
#include "lstack_lwip.h"
#include "lstack_protocol_stack.h"
#include "lstack_control_plane.h"
-#include "gazelle_base_func.h"
+#include "common/gazelle_base_func.h"
#include "lstack_dpdk.h"
#include "lstack_thread_rpc.h"
diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h
index 4d0f611..684ff5e 100644
--- a/src/lstack/include/lstack_cfg.h
+++ b/src/lstack/include/lstack_cfg.h
@@ -17,7 +17,7 @@
#include <lwip/ip_addr.h>
#include "lstack_protocol_stack.h"
-#include "gazelle_opt.h"
+#include "common/gazelle_opt.h"
#define BASE_BIN_SCALE 2
#define BASE_OCT_SCALE 8
diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h
index a189557..610feec 100644
--- a/src/lstack/include/lstack_dpdk.h
+++ b/src/lstack/include/lstack_dpdk.h
@@ -13,8 +13,8 @@
#ifndef _GAZELLE_DPDK_H_
#define _GAZELLE_DPDK_H_
-#include "gazelle_opt.h"
-#include "gazelle_dfx_msg.h"
+#include "common/gazelle_opt.h"
+#include "common/gazelle_dfx_msg.h"
#define RXTX_CACHE_SZ (VDEV_RX_QUEUE_SZ)
#define KNI_NB_MBUF (DEFAULT_RING_SIZE << 4)
diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h
index 3a447dc..5e2b8e6 100644
--- a/src/lstack/include/lstack_protocol_stack.h
+++ b/src/lstack/include/lstack_protocol_stack.h
@@ -20,10 +20,10 @@
#include <lwip/list.h>
#include <lwip/netif.h>
-#include "gazelle_dfx_msg.h"
+#include "common/gazelle_dfx_msg.h"
#include "lstack_lockless_queue.h"
#include "lstack_ethdev.h"
-#include "gazelle_opt.h"
+#include "common/gazelle_opt.h"
#define SOCK_RECV_RING_SIZE (128)
#define SOCK_RECV_FREE_THRES (32)
diff --git a/src/lstack/include/posix/lstack_epoll.h b/src/lstack/include/posix/lstack_epoll.h
index d6c81a7..08cd092 100644
--- a/src/lstack/include/posix/lstack_epoll.h
+++ b/src/lstack/include/posix/lstack_epoll.h
@@ -20,8 +20,8 @@
#include <lwip/list.h>
-#include "gazelle_dfx_msg.h"
-#include "gazelle_opt.h"
+#include "common/gazelle_dfx_msg.h"
+#include "common/gazelle_opt.h"
#ifdef __cplusplus
extern "C" {
diff --git a/src/lstack/netif/dir.mk b/src/lstack/netif/dir.mk
deleted file mode 100644
index ec7c4ad..0000000
--- a/src/lstack/netif/dir.mk
+++ /dev/null
@@ -1,12 +0,0 @@
-# Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
-# gazelle is licensed under the Mulan PSL v2.
-# You can use this software according to the terms and conditions of the Mulan PSL v2.
-# You may obtain a copy of Mulan PSL v2 at:
-# http://license.coscl.org.cn/MulanPSL2
-# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
-# PURPOSE.
-# See the Mulan PSL v2 for more details.
-
-SRC = lstack_ethdev.c lstack_vdev.c
-$(eval $(call register_dir, netif, $(SRC)))
diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c
index e4e7ebd..3d609eb 100644
--- a/src/lstack/netif/lstack_ethdev.c
+++ b/src/lstack/netif/lstack_ethdev.c
@@ -34,7 +34,7 @@
#include "lstack_log.h"
#include "lstack_dpdk.h"
#include "lstack_lwip.h"
-#include "dpdk_common.h"
+#include "common/dpdk_common.h"
#include "lstack_protocol_stack.h"
#include "lstack_thread_rpc.h"
#include "lstack_ethdev.h"
diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c
index 5ea1f31..87df325 100644
--- a/src/lstack/netif/lstack_vdev.c
+++ b/src/lstack/netif/lstack_vdev.c
@@ -26,9 +26,9 @@
#include "lstack_ethdev.h"
#include "lstack_control_plane.h"
#include "lstack_log.h"
-#include "dpdk_common.h"
+#include "common/dpdk_common.h"
#include "lstack_protocol_stack.h"
-#include "gazelle_reg_msg.h"
+#include "common/gazelle_reg_msg.h"
#include "lstack_lwip.h"
#include "lstack_vdev.h"
diff --git a/src/ltran/CMakeLists.txt b/src/ltran/CMakeLists.txt
index f37a232..f74c403 100644
--- a/src/ltran/CMakeLists.txt
+++ b/src/ltran/CMakeLists.txt
@@ -14,7 +14,6 @@ project(ltran)
set(COMMON_DIR ${PROJECT_SOURCE_DIR}/../common)
set(LWIP_DIR /usr/include/lwip)
-set(CMAKE_VERBOSE_MAKEFILE ON)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
set(CMAKE_C_FLAGS "-g -fstack-protector-strong -Wall -Werror -fPIE -pie -pthread -D_FORTIFY_SOURCE=2 -O2 -fPIC")
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
@@ -27,40 +26,63 @@ if($ENV{GAZELLE_COVERAGE_ENABLE})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage -fprofile-arcs")
endif($ENV{GAZELLE_COVERAGE_ENABLE})
-add_executable(ltran main.c ltran_param.c ltran_config.c ltran_ethdev.c ltran_stat.c ltran_errno.c
- ltran_monitor.c ltran_instance.c ltran_stack.c ltran_tcp_conn.c ltran_tcp_sock.c
- ltran_forward.c ltran_timer.c ${COMMON_DIR}/gazelle_dfx_msg.c ${COMMON_DIR}/dpdk_common.c
- ${COMMON_DIR}/gazelle_parse_config.c)
+set(LTRAN_C_FLAGS -march=native -fno-strict-aliasing -D__ARM_FEATURE_CRC32=1
+ -D_GNU_SOURCE -W -Wall -Wstrict-prototypes -Wmissing-declarations -Wmissing-prototypes
+ -Wold-style-definition -Wpointer-arith -Wcast-align -Wcast-qual -Wnested-externs
+ -Wformat-nonliteral -Wformat-security -Wundef -Wdeprecated -Wwrite-strings -Wno-implicit-fallthrough
+ -D_FORTIFY_SOURCE=2)
-target_include_directories(ltran PRIVATE ${COMMON_DIR} ${PROJECT_SOURCE_DIR} ${LWIP_DIR})
-target_compile_options(ltran PRIVATE -march=native -fno-strict-aliasing -D__ARM_FEATURE_CRC32=1 -DRTE_MACHINE_CPUFLAG_NEON
- -DRTE_MACHINE_CPUFLAG_CRC32 -DRTE_MACHINE_CPUFLAG_PMULL -DRTE_MACHINE_CPUFLAG_AES
- -DRTE_MACHINE_CPUFLAG_SHA1 -DRTE_MACHINE_CPUFLAG_SHA2 -include rte_config.h
- -D_GNU_SOURCE -W -Wall -Wstrict-prototypes -Wmissing-declarations -Wmissing-prototypes -Wold-style-definition
- -Wpointer-arith -Wcast-align -Wcast-qual -Wnested-externs -Wformat-nonliteral -Wformat-security -Wundef
- -Wdeprecated -Wwrite-strings -Wno-implicit-fallthrough -D_FORTIFY_SOURCE=2)
+set(LTRAN_DPDK_FLAGS -DRTE_MACHINE_CPUFLAG_NEON -DRTE_MACHINE_CPUFLAG_CRC32 -DRTE_MACHINE_CPUFLAG_PMULL
+ -DRTE_MACHINE_CPUFLAG_AES -DRTE_MACHINE_CPUFLAG_SHA1 -DRTE_MACHINE_CPUFLAG_SHA2
+ -include rte_config.h)
+
+set(LTRAN_LD_FLAGS "-L$ENV{DPDK_LIB_PATH} \
+ -Wl,--whole-archive -Wl,-lrte_pipeline -Wl,--no-whole-archive -Wl,-lrte_table \
+ -Wl,--whole-archive -Wl,--no-whole-archive -Wl,--whole-archive -Wl,-lrte_port \
+ -Wl,--no-whole-archive -Wl,-lrte_distributor -Wl,-lrte_meter -Wl,-lrte_ip_frag -Wl,-lrte_lpm \
+ -Wl,--whole-archive -Wl,-lrte_acl \
+ -Wl,--no-whole-archive -Wl,-lrte_jobstats -Wl,-lrte_bitratestats -Wl,-lrte_metrics \
+ -Wl,-lrte_latencystats -Wl,-lrte_power -Wl,-lrte_efd -Wl,-lrte_bpf \
+ -Wl,--whole-archive -Wl,-lrte_gro -Wl,-lrte_cfgfile -Wl,-lrte_gso -Wl,-lrte_hash -Wl,-lrte_member \
+ -Wl,-lrte_vhost -Wl,-lrte_kvargs -Wl,-lrte_mbuf -Wl,-lrte_ethdev -Wl,-lrte_net -Wl,-lrte_bbdev \
+ -Wl,-lrte_cryptodev -Wl,-lrte_security -Wl,-lrte_compressdev -Wl,-lrte_eventdev -Wl,-lrte_rawdev \
+ -Wl,-lrte_timer -Wl,-lrte_mempool -Wl,-lrte_mempool_ring -Wl,-lrte_ring -Wl,-lrte_pci \
+ -Wl,-Bstatic -lrte_eal -Wl,-Bdynamic -Wl,-lrte_cmdline -Wl,-lrte_sched -Wl,-lrte_reorder \
+ -Wl,-lrte_kni -Wl,-lrte_common_cpt -Wl,-lrte_common_octeontx -Wl,-lrte_common_dpaax \
+ -Wl,-lrte_bus_pci -Wl,-lrte_bus_dpaa -Wl,-lrte_bus_vdev -Wl,-lrte_bus_fslmc \
+ -Wl,-lrte_mempool_bucket -Wl,-lrte_mempool_stack -Wl,-lrte_mempool_dpaa -Wl,-lrte_mempool_dpaa2 \
+ -Wl,-lrte_net_af_packet -Wl,-lrte_net_ark -Wl,-lrte_net_atlantic -Wl,-lrte_net_axgbe \
+ -Wl,-lrte_net_bnxt -Wl,-lrte_net_bond -Wl,-lrte_net_cxgbe -Wl,-lrte_net_dpaa -Wl,-lrte_net_dpaa2 \
+ -Wl,-lrte_net_e1000 -Wl,-lrte_net_ena -Wl,-lrte_net_enetc -Wl,-lrte_net_enic \
+ -Wl,-lrte_net_failsafe -Wl,-lrte_net_i40e -Wl,-lrte_net_hinic -Wl,-lrte_net_ixgbe \
+ -Wl,-lrte_net_kni -Wl,-lrte_net_nfp -Wl,-lrte_net_null -Wl,-lpcap -Wl,-lrte_net_qede \
+ -Wl,-lrte_net_ring -Wl,-lrte_net_softnic -Wl,-lrte_net_pcap -Wl,-lrte_net_tap \
+ -Wl,-lrte_net_vdev_netvsc -Wl,-lrte_net_virtio -Wl,-lrte_net_vhost -Wl,-lrte_bus_vmbus \
+ -Wl,-lrte_net_netvsc -Wl,-lrte_mempool_octeontx -Wl,-lrte_net_octeontx -Wl,-lrte_bus_ifpga \
+ -Wl,-lrte_stack -Wl,-lrte_telemetry \
+ -Wl,--no-whole-archive -Wl,-lm -Wl,-lrt -Wl,-lnuma -Wl,-ldl \
+ -Wl,-export-dynamic -Wl,-export-dynamic -Wl,--as-needed -Wl,-export-dynamic \
+ -Wl,-Map=ltran.map -Wl,--cref")
+
+# compile info
+#set(CMAKE_VERBOSE_MAKEFILE ON)
+message("[CMAKE_C_FLAGS] ${CMAKE_C_FLAGS}")
+message("[LTRAN_C_FLAGS] ${LTRAN_C_FLAGS}")
+message("[LTRAN_DPDK_FLAGS] ${LTRAN_DPDK_FLAGS}")
+message("[LTRAN_LD_FLAGS] ${LTRAN_LD_FLAGS}")
+
+add_executable(ltran main.c ltran_param.c ltran_config.c ltran_ethdev.c ltran_stat.c ltran_errno.c ltran_monitor.c
+ ltran_instance.c ltran_stack.c ltran_tcp_conn.c ltran_tcp_sock.c ltran_forward.c ltran_timer.c
+ ${COMMON_DIR}/gazelle_dfx_msg.c
+ ${COMMON_DIR}/dpdk_common.c
+ ${COMMON_DIR}/gazelle_parse_config.c)
+
+target_include_directories(ltran PRIVATE ${COMMON_DIR}/../ ${PROJECT_SOURCE_DIR} ${LWIP_DIR})
+target_compile_options(ltran PRIVATE ${LTRAN_C_FLAGS} ${LTRAN_DPDK_FLAGS})
target_link_libraries(ltran PRIVATE config boundscheck rte_pdump -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wtrampolines)
-set_target_properties(ltran PROPERTIES LINK_FLAGS "-L$ENV{DPDK_LIB_PATH} -Wl,--whole-archive -Wl,-lrte_pipeline \
- -Wl,--no-whole-archive -Wl,-lrte_table -Wl,--whole-archive -Wl,--no-whole-archive -Wl,--whole-archive -Wl,-lrte_port -Wl,--no-whole-archive \
- -Wl,-lrte_distributor -Wl,-lrte_meter -Wl,-lrte_ip_frag -Wl,-lrte_lpm -Wl,--whole-archive -Wl,-lrte_acl -Wl,--no-whole-archive \
- -Wl,-lrte_jobstats -Wl,-lrte_bitratestats -Wl,-lrte_metrics -Wl,-lrte_latencystats -Wl,-lrte_power -Wl,-lrte_efd -Wl,-lrte_bpf \
- -Wl,--whole-archive -Wl,-lrte_gro -Wl,-lrte_cfgfile -Wl,-lrte_gso -Wl,-lrte_hash -Wl,-lrte_member -Wl,-lrte_vhost -Wl,-lrte_kvargs \
- -Wl,-lrte_mbuf -Wl,-lrte_ethdev -Wl,-lrte_net -Wl,-lrte_bbdev -Wl,-lrte_cryptodev -Wl,-lrte_security -Wl,-lrte_compressdev -Wl,-lrte_eventdev \
- -Wl,-lrte_rawdev -Wl,-lrte_timer -Wl,-lrte_mempool -Wl,-lrte_mempool_ring -Wl,-lrte_ring -Wl,-lrte_pci \
- -Wl,-Bstatic -lrte_eal -Wl,-Bdynamic -Wl,-lrte_cmdline \
- -Wl,-lrte_sched -Wl,-lrte_reorder -Wl,-lrte_kni -Wl,-lrte_common_cpt -Wl,-lrte_common_octeontx -Wl,-lrte_common_dpaax -Wl,-lrte_bus_pci \
- -Wl,-lrte_bus_dpaa -Wl,-lrte_bus_vdev -Wl,-lrte_bus_fslmc -Wl,-lrte_mempool_bucket -Wl,-lrte_mempool_stack -Wl,-lrte_mempool_dpaa \
- -Wl,-lrte_mempool_dpaa2 -Wl,-lrte_net_af_packet -Wl,-lrte_net_ark -Wl,-lrte_net_atlantic -Wl,-lrte_net_axgbe \
- -Wl,-lrte_net_bnxt -Wl,-lrte_net_bond -Wl,-lrte_net_cxgbe -Wl,-lrte_net_dpaa -Wl,-lrte_net_dpaa2 -Wl,-lrte_net_e1000 -Wl,-lrte_net_ena \
- -Wl,-lrte_net_enetc -Wl,-lrte_net_enic -Wl,-lrte_net_failsafe -Wl,-lrte_net_i40e -Wl,-lrte_net_hinic -Wl,-lrte_net_ixgbe -Wl,-lrte_net_kni \
- -Wl,-lrte_net_nfp -Wl,-lrte_net_null -Wl,-lpcap -Wl,-lrte_net_qede -Wl,-lrte_net_ring -Wl,-lrte_net_softnic -Wl,-lrte_net_pcap \
- -Wl,-lrte_net_tap -Wl,-lrte_net_vdev_netvsc -Wl,-lrte_net_virtio -Wl,-lrte_net_vhost \
- -Wl,-lrte_bus_vmbus -Wl,-lrte_net_netvsc -Wl,-lrte_mempool_octeontx -Wl,-lrte_net_octeontx \
- -Wl,-lrte_bus_ifpga -Wl,-lrte_stack -Wl,-lrte_telemetry\
- -Wl,--no-whole-archive -Wl,-lm -Wl,-lrt -Wl,-lnuma -Wl,-ldl -Wl,-export-dynamic -Wl,-export-dynamic \
- -Wl,--as-needed -Wl,-export-dynamic -Wl,-Map=ltran.map -Wl,--cref")
+set_target_properties(ltran PROPERTIES LINK_FLAGS ${LTRAN_LD_FLAGS})
add_executable(gazellectl ltran_dfx.c ${COMMON_DIR}/gazelle_dfx_msg.c)
-target_include_directories(gazellectl PRIVATE $ENV{DPDK_INCLUDE_FILE} ${COMMON_DIR})
+target_include_directories(gazellectl PRIVATE $ENV{DPDK_INCLUDE_FILE} ${COMMON_DIR}/../ ${LWIP_DIR})
target_link_libraries(gazellectl PRIVATE boundscheck -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack)
diff --git a/src/ltran/ltran_base.h b/src/ltran/ltran_base.h
index 6be9152..6e1a4e4 100644
--- a/src/ltran/ltran_base.h
+++ b/src/ltran/ltran_base.h
@@ -15,7 +15,7 @@
#include <limits.h>
-#include "gazelle_opt.h"
+#include "common/gazelle_opt.h"
#define GAZELLE_CMD_BUFFER_SIZE _POSIX_ARG_MAX
#define GAZELLE_PATH_BUFFER_SIZE PATH_MAX
diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c
index e41c6db..c415211 100644
--- a/src/ltran/ltran_dfx.c
+++ b/src/ltran/ltran_dfx.c
@@ -27,7 +27,7 @@
#include "ltran_stat.h"
#include "ltran_base.h"
-#include "gazelle_dfx_msg.h"
+#include "common/gazelle_dfx_msg.h"
/* seeing show_usage() */
#define GAZELLE_TARGET_ARG_IDX 1
diff --git a/src/ltran/ltran_ethdev.c b/src/ltran/ltran_ethdev.c
index e2eb4a8..f723f29 100644
--- a/src/ltran/ltran_ethdev.c
+++ b/src/ltran/ltran_ethdev.c
@@ -25,13 +25,13 @@
#include <syslog.h>
#include <securec.h>
-#include "dpdk_common.h"
+#include "common/dpdk_common.h"
#include "ltran_param.h"
#include "ltran_log.h"
#include "ltran_base.h"
-#include "gazelle_opt.h"
+#include "common/gazelle_opt.h"
#include "ltran_errno.h"
-#include "gazelle_reg_msg.h"
+#include "common/gazelle_reg_msg.h"
uint32_t g_bond_num = 0;
FILE* g_log_file = NULL;
diff --git a/src/ltran/ltran_ethdev.h b/src/ltran/ltran_ethdev.h
index f720c55..b84baae 100644
--- a/src/ltran/ltran_ethdev.h
+++ b/src/ltran/ltran_ethdev.h
@@ -15,7 +15,7 @@
#include <stdint.h>
-#include "gazelle_opt.h"
+#include "common/gazelle_opt.h"
struct port_info {
uint16_t num_ports;
diff --git a/src/ltran/ltran_forward.c b/src/ltran/ltran_forward.c
index b41e1e2..55105f6 100644
--- a/src/ltran/ltran_forward.c
+++ b/src/ltran/ltran_forward.c
@@ -23,7 +23,7 @@
#include <rte_ring.h>
#include <securec.h>
-#include "dpdk_common.h"
+#include "common/dpdk_common.h"
#include "ltran_instance.h"
#include "ltran_tcp_conn.h"
#include "ltran_tcp_sock.h"
diff --git a/src/ltran/ltran_instance.c b/src/ltran/ltran_instance.c
index fc5b0fb..428c1aa 100644
--- a/src/ltran/ltran_instance.c
+++ b/src/ltran/ltran_instance.c
@@ -25,10 +25,10 @@
#include "ltran_stat.h"
#include "ltran_log.h"
#include "ltran_base.h"
-#include "gazelle_opt.h"
+#include "common/gazelle_opt.h"
#include "ltran_errno.h"
-#include "gazelle_dfx_msg.h"
-#include "gazelle_base_func.h"
+#include "common/gazelle_dfx_msg.h"
+#include "common/gazelle_base_func.h"
#include "ltran_instance.h"
volatile unsigned long g_tx_loop_count __rte_cache_aligned;
diff --git a/src/ltran/ltran_instance.h b/src/ltran/ltran_instance.h
index 2b888ec..f0fe580 100644
--- a/src/ltran/ltran_instance.h
+++ b/src/ltran/ltran_instance.h
@@ -17,8 +17,8 @@
#include <netinet/in.h>
#include <limits.h>
-#include "gazelle_opt.h"
-#include "gazelle_reg_msg.h"
+#include "common/gazelle_opt.h"
+#include "common/gazelle_reg_msg.h"
struct gazelle_stack;
struct gazelle_instance {
diff --git a/src/ltran/ltran_monitor.c b/src/ltran/ltran_monitor.c
index d163a47..5112ec3 100644
--- a/src/ltran/ltran_monitor.c
+++ b/src/ltran/ltran_monitor.c
@@ -29,8 +29,8 @@
#include "ltran_log.h"
#include "ltran_stat.h"
#include "ltran_instance.h"
-#include "gazelle_dfx_msg.h"
-#include "gazelle_base_func.h"
+#include "common/gazelle_dfx_msg.h"
+#include "common/gazelle_base_func.h"
#include "ltran_param.h"
#include "ltran_monitor.h"
diff --git a/src/ltran/ltran_param.c b/src/ltran/ltran_param.c
index e16e648..9235caa 100644
--- a/src/ltran/ltran_param.c
+++ b/src/ltran/ltran_param.c
@@ -23,8 +23,8 @@
#include "ltran_errno.h"
#include "ltran_base.h"
#include "ltran_log.h"
-#include "gazelle_dfx_msg.h"
-#include "gazelle_base_func.h"
+#include "common/gazelle_dfx_msg.h"
+#include "common/gazelle_base_func.h"
#include "ltran_param.h"
#define HEX_BASE 16
diff --git a/src/ltran/ltran_param.h b/src/ltran/ltran_param.h
index 40a92b1..71b2b57 100644
--- a/src/ltran/ltran_param.h
+++ b/src/ltran/ltran_param.h
@@ -16,7 +16,7 @@
#include <netinet/in.h>
#include <rte_ether.h>
-#include "gazelle_opt.h"
+#include "common/gazelle_opt.h"
struct ltran_config {
struct {
diff --git a/src/ltran/ltran_stack.c b/src/ltran/ltran_stack.c
index d4e935e..d2ec9f5 100644
--- a/src/ltran/ltran_stack.c
+++ b/src/ltran/ltran_stack.c
@@ -15,7 +15,7 @@
#include "ltran_instance.h"
#include "ltran_log.h"
#include "ltran_jhash.h"
-#include "gazelle_base_func.h"
+#include "common/gazelle_base_func.h"
#include "ltran_stack.h"
struct gazelle_stack_htable *g_stack_htable = NULL;
diff --git a/src/ltran/ltran_stat.c b/src/ltran/ltran_stat.c
index c17a5c1..25dda50 100644
--- a/src/ltran/ltran_stat.c
+++ b/src/ltran/ltran_stat.c
@@ -21,12 +21,12 @@
#include "ltran_tcp_conn.h"
#include "ltran_instance.h"
#include "ltran_log.h"
-#include "gazelle_dfx_msg.h"
+#include "common/gazelle_dfx_msg.h"
#include "ltran_timer.h"
#include "ltran_ethdev.h"
#include "ltran_base.h"
#include "ltran_stack.h"
-#include "dpdk_common.h"
+#include "common/dpdk_common.h"
#include "ltran_forward.h"
/* undefine lwip_ntohs in lwip/def.h */
diff --git a/src/ltran/ltran_stat.h b/src/ltran/ltran_stat.h
index 16d03a1..75cb353 100644
--- a/src/ltran/ltran_stat.h
+++ b/src/ltran/ltran_stat.h
@@ -17,7 +17,7 @@
#include <rte_common.h>
-#include "gazelle_opt.h"
+#include "common/gazelle_opt.h"
/*
* When doing reads from the NIC or the client queues,
diff --git a/src/ltran/ltran_tcp_conn.h b/src/ltran/ltran_tcp_conn.h
index fa508bc..82c5faf 100644
--- a/src/ltran/ltran_tcp_conn.h
+++ b/src/ltran/ltran_tcp_conn.h
@@ -18,7 +18,7 @@
#include <stdbool.h>
#include <lwip/reg_sock.h>
-#include "gazelle_opt.h"
+#include "common/gazelle_opt.h"
struct gazelle_tcp_conn {
uint32_t tid;
diff --git a/src/ltran/ltran_tcp_sock.c b/src/ltran/ltran_tcp_sock.c
index d6a0d17..9bc2c45 100644
--- a/src/ltran/ltran_tcp_sock.c
+++ b/src/ltran/ltran_tcp_sock.c
@@ -18,7 +18,7 @@
#include "ltran_instance.h"
#include "ltran_base.h"
#include "ltran_jhash.h"
-#include "gazelle_base_func.h"
+#include "common/gazelle_base_func.h"
#include "ltran_tcp_sock.h"
struct gazelle_tcp_sock_htable *g_tcp_sock_htable = NULL;
diff --git a/src/ltran/ltran_tcp_sock.h b/src/ltran/ltran_tcp_sock.h
index a6e9571..e40891d 100644
--- a/src/ltran/ltran_tcp_sock.h
+++ b/src/ltran/ltran_tcp_sock.h
@@ -17,7 +17,7 @@
#include <pthread.h>
#include <stdint.h>
-#include "gazelle_opt.h"
+#include "common/gazelle_opt.h"
struct gazelle_stack;
struct gazelle_tcp_sock {
diff --git a/src/ltran/main.c b/src/ltran/main.c
index 87f1e14..3156851 100644
--- a/src/ltran/main.c
+++ b/src/ltran/main.c
@@ -18,7 +18,7 @@
#include <sys/types.h>
#include <rte_malloc.h>
-#include "dpdk_common.h"
+#include "common/dpdk_common.h"
#include "ltran_log.h"
#include "ltran_param.h"
#include "ltran_stat.h"
--
2.23.0