From 88e9eecf09e436c37a5ed3a47dae995d767a035b Mon Sep 17 00:00:00 2001 From: Lu Qiuwen Date: Fri, 16 Nov 2018 20:27:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=9B=AE=E5=BD=95=E7=BB=93?= =?UTF-8?q?=E6=9E=84=EF=BC=8C=E5=A2=9E=E5=8A=A0RPM=E6=89=93=E5=8C=85?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=20*=20=E8=B0=83=E6=95=B4=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E7=BB=93=E6=9E=84=EF=BC=8C=E5=8E=9Fconf=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E5=88=86=E6=8B=86=E4=B8=BAconf=E5=92=8Cresource=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E3=80=82=E5=85=B6=E4=B8=AD=EF=BC=8Cconf=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E5=9C=A8=E8=BD=AF=E4=BB=B6=E6=9B=B4=E6=96=B0=E6=97=B6?= =?UTF-8?q?=E4=B8=8D=E4=BC=9A=E6=9B=B4=E6=96=B0=EF=BC=8Cresource=E5=88=99?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9B=20*=20=E5=A2=9E=E5=8A=A0RPM?= =?UTF-8?q?=E6=89=93=E5=8C=85=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=88=A9=E7=94=A8?= =?UTF-8?q?CI=E5=8F=91=E5=B8=83=E8=BD=AF=E4=BB=B6=E7=9A=84RPM=EF=BC=8C?= =?UTF-8?q?=E5=AF=B9=E5=BA=94=E8=B0=83=E6=95=B4GitLAB-CI=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 54 +++++++++++++++-- CMakeLists.txt | 58 ++++++++++++++++--- ci/travis.sh | 5 +- cmake/Package.cmake | 18 +++--- cmake/Version.cmake | 2 +- conf/CMakeLists.txt | 2 + platform/CMakeLists.txt | 20 +++++-- .../http/include/internal/http_common.h | 6 +- resource/CMakeLists.txt | 3 + .../misc}/DigiCertSHA2SecureServerCA.pem | 0 {conf/tfe => resource/misc}/origin_cert.pem | 0 {conf/pangu => resource/misc}/pangu_ctrl.json | 0 .../misc}/ssca-sha2-g5.crl | 0 .../template => resource/pangu}/HTTP403.html | 0 .../template => resource/pangu}/HTTP404.html | 0 .../template => resource/pangu}/HTTP451.html | 0 {conf => resource}/pangu/table_info.conf | 0 {conf => resource}/tfe/mesalab-ca-untrust.pem | 0 {conf => resource}/tfe/mesalab-ca.pem | 0 {conf => resource}/tfe/tls-ca-bundle.pem | 0 script/r2_tfe | 2 + script/r3_tfe | 17 ++++++ 22 files changed, 154 insertions(+), 33 deletions(-) create mode 100644 conf/CMakeLists.txt create mode 100644 resource/CMakeLists.txt rename {conf/tfe/trusted_storage => resource/misc}/DigiCertSHA2SecureServerCA.pem (100%) rename {conf/tfe => resource/misc}/origin_cert.pem (100%) rename {conf/pangu => resource/misc}/pangu_ctrl.json (100%) rename {conf/tfe/trusted_storage => resource/misc}/ssca-sha2-g5.crl (100%) rename {conf/pangu/template => resource/pangu}/HTTP403.html (100%) rename {conf/pangu/template => resource/pangu}/HTTP404.html (100%) rename {conf/pangu/template => resource/pangu}/HTTP451.html (100%) rename {conf => resource}/pangu/table_info.conf (100%) rename {conf => resource}/tfe/mesalab-ca-untrust.pem (100%) rename {conf => resource}/tfe/mesalab-ca.pem (100%) rename {conf => resource}/tfe/tls-ca-bundle.pem (100%) create mode 100644 script/r2_tfe create mode 100644 script/r3_tfe diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 47d93bb..71c23e3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,8 +1,54 @@ +variables: + GIT_STRATEGY: "clone" + stages: - build +- package -build: - stage: build +before_script: +- mkdir -p /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/$CI_PROJECT_NAMESPACE/ +- ln -s $CI_PROJECT_DIR /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/$CI_PROJECT_PATH +- cd /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/$CI_PROJECT_PATH + +.build_by_travis: script: - - chmod +x ./ci/travis.sh - - ./ci/travis.sh + - chmod +x ./ci/travis.sh + - ./ci/travis.sh + +build_debug: + stage: build + variables: + BUILD_TYPE: Debug + extends: .build_by_travis + +build_release: + stage: build + variables: + BUILD_TYPE: RelWithDebInfo + extends: .build_by_travis + +package_debug: + stage: package + variables: + BUILD_TYPE: Debug + PACKAGE: 1 + extends: .build_by_travis + artifacts: + name: "tfe-install-$CI_COMMIT_REF_NAME-debug" + paths: + - build/*.rpm + only: + - tags + +package_release: + stage: package + variables: + BUILD_TYPE: RelWithDebInfo + PACKAGE: 1 + extends: .build_by_travis + artifacts: + name: "tfe-install-$CI_COMMIT_REF_NAME-release" + paths: + - build/*.rpm + only: + - tags diff --git a/CMakeLists.txt b/CMakeLists.txt index f349346..52e9e0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,18 +3,62 @@ project(tfe) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) include(Version) - -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_C_STANDARD 11) -set(CMAKE_POSITION_INDEPENDENT_CODE ON) +include(Package) add_definitions(-D_GNU_SOURCE) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_C_STANDARD 11) -#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE -Wall -fsanitize=address -fno-omit-frame-pointer") -#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GNU_SOURCE -Wall -fsanitize=address -fno-omit-frame-pointer") -#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan") +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE RelWithDebInfo) +endif() + +# It is not a legal location. +# Consider to the convention, we install the binary tree in /home +if(NOT CMAKE_INSTALL_PREFIX) + set(CMAKE_INSTALL_PREFIX /home/mesasoft/tfe) +endif() + +# Global compile options +option(ENABLE_PIC "Generate position independent code (necessary for shared libraries)" TRUE) +option(ENABLE_WARNING_ALL "Enable all optional warnings which are desirable for normal code" TRUE) +option(ENABLE_SANITIZE_ADDRESS "Enable AddressSanitizer" FALSE) +option(ENABLE_SANITIZE_THREAD "Enable ThreadSanitizer" FALSE) + +# Plugins +option(ENABLE_PLUGIN_HTTP "Enable HTTP support" TRUE) +option(ENABLE_PLUGIN_DECRYPT_MIRRORING "Enable decrypt mirroring" FALSE) +option(ENABLE_PLUGIN_PANGU_HTTP "Enable Pangu-HTTP business" TRUE) + +if(ENABLE_PIC) + set(CMAKE_POSITION_INDEPENDENT_CODE 1) +endif() + +if(ENABLE_WARNING_ALL) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") +endif() + +if(ENABLE_SANITIZE_ADDRESS) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan") +elseif(ENABLE_SANITIZE_THREAD) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread -fno-omit-frame-pointer") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -fno-omit-frame-pointer") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan") +endif() + +if(ENABLE_SANITIZE_ADDRESS AND ENABLE_SANITIZE_THREAD) + message(WARNING "Both ENABLE_SANITIZE_ADDRESS and ENABLE_SANITIZE_THREAD set, only ENABLE_SANITIZE_ADDRESS effected.") +endif() + +add_custom_target("install-program" COMMAND ${CMAKE_COMMAND} ARGS -DCOMPONENT=Program -P cmake_install.cmake) +add_custom_target("install-profile" COMMAND ${CMAKE_COMMAND} ARGS -DCOMPONENT=Profile -P cmake_install.cmake) enable_testing() +add_subdirectory(conf) +add_subdirectory(resource) add_subdirectory(vendor) add_subdirectory(common) add_subdirectory(plugin) diff --git a/ci/travis.sh b/ci/travis.sh index 3661d75..2ba36c8 100644 --- a/ci/travis.sh +++ b/ci/travis.sh @@ -32,10 +32,13 @@ env | sort mkdir build || true cd build -export BUILD_TYPE=Debug cmake -DCMAKE_CXX_FLAGS=$CXX_FLAGS \ -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ .. make CTEST_OUTPUT_ON_FAILURE=1 make test + +if [ -n "${PACKAGE}" ]; then + make package +fi diff --git a/cmake/Package.cmake b/cmake/Package.cmake index 67182f2..8822905 100644 --- a/cmake/Package.cmake +++ b/cmake/Package.cmake @@ -9,7 +9,7 @@ message(STATUS "Package: ${CPACK_PACKAGE_NAME}") set(CPACK_PACKAGE_VENDOR "MESASOFT") set(CPACK_PACKAGE_VERSION_MAJOR "${TFE_VERSION_MAJOR}") set(CPACK_PACKAGE_VERSION_MINOR "${TFE_VERSION_MINOR}") -set(CPACK_PACKAGE_VERSION_PATCH "${TFE_VERSION_PATCH}.${TFE_VERSION_BUILD}") +set(CPACK_PACKAGE_VERSION_PATCH "${TFE_VERSION_PATCH}.${TFE_DESCRIBE}") set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) # RPM Build @@ -19,9 +19,9 @@ set(CPACK_RPM_FILE_NAME "RPM-DEFAULT") set(CPACK_RPM_PACKAGE_AUTOREQPROV "no") set(CPACK_RPM_PACKAGE_RELEASE_DIST on) set(CPACK_RPM_DEBUGINFO_PACKAGE on) -set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PostInstall.in) -set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PostUninstall.in) -set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PreUninstall.in) +#set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PostInstall.in) +#set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PostUninstall.in) +#set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PreUninstall.in) # Must uninstall the debug package before install release package if(CMAKE_BUILD_TYPE STREQUAL "Debug") @@ -31,11 +31,7 @@ else() endif() # setup %config(noreplace) -set(CPACK_RPM_USER_FILELIST "/usr/lib/systemd/system/mrenv.service" - "/usr/lib/systemd/system/mrzcpd.service" - "/usr/lib/systemd/system/mrtunnat.service" - "/usr/lib/systemd/system/mrmonit.service" - "%config(noreplace) ${CMAKE_INSTALL_PREFIX}/etc/mrglobal.conf" - "%config(noreplace) ${CMAKE_INSTALL_PREFIX}/etc/mrtunnat.conf" - "%config(noreplace) /etc/sysconfig/mrzcpd") +set(CPACK_RPM_USER_FILELIST "%config(noreplace) ${CMAKE_INSTALL_PREFIX}/conf/pangu/pangu_pxy.conf" + "%config(noreplace) ${CMAKE_INSTALL_PREFIX}/conf/tfe/decrypt_mirror.conf" + "%config(noreplace) ${CMAKE_INSTALL_PREFIX}/conf/tfe/tfe.conf") include(CPack) diff --git a/cmake/Version.cmake b/cmake/Version.cmake index 63c2b55..b97c9c1 100644 --- a/cmake/Version.cmake +++ b/cmake/Version.cmake @@ -37,6 +37,6 @@ set(TFE_GIT_VERSION "${TFE_VERSION_MAJOR}.${TFE_VERSION_MINOR}.${TFE_VERSION_PAT set(TFE_VAR_VERSION "${TFE_VERSION_MAJOR}_${TFE_VERSION_MINOR}_${TFE_VERSION_PATCH}_${TFE_DESCRIBE}") # print information -message(STATUS "TFE Version: ${TFE_GIT_VERSION}") +message(STATUS "Welcome to Tango Frontend Engine, Version: ${TFE_GIT_VERSION}") add_definitions(-DTFE_GIT_VERSION=\"${TFE_GIT_VERSION}\") add_definitions(-DTFE_VAR_VERSION=${TFE_VAR_VERSION}) diff --git a/conf/CMakeLists.txt b/conf/CMakeLists.txt new file mode 100644 index 0000000..40eb902 --- /dev/null +++ b/conf/CMakeLists.txt @@ -0,0 +1,2 @@ +install(DIRECTORY tfe DESTINATION conf COMPONENT Profile) +install(DIRECTORY pangu DESTINATION conf COMPONENT Profile) diff --git a/platform/CMakeLists.txt b/platform/CMakeLists.txt index 5dfec46..09ae435 100644 --- a/platform/CMakeLists.txt +++ b/platform/CMakeLists.txt @@ -1,4 +1,6 @@ -add_executable(tfe src/key_keeper.cpp src/kni_acceptor.cpp src/ssl_stream.cpp src/ssl_sess_cache.cpp src/ssl_trusted_cert_storage.cpp src/ssl_utils.cc src/tcp_stream.cpp src/main.cpp src/proxy.cpp) +add_executable(tfe src/key_keeper.cpp src/kni_acceptor.cpp src/ssl_stream.cpp + src/ssl_sess_cache.cpp src/ssl_trusted_cert_storage.cpp + src/ssl_utils.cc src/tcp_stream.cpp src/main.cpp src/proxy.cpp) target_include_directories(tfe PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include/external) target_include_directories(tfe PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include/internal) @@ -18,11 +20,19 @@ target_link_libraries(tfe pthread dl MESA_htable wiredcfg MESA_field_stat) -target_link_libraries(tfe -Wl,--whole-archive http -Wl,--no-whole-archive) -target_link_libraries(tfe -Wl,--whole-archive pangu-http -Wl,--no-whole-archive) -#target_link_libraries(tfe -Wl,--whole-archive decrypt-mirroring -Wl,--no-whole-archive) +if(ENABLE_PLUGIN_HTTP) + target_link_libraries(tfe -Wl,--whole-archive http -Wl,--no-whole-archive) +endif() -install(TARGETS tfe RUNTIME DESTINATION ./) +if(ENABLE_PLUGIN_DECRYPT_MIRRORING) + target_link_libraries(tfe -Wl,--whole-archive decrypt-mirroring -Wl,--no-whole-archive) +endif() + +if(ENABLE_PLUGIN_PANGU_HTTP) + target_link_libraries(tfe -Wl,--whole-archive pangu-http -Wl,--no-whole-archive) +endif() + +install(TARGETS tfe RUNTIME DESTINATION bin COMPONENT Program) ### test_key_keeper add_executable(test_key_keeper test/test_key_keeper.cpp src/key_keeper.cpp src/ssl_sess_cache.cpp src/ssl_utils.cc ) diff --git a/plugin/protocol/http/include/internal/http_common.h b/plugin/protocol/http/include/internal/http_common.h index 0bdaeee..2ea85ab 100644 --- a/plugin/protocol/http/include/internal/http_common.h +++ b/plugin/protocol/http/include/internal/http_common.h @@ -54,11 +54,9 @@ struct http_session_private int release_lock; /* thread id */ unsigned int thread_id; - - /* SUSPEND COUNTER, ONLY FOR DEBUG AND LOG */ -#ifndef NDEBUG + /* SUSPEND COUNTER, only for debug and log */ int suspend_counter; -#endif + /* IN GC QUEUE, means the connection of session has destroyed */ bool in_gc_queue; }; diff --git a/resource/CMakeLists.txt b/resource/CMakeLists.txt new file mode 100644 index 0000000..c51b208 --- /dev/null +++ b/resource/CMakeLists.txt @@ -0,0 +1,3 @@ +install(DIRECTORY tfe DESTINATION resource COMPONENT Program) +install(DIRECTORY misc DESTINATION resource COMPONENT Program) +install(DIRECTORY pangu DESTINATION resource COMPONENT Program) diff --git a/conf/tfe/trusted_storage/DigiCertSHA2SecureServerCA.pem b/resource/misc/DigiCertSHA2SecureServerCA.pem similarity index 100% rename from conf/tfe/trusted_storage/DigiCertSHA2SecureServerCA.pem rename to resource/misc/DigiCertSHA2SecureServerCA.pem diff --git a/conf/tfe/origin_cert.pem b/resource/misc/origin_cert.pem similarity index 100% rename from conf/tfe/origin_cert.pem rename to resource/misc/origin_cert.pem diff --git a/conf/pangu/pangu_ctrl.json b/resource/misc/pangu_ctrl.json similarity index 100% rename from conf/pangu/pangu_ctrl.json rename to resource/misc/pangu_ctrl.json diff --git a/conf/tfe/trusted_storage/ssca-sha2-g5.crl b/resource/misc/ssca-sha2-g5.crl similarity index 100% rename from conf/tfe/trusted_storage/ssca-sha2-g5.crl rename to resource/misc/ssca-sha2-g5.crl diff --git a/conf/pangu/template/HTTP403.html b/resource/pangu/HTTP403.html similarity index 100% rename from conf/pangu/template/HTTP403.html rename to resource/pangu/HTTP403.html diff --git a/conf/pangu/template/HTTP404.html b/resource/pangu/HTTP404.html similarity index 100% rename from conf/pangu/template/HTTP404.html rename to resource/pangu/HTTP404.html diff --git a/conf/pangu/template/HTTP451.html b/resource/pangu/HTTP451.html similarity index 100% rename from conf/pangu/template/HTTP451.html rename to resource/pangu/HTTP451.html diff --git a/conf/pangu/table_info.conf b/resource/pangu/table_info.conf similarity index 100% rename from conf/pangu/table_info.conf rename to resource/pangu/table_info.conf diff --git a/conf/tfe/mesalab-ca-untrust.pem b/resource/tfe/mesalab-ca-untrust.pem similarity index 100% rename from conf/tfe/mesalab-ca-untrust.pem rename to resource/tfe/mesalab-ca-untrust.pem diff --git a/conf/tfe/mesalab-ca.pem b/resource/tfe/mesalab-ca.pem similarity index 100% rename from conf/tfe/mesalab-ca.pem rename to resource/tfe/mesalab-ca.pem diff --git a/conf/tfe/tls-ca-bundle.pem b/resource/tfe/tls-ca-bundle.pem similarity index 100% rename from conf/tfe/tls-ca-bundle.pem rename to resource/tfe/tls-ca-bundle.pem diff --git a/script/r2_tfe b/script/r2_tfe new file mode 100644 index 0000000..41a8b4a --- /dev/null +++ b/script/r2_tfe @@ -0,0 +1,2 @@ +killall r3_tfe tfe +./r3_tfe &> /dev/null & diff --git a/script/r3_tfe b/script/r3_tfe new file mode 100644 index 0000000..18cda30 --- /dev/null +++ b/script/r3_tfe @@ -0,0 +1,17 @@ +#!/bin/sh + +while [ 1 ]; do + count=`ls -l core.* |wc -l` + echo $count + if [ $count -lt 5 ] + then + echo "set unlimited" + ulimit -c unlimited + else + ulimit -c 0 + fi + + ./tfe > log/screen.log 2>&1 + echo program crashed, restart at `date +"%w %Y/%m/%d, %H:%M:%S"` >> RESTART.log + sleep 10 +done