23 Commits

Author SHA1 Message Date
lijia
1b30b6d6a2 TSG-8372, 增加三层vlan 自测试用例. 2021-11-08 16:03:29 +08:00
lijia
e1bf15c222 TSG-8372, 修复不支持三层vlan跳转. 2021-11-08 14:19:37 +08:00
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
lijia
9c1e57d6f8 向前兼容, 仍支持历史已有的接口. 2021-09-15 10:36:02 +08:00
16 changed files with 1681 additions and 51 deletions

View File

@@ -7,6 +7,22 @@ variables:
stages: stages:
- build - 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: .build_by_travis:
before_script: before_script:
@@ -26,6 +42,10 @@ branch_build_debug:
extends: .build_by_travis extends: .build_by_travis
variables: variables:
BUILD_TYPE: Debug 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: except:
- /^develop.*$/i - /^develop.*$/i
- /^master.*$/i - /^master.*$/i
@@ -36,6 +56,10 @@ branch_build_release:
variables: variables:
BUILD_TYPE: RelWithDebInfo BUILD_TYPE: RelWithDebInfo
extends: .build_by_travis 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: except:
- /^develop.*$/i - /^develop.*$/i
- /^master.*$/i - /^master.*$/i
@@ -53,8 +77,10 @@ develop_build_debug:
PULP3_REPO_NAME: framework-testing-x86_64.el7 PULP3_REPO_NAME: framework-testing-x86_64.el7
PULP3_DIST_NAME: framework-testing-x86_64.el7 PULP3_DIST_NAME: framework-testing-x86_64.el7
artifacts: artifacts:
name: MESA_jump_layer-$CI_COMMIT_REF_NAME-debug" name: libMESA_jump_layer-$CI_COMMIT_REF_NAME-debug"
paths: 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 - build/*.rpm
only: only:
- /^develop.*$/i - /^develop.*$/i
@@ -72,9 +98,11 @@ develop_build_release:
PULP3_REPO_NAME: framework-testing-x86_64.el7 PULP3_REPO_NAME: framework-testing-x86_64.el7
PULP3_DIST_NAME: framework-testing-x86_64.el7 PULP3_DIST_NAME: framework-testing-x86_64.el7
artifacts: artifacts:
name: MESA_jump_layer-$CI_COMMIT_REF_NAME-release" name: libMESA_jump_layer-$CI_COMMIT_REF_NAME-release"
paths: paths:
- build/*.rpm - 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: only:
- /^develop.*$/i - /^develop.*$/i
- /^master.*$/i - /^master.*$/i
@@ -89,9 +117,11 @@ release_build_debug:
PULP3_DIST_NAME: framework-stable-x86_64.el7 PULP3_DIST_NAME: framework-stable-x86_64.el7
extends: .build_by_travis extends: .build_by_travis
artifacts: artifacts:
name: MESA_jump_layer-$CI_COMMIT_REF_NAME-release" name: libMESA_jump_layer-$CI_COMMIT_REF_NAME-release"
paths: paths:
- build/*.rpm - 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: only:
- tags - tags
@@ -107,8 +137,10 @@ release_build_release:
PULP3_DIST_NAME: framework-stable-x86_64.el7 PULP3_DIST_NAME: framework-stable-x86_64.el7
extends: .build_by_travis extends: .build_by_travis
artifacts: artifacts:
name: MESA_jump_layer-$CI_COMMIT_REF_NAME-release" name: libMESA_jump_layer-$CI_COMMIT_REF_NAME-release"
paths: paths:
- build/*.rpm - 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: only:
- tags - tags

View File

@@ -34,23 +34,10 @@ elseif(ASAN_OPTION MATCHES "THREAD")
endif() endif()
# end of for ASAN # 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) install(FILES inc/MESA_jump_layer.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/MESA COMPONENT HEADER)
include(Package) include(Package)

View File

@@ -26,24 +26,28 @@ set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_COMPONENTS_IGNORE_GROUPS 1) set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP) set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP)
set(CPACK_COMPONENT_HEADER_DISPLAY_NAME "develop") 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_COMPONENT_HEADER_REQUIRED TRUE)
set(CPACK_RPM_HEADER_PACKAGE_NAME "${MY_RPM_NAME_PREFIX}-devel") 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_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_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_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_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}") set(CPACK_BUILD_SOURCE_DIRS "${CMAKE_SOURCE_DIR}")

View File

@@ -13,18 +13,45 @@ extern "C" {
const char *MESA_jump_layer_get_last_error(void); const char *MESA_jump_layer_get_last_error(void);
/* /*
The raw_layer_type and expect_layer_type refer to sapp_base.h->enum addr_type_t CHN : <20><><EFBFBD>ݰ<EFBFBD>ͷ<EFBFBD><CDB7>ƫ<EFBFBD>ƺ<EFBFBD><C6BA><EFBFBD>.
<09><><EFBFBD><EFBFBD>:
raw_data: <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ָ<EFBFBD><D6B8>;
raw_layer_type: <20><>ǰ<EFBFBD><C7B0><EFBFBD>ĵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD>: enum addr_type_t ;
expect_layer_type: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD>ĵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD>: enum addr_type_t ;
<09><><EFBFBD><EFBFBD>ֵ:
NULL: <20>޴˵<DEB4>ַ;
NON-NULL: <20><>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>ַ.
<09><><EFBFBD><EFBFBD>:
<09><><EFBFBD>赱ǰ<E8B5B1><C7B0>ΪEthernet, <20><>ʼ<EFBFBD><CABC>ͷ<EFBFBD><CDB7>ַΪthis_layer_hdr, <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>IPv6<76><36>ͷ<EFBFBD><CDB7>:
struct ip6_hdr *ip6_header;
ip6_header = MESA_net_jump_to_layer(this_layer_hdr, ADDR_TYPE_MAC, ADDR_TYPE_IPV6);
*/ */
const void *MESA_jump_layer(const void *raw_data, int raw_layer_type, int expect_layer_type); const void *MESA_jump_layer(const void *raw_data, int raw_layer_type, int expect_layer_type);
/*
MESA_jump_layer_greedy<64><79>MESA_jump_layer<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD><C7B6>Э<EFBFBD><D0AD><EFBFBD><EFBFBD>˵,
MESA_jump_layer<65><72>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>expect_layer_type;
MESA_jump_layer_greedy<64><79>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD>expect_layer_type;
*/
const void *MESA_jump_layer_greedy(const void *raw_data, int raw_layer_type, int expect_layer_type); const void *MESA_jump_layer_greedy(const void *raw_data, int raw_layer_type, int expect_layer_type);
const char *MESA_jump_layer_ipv4_ntop(const struct ip *ip4_hdr, char *out_buf, int buf_len );
/* <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>Ľӿ<C4BD><D3BF><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC> */
const void *MESA_net_jump_to_layer(const void *raw_data, int raw_layer_type, int expect_layer_type);
const void *MESA_net_jump_to_layer_greedy(const void *raw_data, int raw_layer_type, int expect_layer_type);
const char *MESA_jump_layer_ipv4_ntop(const struct ip *ip4_hdr, char *out_buf, int buf_len );
const char *MESA_jump_layer_ipv6_ntop(const struct ip6_hdr *ip6_hdr, char *out_buf, int buf_len); const char *MESA_jump_layer_ipv6_ntop(const struct ip6_hdr *ip6_hdr, char *out_buf, int buf_len);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

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; return -1;
} }
if(skip_len < 0){
return -1;
}
return gtp_hdr_len + skip_len; 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); 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; 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; return skip_len + mpls_layer_len;
} }
@@ -1175,6 +1187,7 @@ static int vlan8021q_jump_to_layer(const char *raw_data, int raw_layer_type, in
/* QinQ */ /* QinQ */
case ETH_P_8021Q: case ETH_P_8021Q:
snprintf(_g_mesa_jump_layer_last_error, PIPE_BUF, "vlan8021q_jump_to_layer(): multiple VLAN combine to one layer!"); snprintf(_g_mesa_jump_layer_last_error, PIPE_BUF, "vlan8021q_jump_to_layer(): multiple VLAN combine to one layer!");
skip_len = -1;
assert(0); assert(0);
break; break;
@@ -1332,6 +1345,11 @@ const void *MESA_jump_layer(const void *raw_data, int raw_layer_type, int expec
return ((const char *)raw_data + ret); return ((const char *)raw_data + ret);
} }
const void *MESA_net_jump_to_layer(const void *raw_data, int raw_layer_type, int expect_layer_type)
{
return MESA_jump_layer(raw_data, raw_layer_type, expect_layer_type);
}
/* /*
<09><>MESA_jump_layer()<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <09><>MESA_jump_layer()<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
MESA_jump_layer()<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ, <20>ҵ<EFBFBD><D2B5><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD>˳<EFBFBD>; MESA_jump_layer()<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ, <20>ҵ<EFBFBD><D2B5><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD>˳<EFBFBD>;
@@ -1425,6 +1443,11 @@ done:
return success_layer; return success_layer;
} }
const void *MESA_net_jump_to_layer_greedy(const void *raw_data, int raw_layer_type, int expect_layer_type)
{
return MESA_jump_layer_greedy(raw_data, raw_layer_type, expect_layer_type);
}
/* ģ<><C4A3>tcpdump<6D><70>ʽ: 192.168.40.137.22 > 192.168.36.40.49429 */ /* ģ<><C4A3>tcpdump<6D><70>ʽ: 192.168.40.137.22 > 192.168.36.40.49429 */
const char *MESA_jump_layer_ipv4_ntop(const struct ip *ip4_hdr, char *out_buf, int buf_len ) const char *MESA_jump_layer_ipv4_ntop(const struct ip *ip4_hdr, char *out_buf, int buf_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 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 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

1404
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.

Binary file not shown.

View File

@@ -11,6 +11,9 @@ static char *g_input_pcap_name;
static char *g_input_bpf_string; static char *g_input_bpf_string;
static struct bpf_program g_bpf_filter; 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) static void usage(const char *prog)
{ {
printf("Usage:\n"); printf("Usage:\n");
@@ -59,39 +62,109 @@ static int pcap_init(void)
return 0; 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; const void *ip4_hdr, *ip6_h;
char print_buf[128]; char print_buf[128];
int offset_to_eth; int offset_to_eth;
static int pkt_index = 0; static int pkt_index = 0;
ip4_hdr = MESA_jump_layer_greedy(data, ADDR_TYPE_MAC, ADDR_TYPE_IPV4); 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); ip6_h = MESA_jump_layer_greedy(data, ADDR_TYPE_MAC, ADDR_TYPE_IPV6);
printf("-----------------------------packet index:%d------------------------------------------\n", pkt_index++); printf("-----------------------------packet index:%d------------------------------------------\n", pkt_index++);
if(ip4_hdr){ if(ip4_hdr){
offset_to_eth = (u_char *)ip4_hdr-data; offset_to_eth = (u_char *)ip4_hdr-data;
if(g_input_bpf_string 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))){ && (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; 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(ip6_h){ if(g_input_bpf_string
offset_to_eth = (u_char *)ip6_h-data; && (0 == bpf_filter(g_bpf_filter.bf_insns, (const unsigned char *)ip6_h, hdr->caplen-offset_to_eth, hdr->caplen-offset_to_eth))){
if(g_input_bpf_string goto done;
&& (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) 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.