20 Commits

Author SHA1 Message Date
lijia
e683d478a8 修复CI编译错误. 2021-10-29 11:41:09 +08:00
lijia
7a0b7d2316 修复CI编译错误. 2021-10-29 11:10:32 +08:00
lijia
004a1d3b00 修复CI编译错误. 2021-10-29 10:28:22 +08:00
lijia
86ccc7b43a 修复CI编译错误. 2021-10-29 10:02:19 +08:00
lijia
3cdcf375e9 修复CI编译错误. 2021-10-29 09:51:49 +08:00
lijia
ab48f907bf TSG-8236, 修复MESA_jump_layer_greedy跳转到UDP层BUG. 2021-10-28 18:29:19 +08:00
lijia
7bea6fa98e update artifacts. 2021-10-27 18:28:50 +08:00
lijia
d722113df2 update .gitlab-ci.yml. 2021-10-27 18:18:27 +08:00
lijia
caf7e5a32d Update .gitlab-ci.yml 2021-10-27 18:13:06 +08:00
lijia
bde81dcec6 Update .gitlab-ci.yml 2021-10-27 18:08:45 +08:00
李佳
ff7877d432 Update .gitlab-ci.yml 2021-10-27 10:03:27 +00:00
李佳
108c79ff68 Update .gitlab-ci.yml 2021-10-27 09:57:43 +00:00
李佳
0307f185fd Update .gitlab-ci.yml 2021-10-27 09:53:50 +00:00
lijia
637887fddb 修复test stage. 2021-10-27 17:40:06 +08:00
lijia
eee615c453 修复test stage. 2021-10-27 17:32:10 +08:00
lijia
ed151c0c0e 修复test stage. 2021-10-27 17:27:47 +08:00
lijia
0fb6a5c61d 修复test stage. 2021-10-27 17:11:56 +08:00
lijia
b99651da62 修复编译错误, 增加test stage. 2021-10-27 17:01:06 +08:00
lijia
5bcadbe078 添加依赖库googletest. 2021-10-26 22:05:15 +08:00
lijia
daef36bc33 添加gtest测试用例. 2021-10-26 18:41:54 +08:00
14 changed files with 1527 additions and 48 deletions

View File

@@ -7,6 +7,22 @@ variables:
stages:
- build
- test
google_test:
stage: test
script:
- cp -r test/sample_pcap /tmp
- ulimit -c 0
- cp /builds/MESA_framework/mesa_jump_layer/build/test/gtest_jump_layer /tmp/
- mkdir -p /opt/MESA/lib
- cp /builds/MESA_framework/mesa_jump_layer/build/src/libMESA_jump_layer.so /opt/MESA/lib/
- echo "/opt/MESA/lib" >> /etc/ld.so.conf
- ldconfig
- cd /tmp
- ./gtest_jump_layer
tags:
- share
.build_by_travis:
before_script:
@@ -26,6 +42,10 @@ branch_build_debug:
extends: .build_by_travis
variables:
BUILD_TYPE: Debug
artifacts:
paths:
- /builds/MESA_framework/mesa_jump_layer/build/test/gtest_jump_layer
- /builds/MESA_framework/mesa_jump_layer/build/src/libMESA_jump_layer.so
except:
- /^develop.*$/i
- /^master.*$/i
@@ -36,6 +56,10 @@ branch_build_release:
variables:
BUILD_TYPE: RelWithDebInfo
extends: .build_by_travis
artifacts:
paths:
- /builds/MESA_framework/mesa_jump_layer/build/test/gtest_jump_layer
- /builds/MESA_framework/mesa_jump_layer/build/src/libMESA_jump_layer.so
except:
- /^develop.*$/i
- /^master.*$/i
@@ -53,8 +77,10 @@ develop_build_debug:
PULP3_REPO_NAME: framework-testing-x86_64.el7
PULP3_DIST_NAME: framework-testing-x86_64.el7
artifacts:
name: MESA_jump_layer-$CI_COMMIT_REF_NAME-debug"
name: libMESA_jump_layer-$CI_COMMIT_REF_NAME-debug"
paths:
- /builds/MESA_framework/mesa_jump_layer/build/test/gtest_jump_layer
- /builds/MESA_framework/mesa_jump_layer/build/src/libMESA_jump_layer.so
- build/*.rpm
only:
- /^develop.*$/i
@@ -72,9 +98,11 @@ develop_build_release:
PULP3_REPO_NAME: framework-testing-x86_64.el7
PULP3_DIST_NAME: framework-testing-x86_64.el7
artifacts:
name: MESA_jump_layer-$CI_COMMIT_REF_NAME-release"
name: libMESA_jump_layer-$CI_COMMIT_REF_NAME-release"
paths:
- build/*.rpm
- /builds/MESA_framework/mesa_jump_layer/build/test/gtest_jump_layer
- /builds/MESA_framework/mesa_jump_layer/build/src/libMESA_jump_layer.so
only:
- /^develop.*$/i
- /^master.*$/i
@@ -89,9 +117,11 @@ release_build_debug:
PULP3_DIST_NAME: framework-stable-x86_64.el7
extends: .build_by_travis
artifacts:
name: MESA_jump_layer-$CI_COMMIT_REF_NAME-release"
name: libMESA_jump_layer-$CI_COMMIT_REF_NAME-release"
paths:
- build/*.rpm
- /builds/MESA_framework/mesa_jump_layer/build/test/gtest_jump_layer
- /builds/MESA_framework/mesa_jump_layer/build/src/libMESA_jump_layer.so
only:
- tags
@@ -107,8 +137,10 @@ release_build_release:
PULP3_DIST_NAME: framework-stable-x86_64.el7
extends: .build_by_travis
artifacts:
name: MESA_jump_layer-$CI_COMMIT_REF_NAME-release"
name: libMESA_jump_layer-$CI_COMMIT_REF_NAME-release"
paths:
- build/*.rpm
- /builds/MESA_framework/mesa_jump_layer/build/test/gtest_jump_layer
- /builds/MESA_framework/mesa_jump_layer/build/src/libMESA_jump_layer.so
only:
- tags

View File

@@ -34,23 +34,10 @@ elseif(ASAN_OPTION MATCHES "THREAD")
endif()
# end of for ASAN
include_directories(${PROJECT_SOURCE_DIR}/include/)
add_subdirectory(./vendor)
add_subdirectory(./src)
add_subdirectory(./test)
file(GLOB SRC
"src/*.c"
"src/*.cpp"
)
# Shared Library Output
add_library(${lib_name}_shared SHARED ${SRC})
target_link_libraries(${lib_name}_shared m)
if(DEFINED MESA_SHARED_INSTALL_DIR)
set_target_properties(${lib_name}_shared PROPERTIES OUTPUT_NAME ${lib_name} LIBRARY_OUTPUT_DIRECTORY ${MESA_SHARED_INSTALL_DIR})
else()
set_target_properties(${lib_name}_shared PROPERTIES OUTPUT_NAME ${lib_name})
endif()
install(TARGETS ${lib_name}_shared LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT LIBRARY)
install(FILES inc/MESA_jump_layer.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/MESA COMPONENT HEADER)
include(Package)

View File

@@ -26,24 +26,28 @@ set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP)
set(CPACK_COMPONENT_HEADER_DISPLAY_NAME "develop")
set(CPACK_COMPONENT_LIBRARY_REQUIRED TRUE)
set(CPACK_COMPONENT_LIBRARIES_REQUIRED TRUE)
set(CPACK_RPM_LIBRARIES_PACKAGE_NAME ${MY_RPM_NAME_PREFIX})
set(CPACK_RPM_LIBRARIES_FILE_NAME "${CPACK_RPM_LIBRARIES_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
set(CPACK_RPM_LIBRARIES_DEBUGINFO_FILE_NAME "${CPACK_RPM_LIBRARIES_PACKAGE_NAME}-debuginfo-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
set(CPACK_COMPONENT_PROFILE_GROUP "libraries")
set(CPACK_COMPONENT_LIBRARIES_GROUP "libraries")
set(CPACK_COMPONENT_HEADER_REQUIRED TRUE)
set(CPACK_RPM_HEADER_PACKAGE_NAME "${MY_RPM_NAME_PREFIX}-devel")
set(CPACK_RPM_LIBRARY_PACKAGE_NAME ${MY_RPM_NAME_PREFIX})
set(CPACK_RPM_FILE_NAME "${CPACK_RPM_LIBRARY_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
set(CPACK_RPM_LIBRARY_DEBUGINFO_FILE_NAME "${CPACK_RPM_LIBRARY_PACKAGE_NAME}-debuginfo-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
set(CPACK_COMPONENT_LIBRARY_GROUP "library")
set(CPACK_RPM_HEADER_FILE_NAME "${CPACK_RPM_HEADER_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
set(CPACK_RPM_HEADER_DEBUGINFO_FILE_NAME "${CPACK_RPM_HEADER_PACKAGE_NAME}-debuginfo-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
set(CPACK_COMPONENT_HEADER_GROUP "header")
set(CPACK_RPM_HEADER_PACKAGE_REQUIRES_PRE ${CPACK_RPM_LIBRARY_PACKAGE_NAME})
set(CPACK_RPM_HEADER_PACKAGE_REQUIRES_PRE ${CPACK_RPM_LIBRARIES_PACKAGE_NAME})
set(CPACK_RPM_HEADER_PACKAGE_CONFLICTS ${CPACK_RPM_HEADER_PACKAGE_NAME})
set(CPACK_COMPONENTS_ALL LIBRARY HEADER)
set(CPACK_COMPONENTS_ALL HEADER PROFILE LIBRARIES)
set(CPACK_RPM_PACKAGE_AUTOREQPROV "no")
set(CPACK_RPM_PACKAGE_AUTOREQ "no")
set(CPACK_BUILD_SOURCE_DIRS "${CMAKE_SOURCE_DIR}")

36
src/CMakeLists.txt Normal file
View File

@@ -0,0 +1,36 @@
cmake_minimum_required(VERSION 2.8)
set(MESA_SDK_PREFIX "/opt/MESA" CACHE STRING "MESA Framework Prefix")
include_directories(${MESA_SDK_PREFIX}/include)
include_directories(${MESA_SDK_PREFIX}/include/MESA)
include_directories(${MESA_SDK_PREFIX}/include/MESA/include)
include_directories(${MESA_SDK_PREFIX}/include/MESA/stream_inc)
include_directories(${PROJECT_SOURCE_DIR}/include/)
LINK_DIRECTORIES(/opt/MESA/lib)
add_definitions(-D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H)
add_definitions(-DSAPP_V4=1)
add_definitions(-fPIC)
add_definitions(-std=c++11)
set(SRC MESA_jump_layer.cpp)
# Shared Library Output
add_library(${lib_name}_shared SHARED ${SRC})
target_link_libraries(${lib_name}_shared m)
if(DEFINED MESA_SHARED_INSTALL_DIR)
set_target_properties(${lib_name}_shared PROPERTIES OUTPUT_NAME ${lib_name} LIBRARY_OUTPUT_DIRECTORY ${MESA_SHARED_INSTALL_DIR})
else()
set_target_properties(${lib_name}_shared PROPERTIES OUTPUT_NAME ${lib_name})
endif()
target_link_libraries(${lib_name}_shared m)
install(TARGETS ${lib_name}_shared LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT LIBRARIES)
#install(FILES ${CMAKE_BINARY_DIR}/src/libMESA_jump_layer.so DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT LIBRARIES)
include(Package)

View File

@@ -290,6 +290,10 @@ static int gtp_jump_to_layer(const char *raw_data, int raw_layer_type, int expe
return -1;
}
if(skip_len < 0){
return -1;
}
return gtp_hdr_len + skip_len;
}
@@ -425,6 +429,10 @@ static int l2tp_jump_to_layer(const char *raw_data, int raw_layer_type, int exp
skip_len = ipv6_jump_to_layer((char *)next_layer_hdr, __ADDR_TYPE_IP_PAIR_V6, expect_layer_type);
}
}
if(skip_len < 0){
return -1;
}
return l2tp_hdr_len + skip_len;
}
@@ -1020,6 +1028,10 @@ static int mpls_jump_to_layer(const char *raw_data, int raw_layer_type, int exp
}
}
if(skip_len < 0){
return -1;
}
return skip_len + mpls_layer_len;
}

16
test/CMakeLists.txt Normal file
View File

@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 2.8)
include_directories(${CMAKE_SOURCE_DIR}/inc)
include_directories(${MESA_SDK_PREFIX}/include)
include_directories(${MESA_SDK_PREFIX}/include/MESA)
add_definitions(-D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H)
add_definitions(-fPIC -std=c++11)
LINK_DIRECTORIES(/opt/MESA/lib)
LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/src)
add_executable(gtest_jump_layer gtest_jump_layer.cpp)
target_link_libraries(gtest_jump_layer pcap gtest-static MESA_jump_layer)

View File

@@ -1,2 +1,9 @@
all: test_jump_layer gtest_jump_layer
CFLAGS = -g -Wall -fPIC -std=c++11 -DSAPP_V4=1 -D_XOPEN_SOURCE
test_jump_layer:test_jump_layer.c
gcc -g -o $@ test_jump_layer.c -D_GNU_SOURCE -L/opt/MESA/lib -lMESA_jump_layer -I ../inc -I/opt/MESA/include/MESA -l pcap
gtest_jump_layer:gtest_jump_layer.cpp
g++ -g -o $@ $^ $(CFLAGS) -D_GNU_SOURCE -L/opt/MESA/lib -lMESA_jump_layer -I ../inc -I/opt/MESA/include/MESA -lpcap -lgtest -lpthread

1291
test/gtest_jump_layer.cpp Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -11,6 +11,9 @@ static char *g_input_pcap_name;
static char *g_input_bpf_string;
static struct bpf_program g_bpf_filter;
static int g_raw_input_layer_type = (int )ADDR_TYPE_MAC;
static int g_expect_layer_type = (int )ADDR_TYPE_IPV4;
static void usage(const char *prog)
{
printf("Usage:\n");
@@ -59,39 +62,109 @@ static int pcap_init(void)
return 0;
}
static void _pcap_pkt_handle(u_char *user, const struct pcap_pkthdr *hdr, const u_char *data)
static void _jump_from_udp(const void *uhdr)
{
const void *next_hdr;
next_hdr = MESA_jump_layer(uhdr, ADDR_TYPE_UDP, ADDR_TYPE_GPRS_TUNNEL);
if(next_hdr){
printf("bingo! jump to gtp from udp succ!\n");
}
next_hdr = MESA_jump_layer(uhdr, ADDR_TYPE_UDP, ADDR_TYPE_L2TP);
if(next_hdr){
printf("bingo! jump to l2tp from udp succ!\n");
}
}
static void _jump_from_ipv4(const void *ip4_hdr)
{
const void *next_hdr;
next_hdr = MESA_jump_layer(ip4_hdr, ADDR_TYPE_IPV4, ADDR_TYPE_TCP);
if(next_hdr){
printf("bingo! jump to tcp from ipv4 succ!\n");
}
next_hdr = MESA_jump_layer(ip4_hdr, ADDR_TYPE_IPV4, ADDR_TYPE_UDP);
if(next_hdr){
printf("bingo! jump to udp from ipv4 succ!\n");
_jump_from_udp(next_hdr);
}
}
static void _jump_from_ipv6(const void *ip4_hdr)
{
}
static void _jump_from_ethernet(const void *ehdr)
{
const void *next_hdr;
next_hdr = MESA_jump_layer(ehdr, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
if(next_hdr){
printf("bingo! jump to ipv4 from ethernet succ!\n");
_jump_from_ipv4(next_hdr);
}
next_hdr = MESA_jump_layer(ehdr, ADDR_TYPE_MAC, ADDR_TYPE_IPV6);
if(next_hdr){
printf("bingo! jump to ipv6 from ethernet succ!\n");
_jump_from_ipv6(next_hdr);
}
}
static void _jump_greedy(const struct pcap_pkthdr *hdr, const u_char *data)
{
const void *ip4_hdr, *ip6_h;
char print_buf[128];
int offset_to_eth;
static int pkt_index = 0;
ip4_hdr = MESA_jump_layer_greedy(data, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
ip6_h = MESA_jump_layer_greedy(data, ADDR_TYPE_MAC, ADDR_TYPE_IPV6);
printf("-----------------------------packet index:%d------------------------------------------\n", pkt_index++);
if(ip4_hdr){
offset_to_eth = (u_char *)ip4_hdr-data;
if(g_input_bpf_string
&& (0 == bpf_filter(g_bpf_filter.bf_insns, (const unsigned char *)ip4_hdr, hdr->caplen-offset_to_eth, hdr->caplen-offset_to_eth))){
goto done;
printf("-----------------------------packet index:%d------------------------------------------\n", pkt_index++);
if(ip4_hdr){
offset_to_eth = (u_char *)ip4_hdr-data;
if(g_input_bpf_string
&& (0 == bpf_filter(g_bpf_filter.bf_insns, (const unsigned char *)ip4_hdr, hdr->caplen-offset_to_eth, hdr->caplen-offset_to_eth))){
goto done;
}
printf("Innermost layer ipv4 offset:%d, addr: %s\n", offset_to_eth, MESA_jump_layer_ipv4_ntop((struct ip *)ip4_hdr, print_buf, sizeof(print_buf)));
}
printf("Innermost layer ipv4 offset:%d, addr: %s\n", offset_to_eth, MESA_jump_layer_ipv4_ntop((struct ip *)ip4_hdr, print_buf, sizeof(print_buf)));
}
if(ip6_h){
offset_to_eth = (u_char *)ip6_h-data;
if(g_input_bpf_string
&& (0 == bpf_filter(g_bpf_filter.bf_insns, (const unsigned char *)ip6_h, hdr->caplen-offset_to_eth, hdr->caplen-offset_to_eth))){
goto done;
if(ip6_h){
offset_to_eth = (u_char *)ip6_h-data;
if(g_input_bpf_string
&& (0 == bpf_filter(g_bpf_filter.bf_insns, (const unsigned char *)ip6_h, hdr->caplen-offset_to_eth, hdr->caplen-offset_to_eth))){
goto done;
}
printf("Innermost layer ipv6 offset:%d, addr: %s\n", offset_to_eth, MESA_jump_layer_ipv6_ntop((struct ip6_hdr *)ip6_h, print_buf, sizeof(print_buf)));
}
done:
printf("--------------------------------------------------------------------------------------\n\n");
printf("Innermost layer ipv6 offset:%d, addr: %s\n", offset_to_eth, MESA_jump_layer_ipv6_ntop((struct ip6_hdr *)ip6_h, print_buf, sizeof(print_buf)));
}
}
done:
static void _pcap_pkt_handle(u_char *user, const struct pcap_pkthdr *hdr, const u_char *data)
{
_jump_from_ethernet(data);
_jump_greedy(hdr, data);
printf("--------------------------------------------------------------------------------------\n\n");
}
static void pcap_run(void)

21
vendor/CMakeLists.txt vendored Normal file
View File

@@ -0,0 +1,21 @@
# CMakeFiles for 3rd vendor library
include(ExternalProject)
# libgtest
ExternalProject_Add(libgtest PREFIX libgtest
URL ${CMAKE_SOURCE_DIR}/vendor/googletest-release-1.10.0.tar.gz
URL_MD5 ecd1fa65e7de707cd5c00bdac56022cd
#CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_BUILD_TYPE=RELWITHDEBINFO)
ExternalProject_Get_Property(libgtest INSTALL_DIR)
file(MAKE_DIRECTORY ${INSTALL_DIR}/include)
add_library(gtest-static STATIC IMPORTED GLOBAL)
add_dependencies(gtest-static libgtest)
set_property(TARGET gtest-static PROPERTY IMPORTED_LOCATION ${INSTALL_DIR}/lib64/libgtest.a)
set_property(TARGET gtest-static PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include)
set_property(TARGET gtest-static PROPERTY INTERFACE_LINK_LIBRARIES pthread)

BIN
vendor/googletest-release-1.10.0.tar.gz vendored Normal file

Binary file not shown.